diff --git a/FurnitureAssembly/FurnitureAssembly/FormClients.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormClients.Designer.cs new file mode 100644 index 0000000..647794e --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormClients.Designer.cs @@ -0,0 +1,75 @@ +namespace FurnitureAssembly +{ + 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() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.ButtonDel = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(12, 85); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(559, 453); + this.dataGridView.TabIndex = 6; + // + // ButtonDel + // + this.ButtonDel.Location = new System.Drawing.Point(466, 40); + this.ButtonDel.Name = "ButtonDel"; + this.ButtonDel.Size = new System.Drawing.Size(105, 29); + this.ButtonDel.TabIndex = 11; + this.ButtonDel.Text = "Удалить"; + this.ButtonDel.UseVisualStyleBackColor = true; + this.ButtonDel.Click += new System.EventHandler(this.ButtonDel_Click); + // + // FormClients + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(588, 549); + this.Controls.Add(this.ButtonDel); + this.Controls.Add(this.dataGridView); + this.Name = "FormClients"; + this.Text = "Клиенты"; + this.Load += new System.EventHandler(this.FormClients_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private DataGridView dataGridView; + private Button ButtonDel; + } +} \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormClients.cs b/FurnitureAssembly/FurnitureAssembly/FormClients.cs new file mode 100644 index 0000000..1d18bca --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormClients.cs @@ -0,0 +1,79 @@ +using FurnitureAssemblyContracts.BindingModels; +using FurnitureAssemblyContracts.BusinessLogicsContarcts; +using Microsoft.Extensions.Logging; + + +namespace FurnitureAssembly +{ + public partial class FormClients : Form + { + private readonly ILogger _logger; + private readonly IClientLogic _logic; + public FormClients(ILogger logger, IClientLogic clientLogic) + { + InitializeComponent(); + _logger = logger; + _logic = clientLogic; + } + 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; + dataGridView.Columns["Email"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Password"].Visible = false; + } + _logger.LogInformation("Загрузка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void ButtonDel_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); + _logger.LogInformation("Удаление клиента"); + try + { + if (!_logic.Delete(new ClientBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления клиента"); + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + } +} diff --git a/FurnitureAssembly/FurnitureAssembly/FormClients.resx b/FurnitureAssembly/FurnitureAssembly/FormClients.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/FurnitureAssembly/FurnitureAssembly/FormClients.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.Designer.cs index 781f225..5dd5f53 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.Designer.cs @@ -36,12 +36,14 @@ this.textBoxSum = new System.Windows.Forms.TextBox(); this.ButtonSave = new System.Windows.Forms.Button(); this.ButtonCancel = new System.Windows.Forms.Button(); + this.comboBoxClientEmail = new System.Windows.Forms.ComboBox(); + this.labelClient = new System.Windows.Forms.Label(); this.SuspendLayout(); // // labelFurniture // this.labelFurniture.AutoSize = true; - this.labelFurniture.Location = new System.Drawing.Point(29, 23); + this.labelFurniture.Location = new System.Drawing.Point(28, 53); this.labelFurniture.Name = "labelFurniture"; this.labelFurniture.Size = new System.Drawing.Size(56, 15); this.labelFurniture.TabIndex = 0; @@ -50,7 +52,7 @@ // labelCount // this.labelCount.AutoSize = true; - this.labelCount.Location = new System.Drawing.Point(29, 50); + this.labelCount.Location = new System.Drawing.Point(28, 88); this.labelCount.Name = "labelCount"; this.labelCount.Size = new System.Drawing.Size(75, 15); this.labelCount.TabIndex = 1; @@ -59,7 +61,7 @@ // labelSum // this.labelSum.AutoSize = true; - this.labelSum.Location = new System.Drawing.Point(29, 77); + this.labelSum.Location = new System.Drawing.Point(28, 124); this.labelSum.Name = "labelSum"; this.labelSum.Size = new System.Drawing.Size(45, 15); this.labelSum.TabIndex = 2; @@ -67,7 +69,7 @@ // // textBoxCount // - this.textBoxCount.Location = new System.Drawing.Point(125, 44); + this.textBoxCount.Location = new System.Drawing.Point(124, 85); this.textBoxCount.Name = "textBoxCount"; this.textBoxCount.Size = new System.Drawing.Size(297, 23); this.textBoxCount.TabIndex = 3; @@ -76,7 +78,7 @@ // comboBoxProduct // this.comboBoxProduct.FormattingEnabled = true; - this.comboBoxProduct.Location = new System.Drawing.Point(125, 15); + this.comboBoxProduct.Location = new System.Drawing.Point(124, 50); this.comboBoxProduct.Name = "comboBoxProduct"; this.comboBoxProduct.Size = new System.Drawing.Size(297, 23); this.comboBoxProduct.TabIndex = 4; @@ -84,14 +86,14 @@ // // textBoxSum // - this.textBoxSum.Location = new System.Drawing.Point(125, 77); + this.textBoxSum.Location = new System.Drawing.Point(124, 121); this.textBoxSum.Name = "textBoxSum"; this.textBoxSum.Size = new System.Drawing.Size(297, 23); this.textBoxSum.TabIndex = 5; // // ButtonSave // - this.ButtonSave.Location = new System.Drawing.Point(188, 104); + this.ButtonSave.Location = new System.Drawing.Point(186, 150); this.ButtonSave.Name = "ButtonSave"; this.ButtonSave.Size = new System.Drawing.Size(105, 29); this.ButtonSave.TabIndex = 6; @@ -101,7 +103,7 @@ // // ButtonCancel // - this.ButtonCancel.Location = new System.Drawing.Point(317, 104); + this.ButtonCancel.Location = new System.Drawing.Point(316, 150); this.ButtonCancel.Name = "ButtonCancel"; this.ButtonCancel.Size = new System.Drawing.Size(105, 29); this.ButtonCancel.TabIndex = 7; @@ -109,11 +111,30 @@ this.ButtonCancel.UseVisualStyleBackColor = true; this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // + // comboBoxClientEmail + // + this.comboBoxClientEmail.FormattingEnabled = true; + this.comboBoxClientEmail.Location = new System.Drawing.Point(124, 12); + this.comboBoxClientEmail.Name = "comboBoxClientEmail"; + this.comboBoxClientEmail.Size = new System.Drawing.Size(297, 23); + this.comboBoxClientEmail.TabIndex = 9; + // + // labelClient + // + this.labelClient.AutoSize = true; + this.labelClient.Location = new System.Drawing.Point(28, 15); + this.labelClient.Name = "labelClient"; + this.labelClient.Size = new System.Drawing.Size(49, 15); + this.labelClient.TabIndex = 8; + this.labelClient.Text = "Клиент:"; + // // FormCreateOrder // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(453, 137); + this.ClientSize = new System.Drawing.Size(453, 191); + this.Controls.Add(this.comboBoxClientEmail); + this.Controls.Add(this.labelClient); this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.ButtonSave); this.Controls.Add(this.textBoxSum); @@ -140,5 +161,7 @@ private TextBox textBoxSum; private Button ButtonSave; private Button ButtonCancel; + private ComboBox comboBoxClientEmail; + private Label labelClient; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs index 6810051..cea8fa6 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.cs @@ -21,12 +21,14 @@ namespace FurnitureAssembly private readonly ILogger _logger; private readonly IFurnitureLogic _logicF; private readonly IOrderLogic _logicO; - public FormCreateOrder(ILogger logger, IFurnitureLogic logicF, IOrderLogic logicO) + private readonly IClientLogic _logicC; + public FormCreateOrder(ILogger logger, IFurnitureLogic logicF, IOrderLogic logicO, IClientLogic logicC) { InitializeComponent(); _logger = logger; _logicF = logicF; _logicO = logicO; + _logicC = logicC; } private void ButtonSave_Click(object sender, EventArgs e) @@ -43,6 +45,12 @@ namespace FurnitureAssembly MessageBoxButtons.OK, MessageBoxIcon.Error); return; } + if (comboBoxClientEmail.SelectedValue == null) + { + MessageBox.Show("Выберите клиента", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } _logger.LogInformation("Создание заказа"); try { @@ -50,7 +58,8 @@ namespace FurnitureAssembly { FurnitureId = Convert.ToInt32(comboBoxProduct.SelectedValue), Count = Convert.ToInt32(textBoxCount.Text), - Sum = Convert.ToDouble(textBoxSum.Text) + Sum = Convert.ToDouble(textBoxSum.Text), + ClientId = Convert.ToInt32(comboBoxClientEmail.SelectedValue) }); if (!operationResult) { @@ -71,7 +80,7 @@ namespace FurnitureAssembly private void FormCreateOrder_Load(object sender, EventArgs e) { - _logger.LogInformation("Загрузка изделий для заказа"); + _logger.LogInformation("Загрузка изделий и клиентов для заказа"); // прописать логику LoadData(); } @@ -85,6 +94,14 @@ namespace FurnitureAssembly comboBoxProduct.DataSource = _list; comboBoxProduct.SelectedItem = null; } + var _listCli = _logicC.ReadList(null); + if (_listCli != null) + { + comboBoxClientEmail.DisplayMember = "Email"; // по нему однозначно можно определить клиента + comboBoxClientEmail.ValueMember = "Id"; + comboBoxClientEmail.DataSource = _listCli; + comboBoxClientEmail.SelectedItem = null; + } } diff --git a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.resx b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.resx index c3d80ca..f298a7b 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.resx +++ b/FurnitureAssembly/FurnitureAssembly/FormCreateOrder.resx @@ -57,7 +57,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs index b57bf8a..138b9fa 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.Designer.cs @@ -38,6 +38,7 @@ this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ClientsMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.отчетыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.FurnituresToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.FurnituresComponentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -120,7 +121,8 @@ // this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.компонентыToolStripMenuItem, - this.изделияToolStripMenuItem}); + this.изделияToolStripMenuItem, + this.ClientsMenuItem}); this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.справочникиToolStripMenuItem.Text = "Справочники"; @@ -128,17 +130,24 @@ // компонентыToolStripMenuItem // this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.компонентыToolStripMenuItem.Text = "Компоненты"; this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // // изделияToolStripMenuItem // this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - this.изделияToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.изделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.изделияToolStripMenuItem.Text = "Изделия"; this.изделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // + // ClientsMenuItem + // + this.ClientsMenuItem.Name = "ClientsMenuItem"; + this.ClientsMenuItem.Size = new System.Drawing.Size(180, 22); + this.ClientsMenuItem.Text = "Клиенты"; + this.ClientsMenuItem.Click += new System.EventHandler(this.ClientsMenuItem_Click); + // // отчетыToolStripMenuItem // this.отчетыToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { @@ -152,7 +161,7 @@ // FurnituresToolStripMenuItem // this.FurnituresToolStripMenuItem.Name = "FurnituresToolStripMenuItem"; - this.FurnituresToolStripMenuItem.Size = new System.Drawing.Size(218, 22); + this.FurnituresToolStripMenuItem.Size = new System.Drawing.Size(216, 22); this.FurnituresToolStripMenuItem.Text = "Список изделий"; this.FurnituresToolStripMenuItem.Click += new System.EventHandler(this.FurnituresToolStripMenuItem_Click); // @@ -166,7 +175,7 @@ // списокЗаказовToolStripMenuItem // this.списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem"; - this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(218, 22); + this.списокЗаказовToolStripMenuItem.Size = new System.Drawing.Size(216, 22); this.списокЗаказовToolStripMenuItem.Text = "Список заказов"; this.списокЗаказовToolStripMenuItem.Click += new System.EventHandler(this.OrdersToolStripMenuItem_Click); // @@ -210,5 +219,6 @@ private ToolStripMenuItem FurnituresToolStripMenuItem; private ToolStripMenuItem FurnituresComponentsToolStripMenuItem; private ToolStripMenuItem списокЗаказовToolStripMenuItem; + private ToolStripMenuItem ClientsMenuItem; } } \ No newline at end of file diff --git a/FurnitureAssembly/FurnitureAssembly/FormMain.cs b/FurnitureAssembly/FurnitureAssembly/FormMain.cs index 6657a63..5b2285b 100644 --- a/FurnitureAssembly/FurnitureAssembly/FormMain.cs +++ b/FurnitureAssembly/FurnitureAssembly/FormMain.cs @@ -38,7 +38,8 @@ namespace FurnitureAssembly if (list != null) { dataGridView.DataSource = list; - dataGridView.Columns["FurnitureId"].Visible = false; + dataGridView.Columns["FurnitureId"].Visible = false; + dataGridView.Columns["ClientId"].Visible = false; } _logger.LogInformation("Загрузка заказов"); } @@ -190,5 +191,14 @@ namespace FurnitureAssembly form.ShowDialog(); } } + + private void ClientsMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + } + } } }