Eliseev E.E. LabWork02_Hard #7

Closed
ElEgEv wants to merge 23 commits from LabWork02_Hard into LabWork01_Hard
31 changed files with 1499 additions and 119 deletions

View File

@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopContracts
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopBusinessLogic", "BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj", "{B3C97222-2894-4D74-B0D7-B3BEB347081D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopListImplement", "BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj", "{2942D468-0C3B-4B8D-A15F-184F5D7C969A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlacksmithWorkshopListImplement", "BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj", "{2942D468-0C3B-4B8D-A15F-184F5D7C969A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlacksmithWorkshopFileImplement", "BlacksmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj", "{58737D93-9A12-4D07-BF3F-86AC512CE626}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -39,6 +41,10 @@ Global
{2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2942D468-0C3B-4B8D-A15F-184F5D7C969A}.Release|Any CPU.Build.0 = Release|Any CPU
{58737D93-9A12-4D07-BF3F-86AC512CE626}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58737D93-9A12-4D07-BF3F-86AC512CE626}.Debug|Any CPU.Build.0 = Debug|Any CPU
{58737D93-9A12-4D07-BF3F-86AC512CE626}.Release|Any CPU.ActiveCfg = Release|Any CPU
{58737D93-9A12-4D07-BF3F-86AC512CE626}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -17,6 +17,7 @@
<ItemGroup>
<ProjectReference Include="..\BlacksmithWorkshopBusinessLogic\BlacksmithWorkshopBusinessLogic.csproj" />
<ProjectReference Include="..\BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj" />
<ProjectReference Include="..\BlacksmithWorkshopFileImplement\BlacksmithWorkshopFileImplement.csproj" />
<ProjectReference Include="..\BlacksmithWorkshopListImplement\BlacksmithWorkshopListImplement.csproj" />
</ItemGroup>

View File

@ -34,33 +34,32 @@
this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.menuStrip = new System.Windows.Forms.MenuStrip();
this.toolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.workPieceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.manufactureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.shopToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.addManufactureToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonSellManufacture = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(10, 27);
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.dataGridView.Location = new System.Drawing.Point(11, 36);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(820, 302);
this.dataGridView.Size = new System.Drawing.Size(937, 448);
this.dataGridView.TabIndex = 0;
//
// buttonCreateOrder
//
this.buttonCreateOrder.Location = new System.Drawing.Point(887, 50);
this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCreateOrder.Location = new System.Drawing.Point(1014, 67);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(206, 22);
this.buttonCreateOrder.Size = new System.Drawing.Size(235, 29);
this.buttonCreateOrder.TabIndex = 1;
this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreateOrder.UseVisualStyleBackColor = true;
@ -68,10 +67,9 @@
//
// buttonTakeOrderInWork
//
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(887, 107);
this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1014, 143);
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(206, 22);
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(235, 29);
this.buttonTakeOrderInWork.TabIndex = 2;
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
@ -79,10 +77,9 @@
//
// buttonOrderReady
//
this.buttonOrderReady.Location = new System.Drawing.Point(887, 165);
this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonOrderReady.Location = new System.Drawing.Point(1014, 220);
this.buttonOrderReady.Name = "buttonOrderReady";
this.buttonOrderReady.Size = new System.Drawing.Size(206, 22);
this.buttonOrderReady.Size = new System.Drawing.Size(235, 29);
this.buttonOrderReady.TabIndex = 3;
this.buttonOrderReady.Text = "Заказ готов";
this.buttonOrderReady.UseVisualStyleBackColor = true;
@ -90,10 +87,9 @@
//
// buttonIssuedOrder
//
this.buttonIssuedOrder.Location = new System.Drawing.Point(887, 222);
this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonIssuedOrder.Location = new System.Drawing.Point(1014, 296);
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
this.buttonIssuedOrder.Size = new System.Drawing.Size(206, 22);
this.buttonIssuedOrder.Size = new System.Drawing.Size(235, 29);
this.buttonIssuedOrder.TabIndex = 4;
this.buttonIssuedOrder.Text = "Заказ выдан";
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
@ -101,26 +97,25 @@
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(887, 277);
this.buttonRef.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonRef.Location = new System.Drawing.Point(1014, 369);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(206, 22);
this.buttonRef.Size = new System.Drawing.Size(235, 29);
this.buttonRef.TabIndex = 5;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// menuStrip1
// menuStrip
//
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.toolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Padding = new System.Windows.Forms.Padding(5, 2, 0, 2);
this.menuStrip1.Size = new System.Drawing.Size(1135, 24);
this.menuStrip1.TabIndex = 6;
this.menuStrip1.Text = "menuStrip1";
this.menuStrip.Location = new System.Drawing.Point(0, 0);
this.menuStrip.Name = "menuStrip";
this.menuStrip.Padding = new System.Windows.Forms.Padding(6, 3, 0, 3);
this.menuStrip.Size = new System.Drawing.Size(1297, 30);
this.menuStrip.TabIndex = 6;
this.menuStrip.Text = "menuStrip1";
//
// toolStripMenuItem
//
@ -130,57 +125,67 @@
this.shopToolStripMenuItem,
this.addManufactureToolStripMenuItem});
this.toolStripMenuItem.Name = "toolStripMenuItem";
this.toolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.toolStripMenuItem.Size = new System.Drawing.Size(117, 24);
this.toolStripMenuItem.Text = "Справочники";
//
// workPieceToolStripMenuItem
//
this.workPieceToolStripMenuItem.Name = "workPieceToolStripMenuItem";
this.workPieceToolStripMenuItem.Size = new System.Drawing.Size(198, 22);
this.workPieceToolStripMenuItem.Size = new System.Drawing.Size(251, 26);
this.workPieceToolStripMenuItem.Text = "Заготовки";
this.workPieceToolStripMenuItem.Click += new System.EventHandler(this.WorkPieceToolStripMenuItem_Click);
//
// manufactureToolStripMenuItem
//
this.manufactureToolStripMenuItem.Name = "manufactureToolStripMenuItem";
this.manufactureToolStripMenuItem.Size = new System.Drawing.Size(198, 22);
this.manufactureToolStripMenuItem.Size = new System.Drawing.Size(251, 26);
this.manufactureToolStripMenuItem.Text = "Изделия";
this.manufactureToolStripMenuItem.Click += new System.EventHandler(this.ManufactureToolStripMenuItem_Click);
//
// shopToolStripMenuItem
//
this.shopToolStripMenuItem.Name = "shopToolStripMenuItem";
this.shopToolStripMenuItem.Size = new System.Drawing.Size(198, 22);
this.shopToolStripMenuItem.Size = new System.Drawing.Size(251, 26);
this.shopToolStripMenuItem.Text = "Магазины";
this.shopToolStripMenuItem.Click += new System.EventHandler(this.ShopToolStripMenuItem_Click);
//
// addManufactureToolStripMenuItem
//
this.addManufactureToolStripMenuItem.Name = "addManufactureToolStripMenuItem";
this.addManufactureToolStripMenuItem.Size = new System.Drawing.Size(198, 22);
this.addManufactureToolStripMenuItem.Size = new System.Drawing.Size(251, 26);
this.addManufactureToolStripMenuItem.Text = "Пополнение магазина";
this.addManufactureToolStripMenuItem.Click += new System.EventHandler(this.AddManufactureToolStripMenuItem_Click);
//
// buttonSellManufacture
//
this.buttonSellManufacture.Location = new System.Drawing.Point(1014, 440);
this.buttonSellManufacture.Name = "buttonSellManufacture";
this.buttonSellManufacture.Size = new System.Drawing.Size(233, 29);
this.buttonSellManufacture.TabIndex = 7;
this.buttonSellManufacture.Text = "Продажа изделий";
this.buttonSellManufacture.UseVisualStyleBackColor = true;
this.buttonSellManufacture.Click += new System.EventHandler(this.ButtonSellManufacture_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1135, 338);
this.ClientSize = new System.Drawing.Size(1297, 496);
this.Controls.Add(this.buttonSellManufacture);
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.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Controls.Add(this.menuStrip);
this.MainMenuStrip = this.menuStrip;
this.Name = "FormMain";
this.Text = "Кузнечная мастерская";
this.Load += new System.EventHandler(this.FormMain_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.menuStrip.ResumeLayout(false);
this.menuStrip.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
@ -194,11 +199,12 @@
private Button buttonOrderReady;
private Button buttonIssuedOrder;
private Button buttonRef;
private MenuStrip menuStrip1;
private MenuStrip menuStrip;
private ToolStripMenuItem toolStripMenuItem;
private ToolStripMenuItem workPieceToolStripMenuItem;
private ToolStripMenuItem manufactureToolStripMenuItem;
private ToolStripMenuItem shopToolStripMenuItem;
private ToolStripMenuItem addManufactureToolStripMenuItem;
private Button buttonSellManufacture;
}
}

View File

@ -94,7 +94,7 @@ namespace BlacksmithWorkshop
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
@ -177,11 +177,31 @@ namespace BlacksmithWorkshop
}
}
private void ButtonSellIceCream_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellManufacture));
if (service is FormSellManufacture form)
{
form.ShowDialog();
LoadData();
}
}
private void ButtonRef_Click(object sender, EventArgs e)
{
LoadData();
}
private void ButtonSellManufacture_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellManufacture));
if (service is FormSellManufacture form)
{
form.ShowDialog();
LoadData();
}
}
private void ShopToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormShops));
@ -192,7 +212,6 @@ namespace BlacksmithWorkshop
}
}
private void AddManufactureToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormAddManufacture));
@ -204,4 +223,4 @@ namespace BlacksmithWorkshop
}
}
}
}
}

View File

@ -57,7 +57,10 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="menuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="menuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>63</value>
</metadata>
</root>

View File

@ -0,0 +1,121 @@
namespace BlacksmithWorkshop
{
partial class FormSellManufacture
{
/// <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.labelManufacture = new System.Windows.Forms.Label();
this.labelCount = new System.Windows.Forms.Label();
this.comboBoxManufacture = new System.Windows.Forms.ComboBox();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// labelManufacture
//
this.labelManufacture.AutoSize = true;
this.labelManufacture.Location = new System.Drawing.Point(32, 32);
this.labelManufacture.Name = "labelManufacture";
this.labelManufacture.Size = new System.Drawing.Size(71, 20);
this.labelManufacture.TabIndex = 0;
this.labelManufacture.Text = "Изделие:";
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(34, 85);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(93, 20);
this.labelCount.TabIndex = 1;
this.labelCount.Text = "Количество:";
//
// comboBoxManufacture
//
this.comboBoxManufacture.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBoxManufacture.FormattingEnabled = true;
this.comboBoxManufacture.Location = new System.Drawing.Point(170, 32);
this.comboBoxManufacture.Name = "comboBoxManufacture";
this.comboBoxManufacture.Size = new System.Drawing.Size(262, 28);
this.comboBoxManufacture.TabIndex = 3;
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(170, 85);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(262, 27);
this.textBoxCount.TabIndex = 4;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(239, 141);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(94, 29);
this.buttonSave.TabIndex = 6;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(339, 141);
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);
//
// FormSellManufacture
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(440, 180);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.comboBoxManufacture);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.labelManufacture);
this.Name = "FormSellManufacture";
this.Text = "Продажа изделий";
this.Load += new System.EventHandler(this.FormSellManufacture_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Label labelManufacture;
private Label labelCount;
private ComboBox comboBoxManufacture;
private TextBox textBoxCount;
private Button buttonSave;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,100 @@
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.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 BlacksmithWorkshop
{
public partial class FormSellManufacture : Form
{
private readonly ILogger _logger;
private readonly IManufactureLogic _logicI;
private readonly IShopLogic _logicS;
public FormSellManufacture(ILogger<FormAddManufacture> logger, IManufactureLogic logicI, IShopLogic logicS)
{
InitializeComponent();
_logger = logger;
_logicI = logicI;
_logicS = logicS;
}
private void FormSellManufacture_Load(object sender, EventArgs e)
{
_logger.LogInformation("Загрузка списка изделий для продажи");
try
{
var list = _logicI.ReadList(null);
if (list != null)
{
comboBoxManufacture.DisplayMember = "ManufactureName";
comboBoxManufacture.ValueMember = "Id";
comboBoxManufacture.DataSource = list;
comboBoxManufacture.SelectedItem = null;
}
}
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(textBoxCount.Text))
{
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxManufacture.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Продажа изделия");
try
{
var operationResult = _logicS.SellManufatures(_logicI.ReadElement(new ManufactureSearchModel()
{
Id = Convert.ToInt32(comboBoxManufacture.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

@ -34,59 +34,58 @@
this.textBoxAddress = new System.Windows.Forms.TextBox();
this.groupBoxIceCreams = new System.Windows.Forms.GroupBox();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnManufactureName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.labelDate = new System.Windows.Forms.Label();
this.dateTimePickerDate = new System.Windows.Forms.DateTimePicker();
this.ID = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnManufactureName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.labelCount = new System.Windows.Forms.Label();
this.numericUpDownCount = new System.Windows.Forms.NumericUpDown();
this.groupBoxIceCreams.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).BeginInit();
this.SuspendLayout();
//
// labelName
//
this.labelName.AutoSize = true;
this.labelName.Location = new System.Drawing.Point(18, 10);
this.labelName.Location = new System.Drawing.Point(21, 13);
this.labelName.Name = "labelName";
this.labelName.Size = new System.Drawing.Size(62, 15);
this.labelName.Size = new System.Drawing.Size(80, 20);
this.labelName.TabIndex = 0;
this.labelName.Text = "Название:";
//
// labelAddress
//
this.labelAddress.AutoSize = true;
this.labelAddress.Location = new System.Drawing.Point(266, 9);
this.labelAddress.Location = new System.Drawing.Point(304, 12);
this.labelAddress.Name = "labelAddress";
this.labelAddress.Size = new System.Drawing.Size(43, 15);
this.labelAddress.Size = new System.Drawing.Size(54, 20);
this.labelAddress.TabIndex = 1;
this.labelAddress.Text = "Адрес:";
//
// textBoxName
//
this.textBoxName.Location = new System.Drawing.Point(86, 7);
this.textBoxName.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxName.Location = new System.Drawing.Point(107, 10);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(138, 23);
this.textBoxName.Size = new System.Drawing.Size(157, 27);
this.textBoxName.TabIndex = 2;
//
// textBoxAddress
//
this.textBoxAddress.Location = new System.Drawing.Point(315, 6);
this.textBoxAddress.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxAddress.Location = new System.Drawing.Point(364, 9);
this.textBoxAddress.Name = "textBoxAddress";
this.textBoxAddress.Size = new System.Drawing.Size(138, 23);
this.textBoxAddress.Size = new System.Drawing.Size(157, 27);
this.textBoxAddress.TabIndex = 3;
//
// groupBoxIceCreams
//
this.groupBoxIceCreams.Controls.Add(this.dataGridView);
this.groupBoxIceCreams.Location = new System.Drawing.Point(12, 62);
this.groupBoxIceCreams.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBoxIceCreams.Location = new System.Drawing.Point(14, 94);
this.groupBoxIceCreams.Name = "groupBoxIceCreams";
this.groupBoxIceCreams.Padding = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.groupBoxIceCreams.Size = new System.Drawing.Size(720, 206);
this.groupBoxIceCreams.Size = new System.Drawing.Size(823, 275);
this.groupBoxIceCreams.TabIndex = 4;
this.groupBoxIceCreams.TabStop = false;
this.groupBoxIceCreams.Text = "Изделия";
@ -98,57 +97,20 @@
this.ID,
this.ColumnManufactureName,
this.ColumnCount});
this.dataGridView.Location = new System.Drawing.Point(5, 20);
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.dataGridView.Location = new System.Drawing.Point(6, 27);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(709, 182);
this.dataGridView.Size = new System.Drawing.Size(810, 243);
this.dataGridView.TabIndex = 0;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(411, 286);
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(136, 22);
this.buttonSave.TabIndex = 5;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(579, 286);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(136, 22);
this.buttonCancel.TabIndex = 6;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// labelDate
//
this.labelDate.AutoSize = true;
this.labelDate.Location = new System.Drawing.Point(492, 9);
this.labelDate.Name = "labelDate";
this.labelDate.Size = new System.Drawing.Size(90, 15);
this.labelDate.TabIndex = 7;
this.labelDate.Text = "Дата открытия:";
//
// dateTimePickerDate
//
this.dateTimePickerDate.Location = new System.Drawing.Point(588, 7);
this.dateTimePickerDate.Name = "dateTimePickerDate";
this.dateTimePickerDate.Size = new System.Drawing.Size(127, 23);
this.dateTimePickerDate.TabIndex = 9;
//
// ID
//
this.ID.HeaderText = "ID";
this.ID.MinimumWidth = 6;
this.ID.Name = "ID";
this.ID.Visible = false;
this.ID.Width = 125;
//
// ColumnManufactureName
//
@ -165,11 +127,67 @@
this.ColumnCount.Name = "ColumnCount";
this.ColumnCount.Width = 125;
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(470, 381);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(155, 29);
this.buttonSave.TabIndex = 5;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
this.buttonSave.Click += new System.EventHandler(this.ButtonSave_Click);
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(662, 381);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(155, 29);
this.buttonCancel.TabIndex = 6;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// labelDate
//
this.labelDate.AutoSize = true;
this.labelDate.Location = new System.Drawing.Point(562, 12);
this.labelDate.Name = "labelDate";
this.labelDate.Size = new System.Drawing.Size(113, 20);
this.labelDate.TabIndex = 7;
this.labelDate.Text = "Дата открытия:";
//
// dateTimePickerDate
//
this.dateTimePickerDate.Location = new System.Drawing.Point(681, 9);
this.dateTimePickerDate.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.dateTimePickerDate.Name = "dateTimePickerDate";
this.dateTimePickerDate.Size = new System.Drawing.Size(145, 27);
this.dateTimePickerDate.TabIndex = 9;
//
// labelCount
//
this.labelCount.AutoSize = true;
this.labelCount.Location = new System.Drawing.Point(21, 55);
this.labelCount.Name = "labelCount";
this.labelCount.Size = new System.Drawing.Size(173, 20);
this.labelCount.TabIndex = 10;
this.labelCount.Text = "Вместимость магазина:";
//
// numericUpDownCount
//
this.numericUpDownCount.Location = new System.Drawing.Point(200, 53);
this.numericUpDownCount.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.numericUpDownCount.Name = "numericUpDownCount";
this.numericUpDownCount.Size = new System.Drawing.Size(145, 27);
this.numericUpDownCount.TabIndex = 11;
//
// FormShop
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(744, 319);
this.ClientSize = new System.Drawing.Size(850, 425);
this.Controls.Add(this.numericUpDownCount);
this.Controls.Add(this.labelCount);
this.Controls.Add(this.dateTimePickerDate);
this.Controls.Add(this.labelDate);
this.Controls.Add(this.buttonCancel);
@ -179,12 +197,12 @@
this.Controls.Add(this.textBoxName);
this.Controls.Add(this.labelAddress);
this.Controls.Add(this.labelName);
this.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.Name = "FormShop";
this.Text = "Магазин";
this.Load += new System.EventHandler(this.FormShop_Load);
this.groupBoxIceCreams.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownCount)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -205,5 +223,7 @@
private DataGridViewTextBoxColumn ID;
private DataGridViewTextBoxColumn ColumnManufactureName;
private DataGridViewTextBoxColumn ColumnCount;
private Label labelCount;
private NumericUpDown numericUpDownCount;
}
}

View File

@ -30,6 +30,7 @@ namespace BlacksmithWorkshop
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
{
InitializeComponent();
_logger = logger;
_logic = logic;
_shopManufactures = new Dictionary<int, (IManufactureModel, int)>();
@ -46,11 +47,13 @@ namespace BlacksmithWorkshop
{
Id = _id.Value
});
if (view != null)
{
textBoxName.Text = view.ShopName;
textBoxAddress.Text = view.Address.ToString();
dateTimePickerDate.Value = view.DateOpen;
numericUpDownCount.Value = view.MaxCountManufactures;
_shopManufactures = view.Manufactures ?? new Dictionary<int, (IManufactureModel, int)>();
LoadData();
}
@ -104,13 +107,17 @@ namespace BlacksmithWorkshop
Id = _id ?? 0,
ShopName = textBoxName.Text,
Address = textBoxAddress.Text,
DateOpen = dateTimePickerDate.Value.Date
DateOpen = dateTimePickerDate.Value.Date,
MaxCountManufactures = (int)numericUpDownCount.Value
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();

View File

@ -1,19 +1,19 @@
using BlacksmithWorkshopBusinessLogic.BusinessLogic;
using BlacksmithWorkshopContracts.BusinessLogicsContracts;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopListImplement.Implements;
using BlacksmithWorkshopFileImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using System.Drawing;
namespace BlacksmithWorkshop
{
internal static class Program
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
@ -28,6 +28,7 @@ namespace BlacksmithWorkshop
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
@ -56,6 +57,7 @@ namespace BlacksmithWorkshop
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormAddManufacture>();
services.AddTransient<FormSellManufacture>();
}
}

View File

@ -20,10 +20,16 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
private readonly IShopLogic _shopLogic;
private readonly IManufactureStorage _manufactureStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IManufactureStorage manufactureStorage)
{
_logger = logger;
_orderStorage = orderStorage;
_shopLogic = shopLogic;
_manufactureStorage = manufactureStorage;
}
//вывод отфильтрованного списка компонентов
@ -122,7 +128,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
throw new InvalidOperationException("Дата создания должна быть более ранней, нежели дата завершения");
}
_logger.LogInformation("Order. OrderId:{Id}. Sun:{Sum}. ManufactureId:{Id}", model.Id, model.Sum, model.ManufactureId);
_logger.LogInformation("Order. OrderId:{Id}. Sun:{Sum}. ManufactureId:{Id}. Sum:{Sum}", model.Id, model.Sum, model.ManufactureId, model.Sum);
}
//обновление статуса заказа
@ -131,7 +137,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
//если не смогли найти указанный заказ по его Id
if(viewModel == null)
if (viewModel == null)
{
throw new ArgumentNullException(nameof(model));
}
@ -146,9 +152,21 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
model.Status = newOrderStatus;
//проверка на выдачу
if(model.Status == OrderStatus.Выдан)
if (model.Status == OrderStatus.Готов)
{
model.DateImplement = DateTime.Now;
var manufacture = _manufactureStorage.GetElement(new() { Id = viewModel.ManufactureId });
if (manufacture == null)
{
throw new ArgumentNullException(nameof(manufacture));
}
if (!_shopLogic.AddManufactures(manufacture, viewModel.Count))
{
throw new Exception($"AddManufactures operation failed. Shop is full.");
}
}
else
{

View File

@ -8,6 +8,7 @@ using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
@ -72,10 +73,10 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
if (count <= 0)
{
throw new ArgumentNullException("Количество добавляемого мороженого должно быть больше 0", nameof(count));
throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0", nameof(count));
}
_logger.LogInformation("AddIceCream. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id);
_logger.LogInformation("AddManufacture. ShopName:{ShopName}. Id: {Id}", model?.ShopName, model?.Id);
var shop = _shopStorage.GetElement(model);
if (shop == null)
@ -85,6 +86,11 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
return false;
}
if (shop.MaxCountManufactures - shop.Manufactures.Select(x => x.Value.Item2).Sum() < count)
{
throw new ArgumentNullException("Слишком много изделий для одного магазина", nameof(count));
}
if (!shop.Manufactures.ContainsKey(manufacture.Id))
{
shop.Manufactures[manufacture.Id] = (manufacture, count);
@ -99,6 +105,7 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
ShopName = shop.ShopName,
Address = shop.Address,
DateOpen = shop.DateOpen,
MaxCountManufactures = shop.MaxCountManufactures,
Manufactures = shop.Manufactures
});
@ -181,5 +188,61 @@ namespace BlacksmithWorkshopBusinessLogic.BusinessLogic
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
public bool AddManufactures(IManufactureModel model, int count)
{
if (count <= 0)
{
throw new ArgumentNullException("Количество добавляемых изделий должно быть больше 0", nameof(count));
}
_logger.LogInformation("AddManufactures. Manufacture: {Manufacture}. Count: {Count}", model?.ManufactureName, count);
var capacity = _shopStorage.GetFullList().Select(x => x.MaxCountManufactures - x.Manufactures.Select(x => x.Value.Item2).Sum()).Sum() - count;
if (capacity < 0)
{
_logger.LogWarning("AddManufactures operation failed. Sell {count} Manufactures ", -capacity);
return false;
}
foreach (var shop in _shopStorage.GetFullList())
{
if (shop.MaxCountManufactures - shop.Manufactures.Select(x => x.Value.Item2).Sum() < count)
{
if (!AddManufacture(new() { Id = shop.Id }, model, shop.MaxCountManufactures - shop.Manufactures.Select(x => x.Value.Item2).Sum()))
{
_logger.LogWarning("AddManufactures operation failed.");
return false;
}
count -= shop.MaxCountManufactures - shop.Manufactures.Select(x => x.Value.Item2).Sum();
}
else
{
if (!AddManufacture(new() { Id = shop.Id }, model, count))
{
_logger.LogWarning("AddManufactures operation failed.");
return false;
}
count -= count;
}
if (count == 0)
{
return true;
}
}
return true;
}
public bool SellManufatures(IManufactureModel model, int count)
{
return _shopStorage.SellManufactures(model, count);
}
}
}

View File

@ -18,5 +18,7 @@ namespace BlacksmithWorkshopContracts.BindingModels
public Dictionary<int, (IManufactureModel, int)> Manufactures { get; set; } = new();
public int Id { get; set; }
public int MaxCountManufactures { get; set; }
}
}

View File

@ -23,5 +23,9 @@ namespace BlacksmithWorkshopContracts.BusinessLogicsContracts
bool Delete(ShopBindingModel model);
bool AddManufacture(ShopSearchModel model, IManufactureModel manufacture, int count);
bool SellManufatures(IManufactureModel model, int count);
bool AddManufactures(IManufactureModel model, int count);
}
}

View File

@ -1,6 +1,7 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@ -22,5 +23,7 @@ namespace BlacksmithWorkshopContracts.StoragesContracts
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool SellManufactures(IManufactureModel model, int count);
}
}

View File

@ -22,5 +22,8 @@ namespace BlacksmithWorkshopContracts.ViewModels
public DateTime DateOpen { get; set; } = DateTime.Now;
public Dictionary<int, (IManufactureModel, int)> Manufactures { get; set; } = new();
[DisplayName("Вместимость магазина")]
public int MaxCountManufactures { get; set; }
}
}

View File

@ -19,6 +19,9 @@ namespace BlacksmithWorkshopDataModels.Models
//дата открытия магазина
DateTime DateOpen { get; }
//максимальное кол-во изделий в магазине
int MaxCountManufactures { get; }
//изделия в магазине
Dictionary<int, (IManufactureModel, int)> Manufactures { get; }
}

View File

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\BlacksmithWorkshopContracts\BlacksmithWorkshopContracts.csproj" />
<ProjectReference Include="..\BlacksmithWorkshopDataModels\BlacksmithWorkshopDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using BlacksmithWorkshopFileImplement.Models;
namespace BlacksmithWorkshopFileImplement
{
public class DataFileSingleton
{
private static DataFileSingleton? instance;
private readonly string WorkPieceFileName = "WorkPiece.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string ManufactureFileName = "Manufacture.xml";
private readonly string ShopFileName = "Shop.xml";
public List<WorkPiece> WorkPieces { get; private set; }
public List<Order> Orders { get; private set; }
public List<Manufacture> Manufactures { get; private set; }
public List<Shop> Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
{
instance = new DataFileSingleton();
}
return instance;
}
public void SaveWorkPieces() => SaveData(WorkPieces, WorkPieceFileName, "WorkPieces", x => x.GetXElement);
public void SaveManufactures() => SaveData(Manufactures, ManufactureFileName, "Manufactures", x => x.GetXElement);
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
private DataFileSingleton()
{
WorkPieces = LoadData(WorkPieceFileName, "WorkPiece", x => WorkPiece.Create(x)!)!;
Manufactures = LoadData(ManufactureFileName, "Manufacture", x => Manufacture.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
}
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
{
if (File.Exists(filename))
{
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
}
return new List<T>();
}
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
{
if (data != null)
{
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
}
}
}
}

View File

@ -0,0 +1,97 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopFileImplement.Implements
{
//реализация интерфейса хранилища изделий
public class ManufactureStorage : IManufactureStorage
{
private readonly DataFileSingleton source;
public ManufactureStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<ManufactureViewModel> GetFullList()
{
return source.Manufactures.Select(x => x.GetViewModel).ToList();
}
public List<ManufactureViewModel> GetFilteredList(ManufactureSearchModel model)
{
if (string.IsNullOrEmpty(model.ManufactureName))
{
return new();
}
return source.Manufactures.Where(x => x.ManufactureName.Contains(model.ManufactureName)).Select(x => x.GetViewModel).ToList();
}
public ManufactureViewModel? GetElement(ManufactureSearchModel model)
{
if (string.IsNullOrEmpty(model.ManufactureName) && !model.Id.HasValue)
{
return null;
}
return source.Manufactures.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ManufactureName) && x.ManufactureName == model.ManufactureName)
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ManufactureViewModel? Insert(ManufactureBindingModel model)
{
model.Id = source.Manufactures.Count > 0 ? source.Manufactures.Max(x => x.Id) + 1 : 1;
var newManufacture = Manufacture.Create(model);
if (newManufacture == null)
{
return null;
}
source.Manufactures.Add(newManufacture);
source.SaveManufactures();
return newManufacture.GetViewModel;
}
public ManufactureViewModel? Update(ManufactureBindingModel model)
{
var manufacture = source.Manufactures.FirstOrDefault(x => x.Id == model.Id);
if (manufacture == null)
{
return null;
}
manufacture.Update(model);
source.SaveManufactures();
return manufacture.GetViewModel;
}
public ManufactureViewModel? Delete(ManufactureBindingModel model)
{
var element = source.Manufactures.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Manufactures.Remove(element);
source.SaveManufactures();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,111 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopFileImplement.Implements
{
//реализация интерфейса хранилища заказов
public class OrderStorage : IOrderStorage
{
private readonly DataFileSingleton source;
public OrderStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<OrderViewModel> GetFullList()
{
return source.Orders.Select(x => GetViewModel(x)).ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
return source.Orders.Where(x => x.Id == model.Id).Select(x => GetViewModel(x)).ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return source.Orders.FirstOrDefault(x =>(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
//для загрузки названий изделия в заказе
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
var manufacture = source.Manufactures.FirstOrDefault(x => x.Id == order.ManufactureId);
if(manufacture != null)
{
viewModel.ManufactureName = manufacture.ManufactureName;
}
return viewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
source.Orders.Add(newOrder);
source.SaveOrders();
return GetViewModel(newOrder);
}
public OrderViewModel? Update(OrderBindingModel model)
{
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
source.SaveOrders();
return GetViewModel(order);
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Orders.Remove(element);
source.SaveOrders();
return GetViewModel(element);
}
return null;
}
}
}

View File

@ -0,0 +1,139 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using BlacksmithWorkshopFileImplement.Models;
using System.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopFileImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataFileSingleton _source;
public ShopStorage()
{
_source = DataFileSingleton.GetInstance();
}
public List<ShopViewModel> GetFullList()
{
return _source.Shops.Select(x => x.GetViewModel).ToList();
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName))
{
return new();
}
return _source.Shops.Where(x => x.ShopName.Contains(model.ShopName))
.Select(x => x.GetViewModel).ToList();
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
{
return null;
}
return _source.Shops.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName)
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ShopViewModel? Insert(ShopBindingModel model)
{
model.Id = _source.Shops.Count > 0 ? _source.Shops.Max(x => x.Id) + 1 : 1;
var newShop = Shop.Create(model);
if (newShop == null)
{
return null;
}
_source.Shops.Add(newShop);
_source.SaveShops();
return newShop.GetViewModel;
}
public ShopViewModel? Update(ShopBindingModel model)
{
var shop = _source.Shops.FirstOrDefault(x => x.ShopName.Contains(model.ShopName) || x.Id == model.Id);
if (shop == null)
{
return null;
}
shop.Update(model);
_source.SaveShops();
return shop.GetViewModel;
}
public ShopViewModel? Delete(ShopBindingModel model)
{
var element = _source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
_source.Shops.Remove(element);
_source.SaveShops();
return element.GetViewModel;
}
return null;
}
public bool SellManufactures(IManufactureModel model, int count)
{
if (_source.Shops.Select(x => x.Manufactures.FirstOrDefault(x => x.Key == model.Id).Value.Item2).Sum() < count)
{
return false;
}
var list = _source.Shops.Where(x => x.Manufactures.ContainsKey(model.Id));
foreach (var shop in list)
{
if (shop.Manufactures[model.Id].Item2 < count)
{
count -= shop.Manufactures[model.Id].Item2;
shop.Manufactures[model.Id] = (shop.Manufactures[model.Id].Item1, 0);
}
else
{
shop.Manufactures[model.Id] = (shop.Manufactures[model.Id].Item1, shop.Manufactures[model.Id].Item2 - count);
count -= count;
}
Update(new()
{
ShopName = shop.ShopName,
Address = shop.Address,
DateOpen = shop.DateOpen,
MaxCountManufactures = shop.MaxCountManufactures,
Manufactures = shop.Manufactures
});
if (count == 0)
{
return true;
}
}
return true;
}
}
}

View File

@ -0,0 +1,98 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopFileImplement.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BlacksmithWorkshopFileImplement.Implements
{
//реализация интерфейса хранилища заготовок
public class WorkPieceStorage : IWorkPieceStorage
{
private readonly DataFileSingleton source;
public WorkPieceStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<WorkPieceViewModel> GetFullList()
{
return source.WorkPieces.Select(x => x.GetViewModel).ToList();
}
public List<WorkPieceViewModel> GetFilteredList(WorkPieceSearchModel model)
{
if (string.IsNullOrEmpty(model.WorkPieceName))
{
return new();
}
return source.WorkPieces.Where(x => x.WorkPieceName.Contains(model.WorkPieceName)).Select(x => x.GetViewModel).ToList();
}
public WorkPieceViewModel? GetElement(WorkPieceSearchModel model)
{
if (string.IsNullOrEmpty(model.WorkPieceName) && !model.Id.HasValue)
{
return null;
}
return source.WorkPieces.FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkPieceName) && x.WorkPieceName == model.WorkPieceName)
|| (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public WorkPieceViewModel? Insert(WorkPieceBindingModel model)
{
model.Id = source.WorkPieces.Count > 0 ? source.WorkPieces.Max(x => x.Id) + 1 : 1;
var newWorkPiece = WorkPiece.Create(model);
if (newWorkPiece == null)
{
return null;
}
source.WorkPieces.Add(newWorkPiece);
source.SaveWorkPieces();
return newWorkPiece.GetViewModel;
}
public WorkPieceViewModel? Update(WorkPieceBindingModel model)
{
var workPiece = source.WorkPieces.FirstOrDefault(x => x.Id == model.Id);
if (workPiece == null)
{
return null;
}
workPiece.Update(model);
source.SaveWorkPieces();
return workPiece.GetViewModel;
}
public WorkPieceViewModel? Delete(WorkPieceBindingModel model)
{
var element = source.WorkPieces.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.WorkPieces.Remove(element);
source.SaveWorkPieces();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,108 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
//класс реализующий интерфейс модели изделия
public class Manufacture : IManufactureModel
{
public int Id { get; private set; }
public string ManufactureName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, int> WorkPieces { get; private set; } = new();
private Dictionary<int, (IWorkPieceModel, int)>? _manufactureWorkPieces = null;
public Dictionary<int, (IWorkPieceModel, int)> ManufactureWorkPieces
{
get
{
if (_manufactureWorkPieces == null)
{
var source = DataFileSingleton.GetInstance();
_manufactureWorkPieces = WorkPieces.ToDictionary(x => x.Key,
y => ((source.WorkPieces.FirstOrDefault(z => z.Id == y.Key) as IWorkPieceModel)!, y.Value));
}
return _manufactureWorkPieces;
}
}
public static Manufacture? Create(ManufactureBindingModel model)
{
if (model == null)
{
return null;
}
return new Manufacture()
{
Id = model.Id,
ManufactureName = model.ManufactureName,
Price = model.Price,
WorkPieces = model.ManufactureWorkPieces.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
public static Manufacture? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Manufacture()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ManufactureName = element.Element("ManufactureName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
WorkPieces = element.Element("ManufactureWorkPieces")!.Elements("ManufactureWorkPieces").ToDictionary(
x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(ManufactureBindingModel model)
{
if (model == null)
{
return;
}
ManufactureName = model.ManufactureName;
Price = model.Price;
WorkPieces = model.ManufactureWorkPieces.ToDictionary(x => x.Key, x => x.Value.Item2);
_manufactureWorkPieces = null;
}
public ManufactureViewModel GetViewModel => new()
{
Id = Id,
ManufactureName = ManufactureName,
Price = Price,
ManufactureWorkPieces = ManufactureWorkPieces
};
public XElement GetXElement => new("Manufacture",
new XAttribute("Id", Id),
new XElement("ManufactureName", ManufactureName),
new XElement("Price", Price.ToString()),
new XElement("ManufactureWorkPieces", WorkPieces.Select(
x => new XElement("ManufactureWorkPieces",
new XElement("Key", x.Key),
new XElement("Value", x.Value))
).ToArray()));
}
}

View File

@ -0,0 +1,103 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Enums;
using BlacksmithWorkshopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
//класс, реализующий интерфейс модели заказа
public class Order : IOrderModel
{
public int Id { get; private set; }
public int ManufactureId { get; private set; }
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
ManufactureId = model.ManufactureId,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
public static Order? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ManufactureId = Convert.ToInt32(element.Element("ManufactureId")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null :
Convert.ToDateTime(element.Element("DateImplement")!.Value)
};
}
public void Update(OrderBindingModel model)
{
if(model == null)
{
return;
}
Status = model.Status;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
ManufactureId = ManufactureId,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("ManufactureId", ManufactureId.ToString()),
new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()),
new XElement("DateCreate", DateCreate.ToString()),
new XElement("DateImplement", DateImplement.ToString()));
}
}

View File

@ -0,0 +1,110 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; set; }
public string ShopName { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public DateTime DateOpen { get; set; }
public int MaxCountManufactures { get; set; }
public Dictionary<int, int> countManufacture { get; private set; } = new();
public Dictionary<int, (IManufactureModel, int)> _manufactures = null;
public Dictionary<int, (IManufactureModel, int)> Manufactures
{
get
{
if (_manufactures == null)
{
var source = DataFileSingleton.GetInstance();
_manufactures = countManufacture.ToDictionary(x => x.Key, y => ((source.Manufactures.FirstOrDefault(z => z.Id == y.Key) as IManufactureModel)!, y.Value));
}
return _manufactures;
}
}
public static Shop? Create(ShopBindingModel model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
ShopName = model.ShopName,
Address = model.Address,
DateOpen = model.DateOpen,
MaxCountManufactures = model.MaxCountManufactures,
countManufacture = model.Manufactures.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
public static Shop? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Shop()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ShopName = element.Element("ShopName")!.Value,
Address = element.Element("Address")!.Value,
DateOpen = Convert.ToDateTime(element.Element("DateOpen")!.Value),
MaxCountManufactures = Convert.ToInt32(element.Element("MaxCountManufactures")!.Value),
countManufacture = element.Element("Manufactures")!.Elements("Manufactures").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
ShopName = model.ShopName;
Address = model.Address;
DateOpen = model.DateOpen;
MaxCountManufactures = model.MaxCountManufactures;
countManufacture = model.Manufactures.ToDictionary(x => x.Key, x => x.Value.Item2);
_manufactures = null;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Address = Address,
DateOpen = DateOpen,
MaxCountManufactures = MaxCountManufactures,
Manufactures = Manufactures
};
public XElement GetXElement => new("Shop",
new XAttribute("Id", Id),
new XElement("ShopName", ShopName),
new XElement("Address", Address),
new XElement("DateOpen", DateOpen.ToString()),
new XElement("MaxCountManufactures", MaxCountManufactures.ToString()),
new XElement("Manufactures", countManufacture.Select(x => new XElement("Manufactures",
new XElement("Key", x.Key),
new XElement("Value", x.Value))).ToArray()));
}
}

View File

@ -0,0 +1,76 @@
using BlacksmithWorkshopContracts.BindingModels;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace BlacksmithWorkshopFileImplement.Models
{
//реализация интерфейса модели заготовки
public class WorkPiece : IWorkPieceModel
{
public int Id { get; private set; }
public string WorkPieceName { get; private set; } = string.Empty;
public double Cost { get; set; }
public static WorkPiece? Create(WorkPieceBindingModel model)
{
if (model == null)
{
return null;
}
return new WorkPiece()
{
Id = model.Id,
WorkPieceName = model.WorkPieceName,
Cost = model.Cost
};
}
public static WorkPiece? Create(XElement element)
{
if (element == null)
{
return null;
}
return new WorkPiece()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
WorkPieceName = element.Element("WorkPieceName")!.Value,
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
};
}
public void Update(WorkPieceBindingModel model)
{
if (model == null)
{
return;
}
WorkPieceName = model.WorkPieceName;
Cost = model.Cost;
}
public WorkPieceViewModel GetViewModel => new()
{
Id = Id,
WorkPieceName = WorkPieceName,
Cost = Cost
};
public XElement GetXElement => new("WorkPiece",
new XAttribute("Id", Id),
new XElement("WorkPieceName", WorkPieceName),
new XElement("Cost", Cost.ToString()));
}
}

View File

@ -2,6 +2,7 @@
using BlacksmithWorkshopContracts.SearchModels;
using BlacksmithWorkshopContracts.StoragesContracts;
using BlacksmithWorkshopContracts.ViewModels;
using BlacksmithWorkshopDataModels.Models;
using BlacksmithWorkshopListImplement.Models;
using System;
using System.Collections.Generic;
@ -124,5 +125,10 @@ namespace BlacksmithWorkshopListImplement.Implements
return null;
}
public bool SellManufactures(IManufactureModel model, int count)
{
throw new NotImplementedException();
}
}
}

View File

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace BlacksmithWorkshopListImplement.Models
{
//класс реализующий интерфейс модели изделия
//класс, реализующий интерфейс модели изделия
public class Manufacture : IManufactureModel
{
//методы set делаем приватным, чтобы исключить неразрешённые манипуляции

View File

@ -19,6 +19,8 @@ namespace BlacksmithWorkshopListImplement.Models
public int Id { get; set; }
public int MaxCountManufactures { get; set; }
public Dictionary<int, (IManufactureModel, int)> Manufactures { get; private set; } =
new Dictionary<int, (IManufactureModel, int)>();