Вроде все работает, но было бы неплохо порефакторить

This commit is contained in:
Данила Мочалов 2023-03-01 19:04:30 +04:00
parent 94dde9c5d9
commit 6a68de1873
11 changed files with 318 additions and 7 deletions

View File

@ -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;
}
}

View File

@ -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();
}
}
}
}

119
LawFirm/LawFirm/FormShopSell.Designer.cs generated Normal file
View File

@ -0,0 +1,119 @@
namespace LawFirmView
{
partial class FormShopSell
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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;
}
}

View File

@ -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<FormShopSell> 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();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -56,6 +56,7 @@ namespace LawFirm
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormShopSupply>();
services.AddTransient<FormShopSell>();
}
}

View File

@ -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);

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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,

View File

@ -116,5 +116,9 @@ namespace LawFirmListImplements.Implements
return null;
}
public bool SellDocument(DocumentSearchModel model, int count)
{
throw new NotImplementedException();
}
}
}