diff --git a/LawFirm/LawFirm/FormMain.Designer.cs b/LawFirm/LawFirm/FormMain.Designer.cs index f3d664b..9f9a50c 100644 --- a/LawFirm/LawFirm/FormMain.Designer.cs +++ b/LawFirm/LawFirm/FormMain.Designer.cs @@ -40,6 +40,7 @@ this.buttonSetToFinish = new System.Windows.Forms.Button(); this.buttonUpdate = new System.Windows.Forms.Button(); this.buttonSupplyShop = new System.Windows.Forms.Button(); + this.buttonSellDocuments = new System.Windows.Forms.Button(); this.menuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -68,21 +69,21 @@ // бланкиToolStripMenuItem // this.бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem"; - this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(170, 26); this.бланкиToolStripMenuItem.Text = "Бланки"; this.бланкиToolStripMenuItem.Click += new System.EventHandler(this.бланкиToolStripMenuItem_Click); // // документыToolStripMenuItem // this.документыToolStripMenuItem.Name = "документыToolStripMenuItem"; - this.документыToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.документыToolStripMenuItem.Size = new System.Drawing.Size(170, 26); this.документыToolStripMenuItem.Text = "Документы"; this.документыToolStripMenuItem.Click += new System.EventHandler(this.документыToolStripMenuItem_Click); // // магазиныToolStripMenuItem // this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; - this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 26); + this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(170, 26); this.магазиныToolStripMenuItem.Text = "Магазины"; this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click); // @@ -156,11 +157,22 @@ this.buttonSupplyShop.UseVisualStyleBackColor = true; this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click); // + // buttonSellDocuments + // + this.buttonSellDocuments.Location = new System.Drawing.Point(933, 220); + this.buttonSellDocuments.Name = "buttonSellDocuments"; + this.buttonSellDocuments.Size = new System.Drawing.Size(194, 29); + this.buttonSellDocuments.TabIndex = 8; + this.buttonSellDocuments.Text = "Продажа документов"; + this.buttonSellDocuments.UseVisualStyleBackColor = true; + this.buttonSellDocuments.Click += new System.EventHandler(this.buttonSellDocuments_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1139, 450); + this.Controls.Add(this.buttonSellDocuments); this.Controls.Add(this.buttonSupplyShop); this.Controls.Add(this.buttonUpdate); this.Controls.Add(this.buttonSetToFinish); @@ -195,5 +207,6 @@ private Button buttonUpdate; private ToolStripMenuItem магазиныToolStripMenuItem; private Button buttonSupplyShop; + private Button buttonSellDocuments; } } \ No newline at end of file diff --git a/LawFirm/LawFirm/FormMain.cs b/LawFirm/LawFirm/FormMain.cs index 46d6790..db140dc 100644 --- a/LawFirm/LawFirm/FormMain.cs +++ b/LawFirm/LawFirm/FormMain.cs @@ -181,5 +181,14 @@ namespace LawFirmView form.ShowDialog(); } } + + private void buttonSellDocuments_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShopSell)); + if (service is FormShopSell form) + { + form.ShowDialog(); + } + } } } diff --git a/LawFirm/LawFirm/FormShopSell.Designer.cs b/LawFirm/LawFirm/FormShopSell.Designer.cs new file mode 100644 index 0000000..074f8c2 --- /dev/null +++ b/LawFirm/LawFirm/FormShopSell.Designer.cs @@ -0,0 +1,119 @@ +namespace LawFirmView +{ + partial class FormShopSell + { + /// + /// 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.labelCount = new System.Windows.Forms.Label(); + this.labelDocument = new System.Windows.Forms.Label(); + this.comboBoxDocument = new System.Windows.Forms.ComboBox(); + this.textBoxCount = new System.Windows.Forms.TextBox(); + this.buttonSell = new System.Windows.Forms.Button(); + this.buttonCancel = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // labelCount + // + this.labelCount.AutoSize = true; + this.labelCount.Location = new System.Drawing.Point(23, 76); + this.labelCount.Name = "labelCount"; + this.labelCount.Size = new System.Drawing.Size(93, 20); + this.labelCount.TabIndex = 1; + this.labelCount.Text = "Количество:"; + // + // labelDocument + // + this.labelDocument.AutoSize = true; + this.labelDocument.Location = new System.Drawing.Point(23, 24); + this.labelDocument.Name = "labelDocument"; + this.labelDocument.Size = new System.Drawing.Size(79, 20); + this.labelDocument.TabIndex = 2; + this.labelDocument.Text = "Документ:"; + // + // comboBoxDocument + // + this.comboBoxDocument.FormattingEnabled = true; + this.comboBoxDocument.Location = new System.Drawing.Point(124, 24); + this.comboBoxDocument.Name = "comboBoxDocument"; + this.comboBoxDocument.Size = new System.Drawing.Size(278, 28); + this.comboBoxDocument.TabIndex = 4; + // + // textBoxCount + // + this.textBoxCount.Location = new System.Drawing.Point(124, 73); + this.textBoxCount.Name = "textBoxCount"; + this.textBoxCount.Size = new System.Drawing.Size(158, 27); + this.textBoxCount.TabIndex = 5; + // + // buttonSell + // + this.buttonSell.Location = new System.Drawing.Point(188, 142); + this.buttonSell.Name = "buttonSell"; + this.buttonSell.Size = new System.Drawing.Size(94, 29); + this.buttonSell.TabIndex = 6; + this.buttonSell.Text = "Продажа"; + this.buttonSell.UseVisualStyleBackColor = true; + this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click); + // + // buttonCancel + // + this.buttonCancel.Location = new System.Drawing.Point(308, 142); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(94, 29); + this.buttonCancel.TabIndex = 7; + this.buttonCancel.Text = "Отмена"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click); + // + // FormShopSell + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(459, 198); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonSell); + this.Controls.Add(this.textBoxCount); + this.Controls.Add(this.comboBoxDocument); + this.Controls.Add(this.labelDocument); + this.Controls.Add(this.labelCount); + this.Name = "FormShopSell"; + this.Text = "Продажа из магазина"; + this.Load += new System.EventHandler(this.FormShopSell_Load); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + private Label labelCount; + private Label labelDocument; + private ComboBox comboBoxDocument; + private TextBox textBoxCount; + private Button buttonSell; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/LawFirm/LawFirm/FormShopSell.cs b/LawFirm/LawFirm/FormShopSell.cs new file mode 100644 index 0000000..5255aa2 --- /dev/null +++ b/LawFirm/LawFirm/FormShopSell.cs @@ -0,0 +1,97 @@ +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.SearchModels; +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 LawFirmView +{ + public partial class FormShopSell : Form + { + private readonly ILogger _logger; + private readonly IDocumentLogic _logicD; + private readonly IShopLogic _logicS; + + public FormShopSell(ILogger logger, IDocumentLogic logicD, IShopLogic logicS) + { + InitializeComponent(); + _logger = logger; + _logicD = logicD; + _logicS = logicS; + } + + private void FormShopSell_Load(object sender, EventArgs e) + { + _logger.LogInformation("Загрузка документов для продажи"); + try + { + var list = _logicD.ReadList(null); + if (list != null) + { + comboBoxDocument.DisplayMember = "DocumentName"; + comboBoxDocument.ValueMember = "Id"; + comboBoxDocument.DataSource = list; + comboBoxDocument.SelectedItem = null; + } + + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка документов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonSell_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxCount.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (comboBoxDocument.SelectedValue == null) + { + MessageBox.Show("Выберите документ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Создание продажи"); + try + { + var operationResult = _logicS.SellDocument( + new DocumentSearchModel + { + Id = Convert.ToInt32(comboBoxDocument.SelectedValue), + DocumentName = comboBoxDocument.Text + }, + 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, "Ошибка создания продажи"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/LawFirm/LawFirm/FormShopSell.resx b/LawFirm/LawFirm/FormShopSell.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/LawFirm/LawFirm/FormShopSell.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/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs index 60500aa..5acabed 100644 --- a/LawFirm/LawFirm/Program.cs +++ b/LawFirm/LawFirm/Program.cs @@ -56,6 +56,7 @@ namespace LawFirm services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs index 4affe1c..b3250a1 100644 --- a/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs +++ b/LawFirm/LawFirmBusinessLogic/BusinessLogics/ShopLogic.cs @@ -117,6 +117,11 @@ namespace LawFirmBusinessLogic.BusinessLogics return true; } + public bool SellDocument(DocumentSearchModel document, int count) + {; + return _shopStorage.SellDocument(document, count); + } + public bool Create(ShopBindingModel model) { CheckModel(model); diff --git a/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs index 0b47a27..ab76086 100644 --- a/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs +++ b/LawFirm/LawFirmContracts/BusinessLogicContracts/IShopLogic.cs @@ -18,5 +18,7 @@ namespace LawFirmContracts.BusinessLogicContracts bool Update(ShopBindingModel model); bool Delete(ShopBindingModel model); bool SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count); + + bool SellDocument(DocumentSearchModel document, int count); } } diff --git a/LawFirm/LawFirmContracts/StorageContracts/IShopStorage.cs b/LawFirm/LawFirmContracts/StorageContracts/IShopStorage.cs index f84055a..b51b90c 100644 --- a/LawFirm/LawFirmContracts/StorageContracts/IShopStorage.cs +++ b/LawFirm/LawFirmContracts/StorageContracts/IShopStorage.cs @@ -17,5 +17,6 @@ namespace LawFirmContracts.StorageContracts ShopViewModel? Insert(ShopBindingModel model); ShopViewModel? Update(ShopBindingModel model); ShopViewModel? Delete(ShopBindingModel model); + bool SellDocument(DocumentSearchModel model, int count); } } diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs index 7a48f54..bfa4a5d 100644 --- a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs @@ -118,11 +118,11 @@ namespace LawFirmFileImplement.Implements var shop = source.Shops[i]; var documents = shop.ShopDocuments; - for (int j = 0; j < documents.Count; j++) + for (int j =1; j < documents.Count + 1; j++) { if (documents[j].Item1.Id == document.Id) { - while (documents[j].Item2 > 0 || count > 0) + while (documents[j].Item2 > 0 && count > 0) { int tempItem2 = documents[j].Item2; tempItem2--; @@ -140,12 +140,12 @@ namespace LawFirmFileImplement.Implements Adress = shop.Adress, OpeningDate = shop.OpeningDate, MaxCountDocuments = shop.MaxCountDocuments, - ShopDocuments= documents + ShopDocuments = documents }); return true; } } - + shop.Update(new ShopBindingModel { Id = shop.Id, diff --git a/LawFirm/LawFirmListImplements/Implements/ShopStorage.cs b/LawFirm/LawFirmListImplements/Implements/ShopStorage.cs index 11f9ac9..15f5c4e 100644 --- a/LawFirm/LawFirmListImplements/Implements/ShopStorage.cs +++ b/LawFirm/LawFirmListImplements/Implements/ShopStorage.cs @@ -116,5 +116,9 @@ namespace LawFirmListImplements.Implements return null; } + public bool SellDocument(DocumentSearchModel model, int count) + { + throw new NotImplementedException(); + } } }