This commit is contained in:
Данила Селяев 2025-02-21 16:05:46 +04:00
parent fca5f52c57
commit 01fd280859
8 changed files with 230 additions and 124 deletions

View File

@ -63,8 +63,10 @@ namespace FoodOrderDatabaseImplement.Implements
return null; return null;
} }
using var context = new FoodOrdersDataBase(); using var context = new FoodOrdersDataBase();
context.Clients.Add(newClient); context.Clients.Add(newClient);
context.SaveChanges(); context.SaveChanges();
return newClient.GetViewModel; return newClient.GetViewModel;
} }
public ClientViewModel? Update(ClientBindingModel model) public ClientViewModel? Update(ClientBindingModel model)

View File

@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace FoodOrderDatabaseImplement.Migrations namespace FoodOrderDatabaseImplement.Migrations
{ {
[DbContext(typeof(FoodOrdersDataBase))] [DbContext(typeof(FoodOrdersDataBase))]
[Migration("20231122135912_Init")] [Migration("20250217133549_InitMigration")]
partial class Init partial class InitMigration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder) protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -37,7 +37,7 @@ namespace FoodOrderDatabaseImplement.Migrations
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasColumnType("text");
b.Property<string>("Login") b.Property<string>("Email")
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasColumnType("text");

View File

@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace FoodOrderDatabaseImplement.Migrations namespace FoodOrderDatabaseImplement.Migrations
{ {
/// <inheritdoc /> /// <inheritdoc />
public partial class Init : Migration public partial class InitMigration : Migration
{ {
/// <inheritdoc /> /// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder) protected override void Up(MigrationBuilder migrationBuilder)
@ -19,7 +19,7 @@ namespace FoodOrderDatabaseImplement.Migrations
Id = table.Column<int>(type: "integer", nullable: false) Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientFIO = table.Column<string>(type: "text", nullable: false), ClientFIO = table.Column<string>(type: "text", nullable: false),
Login = table.Column<string>(type: "text", nullable: false), Email = table.Column<string>(type: "text", nullable: false),
Password = table.Column<string>(type: "text", nullable: false) Password = table.Column<string>(type: "text", nullable: false)
}, },
constraints: table => constraints: table =>

View File

@ -34,7 +34,7 @@ namespace FoodOrderDatabaseImplement.Migrations
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasColumnType("text");
b.Property<string>("Login") b.Property<string>("Email")
.IsRequired() .IsRequired()
.HasColumnType("text"); .HasColumnType("text");

View File

@ -20,119 +20,139 @@
base.Dispose(disposing); base.Dispose(disposing);
} }
#region Windows Form Designer generated code #region Windows Form Designer generated code
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.WorkNameLabel = new System.Windows.Forms.Label(); WorkNameLabel = new Label();
this.CountLabel = new System.Windows.Forms.Label(); CountLabel = new Label();
this.SumLabel = new System.Windows.Forms.Label(); SumLabel = new Label();
this.FoodComboBox = new System.Windows.Forms.ComboBox(); FoodComboBox = new ComboBox();
this.CountTextBox = new System.Windows.Forms.TextBox(); CountTextBox = new TextBox();
this.SumTextBox = new System.Windows.Forms.TextBox(); SumTextBox = new TextBox();
this.SaveButton = new System.Windows.Forms.Button(); SaveButton = new Button();
this.ButtonCancel = new System.Windows.Forms.Button(); ButtonCancel = new Button();
this.SuspendLayout(); comboBox4 = new ComboBox();
// label1 = new Label();
// WorkNameLabel SuspendLayout();
// //
this.WorkNameLabel.AutoSize = true; // WorkNameLabel
this.WorkNameLabel.Location = new System.Drawing.Point(25, 15); //
this.WorkNameLabel.Name = "WorkNameLabel"; WorkNameLabel.AutoSize = true;
this.WorkNameLabel.Size = new System.Drawing.Size(59, 15); WorkNameLabel.Location = new Point(25, 15);
this.WorkNameLabel.TabIndex = 0; WorkNameLabel.Name = "WorkNameLabel";
this.WorkNameLabel.Text = "Изделие: "; WorkNameLabel.Size = new Size(59, 15);
// WorkNameLabel.TabIndex = 0;
// CountLabel WorkNameLabel.Text = "Изделие: ";
// //
this.CountLabel.AutoSize = true; // CountLabel
this.CountLabel.Location = new System.Drawing.Point(25, 44); //
this.CountLabel.Name = "CountLabel"; CountLabel.AutoSize = true;
this.CountLabel.Size = new System.Drawing.Size(78, 15); CountLabel.Location = new Point(25, 44);
this.CountLabel.TabIndex = 1; CountLabel.Name = "CountLabel";
this.CountLabel.Text = "Количество: "; CountLabel.Size = new Size(78, 15);
// CountLabel.TabIndex = 1;
// SumLabel CountLabel.Text = "Количество: ";
// //
this.SumLabel.AutoSize = true; // SumLabel
this.SumLabel.Location = new System.Drawing.Point(25, 76); //
this.SumLabel.Name = "SumLabel"; SumLabel.AutoSize = true;
this.SumLabel.Size = new System.Drawing.Size(51, 15); SumLabel.Location = new Point(25, 76);
this.SumLabel.TabIndex = 2; SumLabel.Name = "SumLabel";
this.SumLabel.Text = "Сумма: "; SumLabel.Size = new Size(51, 15);
// SumLabel.TabIndex = 2;
// FoodComboBox SumLabel.Text = "Сумма: ";
// //
this.FoodComboBox.FormattingEnabled = true; // FoodComboBox
this.FoodComboBox.Location = new System.Drawing.Point(111, 15); //
this.FoodComboBox.Name = "FoodComboBox"; FoodComboBox.FormattingEnabled = true;
this.FoodComboBox.Size = new System.Drawing.Size(214, 23); FoodComboBox.Location = new Point(111, 15);
this.FoodComboBox.TabIndex = 4; FoodComboBox.Name = "FoodComboBox";
this.FoodComboBox.SelectedIndexChanged += new System.EventHandler(this.FoodComboBox_SelectedIndexChanged); FoodComboBox.Size = new Size(214, 23);
// FoodComboBox.TabIndex = 4;
// CountTextBox FoodComboBox.SelectedIndexChanged += FoodComboBox_SelectedIndexChanged;
// //
this.CountTextBox.Location = new System.Drawing.Point(111, 44); // CountTextBox
this.CountTextBox.Name = "CountTextBox"; //
this.CountTextBox.Size = new System.Drawing.Size(214, 23); CountTextBox.Location = new Point(111, 44);
this.CountTextBox.TabIndex = 5; CountTextBox.Name = "CountTextBox";
this.CountTextBox.TextChanged += new System.EventHandler(this.CountTextBox_TextChanged); CountTextBox.Size = new Size(214, 23);
// CountTextBox.TabIndex = 5;
// SumTextBox CountTextBox.TextChanged += CountTextBox_TextChanged;
// //
this.SumTextBox.Enabled = false; // SumTextBox
this.SumTextBox.Location = new System.Drawing.Point(111, 73); //
this.SumTextBox.Name = "SumTextBox"; SumTextBox.Enabled = false;
this.SumTextBox.Size = new System.Drawing.Size(214, 23); SumTextBox.Location = new Point(111, 73);
this.SumTextBox.TabIndex = 6; SumTextBox.Name = "SumTextBox";
// SumTextBox.Size = new Size(214, 23);
// SaveButton SumTextBox.TabIndex = 6;
// //
this.SaveButton.Location = new System.Drawing.Point(111, 115); // SaveButton
this.SaveButton.Name = "SaveButton"; //
this.SaveButton.Size = new System.Drawing.Size(95, 23); SaveButton.Location = new Point(111, 178);
this.SaveButton.TabIndex = 7; SaveButton.Name = "SaveButton";
this.SaveButton.Text = "Сохранить"; SaveButton.Size = new Size(95, 23);
this.SaveButton.UseVisualStyleBackColor = true; SaveButton.TabIndex = 7;
this.SaveButton.MouseClick += new System.Windows.Forms.MouseEventHandler(this.SaveButton_Click); SaveButton.Text = "Сохранить";
// SaveButton.UseVisualStyleBackColor = true;
// ButtonCancel SaveButton.MouseClick += SaveButton_Click;
// //
this.ButtonCancel.Location = new System.Drawing.Point(230, 115); // ButtonCancel
this.ButtonCancel.Name = "ButtonCancel"; //
this.ButtonCancel.Size = new System.Drawing.Size(95, 23); ButtonCancel.Location = new Point(230, 178);
this.ButtonCancel.TabIndex = 8; ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Text = "Отменить"; ButtonCancel.Size = new Size(95, 23);
this.ButtonCancel.UseVisualStyleBackColor = true; ButtonCancel.TabIndex = 8;
this.ButtonCancel.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ButtonCancel_Click); ButtonCancel.Text = "Отменить";
// ButtonCancel.UseVisualStyleBackColor = true;
// FormCreateOrder ButtonCancel.MouseClick += ButtonCancel_Click;
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); // comboBox4
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; //
this.ClientSize = new System.Drawing.Size(350, 146); comboBox4.FormattingEnabled = true;
this.Controls.Add(this.ButtonCancel); comboBox4.Location = new Point(111, 102);
this.Controls.Add(this.SaveButton); comboBox4.Name = "comboBox4";
this.Controls.Add(this.SumTextBox); comboBox4.Size = new Size(214, 23);
this.Controls.Add(this.CountTextBox); comboBox4.TabIndex = 10;
this.Controls.Add(this.FoodComboBox); //
this.Controls.Add(this.SumLabel); // label1
this.Controls.Add(this.CountLabel); //
this.Controls.Add(this.WorkNameLabel); label1.AutoSize = true;
this.Name = "FormCreateOrder"; label1.Location = new Point(25, 102);
this.Text = "Заказ"; label1.Name = "label1";
this.ResumeLayout(false); label1.Size = new Size(52, 15);
this.PerformLayout(); label1.TabIndex = 9;
label1.Text = "Клиент: ";
//
// FormCreateOrder
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(346, 213);
Controls.Add(comboBox4);
Controls.Add(label1);
Controls.Add(ButtonCancel);
Controls.Add(SaveButton);
Controls.Add(SumTextBox);
Controls.Add(CountTextBox);
Controls.Add(FoodComboBox);
Controls.Add(SumLabel);
Controls.Add(CountLabel);
Controls.Add(WorkNameLabel);
Name = "FormCreateOrder";
Text = "Заказ";
ResumeLayout(false);
PerformLayout();
}
} #endregion
#endregion private Label WorkNameLabel;
private Label WorkNameLabel;
private Label CountLabel; private Label CountLabel;
private Label SumLabel; private Label SumLabel;
private ComboBox FoodComboBox; private ComboBox FoodComboBox;
@ -140,5 +160,7 @@
private TextBox SumTextBox; private TextBox SumTextBox;
private Button SaveButton; private Button SaveButton;
private Button ButtonCancel; private Button ButtonCancel;
} private ComboBox comboBox4;
private Label label1;
}
} }

View File

@ -8,6 +8,7 @@ using System.ComponentModel;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Runtime.ConstrainedExecution;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
@ -19,14 +20,17 @@ namespace FoodOrdersView
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IFoodLogic _logicW; private readonly IFoodLogic _logicW;
private readonly IOrderLogic _logicO; private readonly IOrderLogic _logicO;
private readonly IClientLogic _logicC;
public FormCreateOrder(ILogger<FormCreateOrder> logger, IFoodLogic logicF, IOrderLogic logicO) public FormCreateOrder(ILogger<FormCreateOrder> logger, IFoodLogic logicF, IOrderLogic logicO, IClientLogic logicC)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logicW = logicF; _logicW = logicF;
_logicO = logicO; _logicO = logicO;
LoadData(); _logicC = logicC;
LoadData();
} }
private void FormCreateOrder_Load(object sender, EventArgs e) private void FormCreateOrder_Load(object sender, EventArgs e)
@ -55,7 +59,24 @@ namespace FoodOrdersView
_logger.LogError(ex, "Ошибка загрузки списка изделий"); _logger.LogError(ex, "Ошибка загрузки списка изделий");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} try
{
var list = _logicC.ReadList(null);
if (list != null)
{
comboBox4.DisplayMember = "ClientFIO";
comboBox4.ValueMember = "Id";
comboBox4.DataSource = list;
comboBox4.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки списка пользователей");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void CalcSum() private void CalcSum()
{ {
@ -114,11 +135,12 @@ namespace FoodOrdersView
{ {
FoodId = Convert.ToInt32(FoodComboBox.SelectedValue), FoodId = Convert.ToInt32(FoodComboBox.SelectedValue),
FoodName = FoodComboBox.Text, FoodName = FoodComboBox.Text,
ClientId = 0, ClientId = Convert.ToInt32(comboBox4.SelectedValue),
ClientName = "Admin", ClientName = comboBox4.Text,
Count = Convert.ToInt32(CountTextBox.Text), Count = Convert.ToInt32(CountTextBox.Text),
Sum = Convert.ToDouble(SumTextBox.Text) Sum = Convert.ToDouble(SumTextBox.Text)
}) ; }) ;
Console.Write(Convert.ToInt32(comboBox4.SelectedValue));
if (!operationResult) if (!operationResult)
{ {

View File

@ -1,4 +1,64 @@
<root> <?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" /> <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">

View File

@ -36,7 +36,7 @@ namespace FoodOrdersView
{ {
dataGridView1.DataSource = list; dataGridView1.DataSource = list;
dataGridView1.Columns["FoodId"].Visible = false; dataGridView1.Columns["FoodId"].Visible = false;
dataGridView1.Columns["ClientId"].Visible = false; dataGridView1.Columns["ClientId"].Visible = true;
} }
_logger.LogInformation("Загрузка заказов"); _logger.LogInformation("Загрузка заказов");