diff --git a/RenovationWork/RenovationWork/FormMain.Designer.cs b/RenovationWork/RenovationWork/FormMain.Designer.cs index 39b0859..7e46eda 100644 --- a/RenovationWork/RenovationWork/FormMain.Designer.cs +++ b/RenovationWork/RenovationWork/FormMain.Designer.cs @@ -32,14 +32,14 @@ refbooksToolStripMenuItem = new ToolStripMenuItem(); componentsToolStripMenuItem = new ToolStripMenuItem(); JobTypeToolStripMenuItem = new ToolStripMenuItem(); - dataGridView1 = new DataGridView(); - button1 = new Button(); - button2 = new Button(); - button3 = new Button(); - button4 = new Button(); - button5 = new Button(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); menuStrip.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // // menuStrip @@ -47,7 +47,7 @@ menuStrip.Items.AddRange(new ToolStripItem[] { refbooksToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(809, 24); + menuStrip.Size = new Size(984, 24); menuStrip.TabIndex = 0; menuStrip.Text = "menuStrip1"; // @@ -61,88 +61,96 @@ // componentsToolStripMenuItem // componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; - componentsToolStripMenuItem.Size = new Size(180, 22); + componentsToolStripMenuItem.Size = new Size(145, 22); componentsToolStripMenuItem.Text = "Компоненты"; + componentsToolStripMenuItem.Click += componentsToolStripMenuItem_Click; // // JobTypeToolStripMenuItem // JobTypeToolStripMenuItem.Name = "JobTypeToolStripMenuItem"; - JobTypeToolStripMenuItem.Size = new Size(180, 22); + JobTypeToolStripMenuItem.Size = new Size(145, 22); JobTypeToolStripMenuItem.Text = "Вид работы"; + JobTypeToolStripMenuItem.Click += JobTypeToolStripMenuItem_Click; // - // dataGridView1 + // dataGridView // - dataGridView1.BackgroundColor = SystemColors.ControlLightLight; - dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView1.Location = new Point(12, 27); - dataGridView1.Name = "dataGridView1"; - dataGridView1.RowTemplate.Height = 25; - dataGridView1.Size = new Size(654, 331); - dataGridView1.TabIndex = 1; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 27); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(797, 341); + dataGridView.TabIndex = 1; // - // button1 + // buttonCreateOrder // - button1.Location = new Point(672, 42); - button1.Name = "button1"; - button1.Size = new Size(128, 23); - button1.TabIndex = 2; - button1.Text = "button1"; - button1.UseVisualStyleBackColor = true; + buttonCreateOrder.Location = new Point(815, 42); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(157, 23); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; // - // button2 + // buttonTakeOrderInWork // - button2.Location = new Point(672, 81); - button2.Name = "button2"; - button2.Size = new Size(128, 23); - button2.TabIndex = 3; - button2.Text = "button2"; - button2.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Location = new Point(815, 71); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(157, 23); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отладить на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; // - // button3 + // buttonOrderReady // - button3.Location = new Point(672, 120); - button3.Name = "button3"; - button3.Size = new Size(128, 23); - button3.TabIndex = 4; - button3.Text = "button3"; - button3.UseVisualStyleBackColor = true; + buttonOrderReady.Location = new Point(815, 100); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(157, 23); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += buttonOrderReady_Click; // - // button4 + // buttonIssuedOrder // - button4.Location = new Point(672, 159); - button4.Name = "button4"; - button4.Size = new Size(128, 23); - button4.TabIndex = 5; - button4.Text = "button4"; - button4.UseVisualStyleBackColor = true; + buttonIssuedOrder.Location = new Point(815, 129); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(157, 23); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; // - // button5 + // buttonRef // - button5.Location = new Point(672, 197); - button5.Name = "button5"; - button5.Size = new Size(128, 23); - button5.TabIndex = 6; - button5.Text = "button5"; - button5.UseVisualStyleBackColor = true; + buttonRef.Location = new Point(815, 158); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(157, 23); + buttonRef.TabIndex = 6; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; // // FormMain // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(809, 370); - Controls.Add(button5); - Controls.Add(button4); - Controls.Add(button3); - Controls.Add(button2); - Controls.Add(button1); - Controls.Add(dataGridView1); + ClientSize = new Size(984, 370); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); Controls.Add(menuStrip); MainMenuStrip = menuStrip; Name = "FormMain"; Text = "Ремонтные работы"; + Load += FormMain_Load; menuStrip.ResumeLayout(false); menuStrip.PerformLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -153,11 +161,11 @@ private ToolStripMenuItem refbooksToolStripMenuItem; private ToolStripMenuItem componentsToolStripMenuItem; private ToolStripMenuItem JobTypeToolStripMenuItem; - private DataGridView dataGridView1; - private Button button1; - private Button button2; - private Button button3; - private Button button4; - private Button button5; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRef; } } \ No newline at end of file diff --git a/RenovationWork/RenovationWork/FormMain.cs b/RenovationWork/RenovationWork/FormMain.cs index 08c569c..d143cbe 100644 --- a/RenovationWork/RenovationWork/FormMain.cs +++ b/RenovationWork/RenovationWork/FormMain.cs @@ -7,14 +7,153 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; namespace RenovationWorkView { public partial class FormMain : Form { - public FormMain() + private readonly ILogger _logger; + private readonly IOrderLogic _orderLogic; + public FormMain(ILogger logger, IOrderLogic orderLogic) { InitializeComponent(); + _logger = logger; + _orderLogic = orderLogic; + } + + private void FormMain_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + _logger.LogInformation("Загрузка заказов"); + try + { + var list = _orderLogic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["RepairId"].Visible = false; + dataGridView.Columns["RepairName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки заказов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void componentsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); + if (service is FormComponents form) + { + form.ShowDialog(); + } + } + + private void JobTypeToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRepairs)); + if (service is FormRepairs form) + { + form.ShowDialog(); + } + } + + private void buttonCreateOrder_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); + if (service is FormCreateOrder form) + { + form.ShowDialog(); + LoadData(); + } + } + + private void buttonTakeOrderInWork_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); + try + { + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка передачи заказа в работу"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonOrderReady_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); + try + { + var operationResult = _orderLogic.FinishOrder(new + OrderBindingModel + { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonIssuedOrder_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); + try + { + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + _logger.LogInformation("Заказ №{id} выдан", id); + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); } } } + diff --git a/RenovationWork/RenovationWork/FormRepair.Designer.cs b/RenovationWork/RenovationWork/FormRepair.Designer.cs new file mode 100644 index 0000000..ec5f53a --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepair.Designer.cs @@ -0,0 +1,224 @@ +namespace RenovationWorkView +{ + partial class FormRepair + { + /// + /// 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() + { + labelName = new Label(); + labelPrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBox = new GroupBox(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ID = new DataGridViewTextBoxColumn(); + ComponentT = new DataGridViewTextBoxColumn(); + CountT = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(4, 12); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(4, 43); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(70, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Стоимость:"; + // + // textBoxName + // + textBoxName.Location = new Point(88, 12); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(334, 23); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(88, 43); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(334, 23); + textBoxPrice.TabIndex = 3; + // + // groupBox + // + groupBox.Controls.Add(buttonRef); + groupBox.Controls.Add(buttonDel); + groupBox.Controls.Add(buttonUpd); + groupBox.Controls.Add(buttonAdd); + groupBox.Controls.Add(dataGridView); + groupBox.Location = new Point(12, 87); + groupBox.Name = "groupBox"; + groupBox.Size = new Size(763, 351); + groupBox.TabIndex = 5; + groupBox.TabStop = false; + groupBox.Text = "Компоненты"; + // + // buttonRef + // + buttonRef.Location = new Point(656, 121); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(99, 23); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // buttonDel + // + buttonDel.Location = new Point(656, 92); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(99, 23); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(656, 63); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(99, 23); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(656, 34); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(99, 23); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ID, ComponentT, CountT }); + dataGridView.Location = new Point(6, 22); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(644, 323); + dataGridView.TabIndex = 0; + // + // ID + // + ID.HeaderText = "id"; + ID.Name = "ID"; + ID.Visible = false; + // + // ComponentT + // + ComponentT.HeaderText = "Компонент"; + ComponentT.Name = "ComponentT"; + ComponentT.Width = 300; + // + // CountT + // + CountT.HeaderText = "Количество"; + CountT.Name = "CountT"; + CountT.Width = 300; + // + // buttonSave + // + buttonSave.Location = new Point(599, 451); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(692, 451); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormRepair + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(783, 486); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Controls.Add(groupBox); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormRepair"; + Text = "Работа"; + Load += FormRepair_Load; + groupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBox; + private DataGridView dataGridView; + private Button buttonAdd; + private DataGridViewTextBoxColumn ID; + private DataGridViewTextBoxColumn ComponentT; + private DataGridViewTextBoxColumn CountT; + private Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWork/FormRepair.cs b/RenovationWork/RenovationWork/FormRepair.cs new file mode 100644 index 0000000..777b6cf --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepair.cs @@ -0,0 +1,213 @@ +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; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.SearchModels; +using RenovationWorkDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace RenovationWorkView +{ + public partial class FormRepair : Form + { + private readonly ILogger _logger; + private readonly IRepairLogic _logic; + private int? _id; + private Dictionary _repairComponents; + public int Id { set { _id = value; } } + public FormRepair(ILogger logger, IRepairLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _repairComponents = new Dictionary(); + } + + private void FormRepair_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new RepairSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.RepairName; + textBoxPrice.Text = view.Price.ToString(); + _repairComponents = view.RepairComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_repairComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _repairComponents) + { + dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + } + textBoxPrice.Text = CalcPrice().ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormRepairComponent)); + if (service is FormRepairComponent form) + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_repairComponents.ContainsKey(form.Id)) + { + _repairComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _repairComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRepairComponent)); + if (service is FormRepairComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _repairComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); + _repairComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + + private void buttonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count} ", dataGridView.SelectedRows[0].Cells[1].Value); + _repairComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxPrice.Text)) + { + MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (_repairComponents == null || _repairComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new RepairBindingModel + { + Id = _id ?? 0, + RepairName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + RepairComponents = _repairComponents + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + 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(); + } + + private double CalcPrice() + { + double price = 0; + foreach (var elem in _repairComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/RenovationWork/RenovationWork/FormRepair.resx b/RenovationWork/RenovationWork/FormRepair.resx new file mode 100644 index 0000000..74d6b1d --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepair.resx @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/RenovationWork/RenovationWork/FormRepairComponent.Designer.cs b/RenovationWork/RenovationWork/FormRepairComponent.Designer.cs new file mode 100644 index 0000000..c38f826 --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepairComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace RenovationWorkView +{ + partial class FormRepairComponent + { + /// + /// 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() + { + labelComponent = new Label(); + labelCount = new Label(); + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(9, 9); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(72, 15); + labelComponent.TabIndex = 0; + labelComponent.Text = "Компонент:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(9, 38); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(90, 9); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(354, 23); + comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(90, 38); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(354, 23); + textBoxCount.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(288, 76); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(369, 76); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormRepairComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(456, 107); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormRepairComponent"; + Text = "Компонент работы"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponent; + private Label labelCount; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWork/FormRepairComponent.cs b/RenovationWork/RenovationWork/FormRepairComponent.cs new file mode 100644 index 0000000..01d4ca8 --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepairComponent.cs @@ -0,0 +1,89 @@ +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; +using RenovationWorkContracts.BusinessLogicsContracts; +using RenovationWorkContracts.ViewModels; +using RenovationWorkDataModels.Models; + +namespace RenovationWorkView +{ + public partial class FormRepairComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponent.SelectedValue); + } + set + { + comboBoxComponent.SelectedValue = value; + } + } + public IComponentModel? ComponentModel + { + get + { + if (_list == null) + { + return null; + } + foreach (var elem in _list) + { + if (elem.Id == Id) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set + { textBoxCount.Text = value.ToString(); } + } + public FormRepairComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponent.DisplayMember = "ComponentName"; + comboBoxComponent.ValueMember = "Id"; + comboBoxComponent.DataSource = _list; + comboBoxComponent.SelectedItem = null; + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponent.SelectedValue == null) + { + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + DialogResult = DialogResult.OK; + Close(); + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/RenovationWork/RenovationWork/FormRepairComponent.resx b/RenovationWork/RenovationWork/FormRepairComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepairComponent.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/RenovationWork/RenovationWork/FormRepairs.Designer.cs b/RenovationWork/RenovationWork/FormRepairs.Designer.cs new file mode 100644 index 0000000..638fec6 --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepairs.Designer.cs @@ -0,0 +1,114 @@ +namespace RenovationWorkView +{ + partial class FormRepairs + { + /// + /// 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(); + buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(2, 2); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(553, 444); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(561, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(98, 23); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(561, 41); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(98, 23); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(561, 70); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(98, 23); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(561, 99); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(98, 23); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; + // + // FormRepairs + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(671, 448); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormRepairs"; + Text = "Список работ"; + Load += FormRepairs_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + } +} \ No newline at end of file diff --git a/RenovationWork/RenovationWork/FormRepairs.cs b/RenovationWork/RenovationWork/FormRepairs.cs new file mode 100644 index 0000000..dc8d7f4 --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepairs.cs @@ -0,0 +1,110 @@ +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; +using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace RenovationWorkView +{ + public partial class FormRepairs : Form + { + private readonly ILogger _logger; + private readonly IRepairLogic _logic; + public FormRepairs(ILogger logger, IRepairLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormRepairs_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["RepairName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["RepairComponents"].Visible = false; + } + _logger.LogInformation("Загрузка компьютеров"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компьютеров"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRepair)); + if (service is FormRepair form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormRepair)); + if (service is FormRepair form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + 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 RepairBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления компьютера"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/RenovationWork/RenovationWork/FormRepairs.resx b/RenovationWork/RenovationWork/FormRepairs.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/RenovationWork/RenovationWork/FormRepairs.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/RenovationWork/RenovationWorkListImplement/Implements/ComponentStorage.cs b/RenovationWork/RenovationWorkListImplement/Implements/ComponentStorage.cs index 10fb863..0f8848b 100644 --- a/RenovationWork/RenovationWorkListImplement/Implements/ComponentStorage.cs +++ b/RenovationWork/RenovationWorkListImplement/Implements/ComponentStorage.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using RenovationWorkContracts.BindingModels; +using RenovationWorkContracts.BindingModels; using RenovationWorkContracts.SearchModels; using RenovationWorkContracts.StoragesContracts; using RenovationWorkContracts.ViewModels; @@ -14,10 +8,10 @@ namespace RenovationWorkListImplement.Implements { public class ComponentStorage : IComponentStorage { - private readonly Models.Component _source; + private readonly DataListSingleton _source; public ComponentStorage() { - _source = Models.Component.GetInstance(); + _source = DataListSingleton.GetInstance(); } public List GetFullList() { @@ -72,7 +66,7 @@ namespace RenovationWorkListImplement.Implements model.Id = component.Id + 1; } } - var newComponent = System.ComponentModel.Component.Create(model); + var newComponent = Component.Create(model); if (newComponent == null) { return null; @@ -108,3 +102,4 @@ namespace RenovationWorkListImplement.Implements } } + diff --git a/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs b/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs index 82029ae..f35c26a 100644 --- a/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs +++ b/RenovationWork/RenovationWorkListImplement/Implements/OrderStorage.cs @@ -8,10 +8,10 @@ namespace RenovationWorkListImplement.Implements { public class OrderStorage : IOrderStorage { - private readonly Component _source; + private readonly DataListSingleton _source; public OrderStorage() { - _source = Component.GetInstance(); + _source = DataListSingleton.GetInstance(); } public List GetFullList() { diff --git a/RenovationWork/RenovationWorkListImplement/Implements/RepairStorage.cs b/RenovationWork/RenovationWorkListImplement/Implements/RepairStorage.cs index f5db68c..2c34924 100644 --- a/RenovationWork/RenovationWorkListImplement/Implements/RepairStorage.cs +++ b/RenovationWork/RenovationWorkListImplement/Implements/RepairStorage.cs @@ -13,10 +13,10 @@ namespace RenovationWorkListImplement.Implements { public class RepairStorage : IRepairStorage { - private readonly Component _source; + private readonly DataListSingleton _source; public RepairStorage() { - _source = Component.GetInstance(); + _source = DataListSingleton.GetInstance(); } public List GetFullList() {