From dca942c65da3e559b3d3210e7bfb4e80cf2b5892 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B8=D0=BD=D0=B0?= <Алина@DESKTOP-PH8VQJA> Date: Tue, 16 Apr 2024 23:10:53 +0400 Subject: [PATCH] =?UTF-8?q?formclienteorder=20=D1=81=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B0=D0=BB=20=D1=81=D0=B2=D0=BE=D1=91=20=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... 20240416174343_InitialCreate.Designer.cs} | 45 ++- ...ate.cs => 20240416174343_InitialCreate.cs} | 30 ++ .../TypographyDatabaseModelSnapshot.cs | 43 +++ Typography/TypographyRestApi/Program.cs | 1 - .../FormCreateOrder.Designer.cs | 298 ++++++++++-------- Typography/TypographyView/FormCreateOrder.cs | 208 ++++++------ 6 files changed, 390 insertions(+), 235 deletions(-) rename Typography/TypographyDatabaseImplement/Migrations/{20240416091109_InitialCreate.Designer.cs => 20240416174343_InitialCreate.Designer.cs} (82%) rename Typography/TypographyDatabaseImplement/Migrations/{20240416091109_InitialCreate.cs => 20240416174343_InitialCreate.cs} (82%) diff --git a/Typography/TypographyDatabaseImplement/Migrations/20240416091109_InitialCreate.Designer.cs b/Typography/TypographyDatabaseImplement/Migrations/20240416174343_InitialCreate.Designer.cs similarity index 82% rename from Typography/TypographyDatabaseImplement/Migrations/20240416091109_InitialCreate.Designer.cs rename to Typography/TypographyDatabaseImplement/Migrations/20240416174343_InitialCreate.Designer.cs index d1e71de..9bd109c 100644 --- a/Typography/TypographyDatabaseImplement/Migrations/20240416091109_InitialCreate.Designer.cs +++ b/Typography/TypographyDatabaseImplement/Migrations/20240416174343_InitialCreate.Designer.cs @@ -12,7 +12,7 @@ using TypographyDatabaseImplement; namespace TypographyDatabaseImplement.Migrations { [DbContext(typeof(TypographyDatabase))] - [Migration("20240416091109_InitialCreate")] + [Migration("20240416174343_InitialCreate")] partial class InitialCreate { /// @@ -70,6 +70,33 @@ namespace TypographyDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("TypographyDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("TypographyDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -90,6 +117,9 @@ namespace TypographyDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("PrintedId") .HasColumnType("int"); @@ -103,6 +133,8 @@ namespace TypographyDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("PrintedId"); b.ToTable("Orders"); @@ -162,6 +194,10 @@ namespace TypographyDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("TypographyDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("ImplementerOrders") + .HasForeignKey("ImplementerId"); + b.HasOne("TypographyDatabaseImplement.Models.Printed", "Printed") .WithMany("Orders") .HasForeignKey("PrintedId") @@ -170,6 +206,8 @@ namespace TypographyDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Printed"); }); @@ -202,6 +240,11 @@ namespace TypographyDatabaseImplement.Migrations b.Navigation("PrintedComponents"); }); + modelBuilder.Entity("TypographyDatabaseImplement.Models.Implementer", b => + { + b.Navigation("ImplementerOrders"); + }); + modelBuilder.Entity("TypographyDatabaseImplement.Models.Printed", b => { b.Navigation("Components"); diff --git a/Typography/TypographyDatabaseImplement/Migrations/20240416091109_InitialCreate.cs b/Typography/TypographyDatabaseImplement/Migrations/20240416174343_InitialCreate.cs similarity index 82% rename from Typography/TypographyDatabaseImplement/Migrations/20240416091109_InitialCreate.cs rename to Typography/TypographyDatabaseImplement/Migrations/20240416174343_InitialCreate.cs index d0d7492..42c4492 100644 --- a/Typography/TypographyDatabaseImplement/Migrations/20240416091109_InitialCreate.cs +++ b/Typography/TypographyDatabaseImplement/Migrations/20240416174343_InitialCreate.cs @@ -40,6 +40,22 @@ namespace TypographyDatabaseImplement.Migrations table.PrimaryKey("PK_Components", x => x.Id); }); + migrationBuilder.CreateTable( + name: "Implementers", + columns: table => new + { + Id = table.Column(type: "int", nullable: false) + .Annotation("SqlServer:Identity", "1, 1"), + ImplementerFIO = table.Column(type: "nvarchar(max)", nullable: false), + Password = table.Column(type: "nvarchar(max)", nullable: false), + WorkExperience = table.Column(type: "int", nullable: false), + Qualification = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Implementers", x => x.Id); + }); + migrationBuilder.CreateTable( name: "Printeds", columns: table => new @@ -61,6 +77,7 @@ namespace TypographyDatabaseImplement.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), ClientId = table.Column(type: "int", nullable: false), + ImplementerId = table.Column(type: "int", nullable: true), PrintedId = table.Column(type: "int", nullable: false), Count = table.Column(type: "int", nullable: false), Sum = table.Column(type: "float", nullable: false), @@ -77,6 +94,11 @@ namespace TypographyDatabaseImplement.Migrations principalTable: "Clients", principalColumn: "Id", onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_Orders_Implementers_ImplementerId", + column: x => x.ImplementerId, + principalTable: "Implementers", + principalColumn: "Id"); table.ForeignKey( name: "FK_Orders_Printeds_PrintedId", column: x => x.PrintedId, @@ -117,6 +139,11 @@ namespace TypographyDatabaseImplement.Migrations table: "Orders", column: "ClientId"); + migrationBuilder.CreateIndex( + name: "IX_Orders_ImplementerId", + table: "Orders", + column: "ImplementerId"); + migrationBuilder.CreateIndex( name: "IX_Orders_PrintedId", table: "Orders", @@ -145,6 +172,9 @@ namespace TypographyDatabaseImplement.Migrations migrationBuilder.DropTable( name: "Clients"); + migrationBuilder.DropTable( + name: "Implementers"); + migrationBuilder.DropTable( name: "Components"); diff --git a/Typography/TypographyDatabaseImplement/Migrations/TypographyDatabaseModelSnapshot.cs b/Typography/TypographyDatabaseImplement/Migrations/TypographyDatabaseModelSnapshot.cs index cc7d7f1..16842c9 100644 --- a/Typography/TypographyDatabaseImplement/Migrations/TypographyDatabaseModelSnapshot.cs +++ b/Typography/TypographyDatabaseImplement/Migrations/TypographyDatabaseModelSnapshot.cs @@ -67,6 +67,33 @@ namespace TypographyDatabaseImplement.Migrations b.ToTable("Components"); }); + modelBuilder.Entity("TypographyDatabaseImplement.Models.Implementer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("int"); + + SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + + b.Property("ImplementerFIO") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Password") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.Property("Qualification") + .HasColumnType("int"); + + b.Property("WorkExperience") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.ToTable("Implementers"); + }); + modelBuilder.Entity("TypographyDatabaseImplement.Models.Order", b => { b.Property("Id") @@ -87,6 +114,9 @@ namespace TypographyDatabaseImplement.Migrations b.Property("DateImplement") .HasColumnType("datetime2"); + b.Property("ImplementerId") + .HasColumnType("int"); + b.Property("PrintedId") .HasColumnType("int"); @@ -100,6 +130,8 @@ namespace TypographyDatabaseImplement.Migrations b.HasIndex("ClientId"); + b.HasIndex("ImplementerId"); + b.HasIndex("PrintedId"); b.ToTable("Orders"); @@ -159,6 +191,10 @@ namespace TypographyDatabaseImplement.Migrations .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + b.HasOne("TypographyDatabaseImplement.Models.Implementer", "Implementer") + .WithMany("ImplementerOrders") + .HasForeignKey("ImplementerId"); + b.HasOne("TypographyDatabaseImplement.Models.Printed", "Printed") .WithMany("Orders") .HasForeignKey("PrintedId") @@ -167,6 +203,8 @@ namespace TypographyDatabaseImplement.Migrations b.Navigation("Client"); + b.Navigation("Implementer"); + b.Navigation("Printed"); }); @@ -199,6 +237,11 @@ namespace TypographyDatabaseImplement.Migrations b.Navigation("PrintedComponents"); }); + modelBuilder.Entity("TypographyDatabaseImplement.Models.Implementer", b => + { + b.Navigation("ImplementerOrders"); + }); + modelBuilder.Entity("TypographyDatabaseImplement.Models.Printed", b => { b.Navigation("Components"); diff --git a/Typography/TypographyRestApi/Program.cs b/Typography/TypographyRestApi/Program.cs index 16dae25..333a82a 100644 --- a/Typography/TypographyRestApi/Program.cs +++ b/Typography/TypographyRestApi/Program.cs @@ -44,4 +44,3 @@ app.UseAuthorization(); app.MapControllers(); app.Run(); - diff --git a/Typography/TypographyView/FormCreateOrder.Designer.cs b/Typography/TypographyView/FormCreateOrder.Designer.cs index 7bca9c4..8c3690a 100644 --- a/Typography/TypographyView/FormCreateOrder.Designer.cs +++ b/Typography/TypographyView/FormCreateOrder.Designer.cs @@ -1,146 +1,168 @@ namespace TypographyView { - partial class FormCreateOrder - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; + partial class FormCreateOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + 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.labelPrinted = new System.Windows.Forms.Label(); - this.labelCount = new System.Windows.Forms.Label(); - this.labelSum = new System.Windows.Forms.Label(); - this.comboBoxPrinted = new System.Windows.Forms.ComboBox(); - this.textBoxCount = new System.Windows.Forms.TextBox(); - this.textBoxSum = new System.Windows.Forms.TextBox(); - this.buttonSave = new System.Windows.Forms.Button(); - this.buttonCancel = new System.Windows.Forms.Button(); - this.SuspendLayout(); - // - // labelPrinted - // - this.labelPrinted.AutoSize = true; - this.labelPrinted.Location = new System.Drawing.Point(12, 15); - this.labelPrinted.Name = "labelPrinted"; - this.labelPrinted.Size = new System.Drawing.Size(154, 20); - this.labelPrinted.TabIndex = 0; - this.labelPrinted.Text = "Печатная продукция"; - // - // labelCount - // - this.labelCount.AutoSize = true; - this.labelCount.Location = new System.Drawing.Point(12, 49); - this.labelCount.Name = "labelCount"; - this.labelCount.Size = new System.Drawing.Size(90, 20); - this.labelCount.TabIndex = 1; - this.labelCount.Text = "Количество"; - // - // labelSum - // - this.labelSum.AutoSize = true; - this.labelSum.Location = new System.Drawing.Point(12, 82); - this.labelSum.Name = "labelSum"; - this.labelSum.Size = new System.Drawing.Size(55, 20); - this.labelSum.TabIndex = 2; - this.labelSum.Text = "Сумма"; - // - // comboBoxPrinted - // - this.comboBoxPrinted.FormattingEnabled = true; - this.comboBoxPrinted.Location = new System.Drawing.Point(172, 12); - this.comboBoxPrinted.Name = "comboBoxPrinted"; - this.comboBoxPrinted.Size = new System.Drawing.Size(240, 28); - this.comboBoxPrinted.TabIndex = 3; - this.comboBoxPrinted.SelectedIndexChanged += new System.EventHandler(this.ComboBoxPrinted_SelectedIndexChanged); - // - // textBoxCount - // - this.textBoxCount.Location = new System.Drawing.Point(172, 46); - this.textBoxCount.Name = "textBoxCount"; - this.textBoxCount.Size = new System.Drawing.Size(240, 27); - this.textBoxCount.TabIndex = 4; - this.textBoxCount.TextChanged += new System.EventHandler(this.TextBoxCount_TextChanged); - // - // textBoxSum - // - this.textBoxSum.Location = new System.Drawing.Point(172, 79); - this.textBoxSum.Name = "textBoxSum"; - this.textBoxSum.ReadOnly = true; - this.textBoxSum.Size = new System.Drawing.Size(240, 27); - this.textBoxSum.TabIndex = 5; - // - // buttonSave - // - this.buttonSave.Location = new System.Drawing.Point(202, 112); - this.buttonSave.Name = "buttonSave"; - this.buttonSave.Size = new System.Drawing.Size(102, 29); - this.buttonSave.TabIndex = 6; - this.buttonSave.Text = "Сохранить"; - this.buttonSave.UseVisualStyleBackColor = true; - this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click); - // - // buttonCancel - // - this.buttonCancel.Location = new System.Drawing.Point(310, 112); - this.buttonCancel.Name = "buttonCancel"; - this.buttonCancel.Size = new System.Drawing.Size(102, 29); - this.buttonCancel.TabIndex = 7; - this.buttonCancel.Text = "Отмена"; - this.buttonCancel.UseVisualStyleBackColor = true; - this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); - // - // FormCreateOrder - // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(427, 153); - this.Controls.Add(this.buttonCancel); - this.Controls.Add(this.buttonSave); - this.Controls.Add(this.textBoxSum); - this.Controls.Add(this.textBoxCount); - this.Controls.Add(this.comboBoxPrinted); - this.Controls.Add(this.labelSum); - this.Controls.Add(this.labelCount); - this.Controls.Add(this.labelPrinted); - this.Name = "FormCreateOrder"; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Заказ"; - this.Load += new System.EventHandler(this.FormCreateOrder_Load); - 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() + { + labelPrinted = new Label(); + labelCount = new Label(); + labelSum = new Label(); + comboBoxPrinted = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + labelClient = new Label(); + comboBoxClient = new ComboBox(); + SuspendLayout(); + // + // labelPrinted + // + labelPrinted.AutoSize = true; + labelPrinted.Location = new Point(15, 50); + labelPrinted.Name = "labelPrinted"; + labelPrinted.Size = new Size(154, 20); + labelPrinted.TabIndex = 0; + labelPrinted.Text = "Печатная продукция"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(15, 84); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(90, 20); + labelCount.TabIndex = 1; + labelCount.Text = "Количество"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(15, 117); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(55, 20); + labelSum.TabIndex = 2; + labelSum.Text = "Сумма"; + // + // comboBoxPrinted + // + comboBoxPrinted.FormattingEnabled = true; + comboBoxPrinted.Location = new Point(175, 47); + comboBoxPrinted.Name = "comboBoxPrinted"; + comboBoxPrinted.Size = new Size(240, 28); + comboBoxPrinted.TabIndex = 3; + comboBoxPrinted.SelectedIndexChanged += ComboBoxPrinted_SelectedIndexChanged; + // + // textBoxCount + // + textBoxCount.Location = new Point(175, 81); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(240, 27); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(175, 114); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(240, 27); + textBoxSum.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(205, 147); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(102, 29); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(313, 147); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(102, 29); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // labelClient + // + labelClient.AutoSize = true; + labelClient.Location = new Point(15, 15); + labelClient.Name = "labelClient"; + labelClient.Size = new Size(58, 20); + labelClient.TabIndex = 8; + labelClient.Text = "Клиент"; + // + // comboBoxClient + // + comboBoxClient.FormattingEnabled = true; + comboBoxClient.Location = new Point(175, 12); + comboBoxClient.Name = "comboBoxClient"; + comboBoxClient.Size = new Size(240, 28); + comboBoxClient.TabIndex = 9; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(427, 183); + Controls.Add(comboBoxClient); + Controls.Add(labelClient); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxPrinted); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelPrinted); + Name = "FormCreateOrder"; + StartPosition = FormStartPosition.CenterParent; + Text = "Заказ"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } - } + #endregion - #endregion - - private Label labelPrinted; - private Label labelCount; - private Label labelSum; - private ComboBox comboBoxPrinted; - private TextBox textBoxCount; - private TextBox textBoxSum; - private Button buttonSave; - private Button buttonCancel; - } + private Label labelPrinted; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxPrinted; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + private Label labelClient; + private ComboBox comboBoxClient; + } } \ No newline at end of file diff --git a/Typography/TypographyView/FormCreateOrder.cs b/Typography/TypographyView/FormCreateOrder.cs index 7a34f43..8b600ca 100644 --- a/Typography/TypographyView/FormCreateOrder.cs +++ b/Typography/TypographyView/FormCreateOrder.cs @@ -5,106 +5,124 @@ using Microsoft.Extensions.Logging; namespace TypographyView { - public partial class FormCreateOrder : Form - { - private readonly ILogger _logger; - private readonly IPrintedLogic _logicP; - private readonly IOrderLogic _logicO; + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly IClientLogic _logicC; + private readonly IPrintedLogic _logicP; + private readonly IOrderLogic _logicO; - public FormCreateOrder(ILogger logger, IPrintedLogic logicP, IOrderLogic logicO) - { - InitializeComponent(); - _logger = logger; - _logicP = logicP; - _logicO = logicO; - } + public FormCreateOrder(ILogger logger, IClientLogic logicC, IPrintedLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logicC = logicC; + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } - private void FormCreateOrder_Load(object sender, EventArgs e) - { - _logger.LogInformation("Загрузка изделий для заказа"); - var _list = _logicP.ReadList(null); - if (_list != null) - { - comboBoxPrinted.DisplayMember = "PrintedName"; - comboBoxPrinted.ValueMember = "Id"; - comboBoxPrinted.DataSource = _list; - comboBoxPrinted.SelectedItem = null; - } - } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка клиентов для заказа"); + var _listC = _logicC.ReadList(null); + if (_listC != null) + { + comboBoxClient.DisplayMember = "ClientFIO"; + comboBoxClient.ValueMember = "Id"; + comboBoxClient.DataSource = _listC; + comboBoxClient.SelectedItem = null; + } - private void CalcSum() - { - if (comboBoxPrinted.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) - { - try - { - int id = Convert.ToInt32(comboBoxPrinted.SelectedValue); - var product = _logicP.ReadElement(new PrintedSearchModel - { - Id = id - }); - int count = Convert.ToInt32(textBoxCount.Text); - textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); - _logger.LogInformation("Расчет суммы заказа"); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка расчета суммы заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - } + _logger.LogInformation("Загрузка изделий для заказа"); + var _list = _logicP.ReadList(null); + if (_list != null) + { + comboBoxPrinted.DisplayMember = "PrintedName"; + comboBoxPrinted.ValueMember = "Id"; + comboBoxPrinted.DataSource = _list; + comboBoxPrinted.SelectedItem = null; + } + } - private void ComboBoxPrinted_SelectedIndexChanged(object sender, EventArgs e) - { - CalcSum(); - } + private void CalcSum() + { + if (comboBoxPrinted.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxPrinted.SelectedValue); + var product = _logicP.ReadElement(new PrintedSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Расчет суммы заказа"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка расчета суммы заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } - private void TextBoxCount_TextChanged(object sender, EventArgs e) - { - CalcSum(); - } + private void ComboBoxPrinted_SelectedIndexChanged(object sender, EventArgs e) + { + CalcSum(); + } - private void ButtonSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxCount.Text)) - { - MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (comboBoxPrinted.SelectedValue == null) - { - MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation("Создание заказа"); - try - { - var operationResult = _logicO.CreateOrder(new OrderBindingModel - { - PrintedId = Convert.ToInt32(comboBoxPrinted.SelectedValue), - Count = Convert.ToInt32(textBoxCount.Text), - Sum = Convert.ToDouble(textBoxSum.Text) - }); - if (!operationResult) - { - throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); - } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - DialogResult = DialogResult.OK; - Close(); - } - catch (Exception ex) - { - _logger.LogError(ex, "Ошибка создания заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } + private void TextBoxCount_TextChanged(object sender, EventArgs e) + { + CalcSum(); + } - private void ButtonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxClient.SelectedValue == null) + { + MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPrinted.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + ClientId = Convert.ToInt32(comboBoxClient.SelectedValue), + PrintedId = Convert.ToInt32(comboBoxPrinted.SelectedValue), + Count = Convert.ToInt32(textBoxCount.Text), + Sum = Convert.ToDouble(textBoxSum.Text) + }); + if (!operationResult) + { + throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } } \ No newline at end of file