diff --git a/MotorPlant/MotorPlantContracts/StoragesContracts/IComponentStorage.cs b/MotorPlant/MotorPlantContracts/StoragesContracts/IComponentStorage.cs index 0aea0e3..17501c2 100644 --- a/MotorPlant/MotorPlantContracts/StoragesContracts/IComponentStorage.cs +++ b/MotorPlant/MotorPlantContracts/StoragesContracts/IComponentStorage.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BindingModels; using MotorPlantContracts.SearchModels; using MotorPlantContracts.ViewModels; diff --git a/MotorPlant/MotorPlantContracts/StoragesContracts/IEngineStorage.cs b/MotorPlant/MotorPlantContracts/StoragesContracts/IEngineStorage.cs index d4355cf..cea6728 100644 --- a/MotorPlant/MotorPlantContracts/StoragesContracts/IEngineStorage.cs +++ b/MotorPlant/MotorPlantContracts/StoragesContracts/IEngineStorage.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BindingModels; using MotorPlantContracts.SearchModels; using MotorPlantContracts.ViewModels; diff --git a/MotorPlant/MotorPlantContracts/StoragesContracts/IOrderStorage.cs b/MotorPlant/MotorPlantContracts/StoragesContracts/IOrderStorage.cs index 7970a2e..d08c6cc 100644 --- a/MotorPlant/MotorPlantContracts/StoragesContracts/IOrderStorage.cs +++ b/MotorPlant/MotorPlantContracts/StoragesContracts/IOrderStorage.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BindingModels; using MotorPlantContracts.SearchModels; using MotorPlantContracts.ViewModels; diff --git a/MotorPlant/MotorPlantListImplement/DataListSingleton.cs b/MotorPlant/MotorPlantListImplement/DataListSingleton.cs new file mode 100644 index 0000000..cb0052f --- /dev/null +++ b/MotorPlant/MotorPlantListImplement/DataListSingleton.cs @@ -0,0 +1,33 @@ +using MotorPlantListImplement.Models; + + +namespace MotorPlantListImplement +{ + internal class DataListSingleton + { + private static DataListSingleton? _instance; + + public List Components { get; set; } + + public List Orders { get; set; } + + public List Engines { get; set; } + + private DataListSingleton() + { + Components = new List(); + Orders = new List(); + Engines = new List(); + } + + public static DataListSingleton GetInstance() + { + if (_instance == null) + { + _instance = new DataListSingleton(); + } + + return _instance; + } + } +} diff --git a/MotorPlant/MotorPlantListImplement/Implements/ComponentStorage.cs b/MotorPlant/MotorPlantListImplement/Implements/ComponentStorage.cs index b23dcbe..6212a2d 100644 --- a/MotorPlant/MotorPlantListImplement/Implements/ComponentStorage.cs +++ b/MotorPlant/MotorPlantListImplement/Implements/ComponentStorage.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MotorPlantContracts.BindingModels; -using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.BindingModels; using MotorPlantContracts.SearchModels; +using MotorPlantContracts.StoragesContracts; using MotorPlantContracts.ViewModels; using MotorPlantListImplement.Models; diff --git a/MotorPlant/MotorPlantListImplement/Implements/EngineStorage.cs b/MotorPlant/MotorPlantListImplement/Implements/EngineStorage.cs index 58c41e3..977db77 100644 --- a/MotorPlant/MotorPlantListImplement/Implements/EngineStorage.cs +++ b/MotorPlant/MotorPlantListImplement/Implements/EngineStorage.cs @@ -1,38 +1,38 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MotorPlantContracts.BindingModels; -using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.BindingModels; using MotorPlantContracts.SearchModels; +using MotorPlantContracts.StoragesContracts; using MotorPlantContracts.ViewModels; namespace MotorPlantListImplement.Implements { - public class EngineLogic : IEngineLogic + public class EngineStorage : IEngineStorage { - public bool Create(EngineBindingModel model) + public EngineViewModel? Delete(EngineBindingModel model) { throw new NotImplementedException(); } - public bool Delete(EngineBindingModel model) + public EngineViewModel? GetElement(EngineSearchModel model) { throw new NotImplementedException(); } - public EngineViewModel? ReadElement(EngineSearchModel model) + public List GetFilteredList(EngineSearchModel model) { throw new NotImplementedException(); } - public List? ReadList(EngineSearchModel? model) + public List GetFullList() { throw new NotImplementedException(); } - public bool Update(EngineBindingModel model) + public EngineViewModel? Insert(EngineBindingModel model) + { + throw new NotImplementedException(); + } + + public EngineViewModel? Update(EngineBindingModel model) { throw new NotImplementedException(); } diff --git a/MotorPlant/MotorPlantListImplement/Implements/OrderStorage.cs b/MotorPlant/MotorPlantListImplement/Implements/OrderStorage.cs index 106787c..5746e8e 100644 --- a/MotorPlant/MotorPlantListImplement/Implements/OrderStorage.cs +++ b/MotorPlant/MotorPlantListImplement/Implements/OrderStorage.cs @@ -1,12 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using MotorPlantContracts.BindingModels; -using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.BindingModels; using MotorPlantContracts.SearchModels; using MotorPlantContracts.ViewModels; +using MotorPlantContracts.StoragesContracts; namespace MotorPlantListImplement.Implements { diff --git a/MotorPlant/MotorPlantView/Form1.Designer.cs b/MotorPlant/MotorPlantView/Form1.Designer.cs deleted file mode 100644 index 00d1b90..0000000 --- a/MotorPlant/MotorPlantView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace MotorPlant -{ - 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/MotorPlant/MotorPlantView/Form1.cs b/MotorPlant/MotorPlantView/Form1.cs deleted file mode 100644 index 25290bc..0000000 --- a/MotorPlant/MotorPlantView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace MotorPlant -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/MotorPlant/MotorPlantView/FormComponent.Designer.cs b/MotorPlant/MotorPlantView/FormComponent.Designer.cs new file mode 100644 index 0000000..e1ff14e --- /dev/null +++ b/MotorPlant/MotorPlantView/FormComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace MotorPlantView +{ + 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() + { + ButtonSave = new Button(); + ButtonCancel = new Button(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + labelName = new Label(); + labelCost = new Label(); + SuspendLayout(); + // + // ButtonSave + // + ButtonSave.Location = new Point(253, 125); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(103, 28); + ButtonSave.TabIndex = 0; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(368, 125); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(103, 28); + ButtonCancel.TabIndex = 1; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // textBoxName + // + textBoxName.Location = new Point(99, 22); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(204, 23); + textBoxName.TabIndex = 2; + // + // textBoxCost + // + textBoxCost.Location = new Point(99, 60); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(204, 23); + textBoxCost.TabIndex = 3; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(15, 25); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 4; + labelName.Text = "Название:"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(15, 63); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(38, 15); + labelCost.TabIndex = 5; + labelCost.Text = "Цена:"; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(487, 165); + Controls.Add(labelCost); + Controls.Add(labelName); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Name = "FormComponent"; + Text = "Компонент"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button ButtonSave; + private Button ButtonCancel; + private TextBox textBoxName; + private TextBox textBoxCost; + private Label labelName; + private Label labelCost; + } +} diff --git a/MotorPlant/MotorPlantView/FormComponent.cs b/MotorPlant/MotorPlantView/FormComponent.cs new file mode 100644 index 0000000..b9ebaf5 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormComponent.cs @@ -0,0 +1,87 @@ +using Microsoft.Extensions.Logging; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using Microsoft.Extensions.Logging; +using System.Windows.Forms; + +namespace MotorPlantView +{ + 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/MotorPlant/MotorPlantView/Form1.resx b/MotorPlant/MotorPlantView/FormComponent.resx similarity index 93% rename from MotorPlant/MotorPlantView/Form1.resx rename to MotorPlant/MotorPlantView/FormComponent.resx index 1af7de1..af32865 100644 --- a/MotorPlant/MotorPlantView/Form1.resx +++ b/MotorPlant/MotorPlantView/FormComponent.resx @@ -1,17 +1,17 @@  - diff --git a/MotorPlant/MotorPlantView/FormComponents.Designer.cs b/MotorPlant/MotorPlantView/FormComponents.Designer.cs new file mode 100644 index 0000000..e966e76 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormComponents.Designer.cs @@ -0,0 +1,137 @@ +namespace MotorPlantView +{ + 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(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); + id = new DataGridViewTextBoxColumn(); + ComponentName = new DataGridViewTextBoxColumn(); + Cost = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { id, ComponentName, Cost }); + dataGridView.Location = new Point(2, 1); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(444, 359); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(525, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(135, 30); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(525, 61); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(135, 30); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(525, 106); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(135, 30); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(525, 151); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(135, 30); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // id + // + id.HeaderText = "ID"; + id.Name = "id"; + id.Visible = false; + // + // ComponentName + // + ComponentName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ComponentName.HeaderText = "ComponentName"; + ComponentName.Name = "ComponentName"; + // + // Cost + // + Cost.HeaderText = "Cost"; + Cost.Name = "Cost"; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(682, 360); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormComponents"; + Text = "FormComponents"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; + private DataGridViewTextBoxColumn id; + private DataGridViewTextBoxColumn ComponentName; + private DataGridViewTextBoxColumn Cost; + } +} \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormComponents.cs b/MotorPlant/MotorPlantView/FormComponents.cs new file mode 100644 index 0000000..84f2c8c --- /dev/null +++ b/MotorPlant/MotorPlantView/FormComponents.cs @@ -0,0 +1,103 @@ +using Microsoft.Extensions.Logging; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; + +namespace MotorPlantView +{ + 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/MotorPlant/MotorPlantView/FormComponents.resx b/MotorPlant/MotorPlantView/FormComponents.resx new file mode 100644 index 0000000..a5a136e --- /dev/null +++ b/MotorPlant/MotorPlantView/FormComponents.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/MotorPlant/MotorPlantView/FormCreateOrder.Designer.cs b/MotorPlant/MotorPlantView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..e704629 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormCreateOrder.Designer.cs @@ -0,0 +1,145 @@ +namespace MotorPlantView +{ + 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() + { + labelEngine = new Label(); + labelCount = new Label(); + labelSum = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + comboBoxEngine = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + SuspendLayout(); + // + // labelEngine + // + labelEngine.AutoSize = true; + labelEngine.Location = new Point(18, 13); + labelEngine.Name = "labelEngine"; + labelEngine.Size = new Size(66, 15); + labelEngine.TabIndex = 0; + labelEngine.Text = "Двигатель:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(18, 48); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(18, 83); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(48, 15); + labelSum.TabIndex = 2; + labelSum.Text = "Сумма:"; + // + // buttonSave + // + buttonSave.Location = new Point(246, 125); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(103, 28); + buttonSave.TabIndex = 3; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(366, 125); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(103, 28); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // comboBoxEngine + // + comboBoxEngine.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxEngine.FormattingEnabled = true; + comboBoxEngine.Location = new Point(112, 10); + comboBoxEngine.Name = "comboBoxEngine"; + comboBoxEngine.Size = new Size(204, 23); + comboBoxEngine.TabIndex = 5; + comboBoxEngine.SelectedIndexChanged += ComboBoxEngine_SelectedIndexChanged; + // + // textBoxCount + // + textBoxCount.Location = new Point(112, 45); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(204, 23); + textBoxCount.TabIndex = 6; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(112, 80); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(204, 23); + textBoxSum.TabIndex = 7; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(487, 165); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxEngine); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelEngine); + Name = "FormCreateOrder"; + Text = "FormCreateOrder"; + Load += FormCreateOrder_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelEngine; + private Label labelCount; + private Label labelSum; + private Button buttonSave; + private Button buttonCancel; + private ComboBox comboBoxEngine; + private TextBox textBoxCount; + private TextBox textBoxSum; + } +} \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormCreateOrder.cs b/MotorPlant/MotorPlantView/FormCreateOrder.cs new file mode 100644 index 0000000..98e8c37 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormCreateOrder.cs @@ -0,0 +1,102 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace MotorPlantView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + + private readonly IEngineLogic _logicP; + + private readonly IOrderLogic _logicO; + + public FormCreateOrder(ILogger logger, IEngineLogic logicP, IOrderLogic logicO) + { + InitializeComponent(); + _logger = logger; + _logicP = logicP; + _logicO = logicO; + } + + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + // прописать логику + } + + private void CalcSum() + { + if (comboBoxEngine.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxEngine.SelectedValue); + var Engine = _logicP.ReadElement(new EngineSearchModel { Id = id }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (Engine?.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 ComboBoxEngine_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 (comboBoxEngine.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicO.CreateOrder(new OrderBindingModel + { + EngineId = Convert.ToInt32(comboBoxEngine.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/MotorPlant/MotorPlantView/FormCreateOrder.resx b/MotorPlant/MotorPlantView/FormCreateOrder.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/MotorPlant/MotorPlantView/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/MotorPlant/MotorPlantView/FormEngine.Designer.cs b/MotorPlant/MotorPlantView/FormEngine.Designer.cs new file mode 100644 index 0000000..5948d16 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormEngine.Designer.cs @@ -0,0 +1,223 @@ +namespace MotorPlantView +{ + partial class FormEngine + { + /// + /// 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(); + buttonRef = new Button(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBoxComponents.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(20, 9); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 0; + labelName.Text = "Название:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(20, 45); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(38, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Цена:"; + // + // textBoxName + // + textBoxName.Location = new Point(85, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(204, 23); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(85, 42); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(204, 23); + textBoxPrice.TabIndex = 3; + // + // groupBoxComponents + // + groupBoxComponents.Controls.Add(buttonRef); + groupBoxComponents.Controls.Add(buttonDel); + groupBoxComponents.Controls.Add(buttonUpd); + groupBoxComponents.Controls.Add(buttonAdd); + groupBoxComponents.Controls.Add(dataGridView); + groupBoxComponents.Location = new Point(20, 71); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Size = new Size(549, 239); + groupBoxComponents.TabIndex = 4; + groupBoxComponents.TabStop = false; + groupBoxComponents.Text = "Компоненты"; + // + // buttonRef + // + buttonRef.Location = new Point(392, 163); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(135, 30); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // buttonDel + // + buttonDel.Location = new Point(392, 114); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(135, 30); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(392, 68); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(135, 30); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(392, 22); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(135, 30); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Location = new Point(13, 24); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(351, 203); + dataGridView.TabIndex = 0; + // + // ColumnId + // + ColumnId.HeaderText = "ID"; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Name"; + ColumnName.Name = "ColumnName"; + // + // ColumnCount + // + ColumnCount.AutoSizeMode = DataGridViewAutoSizeColumnMode.None; + ColumnCount.HeaderText = "Count"; + ColumnCount.Name = "ColumnCount"; + // + // buttonSave + // + buttonSave.Location = new Point(280, 325); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(135, 30); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(434, 325); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(135, 30); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormEngine + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(583, 381); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxComponents); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormEngine"; + Text = "Изделие"; + Load += FormEngine_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 Button buttonRef; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormEngine.cs b/MotorPlant/MotorPlantView/FormEngine.cs new file mode 100644 index 0000000..0a579da --- /dev/null +++ b/MotorPlant/MotorPlantView/FormEngine.cs @@ -0,0 +1,208 @@ +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.SearchModels; +using MotorPlantDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace MotorPlantView +{ + public partial class FormEngine : Form + { + private readonly ILogger _logger; + + private readonly IEngineLogic _logic; + + private int? _id; + + private Dictionary _engineComponents; + + public int Id { set { _id = value; } } + + public FormEngine(ILogger logger, IEngineLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _engineComponents = new Dictionary(); + } + + private void FormEngine_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new EngineSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.EngineName; + textBoxPrice.Text = view.Price.ToString(); + _engineComponents = view.EngineComponents ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_engineComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _engineComponents) + { + 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(FormEngineComponent)); + if (service is FormEngineComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + if (_engineComponents.ContainsKey(form.Id)) + { + _engineComponents[form.Id] = (form.ComponentModel, form.Count); + } + else + { + _engineComponents.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(FormEngineComponent)); + if (service is FormEngineComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _engineComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + _engineComponents[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); + _engineComponents?.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 (_engineComponents == null || _engineComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new EngineBindingModel + { + Id = _id ?? 0, + EngineName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + EngineComponents = _engineComponents + }; + 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 _engineComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/MotorPlant/MotorPlantView/FormEngine.resx b/MotorPlant/MotorPlantView/FormEngine.resx new file mode 100644 index 0000000..fcacbcb --- /dev/null +++ b/MotorPlant/MotorPlantView/FormEngine.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/MotorPlant/MotorPlantView/FormEngineComponent.Designer.cs b/MotorPlant/MotorPlantView/FormEngineComponent.Designer.cs new file mode 100644 index 0000000..86ba6f7 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormEngineComponent.Designer.cs @@ -0,0 +1,118 @@ +namespace MotorPlantView +{ + partial class FormEngineComponent + { + /// + /// 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() + { + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); + labelComponent = new Label(); + labelCount = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // comboBoxComponent + // + comboBoxComponent.FormattingEnabled = true; + comboBoxComponent.Location = new Point(135, 18); + comboBoxComponent.Name = "comboBoxComponent"; + comboBoxComponent.Size = new Size(204, 23); + comboBoxComponent.TabIndex = 0; + // + // textBoxCount + // + textBoxCount.Location = new Point(135, 53); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(204, 23); + textBoxCount.TabIndex = 1; + // + // labelComponent + // + labelComponent.AutoSize = true; + labelComponent.Location = new Point(17, 21); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(72, 15); + labelComponent.TabIndex = 2; + labelComponent.Text = "Компонент:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(17, 56); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(75, 15); + labelCount.TabIndex = 3; + labelCount.Text = "Количество:"; + // + // buttonSave + // + buttonSave.Location = new Point(249, 125); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(103, 28); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(372, 125); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(103, 28); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormEngineComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(487, 165); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelCount); + Controls.Add(labelComponent); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Name = "FormEngineComponent"; + Text = "FormEngineComponent"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxComponent; + private TextBox textBoxCount; + private Label labelComponent; + private Label labelCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/FormEngineComponent.cs b/MotorPlant/MotorPlantView/FormEngineComponent.cs new file mode 100644 index 0000000..6039e3b --- /dev/null +++ b/MotorPlant/MotorPlantView/FormEngineComponent.cs @@ -0,0 +1,80 @@ +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.ViewModels; +using MotorPlantDataModels.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 MotorPlantView +{ + public partial class FormEngineComponent : 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 FormEngineComponent(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/MotorPlant/MotorPlantView/FormEngineComponent.resx b/MotorPlant/MotorPlantView/FormEngineComponent.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormEngineComponent.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/MotorPlant/MotorPlantView/FormMain.Designer.cs b/MotorPlant/MotorPlantView/FormMain.Designer.cs new file mode 100644 index 0000000..0dc6872 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormMain.Designer.cs @@ -0,0 +1,170 @@ +namespace MotorPlantView +{ + 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(); + dictionariesToolStripMenuItem = new ToolStripMenuItem(); + componentsToolStripMenuItem = new ToolStripMenuItem(); + enginesToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + buttonIssuedOrder = new Button(); + buttonRef = new Button(); + menuStrip1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.Items.AddRange(new ToolStripItem[] { dictionariesToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(741, 24); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // dictionariesToolStripMenuItem + // + dictionariesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { componentsToolStripMenuItem, enginesToolStripMenuItem }); + dictionariesToolStripMenuItem.Name = "dictionariesToolStripMenuItem"; + dictionariesToolStripMenuItem.Size = new Size(94, 20); + dictionariesToolStripMenuItem.Text = "Справочники"; + // + // componentsToolStripMenuItem + // + componentsToolStripMenuItem.Name = "componentsToolStripMenuItem"; + componentsToolStripMenuItem.Size = new Size(180, 22); + componentsToolStripMenuItem.Text = "Компоненты"; + componentsToolStripMenuItem.Click += componentsToolStripMenuItem_Click; + // + // enginesToolStripMenuItem + // + enginesToolStripMenuItem.Name = "enginesToolStripMenuItem"; + enginesToolStripMenuItem.Size = new Size(180, 22); + enginesToolStripMenuItem.Text = "Двигатели"; + enginesToolStripMenuItem.Click += enginesToolStripMenuItem_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(4, 30); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(490, 240); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(550, 30); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(170, 30); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(550, 66); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(170, 30); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(550, 102); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(170, 30); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(550, 138); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(170, 30); + buttonIssuedOrder.TabIndex = 5; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Location = new Point(550, 174); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(170, 30); + buttonRef.TabIndex = 6; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += ButtonRef_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(741, 278); + Controls.Add(buttonRef); + Controls.Add(buttonIssuedOrder); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormMain"; + Text = "FormMain"; + Load += FormMain_Load; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem dictionariesToolStripMenuItem; + private ToolStripMenuItem componentsToolStripMenuItem; + private ToolStripMenuItem enginesToolStripMenuItem; + 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/MotorPlant/MotorPlantView/FormMain.cs b/MotorPlant/MotorPlantView/FormMain.cs new file mode 100644 index 0000000..93f4805 --- /dev/null +++ b/MotorPlant/MotorPlantView/FormMain.cs @@ -0,0 +1,159 @@ +using Microsoft.Extensions.Logging; +using MotorPlantContracts.BindingModels; +using MotorPlantContracts.BusinessLogicsContracts; +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 MotorPlantView +{ + 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["EngineId"].Visible = false; + dataGridView.Columns["EngineName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + _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 enginesToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormEngine)); + if (service is FormEngine 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/MotorPlant/MotorPlantView/FormMain.resx b/MotorPlant/MotorPlantView/FormMain.resx new file mode 100644 index 0000000..a0623c8 --- /dev/null +++ b/MotorPlant/MotorPlantView/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/MotorPlant/MotorPlantView/MotorPlantView.csproj b/MotorPlant/MotorPlantView/MotorPlantView.csproj index b57c89e..e134139 100644 --- a/MotorPlant/MotorPlantView/MotorPlantView.csproj +++ b/MotorPlant/MotorPlantView/MotorPlantView.csproj @@ -8,4 +8,16 @@ enable + + + + + + + + + + + + \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/Program.cs b/MotorPlant/MotorPlantView/Program.cs index 78a4fae..f3086d6 100644 --- a/MotorPlant/MotorPlantView/Program.cs +++ b/MotorPlant/MotorPlantView/Program.cs @@ -1,17 +1,45 @@ -namespace MotorPlant +using MotorPlantBusinessLogics.BusinessLogics; +using MotorPlantContracts.BusinessLogicsContracts; +using MotorPlantContracts.StoragesContracts; +using MotorPlantListImplement.Implements; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; + +namespace MotorPlantView { internal static class Program { - /// - /// The main entry point for the application. - /// + private static ServiceProvider? _serviceProvider; + public static ServiceProvider? ServiceProvider => _serviceProvider; + [STAThread] static void Main() { - // To customize application configuration such as set high DPI settings or default font, - // see https://aka.ms/applicationconfiguration. - ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + + } + + 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(); } } } \ No newline at end of file diff --git a/MotorPlant/MotorPlantView/nlog.config b/MotorPlant/MotorPlantView/nlog.config new file mode 100644 index 0000000..609afe6 --- /dev/null +++ b/MotorPlant/MotorPlantView/nlog.config @@ -0,0 +1,15 @@ + + + + + + + + + + + + + \ No newline at end of file