From 6ed057e371257e7a497100cdf7f8f78bdcdf0bc5 Mon Sep 17 00:00:00 2001 From: Timourka Date: Mon, 12 Feb 2024 14:42:27 +0400 Subject: [PATCH] final 1 lab --- .../ViewModels/CarViewModel.cs | 4 +- .../ViewModels/ComponentViewModel.cs | 4 +- .../ViewModels/OrderViewModel.cs | 14 +- .../Implements/OrderStorage.cs | 15 +- .../AutomobilePlantView.csproj | 16 ++ .../AutomobilePlantView/Form1.Designer.cs | 39 --- AutomobilePlant/AutomobilePlantView/Form1.cs | 10 - .../AutomobilePlantView/FormCar.Designer.cs | 226 ++++++++++++++++++ .../AutomobilePlantView/FormCar.cs | 211 ++++++++++++++++ .../AutomobilePlantView/FormCar.resx | 129 ++++++++++ .../FormCarComponent.Designer.cs | 118 +++++++++ .../AutomobilePlantView/FormCarComponent.cs | 87 +++++++ .../{Form1.resx => FormCarComponent.resx} | 50 ++-- .../AutomobilePlantView/FormCars.Designer.cs | 113 +++++++++ .../AutomobilePlantView/FormCars.cs | 107 +++++++++ .../AutomobilePlantView/FormCars.resx | 120 ++++++++++ .../FormComponent.Designer.cs | 118 +++++++++ .../AutomobilePlantView/FormComponent.cs | 91 +++++++ .../AutomobilePlantView/FormComponent.resx | 120 ++++++++++ .../FormComponents.Designer.cs | 113 +++++++++ .../AutomobilePlantView/FormComponents.cs | 95 ++++++++ .../AutomobilePlantView/FormComponents.resx | 120 ++++++++++ .../FormCreateOrder.Designer.cs | 144 +++++++++++ .../AutomobilePlantView/FormCreateOrder.cs | 122 ++++++++++ .../AutomobilePlantView/FormCreateOrder.resx | 120 ++++++++++ .../AutomobilePlantView/FormMain.Designer.cs | 169 +++++++++++++ .../AutomobilePlantView/FormMain.cs | 162 +++++++++++++ .../AutomobilePlantView/FormMain.resx | 123 ++++++++++ .../AutomobilePlantView/Program.cs | 39 ++- .../AutomobilePlantView/nlog.config | 18 ++ 30 files changed, 2729 insertions(+), 88 deletions(-) delete mode 100644 AutomobilePlant/AutomobilePlantView/Form1.Designer.cs delete mode 100644 AutomobilePlant/AutomobilePlantView/Form1.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCar.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCar.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCar.resx create mode 100644 AutomobilePlant/AutomobilePlantView/FormCarComponent.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCarComponent.cs rename AutomobilePlant/AutomobilePlantView/{Form1.resx => FormCarComponent.resx} (93%) create mode 100644 AutomobilePlant/AutomobilePlantView/FormCars.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCars.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCars.resx create mode 100644 AutomobilePlant/AutomobilePlantView/FormComponent.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormComponent.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormComponent.resx create mode 100644 AutomobilePlant/AutomobilePlantView/FormComponents.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormComponents.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormComponents.resx create mode 100644 AutomobilePlant/AutomobilePlantView/FormCreateOrder.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCreateOrder.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormCreateOrder.resx create mode 100644 AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormMain.cs create mode 100644 AutomobilePlant/AutomobilePlantView/FormMain.resx create mode 100644 AutomobilePlant/AutomobilePlantView/nlog.config diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs index 8b947f3..0629033 100644 --- a/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/CarViewModel.cs @@ -11,9 +11,9 @@ namespace AutomobilePlantContracts.ViewModels public class CarViewModel : ICarModel { public int Id { get; set; } - [DisplayName("Название изделия")] + [DisplayName("Car's name")] public string CarName { get; set; } = string.Empty; - [DisplayName("Цена")] + [DisplayName("Price")] public double Price { get; set; } public Dictionary CarComponents { diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs index 92d581d..f5bf1a9 100644 --- a/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/ComponentViewModel.cs @@ -11,9 +11,9 @@ namespace AutomobilePlantContracts.ViewModels public class ComponentViewModel : IComponentModel { public int Id { get; set; } - [DisplayName("Название компонента")] + [DisplayName("Component's name")] public string ComponentName { get; set; } = string.Empty; - [DisplayName("Цена")] + [DisplayName("Cost")] public double Cost { get; set; } } } diff --git a/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs b/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs index 06dcbe1..0340d8a 100644 --- a/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs +++ b/AutomobilePlant/AutomobilePlantContracts/ViewModels/OrderViewModel.cs @@ -11,20 +11,20 @@ namespace AutomobilePlantContracts.ViewModels { public class OrderViewModel : IOrderModel { - [DisplayName("Номер")] + [DisplayName("Number")] public int Id { get; set; } public int CarId { get; set; } - [DisplayName("Изделие")] + [DisplayName("Car's name")] public string CarName { get; set; } = string.Empty; - [DisplayName("Количество")] + [DisplayName("Count")] public int Count { get; set; } - [DisplayName("Сумма")] + [DisplayName("Sum")] public double Sum { get; set; } - [DisplayName("Статус")] + [DisplayName("Status")] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; - [DisplayName("Дата создания")] + [DisplayName("Date of creation")] public DateTime DateCreate { get; set; } = DateTime.Now; - [DisplayName("Дата выполнения")] + [DisplayName("Date of completion")] public DateTime? DateImplement { get; set; } } } diff --git a/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs b/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs index d7091fc..02c6c3f 100644 --- a/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs +++ b/AutomobilePlant/AutomobilePlantListImplement/Implements/OrderStorage.cs @@ -23,7 +23,7 @@ namespace AutomobilePlantListImplement.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(order.GetViewModel); + result.Add(GetViewModel(order)); } return result; } @@ -103,5 +103,18 @@ namespace AutomobilePlantListImplement.Implements } return null; } + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var car in _source.Cars) + { + if (car.Id == order.CarId) + { + viewModel.CarName = car.CarName; + break; + } + } + return viewModel; + } } } diff --git a/AutomobilePlant/AutomobilePlantView/AutomobilePlantView.csproj b/AutomobilePlant/AutomobilePlantView/AutomobilePlantView.csproj index b57c89e..3eba142 100644 --- a/AutomobilePlant/AutomobilePlantView/AutomobilePlantView.csproj +++ b/AutomobilePlant/AutomobilePlantView/AutomobilePlantView.csproj @@ -8,4 +8,20 @@ enable + + + + + + + + + + + + + Always + + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/Form1.Designer.cs b/AutomobilePlant/AutomobilePlantView/Form1.Designer.cs deleted file mode 100644 index d0013f5..0000000 --- a/AutomobilePlant/AutomobilePlantView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace AutomobilePlantView -{ - partial class Form1 - { - /// - /// 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.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/AutomobilePlant/AutomobilePlantView/Form1.cs b/AutomobilePlant/AutomobilePlantView/Form1.cs deleted file mode 100644 index d4d11b9..0000000 --- a/AutomobilePlant/AutomobilePlantView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace AutomobilePlantView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/AutomobilePlant/AutomobilePlantView/FormCar.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormCar.Designer.cs new file mode 100644 index 0000000..494be90 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCar.Designer.cs @@ -0,0 +1,226 @@ +namespace AutomobilePlantView +{ + partial class FormCar + { + /// + /// 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(); + groupBoxComponents = new GroupBox(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + IdCol = new DataGridViewTextBoxColumn(); + ComponentCol = new DataGridViewTextBoxColumn(); + CountCol = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(42, 15); + labelName.TabIndex = 0; + labelName.Text = "Name:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(12, 38); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(36, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Price:"; + // + // textBoxName + // + textBoxName.Location = new Point(60, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(641, 23); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(60, 35); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(337, 23); + textBoxPrice.TabIndex = 3; + // + // groupBoxComponents + // + groupBoxComponents.Controls.Add(buttonRefresh); + groupBoxComponents.Controls.Add(buttonDelete); + groupBoxComponents.Controls.Add(buttonUpdate); + groupBoxComponents.Controls.Add(buttonAdd); + groupBoxComponents.Controls.Add(dataGridView); + groupBoxComponents.Location = new Point(12, 64); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Size = new Size(776, 345); + groupBoxComponents.TabIndex = 4; + groupBoxComponents.TabStop = false; + groupBoxComponents.Text = "Components"; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(695, 109); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(75, 23); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Refresh"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(695, 80); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Delete"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDel_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(695, 51); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Update"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(695, 22); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 23); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Add"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { IdCol, ComponentCol, CountCol }); + dataGridView.Location = new Point(6, 22); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(683, 317); + dataGridView.TabIndex = 0; + // + // IdCol + // + IdCol.HeaderText = "Id"; + IdCol.Name = "IdCol"; + IdCol.Visible = false; + // + // ComponentCol + // + ComponentCol.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ComponentCol.HeaderText = "Component"; + ComponentCol.Name = "ComponentCol"; + // + // CountCol + // + CountCol.HeaderText = "Count"; + CountCol.Name = "CountCol"; + // + // buttonSave + // + buttonSave.Location = new Point(632, 415); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 5; + buttonSave.Text = "Save"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(713, 415); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCar + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxComponents); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormCar"; + Text = "Car"; + Load += FormCar_Load; + groupBoxComponents.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 groupBoxComponents; + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonAdd; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn IdCol; + private DataGridViewTextBoxColumn ComponentCol; + private DataGridViewTextBoxColumn CountCol; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormCar.cs b/AutomobilePlant/AutomobilePlantView/FormCar.cs new file mode 100644 index 0000000..45bc080 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCar.cs @@ -0,0 +1,211 @@ +using AutomobilePlantDataModels.Models; +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; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModels; +using AutomobilePlantContracts.BindingModels; + +namespace AutomobilePlantView +{ + public partial class FormCar : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logic; + private int? _id; + private Dictionary _carComponents; + public int Id { set { _id = value; } } + public FormCar(ILogger logger, ICarLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _carComponents = new Dictionary(); + } + private void FormCar_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new CarSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.CarName; + textBoxPrice.Text = view.Price.ToString(); + _carComponents = view.CarComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_carComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _carComponents) + { + 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(FormCarComponent)); + if (service is FormCarComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_carComponents.ContainsKey(form.Id)) + { + _carComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _carComponents.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(FormCarComponent)); + if (service is FormCarComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _carComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _carComponents[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); + _carComponents?.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 (_carComponents == null || _carComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new CarBindingModel + { + Id = _id ?? 0, CarName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + CarComponents = _carComponents + }; + 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 _carComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/AutomobilePlant/AutomobilePlantView/FormCar.resx b/AutomobilePlant/AutomobilePlantView/FormCar.resx new file mode 100644 index 0000000..89c9ec3 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCar.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormCarComponent.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormCarComponent.Designer.cs new file mode 100644 index 0000000..671647c --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCarComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace AutomobilePlantView +{ + partial class FormCarComponent + { + /// + /// 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(12, 9); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(74, 15); + labelComponent.TabIndex = 0; + labelComponent.Text = "Component:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 38); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(43, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Count:"; + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(92, 6); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(520, 23); + comboBoxComponent.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(92, 35); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(520, 23); + textBoxCount.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(456, 64); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 4; + buttonSave.Text = "Save"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(537, 64); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCarComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(624, 94); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Name = "FormCarComponent"; + Text = "Car's component"; + 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/AutomobilePlant/AutomobilePlantView/FormCarComponent.cs b/AutomobilePlant/AutomobilePlantView/FormCarComponent.cs new file mode 100644 index 0000000..519b833 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCarComponent.cs @@ -0,0 +1,87 @@ +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.ViewModels; +using AutomobilePlantDataModels.Models; +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 AutomobilePlantView +{ + public partial class FormCarComponent : 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 FormCarComponent(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/AutomobilePlant/AutomobilePlantView/Form1.resx b/AutomobilePlant/AutomobilePlantView/FormCarComponent.resx similarity index 93% rename from AutomobilePlant/AutomobilePlantView/Form1.resx rename to AutomobilePlant/AutomobilePlantView/FormCarComponent.resx index 1af7de1..af32865 100644 --- a/AutomobilePlant/AutomobilePlantView/Form1.resx +++ b/AutomobilePlant/AutomobilePlantView/FormCarComponent.resx @@ -1,17 +1,17 @@  - diff --git a/AutomobilePlant/AutomobilePlantView/FormCars.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormCars.Designer.cs new file mode 100644 index 0000000..eba9911 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCars.Designer.cs @@ -0,0 +1,113 @@ +namespace AutomobilePlantView +{ + partial class FormCars + { + /// + /// 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(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(707, 438); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(713, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 23); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Add"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(713, 41); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(75, 23); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Update"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpd_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(713, 70); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(75, 23); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Delete"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDel_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(713, 99); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(75, 23); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Refresh"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // FormCars + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormCars"; + Text = "Cars"; + Load += FormCars_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormCars.cs b/AutomobilePlant/AutomobilePlantView/FormCars.cs new file mode 100644 index 0000000..c1875a7 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCars.cs @@ -0,0 +1,107 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.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 AutomobilePlantView +{ + public partial class FormCars : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logic; + public FormCars(ILogger logger, ICarLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormCars_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["CarName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["CarComponents"].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(FormCar)); + if (service is FormCar 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(FormCar)); + if (service is FormCar 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 CarBindingModel { 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/AutomobilePlant/AutomobilePlantView/FormCars.resx b/AutomobilePlant/AutomobilePlantView/FormCars.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCars.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/AutomobilePlant/AutomobilePlantView/FormComponent.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormComponent.Designer.cs new file mode 100644 index 0000000..9bb1942 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace AutomobilePlantView +{ + partial class FormComponent + { + /// + /// 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(); + labelCost = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(42, 15); + labelName.TabIndex = 0; + labelName.Text = "Name:"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(12, 43); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(34, 15); + labelCost.TabIndex = 1; + labelCost.Text = "Cost:"; + // + // textBoxName + // + textBoxName.Location = new Point(60, 9); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(344, 23); + textBoxName.TabIndex = 2; + // + // textBoxCost + // + textBoxCost.Location = new Point(60, 40); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(133, 23); + textBoxCost.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(248, 83); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 4; + buttonSave.Text = "Save"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(329, 83); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(416, 118); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(labelCost); + Controls.Add(labelName); + Name = "FormComponent"; + Text = "Component"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelCost; + private TextBox textBoxName; + private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormComponent.cs b/AutomobilePlant/AutomobilePlantView/FormComponent.cs new file mode 100644 index 0000000..051db60 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormComponent.cs @@ -0,0 +1,91 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModels; +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 AutomobilePlantView +{ + public partial class FormComponent : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + _logger.LogInformation("Получение компонента"); + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + 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(); + } + } +} diff --git a/AutomobilePlant/AutomobilePlantView/FormComponent.resx b/AutomobilePlant/AutomobilePlantView/FormComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormComponent.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/AutomobilePlant/AutomobilePlantView/FormComponents.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormComponents.Designer.cs new file mode 100644 index 0000000..2d653aa --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormComponents.Designer.cs @@ -0,0 +1,113 @@ +namespace AutomobilePlantView +{ + partial class FormComponents + { + /// + /// 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(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(666, 438); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(672, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(116, 23); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Add"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(672, 41); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(116, 23); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Update"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += ButtonUpd_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(672, 70); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(116, 23); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Delete"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDel_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(672, 99); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(116, 23); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Refresh"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "Components"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormComponents.cs b/AutomobilePlant/AutomobilePlantView/FormComponents.cs new file mode 100644 index 0000000..0aa581c --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormComponents.cs @@ -0,0 +1,95 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace AutomobilePlantView +{ + public partial class FormComponents : Form + { + private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormComponents_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["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _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(FormComponent)); + if (service is FormComponent 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(FormComponent)); + if (service is FormComponent 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 ComponentBindingModel { 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/AutomobilePlant/AutomobilePlantView/FormComponents.resx b/AutomobilePlant/AutomobilePlantView/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormComponents.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/AutomobilePlant/AutomobilePlantView/FormCreateOrder.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..f0490bb --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCreateOrder.Designer.cs @@ -0,0 +1,144 @@ +namespace AutomobilePlantView +{ + 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); + } + + #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() + { + labelCar = new Label(); + labelCount = new Label(); + labelSum = new Label(); + comboBoxCar = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelCar + // + labelCar.AutoSize = true; + labelCar.Location = new Point(12, 9); + labelCar.Name = "labelCar"; + labelCar.Size = new Size(28, 15); + labelCar.TabIndex = 0; + labelCar.Text = "Car:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(12, 38); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(43, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Count:"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(12, 67); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(34, 15); + labelSum.TabIndex = 2; + labelSum.Text = "Sum:"; + // + // comboBoxCar + // + comboBoxCar.FormattingEnabled = true; + comboBoxCar.Location = new Point(61, 6); + comboBoxCar.Name = "comboBoxCar"; + comboBoxCar.Size = new Size(727, 23); + comboBoxCar.TabIndex = 3; + comboBoxCar.SelectedIndexChanged += ComboBoxCar_SelectedIndexChanged; + // + // textBoxCount + // + textBoxCount.Location = new Point(61, 35); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(727, 23); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(61, 64); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(727, 23); + textBoxSum.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(632, 93); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Save"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(713, 93); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Cancel"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 125); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxCar); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelCar); + Name = "FormCreateOrder"; + Text = "Create Order"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelCar; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxCar; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormCreateOrder.cs b/AutomobilePlant/AutomobilePlantView/FormCreateOrder.cs new file mode 100644 index 0000000..8b528b2 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCreateOrder.cs @@ -0,0 +1,122 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.SearchModels; +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 AutomobilePlantView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ICarLogic _logicC; + private readonly IOrderLogic _logicO; + public FormCreateOrder(ILogger logger, ICarLogic logicC, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicC = logicC; + _logicO = logicO; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var list = _logicC.ReadList(null); + if (list != null) + { + comboBoxCar.DisplayMember = "CarName"; + comboBoxCar.ValueMember = "Id"; + comboBoxCar.DataSource = list; + comboBoxCar.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка автомобилей"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxCar.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxCar.SelectedValue); + var car = _logicC.ReadElement(new CarSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (car?.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 ComboBoxCar_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 (comboBoxCar.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + CarId = Convert.ToInt32(comboBoxCar.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(); + } + } + +} diff --git a/AutomobilePlant/AutomobilePlantView/FormCreateOrder.resx b/AutomobilePlant/AutomobilePlantView/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormCreateOrder.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/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs b/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs new file mode 100644 index 0000000..e5d1a4e --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormMain.Designer.cs @@ -0,0 +1,169 @@ +namespace AutomobilePlantView +{ + partial class FormMain + { + /// + /// 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() + { + menuStrip1 = new MenuStrip(); + toolStripMenuItemCatalogs = new ToolStripMenuItem(); + toolStripMenuItemComponents = new ToolStripMenuItem(); + toolStripMenuItemCars = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRefresh = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { toolStripMenuItemCatalogs }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(800, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // toolStripMenuItemCatalogs + // + toolStripMenuItemCatalogs.DropDownItems.AddRange(new ToolStripItem[] { toolStripMenuItemComponents, toolStripMenuItemCars }); + toolStripMenuItemCatalogs.Name = "toolStripMenuItemCatalogs"; + toolStripMenuItemCatalogs.Size = new Size(65, 20); + toolStripMenuItemCatalogs.Text = "Catalogs"; + // + // toolStripMenuItemComponents + // + toolStripMenuItemComponents.Name = "toolStripMenuItemComponents"; + toolStripMenuItemComponents.Size = new Size(180, 22); + toolStripMenuItemComponents.Text = "Components"; + toolStripMenuItemComponents.Click += ComponentsToolStripMenuItem_Click; + // + // toolStripMenuItemCars + // + toolStripMenuItemCars.Name = "toolStripMenuItemCars"; + toolStripMenuItemCars.Size = new Size(180, 22); + toolStripMenuItemCars.Text = "Cars"; + toolStripMenuItemCars.Click += CarsToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 27); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(659, 411); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(677, 27); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(111, 23); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Create order"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(677, 56); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(111, 23); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Take order in work"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(677, 85); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(111, 23); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Order is ready"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(677, 114); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(111, 23); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Order is issued"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(677, 143); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(111, 23); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Refresh"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRef_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + Name = "FormMain"; + Text = "Automobile plant"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem toolStripMenuItemCatalogs; + private ToolStripMenuItem toolStripMenuItemComponents; + private ToolStripMenuItem toolStripMenuItemCars; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button buttonIssuedOrder; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/FormMain.cs b/AutomobilePlant/AutomobilePlantView/FormMain.cs new file mode 100644 index 0000000..3321de7 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormMain.cs @@ -0,0 +1,162 @@ +using AutomobilePlantContracts.BindingModels; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantDataModels.Enums; +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 AutomobilePlantView +{ + public partial class FormMain : Form + { + 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["CarId"].Visible = false; + + } + _logger.LogInformation("Загрузка заказов"); + } + 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 CarsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormCars)); + if (service is FormCars 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 OrderBindingModel CreateBindingModel(int id) + { + return new OrderBindingModel + { + Id = id, + CarId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["CarId"].Value), + Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), + DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), + Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), + Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), + }; + } + 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(CreateBindingModel(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(CreateBindingModel(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(CreateBindingModel(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/AutomobilePlant/AutomobilePlantView/FormMain.resx b/AutomobilePlant/AutomobilePlantView/FormMain.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/FormMain.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/Program.cs b/AutomobilePlant/AutomobilePlantView/Program.cs index fdfd874..cc61535 100644 --- a/AutomobilePlant/AutomobilePlantView/Program.cs +++ b/AutomobilePlant/AutomobilePlantView/Program.cs @@ -1,9 +1,20 @@ +using AutomobilePlantBusinessLogic.BusinessLogics; +using AutomobilePlantContracts.BusinessLogicsContracts; +using AutomobilePlantContracts.StoragesContracts; +using AutomobilePlantListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using System.Drawing; + namespace AutomobilePlantView { internal static class Program { + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() @@ -11,7 +22,31 @@ namespace AutomobilePlantView // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + var services = new ServiceCollection(); + ConfigureServices(services); + _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); + } + private static void ConfigureServices(ServiceCollection services) + { + services.AddLogging(option => + { + option.SetMinimumLevel(LogLevel.Information); + option.AddNLog("nlog.config"); + }); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/AutomobilePlant/AutomobilePlantView/nlog.config b/AutomobilePlant/AutomobilePlantView/nlog.config new file mode 100644 index 0000000..95bc762 --- /dev/null +++ b/AutomobilePlant/AutomobilePlantView/nlog.config @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + \ No newline at end of file