Compare commits

...

4 Commits

Author SHA1 Message Date
ityurner02@mail.ru
be0302ba63 Усложненная работа 2 2023-03-28 22:01:07 +04:00
ityurner02@mail.ru
a60bb52fff Merge branch 'LabWork_2' into LabWork_2_Hard 2023-03-26 16:25:44 +04:00
ityurner02@mail.ru
b7a64957f7 Обновление форм 2023-02-21 12:22:35 +04:00
ityurner02@mail.ru
a9b7625b2b Лабораторная 2 2023-02-18 19:58:39 +04:00
36 changed files with 1379 additions and 239 deletions

View File

@ -5,13 +5,15 @@ VisualStudioVersion = 17.3.32825.248
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepair", "PlumbingRepair\PlumbingRepair.csproj", "{F0AEA1F3-7D99-4EC1-B79F-97E6927ECBCA}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepair", "PlumbingRepair\PlumbingRepair.csproj", "{F0AEA1F3-7D99-4EC1-B79F-97E6927ECBCA}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlumbingRepairDataModels", "PlumbingRepairDataModels\PlumbingRepairDataModels.csproj", "{90DD7D7A-91FD-403D-8D3A-FE8842AA5848}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairDataModels", "PlumbingRepairDataModels\PlumbingRepairDataModels.csproj", "{90DD7D7A-91FD-403D-8D3A-FE8842AA5848}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlumbingRepairContracts", "PlumbingRepairContracts\PlumbingRepairContracts.csproj", "{5200A7ED-CC3F-4602-984D-1B56A43A50D2}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairContracts", "PlumbingRepairContracts\PlumbingRepairContracts.csproj", "{5200A7ED-CC3F-4602-984D-1B56A43A50D2}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlumbingRepairBusinessLogic", "PlumbingRepairBusinessLogic\PlumbingRepairBusinessLogic.csproj", "{3C711D99-7E84-4B26-8312-7C10A360BD54}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlumbingRepairBusinessLogic", "PlumbingRepairBusinessLogic\PlumbingRepairBusinessLogic.csproj", "{3C711D99-7E84-4B26-8312-7C10A360BD54}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlumbingRepairListImplement", "PlumbingRepairListImplement\PlumbingRepairListImplement.csproj", "{9B17B17E-1201-4B23-ACCD-EF7F4495E4B7}" 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}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -39,6 +41,10 @@ Global
{9B17B17E-1201-4B23-ACCD-EF7F4495E4B7}.Debug|Any CPU.Build.0 = Debug|Any CPU {9B17B17E-1201-4B23-ACCD-EF7F4495E4B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9B17B17E-1201-4B23-ACCD-EF7F4495E4B7}.Release|Any CPU.ActiveCfg = Release|Any CPU {9B17B17E-1201-4B23-ACCD-EF7F4495E4B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9B17B17E-1201-4B23-ACCD-EF7F4495E4B7}.Release|Any CPU.Build.0 = Release|Any CPU {9B17B17E-1201-4B23-ACCD-EF7F4495E4B7}.Release|Any CPU.Build.0 = Release|Any CPU
{BA7E2CE6-7797-42C7-931C-40C48EA521C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -40,16 +40,19 @@
// //
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.DataGridView.Location = new System.Drawing.Point(2, 0); this.DataGridView.Location = new System.Drawing.Point(2, 0);
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.DataGridView.Name = "DataGridView"; this.DataGridView.Name = "DataGridView";
this.DataGridView.RowHeadersWidth = 51;
this.DataGridView.RowTemplate.Height = 25; this.DataGridView.RowTemplate.Height = 25;
this.DataGridView.Size = new System.Drawing.Size(551, 551); this.DataGridView.Size = new System.Drawing.Size(630, 735);
this.DataGridView.TabIndex = 0; this.DataGridView.TabIndex = 0;
// //
// AddButton // AddButton
// //
this.AddButton.Location = new System.Drawing.Point(571, 26); this.AddButton.Location = new System.Drawing.Point(653, 35);
this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.AddButton.Name = "AddButton"; this.AddButton.Name = "AddButton";
this.AddButton.Size = new System.Drawing.Size(142, 45); this.AddButton.Size = new System.Drawing.Size(162, 60);
this.AddButton.TabIndex = 1; this.AddButton.TabIndex = 1;
this.AddButton.Text = "Добавить"; this.AddButton.Text = "Добавить";
this.AddButton.UseVisualStyleBackColor = true; this.AddButton.UseVisualStyleBackColor = true;
@ -57,9 +60,10 @@
// //
// ChangeButton // ChangeButton
// //
this.ChangeButton.Location = new System.Drawing.Point(571, 93); this.ChangeButton.Location = new System.Drawing.Point(653, 124);
this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ChangeButton.Name = "ChangeButton"; this.ChangeButton.Name = "ChangeButton";
this.ChangeButton.Size = new System.Drawing.Size(142, 45); this.ChangeButton.Size = new System.Drawing.Size(162, 60);
this.ChangeButton.TabIndex = 2; this.ChangeButton.TabIndex = 2;
this.ChangeButton.Text = "Изменить"; this.ChangeButton.Text = "Изменить";
this.ChangeButton.UseVisualStyleBackColor = true; this.ChangeButton.UseVisualStyleBackColor = true;
@ -67,9 +71,10 @@
// //
// DeleteButton // DeleteButton
// //
this.DeleteButton.Location = new System.Drawing.Point(571, 162); this.DeleteButton.Location = new System.Drawing.Point(653, 216);
this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.DeleteButton.Name = "DeleteButton"; this.DeleteButton.Name = "DeleteButton";
this.DeleteButton.Size = new System.Drawing.Size(142, 45); this.DeleteButton.Size = new System.Drawing.Size(162, 60);
this.DeleteButton.TabIndex = 3; this.DeleteButton.TabIndex = 3;
this.DeleteButton.Text = "Удалить"; this.DeleteButton.Text = "Удалить";
this.DeleteButton.UseVisualStyleBackColor = true; this.DeleteButton.UseVisualStyleBackColor = true;
@ -77,9 +82,10 @@
// //
// UpdateButton // UpdateButton
// //
this.UpdateButton.Location = new System.Drawing.Point(571, 230); this.UpdateButton.Location = new System.Drawing.Point(653, 307);
this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.UpdateButton.Name = "UpdateButton"; this.UpdateButton.Name = "UpdateButton";
this.UpdateButton.Size = new System.Drawing.Size(142, 45); this.UpdateButton.Size = new System.Drawing.Size(162, 60);
this.UpdateButton.TabIndex = 4; this.UpdateButton.TabIndex = 4;
this.UpdateButton.Text = "Обновить"; this.UpdateButton.Text = "Обновить";
this.UpdateButton.UseVisualStyleBackColor = true; this.UpdateButton.UseVisualStyleBackColor = true;
@ -87,16 +93,18 @@
// //
// FormComponents // FormComponents
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(725, 552); this.ClientSize = new System.Drawing.Size(829, 736);
this.Controls.Add(this.UpdateButton); this.Controls.Add(this.UpdateButton);
this.Controls.Add(this.DeleteButton); this.Controls.Add(this.DeleteButton);
this.Controls.Add(this.ChangeButton); this.Controls.Add(this.ChangeButton);
this.Controls.Add(this.AddButton); this.Controls.Add(this.AddButton);
this.Controls.Add(this.DataGridView); this.Controls.Add(this.DataGridView);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormComponents"; this.Name = "FormComponents";
this.Text = "Компоненты"; this.Text = "Компоненты";
this.Load += new System.EventHandler(this.FormComponents_Load);
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);

View File

@ -14,6 +14,7 @@ namespace PlumbingRepair
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
LoadData();
} }
private void FormComponents_Load(object sender, EventArgs e) private void FormComponents_Load(object sender, EventArgs e)

View File

@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <root>
<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: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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">

View File

@ -40,6 +40,7 @@
this.IssuedOrderButton = new System.Windows.Forms.Button(); this.IssuedOrderButton = new System.Windows.Forms.Button();
this.UpdateListButton = new System.Windows.Forms.Button(); this.UpdateListButton = new System.Windows.Forms.Button();
this.StoreReplenishment = new System.Windows.Forms.Button(); this.StoreReplenishment = new System.Windows.Forms.Button();
this.SellWorkButton = new System.Windows.Forms.Button();
this.MenuStrip.SuspendLayout(); this.MenuStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@ -154,11 +155,22 @@
this.StoreReplenishment.UseVisualStyleBackColor = true; this.StoreReplenishment.UseVisualStyleBackColor = true;
this.StoreReplenishment.Click += new System.EventHandler(this.StoreReplenishment_Click); 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 // FormMain
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(865, 450); this.ClientSize = new System.Drawing.Size(865, 450);
this.Controls.Add(this.SellWorkButton);
this.Controls.Add(this.StoreReplenishment); this.Controls.Add(this.StoreReplenishment);
this.Controls.Add(this.UpdateListButton); this.Controls.Add(this.UpdateListButton);
this.Controls.Add(this.IssuedOrderButton); this.Controls.Add(this.IssuedOrderButton);
@ -170,6 +182,7 @@
this.MainMenuStrip = this.MenuStrip; this.MainMenuStrip = this.MenuStrip;
this.Name = "FormMain"; this.Name = "FormMain";
this.Text = "Ремонт сантехники"; this.Text = "Ремонт сантехники";
this.Load += new System.EventHandler(this.FormMain_Load);
this.MenuStrip.ResumeLayout(false); this.MenuStrip.ResumeLayout(false);
this.MenuStrip.PerformLayout(); this.MenuStrip.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
@ -192,5 +205,6 @@
private Button UpdateListButton; private Button UpdateListButton;
private ToolStripMenuItem StoreToolStripMenuItem; private ToolStripMenuItem StoreToolStripMenuItem;
private Button StoreReplenishment; private Button StoreReplenishment;
private Button SellWorkButton;
} }
} }

View File

@ -15,6 +15,7 @@ namespace PlumbingRepair
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_orderLogic = orderLogic; _orderLogic = orderLogic;
LoadData();
} }
private void FormMain_Load(object sender, EventArgs e) private void FormMain_Load(object sender, EventArgs e)
@ -206,5 +207,15 @@ namespace PlumbingRepair
form.ShowDialog(); form.ShowDialog();
} }
} }
private void SellWorkButton_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellWork));
if (service is FormSellWork form)
{
form.ShowDialog();
}
}
} }
} }

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

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

View File

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

View File

@ -40,7 +40,10 @@
this.SaveButton = new System.Windows.Forms.Button(); this.SaveButton = new System.Windows.Forms.Button();
this.ButtonCancel = new System.Windows.Forms.Button(); this.ButtonCancel = new System.Windows.Forms.Button();
this.OpeningDatePicker = new System.Windows.Forms.DateTimePicker(); this.OpeningDatePicker = new System.Windows.Forms.DateTimePicker();
this.VolumeNumericUpDown = new System.Windows.Forms.NumericUpDown();
this.WorkMaxCountLable = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.VolumeNumericUpDown)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// StoreNameLabel // StoreNameLabel
@ -70,10 +73,10 @@
this.OpeningDateLabel.TabIndex = 2; this.OpeningDateLabel.TabIndex = 2;
this.OpeningDateLabel.Text = "Дата открытия: "; this.OpeningDateLabel.Text = "Дата открытия: ";
// //
// NameComboBox // NameTextBox
// //
this.NameTextBox.Location = new System.Drawing.Point(137, 6); this.NameTextBox.Location = new System.Drawing.Point(137, 6);
this.NameTextBox.Name = "NameComboBox"; this.NameTextBox.Name = "NameTextBox";
this.NameTextBox.Size = new System.Drawing.Size(174, 23); this.NameTextBox.Size = new System.Drawing.Size(174, 23);
this.NameTextBox.TabIndex = 3; this.NameTextBox.TabIndex = 3;
// //
@ -97,21 +100,21 @@
this.DataGridView.Size = new System.Drawing.Size(776, 288); this.DataGridView.Size = new System.Drawing.Size(776, 288);
this.DataGridView.TabIndex = 6; this.DataGridView.TabIndex = 6;
// //
// PackageName // WorkName
// //
this.WorkName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; this.WorkName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.WorkName.HeaderText = "Название изделия"; this.WorkName.HeaderText = "Название изделия";
this.WorkName.Name = "PackageName"; this.WorkName.Name = "WorkName";
// //
// PackagePrice // WorkPrice
// //
this.WorkPrice.HeaderText = "Цена"; this.WorkPrice.HeaderText = "Цена";
this.WorkPrice.Name = "PackagePrice"; this.WorkPrice.Name = "WorkPrice";
// //
// PackageCount // WorkCount
// //
this.WorkCount.HeaderText = "Количество"; this.WorkCount.HeaderText = "Количество";
this.WorkCount.Name = "PackageCount"; this.WorkCount.Name = "WorkCount";
// //
// SaveButton // SaveButton
// //
@ -140,11 +143,29 @@
this.OpeningDatePicker.Size = new System.Drawing.Size(174, 23); this.OpeningDatePicker.Size = new System.Drawing.Size(174, 23);
this.OpeningDatePicker.TabIndex = 9; this.OpeningDatePicker.TabIndex = 9;
// //
// VolumeNumericUpDown
//
this.VolumeNumericUpDown.Location = new System.Drawing.Point(486, 7);
this.VolumeNumericUpDown.Name = "VolumeNumericUpDown";
this.VolumeNumericUpDown.Size = new System.Drawing.Size(168, 23);
this.VolumeNumericUpDown.TabIndex = 10;
//
// WorkMaxCountLable
//
this.WorkMaxCountLable.AutoSize = true;
this.WorkMaxCountLable.Location = new System.Drawing.Point(340, 9);
this.WorkMaxCountLable.Name = "WorkMaxCountLable";
this.WorkMaxCountLable.Size = new System.Drawing.Size(140, 15);
this.WorkMaxCountLable.TabIndex = 11;
this.WorkMaxCountLable.Text = "Вместимость магазина: ";
//
// FormStore // FormStore
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450); this.ClientSize = new System.Drawing.Size(800, 450);
this.Controls.Add(this.WorkMaxCountLable);
this.Controls.Add(this.VolumeNumericUpDown);
this.Controls.Add(this.OpeningDatePicker); this.Controls.Add(this.OpeningDatePicker);
this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.SaveButton); this.Controls.Add(this.SaveButton);
@ -158,6 +179,7 @@
this.Text = "Изделия магазина"; this.Text = "Изделия магазина";
this.Load += new System.EventHandler(this.FormStore_Load); this.Load += new System.EventHandler(this.FormStore_Load);
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.VolumeNumericUpDown)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@ -177,5 +199,7 @@
private DataGridViewTextBoxColumn WorkPrice; private DataGridViewTextBoxColumn WorkPrice;
private DataGridViewTextBoxColumn WorkCount; private DataGridViewTextBoxColumn WorkCount;
private DateTimePicker OpeningDatePicker; private DateTimePicker OpeningDatePicker;
private NumericUpDown VolumeNumericUpDown;
private Label WorkMaxCountLable;
} }
} }

View File

@ -1,42 +1,30 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairContracts.SearchModels;
using PlumbingRepairContracts.ViewModels; using PlumbingRepairContracts.ViewModels;
using PlumbingRepairDataModels.Models; using PlumbingRepairDataModels.Models;
using System.Reflection;
using System.Windows.Forms;
namespace PlumbingRepair namespace PlumbingRepair
{ {
public partial class FormStore : Form public partial class FormStore : Form
{ {
private readonly List<StoreViewModel>? _listStores;
private readonly IStoreLogic _logic; private readonly IStoreLogic _logic;
private readonly ILogger _logger; private readonly ILogger _logger;
public int Id { get; set; } private int? _id;
private Dictionary<int, (IWorkModel, int)> _listStores;
public int Id { set { _id = value; } }
public FormStore(ILogger<FormStore> logger, IStoreLogic logic) public FormStore(ILogger<FormStore> logger, IStoreLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_listStores = logic.ReadList(null); _listStores = new();
_logic = logic; _logic = logic;
} }
private IStoreModel? GetStore(int id)
{
if (_listStores == null)
{
return null;
}
foreach (var elem in _listStores)
{
if (elem.Id == id)
{
return elem;
}
}
return null;
}
private void SaveButton_Click(object sender, EventArgs e) private void SaveButton_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(NameTextBox.Text)) if (string.IsNullOrEmpty(NameTextBox.Text))
@ -44,49 +32,34 @@ namespace PlumbingRepair
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (string.IsNullOrEmpty(AdressTextBox.Text)) if (string.IsNullOrEmpty(AdressTextBox.Text))
{ {
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
_logger.LogInformation("Сохранение магазина");
_logger.LogInformation("Сохранение изделия");
try try
{ {
DateTime.TryParse(OpeningDatePicker.Text, out var dateTime); var model = new StoreBindingModel
StoreBindingModel model = new()
{ {
Id = _id ?? 0,
StoreName = NameTextBox.Text, StoreName = NameTextBox.Text,
StoreAdress = AdressTextBox.Text, StoreAdress = AdressTextBox.Text,
OpeningDate = dateTime OpeningDate = OpeningDatePicker.Value.Date,
WorkMaxCount = (int)VolumeNumericUpDown.Value
}; };
var vmodel = GetStore(Id); var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
bool operationResult = false;
if (vmodel != null)
{
model.Id = vmodel.Id;
operationResult = _logic.Update(model);
}
else
{
operationResult = _logic.Create(model);
}
if (!operationResult) if (!operationResult)
{ {
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
} }
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
Close(); Close();
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка сохранения изделия"); _logger.LogError(ex, "Ошибка сохранения магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
@ -99,37 +72,52 @@ namespace PlumbingRepair
private void FormStore_Load(object sender, EventArgs e) private void FormStore_Load(object sender, EventArgs e)
{ {
LoadData(); 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) private void LoadData(bool extendDate = true)
{ {
_logger.LogInformation("Загрузка изделий магазина");
try try
{ {
var model = GetStore(extendDate ? Id : Convert.ToInt32(NameTextBox.Text)); if (_listStores != null)
if (model != null)
{ {
NameTextBox.Text = model.StoreName;
AdressTextBox.Text = model.StoreAdress;
OpeningDatePicker.Text = Convert.ToString(model.OpeningDate);
DataGridView.Rows.Clear(); DataGridView.Rows.Clear();
foreach (var el in model.Works.Values) foreach (var elem in _listStores)
{ {
DataGridView.Rows.Add(new object[] { el.Item1.WorkName, el.Item1.Price, el.Item2 }); DataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.WorkName, elem.Value.Item2 });
} }
} }
_logger.LogInformation("Загрузка магазинов");
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка загрузки магазинов"); _logger.LogError(ex, "Ошибка загрузки изделий магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxIcon.Error);
} }
} }
private void NameComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
LoadData(false);
}
} }
} }

View File

@ -31,7 +31,7 @@ namespace PlumbingRepair
DataGridView.DataSource = list; DataGridView.DataSource = list;
DataGridView.Columns["Id"].Visible = false; DataGridView.Columns["Id"].Visible = false;
DataGridView.Columns["StoreName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; DataGridView.Columns["StoreName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
DataGridView.Columns["Works"].Visible = false; DataGridView.Columns["StoreWorks"].Visible = false;
} }
_logger.LogInformation("Загрузка магазинов"); _logger.LogInformation("Загрузка магазинов");

View File

@ -40,16 +40,19 @@
// //
this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.DataGridView.Location = new System.Drawing.Point(1, 1); this.DataGridView.Location = new System.Drawing.Point(1, 1);
this.DataGridView.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.DataGridView.Name = "DataGridView"; this.DataGridView.Name = "DataGridView";
this.DataGridView.RowHeadersWidth = 51;
this.DataGridView.RowTemplate.Height = 25; this.DataGridView.RowTemplate.Height = 25;
this.DataGridView.Size = new System.Drawing.Size(562, 495); this.DataGridView.Size = new System.Drawing.Size(642, 660);
this.DataGridView.TabIndex = 0; this.DataGridView.TabIndex = 0;
// //
// AddButton // AddButton
// //
this.AddButton.Location = new System.Drawing.Point(585, 12); this.AddButton.Location = new System.Drawing.Point(669, 16);
this.AddButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.AddButton.Name = "AddButton"; this.AddButton.Name = "AddButton";
this.AddButton.Size = new System.Drawing.Size(120, 41); this.AddButton.Size = new System.Drawing.Size(137, 55);
this.AddButton.TabIndex = 1; this.AddButton.TabIndex = 1;
this.AddButton.Text = "Добавить"; this.AddButton.Text = "Добавить";
this.AddButton.UseVisualStyleBackColor = true; this.AddButton.UseVisualStyleBackColor = true;
@ -57,9 +60,10 @@
// //
// ChangeButton // ChangeButton
// //
this.ChangeButton.Location = new System.Drawing.Point(585, 71); this.ChangeButton.Location = new System.Drawing.Point(669, 95);
this.ChangeButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.ChangeButton.Name = "ChangeButton"; this.ChangeButton.Name = "ChangeButton";
this.ChangeButton.Size = new System.Drawing.Size(120, 41); this.ChangeButton.Size = new System.Drawing.Size(137, 55);
this.ChangeButton.TabIndex = 2; this.ChangeButton.TabIndex = 2;
this.ChangeButton.Text = "Изменить"; this.ChangeButton.Text = "Изменить";
this.ChangeButton.UseVisualStyleBackColor = true; this.ChangeButton.UseVisualStyleBackColor = true;
@ -67,9 +71,10 @@
// //
// DeleteButton // DeleteButton
// //
this.DeleteButton.Location = new System.Drawing.Point(585, 130); this.DeleteButton.Location = new System.Drawing.Point(669, 173);
this.DeleteButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.DeleteButton.Name = "DeleteButton"; this.DeleteButton.Name = "DeleteButton";
this.DeleteButton.Size = new System.Drawing.Size(120, 41); this.DeleteButton.Size = new System.Drawing.Size(137, 55);
this.DeleteButton.TabIndex = 3; this.DeleteButton.TabIndex = 3;
this.DeleteButton.Text = "Удалить"; this.DeleteButton.Text = "Удалить";
this.DeleteButton.UseVisualStyleBackColor = true; this.DeleteButton.UseVisualStyleBackColor = true;
@ -77,9 +82,10 @@
// //
// UpdateButton // UpdateButton
// //
this.UpdateButton.Location = new System.Drawing.Point(585, 191); this.UpdateButton.Location = new System.Drawing.Point(669, 255);
this.UpdateButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.UpdateButton.Name = "UpdateButton"; this.UpdateButton.Name = "UpdateButton";
this.UpdateButton.Size = new System.Drawing.Size(120, 41); this.UpdateButton.Size = new System.Drawing.Size(137, 55);
this.UpdateButton.TabIndex = 4; this.UpdateButton.TabIndex = 4;
this.UpdateButton.Text = "Обновить"; this.UpdateButton.Text = "Обновить";
this.UpdateButton.UseVisualStyleBackColor = true; this.UpdateButton.UseVisualStyleBackColor = true;
@ -87,16 +93,18 @@
// //
// FormWorks // FormWorks
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(717, 502); this.ClientSize = new System.Drawing.Size(819, 669);
this.Controls.Add(this.UpdateButton); this.Controls.Add(this.UpdateButton);
this.Controls.Add(this.DeleteButton); this.Controls.Add(this.DeleteButton);
this.Controls.Add(this.ChangeButton); this.Controls.Add(this.ChangeButton);
this.Controls.Add(this.AddButton); this.Controls.Add(this.AddButton);
this.Controls.Add(this.DataGridView); this.Controls.Add(this.DataGridView);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormWorks"; this.Name = "FormWorks";
this.Text = "Изделия"; this.Text = "Изделия";
this.Load += new System.EventHandler(this.FormComponents_Load);
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);

View File

@ -14,6 +14,7 @@ namespace PlumbingRepair
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
LoadData();
} }
private void FormComponents_Load(object sender, EventArgs e) private void FormComponents_Load(object sender, EventArgs e)

View File

@ -1,64 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <root>
<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: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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true"> <xsd:element name="root" msdata:IsDataSet="true">

View File

@ -15,6 +15,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\PlumbingRepairBusinessLogic\PlumbingRepairBusinessLogic.csproj" /> <ProjectReference Include="..\PlumbingRepairBusinessLogic\PlumbingRepairBusinessLogic.csproj" />
<ProjectReference Include="..\PlumbingRepairListImplement\PlumbingRepairListImplement.csproj" /> <ProjectReference Include="..\PlumbingRepairListImplement\PlumbingRepairListImplement.csproj" />
<ProjectReference Include="..\PlumpingRepairFileImplement\PlumbingRepairFileImplement.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,6 +1,6 @@
using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.BusinessLogicsContracts;
using PlumbingRepairContracts.StoragesContracts; using PlumbingRepairContracts.StoragesContracts;
using PlumbingRepairListImplement.Implements; using PlumbingRepairFileImplement.Implements;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging; using NLog.Extensions.Logging;
@ -52,6 +52,7 @@ namespace PlumbingRepair
services.AddTransient<FormStores>(); services.AddTransient<FormStores>();
services.AddTransient<FormStore>(); services.AddTransient<FormStore>();
services.AddTransient<FormStoreReplenishment>(); services.AddTransient<FormStoreReplenishment>();
services.AddTransient<FormSellWork>();
} }
} }
} }

View File

@ -12,11 +12,15 @@ namespace PlumbingRepairBusinessLogic.BusinessLogic
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
private readonly IStoreLogic _storeLogic;
private readonly IWorkStorage _workStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage) public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IWorkStorage workStorage, IStoreLogic storeLogic)
{ {
_logger = logger; _logger = logger;
_orderStorage = orderStorage; _orderStorage = orderStorage;
_storeLogic = storeLogic;
_workStorage = workStorage;
} }
public bool CreateOrder(OrderBindingModel model) public bool CreateOrder(OrderBindingModel model)
@ -43,9 +47,14 @@ namespace PlumbingRepairBusinessLogic.BusinessLogic
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus) public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
{ {
CheckModel(model); var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (model.Status + 1 != newStatus) if (viewModel == null)
{
throw new ArgumentNullException(nameof(model));
}
if (viewModel.Status + 1 != newStatus)
{ {
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect."); _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
return false; return false;
@ -53,9 +62,29 @@ namespace PlumbingRepairBusinessLogic.BusinessLogic
model.Status = newStatus; model.Status = newStatus;
if (model.Status == OrderStatus.Выдан) if (model.Status == OrderStatus.Готов)
{
model.DateImplement = DateTime.Now; model.DateImplement = DateTime.Now;
var work = _workStorage.GetElement(new() { Id = viewModel.WorkId });
if (work == null)
{
throw new ArgumentNullException(nameof(work));
}
if (!_storeLogic.AddWork(work, viewModel.Count))
{
throw new Exception($"AddWork operation failed. Store is full.");
}
}
else
{
model.DateImplement = viewModel.DateImplement;
}
CheckModel(model, false);
if (_orderStorage.Update(model) == null) if (_orderStorage.Update(model) == null)
{ {
model.Status--; model.Status--;

View File

@ -26,29 +26,34 @@ namespace PlumbingRepairBusinessLogic.BusinessLogic
if (quantity <= 0) if (quantity <= 0)
{ {
throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(quantity)); throw new ArgumentException("Количество изделий должно быть больше 0", nameof(quantity));
} }
_logger.LogInformation("AddWorkInStore. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id); _logger.LogInformation("AddWork. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id);
var element = _storeStorage.GetElement(model); var element = _storeStorage.GetElement(model);
if (element == null) if (element == null)
{ {
_logger.LogWarning("AddWorkInStore element not found"); _logger.LogWarning("AddWork element not found");
return false; return false;
} }
_logger.LogInformation("AddWorkInStore find. Id:{Id}", element.Id); if (element.WorkMaxCount - element.StoreWorks.Select(x => x.Value.Item2).Sum() < quantity)
if (element.Works.TryGetValue(work.Id, out var pair))
{ {
element.Works[work.Id] = (work, quantity + pair.Item2); throw new ArgumentNullException("Магазин переполнен", nameof(quantity));
_logger.LogInformation("AddWorkInStore. Has been added {quantity} {work} in {StoreName}", quantity, work.WorkName, element.StoreName); }
_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 else
{ {
element.Works[work.Id] = (work, quantity); element.StoreWorks[work.Id] = (work, quantity);
_logger.LogInformation("AddWorkInShop. Has been added {quantity} new Work {work} in {StoreName}", quantity, work.WorkName, element.StoreName); _logger.LogInformation("AddWork. Added {quantity} new package {package} to '{StoreName}' store", quantity, work.WorkName, element.StoreName);
} }
_storeStorage.Update(new() _storeStorage.Update(new()
@ -57,15 +62,63 @@ namespace PlumbingRepairBusinessLogic.BusinessLogic
StoreAdress = element.StoreAdress, StoreAdress = element.StoreAdress,
StoreName = element.StoreName, StoreName = element.StoreName,
OpeningDate = element.OpeningDate, OpeningDate = element.OpeningDate,
Works = element.Works WorkMaxCount = element.WorkMaxCount,
StoreWorks = element.StoreWorks
}); });
return true; 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) public bool Create(StoreBindingModel model)
{ {
CheckModel(model); CheckModel(model);
model.Works = new(); model.StoreWorks = new();
if (_storeStorage.Insert(model) == null) if (_storeStorage.Insert(model) == null)
{ {
@ -126,6 +179,11 @@ namespace PlumbingRepairBusinessLogic.BusinessLogic
return list; return list;
} }
public bool SellWork(IWorkModel work, int quantity)
{
return _storeStorage.SellWork(work, quantity);
}
public bool Update(StoreBindingModel model) public bool Update(StoreBindingModel model)
{ {
CheckModel(model, false); CheckModel(model, false);
@ -160,7 +218,13 @@ namespace PlumbingRepairBusinessLogic.BusinessLogic
throw new ArgumentNullException("Нет названия магазина", nameof(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); _logger.LogInformation("Store. StoreName:{0}.StoreAdress:{1}. Id: {2}", model.StoreName, model.StoreAdress, model.Id);
var element = _storeStorage.GetElement(new StoreSearchModel var element = _storeStorage.GetElement(new StoreSearchModel
{ {
StoreName = model.StoreName StoreName = model.StoreName

View File

@ -9,8 +9,10 @@ namespace PlumbingRepairContracts.BindingModels
public DateTime OpeningDate { get; set; } = DateTime.Now; public DateTime OpeningDate { get; set; } = DateTime.Now;
public Dictionary<int, (IWorkModel, int)> Works { get; set; } = new(); public Dictionary<int, (IWorkModel, int)> StoreWorks { get; set; } = new();
public int Id { get; set; } public int Id { get; set; }
public int WorkMaxCount { get; set; }
} }
} }

View File

@ -13,5 +13,7 @@ namespace PlumbingRepairContracts.BusinessLogicsContracts
bool Update(StoreBindingModel model); bool Update(StoreBindingModel model);
bool Delete(StoreBindingModel model); bool Delete(StoreBindingModel model);
bool AddWork(StoreSearchModel model, IWorkModel work, int quantity); bool AddWork(StoreSearchModel model, IWorkModel work, int quantity);
bool AddWork(IWorkModel package, int quantity);
bool SellWork(IWorkModel package, int quantity);
} }
} }

View File

@ -1,6 +1,7 @@
using PlumbingRepairContracts.BindingModels; using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.SearchModels; using PlumbingRepairContracts.SearchModels;
using PlumbingRepairContracts.ViewModels; using PlumbingRepairContracts.ViewModels;
using PlumbingRepairDataModels.Models;
namespace PlumbingRepairContracts.StoragesContracts namespace PlumbingRepairContracts.StoragesContracts
{ {
@ -12,5 +13,6 @@ namespace PlumbingRepairContracts.StoragesContracts
StoreViewModel? Insert(StoreBindingModel model); StoreViewModel? Insert(StoreBindingModel model);
StoreViewModel? Update(StoreBindingModel model); StoreViewModel? Update(StoreBindingModel model);
StoreViewModel? Delete(StoreBindingModel model); StoreViewModel? Delete(StoreBindingModel model);
bool SellWork(IWorkModel model, int quantity);
} }
} }

View File

@ -5,7 +5,7 @@ namespace PlumbingRepairContracts.ViewModels
{ {
public class StoreViewModel : IStoreModel public class StoreViewModel : IStoreModel
{ {
public Dictionary<int, (IWorkModel, int)> Works { get; set; } = new(); public Dictionary<int, (IWorkModel, int)> StoreWorks { get; set; } = new();
public int Id { get; set; } public int Id { get; set; }
[DisplayName("Название магазина")] [DisplayName("Название магазина")]
@ -14,5 +14,7 @@ namespace PlumbingRepairContracts.ViewModels
public string StoreAdress { get; set; } = string.Empty; public string StoreAdress { get; set; } = string.Empty;
[DisplayName("Дата открытия")] [DisplayName("Дата открытия")]
public DateTime OpeningDate { get; set; } = DateTime.Now; public DateTime OpeningDate { get; set; } = DateTime.Now;
[DisplayName("Вместимость магазина")]
public int WorkMaxCount { get; set; }
} }
} }

View File

@ -5,6 +5,7 @@
public string StoreName { get; } public string StoreName { get; }
public string StoreAdress { get; } public string StoreAdress { get; }
DateTime OpeningDate { get; } DateTime OpeningDate { get; }
Dictionary<int, (IWorkModel, int)> Works { get; } Dictionary<int, (IWorkModel, int)> StoreWorks { get; }
public int WorkMaxCount { get; }
} }
} }

View File

@ -2,6 +2,7 @@
using PlumbingRepairContracts.SearchModels; using PlumbingRepairContracts.SearchModels;
using PlumbingRepairContracts.StoragesContracts; using PlumbingRepairContracts.StoragesContracts;
using PlumbingRepairContracts.ViewModels; using PlumbingRepairContracts.ViewModels;
using PlumbingRepairDataModels.Models;
using PlumbingRepairListImplement.Models; using PlumbingRepairListImplement.Models;
namespace PlumbingRepairListImplement.Implements namespace PlumbingRepairListImplement.Implements
@ -101,6 +102,11 @@ namespace PlumbingRepairListImplement.Implements
return newStore.GetViewModel; return newStore.GetViewModel;
} }
public bool SellWork(IWorkModel model, int quantity)
{
throw new NotImplementedException();
}
public StoreViewModel? Update(StoreBindingModel model) public StoreViewModel? Update(StoreBindingModel model)
{ {
foreach (var store in _source.Stores) foreach (var store in _source.Stores)

View File

@ -13,7 +13,7 @@ namespace PlumbingRepairListImplement.Models
public DateTime OpeningDate { get; private set; } public DateTime OpeningDate { get; private set; }
public Dictionary<int, (IWorkModel, int)> Works { get; private set; } = new(); public Dictionary<int, (IWorkModel, int)> StoreWorks { get; private set; } = new();
public int Id { get; private set; } public int Id { get; private set; }
@ -29,7 +29,7 @@ namespace PlumbingRepairListImplement.Models
StoreName = model.StoreName, StoreName = model.StoreName,
StoreAdress = model.StoreAdress, StoreAdress = model.StoreAdress,
OpeningDate = model.OpeningDate, OpeningDate = model.OpeningDate,
Works = new() StoreWorks = new()
}; };
} }
@ -42,7 +42,7 @@ namespace PlumbingRepairListImplement.Models
StoreName = model.StoreName; StoreName = model.StoreName;
StoreAdress = model.StoreAdress; StoreAdress = model.StoreAdress;
OpeningDate = model.OpeningDate; OpeningDate = model.OpeningDate;
Works = model.Works; StoreWorks = model.StoreWorks;
} }
public StoreViewModel GetViewModel => new() public StoreViewModel GetViewModel => new()
@ -51,7 +51,9 @@ namespace PlumbingRepairListImplement.Models
StoreName = StoreName, StoreName = StoreName,
StoreAdress = StoreAdress, StoreAdress = StoreAdress,
OpeningDate = OpeningDate, OpeningDate = OpeningDate,
Works = Works StoreWorks = StoreWorks
}; };
public int WorkMaxCount => throw new NotImplementedException();
} }
} }

View File

@ -0,0 +1,61 @@
using PlumbingRepairFileImplement.Models;
using System.Xml.Linq;
using static System.Formats.Asn1.AsnWriter;
namespace PlumbingRepairFileImplement
{
public class DataFileSingleton
{
private static DataFileSingleton? instance;
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()
{
if (instance == null)
{
instance = new DataFileSingleton();
}
return instance;
}
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)
{
if (File.Exists(filename))
{
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
}
return new List<T>();
}
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
{
if (data != null)
{
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
}
}
}
}

View File

@ -0,0 +1,89 @@
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.SearchModels;
using PlumbingRepairContracts.StoragesContracts;
using PlumbingRepairContracts.ViewModels;
using PlumbingRepairFileImplement.Models;
namespace PlumbingRepairFileImplement.Implements
{
public class ComponentStorage : IComponentStorage
{
private readonly DataFileSingleton source;
public ComponentStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<ComponentViewModel> GetFullList()
{
return source.Components.Select(x => x.GetViewModel).ToList();
}
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
{
if (string.IsNullOrEmpty(model.ComponentName))
{
return new();
}
return source.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;
}
return source.Components.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public ComponentViewModel? Insert(ComponentBindingModel model)
{
model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
var newComponent = Component.Create(model);
if (newComponent == null)
{
return null;
}
source.Components.Add(newComponent);
source.SaveComponents();
return newComponent.GetViewModel;
}
public ComponentViewModel? Update(ComponentBindingModel model)
{
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
if (component == null)
{
return null;
}
component.Update(model);
source.SaveComponents();
return component.GetViewModel;
}
public ComponentViewModel? Delete(ComponentBindingModel model)
{
var element = source.Components.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Components.Remove(element);
source.SaveComponents();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,89 @@
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.SearchModels;
using PlumbingRepairContracts.StoragesContracts;
using PlumbingRepairContracts.ViewModels;
using PlumbingRepairFileImplement.Models;
namespace PlumbingRepairFileImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly DataFileSingleton source;
public OrderStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<OrderViewModel> GetFullList()
{
return source.Orders.Select(x => x.GetViewModel).ToList();
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
return source.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public OrderViewModel? Insert(OrderBindingModel model)
{
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
var newOrder = Order.Create(model);
if (newOrder == null)
{
return null;
}
source.Orders.Add(newOrder);
source.SaveOrders();
return newOrder.GetViewModel;
}
public OrderViewModel? Update(OrderBindingModel model)
{
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
source.SaveOrders();
return order.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Orders.Remove(element);
source.SaveOrders();
return element.GetViewModel;
}
return null;
}
}
}

View File

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

View File

@ -0,0 +1,89 @@
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.SearchModels;
using PlumbingRepairContracts.StoragesContracts;
using PlumbingRepairContracts.ViewModels;
using PlumbingRepairFileImplement.Models;
namespace PlumbingRepairFileImplement.Implements
{
public class WorkStorage : IWorkStorage
{
private readonly DataFileSingleton source;
public WorkStorage()
{
source = DataFileSingleton.GetInstance();
}
public List<WorkViewModel> GetFullList()
{
return source.Works.Select(x => x.GetViewModel).ToList();
}
public List<WorkViewModel> GetFilteredList(WorkSearchModel model)
{
if (string.IsNullOrEmpty(model.WorkName))
{
return new();
}
return source.Works.Where(x => x.WorkName.Contains(model.WorkName)).Select(x => x.GetViewModel).ToList();
}
public WorkViewModel? GetElement(WorkSearchModel model)
{
if (string.IsNullOrEmpty(model.WorkName) && !model.Id.HasValue)
{
return null;
}
return source.Works.FirstOrDefault(x => (!string.IsNullOrEmpty(model.WorkName) && x.WorkName == model.WorkName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public WorkViewModel? Insert(WorkBindingModel model)
{
model.Id = source.Works.Count > 0 ? source.Works.Max(x => x.Id) + 1 : 1;
var newWork = Work.Create(model);
if (newWork == null)
{
return null;
}
source.Works.Add(newWork);
source.SaveWorks();
return newWork.GetViewModel;
}
public WorkViewModel? Update(WorkBindingModel model)
{
var work = source.Works.FirstOrDefault(x => x.Id == model.Id);
if (work == null)
{
return null;
}
work.Update(model);
source.SaveWorks();
return work.GetViewModel;
}
public WorkViewModel? Delete(WorkBindingModel model)
{
var element = source.Works.FirstOrDefault(x => x.Id == model.Id);
if (element != null)
{
source.Works.Remove(element);
source.SaveWorks();
return element.GetViewModel;
}
return null;
}
}
}

View File

@ -0,0 +1,64 @@
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.ViewModels;
using PlumbingRepairDataModels.Models;
using System.Xml.Linq;
namespace PlumbingRepairFileImplement.Models
{
public class Component : IComponentModel
{
public int Id { get; private set; }
public string ComponentName { get; private set; } = string.Empty;
public double Cost { get; set; }
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(XElement element)
{
if (element == null)
{
return null;
}
return new Component()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
ComponentName = element.Element("ComponentName")!.Value,
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
};
}
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
};
public XElement GetXElement => new("Component",
new XAttribute("Id", Id),
new XElement("ComponentName", ComponentName),
new XElement("Cost", Cost.ToString()));
}
}

View File

@ -0,0 +1,100 @@
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.ViewModels;
using PlumbingRepairDataModels.Enums;
using PlumbingRepairDataModels.Models;
using System.Xml.Linq;
namespace PlumbingRepairFileImplement.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;
public int Count { get; private set; }
public double Sum { get; private set; }
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
public DateTime DateCreate { get; private set; } = DateTime.Now;
public DateTime? DateImplement { get; private set; }
public static Order? Create(OrderBindingModel model)
{
if (model == null)
{
return null;
}
return new Order()
{
Id = model.Id,
WorkId = model.WorkId,
WorkName = model.WorkName,
Count = model.Count,
Sum = model.Sum,
Status = model.Status,
DateCreate = model.DateCreate,
DateImplement = model.DateImplement
};
}
public static Order? Create(XElement element)
{
if (element == null)
{
return null;
}
var order = new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
WorkId = Convert.ToInt32(element.Element("WorkId")!.Value),
WorkName = element.Element("WorkName")!.Value,
Count = Convert.ToInt32(element.Element("Count")!.Value),
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null)
};
DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl);
order.DateImplement = dateImpl;
return order;
}
public void Update(OrderBindingModel model)
{
if (model == null)
{
return;
}
WorkId = model.WorkId;
WorkName = model.WorkName;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
WorkId = WorkId,
WorkName = WorkName,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement
};
public XElement GetXElement => new("Order",
new XAttribute("Id", Id),
new XElement("WorkName", WorkName),
new XElement("WorkId", WorkId.ToString()),
new XElement("Count", Count.ToString()),
new XElement("Sum", Sum.ToString()),
new XElement("Status", Status.ToString()),
new XElement("DateCreate", DateCreate.ToString()),
new XElement("DateImplement", DateImplement.ToString()));
}
}

View File

@ -0,0 +1,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()));
}
}

View File

@ -0,0 +1,91 @@
using PlumbingRepairContracts.BindingModels;
using PlumbingRepairContracts.ViewModels;
using PlumbingRepairDataModels.Models;
using System.Xml.Linq;
namespace PlumbingRepairFileImplement.Models
{
public class Work : IWorkModel
{
public int Id { get; private set; }
public string WorkName { get; private set; } = string.Empty;
public double Price { get; private set; }
public Dictionary<int, int> Components { get; private set; } = new();
public Dictionary<int, (IComponentModel, int)> _workComponents = null;
public Dictionary<int, (IComponentModel, int)> WorkComponents
{
get
{
if (_workComponents == null)
{
var source = DataFileSingleton.GetInstance();
_workComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
}
return _workComponents;
}
}
public static Work? Create(WorkBindingModel model)
{
if (model == null)
{
return null;
}
return new Work()
{
Id = model.Id,
WorkName = model.WorkName,
Price = model.Price,
Components = model.WorkComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
public static Work? Create(XElement element)
{
if (element == null)
{
return null;
}
return new Work()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
WorkName = element.Element("WorkName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
Components = element.Element("WorkComponents")!.Elements("WorkComponent").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(WorkBindingModel model)
{
if (model == null)
{
return;
}
WorkName = model.WorkName;
Price = model.Price;
Components = model.WorkComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
_workComponents = null;
}
public WorkViewModel GetViewModel => new()
{
Id = Id,
WorkName = WorkName,
Price = Price,
WorkComponents = WorkComponents
};
public XElement GetXElement => new("Work",
new XAttribute("Id", Id),
new XElement("WorkName", WorkName),
new XElement("Price", Price.ToString()),
new XElement("WorkComponents", Components.Select(x =>
new XElement("WorkComponent",
new XElement("Key", x.Key),
new XElement("Value", x.Value))).ToArray()));
}
}

View File

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