diff --git a/JewelryStore/JewerlyStoreView/FormClients.Designer.cs b/JewelryStore/JewerlyStoreView/FormClients.Designer.cs new file mode 100644 index 0000000..51c4599 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormClients.Designer.cs @@ -0,0 +1,93 @@ +namespace JewerlyStoreView +{ + partial class FormClients + { + /// + /// 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); + } + + #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() + { + dataGridView = new DataGridView(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.Window; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(8, 7); + dataGridView.Margin = new Padding(2, 2, 2, 2); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 33; + dataGridView.Size = new Size(435, 260); + dataGridView.TabIndex = 0; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(455, 43); + buttonUpdate.Margin = new Padding(2, 2, 2, 2); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(86, 31); + buttonUpdate.TabIndex = 1; + buttonUpdate.Text = "Обновить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpdate_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(455, 89); + buttonDelete.Margin = new Padding(2, 2, 2, 2); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(86, 32); + buttonDelete.TabIndex = 2; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // FormClients + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(560, 270); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(dataGridView); + Margin = new Padding(2, 2, 2, 2); + Name = "FormClients"; + Text = "Клиенты"; + Load += FormClients_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpdate; + private Button buttonDelete; + } +} \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/FormClients.cs b/JewelryStore/JewerlyStoreView/FormClients.cs new file mode 100644 index 0000000..d047cef --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormClients.cs @@ -0,0 +1,83 @@ +using JewelryStoreContracts.BindingModels; +using JewelryStoreContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace JewerlyStoreView +{ + public partial class FormClients : Form + { + private readonly ILogger _logger; + + private readonly IClientLogic _logic; + public FormClients(ILogger logger, IClientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void ButtonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + try + { + if (!_logic.Delete(new ClientBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + _logger.LogInformation("Удаление клиента"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления клиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void ButtonUpdate_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void FormClients_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/JewelryStore/JewerlyStoreView/FormClients.resx b/JewelryStore/JewerlyStoreView/FormClients.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/JewelryStore/JewerlyStoreView/FormClients.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/FormCreateOrder.Designer.cs b/JewelryStore/JewerlyStoreView/FormCreateOrder.Designer.cs index cca7c25..2741da0 100644 --- a/JewelryStore/JewerlyStoreView/FormCreateOrder.Designer.cs +++ b/JewelryStore/JewerlyStoreView/FormCreateOrder.Designer.cs @@ -36,6 +36,8 @@ textBoxSum = new TextBox(); buttonSave = new Button(); buttonCancel = new Button(); + labelClient = new Label(); + comboBoxClient = new ComboBox(); SuspendLayout(); // // labelJewel @@ -50,7 +52,7 @@ // labelCount // labelCount.AutoSize = true; - labelCount.Location = new Point(12, 45); + labelCount.Location = new Point(12, 79); labelCount.Name = "labelCount"; labelCount.Size = new Size(72, 15); labelCount.TabIndex = 1; @@ -59,7 +61,7 @@ // labelSum // labelSum.AutoSize = true; - labelSum.Location = new Point(12, 72); + labelSum.Location = new Point(12, 106); labelSum.Name = "labelSum"; labelSum.Size = new Size(45, 15); labelSum.TabIndex = 2; @@ -75,7 +77,7 @@ // // textBoxCount // - textBoxCount.Location = new Point(101, 45); + textBoxCount.Location = new Point(101, 79); textBoxCount.Name = "textBoxCount"; textBoxCount.Size = new Size(158, 23); textBoxCount.TabIndex = 4; @@ -83,14 +85,14 @@ // // textBoxSum // - textBoxSum.Location = new Point(101, 74); + textBoxSum.Location = new Point(101, 108); textBoxSum.Name = "textBoxSum"; textBoxSum.Size = new Size(158, 23); textBoxSum.TabIndex = 5; // // buttonSave // - buttonSave.Location = new Point(77, 103); + buttonSave.Location = new Point(77, 137); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(84, 32); buttonSave.TabIndex = 6; @@ -100,7 +102,7 @@ // // buttonCancel // - buttonCancel.Location = new Point(167, 103); + buttonCancel.Location = new Point(167, 137); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(92, 32); buttonCancel.TabIndex = 7; @@ -108,11 +110,30 @@ buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; // + // labelClient + // + labelClient.AutoSize = true; + labelClient.Location = new Point(13, 45); + labelClient.Name = "labelClient"; + labelClient.Size = new Size(46, 15); + labelClient.TabIndex = 8; + labelClient.Text = "Клиент"; + // + // comboBoxClient + // + comboBoxClient.FormattingEnabled = true; + comboBoxClient.Location = new Point(101, 45); + comboBoxClient.Name = "comboBoxClient"; + comboBoxClient.Size = new Size(158, 23); + comboBoxClient.TabIndex = 9; + // // FormCreateOrder // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(286, 166); + ClientSize = new Size(286, 207); + Controls.Add(comboBoxClient); + Controls.Add(labelClient); Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(textBoxSum); @@ -138,5 +159,7 @@ private TextBox textBoxSum; private Button buttonSave; private Button buttonCancel; + private Label labelClient; + private ComboBox comboBoxClient; } } \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/FormCreateOrder.cs b/JewelryStore/JewerlyStoreView/FormCreateOrder.cs index 5dbd9a4..dfeded8 100644 --- a/JewelryStore/JewerlyStoreView/FormCreateOrder.cs +++ b/JewelryStore/JewerlyStoreView/FormCreateOrder.cs @@ -21,14 +21,16 @@ namespace JewelryStoreView private readonly ILogger _logger; private readonly IJewelLogic _logicJ; private readonly IOrderLogic _logicO; + private readonly IClientLogic _logicC; private List? _list; - public FormCreateOrder(ILogger logger, IJewelLogic logicJ, IOrderLogic logicO) + public FormCreateOrder(ILogger logger, IJewelLogic logicJ, IOrderLogic logicO, IClientLogic logicC) { InitializeComponent(); _logger = logger; _logicJ = logicJ; _logicO = logicO; + _logicC = logicC; } private void FormCreateOrder_Load(object sender, EventArgs e) @@ -43,6 +45,24 @@ namespace JewelryStoreView comboBoxJewel.DataSource = _list; comboBoxJewel.SelectedItem = null; } + _logger.LogInformation("Загрузка пользователей для заказа"); + try + { + var list = _logicC.ReadList(null); + if (list != null) + { + comboBoxClient.DisplayMember = "ClientFIO"; + comboBoxClient.ValueMember = "Id"; + comboBoxClient.DataSource = list; + comboBoxClient.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } private void CalcSum() { @@ -91,7 +111,8 @@ namespace JewelryStoreView { JewelId = Convert.ToInt32(comboBoxJewel.SelectedIndex) + 1, Count = Convert.ToInt32(textBoxCount.Text), - Sum = Convert.ToDouble(textBoxSum.Text) + Sum = Convert.ToDouble(textBoxSum.Text), + ClientId = Convert.ToInt32(comboBoxClient.SelectedValue) }); if (!operationResult) { @@ -106,6 +127,11 @@ namespace JewelryStoreView _logger.LogError(ex, "Ошибка создания заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } + if (comboBoxClient.SelectedValue == null) + { + MessageBox.Show("Выберите клиента", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } } private void ComboBoxJewel_SelectedIndexChanged(object sender, EventArgs e) diff --git a/JewelryStore/JewerlyStoreView/FormMain.Designer.cs b/JewelryStore/JewerlyStoreView/FormMain.Designer.cs index 689ed88..0c80b33 100644 --- a/JewelryStore/JewerlyStoreView/FormMain.Designer.cs +++ b/JewelryStore/JewerlyStoreView/FormMain.Designer.cs @@ -34,6 +34,7 @@ компонентыToolStripMenuItem = new ToolStripMenuItem(); изделияToolStripMenuItem = new ToolStripMenuItem(); отчётыToolStripMenuItem = new ToolStripMenuItem(); + клиентыToolStripMenuItem = new ToolStripMenuItem(); списокКомпонентовToolStripMenuItem = new ToolStripMenuItem(); компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem(); списокЗаказовToolStripMenuItem = new ToolStripMenuItem(); @@ -67,7 +68,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, клиентыToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(94, 20); справочникиToolStripMenuItem.Text = "Справочники"; @@ -86,6 +87,13 @@ изделияToolStripMenuItem.Text = "Изделия"; изделияToolStripMenuItem.Click += изделияToolStripMenuItem_Click; // + // клиентыToolStripMenuItem + // + клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem"; + клиентыToolStripMenuItem.Size = new Size(180, 22); + клиентыToolStripMenuItem.Text = "Клиенты"; + клиентыToolStripMenuItem.Click += КлиентыToolStripMenuItem_Click; + // // отчётыToolStripMenuItem // отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокКомпонентовToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem }); @@ -208,5 +216,6 @@ private ToolStripMenuItem списокКомпонентовToolStripMenuItem; private ToolStripMenuItem компонентыПоИзделиямToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; + private ToolStripMenuItem клиентыToolStripMenuItem; } } \ No newline at end of file diff --git a/JewelryStore/JewerlyStoreView/FormMain.cs b/JewelryStore/JewerlyStoreView/FormMain.cs index f739409..5eed8b3 100644 --- a/JewelryStore/JewerlyStoreView/FormMain.cs +++ b/JewelryStore/JewerlyStoreView/FormMain.cs @@ -44,6 +44,7 @@ namespace JewelryStoreView { dataGridView.DataSource = list; dataGridView.Columns["JewelId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); } @@ -75,11 +76,7 @@ namespace JewelryStoreView var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id, - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), }); if (!operationResult) { @@ -106,11 +103,7 @@ namespace JewelryStoreView var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()) + ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), }); if (!operationResult) { @@ -138,11 +131,7 @@ namespace JewelryStoreView var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id, - Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), - Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), - Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), - JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), - DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + ClientId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ClientId"].Value), }); if (!operationResult) { @@ -210,5 +199,13 @@ namespace JewelryStoreView form.ShowDialog(); } } + private void КлиентыToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + } + } } }