diff --git a/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs
index d04428c..94ec043 100644
--- a/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs
+++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.Designer.cs
@@ -38,6 +38,8 @@
buttonIssuedOrder = new Button();
buttonOrderReady = new Button();
buttonRefresh = new Button();
+ магазиныToolStripMenuItem = new ToolStripMenuItem();
+ buttonAddPackageInShop = new Button();
menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
SuspendLayout();
@@ -53,7 +55,7 @@
//
// справочникиToolStripMenuItem
//
- справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem });
+ справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, магазиныToolStripMenuItem });
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
справочникиToolStripMenuItem.Size = new Size(94, 20);
справочникиToolStripMenuItem.Text = "Справочники";
@@ -61,14 +63,14 @@
// компонентыToolStripMenuItem
//
компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
- компонентыToolStripMenuItem.Size = new Size(145, 22);
+ компонентыToolStripMenuItem.Size = new Size(180, 22);
компонентыToolStripMenuItem.Text = "Компоненты";
компонентыToolStripMenuItem.Click += компонентыToolStripMenuItem_Click;
//
// изделияToolStripMenuItem
//
изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
- изделияToolStripMenuItem.Size = new Size(145, 22);
+ изделияToolStripMenuItem.Size = new Size(180, 22);
изделияToolStripMenuItem.Text = "Изделия";
изделияToolStripMenuItem.Click += изделияToolStripMenuItem_Click;
//
@@ -130,11 +132,28 @@
buttonRefresh.UseVisualStyleBackColor = true;
buttonRefresh.Click += buttonRefresh_Click;
//
+ // магазиныToolStripMenuItem
+ //
+ магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
+ магазиныToolStripMenuItem.Size = new Size(180, 22);
+ магазиныToolStripMenuItem.Text = "Магазины";
+ //
+ // buttonAddPackageInShop
+ //
+ buttonAddPackageInShop.Location = new Point(785, 335);
+ buttonAddPackageInShop.Name = "buttonAddPackageInShop";
+ buttonAddPackageInShop.Size = new Size(144, 39);
+ buttonAddPackageInShop.TabIndex = 7;
+ buttonAddPackageInShop.Text = "Пополнение магазина";
+ buttonAddPackageInShop.UseVisualStyleBackColor = true;
+ buttonAddPackageInShop.Click += buttonAddPackageInShop_Click;
+ //
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(958, 439);
+ Controls.Add(buttonAddPackageInShop);
Controls.Add(buttonRefresh);
Controls.Add(buttonOrderReady);
Controls.Add(buttonIssuedOrder);
@@ -165,5 +184,7 @@
private Button buttonIssuedOrder;
private Button buttonOrderReady;
private Button buttonRefresh;
+ private ToolStripMenuItem магазиныToolStripMenuItem;
+ private Button buttonAddPackageInShop;
}
}
\ No newline at end of file
diff --git a/SoftwareInstallation/SoftwareInstallationView/FormMain.cs b/SoftwareInstallation/SoftwareInstallationView/FormMain.cs
index c0d136d..08db204 100644
--- a/SoftwareInstallation/SoftwareInstallationView/FormMain.cs
+++ b/SoftwareInstallation/SoftwareInstallationView/FormMain.cs
@@ -160,5 +160,14 @@ namespace SoftwareInstallationView
{
LoadData();
}
+
+ private void buttonAddPackageInShop_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormAddPackageInShop));
+ if (service is FormAddPackageInShop form)
+ {
+ form.ShowDialog();
+ }
+ }
}
}
diff --git a/SoftwareInstallation/SoftwareInstallationView/FormShop.Designer.cs b/SoftwareInstallation/SoftwareInstallationView/FormShop.Designer.cs
new file mode 100644
index 0000000..95b0b63
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationView/FormShop.Designer.cs
@@ -0,0 +1,153 @@
+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()
+ {
+ labelNameShop = new Label();
+ labelAddress = new Label();
+ labelDate = new Label();
+ textBoxShop = new TextBox();
+ textBoxAddress = new TextBox();
+ dateTimePicker1 = new DateTimePicker();
+ dataGridView = new DataGridView();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
+ SuspendLayout();
+ //
+ // labelNameShop
+ //
+ labelNameShop.AutoSize = true;
+ labelNameShop.Location = new Point(12, 9);
+ labelNameShop.Name = "labelNameShop";
+ labelNameShop.Size = new Size(113, 15);
+ labelNameShop.TabIndex = 0;
+ labelNameShop.Text = "Название магазина";
+ //
+ // labelAddress
+ //
+ labelAddress.AutoSize = true;
+ labelAddress.Location = new Point(12, 64);
+ labelAddress.Name = "labelAddress";
+ labelAddress.Size = new Size(94, 15);
+ labelAddress.TabIndex = 1;
+ labelAddress.Text = "Адрес магазина";
+ //
+ // labelDate
+ //
+ labelDate.AutoSize = true;
+ labelDate.Location = new Point(334, 9);
+ labelDate.Name = "labelDate";
+ labelDate.Size = new Size(87, 15);
+ labelDate.TabIndex = 2;
+ labelDate.Text = "Дата открытия";
+ //
+ // textBoxShop
+ //
+ textBoxShop.Location = new Point(12, 27);
+ textBoxShop.Name = "textBoxShop";
+ textBoxShop.Size = new Size(248, 23);
+ textBoxShop.TabIndex = 3;
+ //
+ // textBoxAddress
+ //
+ textBoxAddress.Location = new Point(12, 82);
+ textBoxAddress.Name = "textBoxAddress";
+ textBoxAddress.Size = new Size(248, 23);
+ textBoxAddress.TabIndex = 4;
+ //
+ // dateTimePicker1
+ //
+ dateTimePicker1.Location = new Point(334, 36);
+ dateTimePicker1.Name = "dateTimePicker1";
+ dateTimePicker1.Size = new Size(175, 23);
+ dateTimePicker1.TabIndex = 5;
+ //
+ // dataGridView
+ //
+ dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridView.Location = new Point(12, 128);
+ dataGridView.Name = "dataGridView";
+ dataGridView.Size = new Size(601, 242);
+ dataGridView.TabIndex = 6;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(384, 376);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(107, 31);
+ buttonSave.TabIndex = 7;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += buttonSave_Click;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(497, 376);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(107, 31);
+ buttonCancel.TabIndex = 8;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += buttonCancel_Click;
+ //
+ // FormShop
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(629, 417);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(dataGridView);
+ Controls.Add(dateTimePicker1);
+ Controls.Add(textBoxAddress);
+ Controls.Add(textBoxShop);
+ Controls.Add(labelDate);
+ Controls.Add(labelAddress);
+ Controls.Add(labelNameShop);
+ Name = "FormShop";
+ Text = "FormShop";
+ Load += FormShop_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label labelNameShop;
+ private Label labelAddress;
+ private Label labelDate;
+ private TextBox textBoxShop;
+ private TextBox textBoxAddress;
+ private DateTimePicker dateTimePicker1;
+ private DataGridView dataGridView;
+ private Button buttonSave;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/SoftwareInstallation/SoftwareInstallationView/FormShop.cs b/SoftwareInstallation/SoftwareInstallationView/FormShop.cs
new file mode 100644
index 0000000..ab947bb
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationView/FormShop.cs
@@ -0,0 +1,140 @@
+using SoftwareInstallationContracts.BusinessLogicsContracts;
+using SoftwareInstallationContracts.ViewModels;
+using SoftwareInstallationDataModels;
+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;
+
+namespace SoftwareInstallationView
+{
+ public partial class FormShop : Form
+ {
+ private readonly List? _listShops;
+ private readonly IShopLogic _logic;
+ private readonly ILogger _logger;
+
+ public int Id
+ {
+ get; set;
+ }
+
+ private IShopModel? GetShop(int id)
+ {
+ if (_listShops == null)
+ {
+ return null;
+ }
+ foreach (var elem in _listShops)
+ {
+ if (elem.Id == id)
+ {
+ return elem;
+ }
+ }
+ return null;
+ }
+ public FormShop(ILogger logger, IShopLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _listShops = logic.ReadList(null);
+ _logic = logic;
+
+ }
+ private void LoadData(bool extendDate = true)
+ {
+ try
+ {
+ var model = GetShop(extendDate ? Id : Convert.ToInt32(null));
+ if (model != null)
+ {
+ textBoxShop.Text = model.Name;
+ textBoxAddress.Text = model.Address;
+ textBoxDateOpening.Text = Convert.ToString(model.DateOpening);
+ dataGridView.Rows.Clear();
+ foreach (var el in model.Packages.Values)
+ {
+ dataGridView.Rows.Add(new object[] { el.Item1.PackageName, el.Item1.Price, el.Item2 });
+ }
+ }
+ _logger.LogInformation("Загрузка магазинов");
+ }
+ 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(textBoxShop.Text))
+ {
+ MessageBox.Show("Заполните название", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (string.IsNullOrEmpty(textBoxAddress.Text))
+ {
+ MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение изделия");
+ try
+ {
+ DateTime.TryParse(textBoxDateOpening.Text, out var dateTime);
+ ShopBindingModel model = new()
+ {
+ Name = textBoxShop.Text,
+ Address = textBoxAddress.Text,
+ DateOpening = dateTime
+ };
+ var vmodel = GetShop(Id);
+ bool operationResult = false;
+
+ if (vmodel != null)
+ {
+ model.Id = vmodel.Id;
+ operationResult = _logic.Update(model);
+ }
+ else
+ {
+ operationResult = _logic.Create(model);
+ }
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение",
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void buttonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ private void FormShop_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+ }
+}
diff --git a/SoftwareInstallation/SoftwareInstallationView/FormShop.resx b/SoftwareInstallation/SoftwareInstallationView/FormShop.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/SoftwareInstallation/SoftwareInstallationView/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