diff --git a/SoftwareInstallation/FormComponent.Designer.cs b/SoftwareInstallation/FormComponent.Designer.cs index fae63e4..7a7ad50 100644 --- a/SoftwareInstallation/FormComponent.Designer.cs +++ b/SoftwareInstallation/FormComponent.Designer.cs @@ -1,4 +1,4 @@ -namespace SoftwareInstallation.Forms +namespace SoftwareInstallationView { partial class FormComponent { @@ -28,95 +28,96 @@ /// private void InitializeComponent() { - buttonSave = new Button(); - buttonCancel = new Button(); - label1 = new Label(); - label2 = new Label(); + labelName = new Label(); + labelCost = new Label(); textBoxName = new TextBox(); textBoxCost = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); SuspendLayout(); // - // buttonSave + // labelName // - buttonSave.Location = new Point(217, 119); - buttonSave.Margin = new Padding(3, 4, 3, 4); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(98, 34); - buttonSave.TabIndex = 0; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += buttonSave_Click; + labelName.AutoSize = true; + labelName.Location = new Point(14, 10); + labelName.Name = "labelName"; + labelName.Size = new Size(65, 15); + labelName.TabIndex = 0; + labelName.Text = "Название :"; // - // buttonCancel + // labelCost // - buttonCancel.Location = new Point(325, 119); - buttonCancel.Margin = new Padding(3, 4, 3, 4); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(98, 34); - buttonCancel.TabIndex = 1; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - 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 = "Цена:"; + labelCost.AutoSize = true; + labelCost.Location = new Point(14, 39); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(41, 15); + labelCost.TabIndex = 1; + labelCost.Text = "Цена :"; // // textBoxName // - textBoxName.Location = new Point(118, 26); - textBoxName.Margin = new Padding(3, 4, 3, 4); + textBoxName.Location = new Point(91, 7); + textBoxName.Margin = new Padding(4, 3, 4, 3); textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(305, 27); - textBoxName.TabIndex = 4; + textBoxName.Size = new Size(252, 23); + textBoxName.TabIndex = 2; // // textBoxCost // - textBoxCost.Location = new Point(118, 65); - textBoxCost.Margin = new Padding(3, 4, 3, 4); + textBoxCost.Location = new Point(91, 36); + textBoxCost.Margin = new Padding(4, 3, 4, 3); textBoxCost.Name = "textBoxCost"; - textBoxCost.Size = new Size(186, 27); - textBoxCost.TabIndex = 5; + textBoxCost.Size = new Size(129, 23); + textBoxCost.TabIndex = 4; + // + // buttonSave + // + buttonSave.Location = new Point(162, 71); + buttonSave.Margin = new Padding(4, 3, 4, 3); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(88, 27); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(260, 71); + buttonCancel.Margin = new Padding(4, 3, 4, 3); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(88, 27); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // // FormComponent // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(462, 174); - Controls.Add(textBoxCost); - Controls.Add(textBoxName); - Controls.Add(label2); - Controls.Add(label1); + ClientSize = new Size(364, 110); Controls.Add(buttonCancel); Controls.Add(buttonSave); - Margin = new Padding(3, 4, 3, 4); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(labelCost); + Controls.Add(labelName); Name = "FormComponent"; + StartPosition = FormStartPosition.CenterScreen; Text = "Компонент"; + Load += FormComponent_Load; ResumeLayout(false); PerformLayout(); } #endregion - private Button buttonSave; - private Button buttonCancel; - private Label label1; - private Label label2; + private Label labelName; + private Label labelCost; private TextBox textBoxName; private TextBox textBoxCost; + private Button buttonSave; + private Button buttonCancel; } } \ No newline at end of file diff --git a/SoftwareInstallation/FormComponent.cs b/SoftwareInstallation/FormComponent.cs index 30b4bc0..6781d09 100644 --- a/SoftwareInstallation/FormComponent.cs +++ b/SoftwareInstallation/FormComponent.cs @@ -1,26 +1,20 @@ -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 Microsoft.Extensions.Logging; +using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; -using Microsoft.VisualBasic.Logging; using SoftwareInstallationContracts.SearchModels; -using SoftwareInstallationContracts.BindingModels; +using Microsoft.Extensions.Logging; -namespace SoftwareInstallation.Forms +namespace SoftwareInstallationView { public partial class FormComponent : Form { private readonly ILogger _logger; + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(ILogger logger, IComponentLogic logic) { InitializeComponent(); @@ -34,11 +28,8 @@ namespace SoftwareInstallation.Forms { try { - _logger.LogInformation("Получение компонента"); - var view = _logic.ReadElement(new ComponentSearchModel - { - Id = _id.Value - }); + _logger.LogInformation("Receiving component"); + var view = _logic.ReadElement(new ComponentSearchModel { Id = _id.Value }); if (view != null) { textBoxName.Text = view.ComponentName; @@ -47,21 +38,20 @@ namespace SoftwareInstallation.Forms } catch (Exception ex) { - _logger.LogError(ex, "Ошибка получения компонента"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + _logger.LogError(ex, "Component retrieval error"); + 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("Saving component"); try { var model = new ComponentBindingModel @@ -81,15 +71,15 @@ namespace SoftwareInstallation.Forms } catch (Exception ex) { - _logger.LogError(ex, "Ошибка сохранения компонента"); + _logger.LogError(ex, "Component saving error"); 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(); } } -} +} \ No newline at end of file diff --git a/SoftwareInstallation/FormComponents.Designer.cs b/SoftwareInstallation/FormComponents.Designer.cs index 8be76d3..b9c2e8e 100644 --- a/SoftwareInstallation/FormComponents.Designer.cs +++ b/SoftwareInstallation/FormComponents.Designer.cs @@ -1,4 +1,4 @@ -namespace SoftwareInstallation.Forms +namespace SoftwareInstallationView { partial class FormComponents { @@ -28,83 +28,89 @@ /// private void InitializeComponent() { - dataGridView = new DataGridView(); - buttonAdd = new Button(); buttonUpd = new Button(); buttonDel = new Button(); - buttonRef = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(-1, -2); - dataGridView.Margin = new Padding(3, 4, 3, 4); - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 24; - dataGridView.Size = new Size(499, 568); - dataGridView.TabIndex = 0; - // - // buttonAdd - // - buttonAdd.Location = new Point(525, 48); - buttonAdd.Margin = new Padding(3, 4, 3, 4); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(125, 35); - buttonAdd.TabIndex = 1; - buttonAdd.Text = "Добавить"; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += buttonAdd_Click; - // // buttonUpd // - buttonUpd.Location = new Point(525, 98); - buttonUpd.Margin = new Padding(3, 4, 3, 4); + buttonUpd.Location = new Point(432, 152); + buttonUpd.Margin = new Padding(4, 3, 4, 3); buttonUpd.Name = "buttonUpd"; - buttonUpd.Size = new Size(125, 35); - buttonUpd.TabIndex = 2; - buttonUpd.Text = "Изменить"; + buttonUpd.Size = new Size(88, 27); + buttonUpd.TabIndex = 4; + buttonUpd.Text = "Обновить"; buttonUpd.UseVisualStyleBackColor = true; - buttonUpd.Click += buttonUpd_Click; + buttonUpd.Click += ButtonUpd_Click; // // buttonDel // - buttonDel.Location = new Point(525, 150); - buttonDel.Margin = new Padding(3, 4, 3, 4); + buttonDel.Location = new Point(432, 105); + buttonDel.Margin = new Padding(4, 3, 4, 3); buttonDel.Name = "buttonDel"; - buttonDel.Size = new Size(125, 35); + buttonDel.Size = new Size(88, 27); buttonDel.TabIndex = 3; buttonDel.Text = "Удалить"; buttonDel.UseVisualStyleBackColor = true; - buttonDel.Click += buttonDel_Click; + buttonDel.Click += ButtonDel_Click; // - // buttonRef + // buttonEdit // - 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; + buttonEdit.Location = new Point(432, 58); + buttonEdit.Margin = new Padding(4, 3, 4, 3); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(88, 27); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(432, 14); + buttonAdd.Margin = new Padding(4, 3, 4, 3); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(88, 27); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(4, 3, 4, 3); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(408, 360); + dataGridView.TabIndex = 0; // // FormComponents // - AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(676, 562); - Controls.Add(buttonRef); - Controls.Add(buttonDel); + ClientSize = new Size(541, 360); Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); Controls.Add(buttonAdd); Controls.Add(dataGridView); - Margin = new Padding(3, 4, 3, 4); + Margin = new Padding(4, 3, 4, 3); Name = "FormComponents"; - Text = "Список компонентов"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Компоненты"; Load += FormComponents_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); @@ -112,10 +118,10 @@ #endregion - private DataGridView dataGridView; - private Button buttonAdd; private Button buttonUpd; private Button buttonDel; - private Button buttonRef; + private Button buttonEdit; + private Button buttonAdd; + private DataGridView dataGridView; } } \ No newline at end of file diff --git a/SoftwareInstallation/FormComponents.cs b/SoftwareInstallation/FormComponents.cs index b79da69..baaff13 100644 --- a/SoftwareInstallation/FormComponents.cs +++ b/SoftwareInstallation/FormComponents.cs @@ -1,22 +1,15 @@ 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 SoftwareInstallation.Forms +namespace SoftwareInstallationView { public partial class FormComponents : Form { private readonly ILogger _logger; + private readonly IComponentLogic _logic; + public FormComponents(ILogger logger, IComponentLogic logic) { InitializeComponent(); @@ -40,16 +33,16 @@ namespace SoftwareInstallation.Forms dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; } - _logger.LogInformation("Загрузка компонентов"); + _logger.LogInformation("Components loading"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонентов"); + _logger.LogError(ex, "Components loading error"); 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) @@ -61,7 +54,7 @@ namespace SoftwareInstallation.Forms } } - private void buttonUpd_Click(object sender, EventArgs e) + private void ButtonEdit_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { @@ -77,21 +70,17 @@ namespace SoftwareInstallation.Forms } } - 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("Deletion of component"); try { - if (!_logic.Delete(new ComponentBindingModel - { - Id = id - })) + if (!_logic.Delete(new ComponentBindingModel { Id = id })) { throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); } @@ -99,15 +88,16 @@ namespace SoftwareInstallation.Forms } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления компонента"); + _logger.LogError(ex, "Component deletion error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } - private void buttonRef_Click(object sender, EventArgs e) + + private void ButtonUpd_Click(object sender, EventArgs e) { LoadData(); } } -} +} \ No newline at end of file diff --git a/SoftwareInstallation/FormComponents.resx b/SoftwareInstallation/FormComponents.resx index af32865..1af7de1 100644 --- a/SoftwareInstallation/FormComponents.resx +++ b/SoftwareInstallation/FormComponents.resx @@ -1,17 +1,17 @@  - diff --git a/SoftwareInstallation/FormCreateOrder.Designer.cs b/SoftwareInstallation/FormCreateOrder.Designer.cs index dedb200..a5da16d 100644 --- a/SoftwareInstallation/FormCreateOrder.Designer.cs +++ b/SoftwareInstallation/FormCreateOrder.Designer.cs @@ -1,4 +1,4 @@ -namespace SoftwareInstallation.Forms +namespace SoftwareInstallationView { partial class FormCreateOrder { @@ -28,102 +28,113 @@ /// private void InitializeComponent() { - label1 = new Label(); - label2 = new Label(); - label3 = new Label(); + labelPackage = new Label(); + comboBoxPackage = new ComboBox(); + labelCount = new Label(); textBoxCount = new TextBox(); - comboBoxPackage= new ComboBox(); + labelSum = new Label(); textBoxSum = new TextBox(); buttonSave = new Button(); buttonCancel = new Button(); SuspendLayout(); // - // label1 + // labelPackage // - 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; + labelPackage.AutoSize = true; + labelPackage.Location = new Point(16, 13); + labelPackage.Margin = new Padding(5, 0, 5, 0); + labelPackage.Name = "labelPackage"; + labelPackage.Size = new Size(34, 20); + labelPackage.TabIndex = 1; + labelPackage.Text = "ПО:"; // // comboBoxPackage // + comboBoxPackage.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxPackage.FormattingEnabled = true; - comboBoxPackage.Location = new Point(103, 10); + comboBoxPackage.Location = new Point(117, 9); + comboBoxPackage.Margin = new Padding(5, 4, 5, 4); comboBoxPackage.Name = "comboBoxPackage"; - comboBoxPackage.Size = new Size(246, 23); - comboBoxPackage.TabIndex = 4; + comboBoxPackage.Size = new Size(287, 28); + comboBoxPackage.TabIndex = 2; comboBoxPackage.SelectedIndexChanged += ComboBoxPackage_SelectedIndexChanged; // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(16, 56); + labelCount.Margin = new Padding(5, 0, 5, 0); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(97, 20); + labelCount.TabIndex = 3; + labelCount.Text = "Количество :"; + // + // textBoxCount + // + textBoxCount.Location = new Point(117, 51); + textBoxCount.Margin = new Padding(5, 4, 5, 4); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(287, 27); + textBoxCount.TabIndex = 4; + textBoxCount.TextChanged += TextBoxCount_TextChanged; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(16, 96); + labelSum.Margin = new Padding(5, 0, 5, 0); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(62, 20); + labelSum.TabIndex = 5; + labelSum.Text = "Сумма :"; + // // textBoxSum // - textBoxSum.Location = new Point(103, 70); + textBoxSum.Location = new Point(117, 91); + textBoxSum.Margin = new Padding(5, 4, 5, 4); textBoxSum.Name = "textBoxSum"; textBoxSum.ReadOnly = true; - textBoxSum.Size = new Size(246, 23); - textBoxSum.TabIndex = 5; + textBoxSum.Size = new Size(287, 27); + textBoxSum.TabIndex = 6; // // buttonSave // - buttonSave.Location = new Point(150, 101); + buttonSave.Location = new Point(184, 131); + buttonSave.Margin = new Padding(5, 4, 5, 4); buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(94, 26); - buttonSave.TabIndex = 6; + buttonSave.Size = new Size(101, 36); + buttonSave.TabIndex = 7; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += buttonSave_Click; + buttonSave.Click += ButtonSave_Click; // // buttonCancel // - buttonCancel.Location = new Point(249, 101); + buttonCancel.Location = new Point(291, 131); + buttonCancel.Margin = new Padding(5, 4, 5, 4); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(94, 26); - buttonCancel.TabIndex = 7; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 8; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += buttonCancel_Click; + buttonCancel.Click += ButtonCancel_Click; // // FormCreateOrder // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(374, 136); + ClientSize = new Size(424, 181); Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(textBoxSum); - Controls.Add(comboBoxPackage); + Controls.Add(labelSum); Controls.Add(textBoxCount); - Controls.Add(label3); - Controls.Add(label2); - Controls.Add(label1); + Controls.Add(labelCount); + Controls.Add(comboBoxPackage); + Controls.Add(labelPackage); + Margin = new Padding(3, 4, 3, 4); Name = "FormCreateOrder"; + StartPosition = FormStartPosition.CenterScreen; Text = "Заказ"; Load += FormCreateOrder_Load; ResumeLayout(false); @@ -132,11 +143,11 @@ #endregion - private Label label1; - private Label label2; - private Label label3; - private TextBox textBoxCount; + private Label labelPackage; private ComboBox comboBoxPackage; + private Label labelCount; + private TextBox textBoxCount; + private Label labelSum; private TextBox textBoxSum; private Button buttonSave; private Button buttonCancel; diff --git a/SoftwareInstallation/FormCreateOrder.cs b/SoftwareInstallation/FormCreateOrder.cs index 2779d64..c32ffe0 100644 --- a/SoftwareInstallation/FormCreateOrder.cs +++ b/SoftwareInstallation/FormCreateOrder.cs @@ -1,51 +1,48 @@ 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; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -namespace SoftwareInstallation.Forms +namespace SoftwareInstallationView { public partial class FormCreateOrder : Form { private readonly ILogger _logger; - private readonly IPackageLogic _logicP; + + private readonly IPackageLogic _logicIC; + private readonly IOrderLogic _logicO; - public FormCreateOrder(ILogger logger, IPackageLogic logicP, IOrderLogic logicO) + + public FormCreateOrder(ILogger logger, IPackageLogic logicIC, IOrderLogic logicO) { InitializeComponent(); _logger = logger; - _logicP = logicP; + _logicIC = logicIC; _logicO = logicO; } private void FormCreateOrder_Load(object sender, EventArgs e) { + _logger.LogInformation("Loading ice cream for order"); try { - var list = _logicP.ReadList(null); - if (list != null) + var iceCreamList = _logicIC.ReadList(null); + if (iceCreamList != null) { comboBoxPackage.DisplayMember = "PackageName"; comboBoxPackage.ValueMember = "Id"; - comboBoxPackage.DataSource = list; + comboBoxPackage.DataSource = iceCreamList; comboBoxPackage.SelectedItem = null; - _logger.LogInformation("Загрузка изделий для заказа"); } } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки списка изделий"); + _logger.LogError(ex, "Error during loading ice cream for order"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + private void CalcSum() { if (comboBoxPackage.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text)) @@ -53,22 +50,20 @@ namespace SoftwareInstallation.Forms try { int id = Convert.ToInt32(comboBoxPackage.SelectedValue); - var Package = _logicP.ReadElement(new PackageSearchModel - { - Id = id - }); + var product = _logicIC.ReadElement(new PackageSearchModel { Id = id }); int count = Convert.ToInt32(textBoxCount.Text); - textBoxSum.Text = Math.Round(count * (Package?.Price ?? 0), 2).ToString(); - _logger.LogInformation("Расчет суммы заказа"); + textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString(); + _logger.LogInformation("Calculation of order sum"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка расчета суммы заказа"); + _logger.LogError(ex, "Calculation of order sum error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } - private void textBoxCount_TextChanged(object sender, EventArgs e) + + private void TextBoxCount_TextChanged(object sender, EventArgs e) { CalcSum(); } @@ -78,7 +73,7 @@ namespace SoftwareInstallation.Forms CalcSum(); } - private void buttonSave_Click(object sender, EventArgs e) + private void ButtonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxCount.Text)) { @@ -87,10 +82,10 @@ namespace SoftwareInstallation.Forms } if (comboBoxPackage.SelectedValue == null) { - MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Создание заказа"); + _logger.LogInformation("Order creation"); try { var operationResult = _logicO.CreateOrder(new OrderBindingModel @@ -109,15 +104,15 @@ namespace SoftwareInstallation.Forms } catch (Exception ex) { - _logger.LogError(ex, "Ошибка создания заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "Order creation error"); + 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 ddf56f8..82738eb 100644 --- a/SoftwareInstallation/FormMain.Designer.cs +++ b/SoftwareInstallation/FormMain.Designer.cs @@ -1,16 +1,16 @@ -namespace SoftwareInstallation.Forms +namespace SoftwareInstallationView { partial class FormMain { /// - /// Required designer variable. + /// Обязательная переменная конструктора. /// private System.ComponentModel.IContainer components = null; /// - /// Clean up any resources being used. + /// Освободить все используемые ресурсы. /// - /// true if managed resources should be disposed; otherwise, false. + /// истинно, если управляемый ресурс должен быть удален; иначе ложно. protected override void Dispose(bool disposing) { if (disposing && (components != null)) @@ -20,149 +20,182 @@ base.Dispose(disposing); } - #region Windows Form Designer generated code + #region Код, автоматически созданный конструктором форм Windows /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. + /// Требуемый метод для поддержки конструктора — не изменяйте + /// содержимое этого метода с помощью редактора кода. /// private void InitializeComponent() { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormMain)); - toolStrip1 = new ToolStrip(); - toolStripDropDownButton1 = new ToolStripDropDownButton(); + menuStrip = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); компонентыToolStripMenuItem = new ToolStripMenuItem(); - ПутёвкиToolStripMenuItem = new ToolStripMenuItem(); - buttonCreateOrder = new Button(); - buttonTakeOrderInWork = new Button(); - buttonOrderReady = new Button(); + мороженоеToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + пополнениеМагазинаToolStripMenuItem = new ToolStripMenuItem(); + продажаМороженогоToolStripMenuItem = new ToolStripMenuItem(); buttonIssuedOrder = new Button(); - buttonRef = new Button(); + buttonOrderReady = new Button(); + buttonTakeOrderInWork = new Button(); + buttonCreateOrder = new Button(); dataGridView = new DataGridView(); - toolStrip1.SuspendLayout(); + buttonUpd = new Button(); + menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // - // toolStrip1 + // menuStrip // - 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"; + menuStrip.ImageScalingSize = new Size(20, 20); + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, пополнениеМагазинаToolStripMenuItem, продажаМороженогоToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Padding = new Padding(8, 3, 0, 3); + menuStrip.Size = new Size(1178, 30); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip1"; // - // toolStripDropDownButton1 + // справочникиToolStripMenuItem // - 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.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, мороженоеToolStripMenuItem, магазиныToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; // // компонентыToolStripMenuItem // компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - компонентыToolStripMenuItem.Size = new Size(224, 26); + компонентыToolStripMenuItem.Size = new Size(182, 26); компонентыToolStripMenuItem.Text = "Компоненты"; - компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click; + компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click; // - // ПутёвкиToolStripMenuItem + // мороженоеToolStripMenuItem // - ПутёвкиToolStripMenuItem.Name = "ПутёвкиToolStripMenuItem"; - ПутёвкиToolStripMenuItem.Size = new Size(224, 26); - ПутёвкиToolStripMenuItem.Text = "ПО"; - ПутёвкиToolStripMenuItem.Click += консервыToolStripMenuItem_Click; + мороженоеToolStripMenuItem.Name = "мороженоеToolStripMenuItem"; + мороженоеToolStripMenuItem.Size = new Size(182, 26); + мороженоеToolStripMenuItem.Text = "ПО"; + мороженоеToolStripMenuItem.Click += МороженоеToolStripMenuItem_Click; // - // buttonCreateOrder + // магазиныToolStripMenuItem // - 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; + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(182, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += МагазиныToolStripMenuItem_Click; // - // buttonTakeOrderInWork + // пополнениеМагазинаToolStripMenuItem // - 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; + пополнениеМагазинаToolStripMenuItem.Name = "пополнениеМагазинаToolStripMenuItem"; + пополнениеМагазинаToolStripMenuItem.Size = new Size(182, 24); + пополнениеМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + пополнениеМагазинаToolStripMenuItem.Click += ПополнениеМагазинаToolStripMenuItem_Click; // - // buttonOrderReady + // продажаМороженогоToolStripMenuItem // - 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; + продажаМороженогоToolStripMenuItem.Name = "продажаМороженогоToolStripMenuItem"; + продажаМороженогоToolStripMenuItem.Size = new Size(91, 24); + продажаМороженогоToolStripMenuItem.Text = "Продажа "; + продажаМороженогоToolStripMenuItem.Click += продажаМороженогоToolStripMenuItem_Click; // // buttonIssuedOrder // - buttonIssuedOrder.Location = new Point(914, 241); - buttonIssuedOrder.Margin = new Padding(3, 4, 3, 4); + buttonIssuedOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonIssuedOrder.Location = new Point(965, 308); + buttonIssuedOrder.Margin = new Padding(5, 4, 5, 4); buttonIssuedOrder.Name = "buttonIssuedOrder"; - buttonIssuedOrder.Size = new Size(161, 32); + buttonIssuedOrder.Size = new Size(199, 36); buttonIssuedOrder.TabIndex = 4; buttonIssuedOrder.Text = "Заказ выдан"; buttonIssuedOrder.UseVisualStyleBackColor = true; - buttonIssuedOrder.Click += buttonIssuedOrder_Click; + buttonIssuedOrder.Click += ButtonIssuedOrder_Click; // - // buttonRef + // buttonOrderReady // - 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; + buttonOrderReady.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonOrderReady.Location = new Point(965, 228); + buttonOrderReady.Margin = new Padding(5, 4, 5, 4); + buttonOrderReady.Name = "buttonOrderReady"; + buttonOrderReady.Size = new Size(199, 36); + buttonOrderReady.TabIndex = 3; + buttonOrderReady.Text = "Заказ готов"; + buttonOrderReady.UseVisualStyleBackColor = true; + buttonOrderReady.Click += ButtonOrderReady_Click; + // + // buttonTakeOrderInWork + // + buttonTakeOrderInWork.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonTakeOrderInWork.Location = new Point(965, 156); + buttonTakeOrderInWork.Margin = new Padding(5, 4, 5, 4); + buttonTakeOrderInWork.Name = "buttonTakeOrderInWork"; + buttonTakeOrderInWork.Size = new Size(199, 36); + buttonTakeOrderInWork.TabIndex = 2; + buttonTakeOrderInWork.Text = "Отдать на выполнение"; + buttonTakeOrderInWork.UseVisualStyleBackColor = true; + buttonTakeOrderInWork.Click += ButtonTakeOrderInWork_Click; + // + // buttonCreateOrder + // + buttonCreateOrder.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonCreateOrder.Location = new Point(965, 77); + buttonCreateOrder.Margin = new Padding(5, 4, 5, 4); + buttonCreateOrder.Name = "buttonCreateOrder"; + buttonCreateOrder.Size = new Size(199, 36); + buttonCreateOrder.TabIndex = 1; + buttonCreateOrder.Text = "Создать заказ"; + buttonCreateOrder.UseVisualStyleBackColor = true; + buttonCreateOrder.Click += ButtonCreateOrder_Click; // // dataGridView // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 35); - dataGridView.Margin = new Padding(3, 4, 3, 4); + dataGridView.Location = new Point(0, 36); + dataGridView.Margin = new Padding(5, 4, 5, 4); + dataGridView.MultiSelect = false; dataGridView.Name = "dataGridView"; dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; dataGridView.RowHeadersWidth = 51; - dataGridView.RowTemplate.Height = 24; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(872, 580); - dataGridView.TabIndex = 6; + dataGridView.Size = new Size(944, 387); + dataGridView.TabIndex = 0; + // + // buttonUpd + // + buttonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonUpd.Location = new Point(965, 387); + buttonUpd.Margin = new Padding(5, 4, 5, 4); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(199, 36); + buttonUpd.TabIndex = 5; + buttonUpd.Text = "Обновить список"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; // // FormMain // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1107, 615); - Controls.Add(dataGridView); - Controls.Add(buttonRef); + ClientSize = new Size(1178, 463); + Controls.Add(buttonUpd); Controls.Add(buttonIssuedOrder); Controls.Add(buttonOrderReady); Controls.Add(buttonTakeOrderInWork); Controls.Add(buttonCreateOrder); - Controls.Add(toolStrip1); - Margin = new Padding(3, 4, 3, 4); + Controls.Add(dataGridView); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Margin = new Padding(5, 4, 5, 4); Name = "FormMain"; - Text = "Установка ПО"; + StartPosition = FormStartPosition.CenterScreen; + Text = "ПО"; Load += FormMain_Load; - toolStrip1.ResumeLayout(false); - toolStrip1.PerformLayout(); + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); PerformLayout(); @@ -170,15 +203,19 @@ #endregion - 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; + private System.Windows.Forms.MenuStrip menuStrip; + private System.Windows.Forms.ToolStripMenuItem справочникиToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem компонентыToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem мороженоеToolStripMenuItem; + private System.Windows.Forms.Button buttonIssuedOrder; + private System.Windows.Forms.Button buttonOrderReady; + private System.Windows.Forms.Button buttonTakeOrderInWork; + private System.Windows.Forms.Button buttonCreateOrder; + private System.Windows.Forms.DataGridView dataGridView; + private System.Windows.Forms.Button buttonUpd; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem пополнениеМагазинаToolStripMenuItem; + private ToolStripMenuItem продажаМороженогоToolStripMenuItem; } -} \ No newline at end of file +} + diff --git a/SoftwareInstallation/FormMain.cs b/SoftwareInstallation/FormMain.cs index fa780a1..0b04b56 100644 --- a/SoftwareInstallation/FormMain.cs +++ b/SoftwareInstallation/FormMain.cs @@ -1,54 +1,48 @@ 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 SoftwareInstallation.Forms +namespace SoftwareInstallationView { 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; } - - _logger.LogInformation("Загрузка заказов"); + _logger.LogInformation("Orders loading"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки заказов"); + _logger.LogError(ex, "Orders loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - private void компонентыToolStripMenuItem_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) @@ -56,16 +50,44 @@ namespace SoftwareInstallation.Forms form.ShowDialog(); } } - private void консервыToolStripMenuItem_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 МагазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void ПополнениеМагазинаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormMakeShipment)); + if (service is FormMakeShipment form) + { + form.ShowDialog(); + } + } + + private void продажаМороженогоToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormPackageSale)); + if (service is FormPackageSale form) + { + form.ShowDialog(); + } + } + + private void ButtonCreateOrder_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder)); if (service is FormCreateOrder form) @@ -74,18 +96,16 @@ namespace SoftwareInstallation.Forms 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("Заказ №{id}. Меняется статус на 'В работе'", id); + _logger.LogInformation("Order №{id}. Status changes to 'В работе'", id); try { - var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel - { - Id = id, - }); + var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel { Id = id }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); @@ -94,18 +114,18 @@ namespace SoftwareInstallation.Forms } catch (Exception ex) { - _logger.LogError(ex, "Ошибка передачи заказа в работу"); + _logger.LogError(ex, "Error taking an order to work"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } - 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("Заказ №{id}. Меняется статус на 'Готов'", id); + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Order №{id}. Status changes to 'Готов'", id); try { var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id }); @@ -117,39 +137,39 @@ namespace SoftwareInstallation.Forms } catch (Exception ex) { - _logger.LogError(ex, "Ошибка отметки о готовности заказа"); + _logger.LogError(ex, "Order readiness marking error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } - 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("Заказ №{id}. Меняется статус на 'Выдан'", id); + _logger.LogInformation("Order №{id}. Status changes to 'Выдан'", id); try { - var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel - { - Id = id - }); + var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel { Id = id }); if (!operationResult) { throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); } - _logger.LogInformation("Заказ №{id} выдан", id); + _logger.LogInformation("Order №{id} issued", id); LoadData(); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка отметки о выдачи заказа"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + _logger.LogError(ex, "Order issue marking error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } - private void buttonRef_Click(object sender, EventArgs e) + + private void ButtonUpd_Click(object sender, EventArgs e) { LoadData(); } } -} +} \ No newline at end of file diff --git a/SoftwareInstallation/FormMain.resx b/SoftwareInstallation/FormMain.resx index 672dbc1..6c82d08 100644 --- a/SoftwareInstallation/FormMain.resx +++ b/SoftwareInstallation/FormMain.resx @@ -117,26 +117,7 @@ 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/FormMakeShipment.Designer.cs b/SoftwareInstallation/FormMakeShipment.Designer.cs new file mode 100644 index 0000000..ddea11d --- /dev/null +++ b/SoftwareInstallation/FormMakeShipment.Designer.cs @@ -0,0 +1,154 @@ +namespace SoftwareInstallationView +{ + partial class FormMakeShipment + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelShop = new Label(); + comboBoxShop = new ComboBox(); + labelPackage = new Label(); + comboBoxPackage = new ComboBox(); + labelCount = new Label(); + textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelShop + // + labelShop.AutoSize = true; + labelShop.Location = new Point(16, 17); + labelShop.Margin = new Padding(5, 0, 5, 0); + labelShop.Name = "labelShop"; + labelShop.Size = new Size(76, 20); + labelShop.TabIndex = 2; + labelShop.Text = "Магазин :"; + // + // comboBoxShop + // + comboBoxShop.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxShop.FormattingEnabled = true; + comboBoxShop.Location = new Point(117, 13); + comboBoxShop.Margin = new Padding(5, 4, 5, 4); + comboBoxShop.Name = "comboBoxShop"; + comboBoxShop.Size = new Size(287, 28); + comboBoxShop.TabIndex = 5; + // + // labelPackage + // + labelPackage.AutoSize = true; + labelPackage.Location = new Point(16, 64); + labelPackage.Margin = new Padding(5, 0, 5, 0); + labelPackage.Name = "labelPackage"; + labelPackage.Size = new Size(34, 20); + labelPackage.TabIndex = 6; + labelPackage.Text = "ПО:"; + // + // comboBoxPackage + // + comboBoxPackage.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxPackage.FormattingEnabled = true; + comboBoxPackage.Location = new Point(117, 59); + comboBoxPackage.Margin = new Padding(5, 4, 5, 4); + comboBoxPackage.Name = "comboBoxPackage"; + comboBoxPackage.Size = new Size(287, 28); + comboBoxPackage.TabIndex = 7; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(16, 111); + labelCount.Margin = new Padding(5, 0, 5, 0); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(97, 20); + labelCount.TabIndex = 8; + labelCount.Text = "Количество :"; + // + // textBoxCount + // + textBoxCount.Location = new Point(117, 107); + textBoxCount.Margin = new Padding(5, 4, 5, 4); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(287, 27); + textBoxCount.TabIndex = 9; + // + // buttonSave + // + buttonSave.Location = new Point(183, 149); + buttonSave.Margin = new Padding(5, 4, 5, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 36); + buttonSave.TabIndex = 10; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(290, 149); + buttonCancel.Margin = new Padding(5, 4, 5, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 11; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormMakeShipment + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(426, 196); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(comboBoxPackage); + Controls.Add(labelPackage); + Controls.Add(comboBoxShop); + Controls.Add(labelShop); + Margin = new Padding(3, 4, 3, 4); + Name = "FormMakeShipment"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Пополнение магазина"; + Load += FormMakeShipment_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelShop; + private ComboBox comboBoxShop; + private Label labelPackage; + private ComboBox comboBoxPackage; + private Label labelCount; + private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/FormMakeShipment.cs b/SoftwareInstallation/FormMakeShipment.cs new file mode 100644 index 0000000..8f54807 --- /dev/null +++ b/SoftwareInstallation/FormMakeShipment.cs @@ -0,0 +1,116 @@ +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using Microsoft.Extensions.Logging; + +namespace SoftwareInstallationView +{ + public partial class FormMakeShipment : Form + { + private readonly ILogger _logger; + + private readonly IPackageLogic _logicPackage; + + private readonly IShopLogic _logicShop; + + public FormMakeShipment(ILogger logger, IPackageLogic logicPackage, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicPackage = logicPackage; + _logicShop = logicShop; + } + + private void FormMakeShipment_Load(object sender, EventArgs e) + { + _logger.LogInformation("Ice creams loading"); + try + { + var list = _logicPackage.ReadList(null); + if (list != null) + { + comboBoxPackage.DisplayMember = "PackageName"; + comboBoxPackage.ValueMember = "Id"; + comboBoxPackage.DataSource = list; + comboBoxPackage.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ice creams loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + _logger.LogInformation("Shops loading"); + try + { + var list = _logicShop.ReadList(null); + if (list != null) + { + comboBoxShop.DisplayMember = "ShopName"; + comboBoxShop.ValueMember = "Id"; + comboBoxShop.DataSource = list; + comboBoxShop.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shops loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (comboBoxShop.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxPackage.SelectedValue == null) + { + MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop replenishment"); + try + { + var iceCream = _logicPackage.ReadElement(new PackageSearchModel + { Id = Convert.ToInt32(comboBoxPackage.SelectedValue) }); + if (iceCream == null) + { + throw new Exception("Мороженое не найдено."); + } + var operationResult = _logicShop.MakeShipment(new ShopSearchModel + { + Id = Convert.ToInt32(comboBoxShop.SelectedValue) + }, + iceCream, + Convert.ToInt32(textBoxCount.Text)); + if (!operationResult) + { + throw new Exception("Ошибка при проведении поставки."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop replenishment error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + DialogResult = DialogResult.OK; + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SoftwareInstallation/FormMakeShipment.resx b/SoftwareInstallation/FormMakeShipment.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SoftwareInstallation/FormMakeShipment.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SoftwareInstallation/FormPackage.Designer.cs b/SoftwareInstallation/FormPackage.Designer.cs index 70b2169..10da470 100644 --- a/SoftwareInstallation/FormPackage.Designer.cs +++ b/SoftwareInstallation/FormPackage.Designer.cs @@ -1,4 +1,4 @@ -namespace SoftwareInstallation.Forms +namespace SoftwareInstallationView { partial class FormPackage { @@ -28,220 +28,227 @@ /// private void InitializeComponent() { - label1 = new Label(); - label2 = new Label(); - buttonAdd = new Button(); + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxName = new TextBox(); + labelName = new Label(); + textBoxPrice = new TextBox(); + labelPrice = new Label(); + groupBoxComponents = new GroupBox(); buttonUpd = new Button(); buttonDel = new Button(); - buttonRef = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); dataGridView = new DataGridView(); - Number = new DataGridViewTextBoxColumn(); - Component = new DataGridViewTextBoxColumn(); - Count = new DataGridViewTextBoxColumn(); - textBoxName = new TextBox(); - textBoxPrice = new TextBox(); - groupBox1 = new GroupBox(); - buttonSave = new Button(); - buttonCancel = new Button(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + groupBoxComponents.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - groupBox1.SuspendLayout(); SuspendLayout(); // - // label1 - // - label1.AutoSize = true; - label1.Location = new Point(18, 20); - label1.Name = "label1"; - label1.Size = new Size(80, 20); - label1.TabIndex = 0; - label1.Text = "Название:"; - // - // label2 - // - 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 = 0; - buttonAdd.Text = "Добавить"; - buttonAdd.UseVisualStyleBackColor = true; - 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 = 24; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.ShowEditingIcon = false; - dataGridView.Size = new Size(627, 443); - dataGridView.TabIndex = 4; - // - // Number - // - Number.HeaderText = "Номер"; - Number.MinimumWidth = 6; - Number.Name = "Number"; - Number.ReadOnly = true; - Number.Width = 60; - // - // Component - // - Component.HeaderText = "Компонент"; - Component.MinimumWidth = 6; - Component.Name = "Component"; - Component.ReadOnly = true; - Component.Width = 125; - // - // Count - // - Count.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - Count.HeaderText = "Количество"; - Count.MinimumWidth = 6; - Count.Name = "Count"; - Count.ReadOnly = true; - // - // textBoxName - // - 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 = 0; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += buttonSave_Click; - // // buttonCancel // - buttonCancel.Location = new Point(609, 605); - buttonCancel.Margin = new Padding(3, 4, 3, 4); + buttonCancel.Location = new Point(520, 483); + buttonCancel.Margin = new Padding(5, 4, 5, 4); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(130, 37); - buttonCancel.TabIndex = 0; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 6; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += buttonCancel_Click; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(411, 483); + buttonSave.Margin = new Padding(5, 4, 5, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 36); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // textBoxName + // + textBoxName.Location = new Point(105, 9); + textBoxName.Margin = new Padding(5, 4, 5, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(287, 27); + textBoxName.TabIndex = 1; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(16, 13); + labelName.Margin = new Padding(5, 0, 5, 0); + labelName.Name = "labelName"; + labelName.Size = new Size(84, 20); + labelName.TabIndex = 0; + labelName.Text = "Название :"; + // + // textBoxPrice + // + textBoxPrice.Enabled = false; + textBoxPrice.Location = new Point(105, 49); + textBoxPrice.Margin = new Padding(5, 4, 5, 4); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(167, 27); + textBoxPrice.TabIndex = 3; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(16, 53); + labelPrice.Margin = new Padding(5, 0, 5, 0); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(90, 20); + labelPrice.TabIndex = 2; + labelPrice.Text = "Стоимость :"; + // + // groupBoxComponents + // + groupBoxComponents.Controls.Add(buttonUpd); + groupBoxComponents.Controls.Add(buttonDel); + groupBoxComponents.Controls.Add(buttonEdit); + groupBoxComponents.Controls.Add(buttonAdd); + groupBoxComponents.Controls.Add(dataGridView); + groupBoxComponents.Location = new Point(16, 89); + groupBoxComponents.Margin = new Padding(5, 4, 5, 4); + groupBoxComponents.Name = "groupBoxComponents"; + groupBoxComponents.Padding = new Padding(5, 4, 5, 4); + groupBoxComponents.Size = new Size(638, 384); + groupBoxComponents.TabIndex = 4; + groupBoxComponents.TabStop = false; + groupBoxComponents.Text = "Компоненты"; + // + // buttonUpd + // + buttonUpd.Location = new Point(504, 228); + buttonUpd.Margin = new Padding(5, 4, 5, 4); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(101, 36); + buttonUpd.TabIndex = 4; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(504, 164); + buttonDel.Margin = new Padding(5, 4, 5, 4); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(101, 36); + buttonDel.TabIndex = 3; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(504, 101); + buttonEdit.Margin = new Padding(5, 4, 5, 4); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(101, 36); + buttonEdit.TabIndex = 2; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(504, 43); + buttonAdd.Margin = new Padding(5, 4, 5, 4); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(101, 36); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(5, 24); + dataGridView.Margin = new Padding(5, 4, 5, 4); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(466, 356); + dataGridView.TabIndex = 0; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + ColumnId.Visible = false; + ColumnId.Width = 125; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Компонент"; + ColumnName.MinimumWidth = 6; + ColumnName.Name = "ColumnName"; + ColumnName.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + ColumnCount.Width = 125; // // FormPackage // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(813, 663); - Controls.Add(groupBox1); + ClientSize = new Size(670, 536); + Controls.Add(groupBoxComponents); Controls.Add(textBoxPrice); - Controls.Add(textBoxName); - Controls.Add(label2); + Controls.Add(labelPrice); Controls.Add(buttonCancel); Controls.Add(buttonSave); - Controls.Add(label1); - Margin = new Padding(3, 4, 3, 4); + Controls.Add(textBoxName); + Controls.Add(labelName); + Margin = new Padding(5, 4, 5, 4); Name = "FormPackage"; - Text = "ПО"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Пакеты"; Load += FormPackage_Load; + groupBoxComponents.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - groupBox1.ResumeLayout(false); ResumeLayout(false); PerformLayout(); } #endregion - private Label label1; - private Label label2; - private Button buttonRef; - private Button buttonDel; + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxName; + private Label labelName; + private TextBox textBoxPrice; + private Label labelPrice; + private GroupBox groupBoxComponents; private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; private Button buttonAdd; private DataGridView dataGridView; - private TextBox textBoxName; - private TextBox textBoxPrice; - private GroupBox groupBox1; - private DataGridViewTextBoxColumn Number; - private DataGridViewTextBoxColumn Component; - private DataGridViewTextBoxColumn Count; - private Button buttonSave; - private Button buttonCancel; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; } } \ No newline at end of file diff --git a/SoftwareInstallation/FormPackage.cs b/SoftwareInstallation/FormPackage.cs index 3ead7fd..e4028a3 100644 --- a/SoftwareInstallation/FormPackage.cs +++ b/SoftwareInstallation/FormPackage.cs @@ -1,82 +1,78 @@ -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.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.SearchModels; -using SoftwareInstallationContracts.BindingModels; -using SoftwareInstallation; using SoftwareInstallationDataModels.Models; +using Microsoft.Extensions.Logging; -namespace SoftwareInstallation.Forms +namespace SoftwareInstallationView { public partial class FormPackage : Form { private readonly ILogger _logger; + private readonly IPackageLogic _logic; + private int? _id; - private Dictionary _productComponents; + + private Dictionary _iceCreamComponents; + public int Id { set { _id = value; } } + public FormPackage(ILogger logger, IPackageLogic logic) { InitializeComponent(); _logger = logger; _logic = logic; - _productComponents = new Dictionary(); + _iceCreamComponents = new Dictionary(); } + private void FormPackage_Load(object sender, EventArgs e) { if (_id.HasValue) { - _logger.LogInformation("Загрузка изделия"); + _logger.LogInformation("Ice cream loading"); try { - var view = _logic.ReadElement(new PackageSearchModel - { - Id = _id.Value - }); + var view = _logic.ReadElement(new PackageSearchModel { Id = _id.Value }); if (view != null) { textBoxName.Text = view.PackageName; textBoxPrice.Text = view.Price.ToString(); - _productComponents = view.PackageComponents ?? new Dictionary(); + _iceCreamComponents = view.PackageComponents ?? new Dictionary(); LoadData(); } } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки изделия"); + _logger.LogError(ex, "Ice cream loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } + private void LoadData() { - _logger.LogInformation("Загрузка компонент изделия"); + _logger.LogInformation("Ice cream components loading"); try { - if (_productComponents != null) + if (_iceCreamComponents != null) { dataGridView.Rows.Clear(); - foreach (var pc in _productComponents) + foreach (var iceCreamC in _iceCreamComponents) { - dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); + dataGridView.Rows.Add(new object[] { iceCreamC.Key, iceCreamC.Value.Item1.ComponentName, iceCreamC.Value.Item2 }); } textBoxPrice.Text = CalcPrice().ToString(); } } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонент изделия"); + _logger.LogError(ex, "Ice cream components loading error"); + 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(FormPackageComponent)); if (service is FormPackageComponent form) @@ -87,20 +83,21 @@ namespace SoftwareInstallation.Forms { return; } - _logger.LogInformation("Добавление нового компонента: { ComponentName} - { Count} ", form.ComponentModel.ComponentName, form.Count); - if (_productComponents.ContainsKey(form.Id)) + _logger.LogInformation("Adding new component: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + if (_iceCreamComponents.ContainsKey(form.Id)) { - _productComponents[form.Id] = (form.ComponentModel, form.Count); + _iceCreamComponents[form.Id] = (form.ComponentModel, form.Count); } else { - _productComponents.Add(form.Id, (form.ComponentModel, form.Count)); + _iceCreamComponents.Add(form.Id, (form.ComponentModel, form.Count)); } LoadData(); } } } - private void buttonUpd_Click(object sender, EventArgs e) + + private void ButtonEdit_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { @@ -109,21 +106,22 @@ namespace SoftwareInstallation.Forms { int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); form.Id = id; - form.Count = _productComponents[id].Item2; + form.Count = _iceCreamComponents[id].Item2; if (form.ShowDialog() == DialogResult.OK) { if (form.ComponentModel == null) { return; } - _logger.LogInformation("Изменение компонента: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - _productComponents[form.Id] = (form.ComponentModel, form.Count); + _logger.LogInformation("Component editing: {ComponentName} - {Count}", form.ComponentModel.ComponentName, form.Count); + _iceCreamComponents[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) { @@ -131,8 +129,9 @@ namespace SoftwareInstallation.Forms { try { - _logger.LogInformation("Удаление компонента: { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); - _productComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); + _logger.LogInformation("Deletion of component: {ComponentName} - {Count}", dataGridView.SelectedRows[0].Cells[1].Value, + dataGridView.SelectedRows[0].Cells[2].Value); + _iceCreamComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); } catch (Exception ex) { @@ -142,11 +141,13 @@ namespace SoftwareInstallation.Forms } } } - private void buttonRef_Click(object sender, EventArgs e) + + private void ButtonUpd_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)) { @@ -158,12 +159,12 @@ namespace SoftwareInstallation.Forms MessageBox.Show("Заполните цену", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - if (_productComponents == null || _productComponents.Count == 0) + if (_iceCreamComponents == null || _iceCreamComponents.Count == 0) { MessageBox.Show("Заполните компоненты", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } - _logger.LogInformation("Сохранение изделия"); + _logger.LogInformation("Ice cream saving"); try { var model = new PackageBindingModel @@ -171,24 +172,25 @@ namespace SoftwareInstallation.Forms Id = _id ?? 0, PackageName = textBoxName.Text, Price = Convert.ToDouble(textBoxPrice.Text), - PackageComponents = _productComponents + PackageComponents = _iceCreamComponents }; 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, "Ice cream saving error"); 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(); @@ -197,7 +199,7 @@ namespace SoftwareInstallation.Forms private double CalcPrice() { double price = 0; - foreach (var elem in _productComponents) + foreach (var elem in _iceCreamComponents) { price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); } diff --git a/SoftwareInstallation/FormPackage.resx b/SoftwareInstallation/FormPackage.resx index 27104e8..af32865 100644 --- a/SoftwareInstallation/FormPackage.resx +++ b/SoftwareInstallation/FormPackage.resx @@ -117,22 +117,4 @@ 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 c9af534..0e25d2e 100644 --- a/SoftwareInstallation/FormPackageComponent.Designer.cs +++ b/SoftwareInstallation/FormPackageComponent.Designer.cs @@ -1,4 +1,4 @@ -namespace SoftwareInstallation.Forms +namespace SoftwareInstallationView { partial class FormPackageComponent { @@ -28,84 +28,88 @@ /// private void InitializeComponent() { - buttonSave = new Button(); - buttonCancel = new Button(); - label1 = new Label(); - label2 = new Label(); + labelComponent = new Label(); + labelCount = new Label(); comboBoxComponent = new ComboBox(); textBoxCount = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); SuspendLayout(); // - // buttonSave + // labelComponent // - 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; + labelComponent.AutoSize = true; + labelComponent.Location = new Point(16, 17); + labelComponent.Margin = new Padding(5, 0, 5, 0); + labelComponent.Name = "labelComponent"; + labelComponent.Size = new Size(95, 20); + labelComponent.TabIndex = 1; + labelComponent.Text = "Компонент :"; // - // buttonCancel + // labelCount // - 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 = "Количество:"; + labelCount.AutoSize = true; + labelCount.Location = new Point(16, 64); + labelCount.Margin = new Padding(5, 0, 5, 0); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(97, 20); + labelCount.TabIndex = 3; + labelCount.Text = "Количество :"; // // comboBoxComponent // + comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxComponent.FormattingEnabled = true; - comboBoxComponent.Location = new Point(121, 12); - comboBoxComponent.Margin = new Padding(3, 4, 3, 4); + comboBoxComponent.Location = new Point(117, 13); + comboBoxComponent.Margin = new Padding(5, 4, 5, 4); comboBoxComponent.Name = "comboBoxComponent"; - comboBoxComponent.Size = new Size(285, 28); + comboBoxComponent.Size = new Size(287, 28); comboBoxComponent.TabIndex = 4; // // textBoxCount // - textBoxCount.Location = new Point(121, 59); - textBoxCount.Margin = new Padding(3, 4, 3, 4); + textBoxCount.Location = new Point(117, 59); + textBoxCount.Margin = new Padding(5, 4, 5, 4); textBoxCount.Name = "textBoxCount"; - textBoxCount.Size = new Size(285, 27); + textBoxCount.Size = new Size(287, 27); textBoxCount.TabIndex = 5; // - // FormPackage + // buttonSave + // + buttonSave.Location = new Point(183, 100); + buttonSave.Margin = new Padding(5, 4, 5, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 36); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(290, 100); + buttonCancel.Margin = new Padding(5, 4, 5, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormPackageComponent // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(426, 149); - Controls.Add(textBoxCount); - Controls.Add(comboBoxComponent); - Controls.Add(label2); - Controls.Add(label1); + ClientSize = new Size(426, 148); Controls.Add(buttonCancel); Controls.Add(buttonSave); + Controls.Add(textBoxCount); + Controls.Add(comboBoxComponent); + Controls.Add(labelCount); + Controls.Add(labelComponent); Margin = new Padding(3, 4, 3, 4); - Name = "FormPackage"; + Name = "FormPackageComponent"; + StartPosition = FormStartPosition.CenterScreen; Text = "Компонент ПО"; ResumeLayout(false); PerformLayout(); @@ -113,11 +117,11 @@ #endregion - private Button buttonSave; - private Button buttonCancel; - private Label label1; - private Label label2; + private Label labelComponent; + private Label labelCount; private ComboBox comboBoxComponent; private TextBox textBoxCount; + private Button buttonSave; + private Button buttonCancel; } } \ No newline at end of file diff --git a/SoftwareInstallation/FormPackageComponent.cs b/SoftwareInstallation/FormPackageComponent.cs index 96a8f17..5c9cb91 100644 --- a/SoftwareInstallation/FormPackageComponent.cs +++ b/SoftwareInstallation/FormPackageComponent.cs @@ -1,32 +1,15 @@ using SoftwareInstallationContracts.BusinessLogicsContracts; using SoftwareInstallationContracts.ViewModels; using SoftwareInstallationDataModels.Models; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -namespace SoftwareInstallation.Forms +namespace SoftwareInstallationView { public partial class FormPackageComponent : Form { private readonly List? _list; - public int Id - { - get - { - return Convert.ToInt32(comboBoxComponent.SelectedValue); - } - set - { - comboBoxComponent.SelectedValue = value; - } - } + + public int Id { get { return Convert.ToInt32(comboBoxComponent.SelectedValue); } set { comboBoxComponent.SelectedValue = value; } } + public IComponentModel? ComponentModel { get @@ -45,16 +28,12 @@ namespace SoftwareInstallation.Forms 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) { InitializeComponent(); - _list = logic.ReadList(null); if (_list != null) { @@ -65,7 +44,7 @@ namespace SoftwareInstallation.Forms } } - private void buttonSave_Click(object sender, EventArgs e) + private void ButtonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxCount.Text)) { @@ -77,13 +56,15 @@ namespace SoftwareInstallation.Forms 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(); } } -} +} \ No newline at end of file diff --git a/SoftwareInstallation/FormPackageSale.Designer.cs b/SoftwareInstallation/FormPackageSale.Designer.cs new file mode 100644 index 0000000..bfa9c49 --- /dev/null +++ b/SoftwareInstallation/FormPackageSale.Designer.cs @@ -0,0 +1,128 @@ +namespace SoftwareInstallationView +{ + partial class FormPackageSale + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonCancel = new Button(); + buttonSale = new Button(); + textBoxCount = new TextBox(); + labelCount = new Label(); + comboBoxPackage = new ComboBox(); + labelPackage = new Label(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Location = new Point(289, 111); + buttonCancel.Margin = new Padding(5, 4, 5, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 17; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSale + // + buttonSale.Location = new Point(182, 111); + buttonSale.Margin = new Padding(5, 4, 5, 4); + buttonSale.Name = "buttonSale"; + buttonSale.Size = new Size(101, 36); + buttonSale.TabIndex = 16; + buttonSale.Text = "Продать"; + buttonSale.UseVisualStyleBackColor = true; + buttonSale.Click += ButtonSale_Click; + // + // textBoxCount + // + textBoxCount.Location = new Point(115, 68); + textBoxCount.Margin = new Padding(5, 4, 5, 4); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(287, 27); + textBoxCount.TabIndex = 15; + // + // labelCount + // + labelCount.AutoSize = true; + labelCount.Location = new Point(15, 72); + labelCount.Margin = new Padding(5, 0, 5, 0); + labelCount.Name = "labelCount"; + labelCount.Size = new Size(97, 20); + labelCount.TabIndex = 14; + labelCount.Text = "Количество :"; + // + // comboBoxPackage + // + comboBoxPackage.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxPackage.FormattingEnabled = true; + comboBoxPackage.Location = new Point(115, 20); + comboBoxPackage.Margin = new Padding(5, 4, 5, 4); + comboBoxPackage.Name = "comboBoxPackage"; + comboBoxPackage.Size = new Size(287, 28); + comboBoxPackage.TabIndex = 13; + // + // labelPackage + // + labelPackage.AutoSize = true; + labelPackage.Location = new Point(15, 25); + labelPackage.Margin = new Padding(5, 0, 5, 0); + labelPackage.Name = "labelPackage"; + labelPackage.Size = new Size(34, 20); + labelPackage.TabIndex = 12; + labelPackage.Text = "ПО:"; + // + // FormPackageSale + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(426, 164); + Controls.Add(buttonCancel); + Controls.Add(buttonSale); + Controls.Add(textBoxCount); + Controls.Add(labelCount); + Controls.Add(comboBoxPackage); + Controls.Add(labelPackage); + Margin = new Padding(3, 4, 3, 4); + Name = "FormPackageSale"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Продажа "; + Load += FormPackageSale_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCancel; + private Button buttonSale; + private TextBox textBoxCount; + private Label labelCount; + private ComboBox comboBoxPackage; + private Label labelPackage; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/FormPackageSale.cs b/SoftwareInstallation/FormPackageSale.cs new file mode 100644 index 0000000..2d11dc6 --- /dev/null +++ b/SoftwareInstallation/FormPackageSale.cs @@ -0,0 +1,87 @@ +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.BindingModels; +using Microsoft.Extensions.Logging; + +namespace SoftwareInstallationView +{ + public partial class FormPackageSale : Form + { + private readonly ILogger _logger; + + private readonly IPackageLogic _logicPackage; + + private readonly IShopLogic _logicShop; + + public FormPackageSale(ILogger logger, IPackageLogic logicPackage, IShopLogic logicShop) + { + InitializeComponent(); + _logger = logger; + _logicPackage = logicPackage; + _logicShop = logicShop; + } + + private void FormPackageSale_Load(object sender, EventArgs e) + { + _logger.LogInformation("Ice creams loading"); + try + { + var list = _logicPackage.ReadList(null); + if (list != null) + { + comboBoxPackage.DisplayMember = "PackageName"; + comboBoxPackage.ValueMember = "Id"; + comboBoxPackage.DataSource = list; + comboBoxPackage.SelectedItem = null; + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ice creams loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSale_Click(object sender, EventArgs e) + { + if (comboBoxPackage.SelectedValue == null) + { + MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Ice cream sale"); + try + { + var operationResult = _logicShop.MakeSale( + new PackageBindingModel + { + Id = Convert.ToInt32(comboBoxPackage.SelectedValue) + }, + Convert.ToInt32(textBoxCount.Text) + ); + if (!operationResult) + { + throw new Exception("Ошибка при продаже."); + } + MessageBox.Show("Продажа прошла успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ice cream sale error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SoftwareInstallation/FormPackageSale.resx b/SoftwareInstallation/FormPackageSale.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SoftwareInstallation/FormPackageSale.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SoftwareInstallation/FormPackages.Designer.cs b/SoftwareInstallation/FormPackages.Designer.cs index 49839d2..700b0c6 100644 --- a/SoftwareInstallation/FormPackages.Designer.cs +++ b/SoftwareInstallation/FormPackages.Designer.cs @@ -1,4 +1,4 @@ -namespace SoftwareInstallation.Forms +namespace SoftwareInstallationView { partial class FormPackages { @@ -28,82 +28,90 @@ /// private void InitializeComponent() { - buttonRef = new Button(); - buttonDel = new Button(); - buttonUpd = new Button(); - buttonAdd = new Button(); dataGridView = new DataGridView(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // - // buttonRef + // dataGridView // - 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 = 9; - buttonRef.Text = "Обновить"; - buttonRef.UseVisualStyleBackColor = true; - 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 = 8; - buttonDel.Text = "Удалить"; - buttonDel.UseVisualStyleBackColor = true; - buttonDel.Click += buttonDel_Click; + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(5, 4, 5, 4); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(466, 480); + dataGridView.TabIndex = 1; // // buttonUpd // - buttonUpd.Location = new Point(741, 77); - buttonUpd.Margin = new Padding(3, 4, 3, 4); + buttonUpd.Location = new Point(494, 203); + buttonUpd.Margin = new Padding(5, 4, 5, 4); buttonUpd.Name = "buttonUpd"; - buttonUpd.Size = new Size(128, 35); - buttonUpd.TabIndex = 7; - buttonUpd.Text = "Изменить"; + buttonUpd.Size = new Size(101, 36); + buttonUpd.TabIndex = 8; + buttonUpd.Text = "Обновить"; buttonUpd.UseVisualStyleBackColor = true; - buttonUpd.Click += buttonUpd_Click; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(494, 140); + buttonDel.Margin = new Padding(5, 4, 5, 4); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(101, 36); + buttonDel.TabIndex = 7; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(494, 77); + buttonEdit.Margin = new Padding(5, 4, 5, 4); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(101, 36); + buttonEdit.TabIndex = 6; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; // // buttonAdd // - buttonAdd.Location = new Point(741, 27); - buttonAdd.Margin = new Padding(3, 4, 3, 4); + buttonAdd.Location = new Point(494, 19); + buttonAdd.Margin = new Padding(5, 4, 5, 4); buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(128, 35); - buttonAdd.TabIndex = 6; + buttonAdd.Size = new Size(101, 36); + buttonAdd.TabIndex = 5; 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 = 24; - dataGridView.Size = new Size(709, 568); - dataGridView.TabIndex = 5; - // - // SoftwareInstallation + // FormPackages // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(895, 571); - Controls.Add(buttonRef); - Controls.Add(buttonDel); + ClientSize = new Size(618, 480); Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); Controls.Add(buttonAdd); Controls.Add(dataGridView); - Name = "SoftwareInstallation"; - Text = "Список пакетов установок"; + Margin = new Padding(3, 4, 3, 4); + Name = "FormPackages"; + StartPosition = FormStartPosition.CenterScreen; + Text = "ПО"; Load += FormPackages_Load; ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); @@ -111,10 +119,10 @@ #endregion - private Button buttonRef; - private Button buttonDel; - private Button buttonUpd; - private Button buttonAdd; private DataGridView dataGridView; + private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; } } \ No newline at end of file diff --git a/SoftwareInstallation/FormPackages.cs b/SoftwareInstallation/FormPackages.cs index 0e330db..be650d6 100644 --- a/SoftwareInstallation/FormPackages.cs +++ b/SoftwareInstallation/FormPackages.cs @@ -1,23 +1,15 @@ -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.BindingModels; using SoftwareInstallationContracts.BusinessLogicsContracts; using Microsoft.Extensions.Logging; -namespace SoftwareInstallation.Forms +namespace SoftwareInstallationView { public partial class FormPackages : Form { private readonly ILogger _logger; + private readonly IPackageLogic _logic; + public FormPackages(ILogger logger, IPackageLogic logic) { InitializeComponent(); @@ -39,18 +31,19 @@ namespace SoftwareInstallation.Forms { dataGridView.DataSource = list; dataGridView.Columns["Id"].Visible = false; - dataGridView.Columns["PackageComponents"].Visible = false; dataGridView.Columns["PackageName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["PackageComponents"].Visible = false; } - _logger.LogInformation("Загрузка консерв"); + _logger.LogInformation("Ice creams loading"); } catch (Exception ex) { - _logger.LogError(ex, "Ошибка загрузки компонентов"); + _logger.LogError(ex, "Ice creams loading error"); + 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(FormPackage)); if (service is FormPackage form) @@ -62,7 +55,7 @@ namespace SoftwareInstallation.Forms } } - private void buttonUpd_Click(object sender, EventArgs e) + private void ButtonEdit_Click(object sender, EventArgs e) { if (dataGridView.SelectedRows.Count == 1) { @@ -78,21 +71,17 @@ namespace SoftwareInstallation.Forms } } - 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("Deletion of ice cream"); try { - if (!_logic.Delete(new PackageBindingModel - { - Id = id - })) + if (!_logic.Delete(new PackageBindingModel { Id = id })) { throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); } @@ -100,14 +89,14 @@ namespace SoftwareInstallation.Forms } catch (Exception ex) { - _logger.LogError(ex, "Ошибка удаления консервы"); + _logger.LogError(ex, "Ice cream deletion error"); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } - private void buttonRef_Click(object sender, EventArgs e) + private void ButtonUpd_Click(object sender, EventArgs e) { LoadData(); } diff --git a/SoftwareInstallation/FormShop.Designer.cs b/SoftwareInstallation/FormShop.Designer.cs new file mode 100644 index 0000000..090e444 --- /dev/null +++ b/SoftwareInstallation/FormShop.Designer.cs @@ -0,0 +1,247 @@ +namespace SoftwareInstallationView +{ + partial class FormShop + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + textBoxName = new TextBox(); + labelAddress = new Label(); + textBoxAddress = new TextBox(); + dateTimePicker = new DateTimePicker(); + labelOpeningDate = new Label(); + groupBoxPackages = new GroupBox(); + dataGridView = new DataGridView(); + buttonSave = new Button(); + buttonCancel = new Button(); + textBoxMaximum = new TextBox(); + labelMaximum = new Label(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + groupBoxPackages.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(16, 13); + labelName.Margin = new Padding(5, 0, 5, 0); + labelName.Name = "labelName"; + labelName.Size = new Size(84, 20); + labelName.TabIndex = 1; + labelName.Text = "Название :"; + // + // textBoxName + // + textBoxName.Location = new Point(105, 9); + textBoxName.Margin = new Padding(5, 4, 5, 4); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(287, 27); + textBoxName.TabIndex = 2; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(16, 53); + labelAddress.Margin = new Padding(5, 0, 5, 0); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(58, 20); + labelAddress.TabIndex = 3; + labelAddress.Text = "Адрес :"; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(105, 49); + textBoxAddress.Margin = new Padding(5, 4, 5, 4); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(287, 27); + textBoxAddress.TabIndex = 4; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(144, 88); + dateTimePicker.Margin = new Padding(3, 4, 3, 4); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(249, 27); + dateTimePicker.TabIndex = 5; + // + // labelOpeningDate + // + labelOpeningDate.AutoSize = true; + labelOpeningDate.Location = new Point(16, 92); + labelOpeningDate.Margin = new Padding(5, 0, 5, 0); + labelOpeningDate.Name = "labelOpeningDate"; + labelOpeningDate.Size = new Size(117, 20); + labelOpeningDate.TabIndex = 6; + labelOpeningDate.Text = "Дата открытия :"; + // + // groupBoxPackages + // + groupBoxPackages.Controls.Add(dataGridView); + groupBoxPackages.Location = new Point(6, 184); + groupBoxPackages.Margin = new Padding(5, 4, 5, 4); + groupBoxPackages.Name = "groupBoxPackages"; + groupBoxPackages.Padding = new Padding(5, 4, 5, 4); + groupBoxPackages.Size = new Size(536, 384); + groupBoxPackages.TabIndex = 7; + groupBoxPackages.TabStop = false; + groupBoxPackages.Text = "ПО"; + groupBoxPackages.Enter += groupBoxPackages_Enter; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnCount }); + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(5, 24); + dataGridView.Margin = new Padding(5, 4, 5, 4); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(522, 356); + dataGridView.TabIndex = 0; + dataGridView.CellContentClick += dataGridView_CellContentClick; + // + // buttonSave + // + buttonSave.Location = new Point(293, 579); + buttonSave.Margin = new Padding(5, 4, 5, 4); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(101, 36); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(411, 579); + buttonCancel.Margin = new Padding(5, 4, 5, 4); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(101, 36); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // textBoxMaximum + // + textBoxMaximum.Location = new Point(193, 129); + textBoxMaximum.Margin = new Padding(5, 4, 5, 4); + textBoxMaximum.Name = "textBoxMaximum"; + textBoxMaximum.Size = new Size(199, 27); + textBoxMaximum.TabIndex = 11; + // + // labelMaximum + // + labelMaximum.AutoSize = true; + labelMaximum.Location = new Point(16, 133); + labelMaximum.Margin = new Padding(5, 0, 5, 0); + labelMaximum.Name = "labelMaximum"; + labelMaximum.Size = new Size(85, 20); + labelMaximum.TabIndex = 10; + labelMaximum.Text = "Максимум:"; + // + // ColumnId + // + ColumnId.HeaderText = "Id"; + ColumnId.MinimumWidth = 6; + ColumnId.Name = "ColumnId"; + ColumnId.ReadOnly = true; + ColumnId.Visible = false; + ColumnId.Width = 125; + // + // ColumnName + // + ColumnName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnName.HeaderText = "Название "; + ColumnName.MinimumWidth = 6; + ColumnName.Name = "ColumnName"; + ColumnName.ReadOnly = true; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.ReadOnly = true; + ColumnCount.Width = 125; + // + // FormShop + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(546, 624); + Controls.Add(textBoxMaximum); + Controls.Add(labelMaximum); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxPackages); + Controls.Add(labelOpeningDate); + Controls.Add(dateTimePicker); + Controls.Add(textBoxAddress); + Controls.Add(labelAddress); + Controls.Add(textBoxName); + Controls.Add(labelName); + Margin = new Padding(3, 4, 3, 4); + Name = "FormShop"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Магазин"; + Load += FormShop_Load; + groupBoxPackages.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private TextBox textBoxName; + private Label labelAddress; + private TextBox textBoxAddress; + private DateTimePicker dateTimePicker; + private Label labelOpeningDate; + private GroupBox groupBoxPackages; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxMaximum; + private Label labelMaximum; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/FormShop.cs b/SoftwareInstallation/FormShop.cs new file mode 100644 index 0000000..ed95f79 --- /dev/null +++ b/SoftwareInstallation/FormShop.cs @@ -0,0 +1,142 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace SoftwareInstallationView +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + private int? _id; + + private Dictionary _shopPackages; + + public int Id { set { _id = value; } } + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _shopPackages = new Dictionary(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Shop loading"); + try + { + var view = _logic.ReadElement(new ShopSearchModel { Id = _id.Value }); + if (view != null) + { + textBoxName.Text = view.ShopName; + textBoxAddress.Text = view.Address; + dateTimePicker.Value = view.DateOpening; + textBoxMaximum.Text = view.PackagesMaximum.ToString(); + _shopPackages = view.ShopPackages ?? new Dictionary(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Shop ice creams loading"); + try + { + if (_shopPackages != null) + { + dataGridView.Rows.Clear(); + foreach (var iceCream in _shopPackages) + { + dataGridView.Rows.Add(new object[] { iceCream.Key, iceCream.Value.Item1.PackageName, iceCream.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop ice creams loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(dateTimePicker.Text)) + { + MessageBox.Show("Заполните дату", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxMaximum.Text)) + { + MessageBox.Show("Заполните максимальное количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Shop saving"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + DateOpening = dateTimePicker.Value, + PackagesMaximum = Convert.ToInt32(textBoxMaximum.Text), + ShopPackages = _shopPackages + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop saving error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void groupBoxPackages_Enter(object sender, EventArgs e) + { + + } + + private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + + } + } +} diff --git a/SoftwareInstallation/FormShop.resx b/SoftwareInstallation/FormShop.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SoftwareInstallation/FormShop.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SoftwareInstallation/FormShops.Designer.cs b/SoftwareInstallation/FormShops.Designer.cs new file mode 100644 index 0000000..ef9862a --- /dev/null +++ b/SoftwareInstallation/FormShops.Designer.cs @@ -0,0 +1,126 @@ +namespace SoftwareInstallationView +{ + partial class FormShops + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonEdit = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.BackgroundColor = SystemColors.ControlLightLight; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.Margin = new Padding(4, 3, 4, 3); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(408, 360); + dataGridView.TabIndex = 2; + // + // buttonUpd + // + buttonUpd.Location = new Point(432, 152); + buttonUpd.Margin = new Padding(4, 3, 4, 3); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(88, 27); + buttonUpd.TabIndex = 12; + buttonUpd.Text = "Обновить"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(432, 105); + buttonDel.Margin = new Padding(4, 3, 4, 3); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(88, 27); + buttonDel.TabIndex = 11; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonEdit + // + buttonEdit.Location = new Point(432, 58); + buttonEdit.Margin = new Padding(4, 3, 4, 3); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(88, 27); + buttonEdit.TabIndex = 10; + buttonEdit.Text = "Изменить"; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += ButtonEdit_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(432, 14); + buttonAdd.Margin = new Padding(4, 3, 4, 3); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(88, 27); + buttonAdd.TabIndex = 9; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(541, 360); + Controls.Add(buttonUpd); + Controls.Add(buttonDel); + Controls.Add(buttonEdit); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormShops"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonUpd; + private Button buttonDel; + private Button buttonEdit; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/FormShops.cs b/SoftwareInstallation/FormShops.cs new file mode 100644 index 0000000..d341262 --- /dev/null +++ b/SoftwareInstallation/FormShops.cs @@ -0,0 +1,104 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; + +namespace SoftwareInstallationView +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + + private readonly IShopLogic _logic; + + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopPackages"].Visible = false; + } + _logger.LogInformation("Shops loading"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shops loading error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void ButtonEdit_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Deletion of shop"); + try + { + if (!_logic.Delete(new ShopBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Shop deletion error"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SoftwareInstallation/FormShops.resx b/SoftwareInstallation/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SoftwareInstallation/FormShops.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SoftwareInstallation/Program.cs b/SoftwareInstallation/Program.cs index c75fcba..a572a96 100644 --- a/SoftwareInstallation/Program.cs +++ b/SoftwareInstallation/Program.cs @@ -1,18 +1,18 @@ -using SoftwareInstallation.Forms; +using SoftwareInstallationBusinessLogic.BusinessLogics; using SoftwareInstallationContracts.BusinessLogicsContracts; -using SoftwareInstallationBusinessLogic.BusinessLogic; using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationFileImplement.Implements; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using NLog.Extensions.Logging; -namespace SoftwareInstallation +namespace SoftwareInstallationView { internal static class Program { private static ServiceProvider? _serviceProvider; public static ServiceProvider? ServiceProvider => _serviceProvider; + /// /// The main entry point for the application. /// @@ -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 => @@ -38,9 +38,13 @@ namespace SoftwareInstallation services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -48,6 +52,10 @@ namespace SoftwareInstallation services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs b/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs deleted file mode 100644 index a09428d..0000000 --- a/SoftwareInstallationBusinessLogic/BusinessLogic/OrderLogic.cs +++ /dev/null @@ -1,141 +0,0 @@ -using SoftwareInstallationContracts.BindingModels; -using SoftwareInstallationContracts.BusinessLogicsContracts; -using SoftwareInstallationContracts.SearchModels; -using SoftwareInstallationContracts.StoragesContracts; -using SoftwareInstallationContracts.ViewModels; -using SoftwareInstallationDataModels.Enums; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SoftwareInstallationBusinessLogic.BusinessLogic -{ - public class OrderLogic : IOrderLogic - { - //Класс с логикой для заказов будет отвечать за получение списка заказов, - //создания заказа и смены его статусов. Следует учитывать, что у заказа можно - //менять статус на новый, если его текущий статус предшествует новому - - private readonly ILogger _logger; - private readonly IOrderStorage _orderStorage; - - public OrderLogic(ILogger logger, IOrderStorage orderStorage) - { - _logger = logger; - _orderStorage = orderStorage; - } - - public List? ReadList(OrderSearchModel? model) - { - _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id); - var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); - if (list == null) - { - _logger.LogWarning("ReadList return null list"); - return null; - } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; - } - - public bool CreateOrder(OrderBindingModel model) - { - CheckModel(model); - - if (model.Status != OrderStatus.Неизвестен) - return false; - model.Status = OrderStatus.Принят; - - if (_orderStorage.Insert(model) == null) - { - model.Status = OrderStatus.Неизвестен; - _logger.LogWarning("Insert operation failed"); - return false; - } - return true; - } - - public bool TakeOrderInWork(OrderBindingModel model) - { - return ToNextStatus(model, OrderStatus.Выполняется); - } - - public bool FinishOrder(OrderBindingModel model) - { - return ToNextStatus(model, OrderStatus.Готов); - } - - public bool DeliveryOrder(OrderBindingModel model) - { - return ToNextStatus(model, OrderStatus.Выдан); - } - - public bool ToNextStatus(OrderBindingModel model, OrderStatus orderStatus) - { - CheckModel(model, false); - var element = _orderStorage.GetElement(new OrderSearchModel() - { - Id = model.Id - }); - if (element == null) - { - throw new ArgumentNullException(nameof(element)); - } - - model.PackageId = element.PackageId; - model.DateCreate = element.DateCreate; - model.DateImplement = element.DateImplement; - model.Status = element.Status; - model.Count = element.Count; - model.Sum = element.Sum; - - if (model.Status != orderStatus - 1) - { - _logger.LogWarning("Status update to " + orderStatus + " operation failed"); - return false; - } - model.Status = orderStatus; - - if (model.Status == OrderStatus.Выдан) - { - model.DateImplement = DateTime.Now; - } - - if (_orderStorage.Update(model) == null) - { - model.Status--; - _logger.LogWarning("Changing status operation faled"); - return false; - } - return true; - } - - private void CheckModel(OrderBindingModel model, bool withParams = true) - { - if (model == null) - { - throw new ArgumentNullException(nameof(model)); - } - if (!withParams) - { - return; - } - if (model.Count <= 0) - { - throw new ArgumentNullException("Количество изделий должно быть больше 0", nameof(model.Count)); - } - if (model.Sum <= 0) - { - throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum)); - } - if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) - { - throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} должна быть позже даты его создания {model.DateCreate}"); - } - _logger.LogInformation("Package. PackageId:{PackageId}.Count:{Count}.Sum:{Sum}Id:{Id}", model.PackageId, model.Count, model.Sum, model.Id); - } - } -} diff --git a/SoftwareInstallationBusinessLogic/BusinessLogic/ComponentLogic.cs b/SoftwareInstallationBusinessLogic/BusinessLogics/ComponentLogic.cs similarity index 82% rename from SoftwareInstallationBusinessLogic/BusinessLogic/ComponentLogic.cs rename to SoftwareInstallationBusinessLogic/BusinessLogics/ComponentLogic.cs index 261d831..385e64a 100644 --- a/SoftwareInstallationBusinessLogic/BusinessLogic/ComponentLogic.cs +++ b/SoftwareInstallationBusinessLogic/BusinessLogics/ComponentLogic.cs @@ -5,28 +5,30 @@ using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationContracts.ViewModels; using Microsoft.Extensions.Logging; -namespace SoftwareInstallationBusinessLogic.BusinessLogic +namespace SoftwareInstallationBusinessLogic.BusinessLogics { public class ComponentLogic : IComponentLogic { private readonly ILogger _logger; + private readonly IComponentStorage _componentStorage; - public ComponentLogic(ILogger logger, IComponentStorage - componentStorage) + + public ComponentLogic(ILogger logger, IComponentStorage componentStorage) { _logger = logger; _componentStorage = componentStorage; } + public List? ReadList(ComponentSearchModel? model) { - _logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{Id}", model?.ComponentName, model?.Id); + _logger.LogInformation("ReadList. ComponentName: {ComponentName}. Id: {Id}", model?.ComponentName, model?.Id); var list = model == null ? _componentStorage.GetFullList() : _componentStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); return null; } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); + _logger.LogInformation("ReadList. Count: {Count}", list.Count); return list; } @@ -36,14 +38,14 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. ComponentName:{ComponentName}.Id:{Id}", model.ComponentName, model.Id); + _logger.LogInformation("ReadElement. ComponentName: {ComponentName}. Id: {Id}", model.ComponentName, model.Id); var element = _componentStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement element not found"); return null; } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); return element; } @@ -72,7 +74,7 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic public bool Delete(ComponentBindingModel model) { CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); + _logger.LogInformation("Delete. Id: {Id}", model.Id); if (_componentStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); @@ -99,10 +101,10 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic { throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost)); } - _logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{Cost}. Id: {Id}", model.ComponentName, model.Cost, model.Id); + _logger.LogInformation("Component. ComponentName: {ComponentName}. Cost: {Cost}. Id: {Id}", model.ComponentName, model.Cost, model.Id); var element = _componentStorage.GetElement(new ComponentSearchModel { - ComponentName = model.ComponentName + ComponentName = model.ComponentName }); if (element != null && element.Id != model.Id) { diff --git a/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs b/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs new file mode 100644 index 0000000..5645d32 --- /dev/null +++ b/SoftwareInstallationBusinessLogic/BusinessLogics/OrderLogic.cs @@ -0,0 +1,211 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Enums; +using SoftwareInstallationDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace SoftwareInstallationBusinessLogic.BusinessLogics +{ + public class OrderLogic : IOrderLogic + { + private readonly ILogger _logger; + + private readonly IOrderStorage _orderStorage; + + private readonly IPackageStorage _iceCreamStorage; + + private readonly IShopStorage _shopStorage; + + private readonly IShopLogic _shopLogic; + + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IPackageStorage iceCreamStorage, + IShopStorage shopStorage, IShopLogic shopLogic) + { + _logger = logger; + _orderStorage = orderStorage; + _iceCreamStorage = iceCreamStorage; + _shopStorage = shopStorage; + _shopLogic = shopLogic; + } + + public bool CreateOrder(OrderBindingModel model) + { + CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Invalid order status"); + return false; + } + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public List? ReadList(OrderSearchModel? model) + { + _logger.LogInformation("ReadList. OrderId: {Id}.", model?.Id); + var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public bool TakeOrderInWork(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выполняется); + } + + public bool FinishOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Готов); + } + + public bool DeliveryOrder(OrderBindingModel model) + { + return ChangeStatus(model, OrderStatus.Выдан); + } + + private void CheckModel(OrderBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (model.PackageId <= 0) + { + throw new ArgumentNullException("Некорректный идентификатор мороженого", nameof(model.PackageId)); + } + if (model.Count <= 0) + { + throw new ArgumentNullException("В заказе должно быть хотя бы одно мороженое", nameof(model.Count)); + } + if (model.Sum <= 0) + { + throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. PackageId: {PackageId}. PackageCount: {Count}", model.Id, model.Sum, + model.PackageId, model.Count); + } + + private bool ChangeStatus(OrderBindingModel model, OrderStatus newStatus) + { + CheckModel(model, false); + var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id } ); + if (order == null) + { + _logger.LogWarning("Change status operation failed. Order not found"); + return false; + } + if (order.Status + 1 != newStatus) + { + _logger.LogWarning("Change status operation failed. Incorrect new status: {newStatus}. Current status: {currStatus}", + newStatus, order.Status); + return false; + } + if (newStatus == OrderStatus.Выдан) + { + var iceCream = _iceCreamStorage.GetElement(new PackageSearchModel() { Id = order.PackageId }); + if (iceCream == null) + { + _logger.LogWarning("Change status operation failed. Ice cream not found"); + return false; + } + if (!DeliverPackages(iceCream, order.Count)) + { + _logger.LogWarning("Change status operation failed. Ice creams delivery operation failed"); + return false; + } + } + model.Status = newStatus; + if (model.Status == OrderStatus.Готов) + { + model.DateImplement = DateTime.Now; + } + else + { + model.DateImplement = order.DateImplement; + } + if (_orderStorage.Update(model) == null) + { + _logger.LogWarning("Change status operation failed"); + return false; + } + return true; + } + + private bool DeliverPackages(IPackageModel iceCream, int count) + { + if (count <= 0) + { + _logger.LogWarning("Packages delivery operation failed. Package count <= 0"); + return false; + } + + var shopList = _shopStorage.GetFullList(); + int shopsCapacity = shopList.Sum(x => x.PackagesMaximum); + int currentPackages = shopList.Select(x => x.ShopPackages.Sum(y => y.Value.Item2)).Sum(); + int freePlaces = shopsCapacity - currentPackages; + + if (freePlaces < count) + { + _logger.LogWarning("Package delivery operation failed. No space for new Package"); + return false; + } + + foreach (var shop in shopList) + { + freePlaces = shop.PackagesMaximum - shop.ShopPackages.Sum(x => x.Value.Item2); + if (freePlaces == 0) + { + continue; + } + if (freePlaces >= count) + { + if (_shopLogic.MakeShipment(new() { Id = shop.Id }, iceCream, count)) + { + count = 0; + } + else + { + _logger.LogWarning("Ice creams delivery operation failed"); + return false; + } + } + else + { + if (_shopLogic.MakeShipment(new() { Id = shop.Id }, iceCream, freePlaces)) + { + count -= freePlaces; + } + else + { + _logger.LogWarning("Ice creams delivery operation failed"); + return false; + } + } + if (count == 0) + { + return true; + } + } + return false; + } + } + + +} diff --git a/SoftwareInstallationBusinessLogic/BusinessLogic/PackageLogic.cs b/SoftwareInstallationBusinessLogic/BusinessLogics/PackageLogic.cs similarity index 59% rename from SoftwareInstallationBusinessLogic/BusinessLogic/PackageLogic.cs rename to SoftwareInstallationBusinessLogic/BusinessLogics/PackageLogic.cs index ea87d3b..43b2833 100644 --- a/SoftwareInstallationBusinessLogic/BusinessLogic/PackageLogic.cs +++ b/SoftwareInstallationBusinessLogic/BusinessLogics/PackageLogic.cs @@ -4,34 +4,31 @@ using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationContracts.ViewModels; using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -namespace SoftwareInstallationBusinessLogic.BusinessLogic +namespace SoftwareInstallationBusinessLogic.BusinessLogics { public class PackageLogic : IPackageLogic { private readonly ILogger _logger; - private readonly IPackageStorage _PackageStorage; - public PackageLogic(ILogger logger, IPackageStorage - PackageStorage) + + private readonly IPackageStorage _iceCreamStorage; + + public PackageLogic(ILogger logger, IPackageStorage iceCreamStorage) { _logger = logger; - _PackageStorage = PackageStorage; + _iceCreamStorage = iceCreamStorage; } + public List? ReadList(PackageSearchModel? model) { - _logger.LogInformation("ReadList. PackageName:{PackageName}.Id:{Id}", model?.PackageName, model?.Id); - var list = model == null ? _PackageStorage.GetFullList() : _PackageStorage.GetFilteredList(model); + _logger.LogInformation("ReadList. PackageName: {PackageName}. Id: {Id}", model?.PackageName, model?.Id); + var list = model == null ? _iceCreamStorage.GetFullList() : _iceCreamStorage.GetFilteredList(model); if (list == null) { _logger.LogWarning("ReadList return null list"); return null; } - _logger.LogInformation("ReadList. Count:{Count}", list.Count); + _logger.LogInformation("ReadList. Count: {Count}", list.Count); return list; } @@ -41,21 +38,21 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic { throw new ArgumentNullException(nameof(model)); } - _logger.LogInformation("ReadElement. PackageName:{PackageName}.Id:{Id}", model.PackageName, model.Id); - var element = _PackageStorage.GetElement(model); + _logger.LogInformation("ReadElement. PackageName: {PackageName}. Id: {Id}", model.PackageName, model.Id); + var element = _iceCreamStorage.GetElement(model); if (element == null) { _logger.LogWarning("ReadElement element not found"); return null; } - _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); return element; } public bool Create(PackageBindingModel model) { CheckModel(model); - if (_PackageStorage.Insert(model) == null) + if (_iceCreamStorage.Insert(model) == null) { _logger.LogWarning("Insert operation failed"); return false; @@ -66,7 +63,7 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic public bool Update(PackageBindingModel model) { CheckModel(model); - if (_PackageStorage.Update(model) == null) + if (_iceCreamStorage.Update(model) == null) { _logger.LogWarning("Update operation failed"); return false; @@ -77,8 +74,8 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic public bool Delete(PackageBindingModel model) { CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_PackageStorage.Delete(model) == null) + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_iceCreamStorage.Delete(model) == null) { _logger.LogWarning("Delete operation failed"); return false; @@ -98,20 +95,24 @@ namespace SoftwareInstallationBusinessLogic.BusinessLogic } if (string.IsNullOrEmpty(model.PackageName)) { - throw new ArgumentNullException("Нет названия изделия", nameof(model.PackageName)); + throw new ArgumentNullException("Нет названия мороженого", nameof(model.PackageName)); } if (model.Price <= 0) { - throw new ArgumentNullException("Цена изделия должна быть больше 0", nameof(model.Price)); + throw new ArgumentNullException("Цена мороженого должна быть больше 0", nameof(model.Price)); } - _logger.LogInformation("Package. PackageName:{PackageName}.Price:{Cost}. Id: {Id}", model.PackageName, model.Price, model.Id); - var element = _PackageStorage.GetElement(new PackageSearchModel + if (model.PackageComponents == null || model.PackageComponents.Count == 0) + { + throw new ArgumentNullException("Мороженое должно состоять хотя бы из одного компонента"); + } + _logger.LogInformation("Package. PackageName: {PackageName}. Price: {Price}. Id: {Id}", model.PackageName, model.Price, model.Id); + var element = _iceCreamStorage.GetElement(new PackageSearchModel { PackageName = model.PackageName }); if (element != null && element.Id != model.Id) { - throw new InvalidOperationException("Изделие с таким названием уже есть"); + throw new InvalidOperationException("Мороженое с таким названием уже есть"); } } } diff --git a/SoftwareInstallationBusinessLogic/BusinessLogics/ShopLogic.cs b/SoftwareInstallationBusinessLogic/BusinessLogics/ShopLogic.cs new file mode 100644 index 0000000..453c283 --- /dev/null +++ b/SoftwareInstallationBusinessLogic/BusinessLogics/ShopLogic.cs @@ -0,0 +1,177 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BusinessLogicsContracts; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using Microsoft.Extensions.Logging; + +namespace SoftwareInstallationBusinessLogic.BusinessLogics +{ + public class ShopLogic : IShopLogic + { + private readonly ILogger _logger; + + private readonly IShopStorage _shopStorage; + + public ShopLogic(ILogger logger, IShopStorage shopStorage) + { + _logger = logger; + _shopStorage = shopStorage; + } + + public List? ReadList(ShopSearchModel? model) + { + _logger.LogInformation("ReadList. ShopName: {ShopName}. Id: {Id}", model?.ShopName, model?.Id); + var list = model == null ? _shopStorage.GetFullList() : _shopStorage.GetFilteredList(model); + if (list == null) + { + _logger.LogWarning("ReadList return null list"); + return null; + } + _logger.LogInformation("ReadList. Count: {Count}", list.Count); + return list; + } + + public ShopViewModel? ReadElement(ShopSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ShopName: {ShopName}. Id: {Id}", model.ShopName, model.Id); + var element = _shopStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id: {Id}", element.Id); + return element; + } + + public bool Create(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Insert(model) == null) + { + _logger.LogWarning("Insert operation failed"); + return false; + } + return true; + } + + public bool Update(ShopBindingModel model) + { + CheckModel(model); + if (_shopStorage.Update(model) == null) + { + _logger.LogWarning("Update operation failed"); + return false; + } + return true; + } + + public bool Delete(ShopBindingModel model) + { + CheckModel(model, false); + _logger.LogInformation("Delete. Id: {Id}", model.Id); + if (_shopStorage.Delete(model) == null) + { + _logger.LogWarning("Delete operation failed"); + return false; + } + return true; + } + + public bool MakeShipment(ShopSearchModel shopModel, IPackageModel package, int count) + { + if (shopModel == null) + { + throw new ArgumentNullException(nameof(shopModel)); + } + if (package == null) + { + throw new ArgumentNullException(nameof(package)); + } + if (count <= 0) + { + throw new ArgumentException("Количество товаров(ПО) в магазине должно быть больше нуля", nameof(count)); + } + _logger.LogInformation("MakeShipment(GetElement). ShopName: {ShopName}. Id: {Id}", shopModel.ShopName, shopModel.Id); + var shop = _shopStorage.GetElement(shopModel); + if (shop == null) + { + _logger.LogWarning("MakeShipment(GetElement). Element not found"); + return false; + } + if (shop.PackagesMaximum - shop.ShopPackages.Sum(x => x.Value.Item2) < count) + { + _logger.LogWarning("MakeShipment error. No space for new package"); + return false; + } + if (shop.ShopPackages.ContainsKey(package.Id)) + { + var shopIC = shop.ShopPackages[package.Id]; + shopIC.Item2 += count; + shop.ShopPackages[package.Id] = shopIC; + _logger.LogInformation("MakeShipment. Added {count} '{iceCream}' to '{ShopName}' shop", count, package.PackageName, + shop.ShopName); + } + else + { + shop.ShopPackages.Add(package.Id, (package, count)); + _logger.LogInformation("MakeShipment. Added {count} new '{iceCream}' to '{ShopName}' shop", count, package.PackageName, + shop.ShopName); + } + if (_shopStorage.Update(new ShopBindingModel() + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpening = shop.DateOpening, + PackagesMaximum = shop.PackagesMaximum, + ShopPackages = shop.ShopPackages, + }) == null) + { + _logger.LogWarning("MakeShipment. Update operation failed"); + return false; + } + return true; + } + + public bool MakeSale(IPackageModel model, int count) + { + return _shopStorage.MakeSale(model, count); + } + + private void CheckModel(ShopBindingModel model, bool withParams = true) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + if (!withParams) + { + return; + } + if (string.IsNullOrEmpty(model.ShopName)) + { + throw new ArgumentNullException("Нет названия магазина", nameof(model.ShopName)); + } + if (string.IsNullOrEmpty(model.Address)) + { + throw new ArgumentNullException("Нет адреса магазина", nameof(model.Address)); + } + _logger.LogInformation("Shop. ShopName: {ShopName}. Address: {Address}. Id: {Id}", model.ShopName, model.Address, model.Id); + var element = _shopStorage.GetElement(new ShopSearchModel + { + ShopName = model.ShopName + }); + if (element != null && element.Id != model.Id) + { + throw new InvalidOperationException("Магазин с таким названием уже есть"); + } + } + } +} diff --git a/SoftwareInstallationContracts/BindingModels/ComponentBindingModel.cs b/SoftwareInstallationContracts/BindingModels/ComponentBindingModel.cs index f1da9cf..a59c047 100644 --- a/SoftwareInstallationContracts/BindingModels/ComponentBindingModel.cs +++ b/SoftwareInstallationContracts/BindingModels/ComponentBindingModel.cs @@ -1,16 +1,13 @@ using SoftwareInstallationDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationContracts.BindingModels { public class ComponentBindingModel : IComponentModel { public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } } -} +} \ No newline at end of file diff --git a/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs b/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs index d53ff55..cbaa074 100644 --- a/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs +++ b/SoftwareInstallationContracts/BindingModels/OrderBindingModel.cs @@ -1,21 +1,22 @@ using SoftwareInstallationDataModels.Enums; using SoftwareInstallationDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationContracts.BindingModels { public class OrderBindingModel : IOrderModel { public int Id { get; set; } + public int PackageId { get; set; } + public int Count { get; set; } - public double Sum { get; set; } + + public double Sum { get; set; } + public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + public DateTime DateCreate { get; set; } = DateTime.Now; + public DateTime? DateImplement { get; set; } } -} +} \ No newline at end of file diff --git a/SoftwareInstallationContracts/BindingModels/PackageBindingModel.cs b/SoftwareInstallationContracts/BindingModels/PackageBindingModel.cs index 4650e41..f3d6389 100644 --- a/SoftwareInstallationContracts/BindingModels/PackageBindingModel.cs +++ b/SoftwareInstallationContracts/BindingModels/PackageBindingModel.cs @@ -1,17 +1,19 @@ using SoftwareInstallationDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationContracts.BindingModels { public class PackageBindingModel : IPackageModel { public int Id { get; set; } + public string PackageName { get; set; } = string.Empty; + public double Price { get; set; } - public Dictionary PackageComponents { get; set; } = new(); + + public Dictionary PackageComponents + { + get; + set; + } = new(); } -} +} \ No newline at end of file diff --git a/SoftwareInstallationContracts/BindingModels/ShopBindingModel.cs b/SoftwareInstallationContracts/BindingModels/ShopBindingModel.cs new file mode 100644 index 0000000..78b9b10 --- /dev/null +++ b/SoftwareInstallationContracts/BindingModels/ShopBindingModel.cs @@ -0,0 +1,23 @@ +using SoftwareInstallationDataModels.Models; + +namespace SoftwareInstallationContracts.BindingModels +{ + public class ShopBindingModel : IShopModel + { + public int Id { get; set; } + + public string ShopName { get; set; } = string.Empty; + + public string Address { get; set; } = string.Empty; + + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ShopPackages + { + get; + set; + } = new(); + + public int PackagesMaximum { get; set; } + } +} diff --git a/SoftwareInstallationContracts/BusinessLogicsContracts/IComponentLogic.cs b/SoftwareInstallationContracts/BusinessLogicsContracts/IComponentLogic.cs index 94d4a7d..161179d 100644 --- a/SoftwareInstallationContracts/BusinessLogicsContracts/IComponentLogic.cs +++ b/SoftwareInstallationContracts/BusinessLogicsContracts/IComponentLogic.cs @@ -1,21 +1,19 @@ using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationContracts.BusinessLogicsContracts { public interface IComponentLogic { List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); } -} +} \ No newline at end of file diff --git a/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs b/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs index c589fe2..95df229 100644 --- a/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs +++ b/SoftwareInstallationContracts/BusinessLogicsContracts/IOrderLogic.cs @@ -1,30 +1,19 @@ using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationContracts.BusinessLogicsContracts { public interface IOrderLogic { List? ReadList(OrderSearchModel? model); + bool CreateOrder(OrderBindingModel model); + bool TakeOrderInWork(OrderBindingModel model); - /// - /// Готов - /// - /// - /// + bool FinishOrder(OrderBindingModel model); - /// - /// Доставлен - /// - /// - /// + bool DeliveryOrder(OrderBindingModel model); } -} +} \ No newline at end of file diff --git a/SoftwareInstallationContracts/BusinessLogicsContracts/IPackageLogic.cs b/SoftwareInstallationContracts/BusinessLogicsContracts/IPackageLogic.cs index 49b9995..3847784 100644 --- a/SoftwareInstallationContracts/BusinessLogicsContracts/IPackageLogic.cs +++ b/SoftwareInstallationContracts/BusinessLogicsContracts/IPackageLogic.cs @@ -1,20 +1,19 @@ using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationContracts.BusinessLogicsContracts { public interface IPackageLogic { List? ReadList(PackageSearchModel? model); + PackageViewModel? ReadElement(PackageSearchModel model); + bool Create(PackageBindingModel model); + bool Update(PackageBindingModel model); + bool Delete(PackageBindingModel model); } -} +} \ No newline at end of file diff --git a/SoftwareInstallationContracts/BusinessLogicsContracts/IShopLogic.cs b/SoftwareInstallationContracts/BusinessLogicsContracts/IShopLogic.cs new file mode 100644 index 0000000..67a334f --- /dev/null +++ b/SoftwareInstallationContracts/BusinessLogicsContracts/IShopLogic.cs @@ -0,0 +1,24 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; + +namespace SoftwareInstallationContracts.BusinessLogicsContracts +{ + public interface IShopLogic + { + List? ReadList(ShopSearchModel? model); + + ShopViewModel? ReadElement(ShopSearchModel model); + + bool Create(ShopBindingModel model); + + bool Update(ShopBindingModel model); + + bool Delete(ShopBindingModel model); + + bool MakeShipment(ShopSearchModel shopModel, IPackageModel iceCream, int count); + + bool MakeSale(IPackageModel model, int count); + } +} diff --git a/SoftwareInstallationContracts/SearchModels/ComponentSearchModel.cs b/SoftwareInstallationContracts/SearchModels/ComponentSearchModel.cs index c15aff8..d269c79 100644 --- a/SoftwareInstallationContracts/SearchModels/ComponentSearchModel.cs +++ b/SoftwareInstallationContracts/SearchModels/ComponentSearchModel.cs @@ -1,14 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SoftwareInstallationContracts.SearchModels +namespace SoftwareInstallationContracts.SearchModels { public class ComponentSearchModel { public int? Id { get; set; } + public string? ComponentName { get; set; } } -} +} \ No newline at end of file diff --git a/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs b/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs index b2831f6..414ec2d 100644 --- a/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs +++ b/SoftwareInstallationContracts/SearchModels/OrderSearchModel.cs @@ -1,13 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SoftwareInstallationContracts.SearchModels +namespace SoftwareInstallationContracts.SearchModels { public class OrderSearchModel { public int? Id { get; set; } } -} +} \ No newline at end of file diff --git a/SoftwareInstallationContracts/SearchModels/PackageSearchModel.cs b/SoftwareInstallationContracts/SearchModels/PackageSearchModel.cs index 43c90d4..909630f 100644 --- a/SoftwareInstallationContracts/SearchModels/PackageSearchModel.cs +++ b/SoftwareInstallationContracts/SearchModels/PackageSearchModel.cs @@ -1,14 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SoftwareInstallationContracts.SearchModels +namespace SoftwareInstallationContracts.SearchModels { public class PackageSearchModel { public int? Id { get; set; } + public string? PackageName { get; set; } } -} +} \ No newline at end of file diff --git a/SoftwareInstallationContracts/SearchModels/ShopSearchModel.cs b/SoftwareInstallationContracts/SearchModels/ShopSearchModel.cs new file mode 100644 index 0000000..ffe736d --- /dev/null +++ b/SoftwareInstallationContracts/SearchModels/ShopSearchModel.cs @@ -0,0 +1,9 @@ +namespace SoftwareInstallationContracts.SearchModels +{ + public class ShopSearchModel + { + public int? Id { get; set; } + + public string? ShopName { get; set; } + } +} diff --git a/SoftwareInstallationContracts/StoragesContracts/IComponentStorage.cs b/SoftwareInstallationContracts/StoragesContracts/IComponentStorage.cs index b07927d..6b4aba5 100644 --- a/SoftwareInstallationContracts/StoragesContracts/IComponentStorage.cs +++ b/SoftwareInstallationContracts/StoragesContracts/IComponentStorage.cs @@ -1,22 +1,21 @@ using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationContracts.StoragesContracts { public interface IComponentStorage { List GetFullList(); - List GetFilteredList(ComponentSearchModel model); - ComponentViewModel? GetElement(ComponentSearchModel model); - ComponentViewModel? Insert(ComponentBindingModel model); - ComponentViewModel? Update(ComponentBindingModel model); - ComponentViewModel? Delete(ComponentBindingModel model); + List GetFilteredList(ComponentSearchModel model); + + ComponentViewModel? GetElement(ComponentSearchModel model); + + ComponentViewModel? Insert(ComponentBindingModel model); + + ComponentViewModel? Update(ComponentBindingModel model); + + ComponentViewModel? Delete(ComponentBindingModel model); } -} +} \ No newline at end of file diff --git a/SoftwareInstallationContracts/StoragesContracts/IOrderStorage.cs b/SoftwareInstallationContracts/StoragesContracts/IOrderStorage.cs index 79db704..7bb4fdb 100644 --- a/SoftwareInstallationContracts/StoragesContracts/IOrderStorage.cs +++ b/SoftwareInstallationContracts/StoragesContracts/IOrderStorage.cs @@ -1,21 +1,21 @@ using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationContracts.StoragesContracts { public interface IOrderStorage { List GetFullList(); + List GetFilteredList(OrderSearchModel model); + OrderViewModel? GetElement(OrderSearchModel model); + OrderViewModel? Insert(OrderBindingModel model); + OrderViewModel? Update(OrderBindingModel model); + OrderViewModel? Delete(OrderBindingModel model); } -} +} \ No newline at end of file diff --git a/SoftwareInstallationContracts/StoragesContracts/IPackageStorage.cs b/SoftwareInstallationContracts/StoragesContracts/IPackageStorage.cs index 3148b30..9dfc6eb 100644 --- a/SoftwareInstallationContracts/StoragesContracts/IPackageStorage.cs +++ b/SoftwareInstallationContracts/StoragesContracts/IPackageStorage.cs @@ -1,21 +1,21 @@ using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.ViewModels; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationContracts.StoragesContracts { public interface IPackageStorage { List GetFullList(); + List GetFilteredList(PackageSearchModel model); + PackageViewModel? GetElement(PackageSearchModel model); + PackageViewModel? Insert(PackageBindingModel model); + PackageViewModel? Update(PackageBindingModel model); + PackageViewModel? Delete(PackageBindingModel model); } -} +} \ No newline at end of file diff --git a/SoftwareInstallationContracts/StoragesContracts/IShopStorage.cs b/SoftwareInstallationContracts/StoragesContracts/IShopStorage.cs new file mode 100644 index 0000000..8285ab2 --- /dev/null +++ b/SoftwareInstallationContracts/StoragesContracts/IShopStorage.cs @@ -0,0 +1,24 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; + +namespace SoftwareInstallationContracts.StoragesContracts +{ + public interface IShopStorage + { + List GetFullList(); + + List GetFilteredList(ShopSearchModel model); + + ShopViewModel? GetElement(ShopSearchModel model); + + ShopViewModel? Insert(ShopBindingModel model); + + ShopViewModel? Update(ShopBindingModel model); + + ShopViewModel? Delete(ShopBindingModel model); + + bool MakeSale(IPackageModel model, int count); + } +} diff --git a/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs b/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs index 083b3c3..eb14767 100644 --- a/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs +++ b/SoftwareInstallationContracts/ViewModels/ComponentViewModel.cs @@ -1,19 +1,16 @@ using SoftwareInstallationDataModels.Models; -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationContracts.ViewModels { public class ComponentViewModel : IComponentModel { public int Id { get; set; } + [DisplayName("Название компонента")] public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] public double Cost { get; set; } } -} +} \ No newline at end of file diff --git a/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs b/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs index e4c9a67..75421e1 100644 --- a/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs +++ b/SoftwareInstallationContracts/ViewModels/OrderViewModel.cs @@ -1,28 +1,31 @@ using SoftwareInstallationDataModels.Enums; -using System; -using System.Collections.Generic; +using SoftwareInstallationDataModels.Models; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationContracts.ViewModels { - public class OrderViewModel + public class OrderViewModel : IOrderModel { [DisplayName("Номер")] public int Id { get; set; } + public int PackageId { get; set; } - [DisplayName("Изделие")] + + [DisplayName("ПО")] public string PackageName { get; set; } = string.Empty; + [DisplayName("Количество")] public int Count { get; set; } + [DisplayName("Сумма")] public double Sum { get; set; } + [DisplayName("Статус")] public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; + [DisplayName("Дата создания")] public DateTime DateCreate { get; set; } = DateTime.Now; + [DisplayName("Дата выполнения")] public DateTime? DateImplement { get; set; } } diff --git a/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs b/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs index 12a29dc..5224f77 100644 --- a/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs +++ b/SoftwareInstallationContracts/ViewModels/PackageViewModel.cs @@ -1,21 +1,22 @@ using SoftwareInstallationDataModels.Models; -using System; -using System.Collections.Generic; using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationContracts.ViewModels { public class PackageViewModel : IPackageModel { public int Id { get; set; } - [DisplayName("Название изделия")] - public string PackageName { get; set; } + + [DisplayName("Название мороженого")] + public string PackageName { get; set; } = string.Empty; + [DisplayName("Цена")] public double Price { get; set; } - public Dictionary PackageComponents { get; set; } = new(); + public Dictionary PackageComponents + { + get; + set; + } = new(); } -} +} \ No newline at end of file diff --git a/SoftwareInstallationContracts/ViewModels/ShopViewModel.cs b/SoftwareInstallationContracts/ViewModels/ShopViewModel.cs new file mode 100644 index 0000000..1df8e0a --- /dev/null +++ b/SoftwareInstallationContracts/ViewModels/ShopViewModel.cs @@ -0,0 +1,28 @@ +using SoftwareInstallationDataModels.Models; +using System.ComponentModel; + +namespace SoftwareInstallationContracts.ViewModels +{ + public class ShopViewModel : IShopModel + { + public int Id { get; set; } + + [DisplayName("Название магазина")] + public string ShopName { get; set; } = string.Empty; + + [DisplayName("Адрес")] + public string Address { get; set; } = string.Empty; + + [DisplayName("Дата открытия")] + public DateTime DateOpening { get; set; } = DateTime.Now; + + public Dictionary ShopPackages + { + get; + set; + } = new(); + + [DisplayName("Максимальное количество мороженого")] + public int PackagesMaximum { get; set; } + } +} diff --git a/SoftwareInstallationDataModels/Enums/OrderStatus.cs b/SoftwareInstallationDataModels/Enums/OrderStatus.cs index 13c4efe..798655b 100644 --- a/SoftwareInstallationDataModels/Enums/OrderStatus.cs +++ b/SoftwareInstallationDataModels/Enums/OrderStatus.cs @@ -3,9 +3,13 @@ public enum OrderStatus { Неизвестен = -1, + Принят = 0, + Выполняется = 1, + Готов = 2, - Выдан = 3, + + Выдан = 3 } } \ No newline at end of file diff --git a/SoftwareInstallationDataModels/IId.cs b/SoftwareInstallationDataModels/IId.cs index 4c444f5..3407d0e 100644 --- a/SoftwareInstallationDataModels/IId.cs +++ b/SoftwareInstallationDataModels/IId.cs @@ -1,13 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace SoftwareInstallationDataModels +namespace SoftwareInstallationDataModels { public interface IId { int Id { get; } } -} +} \ No newline at end of file diff --git a/SoftwareInstallationDataModels/Models/IComponentModel.cs b/SoftwareInstallationDataModels/Models/IComponentModel.cs index 5d18120..7db11ed 100644 --- a/SoftwareInstallationDataModels/Models/IComponentModel.cs +++ b/SoftwareInstallationDataModels/Models/IComponentModel.cs @@ -1,8 +1,9 @@ -namespace SoftwareInstallationDataModels.Models +namespace SoftwareInstallationDataModels.Models { public interface IComponentModel : IId { string ComponentName { get; } + double Cost { get; } } -} +} \ No newline at end of file diff --git a/SoftwareInstallationDataModels/Models/IOrderModel.cs b/SoftwareInstallationDataModels/Models/IOrderModel.cs index 95ae88f..2eb9b8e 100644 --- a/SoftwareInstallationDataModels/Models/IOrderModel.cs +++ b/SoftwareInstallationDataModels/Models/IOrderModel.cs @@ -1,4 +1,4 @@ -using SoftwareInstallationDataModels.Enums; +using SoftwareInstallationDataModels.Enums; namespace SoftwareInstallationDataModels.Models { diff --git a/SoftwareInstallationDataModels/Models/IPackageModel.cs b/SoftwareInstallationDataModels/Models/IPackageModel.cs index 6d2a4f9..ba31f83 100644 --- a/SoftwareInstallationDataModels/Models/IPackageModel.cs +++ b/SoftwareInstallationDataModels/Models/IPackageModel.cs @@ -1,9 +1,11 @@ -namespace SoftwareInstallationDataModels.Models +namespace SoftwareInstallationDataModels.Models { - public interface IPackageModel : IId - { - string PackageName { get; } - double Price { get; } - Dictionary PackageComponents { get; } - } -} + public interface IPackageModel : IId + { + string PackageName { get; } + + double Price { get; } + + Dictionary PackageComponents { get; } + } +} \ No newline at end of file diff --git a/SoftwareInstallationDataModels/Models/IShopModel.cs b/SoftwareInstallationDataModels/Models/IShopModel.cs new file mode 100644 index 0000000..1839712 --- /dev/null +++ b/SoftwareInstallationDataModels/Models/IShopModel.cs @@ -0,0 +1,15 @@ +namespace SoftwareInstallationDataModels.Models +{ + public interface IShopModel : IId + { + string ShopName { get; } + + string Address { get; } + + DateTime DateOpening { get; } + + Dictionary ShopPackages { get; } + + int PackagesMaximum { get; } + } +} diff --git a/SoftwareInstallationFileImplement/DataFileSingleton.cs b/SoftwareInstallationFileImplement/DataFileSingleton.cs index e22643d..a6e9a5e 100644 --- a/SoftwareInstallationFileImplement/DataFileSingleton.cs +++ b/SoftwareInstallationFileImplement/DataFileSingleton.cs @@ -1,22 +1,28 @@ 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 + internal class DataFileSingleton { private static DataFileSingleton? instance; + private readonly string ComponentFileName = "Component.xml"; + private readonly string OrderFileName = "Order.xml"; + private readonly string PackageFileName = "Package.xml"; + + private readonly string ShopFileName = "Shop.xml"; + public List Components { get; private set; } + public List Orders { get; private set; } + public List Packages { get; private set; } + + public List Shops { get; private set; } + public static DataFileSingleton GetInstance() { if (instance == null) @@ -25,24 +31,32 @@ namespace SoftwareInstallationFileImplement } 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); + + public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", 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)!)!; + Shops = LoadData(ShopFileName, "Shop", x => Shop.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 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) diff --git a/SoftwareInstallationFileImplement/Implements/ComponentStorage.cs b/SoftwareInstallationFileImplement/Implements/ComponentStorage.cs index 105a8cb..69b006c 100644 --- a/SoftwareInstallationFileImplement/Implements/ComponentStorage.cs +++ b/SoftwareInstallationFileImplement/Implements/ComponentStorage.cs @@ -3,42 +3,49 @@ 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(); + 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(); + 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; + 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; @@ -51,6 +58,7 @@ namespace SoftwareInstallationFileImplement.Implements source.SaveComponents(); return newComponent.GetViewModel; } + public ComponentViewModel? Update(ComponentBindingModel model) { var component = source.Components.FirstOrDefault(x => x.Id == model.Id); @@ -62,6 +70,7 @@ namespace SoftwareInstallationFileImplement.Implements source.SaveComponents(); return component.GetViewModel; } + public ComponentViewModel? Delete(ComponentBindingModel model) { var element = source.Components.FirstOrDefault(x => x.Id == model.Id); @@ -73,6 +82,5 @@ namespace SoftwareInstallationFileImplement.Implements } return null; } - } } diff --git a/SoftwareInstallationFileImplement/Implements/OrderStorage.cs b/SoftwareInstallationFileImplement/Implements/OrderStorage.cs index d83efa0..a732334 100644 --- a/SoftwareInstallationFileImplement/Implements/OrderStorage.cs +++ b/SoftwareInstallationFileImplement/Implements/OrderStorage.cs @@ -3,11 +3,6 @@ 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 { @@ -20,13 +15,11 @@ namespace SoftwareInstallationFileImplement.Implements source = DataFileSingleton.GetInstance(); } - public OrderViewModel? GetElement(OrderSearchModel model) + public List GetFullList() { - if (!model.Id.HasValue) - { - return null; - } - return GetViewModel(source.Orders.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)); + return source.Orders + .Select(x => AddPackageName(x.GetViewModel)) + .ToList(); } public List GetFilteredList(OrderSearchModel model) @@ -35,12 +28,24 @@ namespace SoftwareInstallationFileImplement.Implements { return new(); } - return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList(); + return source.Orders + .Where(x => x.Id == model.Id) + .Select(x => AddPackageName(x.GetViewModel)) + .ToList(); } - public List GetFullList() + public OrderViewModel? GetElement(OrderSearchModel model) { - return source.Orders.Select(x => GetViewModel(x)).ToList(); + if (!model.Id.HasValue) + { + return null; + } + var order = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (order == null) + { + return null; + } + return AddPackageName(order.GetViewModel); } public OrderViewModel? Insert(OrderBindingModel model) @@ -53,7 +58,7 @@ namespace SoftwareInstallationFileImplement.Implements } source.Orders.Add(newOrder); source.SaveOrders(); - return GetViewModel(newOrder); + return AddPackageName(newOrder.GetViewModel); } public OrderViewModel? Update(OrderBindingModel model) @@ -65,32 +70,29 @@ namespace SoftwareInstallationFileImplement.Implements } 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); + return AddPackageName(order.GetViewModel); } - private OrderViewModel GetViewModel(Order order) + public OrderViewModel? Delete(OrderBindingModel model) { - var viewModel = order.GetViewModel; - foreach (var comp in source.Packages) + var element = source.Orders.FirstOrDefault(x => x.Id == model.Id); + if (element != null) { - if (comp.Id == order.PackageId) - { - viewModel.PackageName = comp.PackageName; - break; - } + source.Orders.Remove(element); + source.SaveOrders(); + return AddPackageName(element.GetViewModel); } - return viewModel; + return null; + } + + private OrderViewModel AddPackageName(OrderViewModel model) + { + var selectedPackage = source.Packages.FirstOrDefault(x => x.Id == model.PackageId); + if (selectedPackage != null) + { + model.PackageName = selectedPackage.PackageName; + } + return model; } } } diff --git a/SoftwareInstallationFileImplement/Implements/TravelStorage.cs b/SoftwareInstallationFileImplement/Implements/PackageStorage.cs similarity index 57% rename from SoftwareInstallationFileImplement/Implements/TravelStorage.cs rename to SoftwareInstallationFileImplement/Implements/PackageStorage.cs index 67cc3f1..493921a 100644 --- a/SoftwareInstallationFileImplement/Implements/TravelStorage.cs +++ b/SoftwareInstallationFileImplement/Implements/PackageStorage.cs @@ -3,11 +3,6 @@ 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 { @@ -20,13 +15,11 @@ namespace SoftwareInstallationFileImplement.Implements source = DataFileSingleton.GetInstance(); } - public PackageViewModel? GetElement(PackageSearchModel model) + public List GetFullList() { - 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; + return source.Packages + .Select(x => x.GetViewModel) + .ToList(); } public List GetFilteredList(PackageSearchModel model) @@ -35,48 +28,59 @@ namespace SoftwareInstallationFileImplement.Implements { return new(); } - return source.Packages.Where(x => x.PackageName.Contains(model.PackageName)).Select(x => x.GetViewModel).ToList(); + return source.Packages + .Where(x => x.PackageName.Contains(model.PackageName)) + .Select(x => x.GetViewModel) + .ToList(); } - public List GetFullList() + public PackageViewModel? GetElement(PackageSearchModel model) { - return source.Packages.Select(x => x.GetViewModel).ToList(); + 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 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) + var newPackage = Package.Create(model); + if (newPackage == null) { return null; } - source.Packages.Add(newDoc); + source.Packages.Add(newPackage); source.SavePackages(); - return newDoc.GetViewModel; + return newPackage.GetViewModel; } public PackageViewModel? Update(PackageBindingModel model) { - var document = source.Packages.FirstOrDefault(x => x.Id == model.Id); - if (document == null) + var iceCream = source.Packages.FirstOrDefault(x => x.Id == model.Id); + if (iceCream == null) { return null; } - document.Update(model); + iceCream.Update(model); source.SavePackages(); - return document.GetViewModel; + return iceCream.GetViewModel; } + public PackageViewModel? Delete(PackageBindingModel model) { - var document = source.Packages.FirstOrDefault(x => x.Id == model.Id); - if (document == null) + var element = source.Packages.FirstOrDefault(x => x.Id == model.Id); + if (element != null) { - return null; + source.Packages.Remove(element); + source.SavePackages(); + return element.GetViewModel; } - document.Update(model); - source.SavePackages(); - return document.GetViewModel; + return null; } } } diff --git a/SoftwareInstallationFileImplement/Implements/ShopStorage.cs b/SoftwareInstallationFileImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..03d6cc3 --- /dev/null +++ b/SoftwareInstallationFileImplement/Implements/ShopStorage.cs @@ -0,0 +1,133 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using SoftwareInstallationFileImplement.Models; +using System.Collections.Generic; + +namespace SoftwareInstallationFileImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataFileSingleton source; + + public ShopStorage() + { + source = DataFileSingleton.GetInstance(); + } + + public List GetFullList() + { + return source.Shops + .Select(x => x.GetViewModel) + .ToList(); + } + + public List GetFilteredList(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName)) + { + return new(); + } + return source.Shops + .Where(x => x.ShopName.Contains(model.ShopName)) + .Select(x => x.GetViewModel) + .ToList(); + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + return source.Shops + .FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) || + (model.Id.HasValue && x.Id == model.Id)) + ?.GetViewModel; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1; + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + source.Shops.Add(newShop); + source.SaveShops(); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (shop == null) + { + return null; + } + shop.Update(model); + source.SaveShops(); + return shop.GetViewModel; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + var element = source.Shops.FirstOrDefault(x => x.Id == model.Id); + if (element != null) + { + source.Shops.Remove(element); + source.SaveShops(); + return element.GetViewModel; + } + return null; + } + + public bool MakeSale(IPackageModel model, int count) + { + var Package = source.Packages.FirstOrDefault(x => x.Id == model.Id); + int countInShops = source.Shops.SelectMany(x => x.ShopPackages).Sum(y => y.Key == model.Id ? y.Value.Item2 : 0); + + if (Package == null || countInShops < count) + { + return false; + } + + foreach (var shop in source.Shops) + { + var shopPackages = shop.ShopPackages.Where(x => x.Key == model.Id); + if (shopPackages.Any()) + { + var shopPackage = shopPackages.First(); + int min = Math.Min(shopPackage.Value.Item2, count); + if (min == shopPackage.Value.Item2) + { + shop.ShopPackages.Remove(shopPackage.Key); + } + else + { + shop.ShopPackages[shopPackage.Key] = (shopPackage.Value.Item1, shopPackage.Value.Item2 - min); + } + shop.Update(new ShopBindingModel + { + Id = shop.Id, + ShopName = shop.ShopName, + Address = shop.Address, + DateOpening = shop.DateOpening, + ShopPackages = shop.ShopPackages, + PackagesMaximum = shop.PackagesMaximum + }); + count -= min; + if (count <= 0) + { + break; + } + } + } + source.SaveShops(); + return true; + } + } +} diff --git a/SoftwareInstallationFileImplement/Models/Component.cs b/SoftwareInstallationFileImplement/Models/Component.cs index fe76abf..18a9f5a 100644 --- a/SoftwareInstallationFileImplement/Models/Component.cs +++ b/SoftwareInstallationFileImplement/Models/Component.cs @@ -1,11 +1,6 @@ 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 @@ -13,8 +8,11 @@ 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) @@ -28,6 +26,7 @@ namespace SoftwareInstallationFileImplement.Models Cost = model.Cost }; } + public static Component? Create(XElement element) { if (element == null) @@ -41,6 +40,7 @@ namespace SoftwareInstallationFileImplement.Models Cost = Convert.ToDouble(element.Element("Cost")!.Value) }; } + public void Update(ComponentBindingModel model) { if (model == null) @@ -50,15 +50,17 @@ namespace SoftwareInstallationFileImplement.Models 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())); + new XAttribute("Id", Id), + new XElement("ComponentName", ComponentName), + new XElement("Cost", Cost.ToString())); } } diff --git a/SoftwareInstallationFileImplement/Models/Package.cs b/SoftwareInstallationFileImplement/Models/Package.cs index 7d04cd7..d0002b9 100644 --- a/SoftwareInstallationFileImplement/Models/Package.cs +++ b/SoftwareInstallationFileImplement/Models/Package.cs @@ -1,11 +1,6 @@ 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 @@ -13,25 +8,30 @@ 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; + + private Dictionary? _iceCreamComponents = null; + public Dictionary PackageComponents { get { - if (_PackageComponents == null) + if (_iceCreamComponents == null) { var source = DataFileSingleton.GetInstance(); - _PackageComponents = Components.ToDictionary(x => x.Key, y => - ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, - y.Value)); + _iceCreamComponents = Components.ToDictionary(x => x.Key, + y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value)); } - return _PackageComponents; + return _iceCreamComponents; } } - public static Package? Create(PackageBindingModel model) + + public static Package? Create(PackageBindingModel? model) { if (model == null) { @@ -42,10 +42,10 @@ namespace SoftwareInstallationFileImplement.Models Id = model.Id, PackageName = model.PackageName, Price = model.Price, - Components = model.PackageComponents.ToDictionary(x => x.Key, x - => x.Value.Item2) + Components = model.PackageComponents.ToDictionary(x => x.Key, x => x.Value.Item2) }; } + public static Package? Create(XElement element) { if (element == null) @@ -57,14 +57,12 @@ namespace SoftwareInstallationFileImplement.Models 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)) + 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) + + public void Update(PackageBindingModel? model) { if (model == null) { @@ -72,10 +70,10 @@ namespace SoftwareInstallationFileImplement.Models } PackageName = model.PackageName; Price = model.Price; - Components = model.PackageComponents.ToDictionary(x => x.Key, x => - x.Value.Item2); - _PackageComponents = null; + Components = model.PackageComponents.ToDictionary(x => x.Key, x => x.Value.Item2); + _iceCreamComponents = null; } + public PackageViewModel GetViewModel => new() { Id = Id, @@ -83,13 +81,14 @@ namespace SoftwareInstallationFileImplement.Models 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())); - + 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/Models/Shop.cs b/SoftwareInstallationFileImplement/Models/Shop.cs new file mode 100644 index 0000000..e1fd7ad --- /dev/null +++ b/SoftwareInstallationFileImplement/Models/Shop.cs @@ -0,0 +1,108 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using System.Xml.Linq; + +namespace SoftwareInstallationFileImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + + public Dictionary Packages { get; private set; } = new(); + + private Dictionary? _shopPackages = null; + + public Dictionary ShopPackages + { + get + { + if (_shopPackages == null) + { + var source = DataFileSingleton.GetInstance(); + _shopPackages = Packages.ToDictionary(x => x.Key, + y => ((source.Packages.FirstOrDefault(z => z.Id == y.Key) as IPackageModel)!, y.Value)); + } + return _shopPackages; + } + } + + public int PackagesMaximum { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + Packages = model.ShopPackages.ToDictionary(x => x.Key, x => x.Value.Item2), + PackagesMaximum = model.PackagesMaximum + }; + } + + public static Shop? Create(XElement element) + { + if (element == null) + { + return null; + } + return new Shop() + { + Id = Convert.ToInt32(element.Attribute("Id")!.Value), + ShopName = element.Element("ShopName")!.Value, + Address = element.Element("Address")!.Value, + DateOpening = Convert.ToDateTime(element.Element("DateOpening")!.Value), + PackagesMaximum = Convert.ToInt32(element.Element("PackagesMaximum")!.Value), + Packages = element.Element("ShopPackages")!.Elements("ShopPackage") + .ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value)) + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + PackagesMaximum = model.PackagesMaximum; + Packages = model.ShopPackages.ToDictionary(x => x.Key, x => x.Value.Item2); + _shopPackages = null; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + ShopPackages = ShopPackages, + PackagesMaximum = PackagesMaximum + }; + + public XElement GetXElement => new("Shop", + new XAttribute("Id", Id), + new XElement("ShopName", ShopName), + new XElement("Address", Address), + new XElement("DateOpening", DateOpening.ToString()), + new XElement("PackagesMaximum", PackagesMaximum.ToString()), + new XElement("ShopPackages", + Packages.Select(x => new XElement("ShopPackage", + new XElement("Key", x.Key), + new XElement("Value", x.Value))).ToArray())); + } +} diff --git a/SoftwareInstallationListImplement/DataListSingleton.cs b/SoftwareInstallationListImplement/DataListSingleton.cs index 76fc819..ff529f0 100644 --- a/SoftwareInstallationListImplement/DataListSingleton.cs +++ b/SoftwareInstallationListImplement/DataListSingleton.cs @@ -1,24 +1,27 @@ using SoftwareInstallationListImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationListImplement { - internal class DataListSingleton + public class DataListSingleton { private static DataListSingleton? _instance; + public List Components { get; set; } + public List Orders { get; set; } + public List Packages { get; set; } + + public List Shops { get; set; } + private DataListSingleton() { Components = new List(); Orders = new List(); Packages = new List(); + Shops = new List(); } + public static DataListSingleton GetInstance() { if (_instance == null) @@ -28,4 +31,4 @@ namespace SoftwareInstallationListImplement return _instance; } } -} +} \ No newline at end of file diff --git a/SoftwareInstallationListImplement/Implements/ComponentStorage.cs b/SoftwareInstallationListImplement/Implements/ComponentStorage.cs index 9c26614..27c9264 100644 --- a/SoftwareInstallationListImplement/Implements/ComponentStorage.cs +++ b/SoftwareInstallationListImplement/Implements/ComponentStorage.cs @@ -1,23 +1,20 @@ -using SoftwareInstallationContracts.StoragesContracts; -using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationContracts.ViewModels; using SoftwareInstallationListImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationListImplement.Implements { public class ComponentStorage : IComponentStorage { private readonly DataListSingleton _source; + public ComponentStorage() { _source = DataListSingleton.GetInstance(); } + public List GetFullList() { var result = new List(); @@ -27,6 +24,7 @@ namespace SoftwareInstallationListImplement.Implements } return result; } + public List GetFilteredList(ComponentSearchModel model) { var result = new List(); @@ -43,6 +41,7 @@ namespace SoftwareInstallationListImplement.Implements } return result; } + public ComponentViewModel? GetElement(ComponentSearchModel model) { if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue) @@ -51,7 +50,8 @@ namespace SoftwareInstallationListImplement.Implements } foreach (var component in _source.Components) { - if ((!string.IsNullOrEmpty(model.ComponentName) && component.ComponentName == model.ComponentName) || + if ((!string.IsNullOrEmpty(model.ComponentName) && + component.ComponentName == model.ComponentName) || (model.Id.HasValue && component.Id == model.Id)) { return component.GetViewModel; @@ -59,6 +59,7 @@ namespace SoftwareInstallationListImplement.Implements } return null; } + public ComponentViewModel? Insert(ComponentBindingModel model) { model.Id = 1; @@ -77,6 +78,7 @@ namespace SoftwareInstallationListImplement.Implements _source.Components.Add(newComponent); return newComponent.GetViewModel; } + public ComponentViewModel? Update(ComponentBindingModel model) { foreach (var component in _source.Components) @@ -89,6 +91,7 @@ namespace SoftwareInstallationListImplement.Implements } return null; } + public ComponentViewModel? Delete(ComponentBindingModel model) { for (int i = 0; i < _source.Components.Count; ++i) @@ -103,4 +106,4 @@ namespace SoftwareInstallationListImplement.Implements return null; } } -} +} \ No newline at end of file diff --git a/SoftwareInstallationListImplement/Implements/OrderStorage.cs b/SoftwareInstallationListImplement/Implements/OrderStorage.cs index a3afef2..40840cc 100644 --- a/SoftwareInstallationListImplement/Implements/OrderStorage.cs +++ b/SoftwareInstallationListImplement/Implements/OrderStorage.cs @@ -3,11 +3,6 @@ using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationContracts.ViewModels; using SoftwareInstallationListImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationListImplement.Implements { @@ -25,7 +20,7 @@ namespace SoftwareInstallationListImplement.Implements var result = new List(); foreach (var order in _source.Orders) { - result.Add(AttachPackageName(order.GetViewModel)); + result.Add(AddPackageName(order.GetViewModel)); } return result; } @@ -33,7 +28,7 @@ namespace SoftwareInstallationListImplement.Implements public List GetFilteredList(OrderSearchModel model) { var result = new List(); - if (model == null || !model.Id.HasValue) + if (!model.Id.HasValue) { return result; } @@ -41,7 +36,7 @@ namespace SoftwareInstallationListImplement.Implements { if (order.Id == model.Id) { - result.Add(AttachPackageName(order.GetViewModel)); + result.Add(AddPackageName(order.GetViewModel)); } } return result; @@ -55,9 +50,9 @@ namespace SoftwareInstallationListImplement.Implements } foreach (var order in _source.Orders) { - if (model.Id.HasValue && order.Id == model.Id) + if (order.Id == model.Id) { - return AttachPackageName(order.GetViewModel); + return AddPackageName(order.GetViewModel); } } return null; @@ -79,7 +74,7 @@ namespace SoftwareInstallationListImplement.Implements return null; } _source.Orders.Add(newOrder); - return AttachPackageName(newOrder.GetViewModel); + return AddPackageName(newOrder.GetViewModel); } public OrderViewModel? Update(OrderBindingModel model) @@ -89,7 +84,7 @@ namespace SoftwareInstallationListImplement.Implements if (order.Id == model.Id) { order.Update(model); - return AttachPackageName(order.GetViewModel); + return AddPackageName(order.GetViewModel); } } return null; @@ -103,23 +98,20 @@ namespace SoftwareInstallationListImplement.Implements { var element = _source.Orders[i]; _source.Orders.RemoveAt(i); - return AttachPackageName(element.GetViewModel); + return AddPackageName(element.GetViewModel); } } return null; } - private OrderViewModel AttachPackageName(OrderViewModel model) + private OrderViewModel AddPackageName(OrderViewModel model) { - foreach (var Package in _source.Packages) + var selectedPackage = _source.Packages.Find(iceCream => iceCream.Id == model.PackageId); + if (selectedPackage != null) { - if (Package.Id == model.PackageId) - { - model.PackageName = Package.PackageName; - return model; - } + model.PackageName = selectedPackage.PackageName; } return model; } } -} +} \ No newline at end of file diff --git a/SoftwareInstallationListImplement/Implements/PackageStorage.cs b/SoftwareInstallationListImplement/Implements/PackageStorage.cs index 97a39fb..37c0464 100644 --- a/SoftwareInstallationListImplement/Implements/PackageStorage.cs +++ b/SoftwareInstallationListImplement/Implements/PackageStorage.cs @@ -3,21 +3,95 @@ using SoftwareInstallationContracts.SearchModels; using SoftwareInstallationContracts.StoragesContracts; using SoftwareInstallationContracts.ViewModels; using SoftwareInstallationListImplement.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace SoftwareInstallationListImplement.Implements { - public class PackageStorage : IPackageStorage { + public class PackageStorage : IPackageStorage + { private readonly DataListSingleton _source; + public PackageStorage() { _source = DataListSingleton.GetInstance(); } + public List GetFullList() + { + var result = new List(); + foreach (var iceCream in _source.Packages) + { + result.Add(iceCream.GetViewModel); + } + return result; + } + + public List GetFilteredList(PackageSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.PackageName)) + { + return result; + } + foreach (var iceCream in _source.Packages) + { + if (iceCream.PackageName.Contains(model.PackageName)) + { + result.Add(iceCream.GetViewModel); + } + } + return result; + } + + public PackageViewModel? GetElement(PackageSearchModel model) + { + if (string.IsNullOrEmpty(model.PackageName) && !model.Id.HasValue) + { + return null; + } + foreach (var iceCream in _source.Packages) + { + if ((!string.IsNullOrEmpty(model.PackageName) && + iceCream.PackageName == model.PackageName) || + (model.Id.HasValue && iceCream.Id == model.Id)) + { + return iceCream.GetViewModel; + } + } + return null; + } + + public PackageViewModel? Insert(PackageBindingModel model) + { + model.Id = 1; + foreach (var iceCream in _source.Packages) + { + if (model.Id <= iceCream.Id) + { + model.Id = iceCream.Id + 1; + } + } + var newPackage = Package.Create(model); + if (newPackage == null) + { + return null; + } + _source.Packages.Add(newPackage); + return newPackage.GetViewModel; + } + + public PackageViewModel? Update(PackageBindingModel model) + { + foreach (var iceCream in _source.Packages) + { + if (iceCream.Id == model.Id) + { + iceCream.Update(model); + return iceCream.GetViewModel; + } + } + return null; + } + public PackageViewModel? Delete(PackageBindingModel model) { for (int i = 0; i < _source.Packages.Count; ++i) @@ -31,81 +105,5 @@ namespace SoftwareInstallationListImplement.Implements } return null; } - - public PackageViewModel? GetElement(PackageSearchModel model) - { - if (string.IsNullOrEmpty(model.PackageName) && !model.Id.HasValue) - { - return null; - } - foreach (var Package in _source.Packages) - { - if ((!string.IsNullOrEmpty(model.PackageName) && Package.PackageName == model.PackageName) || - (model.Id.HasValue && Package.Id == model.Id)) - { - return Package.GetViewModel; - } - } - return null; - } - - public List GetFilteredList(PackageSearchModel model) - { - var result = new List(); - if (string.IsNullOrEmpty(model.PackageName)) - { - return result; - } - foreach (var Package in _source.Packages) - { - if (Package.PackageName.Contains(model.PackageName)) - { - result.Add(Package.GetViewModel); - } - } - return result; - } - - public List GetFullList() - { - var result = new List(); - foreach (var Package in _source.Packages) - { - result.Add(Package.GetViewModel); - } - return result; - } - - public PackageViewModel? Insert(PackageBindingModel model) - { - model.Id = 1; - foreach (var Package in _source.Packages) - { - if (model.Id <= Package.Id) - { - model.Id = Package.Id + 1; - } - } - var newPackage = Package.Create(model); - if (newPackage == null) - { - return null; - } - _source.Packages.Add(newPackage); - return newPackage.GetViewModel; - } - - public PackageViewModel? Update(PackageBindingModel model) - { - foreach (var Package in _source.Packages) - { - if (Package.Id == model.Id) - { - Package.Update(model); - return Package.GetViewModel; - } - } - return null; - } } -} +} \ No newline at end of file diff --git a/SoftwareInstallationListImplement/Implements/ShopStorage.cs b/SoftwareInstallationListImplement/Implements/ShopStorage.cs new file mode 100644 index 0000000..1bdf2e7 --- /dev/null +++ b/SoftwareInstallationListImplement/Implements/ShopStorage.cs @@ -0,0 +1,115 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.SearchModels; +using SoftwareInstallationContracts.StoragesContracts; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; +using SoftwareInstallationListImplement.Models; + +namespace SoftwareInstallationListImplement.Implements +{ + public class ShopStorage : IShopStorage + { + private readonly DataListSingleton _source; + + public ShopStorage() + { + _source = DataListSingleton.GetInstance(); + } + + public List GetFullList() + { + var result = new List(); + foreach (var shop in _source.Shops) + { + result.Add(shop.GetViewModel); + } + return result; + } + + public List GetFilteredList(ShopSearchModel model) + { + var result = new List(); + if (string.IsNullOrEmpty(model.ShopName)) + { + return result; + } + foreach (var shop in _source.Shops) + { + if (shop.ShopName.Contains(model.ShopName)) + { + result.Add(shop.GetViewModel); + } + } + return result; + } + + public ShopViewModel? GetElement(ShopSearchModel model) + { + if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue) + { + return null; + } + foreach (var shop in _source.Shops) + { + if ((!string.IsNullOrEmpty(model.ShopName) && + shop.ShopName == model.ShopName) || + (model.Id.HasValue && shop.Id == model.Id)) + { + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Insert(ShopBindingModel model) + { + model.Id = 1; + foreach (var shop in _source.Shops) + { + if (model.Id <= shop.Id) + { + model.Id = shop.Id + 1; + } + } + var newShop = Shop.Create(model); + if (newShop == null) + { + return null; + } + _source.Shops.Add(newShop); + return newShop.GetViewModel; + } + + public ShopViewModel? Update(ShopBindingModel model) + { + foreach (var shop in _source.Shops) + { + if (shop.Id == model.Id) + { + shop.Update(model); + return shop.GetViewModel; + } + } + return null; + } + + public ShopViewModel? Delete(ShopBindingModel model) + { + for (int i = 0; i < _source.Shops.Count; ++i) + { + if (_source.Shops[i].Id == model.Id) + { + var element = _source.Shops[i]; + _source.Shops.RemoveAt(i); + return element.GetViewModel; + } + } + return null; + } + + public bool MakeSale(IPackageModel model, int count) + { + throw new NotImplementedException(); + } + } +} diff --git a/SoftwareInstallationListImplement/Models/Component.cs b/SoftwareInstallationListImplement/Models/Component.cs index 4a114fb..7a6f3d4 100644 --- a/SoftwareInstallationListImplement/Models/Component.cs +++ b/SoftwareInstallationListImplement/Models/Component.cs @@ -7,8 +7,11 @@ namespace SoftwareInstallationListImplement.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) @@ -22,6 +25,7 @@ namespace SoftwareInstallationListImplement.Models Cost = model.Cost }; } + public void Update(ComponentBindingModel? model) { if (model == null) @@ -31,6 +35,7 @@ namespace SoftwareInstallationListImplement.Models ComponentName = model.ComponentName; Cost = model.Cost; } + public ComponentViewModel GetViewModel => new() { Id = Id, diff --git a/SoftwareInstallationListImplement/Models/Order.cs b/SoftwareInstallationListImplement/Models/Order.cs index fe7cccd..d954d40 100644 --- a/SoftwareInstallationListImplement/Models/Order.cs +++ b/SoftwareInstallationListImplement/Models/Order.cs @@ -1,25 +1,26 @@ using SoftwareInstallationContracts.BindingModels; using SoftwareInstallationContracts.ViewModels; -using SoftwareInstallationDataModels.Enums; using SoftwareInstallationDataModels.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Reflection; -using System.Text; -using System.Threading.Tasks; +using SoftwareInstallationDataModels.Enums; namespace SoftwareInstallationListImplement.Models { public class Order : IOrderModel { public int Id { get; private set; } + public int PackageId { get; private set; } + public int Count { get; private set; } + public double Sum { get; private set; } - public OrderStatus Status { get; private set; } - public DateTime DateCreate { get; private set; } + + public OrderStatus Status { get; private set; } + + public DateTime DateCreate { get; private set; } + public DateTime? DateImplement { get; private set; } + public static Order? Create(OrderBindingModel? model) { if (model == null) @@ -34,22 +35,20 @@ namespace SoftwareInstallationListImplement.Models Sum = model.Sum, Status = model.Status, DateCreate = model.DateCreate, - DateImplement = model.DateImplement, + DateImplement = model.DateImplement }; } + public void Update(OrderBindingModel? model) { if (model == null) { return; } - PackageId = model.PackageId; - Count = model.Count; - Sum = model.Sum; Status = model.Status; - DateCreate = model.DateCreate; DateImplement = model.DateImplement; } + public OrderViewModel GetViewModel => new() { Id = Id, @@ -58,7 +57,7 @@ namespace SoftwareInstallationListImplement.Models Sum = Sum, Status = Status, DateCreate = DateCreate, - DateImplement = DateImplement, + DateImplement = DateImplement }; } -} +} \ No newline at end of file diff --git a/SoftwareInstallationListImplement/Models/Package.cs b/SoftwareInstallationListImplement/Models/Package.cs index 3d51572..e94c9e7 100644 --- a/SoftwareInstallationListImplement/Models/Package.cs +++ b/SoftwareInstallationListImplement/Models/Package.cs @@ -1,24 +1,23 @@ 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; namespace SoftwareInstallationListImplement.Models { - internal class Package : IPackageModel + 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 PackageComponents { get; private set; } = new Dictionary(); + public static Package? Create(PackageBindingModel? model) { if (model == null) @@ -33,6 +32,7 @@ namespace SoftwareInstallationListImplement.Models PackageComponents = model.PackageComponents }; } + public void Update(PackageBindingModel? model) { if (model == null) @@ -43,6 +43,7 @@ namespace SoftwareInstallationListImplement.Models Price = model.Price; PackageComponents = model.PackageComponents; } + public PackageViewModel GetViewModel => new() { Id = Id, @@ -50,6 +51,5 @@ namespace SoftwareInstallationListImplement.Models Price = Price, PackageComponents = PackageComponents }; - } -} +} \ No newline at end of file diff --git a/SoftwareInstallationListImplement/Models/Shop.cs b/SoftwareInstallationListImplement/Models/Shop.cs new file mode 100644 index 0000000..dc340d6 --- /dev/null +++ b/SoftwareInstallationListImplement/Models/Shop.cs @@ -0,0 +1,65 @@ +using SoftwareInstallationContracts.BindingModels; +using SoftwareInstallationContracts.ViewModels; +using SoftwareInstallationDataModels.Models; + +namespace SoftwareInstallationListImplement.Models +{ + public class Shop : IShopModel + { + public int Id { get; private set; } + + public string ShopName { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public DateTime DateOpening { get; private set; } + + public Dictionary ShopPackages + { + get; + private set; + } = new Dictionary(); + + public int PackagesMaximum { get; private set; } + + public static Shop? Create(ShopBindingModel? model) + { + if (model == null) + { + return null; + } + return new Shop() + { + Id = model.Id, + ShopName = model.ShopName, + Address = model.Address, + DateOpening = model.DateOpening, + ShopPackages = model.ShopPackages, + PackagesMaximum = model.PackagesMaximum + }; + } + + public void Update(ShopBindingModel? model) + { + if (model == null) + { + return; + } + ShopName = model.ShopName; + Address = model.Address; + DateOpening = model.DateOpening; + ShopPackages = model.ShopPackages; + PackagesMaximum = model.PackagesMaximum; + } + + public ShopViewModel GetViewModel => new() + { + Id = Id, + ShopName = ShopName, + Address = Address, + DateOpening = DateOpening, + ShopPackages = ShopPackages, + PackagesMaximum = PackagesMaximum + }; + } +}