diff --git a/RenovationWork/FormShop.Designer.cs b/RenovationWork/FormShop.Designer.cs
new file mode 100644
index 0000000..e41cc84
--- /dev/null
+++ b/RenovationWork/FormShop.Designer.cs
@@ -0,0 +1,190 @@
+namespace RenovationWorkView
+{
+ 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();
+ labelAdress = new Label();
+ labelDate = new Label();
+ textBoxName = new TextBox();
+ textBoxAddress = new TextBox();
+ dateTimePicker = new DateTimePicker();
+ dataGridView = new DataGridView();
+ ColumnId = new DataGridViewTextBoxColumn();
+ ColumnName = new DataGridViewTextBoxColumn();
+ ColumnPrice = new DataGridViewTextBoxColumn();
+ ColumnCount = new DataGridViewTextBoxColumn();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // labelName
+ //
+ labelName.AutoSize = true;
+ labelName.Location = new Point(12, 7);
+ labelName.Name = "labelName";
+ labelName.Size = new Size(62, 15);
+ labelName.TabIndex = 0;
+ labelName.Text = "Название:";
+ //
+ // labelAdress
+ //
+ labelAdress.AutoSize = true;
+ labelAdress.Location = new Point(12, 38);
+ labelAdress.Name = "labelAdress";
+ labelAdress.Size = new Size(43, 15);
+ labelAdress.TabIndex = 1;
+ labelAdress.Text = "Адрес:";
+ //
+ // labelDate
+ //
+ labelDate.AutoSize = true;
+ labelDate.Location = new Point(12, 67);
+ labelDate.Name = "labelDate";
+ labelDate.Size = new Size(90, 15);
+ labelDate.TabIndex = 2;
+ labelDate.Text = "Дата открытия:";
+ //
+ // textBoxName
+ //
+ textBoxName.Location = new Point(106, 7);
+ textBoxName.Name = "textBoxName";
+ textBoxName.Size = new Size(229, 23);
+ textBoxName.TabIndex = 3;
+ //
+ // textBoxAddress
+ //
+ textBoxAddress.Location = new Point(106, 38);
+ textBoxAddress.Name = "textBoxAddress";
+ textBoxAddress.Size = new Size(229, 23);
+ textBoxAddress.TabIndex = 4;
+ //
+ // dateTimePicker
+ //
+ dateTimePicker.Location = new Point(106, 67);
+ dateTimePicker.Name = "dateTimePicker";
+ dateTimePicker.Size = new Size(229, 23);
+ dateTimePicker.TabIndex = 5;
+ //
+ // dataGridView
+ //
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnPrice, ColumnCount });
+ dataGridView.Location = new Point(12, 108);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowTemplate.Height = 25;
+ dataGridView.Size = new Size(770, 250);
+ dataGridView.TabIndex = 6;
+ //
+ // ColumnId
+ //
+ ColumnId.HeaderText = "ColumnId";
+ ColumnId.Name = "ColumnId";
+ ColumnId.Visible = false;
+ //
+ // ColumnName
+ //
+ ColumnName.HeaderText = "Изделние";
+ ColumnName.MinimumWidth = 8;
+ ColumnName.Name = "ColumnName";
+ ColumnName.Width = 426;
+ //
+ // ColumnPrice
+ //
+ ColumnPrice.HeaderText = "Цена";
+ ColumnPrice.MinimumWidth = 8;
+ ColumnPrice.Name = "ColumnPrice";
+ ColumnPrice.Width = 150;
+ //
+ // ColumnCount
+ //
+ ColumnCount.HeaderText = "Количество";
+ ColumnCount.MinimumWidth = 8;
+ ColumnCount.Name = "ColumnCount";
+ ColumnCount.Width = 150;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(534, 376);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(119, 23);
+ buttonSave.TabIndex = 7;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(659, 376);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(119, 23);
+ buttonCancel.TabIndex = 8;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // FormShop
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(790, 411);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(dataGridView);
+ Controls.Add(dateTimePicker);
+ Controls.Add(textBoxAddress);
+ Controls.Add(textBoxName);
+ Controls.Add(labelDate);
+ Controls.Add(labelAdress);
+ Controls.Add(labelName);
+ Name = "FormShop";
+ Text = "Магазин";
+ Load += FormShop_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelName;
+ private Label labelAdress;
+ private Label labelDate;
+ private TextBox textBoxName;
+ private TextBox textBoxAddress;
+ private DateTimePicker dateTimePicker;
+ private DataGridView dataGridView;
+ private DataGridViewTextBoxColumn ColumnId;
+ private DataGridViewTextBoxColumn ColumnName;
+ private DataGridViewTextBoxColumn ColumnPrice;
+ private DataGridViewTextBoxColumn ColumnCount;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/RenovationWork/FormShop.cs b/RenovationWork/FormShop.cs
new file mode 100644
index 0000000..de327df
--- /dev/null
+++ b/RenovationWork/FormShop.cs
@@ -0,0 +1,128 @@
+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 RenovationWorkContracts.BindingModels;
+using RenovationWorkContracts.BusinessLogicsContracts;
+using RenovationWorkContracts.SearchModels;
+using RenovationWorkDataModels.Models;
+using Microsoft.Extensions.Logging;
+using Microsoft.VisualBasic.Logging;
+using RenovationWorkListImplement.Models;
+
+
+namespace RenovationWorkView
+{
+ public partial class FormShop : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IShopLogic _logic;
+ public int? _id;
+ private Dictionary _repairs;
+ public FormShop(ILogger logger, IShopLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ _repairs = new();
+ }
+
+ private void FormShop_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ _logger.LogInformation("Загрузка магазина");
+ try
+ {
+ var shop = _logic.ReadElement(new ShopSearchModel { Id = _id });
+ if (shop != null)
+ {
+ textBoxName.Text = shop.ShopName;
+ textBoxAddress.Text = shop.Address;
+ dateTimePicker.Text = shop.OpeningDate.ToString();
+ _repairs = shop.ShopRepairs;
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки магазина");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+
+ private void LoadData()
+ {
+ _logger.LogInformation("Загрузка товаров магазина");
+ try
+ {
+ if (_repairs != null)
+ {
+ foreach (var repairs in _repairs)
+ {
+ dataGridView.Rows.Add(new object[] { repairs.Key, repairs.Value.Item1.RepairName,
+ repairs.Value.Item1.Price, repairs.Value.Item2 });
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки изделий магазина");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxName.Text))
+ {
+ MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (string.IsNullOrEmpty(textBoxAddress.Text))
+ {
+ MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение магазина");
+ try
+ {
+ var model = new ShopBindingModel
+ {
+ Id = _id ?? 0,
+ ShopName = textBoxName.Text,
+ Address = textBoxAddress.Text,
+ OpeningDate = dateTimePicker.Value.Date,
+ ShopRepairs = _repairs
+ };
+ var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения магазина");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/RenovationWork/FormShop.resx b/RenovationWork/FormShop.resx
new file mode 100644
index 0000000..ef64542
--- /dev/null
+++ b/RenovationWork/FormShop.resx
@@ -0,0 +1,144 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
\ No newline at end of file
diff --git a/RenovationWork/FormShops.Designer.cs b/RenovationWork/FormShops.Designer.cs
new file mode 100644
index 0000000..ccca102
--- /dev/null
+++ b/RenovationWork/FormShops.Designer.cs
@@ -0,0 +1,114 @@
+namespace RenovationWorkView
+{
+ 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();
+ buttonAdd = new Button();
+ buttonUpdate = new Button();
+ buttonDelete = new Button();
+ buttonRefresh = new Button();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // dataGridView
+ //
+ dataGridView.BackgroundColor = SystemColors.ControlLightLight;
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(12, 12);
+ dataGridView.Name = "dataGridView";
+ dataGridView.RowTemplate.Height = 25;
+ dataGridView.Size = new Size(653, 426);
+ dataGridView.TabIndex = 0;
+ //
+ // buttonAdd
+ //
+ buttonAdd.Location = new Point(671, 38);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(117, 23);
+ buttonAdd.TabIndex = 1;
+ buttonAdd.Text = "Добавить";
+ buttonAdd.UseVisualStyleBackColor = true;
+ buttonAdd.Click += buttonAdd_Click;
+ //
+ // buttonUpdate
+ //
+ buttonUpdate.Location = new Point(671, 78);
+ buttonUpdate.Name = "buttonUpdate";
+ buttonUpdate.Size = new Size(117, 23);
+ buttonUpdate.TabIndex = 2;
+ buttonUpdate.Text = "Изменить";
+ buttonUpdate.UseVisualStyleBackColor = true;
+ buttonUpdate.Click += buttonUpdate_Click;
+ //
+ // buttonDelete
+ //
+ buttonDelete.Location = new Point(671, 119);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(117, 23);
+ buttonDelete.TabIndex = 3;
+ buttonDelete.Text = "Удалить";
+ buttonDelete.UseVisualStyleBackColor = true;
+ buttonDelete.Click += buttonDelete_Click;
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Location = new Point(671, 158);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(117, 23);
+ buttonRefresh.TabIndex = 4;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += buttonRefresh_Click;
+ //
+ // FormShops
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(buttonRefresh);
+ Controls.Add(buttonDelete);
+ Controls.Add(buttonUpdate);
+ Controls.Add(buttonAdd);
+ Controls.Add(dataGridView);
+ Name = "FormShops";
+ Text = "Магазины";
+ Load += FormShops_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private DataGridView dataGridView;
+ private Button buttonAdd;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Button buttonRefresh;
+ }
+}
\ No newline at end of file
diff --git a/RenovationWork/FormShops.cs b/RenovationWork/FormShops.cs
new file mode 100644
index 0000000..90e73cf
--- /dev/null
+++ b/RenovationWork/FormShops.cs
@@ -0,0 +1,117 @@
+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 RenovationWorkContracts.BindingModels;
+using RenovationWorkContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+using Microsoft.VisualBasic.Logging;
+
+
+namespace RenovationWorkView
+{
+ 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["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["OpeningDate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ dataGridView.Columns["ShopRepairs"].Visible = false;
+ }
+ _logger.LogInformation("Загрузка магазинов");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки магазинов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonAdd_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormShop));
+ if (service is FormShop form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+
+ private void buttonUpdate_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 buttonDelete_Click(object sender, EventArgs e)
+ {
+ if (dataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Удаление магазина");
+ try
+ {
+ if (!_logic.Delete(new ShopBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления магазина");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+
+ private void buttonRefresh_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/RenovationWork/FormShops.resx b/RenovationWork/FormShops.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/RenovationWork/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/RenovationWork/FormSupply.Designer.cs b/RenovationWork/FormSupply.Designer.cs
new file mode 100644
index 0000000..2fb0443
--- /dev/null
+++ b/RenovationWork/FormSupply.Designer.cs
@@ -0,0 +1,141 @@
+namespace RenovationWorkView
+{
+ partial class FormSupply
+ {
+ ///
+ /// 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();
+ labelRepair = new Label();
+ labelCount = new Label();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ textBoxCount = new TextBox();
+ comboBoxShop = new ComboBox();
+ comboBoxRepair = new ComboBox();
+ SuspendLayout();
+ //
+ // labelShop
+ //
+ labelShop.AutoSize = true;
+ labelShop.Location = new Point(12, 12);
+ labelShop.Name = "labelShop";
+ labelShop.Size = new Size(57, 15);
+ labelShop.TabIndex = 0;
+ labelShop.Text = "Магазин:";
+ //
+ // labelRepair
+ //
+ labelRepair.AutoSize = true;
+ labelRepair.Location = new Point(13, 41);
+ labelRepair.Name = "labelRepair";
+ labelRepair.Size = new Size(56, 15);
+ labelRepair.TabIndex = 1;
+ labelRepair.Text = "Изделие:";
+ //
+ // labelCount
+ //
+ labelCount.AutoSize = true;
+ labelCount.Location = new Point(12, 67);
+ labelCount.Name = "labelCount";
+ labelCount.Size = new Size(75, 15);
+ labelCount.TabIndex = 2;
+ labelCount.Text = "Количество:";
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(189, 110);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 3;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(280, 110);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 4;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // textBoxCount
+ //
+ textBoxCount.Location = new Point(93, 70);
+ textBoxCount.Name = "textBoxCount";
+ textBoxCount.Size = new Size(126, 23);
+ textBoxCount.TabIndex = 5;
+ //
+ // comboBoxShop
+ //
+ comboBoxShop.FormattingEnabled = true;
+ comboBoxShop.Location = new Point(93, 12);
+ comboBoxShop.Name = "comboBoxShop";
+ comboBoxShop.Size = new Size(262, 23);
+ comboBoxShop.TabIndex = 6;
+ //
+ // comboBoxRepair
+ //
+ comboBoxRepair.FormattingEnabled = true;
+ comboBoxRepair.Location = new Point(93, 41);
+ comboBoxRepair.Name = "comboBoxRepair";
+ comboBoxRepair.Size = new Size(262, 23);
+ comboBoxRepair.TabIndex = 7;
+ //
+ // FormSupply
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(367, 144);
+ Controls.Add(comboBoxRepair);
+ Controls.Add(comboBoxShop);
+ Controls.Add(textBoxCount);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(labelCount);
+ Controls.Add(labelRepair);
+ Controls.Add(labelShop);
+ Name = "FormSupply";
+ Text = "Пополнение магазина";
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelShop;
+ private Label labelRepair;
+ private Label labelCount;
+ private Button buttonSave;
+ private Button buttonCancel;
+ private TextBox textBoxCount;
+ private ComboBox comboBoxShop;
+ private ComboBox comboBoxRepair;
+ }
+}
\ No newline at end of file
diff --git a/RenovationWork/FormSupply.cs b/RenovationWork/FormSupply.cs
new file mode 100644
index 0000000..723394b
--- /dev/null
+++ b/RenovationWork/FormSupply.cs
@@ -0,0 +1,143 @@
+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 RenovationWorkContracts.BusinessLogicsContracts;
+using RenovationWorkContracts.SearchModels;
+using RenovationWorkContracts.ViewModels;
+using RenovationWorkDataModels.Models;
+using RenovationWorkListImplement.Models;
+
+namespace RenovationWorkView
+{
+ public partial class FormSupply : Form
+ {
+ private readonly List? _repairList;
+ private readonly List? _shopsList;
+ IShopLogic _shopLogic;
+ IRepairLogic _repairLogic;
+
+ public int ShopId
+ {
+ get
+ {
+ return Convert.ToInt32(comboBoxShop.SelectedValue);
+ }
+ set
+ {
+ comboBoxShop.SelectedValue = value;
+ }
+ }
+ public int RepairId
+ {
+ get
+ {
+ return Convert.ToInt32(comboBoxRepair.SelectedValue);
+ }
+ set
+ {
+ comboBoxRepair.SelectedValue = value;
+ }
+ }
+ public IRepairModel? RepairModel
+ {
+ get
+ {
+ if (_repairList == null)
+ {
+ return null;
+ }
+ foreach (var elem in _repairList)
+ {
+ if (elem.Id == RepairId)
+ {
+ return elem;
+ }
+ }
+ return null;
+ }
+ }
+ public int Count
+ {
+ get { return Convert.ToInt32(textBoxCount.Text); }
+ set { textBoxCount.Text = value.ToString(); }
+ }
+ public FormSupply(IRepairLogic RepairLogic, IShopLogic shopLogic)
+ {
+ InitializeComponent();
+ _shopLogic = shopLogic;
+ _repairLogic = RepairLogic;
+ _repairList = RepairLogic.ReadList(null);
+ _shopsList = shopLogic.ReadList(null);
+ if (_repairList != null)
+ {
+ comboBoxRepair.DisplayMember = "RepairName";
+ comboBoxRepair.ValueMember = "Id";
+ comboBoxRepair.DataSource = _repairList;
+ comboBoxRepair.SelectedItem = null;
+ }
+ if (_shopsList != null)
+ {
+ comboBoxShop.DisplayMember = "ShopName";
+ comboBoxShop.ValueMember = "Id";
+ comboBoxShop.DataSource = _shopsList;
+ comboBoxShop.SelectedItem = null;
+ }
+ }
+
+ private void buttonSave_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxCount.Text))
+ {
+ MessageBox.Show("Заполните поле Количество", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxRepair.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите кузнечное изделие", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (comboBoxShop.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите магазин", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ try
+ {
+ int count = Convert.ToInt32(textBoxCount.Text);
+ bool res = _shopLogic.ReplenishRepairs(
+ new ShopSearchModel() { Id = Convert.ToInt32(comboBoxShop.SelectedValue) },
+ _repairLogic.ReadElement(new() { Id = Convert.ToInt32(comboBoxRepair.SelectedValue) }),
+ count
+ );
+ if (!res)
+ {
+ throw new Exception("Ошибка при пополнении. Дополнительная информация в логах");
+ }
+ MessageBox.Show("Пополнение прошло успешно");
+ DialogResult = DialogResult.OK;
+ Close();
+
+ }
+ catch (Exception)
+ {
+ MessageBox.Show("Ошибка пополнения");
+ return;
+ }
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/RenovationWork/FormSupply.resx b/RenovationWork/FormSupply.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/RenovationWork/FormSupply.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/RenovationWorkBusinessLogic/BusinessLogics/ShopLogic.cs b/RenovationWorkBusinessLogic/BusinessLogics/ShopLogic.cs
new file mode 100644
index 0000000..7e3960a
--- /dev/null
+++ b/RenovationWorkBusinessLogic/BusinessLogics/ShopLogic.cs
@@ -0,0 +1,155 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using RenovationWorkContracts.BindingModels;
+using RenovationWorkContracts.BusinessLogicsContracts;
+using RenovationWorkContracts.SearchModels;
+using RenovationWorkContracts.StoragesContracts;
+using RenovationWorkContracts.ViewModels;
+using RenovationWorkDataModels.Models;
+using Microsoft.Extensions.Logging;
+
+namespace RenovationWorkBusinessLogic.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 ReplenishRepairs(ShopSearchModel model, IRepairModel repair, int count)
+ {
+ _logger.LogInformation("Try to replenish repairs. ShopName:{ShopName}. Id:{Id}", model.ShopName, model.Id);
+ if (model == null)
+ throw new ArgumentNullException(nameof(model));
+ ShopViewModel? curModel = ReadElement(model);
+ if (curModel == null)
+ {
+ _logger.LogWarning("Read operation failed");
+ return false;
+ }
+ if (repair == null)
+ throw new ArgumentNullException(nameof(repair));
+ if (count <= 0)
+ throw new ArgumentException("Количество должно быть положительным числом");
+
+ //попытка найти информацию о товаре в магазине по его идентификатору в словаре
+ //найден и добавляется
+ if (curModel.ShopRepairs.TryGetValue(repair.Id, out var pair))
+ {
+ curModel.ShopRepairs[repair.Id] = (pair.Item1, pair.Item2 + count);
+ }
+ //не найден и добавляется
+ else
+ {
+ curModel.ShopRepairs.Add(repair.Id, (repair, count));
+ }
+ Update(new()
+ {
+ Id = curModel.Id,
+ ShopName = curModel.ShopName,
+ OpeningDate = curModel.OpeningDate,
+ Address = curModel.Address,
+ ShopRepairs = curModel.ShopRepairs,
+ });
+ _logger.LogInformation("Success. RepairName:{RepairName}. Id:{Id}. Replenish:{count}",
+ repair.RepairName, repair.Id, count);
+ return true;
+ }
+ 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}. DateOpen:{DateOpen}. Id: { Id}",
+ model.ShopName, model.Address, model.OpeningDate, model.Id);
+ var element = _shopStorage.GetElement(new ShopSearchModel
+ {
+ ShopName = model.ShopName
+ });
+ if (element != null && element.Id != model.Id)
+ {
+ throw new InvalidOperationException("Магазин с таким названием уже есть");
+ }
+ }
+ }
+}
+
diff --git a/RenovationWorkContracts/BindingModels/ShopBindingModel.cs b/RenovationWorkContracts/BindingModels/ShopBindingModel.cs
new file mode 100644
index 0000000..9c22402
--- /dev/null
+++ b/RenovationWorkContracts/BindingModels/ShopBindingModel.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using RenovationWorkDataModels.Models;
+
+namespace RenovationWorkContracts.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 OpeningDate { get; set; }
+ public Dictionary ShopRepairs { get; set; } = new();
+ }
+}
diff --git a/RenovationWorkContracts/BusinessLogicsContracts/IShopLogic.cs b/RenovationWorkContracts/BusinessLogicsContracts/IShopLogic.cs
new file mode 100644
index 0000000..391f396
--- /dev/null
+++ b/RenovationWorkContracts/BusinessLogicsContracts/IShopLogic.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using RenovationWorkContracts.BindingModels;
+using RenovationWorkDataModels.Models;
+using RenovationWorkContracts.SearchModels;
+using RenovationWorkContracts.ViewModels;
+
+namespace RenovationWorkContracts.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 ReplenishRepairs(ShopSearchModel shop, IRepairModel repair, int count);
+ }
+}
diff --git a/RenovationWorkContracts/SearchModels/ShopSearchModel.cs b/RenovationWorkContracts/SearchModels/ShopSearchModel.cs
new file mode 100644
index 0000000..8204499
--- /dev/null
+++ b/RenovationWorkContracts/SearchModels/ShopSearchModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RenovationWorkContracts.SearchModels
+{
+ public class ShopSearchModel
+ {
+ public int? Id { get; set; }
+ public string? ShopName { get; set; }
+ }
+}
diff --git a/RenovationWorkContracts/StoragesContracts/IShopStorage.cs b/RenovationWorkContracts/StoragesContracts/IShopStorage.cs
new file mode 100644
index 0000000..ed014d5
--- /dev/null
+++ b/RenovationWorkContracts/StoragesContracts/IShopStorage.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using RenovationWorkContracts.BindingModels;
+using RenovationWorkContracts.SearchModels;
+using RenovationWorkContracts.ViewModels;
+
+namespace RenovationWorkContracts.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);
+ }
+}
\ No newline at end of file
diff --git a/RenovationWorkContracts/ViewModels/ShopViewModel.cs b/RenovationWorkContracts/ViewModels/ShopViewModel.cs
new file mode 100644
index 0000000..8785459
--- /dev/null
+++ b/RenovationWorkContracts/ViewModels/ShopViewModel.cs
@@ -0,0 +1,22 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using RenovationWorkDataModels.Models;
+
+namespace RenovationWorkContracts.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 OpeningDate { get; set; }
+ public Dictionary ShopRepairs { get; set; } = new();
+ }
+}
diff --git a/RenovationWorkDataModels/Models/IShopModel.cs b/RenovationWorkDataModels/Models/IShopModel.cs
new file mode 100644
index 0000000..5b61a19
--- /dev/null
+++ b/RenovationWorkDataModels/Models/IShopModel.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace RenovationWorkDataModels.Models
+{
+ public interface IShopModel : IId
+ {
+ string ShopName { get; }
+ string Address { get; }
+ DateTime OpeningDate { get; }
+ Dictionary ShopRepairs { get; }
+ }
+}
diff --git a/RenovationWorkListImplement/Implements/ShopStorage.cs b/RenovationWorkListImplement/Implements/ShopStorage.cs
new file mode 100644
index 0000000..67bfde4
--- /dev/null
+++ b/RenovationWorkListImplement/Implements/ShopStorage.cs
@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using RenovationWorkContracts.BindingModels;
+using RenovationWorkContracts.SearchModels;
+using RenovationWorkContracts.StoragesContracts;
+using RenovationWorkContracts.ViewModels;
+using RenovationWorkListImplement.Models;
+
+namespace RenovationWorkListImplement.Implements
+{
+ public class ShopStorage : IShopStorage
+ {
+ private readonly DataListSingleton _source;
+ public ShopStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ List result = new List();
+ foreach (var Shop in _source.Shops)
+ {
+ result.Add(Shop.GetViewModel);
+ }
+ return result;
+ }
+ public List GetFilteredList(ShopSearchModel model)
+ {
+ List result = new();
+ 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 (Shop.Id >= model.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;
+ }
+ }
+}
diff --git a/RenovationWorkListImplement/Models/Shop.cs b/RenovationWorkListImplement/Models/Shop.cs
new file mode 100644
index 0000000..6839e2b
--- /dev/null
+++ b/RenovationWorkListImplement/Models/Shop.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using RenovationWorkContracts.BindingModels;
+using RenovationWorkContracts.ViewModels;
+using RenovationWorkDataModels.Models;
+
+namespace RenovationWorkListImplement.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 OpeningDate { get; private set; }
+ public Dictionary ShopRepairs { get; private set; } = new();
+ public static Shop? Create(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Shop()
+ {
+ Id = model.Id,
+ ShopName = model.ShopName,
+ Address = model.Address,
+ OpeningDate = model.OpeningDate,
+ ShopRepairs = model.ShopRepairs
+ };
+ }
+ public void Update(ShopBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ShopName = model.ShopName;
+ Address = model.Address;
+ OpeningDate = model.OpeningDate;
+ ShopRepairs = model.ShopRepairs;
+ }
+ public ShopViewModel GetViewModel => new ShopViewModel()
+ {
+ Id = Id,
+ ShopName = ShopName,
+ Address = Address,
+ OpeningDate = OpeningDate,
+ ShopRepairs = ShopRepairs
+ };
+ }
+}