From 81017da41043b03ed27a42ed7fb374bc68d982e4 Mon Sep 17 00:00:00 2001 From: AnnZhimol Date: Sat, 11 Feb 2023 12:44:10 +0400 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B2=D0=B5=D1=80=D1=88=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SoftwareInstallation/FormMain.Designer.cs | 29 +++- .../SoftwareInstallation/FormMain.cs | 20 +++ .../FormStore.Designer.cs | 20 +-- .../SoftwareInstallation/FormStore.cs | 4 +- .../FormStoreReplenishment.Designer.cs | 142 ++++++++++++++++++ .../FormStoreReplenishment.cs | 104 +++++++++++++ .../FormStoreReplenishment.resx | 60 ++++++++ .../SoftwareInstallation/Program.cs | 5 + 8 files changed, 369 insertions(+), 15 deletions(-) create mode 100644 SoftwareInstallation/SoftwareInstallation/FormStoreReplenishment.Designer.cs create mode 100644 SoftwareInstallation/SoftwareInstallation/FormStoreReplenishment.cs create mode 100644 SoftwareInstallation/SoftwareInstallation/FormStoreReplenishment.resx diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs index 49adff0..d335d1b 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMain.Designer.cs @@ -32,12 +32,14 @@ this.СправочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.StoreToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.DataGridView = new System.Windows.Forms.DataGridView(); this.CreateOrderButton = new System.Windows.Forms.Button(); this.TakeOrderInWorkButton = new System.Windows.Forms.Button(); this.OrderReadyButton = new System.Windows.Forms.Button(); this.IssuedOrderButton = new System.Windows.Forms.Button(); this.UpdateListButton = new System.Windows.Forms.Button(); + this.StoreReplenishment = new System.Windows.Forms.Button(); this.MenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); @@ -56,7 +58,8 @@ // this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ИзделияToolStripMenuItem, - this.КомпонентыToolStripMenuItem}); + this.КомпонентыToolStripMenuItem, + this.StoreToolStripMenuItem}); this.СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem"; this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20); this.СправочникиToolStripMenuItem.Text = "Cправочники"; @@ -64,17 +67,24 @@ // ИзделияToolStripMenuItem // this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem"; - this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.ИзделияToolStripMenuItem.Text = "Изделия"; this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click); // // КомпонентыToolStripMenuItem // this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem"; - this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(145, 22); + this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22); this.КомпонентыToolStripMenuItem.Text = "Компоненты"; this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click); // + // StoreToolStripMenuItem + // + this.StoreToolStripMenuItem.Name = "StoreToolStripMenuItem"; + this.StoreToolStripMenuItem.Size = new System.Drawing.Size(180, 22); + this.StoreToolStripMenuItem.Text = "Магазины"; + this.StoreToolStripMenuItem.Click += new System.EventHandler(this.StoreToolStripMenuItem_Click); + // // DataGridView // this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -134,11 +144,22 @@ this.UpdateListButton.UseVisualStyleBackColor = true; this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click); // + // StoreReplenishment + // + this.StoreReplenishment.Location = new System.Drawing.Point(728, 317); + this.StoreReplenishment.Name = "StoreReplenishment"; + this.StoreReplenishment.Size = new System.Drawing.Size(125, 50); + this.StoreReplenishment.TabIndex = 7; + this.StoreReplenishment.Text = "Пополнение магазина"; + this.StoreReplenishment.UseVisualStyleBackColor = true; + this.StoreReplenishment.Click += new System.EventHandler(this.StoreReplenishment_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(865, 450); + this.Controls.Add(this.StoreReplenishment); this.Controls.Add(this.UpdateListButton); this.Controls.Add(this.IssuedOrderButton); this.Controls.Add(this.OrderReadyButton); @@ -169,5 +190,7 @@ private Button OrderReadyButton; private Button IssuedOrderButton; private Button UpdateListButton; + private ToolStripMenuItem StoreToolStripMenuItem; + private Button StoreReplenishment; } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormMain.cs b/SoftwareInstallation/SoftwareInstallation/FormMain.cs index 8942888..6b38b15 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormMain.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormMain.cs @@ -187,5 +187,25 @@ namespace SoftwareInstallationView { LoadData(); } + + private void StoreReplenishment_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment)); + + if (service is FormStoreReplenishment form) + { + form.ShowDialog(); + } + } + + private void StoreToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormStores)); + + if (service is FormStores form) + { + form.ShowDialog(); + } + } } } diff --git a/SoftwareInstallation/SoftwareInstallation/FormStore.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormStore.Designer.cs index 45b191b..6b491f1 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormStore.Designer.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormStore.Designer.cs @@ -33,13 +33,13 @@ this.OpeningDateLabel = new System.Windows.Forms.Label(); this.NameComboBox = new System.Windows.Forms.ComboBox(); this.AdressTextBox = new System.Windows.Forms.TextBox(); - this.OpeningDateTextBox = new System.Windows.Forms.TextBox(); this.DataGridView = new System.Windows.Forms.DataGridView(); this.PackageName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.PackagePrice = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.PackageCount = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.SaveButton = new System.Windows.Forms.Button(); this.ButtonCancel = new System.Windows.Forms.Button(); + this.OpeningDatePicker = new System.Windows.Forms.DateTimePicker(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); this.SuspendLayout(); // @@ -86,13 +86,6 @@ this.AdressTextBox.Size = new System.Drawing.Size(174, 23); this.AdressTextBox.TabIndex = 4; // - // OpeningDateTextBox - // - this.OpeningDateTextBox.Location = new System.Drawing.Point(137, 69); - this.OpeningDateTextBox.Name = "OpeningDateTextBox"; - this.OpeningDateTextBox.Size = new System.Drawing.Size(174, 23); - this.OpeningDateTextBox.TabIndex = 5; - // // DataGridView // this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; @@ -142,15 +135,22 @@ this.ButtonCancel.UseVisualStyleBackColor = true; this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); // + // OpeningDatePicker + // + this.OpeningDatePicker.Location = new System.Drawing.Point(137, 66); + this.OpeningDatePicker.Name = "OpeningDatePicker"; + this.OpeningDatePicker.Size = new System.Drawing.Size(174, 23); + this.OpeningDatePicker.TabIndex = 9; + // // FormStore // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(800, 450); + this.Controls.Add(this.OpeningDatePicker); this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.SaveButton); this.Controls.Add(this.DataGridView); - this.Controls.Add(this.OpeningDateTextBox); this.Controls.Add(this.AdressTextBox); this.Controls.Add(this.NameComboBox); this.Controls.Add(this.OpeningDateLabel); @@ -172,12 +172,12 @@ private Label OpeningDateLabel; private ComboBox NameComboBox; private TextBox AdressTextBox; - private TextBox OpeningDateTextBox; private DataGridView DataGridView; private Button SaveButton; private Button ButtonCancel; private DataGridViewTextBoxColumn PackageName; private DataGridViewTextBoxColumn PackagePrice; private DataGridViewTextBoxColumn PackageCount; + private DateTimePicker OpeningDatePicker; } } \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormStore.cs b/SoftwareInstallation/SoftwareInstallation/FormStore.cs index 72053c8..a790535 100644 --- a/SoftwareInstallation/SoftwareInstallation/FormStore.cs +++ b/SoftwareInstallation/SoftwareInstallation/FormStore.cs @@ -62,7 +62,7 @@ namespace SoftwareInstallationView try { - DateTime.TryParse(OpeningDateTextBox.Text, out var dateTime); + DateTime.TryParse(OpeningDatePicker.Text, out var dateTime); StoreBindingModel model = new() { StoreName = NameComboBox.Text, @@ -117,7 +117,7 @@ namespace SoftwareInstallationView { NameComboBox.Text = model.StoreName; AdressTextBox.Text = model.StoreAdress; - OpeningDateTextBox.Text = Convert.ToString(model.OpeningDate); + OpeningDatePicker.Text = Convert.ToString(model.OpeningDate); DataGridView.Rows.Clear(); foreach (var el in model.Packages.Values) { diff --git a/SoftwareInstallation/SoftwareInstallation/FormStoreReplenishment.Designer.cs b/SoftwareInstallation/SoftwareInstallation/FormStoreReplenishment.Designer.cs new file mode 100644 index 0000000..118336f --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormStoreReplenishment.Designer.cs @@ -0,0 +1,142 @@ +namespace SoftwareInstallationView +{ + partial class FormStoreReplenishment + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.StoreNameLabel = new System.Windows.Forms.Label(); + this.PackageNameLabel = new System.Windows.Forms.Label(); + this.CountLabel = new System.Windows.Forms.Label(); + this.StoreNameComboBox = new System.Windows.Forms.ComboBox(); + this.PackageNameComboBox = new System.Windows.Forms.ComboBox(); + this.CountTextBox = new System.Windows.Forms.TextBox(); + this.SaveButton = new System.Windows.Forms.Button(); + this.ButtonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // StoreNameLabel + // + this.StoreNameLabel.AutoSize = true; + this.StoreNameLabel.Location = new System.Drawing.Point(12, 9); + this.StoreNameLabel.Name = "StoreNameLabel"; + this.StoreNameLabel.Size = new System.Drawing.Size(119, 15); + this.StoreNameLabel.TabIndex = 0; + this.StoreNameLabel.Text = "Название магазина: "; + // + // PackageNameLabel + // + this.PackageNameLabel.AutoSize = true; + this.PackageNameLabel.Location = new System.Drawing.Point(12, 37); + this.PackageNameLabel.Name = "PackageNameLabel"; + this.PackageNameLabel.Size = new System.Drawing.Size(112, 15); + this.PackageNameLabel.TabIndex = 1; + this.PackageNameLabel.Text = "Название изделия: "; + // + // CountLabel + // + this.CountLabel.AutoSize = true; + this.CountLabel.Location = new System.Drawing.Point(12, 66); + this.CountLabel.Name = "CountLabel"; + this.CountLabel.Size = new System.Drawing.Size(78, 15); + this.CountLabel.TabIndex = 2; + this.CountLabel.Text = "Количество: "; + // + // StoreNameComboBox + // + this.StoreNameComboBox.FormattingEnabled = true; + this.StoreNameComboBox.Location = new System.Drawing.Point(137, 6); + this.StoreNameComboBox.Name = "StoreNameComboBox"; + this.StoreNameComboBox.Size = new System.Drawing.Size(149, 23); + this.StoreNameComboBox.TabIndex = 3; + // + // PackageNameComboBox + // + this.PackageNameComboBox.FormattingEnabled = true; + this.PackageNameComboBox.Location = new System.Drawing.Point(137, 35); + this.PackageNameComboBox.Name = "PackageNameComboBox"; + this.PackageNameComboBox.Size = new System.Drawing.Size(149, 23); + this.PackageNameComboBox.TabIndex = 4; + // + // CountTextBox + // + this.CountTextBox.Location = new System.Drawing.Point(137, 64); + this.CountTextBox.Name = "CountTextBox"; + this.CountTextBox.Size = new System.Drawing.Size(149, 23); + this.CountTextBox.TabIndex = 5; + // + // SaveButton + // + this.SaveButton.Location = new System.Drawing.Point(130, 108); + this.SaveButton.Name = "SaveButton"; + this.SaveButton.Size = new System.Drawing.Size(75, 23); + this.SaveButton.TabIndex = 6; + this.SaveButton.Text = "Сохранить"; + this.SaveButton.UseVisualStyleBackColor = true; + this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click); + // + // ButtonCancel + // + this.ButtonCancel.Location = new System.Drawing.Point(211, 108); + this.ButtonCancel.Name = "ButtonCancel"; + this.ButtonCancel.Size = new System.Drawing.Size(75, 23); + this.ButtonCancel.TabIndex = 7; + this.ButtonCancel.Text = "Отмена"; + this.ButtonCancel.UseVisualStyleBackColor = true; + this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click); + // + // FormStoreReplenishment + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(300, 150); + this.Controls.Add(this.ButtonCancel); + this.Controls.Add(this.SaveButton); + this.Controls.Add(this.CountTextBox); + this.Controls.Add(this.PackageNameComboBox); + this.Controls.Add(this.StoreNameComboBox); + this.Controls.Add(this.CountLabel); + this.Controls.Add(this.PackageNameLabel); + this.Controls.Add(this.StoreNameLabel); + this.Name = "FormStoreReplenishment"; + this.Text = "Пополнение магазина"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private Label StoreNameLabel; + private Label PackageNameLabel; + private Label CountLabel; + private ComboBox StoreNameComboBox; + private ComboBox PackageNameComboBox; + private TextBox CountTextBox; + private Button SaveButton; + private Button ButtonCancel; + } +} \ No newline at end of file diff --git a/SoftwareInstallation/SoftwareInstallation/FormStoreReplenishment.cs b/SoftwareInstallation/SoftwareInstallation/FormStoreReplenishment.cs new file mode 100644 index 0000000..e7fe768 --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormStoreReplenishment.cs @@ -0,0 +1,104 @@ +using Microsoft.Extensions.Logging; +using SofrwareInstallationContracts.BusinessLogicsContracts; +using SofrwareInstallationContracts.ViewModels; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace SoftwareInstallationView +{ + public partial class FormStoreReplenishment : Form + { + private readonly ILogger _logger; + private readonly IStoreLogic _storeLogic; + private readonly IPackageLogic _packageLogic; + private readonly List? _listStores; + private readonly List? _listPackages; + public FormStoreReplenishment(ILogger logger, IStoreLogic storeLogic, IPackageLogic packageLogic) + { + InitializeComponent(); + _storeLogic = storeLogic; + _packageLogic = packageLogic; + _logger = logger; + _listStores = storeLogic.ReadList(null); + if (_listStores != null) + { + StoreNameComboBox.DisplayMember = "StoreName"; + StoreNameComboBox.ValueMember = "Id"; + StoreNameComboBox.DataSource = _listStores; + StoreNameComboBox.SelectedItem = null; + } + + _listPackages = packageLogic.ReadList(null); + if (_listPackages != null) + { + PackageNameComboBox.DisplayMember = "PackageName"; + PackageNameComboBox.ValueMember = "Id"; + PackageNameComboBox.DataSource = _listPackages; + PackageNameComboBox.SelectedItem = null; + } + } + + private void SaveButton_Click(object sender, EventArgs e) + { + if (StoreNameComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + if (PackageNameComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + + _logger.LogInformation("Добавление изделия в магазин"); + + try + { + var package = _packageLogic.ReadElement(new() + { + Id = (int)PackageNameComboBox.SelectedValue + }); + + if (package == null) + { + throw new Exception("Не найдено изделие. Дополнительная информация в логах."); + } + + var resultOperation = _storeLogic.AddPackage( + model: new() { Id = (int)StoreNameComboBox.SelectedValue }, + package: package, + quantity: Convert.ToInt32(CountTextBox.Text) + ); + + if (!resultOperation) + { + 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/SoftwareInstallation/SoftwareInstallation/FormStoreReplenishment.resx b/SoftwareInstallation/SoftwareInstallation/FormStoreReplenishment.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/SoftwareInstallation/SoftwareInstallation/FormStoreReplenishment.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/SoftwareInstallation/Program.cs b/SoftwareInstallation/SoftwareInstallation/Program.cs index da04f53..1853575 100644 --- a/SoftwareInstallation/SoftwareInstallation/Program.cs +++ b/SoftwareInstallation/SoftwareInstallation/Program.cs @@ -34,9 +34,11 @@ namespace SoftwareInstallationView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -44,6 +46,9 @@ namespace SoftwareInstallationView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } }