ISEbd-21 Melnikov I. O. Lab Work 02 Advanced #16

Closed
Igor-Melnikov wants to merge 5 commits from lab2adv into lab1adv
22 changed files with 1536 additions and 136 deletions
Showing only changes of commit b936d03f3a - Show all commits

View File

@ -0,0 +1,145 @@
namespace BlacksmithWorkshopView
{
partial class FormFillStore
{
/// <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.buttonCancel = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
this.labelCount = new System.Windows.Forms.Label();
this.labelManufacture = new System.Windows.Forms.Label();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.comboBoxManufacture = new System.Windows.Forms.ComboBox();
this.comboBoxStore = new System.Windows.Forms.ComboBox();
this.labelStore = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(258, 100);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 9;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(177, 100);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
this.buttonSave.TabIndex = 10;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(14, 44);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(72, 15);
this.labelCount.TabIndex = 7;
this.labelCount.Text = "Количество";
//
// labelManufacture
//
this.labelManufacture.AutoSize = true;
this.labelManufacture.Location = new System.Drawing.Point(14, 15);
this.labelManufacture.Name = "labelManufacture";
this.labelManufacture.Size = new System.Drawing.Size(53, 15);
this.labelManufacture.TabIndex = 8;
this.labelManufacture.Text = "Изделие";
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(109, 41);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(224, 23);
this.textBoxCount.TabIndex = 6;
//
// comboBoxManufacture
//
this.comboBoxManufacture.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxManufacture.FormattingEnabled = true;
this.comboBoxManufacture.Location = new System.Drawing.Point(109, 12);
this.comboBoxManufacture.Name = "comboBoxManufacture";
this.comboBoxManufacture.Size = new System.Drawing.Size(224, 23);
this.comboBoxManufacture.TabIndex = 5;
//
// comboBoxStore
//
this.comboBoxStore.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxStore.FormattingEnabled = true;
this.comboBoxStore.Location = new System.Drawing.Point(109, 71);
this.comboBoxStore.Name = "comboBoxStore";
this.comboBoxStore.Size = new System.Drawing.Size(224, 23);
this.comboBoxStore.TabIndex = 5;
//
// labelStore
//
this.labelStore.AutoSize = true;
this.labelStore.Location = new System.Drawing.Point(14, 74);
this.labelStore.Name = "labelStore";
this.labelStore.Size = new System.Drawing.Size(54, 15);
this.labelStore.TabIndex = 8;
this.labelStore.Text = "Магазин";
//
// FormFillStore
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(348, 130);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.labelStore);
this.Controls.Add(this.labelManufacture);
this.Controls.Add(this.comboBoxStore);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.comboBoxManufacture);
this.Name = "FormFillStore";
this.Text = "Пополнение магазина";
this.Load += new System.EventHandler(this.FormFillStore_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonSave;
private Label labelCount;
private Label labelManufacture;
private TextBox textBoxCount;
private ComboBox comboBoxManufacture;
private ComboBox comboBoxStore;
private Label labelStore;
}
}

View File

@ -0,0 +1,88 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicContracts;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.SearchModels;
using Microsoft.Extensions.Logging;
namespace BlacksmithWorkshopView
{
public partial class FormFillStore : Form
{
private readonly ILogger _logger;
private readonly IStoreLogic _logicS;
private readonly IManufactureLogic _logicM;
public FormFillStore(ILogger<FormCreateOrder> logger, IStoreLogic logicS, IManufactureLogic logicM)
{
InitializeComponent();
_logger = logger;
_logicS = logicS;
_logicM = logicM;
}
private void FormFillStore_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка магазинов и изделий");
var listS = _logicS.ReadList(null);
if (listS != null)
{
comboBoxStore.DisplayMember = "StoreName";
comboBoxStore.ValueMember = "Id";
comboBoxStore.DataSource = listS;
comboBoxStore.SelectedItem = null;
}
var listM = _logicM.ReadList(null);
if (listM != null)
{
comboBoxManufacture.DisplayMember = "ManufactureName";
comboBoxManufacture.ValueMember = "Id";
comboBoxManufacture.DataSource = listM;
comboBoxManufacture.SelectedItem = null;
}
}
private void ButtonSave_Click(object sender, EventArgs e)
{
if (comboBoxStore.SelectedValue == null)
{
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxManufacture.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Пополнение магазина");
try
{
var addedManufacture = _logicM.ReadElement(new ManufactureSearchModel
{
Id = Convert.ToInt32(comboBoxManufacture.SelectedValue)
});
if (addedManufacture == null)
{
return;
}
var operationResult = _logicS.AddManufacture(addedManufacture, new StoreSearchModel
{
Id = Convert.ToInt32(comboBoxStore.SelectedValue)
}, 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

@ -28,139 +28,161 @@
/// </summary>
private void InitializeComponent()
{
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.refbooksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.manufacturesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
this.Load += new System.EventHandler(this.FormMain_Load);
//
// menuStrip
//
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.refbooksToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.componentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.manufacturesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.storesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
this.buttonFillStore = new System.Windows.Forms.Button();
this.menuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// menuStrip
//
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.refbooksToolStripMenuItem});
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(1108, 24);
this.menuStrip.TabIndex = 0;
this.menuStrip.Text = "menuStrip1";
//
// refbooksToolStripMenuItem
//
this.refbooksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Size = new System.Drawing.Size(1108, 24);
this.menuStrip.TabIndex = 0;
this.menuStrip.Text = "menuStrip1";
//
// refbooksToolStripMenuItem
//
this.refbooksToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.componentsToolStripMenuItem,
this.manufacturesToolStripMenuItem});
this.refbooksToolStripMenuItem.Name = "refbooksToolStripMenuItem";
this.refbooksToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.refbooksToolStripMenuItem.Text = "Справочники";
//
// componentsToolStripMenuItem
//
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.componentsToolStripMenuItem.Text = "Компоненты";
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
// manufacturesToolStripMenuItem
//
this.manufacturesToolStripMenuItem.Name = "manufacturesToolStripMenuItem";
this.manufacturesToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.manufacturesToolStripMenuItem.Text = "Изделия";
this.manufacturesToolStripMenuItem.Click += new System.EventHandler(this.ManufacturesToolStripMenuItem_Click);
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 27);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(795, 456);
this.dataGridView.TabIndex = 1;
//
// buttonCreateOrder
//
this.buttonCreateOrder.Location = new System.Drawing.Point(813, 27);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonCreateOrder.Size = new System.Drawing.Size(283, 23);
this.buttonCreateOrder.TabIndex = 2;
this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreateOrder.UseVisualStyleBackColor = true;
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
//
// buttonTakeOrderInWork
//
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(813, 56);
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonTakeOrderInWork.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(283, 23);
this.buttonTakeOrderInWork.TabIndex = 2;
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
//
// buttonOrderReady
//
this.buttonOrderReady.Location = new System.Drawing.Point(813, 85);
this.buttonOrderReady.Name = "buttonOrderReady";
this.buttonOrderReady.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonOrderReady.Size = new System.Drawing.Size(283, 23);
this.buttonOrderReady.TabIndex = 2;
this.buttonOrderReady.Text = "Заказ готов";
this.buttonOrderReady.UseVisualStyleBackColor = true;
this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
//
// buttonIssuedOrder
//
this.buttonIssuedOrder.Location = new System.Drawing.Point(814, 114);
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
this.buttonIssuedOrder.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonIssuedOrder.Size = new System.Drawing.Size(283, 23);
this.buttonIssuedOrder.TabIndex = 2;
this.buttonIssuedOrder.Text = "Заказ выдан";
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(813, 143);
this.buttonRef.Name = "buttonRef";
this.buttonRef.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonRef.Size = new System.Drawing.Size(283, 23);
this.buttonRef.TabIndex = 2;
this.buttonRef.Text = "Обновить список";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1108, 504);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonIssuedOrder);
this.Controls.Add(this.buttonOrderReady);
this.Controls.Add(this.buttonTakeOrderInWork);
this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip;
this.Name = "FormMain";
this.Text = "Кузнечная мастерская";
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
this.manufacturesToolStripMenuItem,
this.storesToolStripMenuItem});
this.refbooksToolStripMenuItem.Name = "refbooksToolStripMenuItem";
this.refbooksToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.refbooksToolStripMenuItem.Text = "Справочники";
//
// componentsToolStripMenuItem
//
this.componentsToolStripMenuItem.Name = "componentsToolStripMenuItem";
this.componentsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.componentsToolStripMenuItem.Text = "Компоненты";
this.componentsToolStripMenuItem.Click += new System.EventHandler(this.ComponentsToolStripMenuItem_Click);
//
// manufacturesToolStripMenuItem
//
this.manufacturesToolStripMenuItem.Name = "manufacturesToolStripMenuItem";
this.manufacturesToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.manufacturesToolStripMenuItem.Text = "Изделия";
this.manufacturesToolStripMenuItem.Click += new System.EventHandler(this.ManufacturesToolStripMenuItem_Click);
//
// storesToolStripMenuItem
//
this.storesToolStripMenuItem.Name = "storesToolStripMenuItem";
this.storesToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.storesToolStripMenuItem.Text = "Магазины";
this.storesToolStripMenuItem.Click += new System.EventHandler(this.StoresToolStripMenuItem_Click);
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(12, 27);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(795, 456);
this.dataGridView.TabIndex = 1;
//
// buttonCreateOrder
//
this.buttonCreateOrder.Location = new System.Drawing.Point(813, 27);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonCreateOrder.Size = new System.Drawing.Size(283, 23);
this.buttonCreateOrder.TabIndex = 2;
this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreateOrder.UseVisualStyleBackColor = true;
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
//
// buttonTakeOrderInWork
//
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(813, 56);
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonTakeOrderInWork.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(283, 23);
this.buttonTakeOrderInWork.TabIndex = 2;
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
//
// buttonOrderReady
//
this.buttonOrderReady.Location = new System.Drawing.Point(813, 85);
this.buttonOrderReady.Name = "buttonOrderReady";
this.buttonOrderReady.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonOrderReady.Size = new System.Drawing.Size(283, 23);
this.buttonOrderReady.TabIndex = 2;
this.buttonOrderReady.Text = "Заказ готов";
this.buttonOrderReady.UseVisualStyleBackColor = true;
this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
//
// buttonIssuedOrder
//
this.buttonIssuedOrder.Location = new System.Drawing.Point(814, 114);
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
this.buttonIssuedOrder.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonIssuedOrder.Size = new System.Drawing.Size(283, 23);
this.buttonIssuedOrder.TabIndex = 2;
this.buttonIssuedOrder.Text = "Заказ выдан";
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(813, 143);
this.buttonRef.Name = "buttonRef";
this.buttonRef.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonRef.Size = new System.Drawing.Size(283, 23);
this.buttonRef.TabIndex = 2;
this.buttonRef.Text = "Обновить список";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// buttonFillStore
//
this.buttonFillStore.Location = new System.Drawing.Point(813, 172);
this.buttonFillStore.Name = "buttonFillStore";
this.buttonFillStore.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.buttonFillStore.Size = new System.Drawing.Size(283, 23);
this.buttonFillStore.TabIndex = 2;
this.buttonFillStore.Text = "Пополнить магазин";
this.buttonFillStore.UseVisualStyleBackColor = true;
this.buttonFillStore.Click += new System.EventHandler(this.ButtonFillStore_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1108, 504);
this.Controls.Add(this.buttonFillStore);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonIssuedOrder);
this.Controls.Add(this.buttonOrderReady);
this.Controls.Add(this.buttonTakeOrderInWork);
this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip;
this.Name = "FormMain";
this.Text = "Кузнечная мастерская";
this.Load += new System.EventHandler(this.FormMain_Load);
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
@ -176,5 +198,7 @@
private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonRef;
}
private ToolStripMenuItem storesToolStripMenuItem;
private Button buttonFillStore;
}
}

View File

@ -146,5 +146,21 @@ namespace BlacksmithWorkshopView
{
LoadData();
}
}
private void StoresToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormStores));
if (service is FormStores form)
{
form.ShowDialog();
}
}
private void ButtonFillStore_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormFillStore));
if (service is FormFillStore form)
{
form.ShowDialog();
}
}
}
}

View File

@ -0,0 +1,184 @@
namespace BlacksmithWorkshopView
{
partial class FormStore
{
/// <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.buttonCancel = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
this.labelAddress = new System.Windows.Forms.Label();
this.labelName = new System.Windows.Forms.Label();
this.textBoxAddress = new System.Windows.Forms.TextBox();
this.textBoxName = new System.Windows.Forms.TextBox();
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
this.labelOpeningDate = new System.Windows.Forms.Label();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.ColumnManufactureName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnPrice = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// buttonCancel
//
this.buttonCancel.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.buttonCancel.Location = new System.Drawing.Point(316, 41);
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);
//
// buttonSave
//
this.buttonSave.Anchor = System.Windows.Forms.AnchorStyles.Top;
this.buttonSave.Location = new System.Drawing.Point(316, 12);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(75, 23);
this.buttonSave.TabIndex = 8;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// labelAddress
//
this.labelAddress.AutoSize = true;
this.labelAddress.Location = new System.Drawing.Point(17, 44);
this.labelAddress.Name = "labelAddress";
this.labelAddress.Size = new System.Drawing.Size(40, 15);
this.labelAddress.TabIndex = 5;
this.labelAddress.Text = "Адрес";
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(17, 15);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(59, 15);
this.labelName.TabIndex = 6;
this.labelName.Text = "Название";
//
// textBoxAddress
//
this.textBoxAddress.Location = new System.Drawing.Point(82, 41);
this.textBoxAddress.Name = "textBoxAddress";
this.textBoxAddress.Size = new System.Drawing.Size(228, 23);
this.textBoxAddress.TabIndex = 3;
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(82, 12);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(228, 23);
this.textBoxName.TabIndex = 4;
//
// dateTimePicker
//
this.dateTimePicker.Location = new System.Drawing.Point(110, 76);
this.dateTimePicker.Name = "dateTimePicker";
this.dateTimePicker.Size = new System.Drawing.Size(200, 23);
this.dateTimePicker.TabIndex = 9;
//
// labelOpeningDate
//
this.labelOpeningDate.AutoSize = true;
this.labelOpeningDate.Location = new System.Drawing.Point(17, 76);
this.labelOpeningDate.Name = "labelOpeningDate";
this.labelOpeningDate.Size = new System.Drawing.Size(87, 15);
this.labelOpeningDate.TabIndex = 5;
this.labelOpeningDate.Text = "Дата открытия";
//
// dataGridView
//
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ColumnManufactureName,
this.ColumnPrice,
this.ColumnCount});
this.dataGridView.Location = new System.Drawing.Point(17, 118);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(608, 450);
this.dataGridView.TabIndex = 10;
//
// ColumnManufactureName
//
this.ColumnManufactureName.HeaderText = "Название";
this.ColumnManufactureName.Name = "ColumnManufactureName";
//
// ColumnPrice
//
this.ColumnPrice.HeaderText = "Цена";
this.ColumnPrice.Name = "ColumnPrice";
//
// ColumnCount
//
this.ColumnCount.HeaderText = "Количество";
this.ColumnCount.Name = "ColumnCount";
//
// FormStore
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(641, 594);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.dateTimePicker);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.labelOpeningDate);
this.Controls.Add(this.labelAddress);
this.Controls.Add(this.labelName);
this.Controls.Add(this.textBoxAddress);
this.Controls.Add(this.textBoxName);
this.Name = "FormStore";
this.Text = "Магазин";
this.Load += new System.EventHandler(this.FormStore_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonSave;
private Label labelAddress;
private Label labelName;
private TextBox textBoxAddress;
private TextBox textBoxName;
private DateTimePicker dateTimePicker;
private Label labelOpeningDate;
private DataGridView dataGridView;
private DataGridViewTextBoxColumn ColumnManufactureName;
private DataGridViewTextBoxColumn ColumnPrice;
private DataGridViewTextBoxColumn ColumnCount;
}
}

View File

@ -0,0 +1,123 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicContracts;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.SearchModels;
using Microsoft.Extensions.Logging;
using System.Reflection;
namespace BlacksmithWorkshopView
{
public partial class FormStore : Form
{
private readonly ILogger _logger;
private readonly IStoreLogic _logicS;
private readonly IComponentLogic _logicC;
private int? _id;
public int Id { set { _id = value; } }
public FormStore(ILogger<FormComponent> logger, IStoreLogic logicS, IComponentLogic logicC)
{
InitializeComponent();
_logger = logger;
_logicS = logicS;
_logicC = logicC;
}
private void FormStore_Load(object sender, EventArgs e)
{
dataGridView.Columns["ColumnManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
if (_id.HasValue)
{
try
{
_logger.LogInformation("Получение магазина");
var view = _logicS.ReadElement(new StoreSearchModel
{
Id = _id.Value
});
if (view != null)
{
textBoxName.Text = view.StoreName;
textBoxAddress.Text = view.Address;
dateTimePicker.Value = view.OpeningDate;
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
private void LoadData()
{
if (_id == null)
{
return;
}
try
{
var list = _logicS.ReadElement(new StoreSearchModel
{
Id = _id.Value
})?.Manufactures;
if (list != null)
{
dataGridView.Rows.Clear();
foreach (var el in list)
{
dataGridView.Rows.Add(new object[] { el.Value.Item1.ManufactureName, el.Value.Item1.Price, el.Value.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(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 StoreBindingModel
{
Id = _id ?? 0,
StoreName = textBoxName.Text,
Address = textBoxAddress.Text,
OpeningDate = dateTimePicker.Value
};
var operationResult = _id.HasValue ? _logicS.Update(model) : _logicS.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();
}
}
}

View File

@ -0,0 +1,69 @@
<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>
<metadata name="ColumnManufactureName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnPrice.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -0,0 +1,115 @@
namespace BlacksmithWorkshopView
{
partial class FormStores
{
/// <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()
{
System.Windows.Forms.Button buttonRef;
this.buttonDel = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
buttonRef = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
this.Load += new System.EventHandler(this.FormStores_Load);
//
// buttonRef
//
buttonRef.Location = new System.Drawing.Point(620, 99);
buttonRef.Name = "buttonRef";
buttonRef.Size = new System.Drawing.Size(174, 23);
buttonRef.TabIndex = 3;
buttonRef.Text = "Обновить";
buttonRef.UseVisualStyleBackColor = true;
buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(620, 70);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(174, 23);
this.buttonDel.TabIndex = 4;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(620, 41);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(174, 23);
this.buttonUpd.TabIndex = 5;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// buttonAdd
//
this.buttonAdd.Location = new System.Drawing.Point(620, 12);
this.buttonAdd.Name = "buttonAdd";
this.buttonAdd.Size = new System.Drawing.Size(174, 23);
this.buttonAdd.TabIndex = 6;
this.buttonAdd.Text = "Добавить";
this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
//
// dataGridView
//
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(6, 0);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(608, 450);
this.dataGridView.TabIndex = 2;
//
// FormStores
//
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(buttonRef);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.buttonUpd);
this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.dataGridView);
this.Name = "FormStores";
this.Text = "Магазины";
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.ResumeLayout(false);
}
#endregion
private Button buttonDel;
private Button buttonUpd;
private Button buttonAdd;
private DataGridView dataGridView;
}
}

View File

@ -0,0 +1,100 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicContracts;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
namespace BlacksmithWorkshopView
{
public partial class FormStores : Form
{
private readonly ILogger _logger;
private readonly IStoreLogic _logic;
public FormStores(ILogger<FormComponents> logger, IStoreLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
}
private void FormStores_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["StoreName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Manufactures"].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(FormStore));
if (service is FormStore form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void ButtonUpd_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
var service = Program.ServiceProvider?.GetService(typeof(FormStore));
if (service is FormStore form)
{
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void ButtonDel_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 StoreBindingModel
{
Id = id
}))
{
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка удаления магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,63 @@
<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>
<metadata name="buttonRef.GenerateMember" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>False</value>
</metadata>
</root>

View File

@ -1,5 +1,7 @@
using BlacksmithWorkshopBusinessLogic.BusinessLogics;
using BlacksmithWorkShopBusinessLogic.BusinessLogics;
using BlacksmithWorkshopContracts.BusinessLogicContracts;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopFileImplement.Implements;
using BlacksmithWorkshopView;
@ -34,16 +36,21 @@ namespace BlacksmithWorkshopView
services.AddTransient<IComponentStorage, ComponentStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IManufactureStorage, ManufactureStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IStoreStorage, StoreStorage>();
services.AddTransient<IComponentLogic, ComponentLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IManufactureLogic, ManufactureLogic>();
services.AddTransient<FormMain>();
services.AddTransient<IStoreLogic, StoreLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormComponent>();
services.AddTransient<FormComponents>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormManufacture>();
services.AddTransient<FormManufactureComponent>();
services.AddTransient<FormManufactures>();
}
services.AddTransient<FormStore>();
services.AddTransient<FormStores>();
services.AddTransient<FormFillStore>();
}
}
}

View File

@ -0,0 +1,155 @@
using BlacksmithWorkShopBusinessLogic.BusinessLogics;
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using Microsoft.Extensions.Logging;
namespace BlacksmithWorkshopBusinessLogic.BusinessLogics
{
public class StoreLogic : IStoreLogic
{
private readonly ILogger _logger;
private readonly IStoreStorage _storeStorage;
public StoreLogic(ILogger<ComponentLogic> logger, IStoreStorage storeStorage)
{
_logger = logger;
_storeStorage = storeStorage;
}
public List<StoreViewModel>? ReadList(StoreSearchModel? model)
{
_logger.LogInformation("Readlist. StoreName: {Storename}. Id: {Id}", model?.StoreName, model?.Id);
var list = model == null ? _storeStorage.GetFullList() : _storeStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("Readlist. Count: {Count}", list.Count);
return list;
}
public StoreViewModel? ReadElement(StoreSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. StoreName: {StoreName}. Id: {Id}", model.StoreName, model.Id);
var element = _storeStorage.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(StoreBindingModel model)
{
CheckModel(model);
if (_storeStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(StoreBindingModel model)
{
CheckModel(model);
if (_storeStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(StoreBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_storeStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void SaveChanges(StoreViewModel? model)
{
if (model == null)
{
return;
}
_storeStorage.Update(new StoreBindingModel()
{
StoreName = model.StoreName,
Address = model.Address,
OpeningDate = model.OpeningDate,
Manufactures = model.Manufactures,
});
}
public bool AddManufacture(IManufactureModel manufacture, StoreSearchModel model, int count)
{
if (model == null)
{
throw new ArgumentNullException("Невозможно найти магазин", nameof(model));
}
if (count <= 0)
{
throw new ArgumentException("Количество добавляемых изделий должно быть больше нуля");
}
_logger.LogInformation("Adding manufacture {manufacture} in store {store}. Id = {id}", manufacture.ManufactureName, model.StoreName, model.Id);
//ищем магазин
StoreViewModel? selectedStore = _storeStorage.GetElement(model);
if (selectedStore == null)
{
_logger.LogWarning("Store with id {Id} not found", model.Id);
return false;
}
//ищем изделие в магазине
if (selectedStore.Manufactures.TryGetValue(manufacture.Id, out var manufactureInStore))
{
selectedStore.Manufactures[manufacture.Id] = (manufacture, manufactureInStore.Item2 + count);//если изделие уже есть в магазине, увеличиваем его количество
_logger.LogInformation("Filled store Id = {storeId} with manufacture Id = {manufactureId}. Count = {count}", model.Id, manufacture.Id, count);
SaveChanges(selectedStore);
return true;
}
//иначе добавляем изделие в магазин в указанном количестве
selectedStore.Manufactures.Add(manufacture.Id, (manufacture, count));
SaveChanges(selectedStore);
_logger.LogInformation("Added new manufacture Id = {manufactureId} in store Id = {storeId}. Count = {count}", manufacture.Id, model.Id, count);
return true;
}
private void CheckModel(StoreBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.StoreName))
{
throw new ArgumentNullException("Нет названия магазина", nameof(model.StoreName));
}
if (string.IsNullOrEmpty(model.Address))
{
throw new ArgumentNullException("Нет адреса магазина", nameof(model.StoreName));
}
_logger.LogInformation("Store. StoreName: {StoreName}. Address: {Address}. Id: {Id}", model.StoreName, model.Address, model.Id);
var element = _storeStorage.GetElement(new StoreSearchModel//проверка на уникальность
{
StoreName = model.StoreName
});
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
}
}

View File

@ -0,0 +1,16 @@
using BlacksmithWorkshopDataModels.Models;
namespace BlacksmithWorkshopContracts.BindingModels
{
public class StoreBindingModel : IStoreModel
{
public int Id { get; set; }
public string StoreName { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public DateTime OpeningDate { get; set; } = DateTime.Now;
/// <summary>
/// Изделия в магазине
/// </summary>
public Dictionary<int, (IManufactureModel, int)> Manufactures { get; set; } = new();
}
}

View File

@ -0,0 +1,24 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
namespace BlacksmithWorkshopContracts.BusinessLogicsContracts
{
public interface IStoreLogic
{
List<StoreViewModel>? ReadList(StoreSearchModel? model);
StoreViewModel? ReadElement(StoreSearchModel model);
bool Create(StoreBindingModel model);
bool Update(StoreBindingModel model);
bool Delete(StoreBindingModel model);
/// <summary>
/// Добавление изделия в магазин
/// </summary>
/// <param name="manufacture">Изделие</param>
/// <param name="model">Модель для поиска нужного магазина</param>
/// <param name="count">Количество изделий</param>
/// <returns></returns>
bool AddManufacture(IManufactureModel manufacture, StoreSearchModel model, int count);
}
}

View File

@ -0,0 +1,8 @@
namespace BlacksmithWorkshopContracts.SearchModels
{
public class StoreSearchModel
{
public int? Id { get; set; }
public string? StoreName { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
namespace BlacksmithWorkshopContracts.StoragesContracts
{
public interface IStoreStorage
{
List<StoreViewModel> GetFullList();
List<StoreViewModel> GetFilteredList(StoreSearchModel model);
StoreViewModel? GetElement(StoreSearchModel model);
StoreViewModel? Insert(StoreBindingModel model);
StoreViewModel? Update(StoreBindingModel model);
StoreViewModel? Delete(StoreBindingModel model);
}
}

View File

@ -0,0 +1,21 @@
using BlacksmithWorkshopDataModels.Models;
using System.ComponentModel;
namespace BlacksmithWorkshopContracts.ViewModels
{
public class StoreViewModel : IStoreModel
{
[DisplayName("Номер магазина")]
public int Id { get; set; }
[DisplayName("Название магазина")]
public string StoreName { get; set; } = string.Empty;
[DisplayName("Адрес магазина")]
public string Address { get; set; } = string.Empty;
[DisplayName("Дата открытия")]
public DateTime OpeningDate { get; set; } = DateTime.Now;
/// <summary>
/// Изделия в магазине
/// </summary>
public Dictionary<int, (IManufactureModel, int)> Manufactures { get; set; } = new();
}
}

View File

@ -0,0 +1,10 @@
namespace BlacksmithWorkshopDataModels.Models
{
public interface IStoreModel : IId
{
string StoreName { get; }
string Address { get; }
DateTime OpeningDate { get; }
Dictionary<int, (IManufactureModel, int)> Manufactures { get; }
}
}

View File

@ -8,11 +8,13 @@ namespace BlacksmithWorkshopListImplement
public List<Component> Components { get; set; }
public List<Order> Orders { get; set; }
public List<Manufacture> Manufactures { get; set; }
public List<Store> Stores { get; set; }
private DataListSingleton()
{
Components = new List<Component>();
Orders = new List<Order>();
Manufactures = new List<Manufacture>();
Stores = new List<Store>();
}
public static DataListSingleton GetInstance()
{

View File

@ -0,0 +1,104 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using BlacksmithWorkshopListImplement;
using BlacksmithWorkshopListImplement.Models;
namespace BlacksmithWorkshopListImplement.Implements
{
public class StoreStorage : IStoreStorage
{
private readonly DataListSingleton _source;
public StoreStorage()
{
_source = DataListSingleton.GetInstance();
}
public List<StoreViewModel> GetFullList()
{
var result = new List<StoreViewModel>();
foreach (var store in _source.Stores)
{
result.Add(store.GetViewModel);
}
return result;
}
public List<StoreViewModel> GetFilteredList(StoreSearchModel model)
{
var result = new List<StoreViewModel>();
if (string.IsNullOrEmpty(model.StoreName))
{
return result;
}
foreach (var store in _source.Stores)
{
if (store.StoreName.Contains(model.StoreName ?? string.Empty))
{
result.Add(store.GetViewModel);
}
}
return result;
}
public StoreViewModel? GetElement(StoreSearchModel model)
{
if (string.IsNullOrEmpty(model.StoreName) && !model.Id.HasValue)
{
return null;
}
foreach (var store in _source.Stores)
{
if ((!string.IsNullOrEmpty(model.StoreName) &&
store.StoreName == model.StoreName) ||
(model.Id.HasValue && store.Id == model.Id))
{
return store.GetViewModel;
}
}
return null;
}
public StoreViewModel? Insert(StoreBindingModel model)
{
model.Id = 1;
foreach (var store in _source.Stores)
{
if (model.Id <= store.Id)
{
model.Id = store.Id + 1;
}
}
var newStore = Store.Create(model);
if (newStore == null)
{
return null;
}
_source.Stores.Add(newStore);
return newStore.GetViewModel;
}
public StoreViewModel? Update(StoreBindingModel model)
{
foreach (var store in _source.Stores)
{
if (store.Id == model.Id)
{
store.Update(model);
return store.GetViewModel;
}
}
return null;
}
public StoreViewModel? Delete(StoreBindingModel model)
{
for (int i = 0; i < _source.Stores.Count; ++i)
{
if (_source.Stores[i].Id == model.Id)
{
var element = _source.Stores[i];
_source.Stores.RemoveAt(i);
return element.GetViewModel;
}
}
return null;
}
}
}

View File

@ -0,0 +1,49 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
namespace BlacksmithWorkshopListImplement.Models
{
public class Store : IStoreModel
{
public int Id { get; private set; }
public string StoreName { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
public DateTime OpeningDate { get; private set; }
public Dictionary<int, (IManufactureModel, int)> Manufactures { get; private set; } = new();
public static Store? Create(StoreBindingModel? model)
{
if (model == null)
{
return null;
}
return new Store()
{
Id = model.Id,
StoreName = model.StoreName,
Address = model.Address,
OpeningDate = model.OpeningDate,
Manufactures = new()
};
}
public void Update(StoreBindingModel? model)
{
if (model == null)
{
return;
}
StoreName = model.StoreName;
Address = model.Address;
OpeningDate = model.OpeningDate;
Manufactures = model.Manufactures;
}
public StoreViewModel GetViewModel => new()
{
Id = Id,
StoreName = StoreName,
Address = Address,
OpeningDate = OpeningDate,
Manufactures = Manufactures
};
}
}