diff --git a/FoodOrders/FoodOrderDatabaseImplement/Implements/ClientStorage.cs b/FoodOrders/FoodOrderDatabaseImplement/Implements/ClientStorage.cs index 195629e..12bc5bf 100644 --- a/FoodOrders/FoodOrderDatabaseImplement/Implements/ClientStorage.cs +++ b/FoodOrders/FoodOrderDatabaseImplement/Implements/ClientStorage.cs @@ -63,8 +63,10 @@ namespace FoodOrderDatabaseImplement.Implements return null; } using var context = new FoodOrdersDataBase(); + context.Clients.Add(newClient); context.SaveChanges(); + return newClient.GetViewModel; } public ClientViewModel? Update(ClientBindingModel model) diff --git a/FoodOrders/FoodOrderDatabaseImplement/Migrations/20231122135912_Init.Designer.cs b/FoodOrders/FoodOrderDatabaseImplement/Migrations/20250217133549_InitMigration.Designer.cs similarity index 98% rename from FoodOrders/FoodOrderDatabaseImplement/Migrations/20231122135912_Init.Designer.cs rename to FoodOrders/FoodOrderDatabaseImplement/Migrations/20250217133549_InitMigration.Designer.cs index 0673ceb..3b9dbef 100644 --- a/FoodOrders/FoodOrderDatabaseImplement/Migrations/20231122135912_Init.Designer.cs +++ b/FoodOrders/FoodOrderDatabaseImplement/Migrations/20250217133549_InitMigration.Designer.cs @@ -12,8 +12,8 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace FoodOrderDatabaseImplement.Migrations { [DbContext(typeof(FoodOrdersDataBase))] - [Migration("20231122135912_Init")] - partial class Init + [Migration("20250217133549_InitMigration")] + partial class InitMigration { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -37,7 +37,7 @@ namespace FoodOrderDatabaseImplement.Migrations .IsRequired() .HasColumnType("text"); - b.Property("Login") + b.Property("Email") .IsRequired() .HasColumnType("text"); diff --git a/FoodOrders/FoodOrderDatabaseImplement/Migrations/20231122135912_Init.cs b/FoodOrders/FoodOrderDatabaseImplement/Migrations/20250217133549_InitMigration.cs similarity index 98% rename from FoodOrders/FoodOrderDatabaseImplement/Migrations/20231122135912_Init.cs rename to FoodOrders/FoodOrderDatabaseImplement/Migrations/20250217133549_InitMigration.cs index 67c2fb9..df71891 100644 --- a/FoodOrders/FoodOrderDatabaseImplement/Migrations/20231122135912_Init.cs +++ b/FoodOrders/FoodOrderDatabaseImplement/Migrations/20250217133549_InitMigration.cs @@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace FoodOrderDatabaseImplement.Migrations { /// - public partial class Init : Migration + public partial class InitMigration : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -19,7 +19,7 @@ namespace FoodOrderDatabaseImplement.Migrations Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), ClientFIO = table.Column(type: "text", nullable: false), - Login = table.Column(type: "text", nullable: false), + Email = table.Column(type: "text", nullable: false), Password = table.Column(type: "text", nullable: false) }, constraints: table => diff --git a/FoodOrders/FoodOrderDatabaseImplement/Migrations/FoodOrdersDataBaseModelSnapshot.cs b/FoodOrders/FoodOrderDatabaseImplement/Migrations/FoodOrdersDataBaseModelSnapshot.cs index b622df4..aa0ce0c 100644 --- a/FoodOrders/FoodOrderDatabaseImplement/Migrations/FoodOrdersDataBaseModelSnapshot.cs +++ b/FoodOrders/FoodOrderDatabaseImplement/Migrations/FoodOrdersDataBaseModelSnapshot.cs @@ -34,7 +34,7 @@ namespace FoodOrderDatabaseImplement.Migrations .IsRequired() .HasColumnType("text"); - b.Property("Login") + b.Property("Email") .IsRequired() .HasColumnType("text"); diff --git a/FoodOrders/FoodOrdersView/FormCreateOrder.Designer.cs b/FoodOrders/FoodOrdersView/FormCreateOrder.Designer.cs index 1050915..e6b8c43 100644 --- a/FoodOrders/FoodOrdersView/FormCreateOrder.Designer.cs +++ b/FoodOrders/FoodOrdersView/FormCreateOrder.Designer.cs @@ -20,119 +20,139 @@ base.Dispose(disposing); } - #region Windows Form Designer generated code + #region Windows Form Designer generated code - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - this.WorkNameLabel = new System.Windows.Forms.Label(); - this.CountLabel = new System.Windows.Forms.Label(); - this.SumLabel = new System.Windows.Forms.Label(); - this.FoodComboBox = new System.Windows.Forms.ComboBox(); - this.CountTextBox = new System.Windows.Forms.TextBox(); - this.SumTextBox = new System.Windows.Forms.TextBox(); - this.SaveButton = new System.Windows.Forms.Button(); - this.ButtonCancel = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // WorkNameLabel - // - this.WorkNameLabel.AutoSize = true; - this.WorkNameLabel.Location = new System.Drawing.Point(25, 15); - this.WorkNameLabel.Name = "WorkNameLabel"; - this.WorkNameLabel.Size = new System.Drawing.Size(59, 15); - this.WorkNameLabel.TabIndex = 0; - this.WorkNameLabel.Text = "Изделие: "; - // - // CountLabel - // - this.CountLabel.AutoSize = true; - this.CountLabel.Location = new System.Drawing.Point(25, 44); - this.CountLabel.Name = "CountLabel"; - this.CountLabel.Size = new System.Drawing.Size(78, 15); - this.CountLabel.TabIndex = 1; - this.CountLabel.Text = "Количество: "; - // - // SumLabel - // - this.SumLabel.AutoSize = true; - this.SumLabel.Location = new System.Drawing.Point(25, 76); - this.SumLabel.Name = "SumLabel"; - this.SumLabel.Size = new System.Drawing.Size(51, 15); - this.SumLabel.TabIndex = 2; - this.SumLabel.Text = "Сумма: "; - // - // FoodComboBox - // - this.FoodComboBox.FormattingEnabled = true; - this.FoodComboBox.Location = new System.Drawing.Point(111, 15); - this.FoodComboBox.Name = "FoodComboBox"; - this.FoodComboBox.Size = new System.Drawing.Size(214, 23); - this.FoodComboBox.TabIndex = 4; - this.FoodComboBox.SelectedIndexChanged += new System.EventHandler(this.FoodComboBox_SelectedIndexChanged); - // - // CountTextBox - // - this.CountTextBox.Location = new System.Drawing.Point(111, 44); - this.CountTextBox.Name = "CountTextBox"; - this.CountTextBox.Size = new System.Drawing.Size(214, 23); - this.CountTextBox.TabIndex = 5; - this.CountTextBox.TextChanged += new System.EventHandler(this.CountTextBox_TextChanged); - // - // SumTextBox - // - this.SumTextBox.Enabled = false; - this.SumTextBox.Location = new System.Drawing.Point(111, 73); - this.SumTextBox.Name = "SumTextBox"; - this.SumTextBox.Size = new System.Drawing.Size(214, 23); - this.SumTextBox.TabIndex = 6; - // - // SaveButton - // - this.SaveButton.Location = new System.Drawing.Point(111, 115); - this.SaveButton.Name = "SaveButton"; - this.SaveButton.Size = new System.Drawing.Size(95, 23); - this.SaveButton.TabIndex = 7; - this.SaveButton.Text = "Сохранить"; - this.SaveButton.UseVisualStyleBackColor = true; - this.SaveButton.MouseClick += new System.Windows.Forms.MouseEventHandler(this.SaveButton_Click); - // - // ButtonCancel - // - this.ButtonCancel.Location = new System.Drawing.Point(230, 115); - this.ButtonCancel.Name = "ButtonCancel"; - this.ButtonCancel.Size = new System.Drawing.Size(95, 23); - this.ButtonCancel.TabIndex = 8; - this.ButtonCancel.Text = "Отменить"; - this.ButtonCancel.UseVisualStyleBackColor = true; - this.ButtonCancel.MouseClick += new System.Windows.Forms.MouseEventHandler(this.ButtonCancel_Click); - // - // FormCreateOrder - // - this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(350, 146); - this.Controls.Add(this.ButtonCancel); - this.Controls.Add(this.SaveButton); - this.Controls.Add(this.SumTextBox); - this.Controls.Add(this.CountTextBox); - this.Controls.Add(this.FoodComboBox); - this.Controls.Add(this.SumLabel); - this.Controls.Add(this.CountLabel); - this.Controls.Add(this.WorkNameLabel); - this.Name = "FormCreateOrder"; - this.Text = "Заказ"; - this.ResumeLayout(false); - this.PerformLayout(); + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + WorkNameLabel = new Label(); + CountLabel = new Label(); + SumLabel = new Label(); + FoodComboBox = new ComboBox(); + CountTextBox = new TextBox(); + SumTextBox = new TextBox(); + SaveButton = new Button(); + ButtonCancel = new Button(); + comboBox4 = new ComboBox(); + label1 = new Label(); + SuspendLayout(); + // + // WorkNameLabel + // + WorkNameLabel.AutoSize = true; + WorkNameLabel.Location = new Point(25, 15); + WorkNameLabel.Name = "WorkNameLabel"; + WorkNameLabel.Size = new Size(59, 15); + WorkNameLabel.TabIndex = 0; + WorkNameLabel.Text = "Изделие: "; + // + // CountLabel + // + CountLabel.AutoSize = true; + CountLabel.Location = new Point(25, 44); + CountLabel.Name = "CountLabel"; + CountLabel.Size = new Size(78, 15); + CountLabel.TabIndex = 1; + CountLabel.Text = "Количество: "; + // + // SumLabel + // + SumLabel.AutoSize = true; + SumLabel.Location = new Point(25, 76); + SumLabel.Name = "SumLabel"; + SumLabel.Size = new Size(51, 15); + SumLabel.TabIndex = 2; + SumLabel.Text = "Сумма: "; + // + // FoodComboBox + // + FoodComboBox.FormattingEnabled = true; + FoodComboBox.Location = new Point(111, 15); + FoodComboBox.Name = "FoodComboBox"; + FoodComboBox.Size = new Size(214, 23); + FoodComboBox.TabIndex = 4; + FoodComboBox.SelectedIndexChanged += FoodComboBox_SelectedIndexChanged; + // + // CountTextBox + // + CountTextBox.Location = new Point(111, 44); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(214, 23); + CountTextBox.TabIndex = 5; + CountTextBox.TextChanged += CountTextBox_TextChanged; + // + // SumTextBox + // + SumTextBox.Enabled = false; + SumTextBox.Location = new Point(111, 73); + SumTextBox.Name = "SumTextBox"; + SumTextBox.Size = new Size(214, 23); + SumTextBox.TabIndex = 6; + // + // SaveButton + // + SaveButton.Location = new Point(111, 178); + SaveButton.Name = "SaveButton"; + SaveButton.Size = new Size(95, 23); + SaveButton.TabIndex = 7; + SaveButton.Text = "Сохранить"; + SaveButton.UseVisualStyleBackColor = true; + SaveButton.MouseClick += SaveButton_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(230, 178); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(95, 23); + ButtonCancel.TabIndex = 8; + ButtonCancel.Text = "Отменить"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.MouseClick += ButtonCancel_Click; + // + // comboBox4 + // + comboBox4.FormattingEnabled = true; + comboBox4.Location = new Point(111, 102); + comboBox4.Name = "comboBox4"; + comboBox4.Size = new Size(214, 23); + comboBox4.TabIndex = 10; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(25, 102); + label1.Name = "label1"; + label1.Size = new Size(52, 15); + 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 SumLabel; private ComboBox FoodComboBox; @@ -140,5 +160,7 @@ private TextBox SumTextBox; private Button SaveButton; private Button ButtonCancel; - } + private ComboBox comboBox4; + private Label label1; + } } \ No newline at end of file diff --git a/FoodOrders/FoodOrdersView/FormCreateOrder.cs b/FoodOrders/FoodOrdersView/FormCreateOrder.cs index 06dd858..030cc7b 100644 --- a/FoodOrders/FoodOrdersView/FormCreateOrder.cs +++ b/FoodOrders/FoodOrdersView/FormCreateOrder.cs @@ -8,6 +8,7 @@ using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; +using System.Runtime.ConstrainedExecution; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; @@ -19,14 +20,17 @@ namespace FoodOrdersView private readonly ILogger _logger; private readonly IFoodLogic _logicW; private readonly IOrderLogic _logicO; + private readonly IClientLogic _logicC; - public FormCreateOrder(ILogger logger, IFoodLogic logicF, IOrderLogic logicO) + public FormCreateOrder(ILogger logger, IFoodLogic logicF, IOrderLogic logicO, IClientLogic logicC) { InitializeComponent(); _logger = logger; _logicW = logicF; _logicO = logicO; - LoadData(); + _logicC = logicC; + + LoadData(); } private void FormCreateOrder_Load(object sender, EventArgs e) @@ -55,7 +59,24 @@ namespace FoodOrdersView _logger.LogError(ex, "Ошибка загрузки списка изделий"); 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() { @@ -114,11 +135,12 @@ namespace FoodOrdersView { FoodId = Convert.ToInt32(FoodComboBox.SelectedValue), FoodName = FoodComboBox.Text, - ClientId = 0, - ClientName = "Admin", + ClientId = Convert.ToInt32(comboBox4.SelectedValue), + ClientName = comboBox4.Text, Count = Convert.ToInt32(CountTextBox.Text), Sum = Convert.ToDouble(SumTextBox.Text) }) ; + Console.Write(Convert.ToInt32(comboBox4.SelectedValue)); if (!operationResult) { diff --git a/FoodOrders/FoodOrdersView/FormCreateOrder.resx b/FoodOrders/FoodOrdersView/FormCreateOrder.resx index f298a7b..af32865 100644 --- a/FoodOrders/FoodOrdersView/FormCreateOrder.resx +++ b/FoodOrders/FoodOrdersView/FormCreateOrder.resx @@ -1,4 +1,64 @@ - + + + diff --git a/FoodOrders/FoodOrdersView/FormMain.cs b/FoodOrders/FoodOrdersView/FormMain.cs index 435966f..2115ef7 100644 --- a/FoodOrders/FoodOrdersView/FormMain.cs +++ b/FoodOrders/FoodOrdersView/FormMain.cs @@ -36,7 +36,7 @@ namespace FoodOrdersView { dataGridView1.DataSource = list; dataGridView1.Columns["FoodId"].Visible = false; - dataGridView1.Columns["ClientId"].Visible = false; + dataGridView1.Columns["ClientId"].Visible = true; } _logger.LogInformation("Загрузка заказов");