From ea0854e9502d059e42d25ff51c660738b506e066 Mon Sep 17 00:00:00 2001 From: "ns.potapov" Date: Mon, 26 Feb 2024 00:11:41 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D1=87=D1=82=D0=B8=20=D0=B2=D1=81?= =?UTF-8?q?=D0=B5=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=BE,=20=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BB=D0=BE=D1=81=D1=8C=20=D1=80=D0=B5=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D1=83=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=BA=D0=B0=20=D0=B8=D0=B7=D0=B4=D0=B5=D0=BB=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataListSingleton.cs | 4 +- .../Implements/SecureStorage.cs | 1 + .../SecuritySystemView/Form1.Designer.cs | 39 --- SecuritySystem/SecuritySystemView/Form1.cs | 10 - .../FormComponent.Designer.cs | 117 +++++++++ .../SecuritySystemView/FormComponent.cs | 86 +++++++ .../{Form1.resx => FormComponent.resx} | 52 ++-- .../FormComponents.Designer.cs | 118 +++++++++ .../SecuritySystemView/FormComponents.cs | 99 ++++++++ .../SecuritySystemView/FormComponents.resx | 120 +++++++++ .../FormCreateOrder.Designer.cs | 144 +++++++++++ .../SecuritySystemView/FormCreateOrder.cs | 117 +++++++++ .../SecuritySystemView/FormCreateOrder.resx | 120 +++++++++ .../SecuritySystemView/FormMain.Designer.cs | 175 +++++++++++++ SecuritySystem/SecuritySystemView/FormMain.cs | 140 +++++++++++ .../SecuritySystemView/FormMain.resx | 123 ++++++++++ .../SecuritySystemView/FormSecure.Designer.cs | 229 ++++++++++++++++++ .../SecuritySystemView/FormSecure.cs | 209 ++++++++++++++++ .../SecuritySystemView/FormSecure.resx | 138 +++++++++++ .../FormSecureComponent.Designer.cs | 119 +++++++++ .../SecuritySystemView/FormSecureComponent.cs | 79 ++++++ .../FormSecureComponent.resx | 120 +++++++++ SecuritySystem/SecuritySystemView/Program.cs | 38 ++- .../SecuritySystemView.csproj | 24 ++ SecuritySystem/SecuritySystemView/nlog.config | 16 ++ 25 files changed, 2357 insertions(+), 80 deletions(-) delete mode 100644 SecuritySystem/SecuritySystemView/Form1.Designer.cs delete mode 100644 SecuritySystem/SecuritySystemView/Form1.cs create mode 100644 SecuritySystem/SecuritySystemView/FormComponent.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/FormComponent.cs rename SecuritySystem/SecuritySystemView/{Form1.resx => FormComponent.resx} (93%) create mode 100644 SecuritySystem/SecuritySystemView/FormComponents.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/FormComponents.cs create mode 100644 SecuritySystem/SecuritySystemView/FormComponents.resx create mode 100644 SecuritySystem/SecuritySystemView/FormCreateOrder.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/FormCreateOrder.cs create mode 100644 SecuritySystem/SecuritySystemView/FormCreateOrder.resx create mode 100644 SecuritySystem/SecuritySystemView/FormMain.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/FormMain.cs create mode 100644 SecuritySystem/SecuritySystemView/FormMain.resx create mode 100644 SecuritySystem/SecuritySystemView/FormSecure.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/FormSecure.cs create mode 100644 SecuritySystem/SecuritySystemView/FormSecure.resx create mode 100644 SecuritySystem/SecuritySystemView/FormSecureComponent.Designer.cs create mode 100644 SecuritySystem/SecuritySystemView/FormSecureComponent.cs create mode 100644 SecuritySystem/SecuritySystemView/FormSecureComponent.resx create mode 100644 SecuritySystem/SecuritySystemView/nlog.config diff --git a/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs b/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs index 0df80bb..e173975 100644 --- a/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs +++ b/SecuritySystem/SecuritySystemListImplement/DataListSingleton.cs @@ -22,7 +22,5 @@ namespace SecuritySystemListImplement } return _instance; } -22 - } - + } } diff --git a/SecuritySystem/SecuritySystemListImplement/Implements/SecureStorage.cs b/SecuritySystem/SecuritySystemListImplement/Implements/SecureStorage.cs index 12b8535..fadad29 100644 --- a/SecuritySystem/SecuritySystemListImplement/Implements/SecureStorage.cs +++ b/SecuritySystem/SecuritySystemListImplement/Implements/SecureStorage.cs @@ -2,6 +2,7 @@ using SecuritySystemContracts.SearchModels; using SecuritySystemContracts.StoragesContracts; using SecuritySystemContracts.ViewModels; +using SecuritySystemListImplement.Models; namespace SecuritySystemListImplement.Implements { diff --git a/SecuritySystem/SecuritySystemView/Form1.Designer.cs b/SecuritySystem/SecuritySystemView/Form1.Designer.cs deleted file mode 100644 index b8ad4ac..0000000 --- a/SecuritySystem/SecuritySystemView/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace SecuritySystemView -{ - 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 - } -} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/Form1.cs b/SecuritySystem/SecuritySystemView/Form1.cs deleted file mode 100644 index 939fef1..0000000 --- a/SecuritySystem/SecuritySystemView/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace SecuritySystemView -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormComponent.Designer.cs b/SecuritySystem/SecuritySystemView/FormComponent.Designer.cs new file mode 100644 index 0000000..289b744 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormComponent.Designer.cs @@ -0,0 +1,117 @@ +namespace SecuritySystemView +{ + 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() + { + textBoxComponentName = new TextBox(); + textBoxComponentCost = new TextBox(); + labelComponentName = new Label(); + labelComponentCost = new Label(); + buttonSaveComponent = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // textBoxComponentName + // + textBoxComponentName.Location = new Point(98, 6); + textBoxComponentName.Name = "textBoxComponentName"; + textBoxComponentName.Size = new Size(372, 27); + textBoxComponentName.TabIndex = 0; + // + // textBoxComponentCost + // + textBoxComponentCost.Location = new Point(98, 41); + textBoxComponentCost.Name = "textBoxComponentCost"; + textBoxComponentCost.Size = new Size(125, 27); + textBoxComponentCost.TabIndex = 1; + // + // labelComponentName + // + labelComponentName.AutoSize = true; + labelComponentName.Location = new Point(12, 9); + labelComponentName.Name = "labelComponentName"; + labelComponentName.Size = new Size(80, 20); + labelComponentName.TabIndex = 2; + labelComponentName.Text = "Название:"; + // + // labelComponentCost + // + labelComponentCost.AutoSize = true; + labelComponentCost.Location = new Point(12, 41); + labelComponentCost.Name = "labelComponentCost"; + labelComponentCost.Size = new Size(48, 20); + labelComponentCost.TabIndex = 3; + labelComponentCost.Text = "Цена:"; + // + // buttonSaveComponent + // + buttonSaveComponent.Location = new Point(211, 80); + buttonSaveComponent.Name = "buttonSaveComponent"; + buttonSaveComponent.Size = new Size(115, 29); + buttonSaveComponent.TabIndex = 4; + buttonSaveComponent.Text = "Сохранить"; + buttonSaveComponent.UseVisualStyleBackColor = true; + buttonSaveComponent.Click += ButtonSaveComponent_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(348, 80); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(122, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(482, 119); + Controls.Add(buttonCancel); + Controls.Add(buttonSaveComponent); + Controls.Add(labelComponentCost); + Controls.Add(labelComponentName); + Controls.Add(textBoxComponentCost); + Controls.Add(textBoxComponentName); + Name = "FormComponent"; + Text = "Компонент"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxComponentName; + private TextBox textBoxComponentCost; + private Label labelComponentName; + private Label labelComponentCost; + private Button buttonSaveComponent; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormComponent.cs b/SecuritySystem/SecuritySystemView/FormComponent.cs new file mode 100644 index 0000000..17044f5 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormComponent.cs @@ -0,0 +1,86 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; +using System.Windows.Forms; + +namespace SecuritySystemView +{ + 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) + { + textBoxComponentName.Text = view.ComponentName; + textBoxComponentCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonSaveComponent_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxComponentName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение компонента"); + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxComponentName.Text, + Cost = Convert.ToDouble(textBoxComponentCost.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/SecuritySystem/SecuritySystemView/Form1.resx b/SecuritySystem/SecuritySystemView/FormComponent.resx similarity index 93% rename from SecuritySystem/SecuritySystemView/Form1.resx rename to SecuritySystem/SecuritySystemView/FormComponent.resx index 1af7de1..a395bff 100644 --- a/SecuritySystem/SecuritySystemView/Form1.resx +++ b/SecuritySystem/SecuritySystemView/FormComponent.resx @@ -1,24 +1,24 @@  - diff --git a/SecuritySystem/SecuritySystemView/FormComponents.Designer.cs b/SecuritySystem/SecuritySystemView/FormComponents.Designer.cs new file mode 100644 index 0000000..be34d06 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormComponents.Designer.cs @@ -0,0 +1,118 @@ +namespace SecuritySystemView +{ + 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() + { + dataGridViewComponents = new DataGridView(); + buttonAddComponent = new Button(); + buttonEditComponent = new Button(); + buttonDeleteComponent = new Button(); + buttonRefreshComponents = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridViewComponents).BeginInit(); + SuspendLayout(); + // + // dataGridViewComponents + // + dataGridViewComponents.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewComponents.Dock = DockStyle.Left; + dataGridViewComponents.Location = new Point(0, 0); + dataGridViewComponents.MultiSelect = false; + dataGridViewComponents.Name = "dataGridViewComponents"; + dataGridViewComponents.ReadOnly = true; + dataGridViewComponents.RowHeadersVisible = false; + dataGridViewComponents.RowHeadersWidth = 51; + dataGridViewComponents.RowTemplate.Height = 29; + dataGridViewComponents.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewComponents.Size = new Size(539, 450); + dataGridViewComponents.TabIndex = 0; + // + // buttonAddComponent + // + buttonAddComponent.Location = new Point(562, 23); + buttonAddComponent.Name = "buttonAddComponent"; + buttonAddComponent.Size = new Size(94, 29); + buttonAddComponent.TabIndex = 1; + buttonAddComponent.Text = "Добавить"; + buttonAddComponent.UseVisualStyleBackColor = true; + buttonAddComponent.Click += ButtonAddComponent_Click; + // + // buttonEditComponent + // + buttonEditComponent.Location = new Point(562, 75); + buttonEditComponent.Name = "buttonEditComponent"; + buttonEditComponent.Size = new Size(94, 29); + buttonEditComponent.TabIndex = 2; + buttonEditComponent.Text = "Изменить"; + buttonEditComponent.UseVisualStyleBackColor = true; + buttonEditComponent.Click += ButtonEditComponent_Click; + // + // buttonDeleteComponent + // + buttonDeleteComponent.Location = new Point(562, 125); + buttonDeleteComponent.Name = "buttonDeleteComponent"; + buttonDeleteComponent.Size = new Size(94, 29); + buttonDeleteComponent.TabIndex = 3; + buttonDeleteComponent.Text = "Удалить"; + buttonDeleteComponent.UseVisualStyleBackColor = true; + buttonDeleteComponent.Click += ButtonDeleteComponent_Click; + // + // buttonRefreshComponents + // + buttonRefreshComponents.Location = new Point(562, 173); + buttonRefreshComponents.Name = "buttonRefreshComponents"; + buttonRefreshComponents.Size = new Size(94, 29); + buttonRefreshComponents.TabIndex = 4; + buttonRefreshComponents.Text = "Обновить"; + buttonRefreshComponents.UseVisualStyleBackColor = true; + buttonRefreshComponents.Click += ButtonRefreshComponents_Click; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(684, 450); + Controls.Add(buttonRefreshComponents); + Controls.Add(buttonDeleteComponent); + Controls.Add(buttonEditComponent); + Controls.Add(buttonAddComponent); + Controls.Add(dataGridViewComponents); + Name = "FormComponents"; + Text = "Компоненты"; + ((System.ComponentModel.ISupportInitialize)dataGridViewComponents).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridViewComponents; + private Button buttonAddComponent; + private Button buttonEditComponent; + private Button buttonDeleteComponent; + private Button buttonRefreshComponents; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormComponents.cs b/SecuritySystem/SecuritySystemView/FormComponents.cs new file mode 100644 index 0000000..b6b3efb --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormComponents.cs @@ -0,0 +1,99 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; + +namespace SecuritySystemView +{ + 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) + { + dataGridViewComponents.DataSource = list; + dataGridViewComponents.Columns["Id"].Visible = false; + dataGridViewComponents.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка компонентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAddComponent_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 ButtonEditComponent_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = + Convert.ToInt32(dataGridViewComponents.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDeleteComponent_Click(object sender, EventArgs e) + { + if (dataGridViewComponents.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridViewComponents.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 ButtonRefreshComponents_Click(object sender, EventArgs e) + { + LoadData(); + } + + } +} diff --git a/SecuritySystem/SecuritySystemView/FormComponents.resx b/SecuritySystem/SecuritySystemView/FormComponents.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/SecuritySystem/SecuritySystemView/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/SecuritySystem/SecuritySystemView/FormCreateOrder.Designer.cs b/SecuritySystem/SecuritySystemView/FormCreateOrder.Designer.cs new file mode 100644 index 0000000..0595ed5 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormCreateOrder.Designer.cs @@ -0,0 +1,144 @@ +namespace SecuritySystemView +{ + 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() + { + labelSecureName = new Label(); + labelCount = new Label(); + labelSum = new Label(); + comboBoxSecure = new ComboBox(); + textBoxCount = new TextBox(); + textBoxSum = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelSecureName + // + labelSecureName.AutoSize = true; + labelSecureName.Location = new Point(11, 12); + labelSecureName.Name = "labelSecureName"; + labelSecureName.Size = new Size(71, 20); + labelSecureName.TabIndex = 0; + labelSecureName.Text = "Изделие:"; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(11, 46); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(93, 20); + labelCount.TabIndex = 1; + labelCount.Text = "Количество:"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(12, 78); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(58, 20); + labelSum.TabIndex = 2; + labelSum.Text = "Сумма:"; + // + // comboBoxSecure + // + comboBoxSecure.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSecure.FormattingEnabled = true; + comboBoxSecure.Location = new Point(110, 9); + comboBoxSecure.Name = "comboBoxSecure"; + comboBoxSecure.Size = new Size(462, 28); + comboBoxSecure.TabIndex = 3; + comboBoxSecure.SelectedIndexChanged += ComboBoxSecure_SelectedIndexChanged; + // + // textBoxCount + // + textBoxCount.Location = new Point(110, 43); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(462, 27); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // textBoxSum + // + textBoxSum.Location = new Point(110, 75); + textBoxSum.Name = "textBoxSum"; + textBoxSum.ReadOnly = true; + textBoxSum.Size = new Size(462, 27); + textBoxSum.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(370, 118); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(478, 118); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormCreateOrder + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(586, 160); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxSum); + Controls.Add(textBoxCount); + Controls.Add(comboBoxSecure); + Controls.Add(labelSum); + Controls.Add(labelCount); + Controls.Add(labelSecureName); + Name = "FormCreateOrder"; + Text = "Создание заказа"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelSecureName; + private Label labelCount; + private Label labelSum; + private ComboBox comboBoxSecure; + private TextBox textBoxCount; + private TextBox textBoxSum; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormCreateOrder.cs b/SecuritySystem/SecuritySystemView/FormCreateOrder.cs new file mode 100644 index 0000000..d075ddf --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormCreateOrder.cs @@ -0,0 +1,117 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; + +namespace SecuritySystemView +{ + public partial class FormCreateOrder : Form + { + private readonly ILogger _logger; + private readonly ISecureLogic _logicSecure; + private readonly IOrderLogic _logicOrder; + public FormCreateOrder(ILogger logger, ISecureLogic logicSecure, IOrderLogic logicOrder) + { + InitializeComponent(); + _logger = logger; + _logicSecure = logicSecure; + _logicOrder = logicOrder; + } + private void FormCreateOrder_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка изделий для заказа"); + try + { + var list = _logicSecure.ReadList(null); + if (list != null) + { + comboBoxSecure.DisplayMember = "SecureName"; + comboBoxSecure.ValueMember = "Id"; + comboBoxSecure.DataSource = list; + comboBoxSecure.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void CalcSum() + { + if (comboBoxSecure.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) + { + try + { + int id = Convert.ToInt32(comboBoxSecure.SelectedValue); + var secure = _logicSecure.ReadElement(new SecureSearchModel + { + Id = id + }); + int count = Convert.ToInt32(textBoxCount.Text); + textBoxSum.Text = Math.Round(count * (secure?.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 ComboBoxSecure_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 (comboBoxSecure.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание заказа"); + try + { + var operationResult = _logicOrder.CreateOrder(new OrderBindingModel + { + SecureId = Convert.ToInt32(comboBoxSecure.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/SecuritySystem/SecuritySystemView/FormCreateOrder.resx b/SecuritySystem/SecuritySystemView/FormCreateOrder.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/SecuritySystem/SecuritySystemView/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/SecuritySystem/SecuritySystemView/FormMain.Designer.cs b/SecuritySystem/SecuritySystemView/FormMain.Designer.cs new file mode 100644 index 0000000..a899111 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormMain.Designer.cs @@ -0,0 +1,175 @@ +namespace SecuritySystemView +{ + 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() + { + menuStrip = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + компонентыToolStripMenuItem = new ToolStripMenuItem(); + изделияToolStripMenuItem = new ToolStripMenuItem(); + dataGridView = new DataGridView(); + buttonCreateOrder = new Button(); + buttonTakeOrderInWork = new Button(); + buttonOrderReady = new Button(); + button4 = new Button(); + buttonRefresh = new Button(); + menuStrip.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(1043, 28); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // компонентыToolStripMenuItem + // + компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; + компонентыToolStripMenuItem.Size = new Size(182, 26); + компонентыToolStripMenuItem.Text = "Компоненты"; + // + // изделияToolStripMenuItem + // + изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; + изделияToolStripMenuItem.Size = new Size(182, 26); + изделияToolStripMenuItem.Text = "Изделия"; + // + // dataGridView + // + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(12, 31); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(775, 296); + dataGridView.TabIndex = 1; + // + // buttonCreateOrder + // + buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonCreateOrder.Location = new Point(816, 56); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(216, 29); + buttonCreateOrder.TabIndex = 2; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonTakeOrderInWork.Location = new Point(816, 110); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(216, 29); + buttonTakeOrderInWork.TabIndex = 3; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonOrderReady.Location = new Point(816, 167); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(216, 29); + buttonOrderReady.TabIndex = 4; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // button4 + // + button4.Anchor = AnchorStyles.Top | AnchorStyles.Right; + button4.Location = new Point(816, 230); + button4.Name = "button4"; + button4.Size = new Size(216, 29); + button4.TabIndex = 5; + button4.Text = "Заказ выдан"; + button4.UseVisualStyleBackColor = true; + button4.Click += ButtonIssuedOrder_Click; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonRefresh.Location = new Point(816, 290); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(216, 29); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить список"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // FormMain + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1043, 339); + Controls.Add(buttonRefresh); + Controls.Add(button4); + Controls.Add(buttonOrderReady); + Controls.Add(buttonTakeOrderInWork); + Controls.Add(buttonCreateOrder); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormMain"; + Text = "Системы безопасности"; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem изделияToolStripMenuItem; + private DataGridView dataGridView; + private Button buttonCreateOrder; + private Button buttonTakeOrderInWork; + private Button buttonOrderReady; + private Button button4; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormMain.cs b/SecuritySystem/SecuritySystemView/FormMain.cs new file mode 100644 index 0000000..2fed95c --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormMain.cs @@ -0,0 +1,140 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; + +namespace SecuritySystemView +{ + 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["SecureId"].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 SecuresToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSecures)); + if (service is FormSecures 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 ButtonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SecuritySystem/SecuritySystemView/FormMain.resx b/SecuritySystem/SecuritySystemView/FormMain.resx new file mode 100644 index 0000000..c17a880 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/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/SecuritySystem/SecuritySystemView/FormSecure.Designer.cs b/SecuritySystem/SecuritySystemView/FormSecure.Designer.cs new file mode 100644 index 0000000..4fb4f68 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecure.Designer.cs @@ -0,0 +1,229 @@ +namespace SecuritySystemView +{ + partial class FormSecure + { + /// + /// 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() + { + labelSecureName = new Label(); + labelSecurePrice = new Label(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBoxComponentsControl = new GroupBox(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBoxComponentsControl.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelSecureName + // + labelSecureName.AutoSize = true; + labelSecureName.Location = new Point(12, 9); + labelSecureName.Name = "labelSecureName"; + labelSecureName.Size = new Size(80, 20); + labelSecureName.TabIndex = 0; + labelSecureName.Text = "Название:"; + // + // labelSecurePrice + // + labelSecurePrice.AutoSize = true; + labelSecurePrice.Location = new Point(12, 46); + labelSecurePrice.Name = "labelSecurePrice"; + labelSecurePrice.Size = new Size(86, 20); + labelSecurePrice.TabIndex = 1; + labelSecurePrice.Text = "Стоимость:"; + // + // textBoxName + // + textBoxName.Location = new Point(108, 6); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(368, 27); + textBoxName.TabIndex = 2; + // + // textBoxPrice + // + textBoxPrice.Enabled = false; + textBoxPrice.Location = new Point(108, 43); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(143, 27); + textBoxPrice.TabIndex = 3; + // + // groupBoxComponentsControl + // + groupBoxComponentsControl.Controls.Add(buttonRefresh); + groupBoxComponentsControl.Controls.Add(buttonDelete); + groupBoxComponentsControl.Controls.Add(buttonEdit); + groupBoxComponentsControl.Controls.Add(buttonAdd); + groupBoxComponentsControl.Controls.Add(dataGridView); + groupBoxComponentsControl.Location = new Point(12, 76); + groupBoxComponentsControl.Name = "groupBoxComponentsControl"; + groupBoxComponentsControl.Size = new Size(776, 317); + groupBoxComponentsControl.TabIndex = 5; + groupBoxComponentsControl.TabStop = false; + groupBoxComponentsControl.Text = "Компоненты"; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(668, 197); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(94, 29); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(668, 147); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(94, 29); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += ButtonDelete_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(668, 99); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(94, 29); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(668, 48); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 29); + 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(6, 26); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.RowTemplate.Height = 29; + dataGridView.Size = new Size(627, 285); + dataGridView.TabIndex = 0; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + ColumnId.Width = 125; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Компонент"; + ColumnName.MinimumWidth = 6; + ColumnName.Name = "ColumnName"; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.Width = 125; + // + // buttonSave + // + buttonSave.Location = new Point(537, 409); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(108, 29); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(665, 409); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(109, 29); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormSecure + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxComponentsControl); + Controls.Add(textBoxPrice); + Controls.Add(textBoxName); + Controls.Add(labelSecurePrice); + Controls.Add(labelSecureName); + Name = "FormSecure"; + Text = "Изделие"; + groupBoxComponentsControl.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelSecureName; + private Label labelSecurePrice; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBoxComponentsControl; + private Button buttonRefresh; + private Button buttonDelete; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormSecure.cs b/SecuritySystem/SecuritySystemView/FormSecure.cs new file mode 100644 index 0000000..6db7f27 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecure.cs @@ -0,0 +1,209 @@ +using Microsoft.Extensions.Logging; +using SecuritySystemContracts.BindingModels; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.SearchModels; +using SecuritySystemDataModels.Models; +using System.Windows.Forms; + +namespace SecuritySystemView +{ + public partial class FormSecure : Form + { + private readonly ILogger _logger; + private readonly ISecureLogic _logic; + private int? _id; + private Dictionary _secureComponents; + public int Id { set { _id = value; } } + public FormSecure(ILogger logger, ISecureLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _secureComponents = new Dictionary(); + } + private void FormSecure_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка изделия"); + try + { + var view = _logic.ReadElement(new SecureSearchModel + { + Id = _id.Value + }); + if (view != null) + { + textBoxName.Text = view.SecureName; + textBoxPrice.Text = view.Price.ToString(); + _secureComponents = view.SecureComponents ?? new + Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделия"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void LoadData() + { + _logger.LogInformation("Загрузка компонент изделия"); + try + { + if (_secureComponents != null) + { + dataGridView.Rows.Clear(); + foreach (var pc in _secureComponents) + { + 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(FormSecureComponent)); + if (service is FormSecureComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + if (_secureComponents.ContainsKey(form.Id)) + { + _secureComponents[form.Id] = (form.ComponentModel, + form.Count); + } + else + { + _secureComponents.Add(form.Id, (form.ComponentModel, + form.Count)); + } + LoadData(); + } + } + } + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSecureComponent)); + if (service is FormSecureComponent form) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); + form.Id = id; + form.Count = _secureComponents[id].Item2; + if (form.ShowDialog() == DialogResult.OK) + { + if (form.ComponentModel == null) + { + return; + } + _logger.LogInformation("Изменение компонента: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); _secureComponents[form.Id] = (form.ComponentModel, form.Count); + LoadData(); + } + } + } + } + private void ButtonDelete_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); + _secureComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + private void ButtonRefresh_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 (_secureComponents == null || _secureComponents.Count == 0) + { + MessageBox.Show("Заполните компоненты", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение изделия"); + try + { + var model = new SecureBindingModel + { + Id = _id ?? 0, + SecureName = textBoxName.Text, + Price = Convert.ToDouble(textBoxPrice.Text), + SecureComponents = _secureComponents + }; + 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 _secureComponents) + { + price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); + } + return Math.Round(price * 1.1, 2); + } + } +} diff --git a/SecuritySystem/SecuritySystemView/FormSecure.resx b/SecuritySystem/SecuritySystemView/FormSecure.resx new file mode 100644 index 0000000..0f9f3e9 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecure.resx @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + True + + + True + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormSecureComponent.Designer.cs b/SecuritySystem/SecuritySystemView/FormSecureComponent.Designer.cs new file mode 100644 index 0000000..598bd54 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecureComponent.Designer.cs @@ -0,0 +1,119 @@ +namespace SecuritySystemView +{ + partial class FormSecureComponent + { + /// + /// 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() + { + labelComponentSelect = new Label(); + labelComponentsCount = new Label(); + comboBoxComponents = new ComboBox(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelComponentSelect + // + labelComponentSelect.AutoSize = true; + labelComponentSelect.Location = new Point(10, 9); + labelComponentSelect.Name = "labelComponentSelect"; + labelComponentSelect.Size = new Size(91, 20); + labelComponentSelect.TabIndex = 0; + labelComponentSelect.Text = "Компонент:"; + // + // labelComponentsCount + // + labelComponentsCount.AutoSize = true; + labelComponentsCount.Location = new Point(10, 44); + labelComponentsCount.Name = "labelComponentsCount"; + labelComponentsCount.Size = new Size(93, 20); + labelComponentsCount.TabIndex = 1; + labelComponentsCount.Text = "Количество:"; + // + // comboBoxComponents + // + comboBoxComponents.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxComponents.FormattingEnabled = true; + comboBoxComponents.Location = new Point(109, 6); + comboBoxComponents.Name = "comboBoxComponents"; + comboBoxComponents.Size = new Size(315, 28); + comboBoxComponents.TabIndex = 2; + // + // textBoxCount + // + textBoxCount.Location = new Point(109, 41); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(315, 27); + textBoxCount.TabIndex = 3; + // + // buttonSave + // + buttonSave.Location = new Point(230, 84); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(330, 84); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormSecureComponent + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(432, 121); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponents); + Controls.Add(labelComponentsCount); + Controls.Add(labelComponentSelect); + Name = "FormSecureComponent"; + Text = "Компонент изделия"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelComponentSelect; + private Label labelComponentsCount; + private ComboBox comboBoxComponents; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/FormSecureComponent.cs b/SecuritySystem/SecuritySystemView/FormSecureComponent.cs new file mode 100644 index 0000000..d8aed90 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecureComponent.cs @@ -0,0 +1,79 @@ +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.ViewModels; +using SecuritySystemDataModels.Models; + +namespace SecuritySystemView +{ + public partial class FormSecureComponent : Form + { + private readonly List? _list; + public int Id + { + get + { + return Convert.ToInt32(comboBoxComponents.SelectedValue); + } + set + { + comboBoxComponents.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 FormSecureComponent(IComponentLogic logic) + { + InitializeComponent(); + _list = logic.ReadList(null); + if (_list != null) + { + comboBoxComponents.DisplayMember = "ComponentName"; + comboBoxComponents.ValueMember = "Id"; + comboBoxComponents.DataSource = _list; + comboBoxComponents.SelectedItem = null; + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxComponents.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/SecuritySystem/SecuritySystemView/FormSecureComponent.resx b/SecuritySystem/SecuritySystemView/FormSecureComponent.resx new file mode 100644 index 0000000..a395bff --- /dev/null +++ b/SecuritySystem/SecuritySystemView/FormSecureComponent.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/SecuritySystem/SecuritySystemView/Program.cs b/SecuritySystem/SecuritySystemView/Program.cs index ce4214b..9621dd6 100644 --- a/SecuritySystem/SecuritySystemView/Program.cs +++ b/SecuritySystem/SecuritySystemView/Program.cs @@ -1,9 +1,19 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using NLog.Extensions.Logging; +using SecuritySystemBusinessLogic.BusinessLogics; +using SecuritySystemContracts.BusinessLogicsContracts; +using SecuritySystemContracts.StoragesContracts; +using SecuritySystemListImplement.Implements; + namespace SecuritySystemView { 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 +21,31 @@ namespace SecuritySystemView // 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/SecuritySystem/SecuritySystemView/SecuritySystemView.csproj b/SecuritySystem/SecuritySystemView/SecuritySystemView.csproj index b57c89e..726d3b3 100644 --- a/SecuritySystem/SecuritySystemView/SecuritySystemView.csproj +++ b/SecuritySystem/SecuritySystemView/SecuritySystemView.csproj @@ -8,4 +8,28 @@ enable + + + + + + + Always + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/SecuritySystem/SecuritySystemView/nlog.config b/SecuritySystem/SecuritySystemView/nlog.config new file mode 100644 index 0000000..036b2f8 --- /dev/null +++ b/SecuritySystem/SecuritySystemView/nlog.config @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + \ No newline at end of file