Compare commits
12 Commits
LabWork_2
...
LabWork_3_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f19965f37b | ||
|
|
a150273330 | ||
|
|
27e819f656 | ||
|
|
06a2966ffc | ||
|
|
cac8ea5d92 | ||
|
|
6ffc6eee95 | ||
|
|
be0302ba63 | ||
|
|
a60bb52fff | ||
|
|
2a1ce016e7 | ||
|
|
c54f78bdb0 | ||
|
|
54d61694e3 | ||
|
|
78c2459fd0 |
@@ -13,7 +13,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairBusinessLogic
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairListImplement", "PlumbingRepairListImplement\PlumbingRepairListImplement.csproj", "{9B17B17E-1201-4B23-ACCD-EF7F4495E4B7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlumbingRepairFileImplement", "PlumpingRepairFileImplement\PlumbingRepairFileImplement.csproj", "{BA7E2CE6-7797-42C7-931C-40C48EA521C7}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairFileImplement", "PlumpingRepairFileImplement\PlumbingRepairFileImplement.csproj", "{BA7E2CE6-7797-42C7-931C-40C48EA521C7}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlumbingRepairDatabaseImplement", "PlumbingRepairDatabaseImplement\PlumbingRepairDatabaseImplement.csproj", "{1E4DDF78-14D2-498B-9A17-473F156DBE11}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -45,6 +47,10 @@ Global
|
||||
{BA7E2CE6-7797-42C7-931C-40C48EA521C7}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BA7E2CE6-7797-42C7-931C-40C48EA521C7}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BA7E2CE6-7797-42C7-931C-40C48EA521C7}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1E4DDF78-14D2-498B-9A17-473F156DBE11}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1E4DDF78-14D2-498B-9A17-473F156DBE11}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1E4DDF78-14D2-498B-9A17-473F156DBE11}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1E4DDF78-14D2-498B-9A17-473F156DBE11}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace PlumbingRepair
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void FormComponents_Load(object sender, EventArgs e)
|
||||
|
||||
84
PlumbingRepair/PlumbingRepair/FormMain.Designer.cs
generated
84
PlumbingRepair/PlumbingRepair/FormMain.Designer.cs
generated
@@ -32,25 +32,26 @@
|
||||
this.СправочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.StoreToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.DataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.CreateOrderButton = new System.Windows.Forms.Button();
|
||||
this.TakeOrderInWorkButton = new System.Windows.Forms.Button();
|
||||
this.OrderReadyButton = new System.Windows.Forms.Button();
|
||||
this.IssuedOrderButton = new System.Windows.Forms.Button();
|
||||
this.UpdateListButton = new System.Windows.Forms.Button();
|
||||
this.StoreReplenishment = new System.Windows.Forms.Button();
|
||||
this.SellWorkButton = new System.Windows.Forms.Button();
|
||||
this.MenuStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// MenuStrip
|
||||
//
|
||||
this.MenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
|
||||
this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.СправочникиToolStripMenuItem});
|
||||
this.MenuStrip.Location = new System.Drawing.Point(0, 0);
|
||||
this.MenuStrip.Name = "MenuStrip";
|
||||
this.MenuStrip.Padding = new System.Windows.Forms.Padding(7, 3, 0, 3);
|
||||
this.MenuStrip.Size = new System.Drawing.Size(989, 30);
|
||||
this.MenuStrip.Size = new System.Drawing.Size(865, 24);
|
||||
this.MenuStrip.TabIndex = 0;
|
||||
this.MenuStrip.Text = "menuStrip1";
|
||||
//
|
||||
@@ -58,42 +59,47 @@
|
||||
//
|
||||
this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||
this.ИзделияToolStripMenuItem,
|
||||
this.КомпонентыToolStripMenuItem});
|
||||
this.КомпонентыToolStripMenuItem,
|
||||
this.StoreToolStripMenuItem});
|
||||
this.СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem";
|
||||
this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(117, 24);
|
||||
this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
|
||||
this.СправочникиToolStripMenuItem.Text = "Cправочники";
|
||||
//
|
||||
// ИзделияToolStripMenuItem
|
||||
//
|
||||
this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem";
|
||||
this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
|
||||
this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.ИзделияToolStripMenuItem.Text = "Изделия";
|
||||
this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
|
||||
//
|
||||
// КомпонентыToolStripMenuItem
|
||||
//
|
||||
this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
|
||||
this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(182, 26);
|
||||
this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.КомпонентыToolStripMenuItem.Text = "Компоненты";
|
||||
this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
|
||||
//
|
||||
// StoreToolStripMenuItem
|
||||
//
|
||||
this.StoreToolStripMenuItem.Name = "StoreToolStripMenuItem";
|
||||
this.StoreToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||
this.StoreToolStripMenuItem.Text = "Магазины";
|
||||
this.StoreToolStripMenuItem.Click += new System.EventHandler(this.StoreToolStripMenuItem_Click);
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.DataGridView.Location = new System.Drawing.Point(0, 36);
|
||||
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.DataGridView.Location = new System.Drawing.Point(0, 27);
|
||||
this.DataGridView.Name = "DataGridView";
|
||||
this.DataGridView.RowHeadersWidth = 51;
|
||||
this.DataGridView.RowTemplate.Height = 25;
|
||||
this.DataGridView.Size = new System.Drawing.Size(825, 561);
|
||||
this.DataGridView.Size = new System.Drawing.Size(722, 421);
|
||||
this.DataGridView.TabIndex = 1;
|
||||
//
|
||||
// CreateOrderButton
|
||||
//
|
||||
this.CreateOrderButton.Location = new System.Drawing.Point(832, 37);
|
||||
this.CreateOrderButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.CreateOrderButton.Location = new System.Drawing.Point(728, 28);
|
||||
this.CreateOrderButton.Name = "CreateOrderButton";
|
||||
this.CreateOrderButton.Size = new System.Drawing.Size(143, 44);
|
||||
this.CreateOrderButton.Size = new System.Drawing.Size(125, 33);
|
||||
this.CreateOrderButton.TabIndex = 2;
|
||||
this.CreateOrderButton.Text = "Создать заказ";
|
||||
this.CreateOrderButton.UseVisualStyleBackColor = true;
|
||||
@@ -101,10 +107,9 @@
|
||||
//
|
||||
// TakeOrderInWorkButton
|
||||
//
|
||||
this.TakeOrderInWorkButton.Location = new System.Drawing.Point(832, 111);
|
||||
this.TakeOrderInWorkButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.TakeOrderInWorkButton.Location = new System.Drawing.Point(728, 83);
|
||||
this.TakeOrderInWorkButton.Name = "TakeOrderInWorkButton";
|
||||
this.TakeOrderInWorkButton.Size = new System.Drawing.Size(143, 52);
|
||||
this.TakeOrderInWorkButton.Size = new System.Drawing.Size(125, 39);
|
||||
this.TakeOrderInWorkButton.TabIndex = 3;
|
||||
this.TakeOrderInWorkButton.Text = "Отдать на выполнение";
|
||||
this.TakeOrderInWorkButton.UseVisualStyleBackColor = true;
|
||||
@@ -112,10 +117,9 @@
|
||||
//
|
||||
// OrderReadyButton
|
||||
//
|
||||
this.OrderReadyButton.Location = new System.Drawing.Point(832, 195);
|
||||
this.OrderReadyButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.OrderReadyButton.Location = new System.Drawing.Point(728, 146);
|
||||
this.OrderReadyButton.Name = "OrderReadyButton";
|
||||
this.OrderReadyButton.Size = new System.Drawing.Size(143, 44);
|
||||
this.OrderReadyButton.Size = new System.Drawing.Size(125, 33);
|
||||
this.OrderReadyButton.TabIndex = 4;
|
||||
this.OrderReadyButton.Text = "Заказ готов";
|
||||
this.OrderReadyButton.UseVisualStyleBackColor = true;
|
||||
@@ -123,10 +127,9 @@
|
||||
//
|
||||
// IssuedOrderButton
|
||||
//
|
||||
this.IssuedOrderButton.Location = new System.Drawing.Point(832, 272);
|
||||
this.IssuedOrderButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.IssuedOrderButton.Location = new System.Drawing.Point(728, 204);
|
||||
this.IssuedOrderButton.Name = "IssuedOrderButton";
|
||||
this.IssuedOrderButton.Size = new System.Drawing.Size(143, 44);
|
||||
this.IssuedOrderButton.Size = new System.Drawing.Size(125, 33);
|
||||
this.IssuedOrderButton.TabIndex = 5;
|
||||
this.IssuedOrderButton.Text = "Заказ выдан";
|
||||
this.IssuedOrderButton.UseVisualStyleBackColor = true;
|
||||
@@ -134,20 +137,41 @@
|
||||
//
|
||||
// UpdateListButton
|
||||
//
|
||||
this.UpdateListButton.Location = new System.Drawing.Point(832, 349);
|
||||
this.UpdateListButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.UpdateListButton.Location = new System.Drawing.Point(728, 262);
|
||||
this.UpdateListButton.Name = "UpdateListButton";
|
||||
this.UpdateListButton.Size = new System.Drawing.Size(143, 44);
|
||||
this.UpdateListButton.Size = new System.Drawing.Size(125, 33);
|
||||
this.UpdateListButton.TabIndex = 6;
|
||||
this.UpdateListButton.Text = "Обновить список";
|
||||
this.UpdateListButton.UseVisualStyleBackColor = true;
|
||||
this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click);
|
||||
//
|
||||
// StoreReplenishment
|
||||
//
|
||||
this.StoreReplenishment.Location = new System.Drawing.Point(728, 317);
|
||||
this.StoreReplenishment.Name = "StoreReplenishment";
|
||||
this.StoreReplenishment.Size = new System.Drawing.Size(125, 50);
|
||||
this.StoreReplenishment.TabIndex = 7;
|
||||
this.StoreReplenishment.Text = "Пополнение магазина";
|
||||
this.StoreReplenishment.UseVisualStyleBackColor = true;
|
||||
this.StoreReplenishment.Click += new System.EventHandler(this.StoreReplenishment_Click);
|
||||
//
|
||||
// SellPackageButton
|
||||
//
|
||||
this.SellWorkButton.Location = new System.Drawing.Point(728, 385);
|
||||
this.SellWorkButton.Name = "SellWorkButton";
|
||||
this.SellWorkButton.Size = new System.Drawing.Size(125, 31);
|
||||
this.SellWorkButton.TabIndex = 8;
|
||||
this.SellWorkButton.Text = "Продать изделие";
|
||||
this.SellWorkButton.UseVisualStyleBackColor = true;
|
||||
this.SellWorkButton.Click += new System.EventHandler(this.SellWorkButton_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(989, 600);
|
||||
this.ClientSize = new System.Drawing.Size(865, 450);
|
||||
this.Controls.Add(this.SellWorkButton);
|
||||
this.Controls.Add(this.StoreReplenishment);
|
||||
this.Controls.Add(this.UpdateListButton);
|
||||
this.Controls.Add(this.IssuedOrderButton);
|
||||
this.Controls.Add(this.OrderReadyButton);
|
||||
@@ -156,7 +180,6 @@
|
||||
this.Controls.Add(this.DataGridView);
|
||||
this.Controls.Add(this.MenuStrip);
|
||||
this.MainMenuStrip = this.MenuStrip;
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.Name = "FormMain";
|
||||
this.Text = "Ремонт сантехники";
|
||||
this.Load += new System.EventHandler(this.FormMain_Load);
|
||||
@@ -180,5 +203,8 @@
|
||||
private Button OrderReadyButton;
|
||||
private Button IssuedOrderButton;
|
||||
private Button UpdateListButton;
|
||||
private ToolStripMenuItem StoreToolStripMenuItem;
|
||||
private Button StoreReplenishment;
|
||||
private Button SellWorkButton;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ namespace PlumbingRepair
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_orderLogic = orderLogic;
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void FormMain_Load(object sender, EventArgs e)
|
||||
@@ -186,5 +187,35 @@ namespace PlumbingRepair
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void StoreReplenishment_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment));
|
||||
|
||||
if (service is FormStoreReplenishment form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void StoreToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStores));
|
||||
|
||||
if (service is FormStores form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void SellWorkButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormSellWork));
|
||||
|
||||
if (service is FormSellWork form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,64 @@
|
||||
<root>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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">
|
||||
@@ -57,7 +117,4 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<metadata name="MenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
</root>
|
||||
124
PlumbingRepair/PlumbingRepair/FormSellWork.Designer.cs
generated
Normal file
124
PlumbingRepair/PlumbingRepair/FormSellWork.Designer.cs
generated
Normal file
@@ -0,0 +1,124 @@
|
||||
namespace PlumbingRepair
|
||||
{
|
||||
partial class FormSellWork
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
WorkLabel = new Label();
|
||||
QuantityLabel = new Label();
|
||||
WorkСomboBox = new ComboBox();
|
||||
QuantityTextBox = new TextBox();
|
||||
SaveButton = new Button();
|
||||
ButtonCancel = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// WorkLabel
|
||||
//
|
||||
WorkLabel.AutoSize = true;
|
||||
WorkLabel.Location = new Point(14, 24);
|
||||
WorkLabel.Name = "WorkLabel";
|
||||
WorkLabel.Size = new Size(71, 20);
|
||||
WorkLabel.TabIndex = 0;
|
||||
WorkLabel.Text = "Изделие:";
|
||||
//
|
||||
// QuantityLabel
|
||||
//
|
||||
QuantityLabel.AutoSize = true;
|
||||
QuantityLabel.Location = new Point(14, 68);
|
||||
QuantityLabel.Name = "QuantityLabel";
|
||||
QuantityLabel.Size = new Size(93, 20);
|
||||
QuantityLabel.TabIndex = 1;
|
||||
QuantityLabel.Text = "Количество:";
|
||||
//
|
||||
// WorkСomboBox
|
||||
//
|
||||
WorkСomboBox.FormattingEnabled = true;
|
||||
WorkСomboBox.Location = new Point(101, 20);
|
||||
WorkСomboBox.Margin = new Padding(3, 4, 3, 4);
|
||||
WorkСomboBox.Name = "WorkСomboBox";
|
||||
WorkСomboBox.Size = new Size(210, 28);
|
||||
WorkСomboBox.TabIndex = 2;
|
||||
//
|
||||
// QuantityTextBox
|
||||
//
|
||||
QuantityTextBox.Location = new Point(101, 64);
|
||||
QuantityTextBox.Margin = new Padding(3, 4, 3, 4);
|
||||
QuantityTextBox.Name = "QuantityTextBox";
|
||||
QuantityTextBox.Size = new Size(210, 27);
|
||||
QuantityTextBox.TabIndex = 3;
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
SaveButton.Location = new Point(82, 133);
|
||||
SaveButton.Margin = new Padding(3, 4, 3, 4);
|
||||
SaveButton.Name = "SaveButton";
|
||||
SaveButton.Size = new Size(111, 39);
|
||||
SaveButton.TabIndex = 4;
|
||||
SaveButton.Text = "Сохранить";
|
||||
SaveButton.UseVisualStyleBackColor = true;
|
||||
SaveButton.Click += SaveButton_Click;
|
||||
//
|
||||
// ButtonCancel
|
||||
//
|
||||
ButtonCancel.Location = new Point(200, 133);
|
||||
ButtonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||
ButtonCancel.Name = "ButtonCancel";
|
||||
ButtonCancel.Size = new Size(111, 39);
|
||||
ButtonCancel.TabIndex = 5;
|
||||
ButtonCancel.Text = "Отмена";
|
||||
ButtonCancel.UseVisualStyleBackColor = true;
|
||||
ButtonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// FormSellWork
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(325, 188);
|
||||
Controls.Add(ButtonCancel);
|
||||
Controls.Add(SaveButton);
|
||||
Controls.Add(QuantityTextBox);
|
||||
Controls.Add(WorkСomboBox);
|
||||
Controls.Add(QuantityLabel);
|
||||
Controls.Add(WorkLabel);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormSellWork";
|
||||
Text = "Продать Изделие";
|
||||
Load += FormSellWork_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label WorkLabel;
|
||||
private Label QuantityLabel;
|
||||
private ComboBox WorkСomboBox;
|
||||
private TextBox QuantityTextBox;
|
||||
private Button SaveButton;
|
||||
private Button ButtonCancel;
|
||||
}
|
||||
}
|
||||
94
PlumbingRepair/PlumbingRepair/FormSellWork.cs
Normal file
94
PlumbingRepair/PlumbingRepair/FormSellWork.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PlumbingRepairContracts.BusinessLogicsContracts;
|
||||
using PlumbingRepairContracts.SearchModels;
|
||||
|
||||
namespace PlumbingRepair
|
||||
{
|
||||
public partial class FormSellWork : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IWorkLogic _logicWork;
|
||||
private readonly IStoreLogic _logicStore;
|
||||
public FormSellWork(ILogger<FormSellWork> logger, IWorkLogic logicPackage, IStoreLogic logicStore)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicWork = logicPackage;
|
||||
_logicStore = logicStore;
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void FormSellWork_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
_logger.LogInformation("Loading works for sale.");
|
||||
|
||||
try
|
||||
{
|
||||
var list = _logicWork.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
WorkСomboBox.DisplayMember = "WorkName";
|
||||
WorkСomboBox.ValueMember = "Id";
|
||||
WorkСomboBox.DataSource = list;
|
||||
WorkСomboBox.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "List loading error.");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(QuantityTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Укажите количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (WorkСomboBox.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Work sale.");
|
||||
|
||||
try
|
||||
{
|
||||
var operationResult = _logicStore.SellWork(_logicWork.ReadElement(new WorkSearchModel()
|
||||
{
|
||||
Id = Convert.ToInt32(WorkСomboBox.SelectedValue)
|
||||
})!, Convert.ToInt32(QuantityTextBox.Text));
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при продаже изделия. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Work sale error.");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
60
PlumbingRepair/PlumbingRepair/FormSellWork.resx
Normal file
60
PlumbingRepair/PlumbingRepair/FormSellWork.resx
Normal 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>
|
||||
215
PlumbingRepair/PlumbingRepair/FormStore.Designer.cs
generated
Normal file
215
PlumbingRepair/PlumbingRepair/FormStore.Designer.cs
generated
Normal file
@@ -0,0 +1,215 @@
|
||||
namespace PlumbingRepair
|
||||
{
|
||||
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()
|
||||
{
|
||||
StoreNameLabel = new Label();
|
||||
StoreAdressLabel = new Label();
|
||||
OpeningDateLabel = new Label();
|
||||
NameTextBox = new TextBox();
|
||||
AdressTextBox = new TextBox();
|
||||
DataGridView = new DataGridView();
|
||||
WorkName = new DataGridViewTextBoxColumn();
|
||||
WorkPrice = new DataGridViewTextBoxColumn();
|
||||
WorkCount = new DataGridViewTextBoxColumn();
|
||||
SaveButton = new Button();
|
||||
ButtonCancel = new Button();
|
||||
OpeningDatePicker = new DateTimePicker();
|
||||
VolumeNumericUpDown = new NumericUpDown();
|
||||
WorkMaxCountLable = new Label();
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)VolumeNumericUpDown).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// StoreNameLabel
|
||||
//
|
||||
StoreNameLabel.AutoSize = true;
|
||||
StoreNameLabel.Location = new Point(14, 12);
|
||||
StoreNameLabel.Name = "StoreNameLabel";
|
||||
StoreNameLabel.Size = new Size(154, 20);
|
||||
StoreNameLabel.TabIndex = 0;
|
||||
StoreNameLabel.Text = "Название магазина: ";
|
||||
//
|
||||
// StoreAdressLabel
|
||||
//
|
||||
StoreAdressLabel.AutoSize = true;
|
||||
StoreAdressLabel.Location = new Point(14, 53);
|
||||
StoreAdressLabel.Name = "StoreAdressLabel";
|
||||
StoreAdressLabel.Size = new Size(128, 20);
|
||||
StoreAdressLabel.TabIndex = 1;
|
||||
StoreAdressLabel.Text = "Адрес магазина: ";
|
||||
//
|
||||
// OpeningDateLabel
|
||||
//
|
||||
OpeningDateLabel.AutoSize = true;
|
||||
OpeningDateLabel.Location = new Point(14, 96);
|
||||
OpeningDateLabel.Name = "OpeningDateLabel";
|
||||
OpeningDateLabel.Size = new Size(117, 20);
|
||||
OpeningDateLabel.TabIndex = 2;
|
||||
OpeningDateLabel.Text = "Дата открытия: ";
|
||||
//
|
||||
// NameTextBox
|
||||
//
|
||||
NameTextBox.Location = new Point(157, 8);
|
||||
NameTextBox.Margin = new Padding(3, 4, 3, 4);
|
||||
NameTextBox.Name = "NameTextBox";
|
||||
NameTextBox.Size = new Size(198, 27);
|
||||
NameTextBox.TabIndex = 3;
|
||||
//
|
||||
// AdressTextBox
|
||||
//
|
||||
AdressTextBox.Location = new Point(157, 49);
|
||||
AdressTextBox.Margin = new Padding(3, 4, 3, 4);
|
||||
AdressTextBox.Name = "AdressTextBox";
|
||||
AdressTextBox.Size = new Size(198, 27);
|
||||
AdressTextBox.TabIndex = 4;
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
DataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
DataGridView.Columns.AddRange(new DataGridViewColumn[] { WorkName, WorkPrice, WorkCount });
|
||||
DataGridView.Location = new Point(14, 145);
|
||||
DataGridView.Margin = new Padding(3, 4, 3, 4);
|
||||
DataGridView.Name = "DataGridView";
|
||||
DataGridView.RowHeadersWidth = 51;
|
||||
DataGridView.RowTemplate.Height = 25;
|
||||
DataGridView.Size = new Size(887, 384);
|
||||
DataGridView.TabIndex = 6;
|
||||
//
|
||||
// WorkName
|
||||
//
|
||||
WorkName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
WorkName.HeaderText = "Название изделия";
|
||||
WorkName.MinimumWidth = 6;
|
||||
WorkName.Name = "WorkName";
|
||||
//
|
||||
// WorkPrice
|
||||
//
|
||||
WorkPrice.HeaderText = "Цена";
|
||||
WorkPrice.MinimumWidth = 6;
|
||||
WorkPrice.Name = "WorkPrice";
|
||||
WorkPrice.Width = 125;
|
||||
//
|
||||
// WorkCount
|
||||
//
|
||||
WorkCount.HeaderText = "Количество";
|
||||
WorkCount.MinimumWidth = 6;
|
||||
WorkCount.Name = "WorkCount";
|
||||
WorkCount.Width = 125;
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
SaveButton.Location = new Point(631, 537);
|
||||
SaveButton.Margin = new Padding(3, 4, 3, 4);
|
||||
SaveButton.Name = "SaveButton";
|
||||
SaveButton.Size = new Size(131, 47);
|
||||
SaveButton.TabIndex = 7;
|
||||
SaveButton.Text = "Сохранить";
|
||||
SaveButton.UseVisualStyleBackColor = true;
|
||||
SaveButton.Click += SaveButton_Click;
|
||||
//
|
||||
// ButtonCancel
|
||||
//
|
||||
ButtonCancel.Location = new Point(769, 537);
|
||||
ButtonCancel.Margin = new Padding(3, 4, 3, 4);
|
||||
ButtonCancel.Name = "ButtonCancel";
|
||||
ButtonCancel.Size = new Size(131, 47);
|
||||
ButtonCancel.TabIndex = 8;
|
||||
ButtonCancel.Text = "Отменить";
|
||||
ButtonCancel.UseVisualStyleBackColor = true;
|
||||
ButtonCancel.Click += ButtonCancel_Click;
|
||||
//
|
||||
// OpeningDatePicker
|
||||
//
|
||||
OpeningDatePicker.Location = new Point(157, 88);
|
||||
OpeningDatePicker.Margin = new Padding(3, 4, 3, 4);
|
||||
OpeningDatePicker.Name = "OpeningDatePicker";
|
||||
OpeningDatePicker.Size = new Size(198, 27);
|
||||
OpeningDatePicker.TabIndex = 9;
|
||||
//
|
||||
// VolumeNumericUpDown
|
||||
//
|
||||
VolumeNumericUpDown.Location = new Point(570, 10);
|
||||
VolumeNumericUpDown.Margin = new Padding(3, 4, 3, 4);
|
||||
VolumeNumericUpDown.Name = "VolumeNumericUpDown";
|
||||
VolumeNumericUpDown.Size = new Size(192, 27);
|
||||
VolumeNumericUpDown.TabIndex = 10;
|
||||
//
|
||||
// WorkMaxCountLable
|
||||
//
|
||||
WorkMaxCountLable.AutoSize = true;
|
||||
WorkMaxCountLable.Location = new Point(389, 12);
|
||||
WorkMaxCountLable.Name = "WorkMaxCountLable";
|
||||
WorkMaxCountLable.Size = new Size(177, 20);
|
||||
WorkMaxCountLable.TabIndex = 11;
|
||||
WorkMaxCountLable.Text = "Вместимость магазина: ";
|
||||
//
|
||||
// FormStore
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(914, 600);
|
||||
Controls.Add(WorkMaxCountLable);
|
||||
Controls.Add(VolumeNumericUpDown);
|
||||
Controls.Add(OpeningDatePicker);
|
||||
Controls.Add(ButtonCancel);
|
||||
Controls.Add(SaveButton);
|
||||
Controls.Add(DataGridView);
|
||||
Controls.Add(AdressTextBox);
|
||||
Controls.Add(NameTextBox);
|
||||
Controls.Add(OpeningDateLabel);
|
||||
Controls.Add(StoreAdressLabel);
|
||||
Controls.Add(StoreNameLabel);
|
||||
Margin = new Padding(3, 4, 3, 4);
|
||||
Name = "FormStore";
|
||||
Text = "Изделия магазина";
|
||||
Load += FormStore_Load;
|
||||
((System.ComponentModel.ISupportInitialize)DataGridView).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)VolumeNumericUpDown).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label StoreNameLabel;
|
||||
private Label StoreAdressLabel;
|
||||
private Label OpeningDateLabel;
|
||||
private TextBox NameTextBox;
|
||||
private TextBox AdressTextBox;
|
||||
private DataGridView DataGridView;
|
||||
private Button SaveButton;
|
||||
private Button ButtonCancel;
|
||||
private DataGridViewTextBoxColumn WorkName;
|
||||
private DataGridViewTextBoxColumn WorkPrice;
|
||||
private DataGridViewTextBoxColumn WorkCount;
|
||||
private DateTimePicker OpeningDatePicker;
|
||||
private NumericUpDown VolumeNumericUpDown;
|
||||
private Label WorkMaxCountLable;
|
||||
}
|
||||
}
|
||||
124
PlumbingRepair/PlumbingRepair/FormStore.cs
Normal file
124
PlumbingRepair/PlumbingRepair/FormStore.cs
Normal file
@@ -0,0 +1,124 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.BusinessLogicsContracts;
|
||||
using PlumbingRepairContracts.SearchModels;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDataModels.Models;
|
||||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace PlumbingRepair
|
||||
{
|
||||
public partial class FormStore : Form
|
||||
{
|
||||
private readonly IStoreLogic _logic;
|
||||
private readonly ILogger _logger;
|
||||
private int? _id;
|
||||
private Dictionary<int, (IWorkModel, int)> _listStores;
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormStore(ILogger<FormStore> logger, IStoreLogic logic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_listStores = new();
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(NameTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(AdressTextBox.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Сохранение магазина");
|
||||
try
|
||||
{
|
||||
var model = new StoreBindingModel
|
||||
{
|
||||
Id = _id ?? 0,
|
||||
StoreName = NameTextBox.Text,
|
||||
StoreAdress = AdressTextBox.Text,
|
||||
OpeningDate = DateTime.SpecifyKind(OpeningDatePicker.Value.Date, DateTimeKind.Utc),
|
||||
WorkMaxCount = (int)VolumeNumericUpDown.Value,
|
||||
StoreWorks = _listStores
|
||||
};
|
||||
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();
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
private void FormStore_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (_id.HasValue)
|
||||
{
|
||||
_logger.LogInformation("Загрузка магазина");
|
||||
try
|
||||
{
|
||||
var view = _logic.ReadElement(new StoreSearchModel
|
||||
{
|
||||
Id = _id.Value
|
||||
});
|
||||
if (view != null)
|
||||
{
|
||||
NameTextBox.Text = view.StoreName;
|
||||
AdressTextBox.Text = view.StoreAdress;
|
||||
OpeningDatePicker.Text = view.OpeningDate.ToString();
|
||||
VolumeNumericUpDown.Value = view.WorkMaxCount;
|
||||
_listStores = view.StoreWorks ?? new Dictionary<int, (IWorkModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки магазина");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void LoadData(bool extendDate = true)
|
||||
{
|
||||
_logger.LogInformation("Загрузка изделий магазина");
|
||||
try
|
||||
{
|
||||
if (_listStores != null)
|
||||
{
|
||||
DataGridView.Rows.Clear();
|
||||
foreach (var elem in _listStores)
|
||||
{
|
||||
DataGridView.Rows.Add(new object[] { elem.Value.Item1.WorkName, elem.Value.Item1.Price, elem.Value.Item2 });
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки изделий магазина");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
PlumbingRepair/PlumbingRepair/FormStore.resx
Normal file
60
PlumbingRepair/PlumbingRepair/FormStore.resx
Normal 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>
|
||||
148
PlumbingRepair/PlumbingRepair/FormStoreReplenishment.Designer.cs
generated
Normal file
148
PlumbingRepair/PlumbingRepair/FormStoreReplenishment.Designer.cs
generated
Normal file
@@ -0,0 +1,148 @@
|
||||
namespace PlumbingRepair
|
||||
{
|
||||
partial class FormStoreReplenishment
|
||||
{
|
||||
/// <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.StoreNameLabel = new System.Windows.Forms.Label();
|
||||
this.WorkNameLabel = new System.Windows.Forms.Label();
|
||||
this.CountLabel = new System.Windows.Forms.Label();
|
||||
this.StoreNameComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.WorkNameComboBox = new System.Windows.Forms.ComboBox();
|
||||
this.CountTextBox = new System.Windows.Forms.TextBox();
|
||||
this.SaveButton = new System.Windows.Forms.Button();
|
||||
this.ButtonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// StoreNameLabel
|
||||
//
|
||||
this.StoreNameLabel.AutoSize = true;
|
||||
this.StoreNameLabel.Location = new System.Drawing.Point(14, 12);
|
||||
this.StoreNameLabel.Name = "StoreNameLabel";
|
||||
this.StoreNameLabel.Size = new System.Drawing.Size(154, 20);
|
||||
this.StoreNameLabel.TabIndex = 0;
|
||||
this.StoreNameLabel.Text = "Название магазина: ";
|
||||
//
|
||||
// WorkNameLabel
|
||||
//
|
||||
this.WorkNameLabel.AutoSize = true;
|
||||
this.WorkNameLabel.Location = new System.Drawing.Point(14, 49);
|
||||
this.WorkNameLabel.Name = "WorkNameLabel";
|
||||
this.WorkNameLabel.Size = new System.Drawing.Size(145, 20);
|
||||
this.WorkNameLabel.TabIndex = 1;
|
||||
this.WorkNameLabel.Text = "Название изделия: ";
|
||||
//
|
||||
// CountLabel
|
||||
//
|
||||
this.CountLabel.AutoSize = true;
|
||||
this.CountLabel.Location = new System.Drawing.Point(14, 88);
|
||||
this.CountLabel.Name = "CountLabel";
|
||||
this.CountLabel.Size = new System.Drawing.Size(97, 20);
|
||||
this.CountLabel.TabIndex = 2;
|
||||
this.CountLabel.Text = "Количество: ";
|
||||
//
|
||||
// StoreNameComboBox
|
||||
//
|
||||
this.StoreNameComboBox.FormattingEnabled = true;
|
||||
this.StoreNameComboBox.Location = new System.Drawing.Point(157, 8);
|
||||
this.StoreNameComboBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.StoreNameComboBox.Name = "StoreNameComboBox";
|
||||
this.StoreNameComboBox.Size = new System.Drawing.Size(170, 28);
|
||||
this.StoreNameComboBox.TabIndex = 3;
|
||||
//
|
||||
// WorkNameComboBox
|
||||
//
|
||||
this.WorkNameComboBox.FormattingEnabled = true;
|
||||
this.WorkNameComboBox.Location = new System.Drawing.Point(157, 47);
|
||||
this.WorkNameComboBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.WorkNameComboBox.Name = "WorkNameComboBox";
|
||||
this.WorkNameComboBox.Size = new System.Drawing.Size(170, 28);
|
||||
this.WorkNameComboBox.TabIndex = 4;
|
||||
//
|
||||
// CountTextBox
|
||||
//
|
||||
this.CountTextBox.Location = new System.Drawing.Point(157, 85);
|
||||
this.CountTextBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.CountTextBox.Name = "CountTextBox";
|
||||
this.CountTextBox.Size = new System.Drawing.Size(170, 27);
|
||||
this.CountTextBox.TabIndex = 5;
|
||||
//
|
||||
// SaveButton
|
||||
//
|
||||
this.SaveButton.Location = new System.Drawing.Point(138, 144);
|
||||
this.SaveButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.SaveButton.Name = "SaveButton";
|
||||
this.SaveButton.Size = new System.Drawing.Size(97, 31);
|
||||
this.SaveButton.TabIndex = 6;
|
||||
this.SaveButton.Text = "Сохранить";
|
||||
this.SaveButton.UseVisualStyleBackColor = true;
|
||||
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
|
||||
//
|
||||
// ButtonCancel
|
||||
//
|
||||
this.ButtonCancel.Location = new System.Drawing.Point(241, 144);
|
||||
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.ButtonCancel.Name = "ButtonCancel";
|
||||
this.ButtonCancel.Size = new System.Drawing.Size(86, 31);
|
||||
this.ButtonCancel.TabIndex = 7;
|
||||
this.ButtonCancel.Text = "Отмена";
|
||||
this.ButtonCancel.UseVisualStyleBackColor = true;
|
||||
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||
//
|
||||
// FormStoreReplenishment
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(343, 200);
|
||||
this.Controls.Add(this.ButtonCancel);
|
||||
this.Controls.Add(this.SaveButton);
|
||||
this.Controls.Add(this.CountTextBox);
|
||||
this.Controls.Add(this.WorkNameComboBox);
|
||||
this.Controls.Add(this.StoreNameComboBox);
|
||||
this.Controls.Add(this.CountLabel);
|
||||
this.Controls.Add(this.WorkNameLabel);
|
||||
this.Controls.Add(this.StoreNameLabel);
|
||||
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
|
||||
this.Name = "FormStoreReplenishment";
|
||||
this.Text = "Пополнение магазина";
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private Label StoreNameLabel;
|
||||
private Label WorkNameLabel;
|
||||
private Label CountLabel;
|
||||
private ComboBox StoreNameComboBox;
|
||||
private ComboBox WorkNameComboBox;
|
||||
private TextBox CountTextBox;
|
||||
private Button SaveButton;
|
||||
private Button ButtonCancel;
|
||||
}
|
||||
}
|
||||
104
PlumbingRepair/PlumbingRepair/FormStoreReplenishment.cs
Normal file
104
PlumbingRepair/PlumbingRepair/FormStoreReplenishment.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PlumbingRepairContracts.BusinessLogicsContracts;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace PlumbingRepair
|
||||
{
|
||||
public partial class FormStoreReplenishment : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStoreLogic _storeLogic;
|
||||
private readonly IWorkLogic _workLogic;
|
||||
private readonly List<StoreViewModel>? _listStores;
|
||||
private readonly List<WorkViewModel>? _listWorks;
|
||||
public FormStoreReplenishment(ILogger<FormStoreReplenishment> logger, IStoreLogic storeLogic, IWorkLogic workLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_storeLogic = storeLogic;
|
||||
_workLogic = workLogic;
|
||||
_logger = logger;
|
||||
_listStores = storeLogic.ReadList(null);
|
||||
if (_listStores != null)
|
||||
{
|
||||
StoreNameComboBox.DisplayMember = "StoreName";
|
||||
StoreNameComboBox.ValueMember = "Id";
|
||||
StoreNameComboBox.DataSource = _listStores;
|
||||
StoreNameComboBox.SelectedItem = null;
|
||||
}
|
||||
|
||||
_listWorks = workLogic.ReadList(null);
|
||||
if (_listWorks != null)
|
||||
{
|
||||
WorkNameComboBox.DisplayMember = "WorkName";
|
||||
WorkNameComboBox.ValueMember = "Id";
|
||||
WorkNameComboBox.DataSource = _listWorks;
|
||||
WorkNameComboBox.SelectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (StoreNameComboBox.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (WorkNameComboBox.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Добавление изделия в магазин");
|
||||
|
||||
try
|
||||
{
|
||||
var work = _workLogic.ReadElement(new()
|
||||
{
|
||||
Id = (int)WorkNameComboBox.SelectedValue
|
||||
});
|
||||
|
||||
if (work == null)
|
||||
{
|
||||
throw new Exception("Не найдено изделие. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
var resultOperation = _storeLogic.AddWork(
|
||||
model: new() { Id = (int)StoreNameComboBox.SelectedValue },
|
||||
work: work,
|
||||
quantity: Convert.ToInt32(CountTextBox.Text)
|
||||
);
|
||||
|
||||
if (!resultOperation)
|
||||
{
|
||||
throw new Exception("Ошибка при добавлении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения изделия");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
60
PlumbingRepair/PlumbingRepair/FormStoreReplenishment.resx
Normal file
60
PlumbingRepair/PlumbingRepair/FormStoreReplenishment.resx
Normal 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>
|
||||
114
PlumbingRepair/PlumbingRepair/FormStores.Designer.cs
generated
Normal file
114
PlumbingRepair/PlumbingRepair/FormStores.Designer.cs
generated
Normal file
@@ -0,0 +1,114 @@
|
||||
namespace PlumbingRepair
|
||||
{
|
||||
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()
|
||||
{
|
||||
this.DataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.AddButton = new System.Windows.Forms.Button();
|
||||
this.ChangeButton = new System.Windows.Forms.Button();
|
||||
this.DeleteButton = new System.Windows.Forms.Button();
|
||||
this.UpdateButton = new System.Windows.Forms.Button();
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// DataGridView
|
||||
//
|
||||
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.DataGridView.Location = new System.Drawing.Point(1, 1);
|
||||
this.DataGridView.Name = "DataGridView";
|
||||
this.DataGridView.RowTemplate.Height = 25;
|
||||
this.DataGridView.Size = new System.Drawing.Size(550, 447);
|
||||
this.DataGridView.TabIndex = 0;
|
||||
//
|
||||
// AddButton
|
||||
//
|
||||
this.AddButton.Location = new System.Drawing.Point(585, 12);
|
||||
this.AddButton.Name = "AddButton";
|
||||
this.AddButton.Size = new System.Drawing.Size(121, 40);
|
||||
this.AddButton.TabIndex = 1;
|
||||
this.AddButton.Text = "Добавить";
|
||||
this.AddButton.UseVisualStyleBackColor = true;
|
||||
this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
|
||||
//
|
||||
// ChangeButton
|
||||
//
|
||||
this.ChangeButton.Location = new System.Drawing.Point(585, 67);
|
||||
this.ChangeButton.Name = "ChangeButton";
|
||||
this.ChangeButton.Size = new System.Drawing.Size(121, 40);
|
||||
this.ChangeButton.TabIndex = 2;
|
||||
this.ChangeButton.Text = "Изменить";
|
||||
this.ChangeButton.UseVisualStyleBackColor = true;
|
||||
this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click);
|
||||
//
|
||||
// DeleteButton
|
||||
//
|
||||
this.DeleteButton.Location = new System.Drawing.Point(585, 122);
|
||||
this.DeleteButton.Name = "DeleteButton";
|
||||
this.DeleteButton.Size = new System.Drawing.Size(121, 40);
|
||||
this.DeleteButton.TabIndex = 3;
|
||||
this.DeleteButton.Text = "Удалить";
|
||||
this.DeleteButton.UseVisualStyleBackColor = true;
|
||||
this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
|
||||
//
|
||||
// UpdateButton
|
||||
//
|
||||
this.UpdateButton.Location = new System.Drawing.Point(585, 179);
|
||||
this.UpdateButton.Name = "UpdateButton";
|
||||
this.UpdateButton.Size = new System.Drawing.Size(121, 40);
|
||||
this.UpdateButton.TabIndex = 4;
|
||||
this.UpdateButton.Text = "Обновить";
|
||||
this.UpdateButton.UseVisualStyleBackColor = true;
|
||||
this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
|
||||
//
|
||||
// FormStores
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(718, 450);
|
||||
this.Controls.Add(this.UpdateButton);
|
||||
this.Controls.Add(this.DeleteButton);
|
||||
this.Controls.Add(this.ChangeButton);
|
||||
this.Controls.Add(this.AddButton);
|
||||
this.Controls.Add(this.DataGridView);
|
||||
this.Name = "FormStores";
|
||||
this.Text = "Магазины";
|
||||
this.Load += new System.EventHandler(this.FormStores_Load);
|
||||
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private DataGridView DataGridView;
|
||||
private Button AddButton;
|
||||
private Button ChangeButton;
|
||||
private Button DeleteButton;
|
||||
private Button UpdateButton;
|
||||
}
|
||||
}
|
||||
113
PlumbingRepair/PlumbingRepair/FormStores.cs
Normal file
113
PlumbingRepair/PlumbingRepair/FormStores.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace PlumbingRepair
|
||||
{
|
||||
public partial class FormStores : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStoreLogic _logic;
|
||||
public FormStores(ILogger<FormStores> 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["StoreWorks"].Visible = false;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Загрузка магазинов");
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки магазинов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void DeleteButton_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 ChangeButton_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 AddButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormStore));
|
||||
|
||||
if (service is FormStore form)
|
||||
{
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
120
PlumbingRepair/PlumbingRepair/FormStores.resx
Normal file
120
PlumbingRepair/PlumbingRepair/FormStores.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<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>
|
||||
@@ -14,6 +14,7 @@ namespace PlumbingRepair
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void FormComponents_Load(object sender, EventArgs e)
|
||||
|
||||
@@ -9,11 +9,16 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PlumbingRepairBusinessLogic\PlumbingRepairBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\PlumbingRepairDatabaseImplement\PlumbingRepairDatabaseImplement.csproj" />
|
||||
<ProjectReference Include="..\PlumbingRepairListImplement\PlumbingRepairListImplement.csproj" />
|
||||
<ProjectReference Include="..\PlumpingRepairFileImplement\PlumbingRepairFileImplement.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using PlumbingRepairContracts.BusinessLogicsContracts;
|
||||
using PlumbingRepairContracts.StoragesContracts;
|
||||
using PlumbingRepairFileImplement.Implements;
|
||||
using PlumbingRepairDatabaseImplement.Implements;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog.Extensions.Logging;
|
||||
@@ -24,7 +24,7 @@ namespace PlumbingRepair
|
||||
ApplicationConfiguration.Initialize();
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
@@ -37,9 +37,11 @@ namespace PlumbingRepair
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<IWorkStorage, WorkStorage>();
|
||||
services.AddTransient<IStoreStorage, StoreStorage>();
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<IWorkLogic, WorkLogic>();
|
||||
services.AddTransient<IStoreLogic, StoreLogic>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormComponents>();
|
||||
@@ -47,6 +49,10 @@ namespace PlumbingRepair
|
||||
services.AddTransient<FormWork>();
|
||||
services.AddTransient<FormWorkComponent>();
|
||||
services.AddTransient<FormWorks>();
|
||||
services.AddTransient<FormStores>();
|
||||
services.AddTransient<FormStore>();
|
||||
services.AddTransient<FormStoreReplenishment>();
|
||||
services.AddTransient<FormSellWork>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,123 +8,152 @@ using PlumbingRepairDataModels.Enums;
|
||||
|
||||
namespace PlumbingRepairBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
public class OrderLogic : IOrderLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IStoreLogic _storeLogic;
|
||||
private readonly IWorkStorage _workStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
}
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IWorkStorage workStorage, IStoreLogic storeLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_storeLogic = storeLogic;
|
||||
_workStorage = workStorage;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
||||
if (model.Status != OrderStatus.Неизвестен)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
if (model.Status != OrderStatus.Неизвестен)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
|
||||
model.Status = OrderStatus.Принят;
|
||||
model.Status = OrderStatus.Принят;
|
||||
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
model.Status = OrderStatus.Неизвестен;
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
model.Status = OrderStatus.Неизвестен;
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
||||
{
|
||||
CheckModel(model);
|
||||
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
||||
{
|
||||
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
|
||||
if (model.Status + 1 != newStatus)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
if (viewModel == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
model.Status = newStatus;
|
||||
if (viewModel.Status + 1 != newStatus)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
model.DateImplement = DateTime.Now;
|
||||
model.Status = newStatus;
|
||||
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
model.Status--;
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
if (model.Status == OrderStatus.Готов)
|
||||
{
|
||||
model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||
|
||||
return true;
|
||||
}
|
||||
var work = _workStorage.GetElement(new() { Id = viewModel.WorkId });
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Выполняется);
|
||||
}
|
||||
if (work == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(work));
|
||||
}
|
||||
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Готов);
|
||||
}
|
||||
if (!_storeLogic.AddWork(work, viewModel.Count))
|
||||
{
|
||||
throw new Exception($"AddWork operation failed. Store is full.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
model.DateImplement = viewModel.DateImplement;
|
||||
}
|
||||
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Выдан);
|
||||
}
|
||||
CheckModel(model, false);
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("Order. OrderId:{Id}", model?.Id);
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
model.Status--;
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Выполняется);
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public bool DeliveryOrder(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Готов);
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
public bool FinishOrder(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Выдан);
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("Order. OrderId:{Id}", model?.Id);
|
||||
|
||||
if (model.WorkId < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.WorkId));
|
||||
}
|
||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count));
|
||||
}
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (model.Sum <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
|
||||
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.WorkId);
|
||||
}
|
||||
}
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (model.WorkId < 0)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.WorkId));
|
||||
}
|
||||
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count));
|
||||
}
|
||||
|
||||
if (model.Sum <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.WorkId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.BusinessLogicsContracts;
|
||||
using PlumbingRepairContracts.SearchModels;
|
||||
using PlumbingRepairContracts.StoragesContracts;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDataModels.Models;
|
||||
|
||||
namespace PlumbingRepairBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class StoreLogic : IStoreLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStoreStorage _storeStorage;
|
||||
public StoreLogic(ILogger<StoreLogic> logger, IStoreStorage storeStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_storeStorage = storeStorage;
|
||||
}
|
||||
public bool AddWork(StoreSearchModel model, IWorkModel work, int quantity)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
if (quantity <= 0)
|
||||
{
|
||||
throw new ArgumentException("Количество изделий должно быть больше 0", nameof(quantity));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddWork. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id);
|
||||
var element = _storeStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("AddWork element not found");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (element.WorkMaxCount - element.StoreWorks.Select(x => x.Value.Item2).Sum() < quantity)
|
||||
{
|
||||
throw new ArgumentNullException("Магазин переполнен", nameof(quantity));
|
||||
}
|
||||
|
||||
_logger.LogInformation("AddWork find. Id:{Id}", element.Id);
|
||||
|
||||
if (element.StoreWorks.TryGetValue(work.Id, out var pair))
|
||||
{
|
||||
element.StoreWorks[work.Id] = (work, quantity + pair.Item2);
|
||||
_logger.LogInformation("AddWork. Added {quantity} {work} to '{StoreName}' store", quantity, work.WorkName, element.StoreName);
|
||||
}
|
||||
else
|
||||
{
|
||||
element.StoreWorks[work.Id] = (work, quantity);
|
||||
_logger.LogInformation("AddWork. Added {quantity} new work {work} to '{StoreName}' store", quantity, work.WorkName, element.StoreName);
|
||||
}
|
||||
|
||||
_storeStorage.Update(new()
|
||||
{
|
||||
Id = element.Id,
|
||||
StoreAdress = element.StoreAdress,
|
||||
StoreName = element.StoreName,
|
||||
OpeningDate = element.OpeningDate,
|
||||
WorkMaxCount = element.WorkMaxCount,
|
||||
StoreWorks = element.StoreWorks
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool AddWork(IWorkModel work, int quantity)
|
||||
{
|
||||
if (work == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(work));
|
||||
}
|
||||
|
||||
if (quantity <= 0)
|
||||
{
|
||||
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(quantity));
|
||||
}
|
||||
|
||||
var freePlaces = _storeStorage.GetFullList()
|
||||
.Select(x => x.WorkMaxCount - x.StoreWorks
|
||||
.Select(p => p.Value.Item2).Sum()).Sum() - quantity;
|
||||
|
||||
if (freePlaces < 0)
|
||||
{
|
||||
_logger.LogInformation("AddWork. Failed to add work to store. It's full.");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var store in _storeStorage.GetFullList())
|
||||
{
|
||||
var temp = Math.Min(quantity, store.WorkMaxCount - store.StoreWorks.Select(x => x.Value.Item2).Sum());
|
||||
|
||||
if (temp <= 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!AddWork(new() { Id = store.Id }, work, temp))
|
||||
{
|
||||
_logger.LogWarning("An error occurred while adding work to stores");
|
||||
return false;
|
||||
}
|
||||
|
||||
quantity -= temp;
|
||||
|
||||
if (quantity == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool Create(StoreBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
model.StoreWorks = new();
|
||||
|
||||
if (_storeStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert 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;
|
||||
}
|
||||
|
||||
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 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 bool SellWork(IWorkModel work, int quantity)
|
||||
{
|
||||
return _storeStorage.SellWork(work, quantity);
|
||||
}
|
||||
|
||||
public bool Update(StoreBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
|
||||
if (string.IsNullOrEmpty(model.StoreName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия магазина", nameof(model.StoreName));
|
||||
}
|
||||
|
||||
if (_storeStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
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 (model.WorkMaxCount < 0)
|
||||
{
|
||||
throw new ArgumentException("Максимальное количество изделий в магазине не может быть меньше нуля", nameof(model.WorkMaxCount));
|
||||
}
|
||||
|
||||
_logger.LogInformation("Store. StoreName:{0}.StoreAdress:{1}. Id: {2}", model.StoreName, model.StoreAdress, model.Id);
|
||||
|
||||
var element = _storeStorage.GetElement(new StoreSearchModel
|
||||
{
|
||||
StoreName = model.StoreName
|
||||
});
|
||||
|
||||
if (element != null && element.Id != model.Id && element.StoreName == model.StoreName)
|
||||
{
|
||||
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace PlumbingRepairContracts.BindingModels
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
||||
public DateTime? DateImplement { get; set; }
|
||||
public string WorkName { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using PlumbingRepairDataModels.Models;
|
||||
|
||||
namespace PlumbingRepairContracts.BindingModels
|
||||
{
|
||||
public class StoreBindingModel : IStoreModel
|
||||
{
|
||||
public string StoreName { get; set; } = string.Empty;
|
||||
public string StoreAdress { get; set; } = string.Empty;
|
||||
|
||||
public DateTime OpeningDate { get; set; }
|
||||
|
||||
public Dictionary<int, (IWorkModel, int)> StoreWorks { get; set; } = new();
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public int WorkMaxCount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.SearchModels;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDataModels.Models;
|
||||
|
||||
namespace PlumbingRepairContracts.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);
|
||||
bool AddWork(StoreSearchModel model, IWorkModel work, int quantity);
|
||||
bool AddWork(IWorkModel package, int quantity);
|
||||
bool SellWork(IWorkModel package, int quantity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PlumbingRepairContracts.SearchModels
|
||||
{
|
||||
public class StoreSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? StoreName { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.SearchModels;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDataModels.Models;
|
||||
|
||||
namespace PlumbingRepairContracts.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);
|
||||
bool SellWork(IWorkModel model, int quantity);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using PlumbingRepairDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace PlumbingRepairContracts.ViewModels
|
||||
{
|
||||
public class StoreViewModel : IStoreModel
|
||||
{
|
||||
public Dictionary<int, (IWorkModel, int)> StoreWorks { get; set; } = new();
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Название магазина")]
|
||||
public string StoreName { get; set; } = string.Empty;
|
||||
[DisplayName("Адрес магазина")]
|
||||
public string StoreAdress { get; set; } = string.Empty;
|
||||
[DisplayName("Дата открытия")]
|
||||
public DateTime OpeningDate { get; set; }
|
||||
[DisplayName("Вместимость магазина")]
|
||||
public int WorkMaxCount { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace PlumbingRepairDataModels.Models
|
||||
{
|
||||
public interface IStoreModel : IId
|
||||
{
|
||||
public string StoreName { get; }
|
||||
public string StoreAdress { get; }
|
||||
DateTime OpeningDate { get; }
|
||||
Dictionary<int, (IWorkModel, int)> StoreWorks { get; }
|
||||
public int WorkMaxCount { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.SearchModels;
|
||||
using PlumbingRepairContracts.StoragesContracts;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDatabaseImplement.Models;
|
||||
|
||||
namespace PlumbingRepairDatabaseImplement.Implements
|
||||
{
|
||||
public class ComponentStorage : IComponentStorage
|
||||
{
|
||||
public List<ComponentViewModel> GetFullList()
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
return context.Components.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
return context.Components.Where(x => x.ComponentName.Contains(model.ComponentName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
return context.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||
{
|
||||
var newComponent = Component.Create(model);
|
||||
|
||||
if (newComponent == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
context.Components.Add(newComponent);
|
||||
context.SaveChanges();
|
||||
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
var component = context.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (component == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
component.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return component.GetViewModel;
|
||||
}
|
||||
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
var element = context.Components.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Components.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.SearchModels;
|
||||
using PlumbingRepairContracts.StoragesContracts;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDatabaseImplement.Models;
|
||||
|
||||
namespace PlumbingRepairDatabaseImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
return context.Orders.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
return context.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
return context.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
var newOrder = Order.Create(model);
|
||||
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
|
||||
return newOrder.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
order.Update(model);
|
||||
context.SaveChanges();
|
||||
|
||||
return order.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Orders.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.SearchModels;
|
||||
using PlumbingRepairContracts.StoragesContracts;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDatabaseImplement.Models;
|
||||
using PlumbingRepairDataModels.Models;
|
||||
|
||||
namespace PlumbingRepairDatabaseImplement.Implements
|
||||
{
|
||||
public class StoreStorage : IStoreStorage
|
||||
{
|
||||
public StoreViewModel? Delete(StoreBindingModel model)
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
var element = context.Stores
|
||||
.Include(x => x.Works)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Stores.Remove(element);
|
||||
context.SaveChanges();
|
||||
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public StoreViewModel? GetElement(StoreSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.StoreName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
return context.Stores
|
||||
.Include(x => x.Works)
|
||||
.ThenInclude(x => x.Work)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.StoreName) && x.StoreName == model.StoreName) || (model.Id.HasValue && x.Id == model.Id))
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<StoreViewModel> GetFilteredList(StoreSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.StoreName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
return context.Stores
|
||||
.Include(x => x.Works)
|
||||
.ThenInclude(x => x.Work)
|
||||
.Where(x => x.StoreName.Contains(model.StoreName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<StoreViewModel> GetFullList()
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
return context.Stores
|
||||
.Include(x => x.Works)
|
||||
.ThenInclude(x => x.Work)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public StoreViewModel? Insert(StoreBindingModel model)
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
var newStore = Store.Create(context, model);
|
||||
if (newStore == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
context.Stores.Add(newStore);
|
||||
context.SaveChanges();
|
||||
return newStore.GetViewModel;
|
||||
}
|
||||
|
||||
public bool SellWork(IWorkModel model, int quantity)
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
foreach (var store in context.Stores
|
||||
.Include(x => x.Works)
|
||||
.ThenInclude(x => x.Work)
|
||||
.ToList()
|
||||
.Where(x => x.StoreWorks.ContainsKey(model.Id)))
|
||||
{
|
||||
int countInCurrentStore = store.StoreWorks[model.Id].Item2;
|
||||
if (countInCurrentStore <= quantity)
|
||||
{
|
||||
var elem = context.StoreWorks
|
||||
.Where(x => x.WorkId == model.Id)
|
||||
.FirstOrDefault(x => x.StoreId == store.Id);
|
||||
context.StoreWorks.Remove(elem);
|
||||
store.StoreWorks.Remove(model.Id);
|
||||
quantity -= countInCurrentStore;
|
||||
}
|
||||
else
|
||||
{
|
||||
store.StoreWorks[model.Id] = (store.StoreWorks[model.Id].Item1, countInCurrentStore - quantity);
|
||||
quantity = 0;
|
||||
store.UpdateWorks(context, new()
|
||||
{
|
||||
Id = store.Id,
|
||||
StoreWorks = store.StoreWorks,
|
||||
});
|
||||
}
|
||||
if (quantity == 0)
|
||||
{
|
||||
context.SaveChanges();
|
||||
transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
transaction.Rollback();
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public StoreViewModel? Update(StoreBindingModel model)
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var store = context.Stores.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (store == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
store.Update(model);
|
||||
context.SaveChanges();
|
||||
store.UpdateWorks(context, model);
|
||||
transaction.Commit();
|
||||
return store.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.SearchModels;
|
||||
using PlumbingRepairContracts.StoragesContracts;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDatabaseImplement.Models;
|
||||
|
||||
namespace PlumbingRepairDatabaseImplement.Implements
|
||||
{
|
||||
public class WorkStorage : IWorkStorage
|
||||
{
|
||||
public List<WorkViewModel> GetFullList()
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
return context.Works
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<WorkViewModel> GetFilteredList(WorkSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.WorkName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
return context.Works
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.Where(x => x.WorkName.Contains(model.WorkName))
|
||||
.ToList()
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public WorkViewModel? GetElement(WorkSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.WorkName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
return context.Works
|
||||
.Include(x => x.Components)
|
||||
.ThenInclude(x => x.Component)
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkName) && x.WorkName == model.WorkName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public WorkViewModel? Insert(WorkBindingModel model)
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
var newWork = Work.Create(context, model);
|
||||
|
||||
if (newWork == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
context.Works.Add(newWork);
|
||||
context.SaveChanges();
|
||||
|
||||
return newWork.GetViewModel;
|
||||
}
|
||||
|
||||
public WorkViewModel? Update(WorkBindingModel model)
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
|
||||
try
|
||||
{
|
||||
var package = context.Works.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (package == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
package.Update(model);
|
||||
context.SaveChanges();
|
||||
package.UpdateComponents(context, model);
|
||||
transaction.Commit();
|
||||
|
||||
return package.GetViewModel;
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public WorkViewModel? Delete(WorkBindingModel model)
|
||||
{
|
||||
using var context = new PlumbingRepairDataBase();
|
||||
|
||||
var element = context.Works.Include(x => x.Components).FirstOrDefault(rec => rec.Id == model.Id);
|
||||
|
||||
if (element != null)
|
||||
{
|
||||
context.Works.Remove(element);
|
||||
context.SaveChanges();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
252
PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230428142925_CreateDB.Designer.cs
generated
Normal file
252
PlumbingRepair/PlumbingRepairDatabaseImplement/Migrations/20230428142925_CreateDB.Designer.cs
generated
Normal file
@@ -0,0 +1,252 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using PlumbingRepairDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PlumbingRepairDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(PlumbingRepairDataBase))]
|
||||
[Migration("20230428142925_CreateDB")]
|
||||
partial class CreateDB
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int>("WorkId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("WorkName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorkId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Store", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("OpeningDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("StoreAdress")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("StoreName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("WorkMaxCount")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Stores");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.StoreWork", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("StoreId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("WorkId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("StoreId");
|
||||
|
||||
b.HasIndex("WorkId");
|
||||
|
||||
b.ToTable("StoreWorks");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Work", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("WorkName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Works");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.WorkComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("WorkId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("WorkId");
|
||||
|
||||
b.ToTable("WorkComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("PlumbingRepairDatabaseImplement.Models.Work", "Work")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("WorkId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Work");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.StoreWork", b =>
|
||||
{
|
||||
b.HasOne("PlumbingRepairDatabaseImplement.Models.Store", "Store")
|
||||
.WithMany("Works")
|
||||
.HasForeignKey("StoreId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PlumbingRepairDatabaseImplement.Models.Work", "Work")
|
||||
.WithMany()
|
||||
.HasForeignKey("WorkId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Store");
|
||||
|
||||
b.Navigation("Work");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.WorkComponent", b =>
|
||||
{
|
||||
b.HasOne("PlumbingRepairDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("WorkComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PlumbingRepairDatabaseImplement.Models.Work", "Work")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("WorkId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Work");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("WorkComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Store", b =>
|
||||
{
|
||||
b.Navigation("Works");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Work", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PlumbingRepairDatabaseImplement.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class CreateDB : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
ComponentName = table.Column<string>(type: "text", nullable: false),
|
||||
Cost = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Stores",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
StoreName = table.Column<string>(type: "text", nullable: false),
|
||||
StoreAdress = table.Column<string>(type: "text", nullable: false),
|
||||
OpeningDate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
WorkMaxCount = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Stores", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Works",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
WorkName = table.Column<string>(type: "text", nullable: false),
|
||||
Price = table.Column<double>(type: "double precision", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Works", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
WorkId = table.Column<int>(type: "integer", nullable: false),
|
||||
WorkName = table.Column<string>(type: "text", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false),
|
||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
||||
Status = table.Column<int>(type: "integer", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
||||
DateImplement = table.Column<DateTime>(type: "timestamp with time zone", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Works_WorkId",
|
||||
column: x => x.WorkId,
|
||||
principalTable: "Works",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "StoreWorks",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
WorkId = table.Column<int>(type: "integer", nullable: false),
|
||||
StoreId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_StoreWorks", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_StoreWorks_Stores_StoreId",
|
||||
column: x => x.StoreId,
|
||||
principalTable: "Stores",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_StoreWorks_Works_WorkId",
|
||||
column: x => x.WorkId,
|
||||
principalTable: "Works",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "WorkComponents",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "integer", nullable: false)
|
||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
||||
WorkId = table.Column<int>(type: "integer", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "integer", nullable: false),
|
||||
Count = table.Column<int>(type: "integer", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_WorkComponents", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_WorkComponents_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_WorkComponents_Works_WorkId",
|
||||
column: x => x.WorkId,
|
||||
principalTable: "Works",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_WorkId",
|
||||
table: "Orders",
|
||||
column: "WorkId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_StoreWorks_StoreId",
|
||||
table: "StoreWorks",
|
||||
column: "StoreId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_StoreWorks_WorkId",
|
||||
table: "StoreWorks",
|
||||
column: "WorkId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_WorkComponents_ComponentId",
|
||||
table: "WorkComponents",
|
||||
column: "ComponentId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_WorkComponents_WorkId",
|
||||
table: "WorkComponents",
|
||||
column: "WorkId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "StoreWorks");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "WorkComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Stores");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Works");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||
using PlumbingRepairDatabaseImplement;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace PlumbingRepairDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(PlumbingRepairDataBase))]
|
||||
partial class PlumbingRepairDataBaseModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "7.0.3")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||
|
||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<DateTime>("DateCreate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<DateTime?>("DateImplement")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<int>("WorkId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<string>("WorkName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("WorkId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Store", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<DateTime>("OpeningDate")
|
||||
.HasColumnType("timestamp with time zone");
|
||||
|
||||
b.Property<string>("StoreAdress")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<string>("StoreName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.Property<int>("WorkMaxCount")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Stores");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.StoreWork", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("StoreId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("WorkId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("StoreId");
|
||||
|
||||
b.HasIndex("WorkId");
|
||||
|
||||
b.ToTable("StoreWorks");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Work", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("double precision");
|
||||
|
||||
b.Property<string>("WorkName")
|
||||
.IsRequired()
|
||||
.HasColumnType("text");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Works");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.WorkComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("integer");
|
||||
|
||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.Property<int>("WorkId")
|
||||
.HasColumnType("integer");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("WorkId");
|
||||
|
||||
b.ToTable("WorkComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("PlumbingRepairDatabaseImplement.Models.Work", "Work")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("WorkId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Work");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.StoreWork", b =>
|
||||
{
|
||||
b.HasOne("PlumbingRepairDatabaseImplement.Models.Store", "Store")
|
||||
.WithMany("Works")
|
||||
.HasForeignKey("StoreId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PlumbingRepairDatabaseImplement.Models.Work", "Work")
|
||||
.WithMany()
|
||||
.HasForeignKey("WorkId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Store");
|
||||
|
||||
b.Navigation("Work");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.WorkComponent", b =>
|
||||
{
|
||||
b.HasOne("PlumbingRepairDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("WorkComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("PlumbingRepairDatabaseImplement.Models.Work", "Work")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("WorkId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Work");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("WorkComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Store", b =>
|
||||
{
|
||||
b.Navigation("Works");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("PlumbingRepairDatabaseImplement.Models.Work", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace PlumbingRepairDatabaseImplement.Models
|
||||
{
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
[Required]
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Cost { get; set; }
|
||||
|
||||
[ForeignKey("ComponentId")]
|
||||
public virtual List<WorkComponent> WorkComponents { get; set; } = new();
|
||||
|
||||
public static Component? Create(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Component()
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
public static Component Create(ComponentViewModel model)
|
||||
{
|
||||
return new Component
|
||||
{
|
||||
Id = model.Id,
|
||||
ComponentName = model.ComponentName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
public void Update(ComponentBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ComponentName = model.ComponentName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ComponentName = ComponentName,
|
||||
Cost = Cost
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDataModels.Enums;
|
||||
using PlumbingRepairDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace PlumbingRepairDatabaseImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int WorkId { get; private set; }
|
||||
|
||||
public string WorkName { get; private set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public int Count { get; private set; }
|
||||
|
||||
[Required]
|
||||
public double Sum { get; private set; }
|
||||
|
||||
[Required]
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
|
||||
[Required]
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public virtual Work Work { get; set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
WorkId = model.WorkId,
|
||||
WorkName = model.WorkName,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
WorkId = WorkId,
|
||||
WorkName = WorkName,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement
|
||||
};
|
||||
}
|
||||
}
|
||||
105
PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Store.cs
Normal file
105
PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Store.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace PlumbingRepairDatabaseImplement.Models
|
||||
{
|
||||
public class Store : IStoreModel
|
||||
{
|
||||
[Required]
|
||||
public string StoreName { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public string StoreAdress { get; private set; } = string.Empty;
|
||||
[Required]
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
[Required]
|
||||
public int WorkMaxCount { get; private set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
|
||||
private Dictionary<int, (IWorkModel, int)> _storeWorks = null;
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IWorkModel, int)> StoreWorks
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_storeWorks == null)
|
||||
{
|
||||
_storeWorks = Works
|
||||
.ToDictionary(recPC => recPC.WorkId, recPC => (recPC.Work as IWorkModel, recPC.Count));
|
||||
}
|
||||
return _storeWorks;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("StoreId")]
|
||||
public virtual List<StoreWork> Works { get; set; } = new();
|
||||
|
||||
public static Store Create(PlumbingRepairDataBase context, StoreBindingModel model)
|
||||
{
|
||||
return new Store()
|
||||
{
|
||||
Id = model.Id,
|
||||
StoreName = model.StoreName,
|
||||
StoreAdress = model.StoreAdress,
|
||||
OpeningDate = model.OpeningDate,
|
||||
WorkMaxCount = model.WorkMaxCount,
|
||||
Works = model.StoreWorks.Select(x => new StoreWork
|
||||
{
|
||||
Work = context.Works.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(StoreBindingModel model)
|
||||
{
|
||||
StoreName = model.StoreName;
|
||||
StoreAdress = model.StoreAdress;
|
||||
OpeningDate = model.OpeningDate;
|
||||
WorkMaxCount = model.WorkMaxCount;
|
||||
}
|
||||
|
||||
public StoreViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
StoreName = StoreName,
|
||||
StoreAdress = StoreAdress,
|
||||
OpeningDate = OpeningDate,
|
||||
WorkMaxCount = WorkMaxCount,
|
||||
StoreWorks = StoreWorks
|
||||
};
|
||||
|
||||
public void UpdateWorks(PlumbingRepairDataBase context, StoreBindingModel model)
|
||||
{
|
||||
var storeWorks = context.StoreWorks.Where(rec => rec.StoreId == model.Id).ToList();
|
||||
if (storeWorks != null && storeWorks.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.StoreWorks.RemoveRange(storeWorks.Where(rec => !model.StoreWorks.ContainsKey(rec.WorkId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateWork in storeWorks)
|
||||
{
|
||||
updateWork.Count = model.StoreWorks[updateWork.WorkId].Item2;
|
||||
model.StoreWorks.Remove(updateWork.WorkId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
var store = context.Stores.First(x => x.Id == Id);
|
||||
foreach (var sw in model.StoreWorks)
|
||||
{
|
||||
context.StoreWorks.Add(new StoreWork
|
||||
{
|
||||
Store = store,
|
||||
Work = context.Works.First(x => x.Id == sw.Key),
|
||||
Count = sw.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_storeWorks = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace PlumbingRepairDatabaseImplement.Models
|
||||
{
|
||||
public class StoreWork
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int WorkId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int StoreId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Store Store { get; set; } = new();
|
||||
|
||||
public virtual Work Work { get; set; } = new();
|
||||
}
|
||||
}
|
||||
101
PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Work.cs
Normal file
101
PlumbingRepair/PlumbingRepairDatabaseImplement/Models/Work.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDataModels.Models;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace PlumbingRepairDatabaseImplement.Models
|
||||
{
|
||||
public class Work : IWorkModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public string WorkName { get; set; } = string.Empty;
|
||||
|
||||
[Required]
|
||||
public double Price { get; set; }
|
||||
|
||||
private Dictionary<int, (IComponentModel, int)>? _workComponents = null;
|
||||
|
||||
[NotMapped]
|
||||
public Dictionary<int, (IComponentModel, int)> WorkComponents
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_workComponents == null)
|
||||
{
|
||||
_workComponents = Components.ToDictionary(recPC => recPC.ComponentId, recPC => (recPC.Component as IComponentModel, recPC.Count));
|
||||
}
|
||||
return _workComponents;
|
||||
}
|
||||
}
|
||||
|
||||
[ForeignKey("WorkId")]
|
||||
public virtual List<WorkComponent> Components { get; set; } = new();
|
||||
|
||||
[ForeignKey("WorkId")]
|
||||
public virtual List<Order> Orders { get; set; } = new();
|
||||
|
||||
public static Work Create(PlumbingRepairDataBase context, WorkBindingModel model)
|
||||
{
|
||||
return new Work()
|
||||
{
|
||||
Id = model.Id,
|
||||
WorkName = model.WorkName,
|
||||
Price = model.Price,
|
||||
Components = model.WorkComponents.Select(x => new WorkComponent
|
||||
{
|
||||
Component = context.Components.First(y => y.Id == x.Key),
|
||||
Count = x.Value.Item2
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(WorkBindingModel model)
|
||||
{
|
||||
WorkName = model.WorkName;
|
||||
Price = model.Price;
|
||||
}
|
||||
|
||||
public WorkViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
WorkName = WorkName,
|
||||
Price = Price,
|
||||
WorkComponents = WorkComponents
|
||||
};
|
||||
|
||||
public void UpdateComponents(PlumbingRepairDataBase context, WorkBindingModel model)
|
||||
{
|
||||
var workComponents = context.WorkComponents.Where(rec => rec.WorkId == model.Id).ToList();
|
||||
|
||||
if (workComponents != null && workComponents.Count > 0)
|
||||
{ // удалили те, которых нет в модели
|
||||
context.WorkComponents.RemoveRange(workComponents.Where(rec => !model.WorkComponents.ContainsKey(rec.ComponentId)));
|
||||
context.SaveChanges();
|
||||
// обновили количество у существующих записей
|
||||
foreach (var updateComponent in workComponents)
|
||||
{
|
||||
updateComponent.Count = model.WorkComponents[updateComponent.ComponentId].Item2;
|
||||
model.WorkComponents.Remove(updateComponent.ComponentId);
|
||||
}
|
||||
context.SaveChanges();
|
||||
}
|
||||
|
||||
var work = context.Works.First(x => x.Id == Id);
|
||||
|
||||
foreach (var pc in model.WorkComponents)
|
||||
{
|
||||
context.WorkComponents.Add(new WorkComponent
|
||||
{
|
||||
Work = work,
|
||||
Component = context.Components.First(x => x.Id == pc.Key),
|
||||
Count = pc.Value.Item2
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
_workComponents = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace PlumbingRepairDatabaseImplement.Models
|
||||
{
|
||||
public class WorkComponent
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public int WorkId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int ComponentId { get; set; }
|
||||
|
||||
[Required]
|
||||
public int Count { get; set; }
|
||||
|
||||
public virtual Component Component { get; set; } = new();
|
||||
public virtual Work Work { get; set; } = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using PlumbingRepairDatabaseImplement.Models;
|
||||
|
||||
namespace PlumbingRepairDatabaseImplement
|
||||
{
|
||||
public class PlumbingRepairDataBase : DbContext
|
||||
{
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
if (optionsBuilder.IsConfigured == false)
|
||||
{
|
||||
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=PlumbingRepairDatabaseHardFull;Username=postgres;Password=186qazwsx");
|
||||
}
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
public virtual DbSet<Component> Components { set; get; }
|
||||
public virtual DbSet<Work> Works { set; get; }
|
||||
public virtual DbSet<WorkComponent> WorkComponents { set; get; }
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<Store> Stores { set; get; }
|
||||
public virtual DbSet<StoreWork> StoreWorks { set; get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PlumbingRepairContracts\PlumbingRepairContracts.csproj" />
|
||||
<ProjectReference Include="..\PlumbingRepairDataModels\PlumbingRepairDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,4 +1,5 @@
|
||||
using PlumbingRepairListImplement.Models;
|
||||
using static System.Formats.Asn1.AsnWriter;
|
||||
|
||||
namespace PlumbingRepairListImplement
|
||||
{
|
||||
@@ -8,12 +9,14 @@ namespace PlumbingRepairListImplement
|
||||
public List<Component> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Work> Works { get; set; }
|
||||
public List<Store> Stores { get; set; }
|
||||
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Works = new List<Work>();
|
||||
Stores = new List<Store>();
|
||||
}
|
||||
|
||||
public static DataListSingleton GetInstance()
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.SearchModels;
|
||||
using PlumbingRepairContracts.StoragesContracts;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDataModels.Models;
|
||||
using PlumbingRepairListImplement.Models;
|
||||
|
||||
namespace PlumbingRepairListImplement.Implements
|
||||
{
|
||||
public class StoreStorage : IStoreStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public StoreStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
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 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))
|
||||
{
|
||||
result.Add(store.GetViewModel);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<StoreViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<StoreViewModel>();
|
||||
|
||||
foreach (var store in _source.Stores)
|
||||
{
|
||||
result.Add(store.GetViewModel);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
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 bool SellWork(IWorkModel model, int quantity)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public StoreViewModel? Update(StoreBindingModel model)
|
||||
{
|
||||
foreach (var store in _source.Stores)
|
||||
{
|
||||
if (store.Id == model.Id)
|
||||
{
|
||||
store.Update(model);
|
||||
return store.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
59
PlumbingRepair/PlumbingRepairListImplement/Models/Store.cs
Normal file
59
PlumbingRepair/PlumbingRepairListImplement/Models/Store.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDataModels.Models;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
|
||||
namespace PlumbingRepairListImplement.Models
|
||||
{
|
||||
public class Store : IStoreModel
|
||||
{
|
||||
public string StoreName { get; private set; } = string.Empty;
|
||||
public string StoreAdress { get; private set; } = string.Empty;
|
||||
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
|
||||
public Dictionary<int, (IWorkModel, int)> StoreWorks { get; private set; } = new();
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public static Store? Create(StoreBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Store()
|
||||
{
|
||||
Id = model.Id,
|
||||
StoreName = model.StoreName,
|
||||
StoreAdress = model.StoreAdress,
|
||||
OpeningDate = model.OpeningDate,
|
||||
StoreWorks = new()
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(StoreBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
StoreName = model.StoreName;
|
||||
StoreAdress = model.StoreAdress;
|
||||
OpeningDate = model.OpeningDate;
|
||||
StoreWorks = model.StoreWorks;
|
||||
}
|
||||
|
||||
public StoreViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
StoreName = StoreName,
|
||||
StoreAdress = StoreAdress,
|
||||
OpeningDate = OpeningDate,
|
||||
StoreWorks = StoreWorks
|
||||
};
|
||||
|
||||
public int WorkMaxCount => throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using PlumbingRepairFileImplement.Models;
|
||||
using System.Xml.Linq;
|
||||
using static System.Formats.Asn1.AsnWriter;
|
||||
|
||||
namespace PlumbingRepairFileImplement
|
||||
{
|
||||
@@ -10,10 +11,12 @@ namespace PlumbingRepairFileImplement
|
||||
private readonly string ComponentFileName = "Component.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string WorkFileName = "Work.xml";
|
||||
private readonly string StoreFileName = "Store.xml";
|
||||
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Work> Works { get; private set; }
|
||||
public List<Store> Stores { get; private set; }
|
||||
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
@@ -27,12 +30,14 @@ namespace PlumbingRepairFileImplement
|
||||
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||
public void SaveWorks() => SaveData(Works, WorkFileName, "Works", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
public void SaveStores() => SaveData(Stores, StoreFileName, "Stores", x => x.GetXElement);
|
||||
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Works = LoadData(WorkFileName, "Work", x => Work.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Stores = LoadData(StoreFileName, "Store", x => Store.Create(x)!)!;
|
||||
}
|
||||
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.SearchModels;
|
||||
using PlumbingRepairContracts.StoragesContracts;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDataModels.Models;
|
||||
using PlumbingRepairFileImplement.Models;
|
||||
|
||||
namespace PlumbingRepairFileImplement.Implements
|
||||
{
|
||||
public class StoreStorage : IStoreStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public StoreStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public StoreViewModel? GetElement(StoreSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.StoreName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Stores.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(model.StoreName) && x.StoreName ==
|
||||
model.StoreName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<StoreViewModel> GetFilteredList(StoreSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.StoreName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Stores.Where(x =>
|
||||
x.StoreName.Contains(model.StoreName)).Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public List<StoreViewModel> GetFullList()
|
||||
{
|
||||
return source.Stores.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public StoreViewModel? Insert(StoreBindingModel model)
|
||||
{
|
||||
model.Id = source.Stores.Count > 0 ? source.Stores.Max(x => x.Id) + 1 : 1;
|
||||
var newStore = Store.Create(model);
|
||||
if (newStore == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Stores.Add(newStore);
|
||||
source.SaveStores();
|
||||
return newStore.GetViewModel;
|
||||
}
|
||||
|
||||
public StoreViewModel? Update(StoreBindingModel model)
|
||||
{
|
||||
var store = source.Stores.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (store == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
store.Update(model);
|
||||
source.SaveStores();
|
||||
return store.GetViewModel;
|
||||
}
|
||||
|
||||
public StoreViewModel? Delete(StoreBindingModel model)
|
||||
{
|
||||
var element = source.Stores.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
source.Stores.Remove(element);
|
||||
source.SaveStores();
|
||||
return element.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool SellWork(IWorkModel model, int quantity)
|
||||
{
|
||||
if (source.Stores.Select(x => x.StoreWorks.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < quantity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
foreach (var store in source.Stores.Where(x => x.StoreWorks.ContainsKey(model.Id)))
|
||||
{
|
||||
int QuantityInCurrentShop = store.StoreWorks[model.Id].Item2;
|
||||
if (QuantityInCurrentShop <= quantity)
|
||||
{
|
||||
store.StoreWorks.Remove(model.Id);
|
||||
quantity -= QuantityInCurrentShop;
|
||||
}
|
||||
else
|
||||
{
|
||||
store.StoreWorks[model.Id] = (store.StoreWorks[model.Id].Item1, QuantityInCurrentShop - quantity);
|
||||
quantity = 0;
|
||||
}
|
||||
if (quantity == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
103
PlumbingRepair/PlumpingRepairFileImplement/Models/Store.cs
Normal file
103
PlumbingRepair/PlumpingRepairFileImplement/Models/Store.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
using PlumbingRepairContracts.BindingModels;
|
||||
using PlumbingRepairContracts.ViewModels;
|
||||
using PlumbingRepairDataModels.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace PlumbingRepairFileImplement.Models
|
||||
{
|
||||
public class Store : IStoreModel
|
||||
{
|
||||
public string StoreName { get; private set; } = string.Empty;
|
||||
public string StoreAdress { get; private set; } = string.Empty;
|
||||
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
public Dictionary<int, int> Works { get; private set; } = new();
|
||||
|
||||
public Dictionary<int, (IWorkModel, int)> _storeWorks = null;
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int WorkMaxCount { get; private set; }
|
||||
|
||||
public Dictionary<int, (IWorkModel, int)> StoreWorks
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_storeWorks == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_storeWorks = Works.ToDictionary(x => x.Key, y => ((source.Works.FirstOrDefault(z => z.Id == y.Key) as IWorkModel)!, y.Value));
|
||||
}
|
||||
return _storeWorks;
|
||||
}
|
||||
}
|
||||
|
||||
public static Store? Create(StoreBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Store()
|
||||
{
|
||||
Id = model.Id,
|
||||
StoreName = model.StoreName,
|
||||
StoreAdress = model.StoreAdress,
|
||||
WorkMaxCount = model.WorkMaxCount,
|
||||
OpeningDate = model.OpeningDate,
|
||||
Works = model.StoreWorks.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
public static Store? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
StoreName = element.Element("StoreName")!.Value,
|
||||
StoreAdress = element.Element("StoreAdress")!.Value,
|
||||
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
|
||||
WorkMaxCount = Convert.ToInt32(element.Element("WorkMaxCount")!.Value),
|
||||
Works = element.Element("StoreWorks")!.Elements("Work").ToDictionary(
|
||||
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||
};
|
||||
}
|
||||
public void Update(StoreBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
StoreName = model.StoreName;
|
||||
StoreAdress = model.StoreAdress;
|
||||
OpeningDate = model.OpeningDate;
|
||||
WorkMaxCount = model.WorkMaxCount;
|
||||
Works = model.StoreWorks.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_storeWorks = null;
|
||||
}
|
||||
public StoreViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
StoreName = StoreName,
|
||||
StoreAdress = StoreAdress,
|
||||
StoreWorks = StoreWorks,
|
||||
OpeningDate = OpeningDate,
|
||||
WorkMaxCount = WorkMaxCount,
|
||||
};
|
||||
public XElement GetXElement => new("Store",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("StoreName", StoreName),
|
||||
new XElement("StoreAdress", StoreAdress),
|
||||
new XElement("OpeningDate", OpeningDate),
|
||||
new XElement("WorkMaxCount", WorkMaxCount),
|
||||
new XElement("StoreWorks", Works
|
||||
.Select(x => new XElement("Work",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value))
|
||||
).ToArray()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user