diff --git a/LawFirm/LawFirm/FormMain.Designer.cs b/LawFirm/LawFirm/FormMain.Designer.cs
index a32ae7a..7af45c1 100644
--- a/LawFirm/LawFirm/FormMain.Designer.cs
+++ b/LawFirm/LawFirm/FormMain.Designer.cs
@@ -32,14 +32,15 @@
this.toolStripMenuItemCatalogs = new System.Windows.Forms.ToolStripMenuItem();
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.пакетыДокументовToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
- this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonSupplyShop = new System.Windows.Forms.Button();
+ this.buttonSellDocs = new System.Windows.Forms.Button();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@@ -78,6 +79,13 @@
this.пакетыДокументовToolStripMenuItem.Text = "Пакеты документов";
this.пакетыДокументовToolStripMenuItem.Click += new System.EventHandler(this.пакетыДокументовToolStripMenuItem_Click);
//
+ // магазиныToolStripMenuItem
+ //
+ this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
+ this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(183, 22);
+ this.магазиныToolStripMenuItem.Text = "Магазины";
+ this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
+ //
// dataGridView
//
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
@@ -137,13 +145,6 @@
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.buttonRef_Click);
//
- // магазиныToolStripMenuItem
- //
- this.магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem";
- this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(183, 22);
- this.магазиныToolStripMenuItem.Text = "Магазины";
- this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
- //
// buttonSupplyShop
//
this.buttonSupplyShop.Location = new System.Drawing.Point(742, 187);
@@ -154,11 +155,22 @@
this.buttonSupplyShop.UseVisualStyleBackColor = true;
this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click);
//
+ // buttonSellDocs
+ //
+ this.buttonSellDocs.Location = new System.Drawing.Point(742, 216);
+ this.buttonSellDocs.Name = "buttonSellDocs";
+ this.buttonSellDocs.Size = new System.Drawing.Size(156, 23);
+ this.buttonSellDocs.TabIndex = 8;
+ this.buttonSellDocs.Text = "Продать документы";
+ this.buttonSellDocs.UseVisualStyleBackColor = true;
+ this.buttonSellDocs.Click += new System.EventHandler(this.buttonSellDocs_Click);
+ //
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(910, 477);
+ this.Controls.Add(this.buttonSellDocs);
this.Controls.Add(this.buttonSupplyShop);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonIssuedOrder);
@@ -193,5 +205,6 @@
private Button buttonRef;
private ToolStripMenuItem магазиныToolStripMenuItem;
private Button buttonSupplyShop;
+ private Button buttonSellDocs;
}
}
\ No newline at end of file
diff --git a/LawFirm/LawFirm/FormMain.cs b/LawFirm/LawFirm/FormMain.cs
index bcfbaf6..fff1971 100644
--- a/LawFirm/LawFirm/FormMain.cs
+++ b/LawFirm/LawFirm/FormMain.cs
@@ -194,5 +194,14 @@ namespace LawFirmView
form.ShowDialog();
}
}
+
+ private void buttonSellDocs_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormSellDocuments));
+ if (service is FormSellDocuments form)
+ {
+ form.ShowDialog();
+ }
+ }
}
}
diff --git a/LawFirm/LawFirm/FormSellDocuments.Designer.cs b/LawFirm/LawFirm/FormSellDocuments.Designer.cs
new file mode 100644
index 0000000..07cbb98
--- /dev/null
+++ b/LawFirm/LawFirm/FormSellDocuments.Designer.cs
@@ -0,0 +1,120 @@
+namespace LawFirmView
+{
+ partial class FormSellDocuments
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.comboBoxDoc = new System.Windows.Forms.ComboBox();
+ this.label1 = new System.Windows.Forms.Label();
+ this.textBoxCount = new System.Windows.Forms.TextBox();
+ this.label2 = new System.Windows.Forms.Label();
+ this.buttonSell = new System.Windows.Forms.Button();
+ this.buttonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // comboBoxDoc
+ //
+ this.comboBoxDoc.FormattingEnabled = true;
+ this.comboBoxDoc.Location = new System.Drawing.Point(149, 12);
+ this.comboBoxDoc.Name = "comboBoxDoc";
+ this.comboBoxDoc.Size = new System.Drawing.Size(218, 23);
+ this.comboBoxDoc.TabIndex = 0;
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(24, 15);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(110, 15);
+ this.label1.TabIndex = 1;
+ this.label1.Text = "Пакет документов:";
+ //
+ // textBoxCount
+ //
+ this.textBoxCount.Location = new System.Drawing.Point(149, 41);
+ this.textBoxCount.Name = "textBoxCount";
+ this.textBoxCount.Size = new System.Drawing.Size(218, 23);
+ this.textBoxCount.TabIndex = 2;
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(59, 49);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(75, 15);
+ this.label2.TabIndex = 4;
+ this.label2.Text = "Количество:";
+ //
+ // buttonSell
+ //
+ this.buttonSell.Location = new System.Drawing.Point(149, 92);
+ this.buttonSell.Name = "buttonSell";
+ this.buttonSell.Size = new System.Drawing.Size(75, 23);
+ this.buttonSell.TabIndex = 5;
+ this.buttonSell.Text = "Продать";
+ this.buttonSell.UseVisualStyleBackColor = true;
+ this.buttonSell.Click += new System.EventHandler(this.buttonSell_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(259, 92);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(75, 23);
+ this.buttonCancel.TabIndex = 6;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
+ //
+ // FormSellDocuments
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(394, 137);
+ this.Controls.Add(this.buttonCancel);
+ this.Controls.Add(this.buttonSell);
+ this.Controls.Add(this.label2);
+ this.Controls.Add(this.textBoxCount);
+ this.Controls.Add(this.label1);
+ this.Controls.Add(this.comboBoxDoc);
+ this.Name = "FormSellDocuments";
+ this.Text = "FormSellDocuments";
+ this.Load += new System.EventHandler(this.FormSellDocuments_Load);
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private ComboBox comboBoxDoc;
+ private Label label1;
+ private TextBox textBoxCount;
+ private Label label2;
+ private Button buttonSell;
+ private Button buttonCancel;
+ }
+}
\ No newline at end of file
diff --git a/LawFirm/LawFirm/FormSellDocuments.cs b/LawFirm/LawFirm/FormSellDocuments.cs
new file mode 100644
index 0000000..7019304
--- /dev/null
+++ b/LawFirm/LawFirm/FormSellDocuments.cs
@@ -0,0 +1,94 @@
+using LawFirmContracts.BusinessLogicsContracts;
+using Microsoft.Extensions.Logging;
+using LawFirmContracts.BindingModels;
+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 FormSellDocuments : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IDocumentLogic _logicDocument;
+ private readonly IShopLogic _logicShop;
+ public FormSellDocuments(ILogger logger, IDocumentLogic logicDocument, IShopLogic logicShop)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicDocument = logicDocument;
+ _logicShop = logicShop;
+ }
+
+ private void FormSellDocuments_Load(object sender, EventArgs e)
+ {
+ _logger.LogInformation("Загрузка документов для продажи");
+ try
+ {
+ var list = _logicDocument.ReadList(null);
+ if (list != null)
+ {
+ comboBoxDoc.DisplayMember = "DocumentName";
+ comboBoxDoc.ValueMember = "Id";
+ comboBoxDoc.DataSource = list;
+ comboBoxDoc.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 (comboBoxDoc.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите пакет документов", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Создание продажи");
+ try
+ {
+ var operationResult = _logicShop.SellDocument(
+ new DocumentBindingModel
+ {
+ Id = Convert.ToInt32(comboBoxDoc.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();
+ }
+ }
+}
diff --git a/LawFirm/LawFirm/FormSellDocuments.resx b/LawFirm/LawFirm/FormSellDocuments.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/LawFirm/LawFirm/FormSellDocuments.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/LawFirm/LawFirm/FormShop.Designer.cs b/LawFirm/LawFirm/FormShop.Designer.cs
index 7eecfa1..85f78a7 100644
--- a/LawFirm/LawFirm/FormShop.Designer.cs
+++ b/LawFirm/LawFirm/FormShop.Designer.cs
@@ -32,34 +32,36 @@
this.textBoxAddress = new System.Windows.Forms.TextBox();
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
this.dataGridView = new System.Windows.Forms.DataGridView();
+ this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.buttonSave = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
- this.Column1 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Column2 = new System.Windows.Forms.DataGridViewTextBoxColumn();
- this.Column3 = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.textBoxMaxCountDoc = new System.Windows.Forms.TextBox();
+ this.label4 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
//
// textBoxName
//
- this.textBoxName.Location = new System.Drawing.Point(122, 12);
+ this.textBoxName.Location = new System.Drawing.Point(274, 15);
this.textBoxName.Name = "textBoxName";
this.textBoxName.Size = new System.Drawing.Size(200, 23);
this.textBoxName.TabIndex = 0;
//
// textBoxAddress
//
- this.textBoxAddress.Location = new System.Drawing.Point(122, 41);
+ this.textBoxAddress.Location = new System.Drawing.Point(274, 41);
this.textBoxAddress.Name = "textBoxAddress";
this.textBoxAddress.Size = new System.Drawing.Size(200, 23);
this.textBoxAddress.TabIndex = 1;
//
// dateTimePicker
//
- this.dateTimePicker.Location = new System.Drawing.Point(122, 70);
+ this.dateTimePicker.Location = new System.Drawing.Point(274, 102);
this.dateTimePicker.Name = "dateTimePicker";
this.dateTimePicker.Size = new System.Drawing.Size(200, 23);
this.dateTimePicker.TabIndex = 2;
@@ -72,59 +74,12 @@
this.Column1,
this.Column2,
this.Column3});
- this.dataGridView.Location = new System.Drawing.Point(12, 99);
+ this.dataGridView.Location = new System.Drawing.Point(12, 155);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowTemplate.Height = 25;
this.dataGridView.Size = new System.Drawing.Size(536, 245);
this.dataGridView.TabIndex = 3;
//
- // buttonSave
- //
- this.buttonSave.Location = new System.Drawing.Point(347, 371);
- this.buttonSave.Name = "buttonSave";
- this.buttonSave.Size = new System.Drawing.Size(75, 23);
- this.buttonSave.TabIndex = 4;
- this.buttonSave.Text = "Сохранить";
- this.buttonSave.UseVisualStyleBackColor = true;
- this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
- //
- // buttonCancel
- //
- this.buttonCancel.Location = new System.Drawing.Point(445, 371);
- this.buttonCancel.Name = "buttonCancel";
- this.buttonCancel.Size = new System.Drawing.Size(75, 23);
- this.buttonCancel.TabIndex = 5;
- this.buttonCancel.Text = "Отмена";
- this.buttonCancel.UseVisualStyleBackColor = true;
- this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(42, 15);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(62, 15);
- this.label1.TabIndex = 6;
- this.label1.Text = "Название:";
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(52, 44);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(43, 15);
- this.label2.TabIndex = 7;
- this.label2.Text = "Адрес:";
- //
- // label3
- //
- this.label3.AutoSize = true;
- this.label3.Location = new System.Drawing.Point(26, 76);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(90, 15);
- this.label3.TabIndex = 8;
- this.label3.Text = "Дата открытия:";
- //
// Column1
//
this.Column1.HeaderText = "id";
@@ -141,11 +96,76 @@
this.Column3.HeaderText = "Количество";
this.Column3.Name = "Column3";
//
+ // buttonSave
+ //
+ this.buttonSave.Location = new System.Drawing.Point(346, 406);
+ this.buttonSave.Name = "buttonSave";
+ this.buttonSave.Size = new System.Drawing.Size(75, 23);
+ this.buttonSave.TabIndex = 4;
+ this.buttonSave.Text = "Сохранить";
+ this.buttonSave.UseVisualStyleBackColor = true;
+ this.buttonSave.Click += new System.EventHandler(this.buttonSave_Click);
+ //
+ // buttonCancel
+ //
+ this.buttonCancel.Location = new System.Drawing.Point(445, 406);
+ this.buttonCancel.Name = "buttonCancel";
+ this.buttonCancel.Size = new System.Drawing.Size(75, 23);
+ this.buttonCancel.TabIndex = 5;
+ this.buttonCancel.Text = "Отмена";
+ this.buttonCancel.UseVisualStyleBackColor = true;
+ this.buttonCancel.Click += new System.EventHandler(this.buttonCancel_Click);
+ //
+ // label1
+ //
+ this.label1.AutoSize = true;
+ this.label1.Location = new System.Drawing.Point(206, 18);
+ this.label1.Name = "label1";
+ this.label1.Size = new System.Drawing.Size(62, 15);
+ this.label1.TabIndex = 6;
+ this.label1.Text = "Название:";
+ //
+ // label2
+ //
+ this.label2.AutoSize = true;
+ this.label2.Location = new System.Drawing.Point(225, 44);
+ this.label2.Name = "label2";
+ this.label2.Size = new System.Drawing.Size(43, 15);
+ this.label2.TabIndex = 7;
+ this.label2.Text = "Адрес:";
+ //
+ // label3
+ //
+ this.label3.AutoSize = true;
+ this.label3.Location = new System.Drawing.Point(178, 108);
+ this.label3.Name = "label3";
+ this.label3.Size = new System.Drawing.Size(90, 15);
+ this.label3.TabIndex = 8;
+ this.label3.Text = "Дата открытия:";
+ //
+ // textBoxMaxCountDoc
+ //
+ this.textBoxMaxCountDoc.Location = new System.Drawing.Point(274, 73);
+ this.textBoxMaxCountDoc.Name = "textBoxMaxCountDoc";
+ this.textBoxMaxCountDoc.Size = new System.Drawing.Size(200, 23);
+ this.textBoxMaxCountDoc.TabIndex = 9;
+ //
+ // label4
+ //
+ this.label4.AutoSize = true;
+ this.label4.Location = new System.Drawing.Point(42, 73);
+ this.label4.Name = "label4";
+ this.label4.Size = new System.Drawing.Size(229, 15);
+ this.label4.TabIndex = 10;
+ this.label4.Text = "Максимальное количество документов:";
+ //
// FormShop
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(560, 418);
+ this.ClientSize = new System.Drawing.Size(649, 459);
+ this.Controls.Add(this.label4);
+ this.Controls.Add(this.textBoxMaxCountDoc);
this.Controls.Add(this.label3);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
@@ -178,5 +198,7 @@
private DataGridViewTextBoxColumn Column1;
private DataGridViewTextBoxColumn Column2;
private DataGridViewTextBoxColumn Column3;
+ private TextBox textBoxMaxCountDoc;
+ private Label label4;
}
}
\ No newline at end of file
diff --git a/LawFirm/LawFirm/FormShop.cs b/LawFirm/LawFirm/FormShop.cs
index c746916..a93cb19 100644
--- a/LawFirm/LawFirm/FormShop.cs
+++ b/LawFirm/LawFirm/FormShop.cs
@@ -45,6 +45,7 @@ namespace LawFirmView
{
textBoxName.Text = view.ShopName;
textBoxAddress.Text = view.Address;
+ textBoxMaxCountDoc.Text = view.MaxCountDocuments.ToString();
dateTimePicker.Value = view.OpeningDate;
_shopDocuments = view.ShopDocuments ?? new Dictionary();
LoadData();
@@ -98,6 +99,11 @@ namespace LawFirmView
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
+ if (string.IsNullOrEmpty(textBoxMaxCountDoc.Text))
+ {
+ MessageBox.Show("Заполните макс. количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
_logger.LogInformation("Сохранение магазина");
try
{
@@ -106,6 +112,7 @@ namespace LawFirmView
Id = _id ?? 0,
ShopName = textBoxName.Text,
Address = textBoxAddress.Text,
+ MaxCountDocuments = Convert.ToInt32(textBoxMaxCountDoc.Text),
OpeningDate = dateTimePicker.Value.Date,
ShopDocuments = _shopDocuments
};
diff --git a/LawFirm/LawFirm/Program.cs b/LawFirm/LawFirm/Program.cs
index 8442936..97f188b 100644
--- a/LawFirm/LawFirm/Program.cs
+++ b/LawFirm/LawFirm/Program.cs
@@ -52,6 +52,7 @@ namespace LawFirmView
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
}
}
diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogic/OrderLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogic/OrderLogic.cs
index 049f29a..0ec9401 100644
--- a/LawFirm/LawFirmBusinessLogic/BusinessLogic/OrderLogic.cs
+++ b/LawFirm/LawFirmBusinessLogic/BusinessLogic/OrderLogic.cs
@@ -4,6 +4,7 @@ using LawFirmContracts.SearchModels;
using LawFirmContracts.StoragesContracts;
using LawFirmContracts.ViewModels;
using LawFirmDataModels.Enums;
+using LawFirmDataModels.Models;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
@@ -17,11 +18,17 @@ namespace LawFirmBusinessLogic.BusinessLogic
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
+ private readonly IShopStorage _shopStorage;
+ private readonly IShopLogic _shopLogic;
+ private readonly IDocumentStorage _documentStorage;
- public OrderLogic(ILogger logger, IOrderStorage orderStorage)
+ public OrderLogic(ILogger logger, IOrderStorage orderStorage, IShopLogic shopLogic, IDocumentStorage documentStorage, IShopStorage shopStorage)
{
_logger = logger;
_orderStorage = orderStorage;
+ _shopLogic = shopLogic;
+ _documentStorage = documentStorage;
+ _shopStorage = shopStorage;
}
public List? ReadList(OrderSearchModel? model)
@@ -45,6 +52,7 @@ namespace LawFirmBusinessLogic.BusinessLogic
model.Status = OrderStatus.Принят;
if (_orderStorage.Insert(model) == null)
{
+ model.Status = OrderStatus.Неизвестен;
_logger.LogWarning("Insert operation failed");
return false;
}
@@ -53,7 +61,7 @@ namespace LawFirmBusinessLogic.BusinessLogic
public bool ChangeStatus(OrderBindingModel model, OrderStatus status)
{
- CheckModel(model);
+ CheckModel(model, false);
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (element == null)
{
@@ -65,9 +73,31 @@ namespace LawFirmBusinessLogic.BusinessLogic
_logger.LogWarning("Status change operation failed");
throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный");
}
+ if (status == OrderStatus.Готов)
+ {
+ var document = _documentStorage.GetElement(new DocumentSearchModel() { Id = model.DocumentId });
+ if (document == null)
+ {
+ _logger.LogWarning("Status change operation failed. Car not found.");
+ return false;
+ }
+
+ if (!CheckThenSupplyMany(document, model.Count))
+ {
+ _logger.LogWarning("Status change operation failed. Shop supply error.");
+ return false;
+ }
+ }
+
model.Status = status;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
_orderStorage.Update(model);
+ if (_orderStorage.Update(model) == null)
+ {
+ model.Status--;
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
return true;
}
@@ -97,6 +127,10 @@ true)
{
return;
}
+ if (model.DocumentId < 0)
+ {
+ throw new ArgumentNullException("Некорректный идентификатор документа", nameof(model.DocumentId));
+ }
if (model.Sum <= 0)
{
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
@@ -107,5 +141,67 @@ true)
}
_logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id);
}
+ public bool CheckThenSupplyMany(IDocumentModel document, int count)
+ {
+ if (count <= 0)
+ {
+ _logger.LogWarning("Check then supply operation error. Car count < 0.");
+ return false;
+ }
+
+ int freeSpace = 0;
+ foreach (var shop in _shopStorage.GetFullList())
+ {
+ freeSpace += shop.MaxCountDocuments;
+ foreach (var c in shop.ShopDocuments)
+ {
+ freeSpace -= c.Value.Item2;
+ }
+ }
+
+ if (freeSpace < count)
+ {
+ _logger.LogWarning("Check then supply operation error. There's no place for new cars in shops.");
+ return false;
+ }
+
+ foreach (var shop in _shopStorage.GetFullList())
+ {
+ freeSpace = shop.MaxCountDocuments;
+
+ foreach (var c in shop.ShopDocuments)
+ freeSpace -= c.Value.Item2;
+
+ if (freeSpace <= 0)
+ continue;
+
+ if (freeSpace >= count)
+ {
+ if (_shopLogic.SupplyDocuments(new ShopSearchModel() { Id = shop.Id }, document, count))
+ count = 0;
+ else
+ {
+ _logger.LogWarning("Supply error");
+ return false;
+ }
+ }
+ if (freeSpace < count)
+ {
+ if (_shopLogic.SupplyDocuments(new ShopSearchModel() { Id = shop.Id }, document, freeSpace))
+ count -= freeSpace;
+ else
+ {
+ _logger.LogWarning("Supply error");
+ return false;
+ }
+ }
+ if (count <= 0)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
}
}
diff --git a/LawFirm/LawFirmBusinessLogic/BusinessLogic/ShopLogic.cs b/LawFirm/LawFirmBusinessLogic/BusinessLogic/ShopLogic.cs
index 7adc3c0..ff94463 100644
--- a/LawFirm/LawFirmBusinessLogic/BusinessLogic/ShopLogic.cs
+++ b/LawFirm/LawFirmBusinessLogic/BusinessLogic/ShopLogic.cs
@@ -112,26 +112,37 @@ namespace LawFirmBusinessLogic.BusinessLogic
return false;
}
_logger.LogInformation("AddPlaneInShop find. Id:{Id}", element.Id);
-
- if (element.ShopDocuments.TryGetValue(document.Id, out var pair))
+ int countDocuments = 0;
+ foreach (var c in element.ShopDocuments)
+ countDocuments += c.Value.Item2;
+ if (count > element.MaxCountDocuments - countDocuments)
{
- element.ShopDocuments[document.Id] = (document, count + pair.Item2);
- _logger.LogInformation("AddPlaneInShop. Added {count} {plane} to '{ShopName}' shop", count, document.DocumentName, element.ShopName);
+ _logger.LogWarning("Required shop will be overflowed");
+ return false;
}
else
{
- element.ShopDocuments[document.Id] = (document, count);
- _logger.LogInformation("AddPlaneInShop. Added {count} new plane {plane} to '{ShopName}' shop", count,document.DocumentName, element.ShopName);
- }
+ if (element.ShopDocuments.TryGetValue(document.Id, out var pair))
+ {
+ element.ShopDocuments[document.Id] = (document, count + pair.Item2);
+ _logger.LogInformation("AddPlaneInShop. Added {count} {plane} to '{ShopName}' shop", count, document.DocumentName, element.ShopName);
+ }
+ else
+ {
+ element.ShopDocuments[document.Id] = (document, count);
+ _logger.LogInformation("AddPlaneInShop. Added {count} new plane {plane} to '{ShopName}' shop", count, document.DocumentName, element.ShopName);
+ }
- _shopStorage.Update(new()
- {
- Id = element.Id,
- Address = element.Address,
- ShopName = element.ShopName,
- OpeningDate = element.OpeningDate,
- ShopDocuments = element.ShopDocuments
- });
+ _shopStorage.Update(new()
+ {
+ Id = element.Id,
+ Address = element.Address,
+ ShopName = element.ShopName,
+ MaxCountDocuments = element.MaxCountDocuments,
+ OpeningDate = element.OpeningDate,
+ ShopDocuments = element.ShopDocuments
+ });
+ }
return true;
}
private void CheckModel(ShopBindingModel model, bool withParams = true)
@@ -158,5 +169,9 @@ namespace LawFirmBusinessLogic.BusinessLogic
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
+ public bool SellDocument(IDocumentModel document, int count)
+ {
+ return _shopStorage.SellDocument(document, count);
+ }
}
}
diff --git a/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs b/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs
index 3fab584..9158390 100644
--- a/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs
+++ b/LawFirm/LawFirmContracts/BindingModels/ShopBindingModel.cs
@@ -22,5 +22,6 @@ namespace LawFirmContracts.BindingModels
get;
set;
} = new();
+ public int MaxCountDocuments { get; set; }
}
}
diff --git a/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs b/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs
index 8b2cbd2..4d97726 100644
--- a/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs
+++ b/LawFirm/LawFirmContracts/BusinessLogicsContracts/IShopLogic.cs
@@ -18,5 +18,6 @@ namespace LawFirmContracts.BusinessLogicsContracts
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool SupplyDocuments(ShopSearchModel model, IDocumentModel document, int count);
+ bool SellDocument(IDocumentModel document, int count);
}
}
diff --git a/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs b/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs
index 68515f3..c9a843b 100644
--- a/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs
+++ b/LawFirm/LawFirmContracts/StoragesContracts/IShopStorage.cs
@@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using LawFirmDataModels.Models;
namespace LawFirmContracts.StoragesContracts
{
@@ -17,5 +18,6 @@ namespace LawFirmContracts.StoragesContracts
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
+ bool SellDocument(IDocumentModel model, int count);
}
}
diff --git a/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs b/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs
index 3492d68..751a28e 100644
--- a/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs
+++ b/LawFirm/LawFirmContracts/ViewModels/ShopViewModel.cs
@@ -25,5 +25,7 @@ namespace LawFirmContracts.ViewModels
get;
set;
} = new();
+ [DisplayName("Максимальное количество пакетов документов в магазине")]
+ public int MaxCountDocuments { get; set; }
}
}
diff --git a/LawFirm/LawFirmDataModels/Models/IShopModel.cs b/LawFirm/LawFirmDataModels/Models/IShopModel.cs
index 1a9307c..afebd62 100644
--- a/LawFirm/LawFirmDataModels/Models/IShopModel.cs
+++ b/LawFirm/LawFirmDataModels/Models/IShopModel.cs
@@ -12,5 +12,6 @@ namespace LawFirmDataModels.Models
String Address { get; }
DateTime OpeningDate { get; }
Dictionary ShopDocuments { get; }
+ int MaxCountDocuments { get; }
}
}
diff --git a/LawFirm/LawFirmFileImplement/DataFileSingleton.cs b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs
index 2641f2c..7a7263d 100644
--- a/LawFirm/LawFirmFileImplement/DataFileSingleton.cs
+++ b/LawFirm/LawFirmFileImplement/DataFileSingleton.cs
@@ -14,9 +14,12 @@ namespace LawFirmFileImplement
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string DocumentFileName = "Document.xml";
+ private readonly string ShopFileName = "Shop.xml";
+
public List Components { get; private set; }
public List Orders { get; private set; }
public List Documents { get; private set; }
+ public List Shops { get; private set; }
public static DataFileSingleton GetInstance()
{
if (instance == null)
@@ -28,12 +31,13 @@ namespace LawFirmFileImplement
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", 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()
{
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
Documents = LoadData(DocumentFileName, "Document", x => Document.Create(x)!)!;
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
- //Orders = new List();
+ Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
}
private static List? LoadData(string filename, string xmlNodeName,
Func selectFunction)
diff --git a/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs
new file mode 100644
index 0000000..f79690f
--- /dev/null
+++ b/LawFirm/LawFirmFileImplement/Implements/ShopStorage.cs
@@ -0,0 +1,137 @@
+using LawFirmContracts.BindingModels;
+using LawFirmContracts.SearchModels;
+using LawFirmContracts.StoragesContracts;
+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 GetFilteredList(ShopSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ShopName))
+ {
+ return new();
+ }
+ return source.Shops
+ .Select(x => x.GetViewModel)
+ .Where(x => x.ShopName.Contains(model.ShopName ?? string.Empty))
+ .ToList();
+ }
+
+ public List 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 shopDocuments = source.Shops.SelectMany(shop => shop.ShopDocuments.Where(c => c.Value.Item1.Id == document.Id));
+
+ int countStore = 0;
+
+ foreach (var it in shopDocuments)
+ countStore += it.Value.Item2;
+
+ if (count > countStore)
+ return false;
+
+ foreach (var shop in source.Shops)
+ {
+ var documents = shop.ShopDocuments;
+
+ foreach (var c in documents.Where(x => x.Value.Item1.Id == document.Id))
+ {
+ int min = Math.Min(c.Value.Item2, count);
+ documents[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min);
+ count -= min;
+
+ if (count <= 0)
+ break;
+ }
+
+ shop.Update(new ShopBindingModel
+ {
+ Id = shop.Id,
+ ShopName = shop.ShopName,
+ Address = shop.Address,
+ MaxCountDocuments = shop.MaxCountDocuments,
+ OpeningDate = shop.OpeningDate,
+ ShopDocuments = documents
+ });
+
+ source.SaveShops();
+
+ if (count <= 0)
+ return true;
+ }
+
+ return true;
+ }
+ }
+}
diff --git a/LawFirm/LawFirmFileImplement/Models/Shop.cs b/LawFirm/LawFirmFileImplement/Models/Shop.cs
new file mode 100644
index 0000000..9c10f48
--- /dev/null
+++ b/LawFirm/LawFirmFileImplement/Models/Shop.cs
@@ -0,0 +1,113 @@
+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 Shop : IShopModel
+ {
+ public int Id { get; private set; }
+ public string ShopName { get; private set; } = string.Empty;
+ public string Address { get; private set; } = string.Empty;
+ public int MaxCountDocuments { get; private set; }
+ public DateTime OpeningDate { get; private set; }
+ public Dictionary Documents { get; private set; } = new();
+ private Dictionary? _shopDocuments = null;
+ public Dictionary 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,
+ ShopName = model.ShopName,
+ Address = model.Address,
+ 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),
+ ShopName = element.Element("ShopName")!.Value,
+ Address = 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;
+ }
+ ShopName = model.ShopName;
+ Address = model.Address;
+ MaxCountDocuments = model.MaxCountDocuments;
+ OpeningDate = model.OpeningDate;
+ if (model.ShopDocuments.Count > 0)
+ {
+ Documents = model.ShopDocuments.ToDictionary(x => x.Key, x => x.Value.Item2);
+ _shopDocuments = null;
+ }
+ }
+ public ShopViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ShopName = ShopName,
+ Address = Address,
+ MaxCountDocuments = MaxCountDocuments,
+ OpeningDate = OpeningDate,
+ ShopDocuments = ShopDocuments,
+ };
+
+ public XElement GetXElement => new(
+ "Shop",
+ new XAttribute("Id", Id),
+ new XElement("ShopName", ShopName),
+ new XElement("Address", Address),
+ 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()));
+ }
+}
diff --git a/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs b/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs
index 0a9f551..c92528a 100644
--- a/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs
+++ b/LawFirm/LawFirmListImplement/Implements/ShopStorage.cs
@@ -3,6 +3,7 @@ using LawFirmContracts.SearchModels;
using LawFirmContracts.StoragesContracts;
using LawFirmContracts.ViewModels;
using LawFirmListImplement.Models;
+using LawFirmDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
@@ -14,6 +15,10 @@ namespace LawFirmListImplement.Implements
public class ShopStorage : IShopStorage
{
private readonly DataListSingleton _source;
+ public bool SellDocument(IDocumentModel document, int count)
+ {
+ throw new NotImplementedException();
+ }
public ShopStorage()
{
diff --git a/LawFirm/LawFirmListImplement/Models/Shop.cs b/LawFirm/LawFirmListImplement/Models/Shop.cs
index 338bc49..045bd7c 100644
--- a/LawFirm/LawFirmListImplement/Models/Shop.cs
+++ b/LawFirm/LawFirmListImplement/Models/Shop.cs
@@ -14,6 +14,7 @@ namespace LawFirmListImplement.Models
public int Id { get; private set; }
public string ShopName { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty;
+ public int MaxCountDocuments { get; private set; }
public DateTime OpeningDate { get; private set; }
public Dictionary ShopDocuments
{