From 29d13d49edaa2d5b59d1b92a70067797dc7b1d94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=9A=D1=83=D0=BA?= =?UTF-8?q?=D0=BB=D0=B5=D0=B2?= Date: Sun, 7 Apr 2024 17:05:30 +0400 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=B8?= =?UTF-8?q?=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormComponent.Designer.cs | 121 +++++---- SoftwareInstallation/FormComponent.cs | 29 +-- .../FormComponents.Designer.cs | 112 ++++----- SoftwareInstallation/FormComponents.cs | 51 ++-- .../FormCreateOrder.Designer.cs | 130 +++++----- SoftwareInstallation/FormCreateOrder.cs | 44 ++-- SoftwareInstallation/FormMain.Designer.cs | 187 +++++++------- SoftwareInstallation/FormMain.cs | 69 +++-- SoftwareInstallation/FormMain.resx | 21 +- SoftwareInstallation/FormPackage.Designer.cs | 237 +++++++++--------- SoftwareInstallation/FormPackage.cs | 104 ++++---- SoftwareInstallation/FormPackage.resx | 18 ++ .../FormPackageComponent.Designer.cs | 117 ++++----- SoftwareInstallation/FormPackageComponent.cs | 18 +- SoftwareInstallation/FormPackages.Designer.cs | 38 +-- SoftwareInstallation/FormPackages.cs | 39 +-- SoftwareInstallation/Program.cs | 17 +- SoftwareInstallation/SoftwareInstallation.sln | 8 +- ...csproj => SoftwareInstallationView.csproj} | 1 + SoftwareInstallation/nlog.config | 2 +- .../DataFileSingleton.cs | 54 ++++ .../Implements/ComponentStorage.cs | 78 ++++++ .../Implements/OrderStorage.cs | 96 +++++++ .../Implements/TravelStorage.cs | 82 ++++++ .../Models/Component.cs | 64 +++++ .../Models/Order.cs | 104 ++++++++ .../Models/Package.cs | 95 +++++++ .../SoftwareInstallationFileImplement.csproj | 14 ++ 28 files changed, 1301 insertions(+), 649 deletions(-) rename SoftwareInstallation/{SoftwareInstallation.csproj => SoftwareInstallationView.csproj} (89%) create mode 100644 SoftwareInstallationFileImplement/DataFileSingleton.cs create mode 100644 SoftwareInstallationFileImplement/Implements/ComponentStorage.cs create mode 100644 SoftwareInstallationFileImplement/Implements/OrderStorage.cs create mode 100644 SoftwareInstallationFileImplement/Implements/TravelStorage.cs create mode 100644 SoftwareInstallationFileImplement/Models/Component.cs create mode 100644 SoftwareInstallationFileImplement/Models/Order.cs create mode 100644 SoftwareInstallationFileImplement/Models/Package.cs create mode 100644 SoftwareInstallationFileImplement/SoftwareInstallationFileImplement.csproj diff --git a/SoftwareInstallation/FormComponent.Designer.cs b/SoftwareInstallation/FormComponent.Designer.cs index 9f6e489..fae63e4 100644 --- a/SoftwareInstallation/FormComponent.Designer.cs +++ b/SoftwareInstallation/FormComponent.Designer.cs @@ -1,4 +1,4 @@ -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { partial class FormComponent { @@ -28,96 +28,95 @@ /// private void InitializeComponent() { - labelName = new Label(); - textBoxName = new TextBox(); - textBoxCost = new TextBox(); - labelCost = new Label(); buttonSave = new Button(); buttonCancel = new Button(); + label1 = new Label(); + label2 = new Label(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); SuspendLayout(); // - // labelName - // - labelName.AutoSize = true; - labelName.Location = new Point(21, 22); - labelName.Name = "labelName"; - labelName.Size = new Size(62, 15); - labelName.TabIndex = 0; - labelName.Text = "Название:"; - // - // textBoxName - // - textBoxName.Location = new Point(103, 20); - textBoxName.Margin = new Padding(3, 2, 3, 2); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(267, 23); - textBoxName.TabIndex = 1; - // - // textBoxCost - // - textBoxCost.Location = new Point(103, 49); - textBoxCost.Margin = new Padding(3, 2, 3, 2); - textBoxCost.Name = "textBoxCost"; - textBoxCost.Size = new Size(163, 23); - textBoxCost.TabIndex = 3; - // - // labelCost - // - labelCost.AutoSize = true; - labelCost.Location = new Point(21, 52); - labelCost.Name = "labelCost"; - labelCost.Size = new Size(35, 15); - labelCost.TabIndex = 2; - labelCost.Text = "Цена"; - // // buttonSave // - buttonSave.Location = new Point(190, 89); - buttonSave.Margin = new Padding(3, 2, 3, 2); + buttonSave.Location = new Point(217, 119); + buttonSave.Margin = new Padding(3, 4, 3, 4); buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(86, 26); - buttonSave.TabIndex = 4; + buttonSave.Size = new Size(98, 34); + buttonSave.TabIndex = 0; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; + buttonSave.Click += buttonSave_Click; // // buttonCancel // - buttonCancel.Location = new Point(284, 89); - buttonCancel.Margin = new Padding(3, 2, 3, 2); + buttonCancel.Location = new Point(325, 119); + buttonCancel.Margin = new Padding(3, 4, 3, 4); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(86, 26); - buttonCancel.TabIndex = 5; + buttonCancel.Size = new Size(98, 34); + buttonCancel.TabIndex = 1; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; + buttonCancel.Click += buttonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(24, 30); + label1.Name = "label1"; + label1.Size = new Size(80, 20); + label1.TabIndex = 2; + label1.Text = "Название:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(24, 69); + label2.Name = "label2"; + label2.Size = new Size(48, 20); + label2.TabIndex = 3; + label2.Text = "Цена:"; + // + // textBoxName + // + textBoxName.Location = new Point(118, 26); + textBoxName.Margin = new Padding(3, 4, 3, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(305, 27); + textBoxName.TabIndex = 4; + // + // textBoxCost + // + textBoxCost.Location = new Point(118, 65); + textBoxCost.Margin = new Padding(3, 4, 3, 4); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(186, 27); + textBoxCost.TabIndex = 5; // // FormComponent // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(404, 130); + ClientSize = new Size(462, 174); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(label2); + Controls.Add(label1); Controls.Add(buttonCancel); Controls.Add(buttonSave); - Controls.Add(textBoxCost); - Controls.Add(labelCost); - Controls.Add(textBoxName); - Controls.Add(labelName); - Margin = new Padding(3, 2, 3, 2); + Margin = new Padding(3, 4, 3, 4); Name = "FormComponent"; Text = "Компонент"; - Load += FormComponent_Load; ResumeLayout(false); PerformLayout(); } #endregion - private Label labelName; - private TextBox textBoxName; - private TextBox textBoxCost; - private Label labelCost; private Button buttonSave; private Button buttonCancel; + private Label label1; + private Label label2; + private TextBox textBoxName; + private TextBox textBoxCost; } } \ No newline at end of file diff --git a/SoftwareInstallation/FormComponent.cs b/SoftwareInstallation/FormComponent.cs index c62d9d5..30b4bc0 100644 --- a/SoftwareInstallation/FormComponent.cs +++ b/SoftwareInstallation/FormComponent.cs @@ -1,8 +1,4 @@ -using Microsoft.Extensions.Logging; -using SoftwareInstallationContracts.BindingModels; -using SoftwareInstallationContracts.BusinessLogicsContracts; -using SoftwareInstallationContracts.SearchModels; -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -11,8 +7,13 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Microsoft.Extensions.Logging; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using Microsoft.VisualBasic.Logging; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.BindingModels; -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { public partial class FormComponent : Form { @@ -20,7 +21,6 @@ namespace SoftwareInstallationView private readonly IComponentLogic _logic; private int? _id; public int Id { set { _id = value; } } - public FormComponent(ILogger logger, IComponentLogic logic) { InitializeComponent(); @@ -34,7 +34,7 @@ namespace SoftwareInstallationView { try { - _logger.LogInformation("Получение ингридиента"); + _logger.LogInformation("Получение компонента"); var view = _logic.ReadElement(new ComponentSearchModel { Id = _id.Value @@ -47,20 +47,21 @@ namespace SoftwareInstallationView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения ингридиента"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка получения компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); } } } - private void ButtonSave_Click(object sender, EventArgs e) + private void buttonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxName.Text)) { MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Сохранение ингридиента"); + _logger.LogInformation("Сохранение компонента"); try { var model = new ComponentBindingModel @@ -80,12 +81,12 @@ namespace SoftwareInstallationView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения ингридиента"); + _logger.LogError(ex, "Ошибка сохранения компонента"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ButtonCancel_Click(object sender, EventArgs e) + private void buttonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); diff --git a/SoftwareInstallation/FormComponents.Designer.cs b/SoftwareInstallation/FormComponents.Designer.cs index b0ebeec..8be76d3 100644 --- a/SoftwareInstallation/FormComponents.Designer.cs +++ b/SoftwareInstallation/FormComponents.Designer.cs @@ -1,4 +1,4 @@ -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { partial class FormComponents { @@ -29,82 +29,80 @@ private void InitializeComponent() { dataGridView = new DataGridView(); - buttonUpdate = new Button(); - buttonDelete = new Button(); - buttonEdit = new Button(); buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // // dataGridView // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Location = new Point(-1, -2); - dataGridView.Margin = new Padding(3, 2, 3, 2); + dataGridView.Margin = new Padding(3, 4, 3, 4); dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; - dataGridView.Size = new Size(437, 426); + dataGridView.RowTemplate.Height = 24; + dataGridView.Size = new Size(499, 568); dataGridView.TabIndex = 0; // - // buttonUpdate - // - buttonUpdate.Location = new Point(459, 151); - buttonUpdate.Margin = new Padding(3, 2, 3, 2); - buttonUpdate.Name = "buttonUpdate"; - buttonUpdate.Size = new Size(109, 26); - buttonUpdate.TabIndex = 3; - buttonUpdate.Text = "Обновить"; - buttonUpdate.UseVisualStyleBackColor = true; - buttonUpdate.Click += ButtonRef_Click; - // - // buttonDelete - // - buttonDelete.Location = new Point(459, 112); - buttonDelete.Margin = new Padding(3, 2, 3, 2); - buttonDelete.Name = "buttonDelete"; - buttonDelete.Size = new Size(109, 26); - buttonDelete.TabIndex = 2; - buttonDelete.Text = "Удалить"; - buttonDelete.UseVisualStyleBackColor = true; - buttonDelete.Click += ButtonDel_Click; - // - // buttonEdit - // - buttonEdit.Location = new Point(459, 74); - buttonEdit.Margin = new Padding(3, 2, 3, 2); - buttonEdit.Name = "buttonEdit"; - buttonEdit.Size = new Size(109, 26); - buttonEdit.TabIndex = 1; - buttonEdit.Text = "Изменить"; - buttonEdit.UseVisualStyleBackColor = true; - buttonEdit.Click += ButtonUpd_Click; - // // buttonAdd // - buttonAdd.Location = new Point(459, 36); - buttonAdd.Margin = new Padding(3, 2, 3, 2); + buttonAdd.Location = new Point(525, 48); + buttonAdd.Margin = new Padding(3, 4, 3, 4); buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(109, 26); - buttonAdd.TabIndex = 0; + buttonAdd.Size = new Size(125, 35); + buttonAdd.TabIndex = 1; buttonAdd.Text = "Добавить"; buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += ButtonAdd_Click; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(525, 98); + buttonUpd.Margin = new Padding(3, 4, 3, 4); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(125, 35); + buttonUpd.TabIndex = 2; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(525, 150); + buttonDel.Margin = new Padding(3, 4, 3, 4); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(125, 35); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(525, 201); + buttonRef.Margin = new Padding(3, 4, 3, 4); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(125, 35); + buttonRef.TabIndex = 4; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; // // FormComponents // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(592, 422); - Controls.Add(buttonUpdate); - Controls.Add(buttonDelete); - Controls.Add(dataGridView); - Controls.Add(buttonEdit); + ClientSize = new Size(676, 562); + Controls.Add(buttonRef); + Controls.Add(buttonDel); + Controls.Add(buttonUpd); Controls.Add(buttonAdd); - Margin = new Padding(3, 2, 3, 2); + Controls.Add(dataGridView); + Margin = new Padding(3, 4, 3, 4); Name = "FormComponents"; Text = "Список компонентов"; Load += FormComponents_Load; @@ -115,9 +113,9 @@ #endregion private DataGridView dataGridView; - private Button buttonUpdate; - private Button buttonDelete; - private Button buttonEdit; private Button buttonAdd; + private Button buttonUpd; + private Button buttonDel; + private Button buttonRef; } } \ No newline at end of file diff --git a/SoftwareInstallation/FormComponents.cs b/SoftwareInstallation/FormComponents.cs index ad09b43..b79da69 100644 --- a/SoftwareInstallation/FormComponents.cs +++ b/SoftwareInstallation/FormComponents.cs @@ -1,15 +1,22 @@ -using Microsoft.Extensions.Logging; -using SoftwareInstallation; -using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { public partial class FormComponents : Form { private readonly ILogger _logger; private readonly IComponentLogic _logic; - public FormComponents(ILogger logger, IComponentLogic logic) { InitializeComponent(); @@ -31,20 +38,18 @@ namespace SoftwareInstallationView { dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["ComponentName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } - _logger.LogInformation("Загрузка ингридиентов"); + _logger.LogInformation("Загрузка компонентов"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки ингридиентов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка загрузки компонентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ButtonAdd_Click(object sender, EventArgs e) + private void buttonAdd_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormComponent)); if (service is FormComponent form) @@ -56,15 +61,14 @@ namespace SoftwareInstallationView } } - private void ButtonUpd_Click(object sender, EventArgs e) + 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); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); if (form.ShowDialog() == DialogResult.OK) { LoadData(); @@ -73,16 +77,15 @@ namespace SoftwareInstallationView } } - private void ButtonDel_Click(object sender, EventArgs e) + private void buttonDel_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { - if (MessageBox.Show("Удалить запись?", "Вопрос", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); - _logger.LogInformation("Удаление ингридиента"); + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление компонента"); try { if (!_logic.Delete(new ComponentBindingModel @@ -96,15 +99,13 @@ namespace SoftwareInstallationView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления ингридиента"); - MessageBox.Show(ex.Message, "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка удаления компонента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } - - private void ButtonRef_Click(object sender, EventArgs e) + private void buttonRef_Click(object sender, EventArgs e) { LoadData(); } diff --git a/SoftwareInstallation/FormCreateOrder.Designer.cs b/SoftwareInstallation/FormCreateOrder.Designer.cs index 3b8cb40..dedb200 100644 --- a/SoftwareInstallation/FormCreateOrder.Designer.cs +++ b/SoftwareInstallation/FormCreateOrder.Designer.cs @@ -1,4 +1,4 @@ -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { partial class FormCreateOrder { @@ -28,107 +28,101 @@ /// private void InitializeComponent() { - labelPackage = new Label(); - comboBoxPackage = new ComboBox(); - labelCount = new Label(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); textBoxCount = new TextBox(); - labelSum = new Label(); + comboBoxPackage= new ComboBox(); textBoxSum = new TextBox(); - buttonCancel = new Button(); buttonSave = new Button(); + buttonCancel = new Button(); SuspendLayout(); // - // labelPackage + // label1 // - labelPackage.AutoSize = true; - labelPackage.Location = new Point(19, 12); - labelPackage.Name = "labelPackage"; - labelPackage.Size = new Size(56, 15); - labelPackage.TabIndex = 0; - labelPackage.Text = "Изделие:"; + label1.AutoSize = true; + label1.Location = new Point(19, 12); + label1.Name = "label1"; + label1.Size = new Size(56, 15); + label1.TabIndex = 0; + label1.Text = "Изделие:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(19, 44); + label2.Name = "label2"; + label2.Size = new Size(75, 15); + label2.TabIndex = 1; + label2.Text = "Количество:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(19, 70); + label3.Name = "label3"; + label3.Size = new Size(48, 15); + label3.TabIndex = 2; + label3.Text = "Сумма:"; + // + // textBoxCount + // + textBoxCount.Location = new Point(103, 41); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(246, 23); + textBoxCount.TabIndex = 3; + textBoxCount.TextChanged += textBoxCount_TextChanged; // // comboBoxPackage // comboBoxPackage.FormattingEnabled = true; comboBoxPackage.Location = new Point(103, 10); - comboBoxPackage.Margin = new Padding(3, 2, 3, 2); comboBoxPackage.Name = "comboBoxPackage"; comboBoxPackage.Size = new Size(246, 23); - comboBoxPackage.TabIndex = 1; + comboBoxPackage.TabIndex = 4; comboBoxPackage.SelectedIndexChanged += ComboBoxPackage_SelectedIndexChanged; // - // labelCount - // - labelCount.AutoSize = true; - labelCount.Location = new Point(19, 44); - labelCount.Name = "labelCount"; - labelCount.Size = new Size(78, 15); - labelCount.TabIndex = 2; - labelCount.Text = "Количество: "; - // - // textBoxCount - // - textBoxCount.Location = new Point(103, 41); - textBoxCount.Margin = new Padding(3, 2, 3, 2); - textBoxCount.Name = "textBoxCount"; - textBoxCount.Size = new Size(246, 23); - textBoxCount.TabIndex = 3; - textBoxCount.TextChanged += TextBoxCount_TextChanged; - // - // labelSum - // - labelSum.AutoSize = true; - labelSum.Location = new Point(19, 70); - labelSum.Name = "labelSum"; - labelSum.Size = new Size(51, 15); - labelSum.TabIndex = 4; - labelSum.Text = "Сумма: "; - // // textBoxSum // textBoxSum.Location = new Point(103, 70); - textBoxSum.Margin = new Padding(3, 2, 3, 2); textBoxSum.Name = "textBoxSum"; textBoxSum.ReadOnly = true; textBoxSum.Size = new Size(246, 23); textBoxSum.TabIndex = 5; // - // buttonCancel - // - buttonCancel.Location = new Point(249, 101); - buttonCancel.Margin = new Padding(3, 2, 3, 2); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(94, 26); - buttonCancel.TabIndex = 6; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; - // // buttonSave // buttonSave.Location = new Point(150, 101); - buttonSave.Margin = new Padding(3, 2, 3, 2); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(94, 26); - buttonSave.TabIndex = 7; + buttonSave.TabIndex = 6; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(249, 101); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 26); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; // // FormCreateOrder // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(374, 136); - Controls.Add(buttonSave); Controls.Add(buttonCancel); + Controls.Add(buttonSave); Controls.Add(textBoxSum); - Controls.Add(labelSum); - Controls.Add(textBoxCount); - Controls.Add(labelCount); Controls.Add(comboBoxPackage); - Controls.Add(labelPackage); - Margin = new Padding(3, 2, 3, 2); + Controls.Add(textBoxCount); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); Name = "FormCreateOrder"; Text = "Заказ"; Load += FormCreateOrder_Load; @@ -138,13 +132,13 @@ #endregion - private Label labelPackage; - private ComboBox comboBoxPackage; - private Label labelCount; + private Label label1; + private Label label2; + private Label label3; private TextBox textBoxCount; - private Label labelSum; + private ComboBox comboBoxPackage; private TextBox textBoxSum; - private Button buttonCancel; private Button buttonSave; + private Button buttonCancel; } } \ No newline at end of file diff --git a/SoftwareInstallation/FormCreateOrder.cs b/SoftwareInstallation/FormCreateOrder.cs index c44aed2..2779d64 100644 --- a/SoftwareInstallation/FormCreateOrder.cs +++ b/SoftwareInstallation/FormCreateOrder.cs @@ -1,8 +1,7 @@ -using Microsoft.Extensions.Logging; -using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.SearchModels; -using SoftwareInstallationContracts.ViewModels; +using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.ComponentModel; @@ -13,15 +12,13 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { public partial class FormCreateOrder : Form { private readonly ILogger _logger; private readonly IPackageLogic _logicP; private readonly IOrderLogic _logicO; - private List? _list; - public FormCreateOrder(ILogger logger, IPackageLogic logicP, IOrderLogic logicO) { InitializeComponent(); @@ -32,17 +29,23 @@ namespace SoftwareInstallationView private void FormCreateOrder_Load(object sender, EventArgs e) { - _list = _logicP.ReadList(null); - if (_list != null) + try { - comboBoxPackage.DisplayMember = "PackageName"; - comboBoxPackage.ValueMember = "Id"; - comboBoxPackage.DataSource = _list; - comboBoxPackage.SelectedItem = null; - _logger.LogInformation("Загрузка пиццы для заказа"); + var list = _logicP.ReadList(null); + if (list != null) + { + comboBoxPackage.DisplayMember = "PackageName"; + comboBoxPackage.ValueMember = "Id"; + comboBoxPackage.DataSource = list; + comboBoxPackage.SelectedItem = null; + _logger.LogInformation("Загрузка изделий для заказа"); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка изделий"); } } - private void CalcSum() { if (comboBoxPackage.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) @@ -65,8 +68,7 @@ namespace SoftwareInstallationView } } } - - private void TextBoxCount_TextChanged(object sender, EventArgs e) + private void textBoxCount_TextChanged(object sender, EventArgs e) { CalcSum(); } @@ -76,7 +78,7 @@ namespace SoftwareInstallationView CalcSum(); } - private void ButtonSave_Click(object sender, EventArgs e) + private void buttonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxCount.Text)) { @@ -85,7 +87,7 @@ namespace SoftwareInstallationView } if (comboBoxPackage.SelectedValue == null) { - MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } _logger.LogInformation("Создание заказа"); @@ -107,15 +109,15 @@ namespace SoftwareInstallationView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка создания заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка создания заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ButtonCancel_Click(object sender, EventArgs e) + private void buttonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); } + } } diff --git a/SoftwareInstallation/FormMain.Designer.cs b/SoftwareInstallation/FormMain.Designer.cs index 2bb45a9..ddf56f8 100644 --- a/SoftwareInstallation/FormMain.Designer.cs +++ b/SoftwareInstallation/FormMain.Designer.cs @@ -1,4 +1,4 @@ -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { partial class FormMain { @@ -28,132 +28,141 @@ /// private void InitializeComponent() { - menuStrip1 = new MenuStrip(); - bookToolStripMenuItem = new ToolStripMenuItem(); + System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); + toolStrip1 = new ToolStrip(); + toolStripDropDownButton1 = new ToolStripDropDownButton(); компонентыToolStripMenuItem = new ToolStripMenuItem(); - pizzasToolStripMenuItem = new ToolStripMenuItem(); - dataGridView = new DataGridView(); + ПутёвкиToolStripMenuItem = new ToolStripMenuItem(); buttonCreateOrder = new Button(); buttonTakeOrderInWork = new Button(); buttonOrderReady = new Button(); buttonIssuedOrder = new Button(); buttonRef = new Button(); - menuStrip1.SuspendLayout(); + dataGridView = new DataGridView(); + toolStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // - // menuStrip1 + // toolStrip1 // - menuStrip1.ImageScalingSize = new Size(20, 20); - menuStrip1.Items.AddRange(new ToolStripItem[] { bookToolStripMenuItem }); - menuStrip1.Location = new Point(0, 0); - menuStrip1.Name = "menuStrip1"; - menuStrip1.Padding = new Padding(6, 3, 0, 3); - menuStrip1.Size = new Size(1107, 30); - menuStrip1.TabIndex = 0; - menuStrip1.Text = "menuStrip1"; + toolStrip1.ImageScalingSize = new Size(20, 20); + toolStrip1.Items.AddRange(new ToolStripItem[] { toolStripDropDownButton1 }); + toolStrip1.Location = new Point(0, 0); + toolStrip1.Name = "toolStrip1"; + toolStrip1.Size = new Size(1107, 27); + toolStrip1.TabIndex = 0; + toolStrip1.Text = "toolStrip1"; // - // bookToolStripMenuItem + // toolStripDropDownButton1 // - bookToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, pizzasToolStripMenuItem }); - bookToolStripMenuItem.Name = "bookToolStripMenuItem"; - bookToolStripMenuItem.Size = new Size(108, 24); - bookToolStripMenuItem.Text = "Справочник"; + toolStripDropDownButton1.DisplayStyle = ToolStripItemDisplayStyle.Text; + toolStripDropDownButton1.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, ПутёвкиToolStripMenuItem }); + toolStripDropDownButton1.Image = (Image)resources.GetObject("toolStripDropDownButton1.Image"); + toolStripDropDownButton1.ImageTransparentColor = Color.Magenta; + toolStripDropDownButton1.Name = "toolStripDropDownButton1"; + toolStripDropDownButton1.Size = new Size(108, 24); + toolStripDropDownButton1.Text = "Справочник"; // // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; компонентыToolStripMenuItem.Size = new Size(224, 26); компонентыToolStripMenuItem.Text = "Компоненты"; - компонентыToolStripMenuItem.Click += IngridentsToolStripMenuItem_Click; + компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; // - // pizzasToolStripMenuItem + // ПутёвкиToolStripMenuItem // - pizzasToolStripMenuItem.Name = "pizzasToolStripMenuItem"; - pizzasToolStripMenuItem.Size = new Size(224, 26); - pizzasToolStripMenuItem.Text = "ПО"; - pizzasToolStripMenuItem.Click += PackagesToolStripMenuItem_Click; + ПутёвкиToolStripMenuItem.Name = "ПутёвкиToolStripMenuItem"; + ПутёвкиToolStripMenuItem.Size = new Size(224, 26); + ПутёвкиToolStripMenuItem.Text = "ПО"; + ПутёвкиToolStripMenuItem.Click += консервыToolStripMenuItem_Click; + // + // buttonCreateOrder + // + buttonCreateOrder.Location = new Point(914, 75); + buttonCreateOrder.Margin = new Padding(3, 4, 3, 4); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(161, 32); + buttonCreateOrder.TabIndex = 1; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += buttonCreateOrder_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Location = new Point(914, 133); + buttonTakeOrderInWork.Margin = new Padding(3, 4, 3, 4); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(161, 32); + buttonTakeOrderInWork.TabIndex = 2; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += buttonTakeOrderInWork_Click; + // + // buttonOrderReady + // + buttonOrderReady.Location = new Point(914, 189); + buttonOrderReady.Margin = new Padding(3, 4, 3, 4); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(161, 32); + buttonOrderReady.TabIndex = 3; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += buttonOrderReady_Click; + // + // buttonIssuedOrder + // + buttonIssuedOrder.Location = new Point(914, 241); + buttonIssuedOrder.Margin = new Padding(3, 4, 3, 4); + buttonIssuedOrder.Name = "buttonIssuedOrder"; + buttonIssuedOrder.Size = new Size(161, 32); + buttonIssuedOrder.TabIndex = 4; + buttonIssuedOrder.Text = "Заказ выдан"; + buttonIssuedOrder.UseVisualStyleBackColor = true; + buttonIssuedOrder.Click += buttonIssuedOrder_Click; + // + // buttonRef + // + buttonRef.Location = new Point(914, 296); + buttonRef.Margin = new Padding(3, 4, 3, 4); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(161, 32); + buttonRef.TabIndex = 5; + buttonRef.Text = "Обновить список"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Location = new Point(0, 35); + dataGridView.Margin = new Padding(3, 4, 3, 4); dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; + dataGridView.RowTemplate.Height = 24; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.Size = new Size(872, 580); - dataGridView.TabIndex = 1; - // - // buttonCreateOrder - // - buttonCreateOrder.Location = new Point(914, 75); - buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(161, 32); - buttonCreateOrder.TabIndex = 2; - buttonCreateOrder.Text = "Создать заказ"; - buttonCreateOrder.UseVisualStyleBackColor = true; - buttonCreateOrder.Click += ButtonCreateOrder_Click; - // - // buttonTakeOrderInWork - // - buttonTakeOrderInWork.Location = new Point(914, 133); - buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; - buttonTakeOrderInWork.Size = new Size(161, 32); - buttonTakeOrderInWork.TabIndex = 3; - buttonTakeOrderInWork.Text = "Отдать на выполнение"; - buttonTakeOrderInWork.UseVisualStyleBackColor = true; - buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; - // - // buttonOrderReady - // - buttonOrderReady.Location = new Point(914, 189); - buttonOrderReady.Name = "buttonOrderReady"; - buttonOrderReady.Size = new Size(161, 32); - buttonOrderReady.TabIndex = 4; - buttonOrderReady.Text = "Заказ готов"; - buttonOrderReady.UseVisualStyleBackColor = true; - buttonOrderReady.Click += ButtonOrderReady_Click; - // - // buttonIssuedOrder - // - buttonIssuedOrder.Location = new Point(914, 241); - buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(161, 32); - buttonIssuedOrder.TabIndex = 5; - buttonIssuedOrder.Text = "Заказ выдан"; - buttonIssuedOrder.UseVisualStyleBackColor = true; - buttonIssuedOrder.Click += ButtonIssuedOrder_Click; - // - // buttonRef - // - buttonRef.Location = new Point(914, 296); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(161, 32); - buttonRef.TabIndex = 6; - buttonRef.Text = "Обновить список"; - buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += ButtonRef_Click; + dataGridView.TabIndex = 6; // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(1107, 615); + Controls.Add(dataGridView); Controls.Add(buttonRef); Controls.Add(buttonIssuedOrder); Controls.Add(buttonOrderReady); Controls.Add(buttonTakeOrderInWork); Controls.Add(buttonCreateOrder); - Controls.Add(dataGridView); - Controls.Add(menuStrip1); - MainMenuStrip = menuStrip1; + Controls.Add(toolStrip1); + Margin = new Padding(3, 4, 3, 4); Name = "FormMain"; - Text = "ПО"; + Text = "Установка ПО"; Load += FormMain_Load; - menuStrip1.ResumeLayout(false); - menuStrip1.PerformLayout(); + toolStrip1.ResumeLayout(false); + toolStrip1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); PerformLayout(); @@ -161,15 +170,15 @@ #endregion - private MenuStrip menuStrip1; - private ToolStripMenuItem bookToolStripMenuItem; - private ToolStripMenuItem компонентыToolStripMenuItem; - private ToolStripMenuItem pizzasToolStripMenuItem; - private DataGridView dataGridView; + private ToolStrip toolStrip1; private Button buttonCreateOrder; private Button buttonTakeOrderInWork; private Button buttonOrderReady; private Button buttonIssuedOrder; private Button buttonRef; + private DataGridView dataGridView; + private ToolStripDropDownButton toolStripDropDownButton1; + private ToolStripMenuItem компонентыToolStripMenuItem; + private ToolStripMenuItem ПутёвкиToolStripMenuItem; } } \ No newline at end of file diff --git a/SoftwareInstallation/FormMain.cs b/SoftwareInstallation/FormMain.cs index 28564b1..fa780a1 100644 --- a/SoftwareInstallation/FormMain.cs +++ b/SoftwareInstallation/FormMain.cs @@ -1,49 +1,54 @@ -using Microsoft.Extensions.Logging; -using SoftwareInstallation; -using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { 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["PackageId"].Visible = false; - dataGridView.Columns["PackageName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["PackageName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } + _logger.LogInformation("Загрузка заказов"); } catch (Exception ex) { _logger.LogError(ex, "Ошибка загрузки заказов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - - private void IngridentsToolStripMenuItem_Click(object sender, EventArgs e) + private void компонентыToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormComponents)); if (service is FormComponents form) @@ -51,17 +56,16 @@ namespace SoftwareInstallationView form.ShowDialog(); } } - - private void PackagesToolStripMenuItem_Click(object sender, EventArgs e) + private void консервыToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormPackages)); + if (service is FormPackages form) { form.ShowDialog(); } } - - private void ButtonCreateOrder_Click(object sender, EventArgs e) + private void buttonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); if (service is FormCreateOrder form) @@ -70,18 +74,17 @@ namespace SoftwareInstallationView LoadData(); } } - - private void ButtonTakeOrderInWork_Click(object sender, EventArgs e) + 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("Заказ No{id}. Меняется статус на 'В работе'", id); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id); try { var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { - Id = id + Id = id, }); if (!operationResult) { @@ -96,19 +99,16 @@ namespace SoftwareInstallationView } } } - - private void ButtonOrderReady_Click(object sender, EventArgs e) + 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("Заказ No{id}. Меняется статус на 'Готов'", id); + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id); try { - var operationResult = _orderLogic.FinishOrder(new OrderBindingModel - { - Id = id - }); + var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -122,13 +122,12 @@ namespace SoftwareInstallationView } } } - - private void ButtonIssuedOrder_Click(object sender, EventArgs e) + 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("Заказ No{id}. Меняется статус на 'Выдан'", id); + _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id); try { var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel @@ -139,18 +138,16 @@ namespace SoftwareInstallationView { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } - _logger.LogInformation("Заказ No{id} выдан", id); + _logger.LogInformation("Заказ №{id} выдан", id); LoadData(); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } - - private void ButtonRef_Click(object sender, EventArgs e) + private void buttonRef_Click(object sender, EventArgs e) { LoadData(); } diff --git a/SoftwareInstallation/FormMain.resx b/SoftwareInstallation/FormMain.resx index a0623c8..672dbc1 100644 --- a/SoftwareInstallation/FormMain.resx +++ b/SoftwareInstallation/FormMain.resx @@ -117,7 +117,26 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 17, 17 + + + + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 + YQUAAAAJcEhZcwAAEnQAABJ0Ad5mH3gAAAIDSURBVDhPpZLrS5NhGMb3j4SWh0oRQVExD4gonkDpg4hG + YKxG6WBogkMZKgPNCEVJFBGdGETEvgwyO9DJE5syZw3PIlPEE9pgBCLZ5XvdMB8Ew8gXbl54nuf63dd9 + 0OGSnwCahxbPRNPAPMw9Xpg6ZmF46kZZ0xSKzJPIrhpDWsVnpBhGkKx3nAX8Pv7z1zg8OoY/cITdn4fw + bf/C0kYAN3Ma/w3gWfZL5kzTKBxjWyK2DftwI9tyMYCZKXbNHaD91bLYJrDXsYbrWfUKwJrPE9M2M1Oc + VzOOpHI7Jr376Hi9ogHqFIANO0/MmmmbmSmm9a8ze+I4MrNWAdjtoJgWcx+PSzg166yZZ8xM8XvXDix9 + c4jIqFYAjoriBV9AhEPv1mH/sonogha0afbZMMZz+yreTGyhpusHwtNNCsA5U1zS4BLxzJIfg299qO32 + Ir7UJtZfftyATqeT+8o2D8JSjQrAJblrncYL7ZJ2+bfaFnC/1S1NjL3diRat7qrO7wLRP3HjWsojBeCo + mDEo5mNjuweFGvjWg2EBhCbpkW78htSHHwRyNdmgAFzPEee2iFkzayy2OLXzT4gr6UdUnlXrullsxxQ+ + kx0g8BTA3aZlButjSTyjODq/WcQcW/B/Je4OQhLvKQDnzN1mp0nnkvAhR8VuMzNrpm1mpjgkoVwB/v8D + TgDQASA1MVpwzwAAAABJRU5ErkJggg== + + + + 56 + \ No newline at end of file diff --git a/SoftwareInstallation/FormPackage.Designer.cs b/SoftwareInstallation/FormPackage.Designer.cs index 2971c3f..70b2169 100644 --- a/SoftwareInstallation/FormPackage.Designer.cs +++ b/SoftwareInstallation/FormPackage.Designer.cs @@ -1,4 +1,4 @@ -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { partial class FormPackage { @@ -28,126 +28,101 @@ /// private void InitializeComponent() { - labelName = new Label(); - textBoxName = new TextBox(); - labelPrice = new Label(); - textBoxPrice = new TextBox(); - groupBoxComponents = new GroupBox(); - buttonRef = new Button(); - buttonDel = new Button(); - buttonUpd = new Button(); + label1 = new Label(); + label2 = new Label(); buttonAdd = new Button(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonRef = new Button(); dataGridView = new DataGridView(); Number = new DataGridViewTextBoxColumn(); Component = new DataGridViewTextBoxColumn(); Count = new DataGridViewTextBoxColumn(); - buttonCancel = new Button(); + textBoxName = new TextBox(); + textBoxPrice = new TextBox(); + groupBox1 = new GroupBox(); buttonSave = new Button(); - groupBoxComponents.SuspendLayout(); + buttonCancel = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + groupBox1.SuspendLayout(); SuspendLayout(); // - // labelName + // label1 // - labelName.AutoSize = true; - labelName.Location = new Point(18, 20); - labelName.Name = "labelName"; - labelName.Size = new Size(84, 20); - labelName.TabIndex = 0; - labelName.Text = "Название: "; + label1.AutoSize = true; + label1.Location = new Point(18, 20); + label1.Name = "label1"; + label1.Size = new Size(80, 20); + label1.TabIndex = 0; + label1.Text = "Название:"; // - // textBoxName + // label2 // - textBoxName.Location = new Point(107, 19); - textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(281, 27); - textBoxName.TabIndex = 1; - // - // labelPrice - // - labelPrice.AutoSize = true; - labelPrice.Location = new Point(18, 55); - labelPrice.Name = "labelPrice"; - labelPrice.Size = new Size(90, 20); - labelPrice.TabIndex = 2; - labelPrice.Text = "Стоимость: "; - // - // textBoxPrice - // - textBoxPrice.Location = new Point(107, 52); - textBoxPrice.Name = "textBoxPrice"; - textBoxPrice.ReadOnly = true; - textBoxPrice.Size = new Size(97, 27); - textBoxPrice.TabIndex = 3; - textBoxPrice.TabStop = false; - // - // 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(16, 95); - groupBoxComponents.Name = "groupBoxComponents"; - groupBoxComponents.Size = new Size(787, 489); - groupBoxComponents.TabIndex = 4; - groupBoxComponents.TabStop = false; - groupBoxComponents.Text = "Компоненты"; - // - // buttonRef - // - buttonRef.Location = new Point(656, 231); - buttonRef.Name = "buttonRef"; - buttonRef.Size = new Size(111, 37); - buttonRef.TabIndex = 4; - buttonRef.Text = "Обновить"; - buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += ButtonRef_Click; - // - // buttonDel - // - buttonDel.Location = new Point(656, 179); - buttonDel.Name = "buttonDel"; - buttonDel.Size = new Size(111, 37); - buttonDel.TabIndex = 3; - buttonDel.Text = "Удалить"; - buttonDel.UseVisualStyleBackColor = true; - buttonDel.Click += ButtonDel_Click; - // - // buttonUpd - // - buttonUpd.Location = new Point(656, 120); - buttonUpd.Name = "buttonUpd"; - buttonUpd.Size = new Size(111, 37); - buttonUpd.TabIndex = 2; - buttonUpd.Text = "Изменить"; - buttonUpd.UseVisualStyleBackColor = true; - buttonUpd.Click += ButtonUpd_Click; + label2.AutoSize = true; + label2.Location = new Point(18, 55); + label2.Name = "label2"; + label2.Size = new Size(86, 20); + label2.TabIndex = 1; + label2.Text = "Стоимость:"; // // buttonAdd // buttonAdd.Location = new Point(656, 59); + buttonAdd.Margin = new Padding(3, 4, 3, 4); buttonAdd.Name = "buttonAdd"; buttonAdd.Size = new Size(111, 37); - buttonAdd.TabIndex = 1; + buttonAdd.TabIndex = 0; buttonAdd.Text = "Добавить"; buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += ButtonAdd_Click; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpd + // + buttonUpd.Location = new Point(656, 120); + buttonUpd.Margin = new Padding(3, 4, 3, 4); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(111, 37); + buttonUpd.TabIndex = 1; + buttonUpd.Text = "Изменить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += buttonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(656, 179); + buttonDel.Margin = new Padding(3, 4, 3, 4); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(111, 37); + buttonDel.TabIndex = 2; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonRef + // + buttonRef.Location = new Point(656, 231); + buttonRef.Margin = new Padding(3, 4, 3, 4); + buttonRef.Name = "buttonRef"; + buttonRef.Size = new Size(111, 37); + buttonRef.TabIndex = 3; + buttonRef.Text = "Обновить"; + buttonRef.UseVisualStyleBackColor = true; + buttonRef.Click += buttonRef_Click; // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Columns.AddRange(new DataGridViewColumn[] { Number, Component, Count }); dataGridView.Location = new Point(0, 27); + dataGridView.Margin = new Padding(3, 4, 3, 4); dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; + dataGridView.RowTemplate.Height = 24; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGridView.ShowEditingIcon = false; dataGridView.Size = new Size(627, 443); - dataGridView.TabIndex = 0; + dataGridView.TabIndex = 4; // // Number // @@ -173,64 +148,100 @@ Count.Name = "Count"; Count.ReadOnly = true; // - // buttonCancel + // textBoxName // - buttonCancel.Location = new Point(609, 605); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(130, 37); - buttonCancel.TabIndex = 5; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; + textBoxName.Location = new Point(107, 19); + textBoxName.Margin = new Padding(3, 4, 3, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(281, 27); + textBoxName.TabIndex = 3; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(107, 52); + textBoxPrice.Margin = new Padding(3, 4, 3, 4); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.ReadOnly = true; + textBoxPrice.Size = new Size(97, 27); + textBoxPrice.TabIndex = 4; + textBoxPrice.TabStop = false; + // + // groupBox1 + // + groupBox1.Controls.Add(buttonRef); + groupBox1.Controls.Add(buttonDel); + groupBox1.Controls.Add(dataGridView); + groupBox1.Controls.Add(buttonUpd); + groupBox1.Controls.Add(buttonAdd); + groupBox1.Location = new Point(16, 95); + groupBox1.Margin = new Padding(3, 4, 3, 4); + groupBox1.Name = "groupBox1"; + groupBox1.Padding = new Padding(3, 4, 3, 4); + groupBox1.Size = new Size(787, 489); + groupBox1.TabIndex = 5; + groupBox1.TabStop = false; + groupBox1.Text = "Компоненты"; // // buttonSave // buttonSave.Location = new Point(454, 605); + buttonSave.Margin = new Padding(3, 4, 3, 4); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(130, 37); - buttonSave.TabIndex = 6; + buttonSave.TabIndex = 0; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(609, 605); + buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(130, 37); + buttonCancel.TabIndex = 0; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; // // FormPackage // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(813, 663); - Controls.Add(buttonSave); - Controls.Add(buttonCancel); - Controls.Add(groupBoxComponents); + Controls.Add(groupBox1); Controls.Add(textBoxPrice); - Controls.Add(labelPrice); Controls.Add(textBoxName); - Controls.Add(labelName); + Controls.Add(label2); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(label1); + Margin = new Padding(3, 4, 3, 4); Name = "FormPackage"; Text = "ПО"; Load += FormPackage_Load; - groupBoxComponents.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + groupBox1.ResumeLayout(false); ResumeLayout(false); PerformLayout(); } - #endregion - private Label labelName; - private TextBox textBoxName; - private Label labelPrice; - private TextBox textBoxPrice; - private GroupBox groupBoxComponents; + private Label label1; + private Label label2; private Button buttonRef; private Button buttonDel; private Button buttonUpd; private Button buttonAdd; private DataGridView dataGridView; - private Button buttonCancel; - private Button buttonSave; + private TextBox textBoxName; + private TextBox textBoxPrice; + private GroupBox groupBox1; private DataGridViewTextBoxColumn Number; private DataGridViewTextBoxColumn Component; private DataGridViewTextBoxColumn Count; + private Button buttonSave; + private Button buttonCancel; } } \ No newline at end of file diff --git a/SoftwareInstallation/FormPackage.cs b/SoftwareInstallation/FormPackage.cs index 30ddf42..3ead7fd 100644 --- a/SoftwareInstallation/FormPackage.cs +++ b/SoftwareInstallation/FormPackage.cs @@ -1,33 +1,41 @@ -using Microsoft.Extensions.Logging; -using SoftwareInstallation; -using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationDataModels.Models; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallation; using SoftwareInstallationDataModels.Models; -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { public partial class FormPackage : Form { private readonly ILogger _logger; private readonly IPackageLogic _logic; private int? _id; - private Dictionary _PackageComponents; + private Dictionary _productComponents; public int Id { set { _id = value; } } - public FormPackage(ILogger logger, IPackageLogic logic) { InitializeComponent(); _logger = logger; _logic = logic; - _PackageComponents = new Dictionary(); + _productComponents = new Dictionary(); } - private void FormPackage_Load(object sender, EventArgs e) { if (_id.HasValue) { - _logger.LogInformation("Загрузка пиццы"); + _logger.LogInformation("Загрузка изделия"); try { var view = _logic.ReadElement(new PackageSearchModel @@ -38,29 +46,25 @@ namespace SoftwareInstallationView { textBoxName.Text = view.PackageName; textBoxPrice.Text = view.Price.ToString(); - _PackageComponents = view.PackageComponents ?? new - Dictionary(); + _productComponents = view.PackageComponents ?? new Dictionary(); LoadData(); } } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки пиццы"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка загрузки изделия"); } } } - private void LoadData() { - _logger.LogInformation("Загрузка ингредиент пиццы"); + _logger.LogInformation("Загрузка компонент изделия"); try { - if (_PackageComponents != null) + if (_productComponents != null) { dataGridView.Rows.Clear(); - foreach (var pc in _PackageComponents) + foreach (var pc in _productComponents) { dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); } @@ -69,13 +73,10 @@ namespace SoftwareInstallationView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки ингредиента пиццы"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка загрузки компонент изделия"); } } - - private void ButtonAdd_Click(object sender, EventArgs e) + private void buttonAdd_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormPackageComponent)); if (service is FormPackageComponent form) @@ -86,23 +87,20 @@ namespace SoftwareInstallationView { return; } - _logger.LogInformation("Добавление нового ингредиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); - if (_PackageComponents.ContainsKey(form.Id)) + _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); + if (_productComponents.ContainsKey(form.Id)) { - _PackageComponents[form.Id] = (form.ComponentModel, - form.Count); + _productComponents[form.Id] = (form.ComponentModel, form.Count); } else { - _PackageComponents.Add(form.Id, (form.ComponentModel, - form.Count)); + _productComponents.Add(form.Id, (form.ComponentModel, form.Count)); } LoadData(); } } } - - private void ButtonUpd_Click(object sender, EventArgs e) + private void buttonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { @@ -111,22 +109,21 @@ namespace SoftwareInstallationView { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); form.Id = id; - form.Count = _PackageComponents[id].Item2; + form.Count = _productComponents[id].Item2; if (form.ShowDialog() == DialogResult.OK) { if (form.ComponentModel == null) { return; } - _logger.LogInformation("Изменение ингредиента:{ ComponentName}-{ Count}", form.ComponentModel.ComponentName, form.Count); - _PackageComponents[form.Id] = (form.ComponentModel, form.Count); + _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); + _productComponents[form.Id] = (form.ComponentModel, form.Count); LoadData(); } } } } - - private void ButtonDel_Click(object sender, EventArgs e) + private void buttonDel_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { @@ -134,25 +131,22 @@ namespace SoftwareInstallationView { try { - _logger.LogInformation("Удаление ингредиента:{ ComponentName}-{ Count}", dataGridView.SelectedRows[0].Cells[1].Value); - _PackageComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); + _productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(); } } } - - private void ButtonRef_Click(object sender, EventArgs e) + private void buttonRef_Click(object sender, EventArgs e) { LoadData(); } - - private void ButtonSave_Click(object sender, EventArgs e) + private void buttonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxName.Text)) { @@ -164,12 +158,12 @@ namespace SoftwareInstallationView MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (_PackageComponents == null || _PackageComponents.Count == 0) + if (_productComponents == null || _productComponents.Count == 0) { - MessageBox.Show("Заполните ингредиенты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Сохранение пиццы"); + _logger.LogInformation("Сохранение изделия"); try { var model = new PackageBindingModel @@ -177,26 +171,24 @@ namespace SoftwareInstallationView Id = _id ?? 0, PackageName = textBoxName.Text, Price = Convert.ToDouble(textBoxPrice.Text), - PackageComponents = _PackageComponents + PackageComponents = _productComponents }; - var operationResult = _id.HasValue ? _logic.Update(model) : - _logic.Create(model); + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } - MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); - DialogResult = DialogResult.OK; + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения пиццы"); + _logger.LogError(ex, "Ошибка сохранения изделия"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void ButtonCancel_Click(object sender, EventArgs e) + private void buttonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); @@ -205,11 +197,11 @@ namespace SoftwareInstallationView private double CalcPrice() { double price = 0; - foreach (var elem in _PackageComponents) + foreach (var elem in _productComponents) { price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); } return Math.Round(price * 1.1, 2); } } -} +} \ No newline at end of file diff --git a/SoftwareInstallation/FormPackage.resx b/SoftwareInstallation/FormPackage.resx index af32865..27104e8 100644 --- a/SoftwareInstallation/FormPackage.resx +++ b/SoftwareInstallation/FormPackage.resx @@ -117,4 +117,22 @@ 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/SoftwareInstallation/FormPackageComponent.Designer.cs b/SoftwareInstallation/FormPackageComponent.Designer.cs index 6218708..c9af534 100644 --- a/SoftwareInstallation/FormPackageComponent.Designer.cs +++ b/SoftwareInstallation/FormPackageComponent.Designer.cs @@ -1,4 +1,4 @@ -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { partial class FormPackageComponent { @@ -28,91 +28,96 @@ /// private void InitializeComponent() { - labelComponent = new Label(); - comboBoxComponent = new ComboBox(); - labelCount = new Label(); - textBoxCount = new TextBox(); - buttonCancel = new Button(); buttonSave = new Button(); + buttonCancel = new Button(); + label1 = new Label(); + label2 = new Label(); + comboBoxComponent = new ComboBox(); + textBoxCount = new TextBox(); SuspendLayout(); // - // labelComponent + // buttonSave // - labelComponent.AutoSize = true; - labelComponent.Location = new Point(14, 19); - labelComponent.Name = "labelComponent"; - labelComponent.Size = new Size(91, 20); - labelComponent.TabIndex = 0; - labelComponent.Text = "Компонент:"; + buttonSave.Location = new Point(199, 100); + buttonSave.Margin = new Padding(3, 4, 3, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(98, 36); + buttonSave.TabIndex = 0; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += this.buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(309, 100); + buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(98, 36); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += this.buttonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(14, 19); + label1.Name = "label1"; + label1.Size = new Size(91, 20); + label1.TabIndex = 2; + label1.Text = "Компонент:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(14, 59); + label2.Name = "label2"; + label2.Size = new Size(93, 20); + label2.TabIndex = 3; + label2.Text = "Количество:"; // // comboBoxComponent // comboBoxComponent.FormattingEnabled = true; comboBoxComponent.Location = new Point(121, 12); + comboBoxComponent.Margin = new Padding(3, 4, 3, 4); comboBoxComponent.Name = "comboBoxComponent"; comboBoxComponent.Size = new Size(285, 28); - comboBoxComponent.TabIndex = 1; - // - // labelCount - // - labelCount.AutoSize = true; - labelCount.Location = new Point(14, 59); - labelCount.Name = "labelCount"; - labelCount.Size = new Size(93, 20); - labelCount.TabIndex = 2; - labelCount.Text = "Количество:"; + comboBoxComponent.TabIndex = 4; // // textBoxCount // textBoxCount.Location = new Point(121, 59); + textBoxCount.Margin = new Padding(3, 4, 3, 4); textBoxCount.Name = "textBoxCount"; textBoxCount.Size = new Size(285, 27); - textBoxCount.TabIndex = 3; + textBoxCount.TabIndex = 5; // - // buttonCancel - // - buttonCancel.Location = new Point(309, 100); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(98, 36); - buttonCancel.TabIndex = 4; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; - // - // buttonSave - // - buttonSave.Location = new Point(199, 100); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(98, 36); - buttonSave.TabIndex = 5; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += ButtonSave_Click; - // - // FormPackageComponent + // FormPackage // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(426, 149); - Controls.Add(buttonSave); - Controls.Add(buttonCancel); Controls.Add(textBoxCount); - Controls.Add(labelCount); Controls.Add(comboBoxComponent); - Controls.Add(labelComponent); - Name = "FormPackageComponent"; - Text = "ПО"; + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Margin = new Padding(3, 4, 3, 4); + Name = "FormPackage"; + Text = "Компонент ПО"; ResumeLayout(false); PerformLayout(); } #endregion - private Label labelComponent; - private ComboBox comboBoxComponent; - private Label labelCount; - private TextBox textBoxCount; - private Button buttonCancel; private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + private ComboBox comboBoxComponent; + private TextBox textBoxCount; } } \ No newline at end of file diff --git a/SoftwareInstallation/FormPackageComponent.cs b/SoftwareInstallation/FormPackageComponent.cs index e6a2b6a..96a8f17 100644 --- a/SoftwareInstallation/FormPackageComponent.cs +++ b/SoftwareInstallation/FormPackageComponent.cs @@ -11,12 +11,11 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Forms; -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { public partial class FormPackageComponent : Form { private readonly List? _list; - public int Id { get @@ -28,7 +27,6 @@ namespace SoftwareInstallationView comboBoxComponent.SelectedValue = value; } } - public IComponentModel? ComponentModel { get @@ -47,8 +45,11 @@ namespace SoftwareInstallationView return null; } } - - public int Count { get { return Convert.ToInt32(textBoxCount.Text); } set { textBoxCount.Text = value.ToString(); } } + public int Count + { + get { return Convert.ToInt32(textBoxCount.Text); } + set { textBoxCount.Text = value.ToString(); } + } public FormPackageComponent(IComponentLogic logic) { @@ -64,7 +65,7 @@ namespace SoftwareInstallationView } } - private void ButtonSave_Click(object sender, EventArgs e) + private void buttonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxCount.Text)) { @@ -73,14 +74,13 @@ namespace SoftwareInstallationView } if (comboBoxComponent.SelectedValue == null) { - MessageBox.Show("Выберите ингредиент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Выберите компонент", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult = DialogResult.OK; Close(); } - - private void ButtonCancel_Click(object sender, EventArgs e) + private void buttonCancel_Click(object sender, EventArgs e) { DialogResult = DialogResult.Cancel; Close(); diff --git a/SoftwareInstallation/FormPackages.Designer.cs b/SoftwareInstallation/FormPackages.Designer.cs index 68bfac9..49839d2 100644 --- a/SoftwareInstallation/FormPackages.Designer.cs +++ b/SoftwareInstallation/FormPackages.Designer.cs @@ -1,4 +1,4 @@ -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { partial class FormPackages { @@ -39,72 +39,78 @@ // buttonRef // buttonRef.Location = new Point(741, 180); + buttonRef.Margin = new Padding(3, 4, 3, 4); buttonRef.Name = "buttonRef"; buttonRef.Size = new Size(128, 35); - buttonRef.TabIndex = 3; + buttonRef.TabIndex = 9; buttonRef.Text = "Обновить"; buttonRef.UseVisualStyleBackColor = true; - buttonRef.Click += ButtonRef_Click; + buttonRef.Click += buttonRef_Click; // // buttonDel // buttonDel.Location = new Point(741, 129); + buttonDel.Margin = new Padding(3, 4, 3, 4); buttonDel.Name = "buttonDel"; buttonDel.Size = new Size(128, 35); - buttonDel.TabIndex = 2; + buttonDel.TabIndex = 8; buttonDel.Text = "Удалить"; buttonDel.UseVisualStyleBackColor = true; - buttonDel.Click += ButtonDel_Click; + buttonDel.Click += buttonDel_Click; // // buttonUpd // buttonUpd.Location = new Point(741, 77); + buttonUpd.Margin = new Padding(3, 4, 3, 4); buttonUpd.Name = "buttonUpd"; buttonUpd.Size = new Size(128, 35); - buttonUpd.TabIndex = 1; + buttonUpd.TabIndex = 7; buttonUpd.Text = "Изменить"; buttonUpd.UseVisualStyleBackColor = true; - buttonUpd.Click += ButtonUpd_Click; + buttonUpd.Click += buttonUpd_Click; // // buttonAdd // buttonAdd.Location = new Point(741, 27); + buttonAdd.Margin = new Padding(3, 4, 3, 4); buttonAdd.Name = "buttonAdd"; buttonAdd.Size = new Size(128, 35); - buttonAdd.TabIndex = 0; + buttonAdd.TabIndex = 6; buttonAdd.Text = "Добавить"; buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += ButtonAdd_Click; + buttonAdd.Click += buttonAdd_Click; // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; dataGridView.Location = new Point(-1, 0); + dataGridView.Margin = new Padding(3, 4, 3, 4); dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 29; + dataGridView.RowTemplate.Height = 24; dataGridView.Size = new Size(709, 568); - dataGridView.TabIndex = 2; + dataGridView.TabIndex = 5; // - // FormPackages + // SoftwareInstallation // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(895, 571); Controls.Add(buttonRef); Controls.Add(buttonDel); - Controls.Add(dataGridView); Controls.Add(buttonUpd); Controls.Add(buttonAdd); - Name = "FormPackages"; - Text = "Список ПО"; - Load += FormPackage_Load; + Controls.Add(dataGridView); + Name = "SoftwareInstallation"; + Text = "Список пакетов установок"; + Load += FormPackages_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); } #endregion + private Button buttonRef; private Button buttonDel; private Button buttonUpd; diff --git a/SoftwareInstallation/FormPackages.cs b/SoftwareInstallation/FormPackages.cs index 437f6bb..0e330db 100644 --- a/SoftwareInstallation/FormPackages.cs +++ b/SoftwareInstallation/FormPackages.cs @@ -1,15 +1,23 @@ -using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; using SoftwareInstallation; using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; -namespace SoftwareInstallationView +namespace SoftwareInstallation.Forms { public partial class FormPackages : Form { private readonly ILogger _logger; private readonly IPackageLogic _logic; - public FormPackages(ILogger logger, IPackageLogic logic) { InitializeComponent(); @@ -17,7 +25,7 @@ namespace SoftwareInstallationView _logic = logic; } - private void FormPackage_Load(object sender, EventArgs e) + private void FormPackages_Load(object sender, EventArgs e) { LoadData(); } @@ -32,19 +40,17 @@ namespace SoftwareInstallationView dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["PackageComponents"].Visible = false; - dataGridView.Columns["PackageName"].AutoSizeMode = - DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["PackageName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } - _logger.LogInformation("Загрузка пиццы"); + _logger.LogInformation("Загрузка консерв"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки пиццы"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка загрузки компонентов"); } } - private void ButtonAdd_Click(object sender, EventArgs e) + private void buttonAdd_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormPackage)); if (service is FormPackage form) @@ -56,7 +62,7 @@ namespace SoftwareInstallationView } } - private void ButtonUpd_Click(object sender, EventArgs e) + private void buttonUpd_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { @@ -72,14 +78,15 @@ namespace SoftwareInstallationView } } - private void ButtonDel_Click(object sender, EventArgs e) + 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("Удаление пиццы"); + int id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление консервы"); try { if (!_logic.Delete(new PackageBindingModel @@ -93,14 +100,14 @@ namespace SoftwareInstallationView } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления пиццы"); + _logger.LogError(ex, "Ошибка удаления консервы"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } - private void ButtonRef_Click(object sender, EventArgs e) + private void buttonRef_Click(object sender, EventArgs e) { LoadData(); } diff --git a/SoftwareInstallation/Program.cs b/SoftwareInstallation/Program.cs index 8bfbcc7..c75fcba 100644 --- a/SoftwareInstallation/Program.cs +++ b/SoftwareInstallation/Program.cs @@ -1,11 +1,11 @@ +using SoftwareInstallation.Forms; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationBusinessLogic.BusinessLogic; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -using SoftwareInstallationBusinessLogic.BusinessLogic; -using SoftwareInstallationContracts.BusinessLogicsContracts; -using SoftwareInstallationContracts.StoragesContracts; -using SoftwareInstallationListImplement.Implements; -using SoftwareInstallationView; namespace SoftwareInstallation { @@ -14,7 +14,7 @@ namespace SoftwareInstallation 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() @@ -25,9 +25,9 @@ namespace SoftwareInstallation var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); + Application.Run(_serviceProvider.GetRequiredService()); } - private static void ConfigureServices(ServiceCollection services) { services.AddLogging(option => @@ -35,14 +35,13 @@ namespace SoftwareInstallation 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(); diff --git a/SoftwareInstallation/SoftwareInstallation.sln b/SoftwareInstallation/SoftwareInstallation.sln index 2055867..4878f75 100644 --- a/SoftwareInstallation/SoftwareInstallation.sln +++ b/SoftwareInstallation/SoftwareInstallation.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.8.34525.116 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallation", "SoftwareInstallation.csproj", "{A6865B23-8593-40C9-B39E-E4837E348722}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationView", "SoftwareInstallationView.csproj", "{A6865B23-8593-40C9-B39E-E4837E348722}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationBusinessLogic", "..\SoftwareInstallationBusinessLogic\SoftwareInstallationBusinessLogic.csproj", "{2A8D4417-01AF-46D5-A1C1-B569BD9C4B24}" EndProject @@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationDataMod EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationListImplement", "..\SoftwareInstallationListImplement\SoftwareInstallationListImplement.csproj", "{9A82C09E-9721-4067-A449-D7984CBAB121}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationFileImplement", "..\SoftwareInstallationFileImplement\SoftwareInstallationFileImplement.csproj", "{11B51E5D-2FA6-4DC4-845B-8F051EC833D6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -39,6 +41,10 @@ Global {9A82C09E-9721-4067-A449-D7984CBAB121}.Debug|Any CPU.Build.0 = Debug|Any CPU {9A82C09E-9721-4067-A449-D7984CBAB121}.Release|Any CPU.ActiveCfg = Release|Any CPU {9A82C09E-9721-4067-A449-D7984CBAB121}.Release|Any CPU.Build.0 = Release|Any CPU + {11B51E5D-2FA6-4DC4-845B-8F051EC833D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {11B51E5D-2FA6-4DC4-845B-8F051EC833D6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {11B51E5D-2FA6-4DC4-845B-8F051EC833D6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {11B51E5D-2FA6-4DC4-845B-8F051EC833D6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SoftwareInstallation/SoftwareInstallation.csproj b/SoftwareInstallation/SoftwareInstallationView.csproj similarity index 89% rename from SoftwareInstallation/SoftwareInstallation.csproj rename to SoftwareInstallation/SoftwareInstallationView.csproj index 7d46116..f3e2076 100644 --- a/SoftwareInstallation/SoftwareInstallation.csproj +++ b/SoftwareInstallation/SoftwareInstallationView.csproj @@ -18,6 +18,7 @@ + diff --git a/SoftwareInstallation/nlog.config b/SoftwareInstallation/nlog.config index 85797a7..af70d20 100644 --- a/SoftwareInstallation/nlog.config +++ b/SoftwareInstallation/nlog.config @@ -5,7 +5,7 @@ autoReload="true" internalLogLevel="Info"> - + diff --git a/SoftwareInstallationFileImplement/DataFileSingleton.cs b/SoftwareInstallationFileImplement/DataFileSingleton.cs new file mode 100644 index 0000000..e22643d --- /dev/null +++ b/SoftwareInstallationFileImplement/DataFileSingleton.cs @@ -0,0 +1,54 @@ +using SoftwareInstallationFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement +{ + public class DataFileSingleton + { + private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string PackageFileName = "Package.xml"; + public List Components { get; private set; } + public List Orders { get; private set; } + public List Packages { get; private set; } + public static DataFileSingleton GetInstance() + { + if (instance == null) + { + instance = new DataFileSingleton(); + } + return instance; + } + public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement); + public void SavePackages() => SaveData(Packages, PackageFileName, "Packages", x => x.GetXElement); + public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement); + private DataFileSingleton() + { + Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!; + Packages = LoadData(PackageFileName, "Package", x => Package.Create(x)!)!; + Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!; + } + private static List? LoadData(string filename, string xmlNodeName, Func selectFunction) + { + if (File.Exists(filename)) + { + return + XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList(); + } + return new List(); + } + private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction) + { + if (data != null) + { + new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename); + } + } + } +} diff --git a/SoftwareInstallationFileImplement/Implements/ComponentStorage.cs b/SoftwareInstallationFileImplement/Implements/ComponentStorage.cs new file mode 100644 index 0000000..105a8cb --- /dev/null +++ b/SoftwareInstallationFileImplement/Implements/ComponentStorage.cs @@ -0,0 +1,78 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationFileImplement.Implements +{ + public class ComponentStorage : IComponentStorage + { + private readonly DataFileSingleton source; + public ComponentStorage() + { + source = DataFileSingleton.GetInstance(); + } + public List GetFullList() + { + return source.Components.Select(x => x.GetViewModel).ToList(); + } + public List GetFilteredList(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName)) + { + return new(); + } + return source.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList(); + } + public ComponentViewModel? GetElement(ComponentSearchModel model) + { + if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) + { + return null; + } + return source.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || + (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + public ComponentViewModel? Insert(ComponentBindingModel model) + { + model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1; + var newComponent = Component.Create(model); + if (newComponent == null) + { + return null; + } + source.Components.Add(newComponent); + source.SaveComponents(); + return newComponent.GetViewModel; + } + public ComponentViewModel? Update(ComponentBindingModel model) + { + var component = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (component == null) + { + return null; + } + component.Update(model); + source.SaveComponents(); + return component.GetViewModel; + } + public ComponentViewModel? Delete(ComponentBindingModel model) + { + var element = source.Components.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Components.Remove(element); + source.SaveComponents(); + return element.GetViewModel; + } + return null; + } + + } +} diff --git a/SoftwareInstallationFileImplement/Implements/OrderStorage.cs b/SoftwareInstallationFileImplement/Implements/OrderStorage.cs new file mode 100644 index 0000000..d83efa0 --- /dev/null +++ b/SoftwareInstallationFileImplement/Implements/OrderStorage.cs @@ -0,0 +1,96 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationFileImplement.Implements +{ + public class OrderStorage : IOrderStorage + { + private readonly DataFileSingleton source; + + public OrderStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public OrderViewModel? GetElement(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return null; + } + return GetViewModel(source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)); + } + + public List GetFilteredList(OrderSearchModel model) + { + if (!model.Id.HasValue) + { + return new(); + } + return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList(); + } + + public List GetFullList() + { + return source.Orders.Select(x => GetViewModel(x)).ToList(); + } + + public OrderViewModel? Insert(OrderBindingModel model) + { + model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1; + var newOrder = Order.Create(model); + if (newOrder == null) + { + return null; + } + source.Orders.Add(newOrder); + source.SaveOrders(); + return GetViewModel(newOrder); + } + + public OrderViewModel? Update(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return GetViewModel(order); + } + public OrderViewModel? Delete(OrderBindingModel model) + { + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + order.Update(model); + source.SaveOrders(); + return GetViewModel(order); + } + + private OrderViewModel GetViewModel(Order order) + { + var viewModel = order.GetViewModel; + foreach (var comp in source.Packages) + { + if (comp.Id == order.PackageId) + { + viewModel.PackageName = comp.PackageName; + break; + } + } + return viewModel; + } + } +} diff --git a/SoftwareInstallationFileImplement/Implements/TravelStorage.cs b/SoftwareInstallationFileImplement/Implements/TravelStorage.cs new file mode 100644 index 0000000..67cc3f1 --- /dev/null +++ b/SoftwareInstallationFileImplement/Implements/TravelStorage.cs @@ -0,0 +1,82 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationFileImplement.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftwareInstallationFileImplement.Implements +{ + public class PackageStorage : IPackageStorage + { + private readonly DataFileSingleton source; + + public PackageStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public PackageViewModel? GetElement(PackageSearchModel model) + { + if (string.IsNullOrEmpty(model.PackageName) && !model.Id.HasValue) + { + return null; + } + return source.Packages.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PackageName) && x.PackageName == model.PackageName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel; + } + + public List GetFilteredList(PackageSearchModel model) + { + if (string.IsNullOrEmpty(model.PackageName)) + { + return new(); + } + return source.Packages.Where(x => x.PackageName.Contains(model.PackageName)).Select(x => x.GetViewModel).ToList(); + } + + public List GetFullList() + { + return source.Packages.Select(x => x.GetViewModel).ToList(); + } + + public PackageViewModel? Insert(PackageBindingModel model) + { + model.Id = source.Packages.Count > 0 ? source.Packages.Max(x => x.Id) + 1 : 1; + var newDoc = Package.Create(model); + if (newDoc == null) + { + return null; + } + source.Packages.Add(newDoc); + source.SavePackages(); + return newDoc.GetViewModel; + } + + public PackageViewModel? Update(PackageBindingModel model) + { + var document = source.Packages.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + source.SavePackages(); + return document.GetViewModel; + } + public PackageViewModel? Delete(PackageBindingModel model) + { + var document = source.Packages.FirstOrDefault(x => x.Id == model.Id); + if (document == null) + { + return null; + } + document.Update(model); + source.SavePackages(); + return document.GetViewModel; + } + } +} diff --git a/SoftwareInstallationFileImplement/Models/Component.cs b/SoftwareInstallationFileImplement/Models/Component.cs new file mode 100644 index 0000000..fe76abf --- /dev/null +++ b/SoftwareInstallationFileImplement/Models/Component.cs @@ -0,0 +1,64 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement.Models +{ + public class Component : IComponentModel + { + public int Id { get; private set; } + public string ComponentName { get; private set; } = string.Empty; + public double Cost { get; set; } + public static Component? Create(ComponentBindingModel model) + { + if (model == null) + { + return null; + } + return new Component() + { + Id = model.Id, + ComponentName = model.ComponentName, + Cost = model.Cost + }; + } + public static Component? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Component() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ComponentName = element.Element("ComponentName")!.Value, + Cost = Convert.ToDouble(element.Element("Cost")!.Value) + }; + } + public void Update(ComponentBindingModel model) + { + if (model == null) + { + return; + } + ComponentName = model.ComponentName; + Cost = model.Cost; + } + public ComponentViewModel GetViewModel => new() + { + Id = Id, + ComponentName = ComponentName, + Cost = Cost + }; + public XElement GetXElement => new("Component", + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); + } +} diff --git a/SoftwareInstallationFileImplement/Models/Order.cs b/SoftwareInstallationFileImplement/Models/Order.cs new file mode 100644 index 0000000..20132c7 --- /dev/null +++ b/SoftwareInstallationFileImplement/Models/Order.cs @@ -0,0 +1,104 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Enums; +using SoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement.Models +{ + public class Order : IOrderModel + { + public int PackageId { get; private set; } + + public int Count { get; private set; } + + public double Sum { get; private set; } + + public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен; + + public DateTime DateCreate { get; private set; } = DateTime.Now; + + public DateTime? DateImplement { get; private set; } + + public int Id { get; private set; } + + public static Order? Create(OrderBindingModel? model) + { + if (model == null) + { + return null; + } + return new Order() + { + Id = model.Id, + PackageId = model.PackageId, + Count = model.Count, + Sum = model.Sum, + Status = model.Status, + DateCreate = model.DateCreate, + DateImplement = model.DateImplement + }; + } + + public static Order? Create(XElement element) + { + if (element == null) + { + return null; + } + var order = new Order() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + PackageId = Convert.ToInt32(element.Element("PackageId")!.Value), + Count = Convert.ToInt32(element.Element("Count")!.Value), + Sum = Convert.ToDouble(element.Element("Sum")!.Value), + DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null), + }; + DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl); + + order.DateImplement = dateImpl; + + if (!Enum.TryParse(element.Element("Status")!.Value, out OrderStatus status)) + { + return null; + } + order.Status = status; + return order; + } + + public void Update(OrderBindingModel? model) + { + if (model == null) + { + return; + } + Status = model.Status; + DateImplement = model.DateImplement; + } + + public OrderViewModel GetViewModel => new() + { + Id = Id, + PackageId = PackageId, + Count = Count, + Sum = Sum, + Status = Status, + DateCreate = DateCreate, + DateImplement = DateImplement + }; + + public XElement GetXElement => new("Order", + new XAttribute("Id", Id), + new XElement("PackageId", PackageId), + new XElement("Count", Count.ToString()), + new XElement("Sum", Sum.ToString()), + new XElement("Status", Status.ToString()), + new XElement("DateCreate", DateCreate.ToString()), + new XElement("DateImplement", DateImplement.ToString())); + } +} diff --git a/SoftwareInstallationFileImplement/Models/Package.cs b/SoftwareInstallationFileImplement/Models/Package.cs new file mode 100644 index 0000000..7d04cd7 --- /dev/null +++ b/SoftwareInstallationFileImplement/Models/Package.cs @@ -0,0 +1,95 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement.Models +{ + public class Package : IPackageModel + { + public int Id { get; private set; } + public string PackageName { get; private set; } = string.Empty; + public double Price { get; private set; } + public Dictionary Components { get; private set; } = new(); + private Dictionary? _PackageComponents = null; + public Dictionary PackageComponents + { + get + { + if (_PackageComponents == null) + { + var source = DataFileSingleton.GetInstance(); + _PackageComponents = Components.ToDictionary(x => x.Key, y => + ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, + y.Value)); + } + return _PackageComponents; + } + } + public static Package? Create(PackageBindingModel model) + { + if (model == null) + { + return null; + } + return new Package() + { + Id = model.Id, + PackageName = model.PackageName, + Price = model.Price, + Components = model.PackageComponents.ToDictionary(x => x.Key, x + => x.Value.Item2) + }; + } + public static Package? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Package() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + PackageName = element.Element("PackageName")!.Value, + Price = Convert.ToDouble(element.Element("Price")!.Value), + Components = + element.Element("PackageComponents")!.Elements("PackageComponent") + .ToDictionary(x => + Convert.ToInt32(x.Element("Key")?.Value), x => + Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + public void Update(PackageBindingModel model) + { + if (model == null) + { + return; + } + PackageName = model.PackageName; + Price = model.Price; + Components = model.PackageComponents.ToDictionary(x => x.Key, x => + x.Value.Item2); + _PackageComponents = null; + } + public PackageViewModel GetViewModel => new() + { + Id = Id, + PackageName = PackageName, + Price = Price, + PackageComponents = PackageComponents + }; + public XElement GetXElement => new("Package", + new XAttribute("Id", Id), + new XElement("PackageName", PackageName), + new XElement("Price", Price.ToString()), + new XElement("PackageComponents", Components.Select(x => new XElement("PackageComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))) + + .ToArray())); + + } +} diff --git a/SoftwareInstallationFileImplement/SoftwareInstallationFileImplement.csproj b/SoftwareInstallationFileImplement/SoftwareInstallationFileImplement.csproj new file mode 100644 index 0000000..3a28f9a --- /dev/null +++ b/SoftwareInstallationFileImplement/SoftwareInstallationFileImplement.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + +