Mochalov D.V. LabWork02_Hard #6
@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmContracts", "LawFirm
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmBusinessLogic", "LawFirmBusinessLogic\LawFirmBusinessLogic.csproj", "{1A498224-4BAC-48FF-B6BC-E829BF86C5E4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmListImplements", "LawFirmListImplements\LawFirmListImplements.csproj", "{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LawFirmListImplements", "LawFirmListImplements\LawFirmListImplements.csproj", "{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LawFirmFileImplement", "LawFirmFileImplement\LawFirmFileImplement.csproj", "{E75AF81D-A466-470A-A3F7-EC0E6F33C866}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -39,6 +41,10 @@ Global
|
||||
{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{43B2BE7C-83F0-4A91-B2F1-F2F2A2BE5CAE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E75AF81D-A466-470A-A3F7-EC0E6F33C866}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
19
LawFirm/LawFirm/FormMain.Designer.cs
generated
19
LawFirm/LawFirm/FormMain.Designer.cs
generated
@ -40,6 +40,7 @@
|
||||
this.buttonSetToFinish = new System.Windows.Forms.Button();
|
||||
this.buttonUpdate = new System.Windows.Forms.Button();
|
||||
this.buttonSupplyShop = new System.Windows.Forms.Button();
|
||||
this.buttonSellDocuments = new System.Windows.Forms.Button();
|
||||
this.menuStrip.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
@ -68,21 +69,21 @@
|
||||
// бланкиToolStripMenuItem
|
||||
//
|
||||
this.бланкиToolStripMenuItem.Name = "бланкиToolStripMenuItem";
|
||||
this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.бланкиToolStripMenuItem.Size = new System.Drawing.Size(170, 26);
|
||||
this.бланкиToolStripMenuItem.Text = "Бланки";
|
||||
this.бланкиToolStripMenuItem.Click += new System.EventHandler(this.бланкиToolStripMenuItem_Click);
|
||||
//
|
||||
// документыToolStripMenuItem
|
||||
//
|
||||
this.документыToolStripMenuItem.Name = "документыToolStripMenuItem";
|
||||
this.документыToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.документыToolStripMenuItem.Size = new System.Drawing.Size(170, 26);
|
||||
this.документыToolStripMenuItem.Text = "Документы";
|
||||
this.документыToolStripMenuItem.Click += new System.EventHandler(this.документыToolStripMenuItem_Click);
|
||||
//
|
||||
// магазиныToolStripMenuItem
|
||||
//
|
||||
this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
|
||||
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
|
||||
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(170, 26);
|
||||
this.магазиныToolStripMenuItem.Text = "Магазины";
|
||||
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
|
||||
//
|
||||
@ -156,11 +157,22 @@
|
||||
this.buttonSupplyShop.UseVisualStyleBackColor = true;
|
||||
this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click);
|
||||
//
|
||||
// buttonSellDocuments
|
||||
//
|
||||
this.buttonSellDocuments.Location = new System.Drawing.Point(933, 220);
|
||||
this.buttonSellDocuments.Name = "buttonSellDocuments";
|
||||
this.buttonSellDocuments.Size = new System.Drawing.Size(194, 29);
|
||||
this.buttonSellDocuments.TabIndex = 8;
|
||||
this.buttonSellDocuments.Text = "Продажа документов";
|
||||
this.buttonSellDocuments.UseVisualStyleBackColor = true;
|
||||
this.buttonSellDocuments.Click += new System.EventHandler(this.buttonSellDocuments_Click);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(1139, 450);
|
||||
this.Controls.Add(this.buttonSellDocuments);
|
||||
this.Controls.Add(this.buttonSupplyShop);
|
||||
this.Controls.Add(this.buttonUpdate);
|
||||
this.Controls.Add(this.buttonSetToFinish);
|
||||
@ -195,5 +207,6 @@
|
||||
private Button buttonUpdate;
|
||||
private ToolStripMenuItem магазиныToolStripMenuItem;
|
||||
private Button buttonSupplyShop;
|
||||
private Button buttonSellDocuments;
|
||||
}
|
||||
}
|
@ -181,5 +181,14 @@ namespace LawFirmView
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSellDocuments_Click(object sender, EventArgs e)
|
||||
{
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormShopSell));
|
||||
if (service is FormShopSell form)
|
||||
{
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
70
LawFirm/LawFirm/FormShop.Designer.cs
generated
70
LawFirm/LawFirm/FormShop.Designer.cs
generated
@ -35,11 +35,13 @@
|
||||
this.labelOpeningDate = new System.Windows.Forms.Label();
|
||||
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
|
||||
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ColumnDocumentName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.buttonSave = new System.Windows.Forms.Button();
|
||||
this.labelMaxCount = new System.Windows.Forms.Label();
|
||||
this.textBoxMaxCountDocs = new System.Windows.Forms.TextBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
@ -98,33 +100,13 @@
|
||||
this.ColumnId,
|
||||
this.ColumnDocumentName,
|
||||
this.ColumnCount});
|
||||
this.dataGridView.Location = new System.Drawing.Point(14, 138);
|
||||
this.dataGridView.Location = new System.Drawing.Point(14, 173);
|
||||
this.dataGridView.Name = "dataGridView";
|
||||
this.dataGridView.RowHeadersWidth = 51;
|
||||
this.dataGridView.RowTemplate.Height = 29;
|
||||
this.dataGridView.Size = new System.Drawing.Size(401, 300);
|
||||
this.dataGridView.Size = new System.Drawing.Size(401, 265);
|
||||
this.dataGridView.TabIndex = 10;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(228, 448);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(155, 29);
|
||||
this.buttonCancel.TabIndex = 12;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(48, 448);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(155, 29);
|
||||
this.buttonSave.TabIndex = 11;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||
//
|
||||
// ColumnId
|
||||
//
|
||||
this.ColumnId.HeaderText = "ID";
|
||||
@ -147,11 +129,49 @@
|
||||
this.ColumnCount.Name = "ColumnCount";
|
||||
this.ColumnCount.Width = 125;
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(228, 448);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(155, 29);
|
||||
this.buttonCancel.TabIndex = 12;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
this.buttonSave.Location = new System.Drawing.Point(48, 448);
|
||||
this.buttonSave.Name = "buttonSave";
|
||||
this.buttonSave.Size = new System.Drawing.Size(155, 29);
|
||||
this.buttonSave.TabIndex = 11;
|
||||
this.buttonSave.Text = "Сохранить";
|
||||
this.buttonSave.UseVisualStyleBackColor = true;
|
||||
this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
|
||||
//
|
||||
// labelMaxCount
|
||||
//
|
||||
this.labelMaxCount.AutoSize = true;
|
||||
this.labelMaxCount.Location = new System.Drawing.Point(18, 128);
|
||||
this.labelMaxCount.Name = "labelMaxCount";
|
||||
this.labelMaxCount.Size = new System.Drawing.Size(216, 20);
|
||||
this.labelMaxCount.TabIndex = 13;
|
||||
this.labelMaxCount.Text = "Макс. количество документов";
|
||||
//
|
||||
// textBoxMaxCountDocs
|
||||
//
|
||||
this.textBoxMaxCountDocs.Location = new System.Drawing.Point(240, 128);
|
||||
this.textBoxMaxCountDocs.Name = "textBoxMaxCountDocs";
|
||||
this.textBoxMaxCountDocs.Size = new System.Drawing.Size(175, 27);
|
||||
this.textBoxMaxCountDocs.TabIndex = 14;
|
||||
//
|
||||
// FormShop
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(445, 489);
|
||||
this.Controls.Add(this.textBoxMaxCountDocs);
|
||||
this.Controls.Add(this.labelMaxCount);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSave);
|
||||
this.Controls.Add(this.dataGridView);
|
||||
@ -184,5 +204,7 @@
|
||||
private DataGridViewTextBoxColumn ColumnId;
|
||||
private DataGridViewTextBoxColumn ColumnDocumentName;
|
||||
private DataGridViewTextBoxColumn ColumnCount;
|
||||
private Label labelMaxCount;
|
||||
private TextBox textBoxMaxCountDocs;
|
||||
}
|
||||
}
|
@ -50,6 +50,7 @@ namespace LawFirmView
|
||||
textBoxName.Text = view.Name;
|
||||
textBoxAddress.Text = view.Adress;
|
||||
_shopDocuments = view.ShopDocuments ?? new Dictionary<int, (IDocumentModel, int)>();
|
||||
textBoxMaxCountDocs.Text = view.MaxCountDocuments.ToString();
|
||||
LoadData();
|
||||
}
|
||||
}
|
||||
@ -102,6 +103,11 @@ namespace LawFirmView
|
||||
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(textBoxMaxCountDocs.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните макс. количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Сохранение магазина");
|
||||
try
|
||||
{
|
||||
@ -111,7 +117,7 @@ namespace LawFirmView
|
||||
Name = textBoxName.Text,
|
||||
Adress = textBoxAddress.Text,
|
||||
OpeningDate = dateTimePicker.Value.Date,
|
||||
ShopDocuments = _shopDocuments
|
||||
MaxCountDocuments = Convert.ToInt32(textBoxMaxCountDocs.Text)
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
if (!operationResult)
|
||||
|
119
LawFirm/LawFirm/FormShopSell.Designer.cs
generated
Normal file
119
LawFirm/LawFirm/FormShopSell.Designer.cs
generated
Normal file
@ -0,0 +1,119 @@
|
||||
namespace LawFirmView
|
||||
{
|
||||
partial class FormShopSell
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.labelCount = new System.Windows.Forms.Label();
|
||||
this.labelDocument = new System.Windows.Forms.Label();
|
||||
this.comboBoxDocument = new System.Windows.Forms.ComboBox();
|
||||
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||
this.buttonSell = new System.Windows.Forms.Button();
|
||||
this.buttonCancel = new System.Windows.Forms.Button();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// labelCount
|
||||
//
|
||||
this.labelCount.AutoSize = true;
|
||||
this.labelCount.Location = new System.Drawing.Point(23, 76);
|
||||
this.labelCount.Name = "labelCount";
|
||||
this.labelCount.Size = new System.Drawing.Size(93, 20);
|
||||
this.labelCount.TabIndex = 1;
|
||||
this.labelCount.Text = "Количество:";
|
||||
//
|
||||
// labelDocument
|
||||
//
|
||||
this.labelDocument.AutoSize = true;
|
||||
this.labelDocument.Location = new System.Drawing.Point(23, 24);
|
||||
this.labelDocument.Name = "labelDocument";
|
||||
this.labelDocument.Size = new System.Drawing.Size(79, 20);
|
||||
this.labelDocument.TabIndex = 2;
|
||||
this.labelDocument.Text = "Документ:";
|
||||
//
|
||||
// comboBoxDocument
|
||||
//
|
||||
this.comboBoxDocument.FormattingEnabled = true;
|
||||
this.comboBoxDocument.Location = new System.Drawing.Point(124, 24);
|
||||
this.comboBoxDocument.Name = "comboBoxDocument";
|
||||
this.comboBoxDocument.Size = new System.Drawing.Size(278, 28);
|
||||
this.comboBoxDocument.TabIndex = 4;
|
||||
//
|
||||
// textBoxCount
|
||||
//
|
||||
this.textBoxCount.Location = new System.Drawing.Point(124, 73);
|
||||
this.textBoxCount.Name = "textBoxCount";
|
||||
this.textBoxCount.Size = new System.Drawing.Size(158, 27);
|
||||
this.textBoxCount.TabIndex = 5;
|
||||
//
|
||||
// buttonSell
|
||||
//
|
||||
this.buttonSell.Location = new System.Drawing.Point(188, 142);
|
||||
this.buttonSell.Name = "buttonSell";
|
||||
this.buttonSell.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonSell.TabIndex = 6;
|
||||
this.buttonSell.Text = "Продажа";
|
||||
this.buttonSell.UseVisualStyleBackColor = true;
|
||||
this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click);
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
this.buttonCancel.Location = new System.Drawing.Point(308, 142);
|
||||
this.buttonCancel.Name = "buttonCancel";
|
||||
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
|
||||
this.buttonCancel.TabIndex = 7;
|
||||
this.buttonCancel.Text = "Отмена";
|
||||
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||
this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
|
||||
//
|
||||
// FormShopSell
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(459, 198);
|
||||
this.Controls.Add(this.buttonCancel);
|
||||
this.Controls.Add(this.buttonSell);
|
||||
this.Controls.Add(this.textBoxCount);
|
||||
this.Controls.Add(this.comboBoxDocument);
|
||||
this.Controls.Add(this.labelDocument);
|
||||
this.Controls.Add(this.labelCount);
|
||||
this.Name = "FormShopSell";
|
||||
this.Text = "Продажа из магазина";
|
||||
this.Load += new System.EventHandler(this.FormShopSell_Load);
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
}
|
||||
|
||||
#endregion
|
||||
private Label labelCount;
|
||||
private Label labelDocument;
|
||||
private ComboBox comboBoxDocument;
|
||||
private TextBox textBoxCount;
|
||||
private Button buttonSell;
|
||||
private Button buttonCancel;
|
||||
}
|
||||
}
|
96
LawFirm/LawFirm/FormShopSell.cs
Normal file
96
LawFirm/LawFirm/FormShopSell.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.BusinessLogicContracts;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace LawFirmView
|
||||
{
|
||||
public partial class FormShopSell : Form
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IDocumentLogic _logicD;
|
||||
private readonly IShopLogic _logicS;
|
||||
|
||||
public FormShopSell(ILogger<FormShopSell> logger, IDocumentLogic logicD, IShopLogic logicS)
|
||||
{
|
||||
InitializeComponent();
|
||||
_logger = logger;
|
||||
_logicD = logicD;
|
||||
_logicS = logicS;
|
||||
}
|
||||
|
||||
private void FormShopSell_Load(object sender, EventArgs e)
|
||||
{
|
||||
_logger.LogInformation("Загрузка документов для продажи");
|
||||
try
|
||||
{
|
||||
var list = _logicD.ReadList(null);
|
||||
if (list != null)
|
||||
{
|
||||
comboBoxDocument.DisplayMember = "DocumentName";
|
||||
comboBoxDocument.ValueMember = "Id";
|
||||
comboBoxDocument.DataSource = list;
|
||||
comboBoxDocument.SelectedItem = null;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки списка документов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonSell_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
if (comboBoxDocument.SelectedValue == null)
|
||||
{
|
||||
MessageBox.Show("Выберите документ", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Создание продажи");
|
||||
try
|
||||
{
|
||||
var operationResult = _logicS.SellDocument(
|
||||
new DocumentBindingModel
|
||||
{
|
||||
Id = Convert.ToInt32(comboBoxDocument.SelectedValue)
|
||||
},
|
||||
Convert.ToInt32(textBoxCount.Text)
|
||||
);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при создании продажи. Дополнительная информация в логах.");
|
||||
}
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка создания продажи");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void buttonCancel_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
60
LawFirm/LawFirm/FormShopSell.resx
Normal file
60
LawFirm/LawFirm/FormShopSell.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>
|
@ -17,6 +17,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\LawFirmBusinessLogic\LawFirmBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\LawFirmContracts\LawFirmContracts.csproj" />
|
||||
<ProjectReference Include="..\LawFirmFileImplement\LawFirmFileImplement.csproj" />
|
||||
<ProjectReference Include="..\LawFirmListImplements\LawFirmListImplements.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
using LawFirmBusinessLogic.BusinessLogics;
|
||||
using LawFirmContracts.BusinessLogicContracts;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmListImplements.Implements;
|
||||
using LawFirmFileImplement.Implements;
|
||||
using LawFirmView;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@ -56,6 +56,7 @@ namespace LawFirm
|
||||
services.AddTransient<FormShop>();
|
||||
services.AddTransient<FormShops>();
|
||||
services.AddTransient<FormShopSupply>();
|
||||
services.AddTransient<FormShopSell>();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmDataModels.Enums;
|
||||
using LawFirmDataModels.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -17,11 +18,18 @@ namespace LawFirmBusinessLogic.BusinessLogics
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IShopStorage _shopStorage;
|
||||
private readonly IShopLogic _shopLogic;
|
||||
private readonly IDocumentStorage _documentStorage;
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopLogic shopLogic, IDocumentStorage documentStorage, IShopStorage shopStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
_shopLogic = shopLogic;
|
||||
_documentStorage = documentStorage;
|
||||
_shopStorage = shopStorage;
|
||||
}
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
@ -72,6 +80,22 @@ namespace LawFirmBusinessLogic.BusinessLogics
|
||||
_logger.LogWarning("Status update to " + newStatus.ToString() +" operation failed. Order status incorrect.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (newStatus == OrderStatus.Готов)
|
||||
{
|
||||
var document = _documentStorage.GetElement(new DocumentSearchModel() { Id = model.DocumentId});
|
||||
if (document == null)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Document not found.");
|
||||
return false;
|
||||
}
|
||||
if (CheckThenSupplyMany(document, model.Count) == false)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Shop supply error.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
model.Status = newStatus;
|
||||
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
|
||||
if (_orderStorage.Update(model) == null)
|
||||
@ -83,6 +107,67 @@ namespace LawFirmBusinessLogic.BusinessLogics
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CheckThenSupplyMany(IDocumentModel document, int count)
|
||||
{
|
||||
if (count <= 0)
|
||||
{
|
||||
_logger.LogWarning("Check then supply operation error. Document count < 0.");
|
||||
return false;
|
||||
}
|
||||
|
||||
int freeSpace = 0;
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
freeSpace += shop.MaxCountDocuments;
|
||||
foreach (var doc in shop.ShopDocuments)
|
||||
{
|
||||
freeSpace -= doc.Value.Item2;
|
||||
}
|
||||
}
|
||||
|
||||
if (freeSpace - count < 0)
|
||||
{
|
||||
_logger.LogWarning("Check then supply operation error. There's no place for new docs in shops.");
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var shop in _shopStorage.GetFullList())
|
||||
{
|
||||
freeSpace = shop.MaxCountDocuments;
|
||||
foreach (var doc in shop.ShopDocuments)
|
||||
{
|
||||
freeSpace -= doc.Value.Item2;
|
||||
}
|
||||
if (freeSpace == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (freeSpace - count >= 0)
|
||||
{
|
||||
if (_shopLogic.SupplyDocuments(new() { Id = shop.Id }, document, count)) count = 0;
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Supply error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (freeSpace - count < 0)
|
||||
{
|
||||
if (_shopLogic.SupplyDocuments(new() { Id = shop.Id }, document, freeSpace)) count -= freeSpace;
|
||||
else
|
||||
{
|
||||
_logger.LogWarning("Supply error");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (count <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
return StatusUpdate(model, OrderStatus.Выполняется);
|
||||
|
@ -82,29 +82,46 @@ namespace LawFirmBusinessLogic.BusinessLogics
|
||||
}
|
||||
_logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name);
|
||||
|
||||
if (shopElement.ShopDocuments.TryGetValue(document.Id, out var sameDocument))
|
||||
var countDocs = 0;
|
||||
foreach (var doc in shopElement.ShopDocuments)
|
||||
{
|
||||
shopElement.ShopDocuments[document.Id] = (document, sameDocument.Item2 + count);
|
||||
_logger.LogInformation("Same document found by supply. Added {0} of {1} in {2} shop", count, document.DocumentName, shopElement.Name);
|
||||
countDocs += doc.Value.Item2;
|
||||
}
|
||||
if (shopElement.MaxCountDocuments - countDocs >= count)
|
||||
{
|
||||
if (shopElement.ShopDocuments.TryGetValue(document.Id, out var sameDocument))
|
||||
{
|
||||
shopElement.ShopDocuments[document.Id] = (document, sameDocument.Item2 + count);
|
||||
_logger.LogInformation("Same document found by supply. Added {0} of {1} in {2} shop", count, document.DocumentName, shopElement.Name);
|
||||
}
|
||||
else
|
||||
{
|
||||
shopElement.ShopDocuments[document.Id] = (document, count);
|
||||
_logger.LogInformation("New document added by supply. Added {0} of {1} in {2} shop", count, document.DocumentName, shopElement.Name);
|
||||
}
|
||||
_shopStorage.Update(new()
|
||||
{
|
||||
Id = shopElement.Id,
|
||||
Name = shopElement.Name,
|
||||
Adress = shopElement.Adress,
|
||||
OpeningDate = shopElement.OpeningDate,
|
||||
ShopDocuments = shopElement.ShopDocuments,
|
||||
MaxCountDocuments = shopElement.MaxCountDocuments
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
shopElement.ShopDocuments[document.Id] = (document, count);
|
||||
_logger.LogInformation("New document added by supply. Added {0} of {1} in {2} shop", count, document.DocumentName, shopElement.Name);
|
||||
_logger.LogWarning("Required shop is overflowed");
|
||||
return false;
|
||||
}
|
||||
|
||||
_shopStorage.Update(new()
|
||||
{
|
||||
Id = shopElement.Id,
|
||||
Name = shopElement.Name,
|
||||
Adress = shopElement.Adress,
|
||||
OpeningDate = shopElement.OpeningDate,
|
||||
ShopDocuments = shopElement.ShopDocuments
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool SellDocument(IDocumentModel document, int count)
|
||||
{;
|
||||
return _shopStorage.SellDocument(document, count);
|
||||
}
|
||||
|
||||
public bool Create(ShopBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
@ -154,6 +171,10 @@ namespace LawFirmBusinessLogic.BusinessLogics
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия магазина!", nameof(model.Name));
|
||||
}
|
||||
if (model.MaxCountDocuments < 0)
|
||||
{
|
||||
throw new InvalidOperationException("Магазин с отрицательным количеством максимального количества документов!");
|
||||
}
|
||||
_logger.LogInformation("Shop. Name: {0}, Adress: {1}, ID: {2}", model.Name, model.Adress, model.Id);
|
||||
var element = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
|
@ -18,5 +18,7 @@ namespace LawFirmContracts.BindingModels
|
||||
public Dictionary<int, (IDocumentModel, int)> ShopDocuments { get; set; } = new();
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public int MaxCountDocuments { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -18,5 +18,6 @@ namespace LawFirmContracts.BusinessLogicContracts
|
||||
bool Update(ShopBindingModel model);
|
||||
bool Delete(ShopBindingModel model);
|
||||
bool SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count);
|
||||
bool SellDocument(IDocumentModel document, int count);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@ -17,5 +18,6 @@ namespace LawFirmContracts.StorageContracts
|
||||
ShopViewModel? Insert(ShopBindingModel model);
|
||||
ShopViewModel? Update(ShopBindingModel model);
|
||||
ShopViewModel? Delete(ShopBindingModel model);
|
||||
bool SellDocument(IDocumentModel model, int count);
|
||||
}
|
||||
}
|
||||
|
@ -20,5 +20,8 @@ namespace LawFirmContracts.ViewModels
|
||||
public Dictionary<int, (IDocumentModel, int)> ShopDocuments { get; set; } = new();
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
[DisplayName("Макс. документов в магазине")]
|
||||
public int MaxCountDocuments { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -12,5 +12,6 @@ namespace LawFirmDataModels.Models
|
||||
String Adress { get; }
|
||||
DateTime OpeningDate { get; }
|
||||
Dictionary<int, (IDocumentModel, int)> ShopDocuments { get; }
|
||||
int MaxCountDocuments { get; }
|
||||
}
|
||||
}
|
||||
|
60
LawFirm/LawFirmFileImplement/DataFileSingleton.cs
Normal file
60
LawFirm/LawFirmFileImplement/DataFileSingleton.cs
Normal file
@ -0,0 +1,60 @@
|
||||
using LawFirmFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace LawFirmFileImplement
|
||||
{
|
||||
public class DataFileSingleton
|
||||
{
|
||||
private static DataFileSingleton? instance;
|
||||
private readonly string BlankFileName = "Blank.xml";
|
||||
private readonly string OrderFileName = "Order.xml";
|
||||
private readonly string DocumentFileName = "Document.xml";
|
||||
private readonly string ShopFileName = "Shop.xml";
|
||||
public List<Blank> Blanks { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Document> Documents { get; private set; }
|
||||
public List<Shop> Shops { get; private set; }
|
||||
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new DataFileSingleton();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
public void SaveBlanks() => SaveData(Blanks, BlankFileName, "Blanks", x => x.GetXElement);
|
||||
public void SaveDocuments() => SaveData(Documents, DocumentFileName, "Documents", x => x.GetXElement);
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Blanks = LoadData(BlankFileName, "Blank", x => Blank.Create(x)!)!;
|
||||
Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||
}
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
{
|
||||
if (File.Exists(filename))
|
||||
{
|
||||
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
||||
}
|
||||
return new List<T>();
|
||||
}
|
||||
|
||||
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
88
LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs
Normal file
88
LawFirm/LawFirmFileImplement/Implements/BlankStorage.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LawFirmFileImplement.Implements
|
||||
{
|
||||
public class BlankStorage : IBlankStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public BlankStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public BlankViewModel? GetElement(BlankSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.BlankName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Blanks
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.BlankName) && x.BlankName == model.BlankName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<BlankViewModel> GetFilteredList(BlankSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.BlankName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Blanks
|
||||
.Where(x => x.BlankName.Contains(model.BlankName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<BlankViewModel> GetFullList()
|
||||
{
|
||||
return source.Blanks.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public BlankViewModel? Insert(BlankBindingModel model)
|
||||
{
|
||||
model.Id = source.Blanks.Count > 0 ? source.Blanks.Max(x => x.Id) + 1 : 1;
|
||||
var newBlank = Blank.Create(model);
|
||||
if (newBlank == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Blanks.Add(newBlank);
|
||||
source.SaveBlanks();
|
||||
return newBlank.GetViewModel;
|
||||
}
|
||||
|
||||
public BlankViewModel? Update(BlankBindingModel model)
|
||||
{
|
||||
var blank = source.Blanks.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (blank == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
blank.Update(model);
|
||||
source.SaveBlanks();
|
||||
return blank.GetViewModel;
|
||||
}
|
||||
public BlankViewModel? Delete(BlankBindingModel model)
|
||||
{
|
||||
var blank = source.Blanks.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (blank == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Blanks.Remove(blank);
|
||||
source.SaveBlanks();
|
||||
return blank.GetViewModel;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
88
LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs
Normal file
88
LawFirm/LawFirmFileImplement/Implements/DocumentStorage.cs
Normal file
@ -0,0 +1,88 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace LawFirmFileImplement.Implements
|
||||
{
|
||||
public class DocumentStorage : IDocumentStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public DocumentStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public DocumentViewModel? GetElement(DocumentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.DocumentName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Documents
|
||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.DocumentName) && x.DocumentName == model.DocumentName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<DocumentViewModel> GetFilteredList(DocumentSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.DocumentName))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Documents
|
||||
.Where(x => x.DocumentName.Contains(model.DocumentName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<DocumentViewModel> GetFullList()
|
||||
{
|
||||
return source.Documents.Select(x => x.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public DocumentViewModel? Insert(DocumentBindingModel model)
|
||||
{
|
||||
model.Id = source.Documents.Count > 0 ? source.Documents.Max(x => x.Id) + 1 : 1;
|
||||
var newDoc = Document.Create(model);
|
||||
if (newDoc == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Documents.Add(newDoc);
|
||||
source.SaveDocuments();
|
||||
return newDoc.GetViewModel;
|
||||
}
|
||||
|
||||
public DocumentViewModel? Update(DocumentBindingModel model)
|
||||
{
|
||||
var document = source.Documents.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (document == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
document.Update(model);
|
||||
source.SaveDocuments();
|
||||
return document.GetViewModel;
|
||||
}
|
||||
public DocumentViewModel? Delete(DocumentBindingModel model)
|
||||
{
|
||||
var document = source.Documents.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (document == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Documents.Remove(document);
|
||||
source.SaveDocuments();
|
||||
return document.GetViewModel;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
98
LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs
Normal file
98
LawFirm/LawFirmFileImplement/Implements/OrderStorage.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LawFirmFileImplement.Implements
|
||||
{
|
||||
public class OrderStorage : IOrderStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
|
||||
public OrderStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return GetViewModel(source.Orders
|
||||
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id)));
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Orders
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => GetViewModel(x))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<OrderViewModel> GetFullList()
|
||||
{
|
||||
return source.Orders.Select(x => GetViewModel(x)).ToList();
|
||||
}
|
||||
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||
var newOrder = Order.Create(model);
|
||||
if (newOrder == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Orders.Add(newOrder);
|
||||
source.SaveOrders();
|
||||
return GetViewModel(newOrder);
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
order.Update(model);
|
||||
source.SaveOrders();
|
||||
return GetViewModel(order);
|
||||
}
|
||||
public OrderViewModel? Delete(OrderBindingModel model)
|
||||
{
|
||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Orders.Remove(order);
|
||||
source.SaveOrders();
|
||||
return GetViewModel(order);
|
||||
}
|
||||
|
||||
private OrderViewModel GetViewModel(Order order)
|
||||
{
|
||||
var viewModel = order.GetViewModel;
|
||||
var document = source.Documents.FirstOrDefault(x => x.Id == order.DocumentId);
|
||||
if (document != null)
|
||||
{
|
||||
viewModel.DocumentName = document.DocumentName;
|
||||
}
|
||||
return viewModel;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
148
LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs
Normal file
148
LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs
Normal file
@ -0,0 +1,148 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmDataModels.Models;
|
||||
using LawFirmFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LawFirmFileImplement.Implements
|
||||
{
|
||||
public class ShopStorage : IShopStorage
|
||||
{
|
||||
private readonly DataFileSingleton source;
|
||||
public ShopStorage()
|
||||
{
|
||||
source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.Name))
|
||||
{
|
||||
return new();
|
||||
}
|
||||
return source.Shops
|
||||
.Select(x => x.GetViewModel)
|
||||
.Where(x => x.Name.Contains(model.Name ?? string.Empty))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ShopViewModel> GetFullList()
|
||||
{
|
||||
return source.Shops.Select(shop => shop.GetViewModel).ToList();
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel model)
|
||||
{
|
||||
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
|
||||
var newShop = Shop.Create(model);
|
||||
if (newShop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Shops.Add(newShop);
|
||||
source.SaveShops();
|
||||
return newShop.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Update(ShopBindingModel model)
|
||||
{
|
||||
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
shop.Update(model);
|
||||
source.SaveShops();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
public ShopViewModel? Delete(ShopBindingModel model)
|
||||
{
|
||||
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||
if (shop == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
source.Shops.Remove(shop);
|
||||
source.SaveShops();
|
||||
return shop.GetViewModel;
|
||||
}
|
||||
|
||||
public bool SellDocument(IDocumentModel model, int count)
|
||||
{
|
||||
var document = source.Documents.FirstOrDefault(x => x.Id == model.Id);
|
||||
|
||||
if (document == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var countStore = count;
|
||||
|
||||
var shopDocuments = source.Shops.SelectMany(shop => shop.ShopDocuments.Where(doc => doc.Value.Item1.Id == document.Id));
|
||||
|
||||
foreach (var doc in shopDocuments)
|
||||
|
||||
{
|
||||
count -= doc.Value.Item2;
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
count = countStore;
|
||||
|
||||
foreach (var shop in source.Shops)
|
||||
{
|
||||
var documents = shop.ShopDocuments;
|
||||
|
||||
foreach (var doc in documents.Where(x => x.Value.Item1.Id == document.Id))
|
||||
{
|
||||
var min = Math.Min(doc.Value.Item2, count);
|
||||
documents[doc.Value.Item1.Id] = (doc.Value.Item1, doc.Value.Item2 - min);
|
||||
count -= min;
|
||||
|
||||
if (count <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
shop.Update(new ShopBindingModel
|
||||
{
|
||||
Id = shop.Id,
|
||||
Name = shop.Name,
|
||||
Adress = shop.Adress,
|
||||
OpeningDate = shop.OpeningDate,
|
||||
MaxCountDocuments = shop.MaxCountDocuments,
|
||||
ShopDocuments = documents
|
||||
});
|
||||
|
||||
source.SaveShops();
|
||||
|
||||
if (count <= 0) break;
|
||||
}
|
||||
|
||||
return count <= 0;
|
||||
}
|
||||
}
|
||||
}
|
14
LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj
Normal file
14
LawFirm/LawFirmFileImplement/LawFirmFileImplement.csproj
Normal 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="..\LawFirmContracts\LawFirmContracts.csproj" />
|
||||
<ProjectReference Include="..\LawFirmDataModels\LawFirmDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
74
LawFirm/LawFirmFileImplement/Models/Blank.cs
Normal file
74
LawFirm/LawFirmFileImplement/Models/Blank.cs
Normal file
@ -0,0 +1,74 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace LawFirmFileImplement.Models
|
||||
{
|
||||
public class Blank : IBlankModel
|
||||
{
|
||||
public string BlankName { get; private set; } = String.Empty;
|
||||
|
||||
public double Cost { get; set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public static Blank? Create(BlankBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Blank()
|
||||
{
|
||||
Id = model.Id,
|
||||
BlankName = model.BlankName,
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
public static Blank? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Blank()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
BlankName = element.Element("BlankName")!.Value,
|
||||
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(BlankBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
BlankName = model.BlankName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
public BlankViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
BlankName = BlankName,
|
||||
Cost = Cost
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Blank",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("BlankName", BlankName),
|
||||
new XElement("Cost", Cost.ToString())
|
||||
);
|
||||
|
||||
}
|
||||
}
|
105
LawFirm/LawFirmFileImplement/Models/Document.cs
Normal file
105
LawFirm/LawFirmFileImplement/Models/Document.cs
Normal file
@ -0,0 +1,105 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace LawFirmFileImplement.Models
|
||||
{
|
||||
public class Document : IDocumentModel
|
||||
{
|
||||
public string DocumentName { get; private set; } = string.Empty;
|
||||
|
||||
public double Price { get; private set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public Dictionary<int, int> Blanks { get; private set; } = new();
|
||||
|
||||
private Dictionary<int, (IBlankModel, int)>? _documentBlanks = null;
|
||||
public Dictionary<int, (IBlankModel, int)> DocumentBlanks
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_documentBlanks == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_documentBlanks = Blanks.ToDictionary(
|
||||
x => x.Key,
|
||||
y => ((source.Blanks.FirstOrDefault(z => z.Id == y.Key) as IBlankModel)!, y.Value)
|
||||
);
|
||||
}
|
||||
return _documentBlanks;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Document? Create(DocumentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Document()
|
||||
{
|
||||
Id = model.Id,
|
||||
DocumentName = model.DocumentName,
|
||||
Price = model.Price,
|
||||
Blanks = model.DocumentBlanks.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
|
||||
public static Document? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Document()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
DocumentName = element.Element("DocumentName")!.Value,
|
||||
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||
Blanks = element.Element("DocumentBlanks")!.Elements("DocumentBlank").ToDictionary(
|
||||
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value)
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void Update(DocumentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
DocumentName = model.DocumentName;
|
||||
Price = model.Price;
|
||||
Blanks = model.DocumentBlanks.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_documentBlanks = null;
|
||||
}
|
||||
public DocumentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
DocumentName = DocumentName,
|
||||
Price = Price,
|
||||
DocumentBlanks = DocumentBlanks
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Document",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("DocumentName", DocumentName),
|
||||
new XElement("Price", Price.ToString()),
|
||||
new XElement("DocumentBlanks", Blanks.Select(x =>
|
||||
new XElement("DocumentBlank",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value)))
|
||||
.ToArray()));
|
||||
}
|
||||
}
|
98
LawFirm/LawFirmFileImplement/Models/Order.cs
Normal file
98
LawFirm/LawFirmFileImplement/Models/Order.cs
Normal file
@ -0,0 +1,98 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmDataModels.Enums;
|
||||
using LawFirmDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace LawFirmFileImplement.Models
|
||||
{
|
||||
public class Order : IOrderModel
|
||||
{
|
||||
public int DocumentId { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||
|
||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; private set; }
|
||||
|
||||
public int Id { get; private set; }
|
||||
|
||||
public static Order? Create(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order
|
||||
{
|
||||
DocumentId = model.DocumentId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
DateCreate = model.DateCreate,
|
||||
DateImplement = model.DateImplement,
|
||||
Id = model.Id,
|
||||
};
|
||||
}
|
||||
|
||||
public static Order? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Order()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
DocumentId = Convert.ToInt32(element.Element("DocumentId")!.Value),
|
||||
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
|
||||
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value)
|
||||
};
|
||||
}
|
||||
|
||||
public void Update(OrderBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Status = model.Status;
|
||||
DateImplement = model.DateImplement;
|
||||
}
|
||||
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
DocumentId = DocumentId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
DateCreate = DateCreate,
|
||||
DateImplement = DateImplement,
|
||||
Id = Id,
|
||||
Status = Status,
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Order",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("DocumentId", DocumentId.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())
|
||||
);
|
||||
}
|
||||
}
|
124
LawFirm/LawFirmFileImplement/Models/Shop.cs
Normal file
124
LawFirm/LawFirmFileImplement/Models/Shop.cs
Normal file
@ -0,0 +1,124 @@
|
||||
using LawFirmContracts.BindingModels;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace LawFirmFileImplement.Models
|
||||
{
|
||||
public class Shop : IShopModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public string Name { get; private set; } = string.Empty;
|
||||
|
||||
public string Adress { get; private set; } = string.Empty;
|
||||
|
||||
public int MaxCountDocuments { get; private set; }
|
||||
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
|
||||
public Dictionary<int, int> Documents { get; private set; } = new();
|
||||
|
||||
private Dictionary<int, (IDocumentModel, int)>? _shopDocuments = null;
|
||||
|
||||
public Dictionary<int, (IDocumentModel, int)> ShopDocuments
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_shopDocuments == null)
|
||||
{
|
||||
var source = DataFileSingleton.GetInstance();
|
||||
_shopDocuments = Documents.ToDictionary(
|
||||
x => x.Key,
|
||||
y => ((source.Documents.FirstOrDefault(z => z.Id == y.Key) as IDocumentModel)!, y.Value)
|
||||
);
|
||||
}
|
||||
return _shopDocuments;
|
||||
}
|
||||
}
|
||||
|
||||
public static Shop? Create(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Shop()
|
||||
{
|
||||
Id = model.Id,
|
||||
Name = model.Name,
|
||||
Adress = model.Adress,
|
||||
MaxCountDocuments = model.MaxCountDocuments,
|
||||
OpeningDate = model.OpeningDate,
|
||||
Documents = model.ShopDocuments.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||
};
|
||||
}
|
||||
|
||||
public static Shop? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Shop()
|
||||
{
|
||||
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||
Name = element.Element("Name")!.Value,
|
||||
Adress = element.Element("Address")!.Value,
|
||||
MaxCountDocuments = Convert.ToInt32(element.Element("MaxCountDocuments")!.Value),
|
||||
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
|
||||
Documents= element.Element("ShopDocuments")!.Elements("ShopDocument").ToDictionary(
|
||||
x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||
x => Convert.ToInt32(x.Element("Value")?.Value)
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public void Update(ShopBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Name = model.Name;
|
||||
Adress = model.Adress;
|
||||
OpeningDate = model.OpeningDate;
|
||||
MaxCountDocuments = model.MaxCountDocuments;
|
||||
if (model.ShopDocuments.Count > 0)
|
||||
{
|
||||
Documents = model.ShopDocuments.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||
_shopDocuments = null;
|
||||
}
|
||||
}
|
||||
public ShopViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
Name = Name,
|
||||
Adress = Adress,
|
||||
OpeningDate = OpeningDate,
|
||||
ShopDocuments = ShopDocuments,
|
||||
MaxCountDocuments = MaxCountDocuments
|
||||
};
|
||||
|
||||
public XElement GetXElement => new(
|
||||
"Shop",
|
||||
new XAttribute("Id", Id),
|
||||
new XElement("Name", Name),
|
||||
new XElement("Address", Adress),
|
||||
new XElement("MaxCountDocuments", MaxCountDocuments),
|
||||
new XElement("OpeningDate", OpeningDate.ToString()),
|
||||
new XElement("ShopDocuments", Documents.Select (x =>
|
||||
new XElement("ShopDocument",
|
||||
new XElement("Key", x.Key),
|
||||
new XElement("Value", x.Value)))
|
||||
.ToArray()));
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using LawFirmContracts.SearchModels;
|
||||
using LawFirmContracts.StorageContracts;
|
||||
using LawFirmContracts.ViewModels;
|
||||
using LawFirmDataModels.Models;
|
||||
using LawFirmListImplements.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -116,5 +117,9 @@ namespace LawFirmListImplements.Implements
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool SellDocument(IDocumentModel model, int count)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ namespace LawFirmListImplements.Models
|
||||
|
||||
public DateTime OpeningDate { get; private set; }
|
||||
|
||||
public int MaxCountDocuments { get; private set; }
|
||||
|
||||
public Dictionary<int, (IDocumentModel, int)> ShopDocuments { get; private set; } = new();
|
||||
|
||||
public static Shop? Create (ShopBindingModel model)
|
||||
@ -35,6 +37,7 @@ namespace LawFirmListImplements.Models
|
||||
Name = model.Name,
|
||||
Adress = model.Adress,
|
||||
OpeningDate = model.OpeningDate,
|
||||
MaxCountDocuments = model.MaxCountDocuments,
|
||||
ShopDocuments = new()
|
||||
};
|
||||
}
|
||||
@ -49,6 +52,7 @@ namespace LawFirmListImplements.Models
|
||||
Adress = model.Adress;
|
||||
OpeningDate = model.OpeningDate;
|
||||
ShopDocuments = model.ShopDocuments;
|
||||
MaxCountDocuments= model.MaxCountDocuments;
|
||||
}
|
||||
|
||||
public ShopViewModel GetViewModel => new()
|
||||
@ -57,7 +61,10 @@ namespace LawFirmListImplements.Models
|
||||
Name = Name,
|
||||
Adress = Adress,
|
||||
OpeningDate = OpeningDate,
|
||||
ShopDocuments = ShopDocuments
|
||||
ShopDocuments = ShopDocuments,
|
||||
MaxCountDocuments = MaxCountDocuments
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user
Значение можно получить через LINQ-запрос