From 9c140589450c08ca1ff6e6007cf01b352d403507 Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Sun, 7 Apr 2024 14:27:09 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D1=83=D1=87=D1=88=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ProjectFlowerShop/FormCreateOrder.Designer.cs | 33 ++++++++++++++++--- ProjectFlowerShop/FormCreateOrder.cs | 33 +++++++++++++++++-- ProjectFlowerShop/Program.cs | 2 ++ 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/ProjectFlowerShop/FormCreateOrder.Designer.cs b/ProjectFlowerShop/FormCreateOrder.Designer.cs index ba89839..6ddfe7d 100644 --- a/ProjectFlowerShop/FormCreateOrder.Designer.cs +++ b/ProjectFlowerShop/FormCreateOrder.Designer.cs @@ -36,6 +36,8 @@ textBoxCount = new TextBox(); comboBoxProduct = new ComboBox(); textBoxSum = new TextBox(); + comboBoxClient = new ComboBox(); + labelClient = new Label(); SuspendLayout(); // // labelProduct @@ -59,7 +61,7 @@ // LabelSum // LabelSum.AutoSize = true; - LabelSum.Location = new Point(12, 113); + LabelSum.Location = new Point(15, 159); LabelSum.Name = "LabelSum"; LabelSum.Size = new Size(55, 20); LabelSum.TabIndex = 2; @@ -67,7 +69,7 @@ // // buttonSave // - buttonSave.Location = new Point(292, 158); + buttonSave.Location = new Point(295, 222); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(94, 29); buttonSave.TabIndex = 3; @@ -77,7 +79,7 @@ // // buttonCancel // - buttonCancel.Location = new Point(411, 158); + buttonCancel.Location = new Point(408, 222); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(94, 29); buttonCancel.TabIndex = 4; @@ -104,18 +106,37 @@ // // textBoxSum // - textBoxSum.Location = new Point(97, 110); + textBoxSum.Location = new Point(97, 156); textBoxSum.Name = "textBoxSum"; textBoxSum.ReadOnly = true; textBoxSum.Size = new Size(274, 27); textBoxSum.TabIndex = 7; textBoxSum.TextChanged += textBox2_TextChanged; // + // comboBoxClient + // + comboBoxClient.FormattingEnabled = true; + comboBoxClient.Location = new Point(97, 112); + comboBoxClient.Name = "comboBoxClient"; + comboBoxClient.Size = new Size(274, 28); + comboBoxClient.TabIndex = 8; + // + // labelClient + // + labelClient.AutoSize = true; + labelClient.Location = new Point(12, 115); + labelClient.Name = "labelClient"; + labelClient.Size = new Size(58, 20); + labelClient.TabIndex = 9; + labelClient.Text = "Кол-во"; + // // FormCreateOrder // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(514, 199); + ClientSize = new Size(514, 263); + Controls.Add(labelClient); + Controls.Add(comboBoxClient); Controls.Add(textBoxSum); Controls.Add(comboBoxProduct); Controls.Add(textBoxCount); @@ -141,5 +162,7 @@ private TextBox textBoxCount; private ComboBox comboBoxProduct; private TextBox textBoxSum; + private ComboBox comboBoxClient; + private Label labelClient; } } \ No newline at end of file diff --git a/ProjectFlowerShop/FormCreateOrder.cs b/ProjectFlowerShop/FormCreateOrder.cs index 10bd326..930fd17 100644 --- a/ProjectFlowerShop/FormCreateOrder.cs +++ b/ProjectFlowerShop/FormCreateOrder.cs @@ -20,13 +20,15 @@ namespace ProjectFlowerShop private readonly ILogger _logger; private readonly IFlowerLogic _logicF; private readonly IOrderLogic _logicO; + private readonly IClientLogic _logicC; - public FormCreateOrder(ILogger logger, IFlowerLogic logicP, IOrderLogic logicO) + public FormCreateOrder(ILogger logger, IFlowerLogic logicP, IOrderLogic logicO, IClientLogic logicC) { InitializeComponent(); _logger = logger; _logicF = logicP; _logicO = logicO; + _logicC = logicC; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) @@ -64,6 +66,26 @@ namespace ProjectFlowerShop _logger.LogError(ex, "Ошибка загрузки цветов"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } + + _logger.LogInformation("Загрузка клиентов для заказа"); + try + { + var list = _logicC.ReadList(null); + if (list != null) + { + comboBoxClient.DisplayMember = "ClientFIO"; + comboBoxClient.ValueMember = "Id"; + comboBoxClient.DataSource = list; + comboBoxClient.SelectedItem = null; + } + _logger.LogInformation("Клиенты загружены"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } } private void CalcSum() @@ -106,6 +128,12 @@ namespace ProjectFlowerShop MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (comboBoxClient.SelectedValue == null) + { + MessageBox.Show("Выберите клиента", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Создание заказа"); try { @@ -113,7 +141,8 @@ namespace ProjectFlowerShop { FlowerId = Convert.ToInt32(comboBoxProduct.SelectedValue), Count = Convert.ToInt32(textBoxCount.Text), - Sum = Convert.ToDouble(textBoxSum.Text) + Sum = Convert.ToDouble(textBoxSum.Text), + ClientId = Convert.ToInt32(comboBoxClient.SelectedValue), }); if (!operationResult) { diff --git a/ProjectFlowerShop/Program.cs b/ProjectFlowerShop/Program.cs index ed336d3..8396548 100644 --- a/ProjectFlowerShop/Program.cs +++ b/ProjectFlowerShop/Program.cs @@ -40,10 +40,12 @@ namespace ProjectFlowerShop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient();