diff --git a/JewelryStore/FormJewels.cs b/JewelryStore/FormJewels.cs
index 5f5f06f..5d0a48a 100644
--- a/JewelryStore/FormJewels.cs
+++ b/JewelryStore/FormJewels.cs
@@ -40,12 +40,12 @@ namespace JewelryStore
}
- _logger.LogInformation("Загрузка компонентов");
+ _logger.LogInformation("Загрузка изделий");
}
catch (Exception ex)
{
- _logger.LogError(ex, "Ошибка загрузки компонентов");
+ _logger.LogError(ex, "Ошибка загрузки изделий");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
diff --git a/JewelryStore/FormMain.Designer.cs b/JewelryStore/FormMain.Designer.cs
index 4988313..8b01902 100644
--- a/JewelryStore/FormMain.Designer.cs
+++ b/JewelryStore/FormMain.Designer.cs
@@ -1,176 +1,211 @@
namespace JewelryStore
{
- partial class FormMain
- {
- ///
- /// 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)
+
+ partial class FormMain
{
- if (disposing && (components != null))
+ ///
+ /// 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)
{
- components.Dispose();
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
}
- base.Dispose(disposing);
- }
- #region Windows Form Designer generated code
+ #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.buttonReady = new System.Windows.Forms.Button();
- this.dataGridView = new System.Windows.Forms.DataGridView();
- this.buttonCreate = new System.Windows.Forms.Button();
- this.buttonToWork = new System.Windows.Forms.Button();
- this.buttonPut = new System.Windows.Forms.Button();
- this.buttonRefresh = new System.Windows.Forms.Button();
- this.menuStrip = new System.Windows.Forms.MenuStrip();
- this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
- this.menuStrip.SuspendLayout();
- this.SuspendLayout();
- //
- // buttonReady
- //
- this.buttonReady.Location = new System.Drawing.Point(1273, 225);
- this.buttonReady.Name = "buttonReady";
- this.buttonReady.Size = new System.Drawing.Size(215, 34);
- this.buttonReady.TabIndex = 3;
- this.buttonReady.Text = "Заказ готов";
- this.buttonReady.UseVisualStyleBackColor = true;
- this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click);
- //
- // dataGridView
- //
- this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
- this.dataGridView.Location = new System.Drawing.Point(9, 52);
- this.dataGridView.Name = "dataGridView";
- this.dataGridView.RowHeadersWidth = 62;
- this.dataGridView.RowTemplate.Height = 33;
- this.dataGridView.Size = new System.Drawing.Size(1227, 386);
- this.dataGridView.TabIndex = 0;
- //
- // buttonCreate
- //
- this.buttonCreate.Location = new System.Drawing.Point(1273, 52);
- this.buttonCreate.Name = "buttonCreate";
- this.buttonCreate.Size = new System.Drawing.Size(215, 34);
- this.buttonCreate.TabIndex = 1;
- this.buttonCreate.Text = "Создать заказ";
- this.buttonCreate.UseVisualStyleBackColor = true;
- this.buttonCreate.Click += new System.EventHandler(this.buttonCreate_Click);
- //
- // buttonToWork
- //
- this.buttonToWork.Location = new System.Drawing.Point(1273, 137);
- this.buttonToWork.Name = "buttonToWork";
- this.buttonToWork.Size = new System.Drawing.Size(215, 34);
- this.buttonToWork.TabIndex = 2;
- this.buttonToWork.Text = "Отдать на выполнение";
- this.buttonToWork.UseVisualStyleBackColor = true;
- this.buttonToWork.Click += new System.EventHandler(this.buttonToWork_Click);
- //
- // buttonPut
- //
- this.buttonPut.Location = new System.Drawing.Point(1273, 308);
- this.buttonPut.Name = "buttonPut";
- this.buttonPut.Size = new System.Drawing.Size(215, 34);
- this.buttonPut.TabIndex = 4;
- this.buttonPut.Text = "Заказ выдан";
- this.buttonPut.UseVisualStyleBackColor = true;
- this.buttonPut.Click += new System.EventHandler(this.buttonPut_Click);
- //
- // buttonRefresh
- //
- this.buttonRefresh.Location = new System.Drawing.Point(1273, 389);
- this.buttonRefresh.Name = "buttonRefresh";
- this.buttonRefresh.Size = new System.Drawing.Size(215, 34);
- this.buttonRefresh.TabIndex = 5;
- this.buttonRefresh.Text = "Обновить список";
- this.buttonRefresh.UseVisualStyleBackColor = true;
- this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click);
- //
- // menuStrip
- //
- this.menuStrip.ImageScalingSize = new System.Drawing.Size(24, 24);
- this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.справочникиToolStripMenuItem});
- this.menuStrip.Location = new System.Drawing.Point(0, 0);
- this.menuStrip.Name = "menuStrip";
- this.menuStrip.Size = new System.Drawing.Size(1530, 33);
- this.menuStrip.TabIndex = 6;
- this.menuStrip.Text = "menuStrip1";
- //
- // справочникиToolStripMenuItem
- //
- this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.компонентыToolStripMenuItem,
- this.изделияToolStripMenuItem});
- this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
- this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29);
- this.справочникиToolStripMenuItem.Text = "Справочники";
- //
- // компонентыToolStripMenuItem
- //
- this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
- this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(240, 34);
- this.компонентыToolStripMenuItem.Text = "Компоненты";
- this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click);
- //
- // изделияToolStripMenuItem
- //
- this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
- this.изделияToolStripMenuItem.Size = new System.Drawing.Size(240, 34);
- this.изделияToolStripMenuItem.Text = "Драгоценности";
- this.изделияToolStripMenuItem.Click += new System.EventHandler(this.драгоценностиToolStripMenuItem_Click);
- //
- // FormMain
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(1530, 450);
- this.Controls.Add(this.buttonRefresh);
- this.Controls.Add(this.buttonPut);
- this.Controls.Add(this.buttonReady);
- this.Controls.Add(this.buttonToWork);
- this.Controls.Add(this.buttonCreate);
- this.Controls.Add(this.dataGridView);
- this.Controls.Add(this.menuStrip);
- this.MainMenuStrip = this.menuStrip;
- this.Name = "FormMain";
- this.Text = "Изготовление Драгоценностей";
- this.Load += new System.EventHandler(this.FormMain_Load);
- ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
- this.menuStrip.ResumeLayout(false);
- this.menuStrip.PerformLayout();
- this.ResumeLayout(false);
- this.PerformLayout();
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.MenuStrip = new System.Windows.Forms.MenuStrip();
+ this.СправочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.StoreToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.DataGridView = new System.Windows.Forms.DataGridView();
+ this.CreateOrderButton = new System.Windows.Forms.Button();
+ this.TakeOrderInWorkButton = new System.Windows.Forms.Button();
+ this.OrderReadyButton = new System.Windows.Forms.Button();
+ this.IssuedOrderButton = new System.Windows.Forms.Button();
+ this.UpdateListButton = new System.Windows.Forms.Button();
+ this.StoreReplenishment = new System.Windows.Forms.Button();
+ this.SellJewelButton = new System.Windows.Forms.Button();
+ this.MenuStrip.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // MenuStrip
+ //
+ this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.СправочникиToolStripMenuItem});
+ this.MenuStrip.Location = new System.Drawing.Point(0, 0);
+ this.MenuStrip.Name = "MenuStrip";
+ this.MenuStrip.Size = new System.Drawing.Size(865, 24);
+ this.MenuStrip.TabIndex = 0;
+ this.MenuStrip.Text = "menuStrip1";
+ //
+ // СправочникиToolStripMenuItem
+ //
+ this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.ИзделияToolStripMenuItem,
+ this.КомпонентыToolStripMenuItem,
+ this.StoreToolStripMenuItem});
+ this.СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem";
+ this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
+ this.СправочникиToolStripMenuItem.Text = "Cправочники";
+ //
+ // ИзделияToolStripMenuItem
+ //
+ this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem";
+ this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.ИзделияToolStripMenuItem.Text = "Изделия";
+ this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
+ //
+ // КомпонентыToolStripMenuItem
+ //
+ this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
+ this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.КомпонентыToolStripMenuItem.Text = "Компоненты";
+ this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
+ //
+ // StoreToolStripMenuItem
+ //
+ this.StoreToolStripMenuItem.Name = "StoreToolStripMenuItem";
+ this.StoreToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
+ this.StoreToolStripMenuItem.Text = "Магазины";
+ this.StoreToolStripMenuItem.Click += new System.EventHandler(this.StoreToolStripMenuItem_Click);
+ //
+ // DataGridView
+ //
+ this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.DataGridView.Location = new System.Drawing.Point(0, 27);
+ this.DataGridView.Name = "DataGridView";
+ this.DataGridView.RowTemplate.Height = 25;
+ this.DataGridView.Size = new System.Drawing.Size(722, 421);
+ this.DataGridView.TabIndex = 1;
+ //
+ // CreateOrderButton
+ //
+ this.CreateOrderButton.Location = new System.Drawing.Point(728, 28);
+ this.CreateOrderButton.Name = "CreateOrderButton";
+ this.CreateOrderButton.Size = new System.Drawing.Size(125, 33);
+ this.CreateOrderButton.TabIndex = 2;
+ this.CreateOrderButton.Text = "Создать заказ";
+ this.CreateOrderButton.UseVisualStyleBackColor = true;
+ this.CreateOrderButton.Click += new System.EventHandler(this.CreateOrderButton_Click);
+ //
+ // TakeOrderInWorkButton
+ //
+ this.TakeOrderInWorkButton.Location = new System.Drawing.Point(728, 83);
+ this.TakeOrderInWorkButton.Name = "TakeOrderInWorkButton";
+ this.TakeOrderInWorkButton.Size = new System.Drawing.Size(125, 39);
+ this.TakeOrderInWorkButton.TabIndex = 3;
+ this.TakeOrderInWorkButton.Text = "Отдать на выполнение";
+ this.TakeOrderInWorkButton.UseVisualStyleBackColor = true;
+ this.TakeOrderInWorkButton.Click += new System.EventHandler(this.TakeOrderInWorkButton_Click);
+ //
+ // OrderReadyButton
+ //
+ this.OrderReadyButton.Location = new System.Drawing.Point(728, 146);
+ this.OrderReadyButton.Name = "OrderReadyButton";
+ this.OrderReadyButton.Size = new System.Drawing.Size(125, 33);
+ this.OrderReadyButton.TabIndex = 4;
+ this.OrderReadyButton.Text = "Заказ готов";
+ this.OrderReadyButton.UseVisualStyleBackColor = true;
+ this.OrderReadyButton.Click += new System.EventHandler(this.OrderReadyButton_Click);
+ //
+ // IssuedOrderButton
+ //
+ this.IssuedOrderButton.Location = new System.Drawing.Point(728, 204);
+ this.IssuedOrderButton.Name = "IssuedOrderButton";
+ this.IssuedOrderButton.Size = new System.Drawing.Size(125, 33);
+ this.IssuedOrderButton.TabIndex = 5;
+ this.IssuedOrderButton.Text = "Заказ выдан";
+ this.IssuedOrderButton.UseVisualStyleBackColor = true;
+ this.IssuedOrderButton.Click += new System.EventHandler(this.IssuedOrderButton_Click);
+ //
+ // UpdateListButton
+ //
+ this.UpdateListButton.Location = new System.Drawing.Point(728, 262);
+ this.UpdateListButton.Name = "UpdateListButton";
+ this.UpdateListButton.Size = new System.Drawing.Size(125, 33);
+ this.UpdateListButton.TabIndex = 6;
+ this.UpdateListButton.Text = "Обновить список";
+ this.UpdateListButton.UseVisualStyleBackColor = true;
+ this.UpdateListButton.Click += new System.EventHandler(this.UpdateListButton_Click);
+ //
+ // StoreReplenishment
+ //
+ this.StoreReplenishment.Location = new System.Drawing.Point(728, 317);
+ this.StoreReplenishment.Name = "StoreReplenishment";
+ this.StoreReplenishment.Size = new System.Drawing.Size(125, 50);
+ this.StoreReplenishment.TabIndex = 7;
+ this.StoreReplenishment.Text = "Пополнение магазина";
+ this.StoreReplenishment.UseVisualStyleBackColor = true;
+ this.StoreReplenishment.Click += new System.EventHandler(this.StoreReplenishment_Click);
+ //
+ // SellJewelButton
+ //
+ this.SellJewelButton.Location = new System.Drawing.Point(728, 385);
+ this.SellJewelButton.Name = "SellJewelButton";
+ this.SellJewelButton.Size = new System.Drawing.Size(125, 31);
+ this.SellJewelButton.TabIndex = 8;
+ this.SellJewelButton.Text = "Продать изделие";
+ this.SellJewelButton.UseVisualStyleBackColor = true;
+ this.SellJewelButton.Click += new System.EventHandler(this.SellJewelButton_Click);
+ //
+ // FormMain
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(865, 450);
+ this.Controls.Add(this.SellJewelButton);
+ this.Controls.Add(this.StoreReplenishment);
+ this.Controls.Add(this.UpdateListButton);
+ this.Controls.Add(this.IssuedOrderButton);
+ this.Controls.Add(this.OrderReadyButton);
+ this.Controls.Add(this.TakeOrderInWorkButton);
+ this.Controls.Add(this.CreateOrderButton);
+ this.Controls.Add(this.DataGridView);
+ this.Controls.Add(this.MenuStrip);
+ this.MainMenuStrip = this.MenuStrip;
+ this.Name = "FormMain";
+ this.Text = "Установка ПО";
+ this.MenuStrip.ResumeLayout(false);
+ this.MenuStrip.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
- }
+ }
- #endregion
+ #endregion
- private DataGridView dataGridView;
- private Button buttonCreate;
- private Button buttonToWork;
- private Button buttonPut;
- private Button buttonRefresh;
- private MenuStrip menuStrip;
- private ToolStripMenuItem справочникиToolStripMenuItem;
- private ToolStripMenuItem компонентыToolStripMenuItem;
- private ToolStripMenuItem изделияToolStripMenuItem;
- private Button buttonReady;
+ private MenuStrip MenuStrip;
+ private ToolStripMenuItem СправочникиToolStripMenuItem;
+ private ToolStripMenuItem ИзделияToolStripMenuItem;
+ private ToolStripMenuItem КомпонентыToolStripMenuItem;
+ private DataGridView DataGridView;
+ private Button CreateOrderButton;
+ private Button TakeOrderInWorkButton;
+ private Button OrderReadyButton;
+ private Button IssuedOrderButton;
+ private Button UpdateListButton;
+ private ToolStripMenuItem StoreToolStripMenuItem;
+ private Button StoreReplenishment;
+ private Button SellJewelButton;
+
}
}
\ No newline at end of file
diff --git a/JewelryStore/FormMain.cs b/JewelryStore/FormMain.cs
index 3baf773..6d5821c 100644
--- a/JewelryStore/FormMain.cs
+++ b/JewelryStore/FormMain.cs
@@ -16,6 +16,7 @@ namespace JewelryStore
{
public partial class FormMain : Form
{
+
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
@@ -24,24 +25,26 @@ namespace JewelryStore
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
-
+ LoadData();
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
+
private void LoadData()
{
_logger.LogInformation("Загрузка заказов");
+
try
{
var list = _orderLogic.ReadList(null);
if (list != null)
{
- dataGridView.DataSource = list;
- dataGridView.Columns["JewelId"].Visible = false;
+ DataGridView.DataSource = list;
+ DataGridView.Columns["JewelId"].Visible = false;
}
_logger.LogInformation("Загрузка заказов");
@@ -53,16 +56,17 @@ namespace JewelryStore
}
}
- private void компонентыToolStripMenuItem_Click(object sender, EventArgs e)
+ private void КомпонентыToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
+
if (service is FormComponents form)
{
form.ShowDialog();
}
}
- private void драгоценностиToolStripMenuItem_Click(object sender, EventArgs e)
+ private void ИзделияToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormJewels));
@@ -72,9 +76,10 @@ namespace JewelryStore
}
}
- private void buttonCreate_Click(object sender, EventArgs e)
+ private void CreateOrderButton_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
+
if (service is FormCreateOrder form)
{
form.ShowDialog();
@@ -82,62 +87,66 @@ namespace JewelryStore
}
}
- private void buttonToWork_Click(object sender, EventArgs e)
+ private void TakeOrderInWorkButton_Click(object sender, EventArgs e)
{
- if (dataGridView.SelectedRows.Count == 1)
+ if (DataGridView.SelectedRows.Count == 1)
{
- int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
+
try
{
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{
Id = id,
- JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value),
- JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
- Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
- Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
- Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
- DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
+ JewelId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["JewelId"].Value),
+ JewelName = DataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
+ Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
+ Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value),
+ Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
+ DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
+
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
+
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка передачи заказа в работу");
- MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
- MessageBoxIcon.Error);
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
-
}
- private void buttonReady_Click(object sender, EventArgs e)
+ private void IssuedOrderButton_Click(object sender, EventArgs e)
{
- if (dataGridView.SelectedRows.Count == 1)
+ if (DataGridView.SelectedRows.Count == 1)
{
- int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
+
try
{
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{
Id = id,
- JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value),
- JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
- Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
- Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
- Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
- DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
+ JewelId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["JewelId"].Value),
+ JewelName = DataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
+ Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
+ Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value),
+ Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
+ DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
+
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
+
LoadData();
}
catch (Exception ex)
@@ -146,48 +155,77 @@ namespace JewelryStore
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
-
}
- private void buttonPut_Click(object sender, EventArgs e)
+ private void OrderReadyButton_Click(object sender, EventArgs e)
{
- if (dataGridView.SelectedRows.Count == 1)
+ if (DataGridView.SelectedRows.Count == 1)
{
- int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
+ int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
+
try
{
- var operationResult = _orderLogic.DeliveryOrder(new
- OrderBindingModel
+ var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
{
Id = id,
- JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value),
- JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
- Status = Enum.Parse(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
- Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
- Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
- DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
+ JewelId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["JewelId"].Value),
+ JewelName = DataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
+ Status = Enum.Parse(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
+ Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value),
+ Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
+ DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
});
+
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
+
_logger.LogInformation("Заказ №{id} выдан", id);
LoadData();
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка отметки о выдачи заказа");
- MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
- MessageBoxIcon.Error);
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
-
}
- private void buttonRefresh_Click(object sender, EventArgs e)
+ private void UpdateListButton_Click(object sender, EventArgs e)
{
LoadData();
}
+
+ private void StoreReplenishment_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment));
+
+ if (service is FormStoreReplenishment form)
+ {
+ form.ShowDialog();
+ }
+ }
+
+ private void StoreToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormStores));
+
+ if (service is FormStores form)
+ {
+ form.ShowDialog();
+ }
+ }
+
+ private void SellJewelButton_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormSellJewel));
+
+ if (service is FormSellJewel form)
+ {
+ form.ShowDialog();
+ }
+ }
}
}
diff --git a/JewelryStore/FormSellJewel.Designer.cs b/JewelryStore/FormSellJewel.Designer.cs
new file mode 100644
index 0000000..cbb72a2
--- /dev/null
+++ b/JewelryStore/FormSellJewel.Designer.cs
@@ -0,0 +1,120 @@
+namespace JewelryStore
+{
+ partial class FormSellJewel
+ {
+
+ ///
+ /// 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.JewelLabel = new System.Windows.Forms.Label();
+ this.QuantityLabel = new System.Windows.Forms.Label();
+ this.JewelСomboBox = new System.Windows.Forms.ComboBox();
+ this.QuantityTextBox = new System.Windows.Forms.TextBox();
+ this.SaveButton = new System.Windows.Forms.Button();
+ this.ButtonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // JewelLabel
+ //
+ this.JewelLabel.AutoSize = true;
+ this.JewelLabel.Location = new System.Drawing.Point(12, 18);
+ this.JewelLabel.Name = "JewelLabel";
+ this.JewelLabel.Size = new System.Drawing.Size(56, 15);
+ this.JewelLabel.TabIndex = 0;
+ this.JewelLabel.Text = "Изделие:";
+ //
+ // QuantityLabel
+ //
+ this.QuantityLabel.AutoSize = true;
+ this.QuantityLabel.Location = new System.Drawing.Point(12, 51);
+ this.QuantityLabel.Name = "QuantityLabel";
+ this.QuantityLabel.Size = new System.Drawing.Size(75, 15);
+ this.QuantityLabel.TabIndex = 1;
+ this.QuantityLabel.Text = "Количество:";
+ //
+ // JewelСomboBox
+ //
+ this.JewelСomboBox.FormattingEnabled = true;
+ this.JewelСomboBox.Location = new System.Drawing.Point(88, 15);
+ this.JewelСomboBox.Name = "JewelСomboBox";
+ this.JewelСomboBox.Size = new System.Drawing.Size(184, 23);
+ this.JewelСomboBox.TabIndex = 2;
+ //
+ // QuantityTextBox
+ //
+ this.QuantityTextBox.Location = new System.Drawing.Point(88, 48);
+ this.QuantityTextBox.Name = "QuantityTextBox";
+ this.QuantityTextBox.Size = new System.Drawing.Size(184, 23);
+ this.QuantityTextBox.TabIndex = 3;
+ //
+ // SaveButton
+ //
+ this.SaveButton.Location = new System.Drawing.Point(72, 100);
+ this.SaveButton.Name = "SaveButton";
+ this.SaveButton.Size = new System.Drawing.Size(97, 29);
+ this.SaveButton.TabIndex = 4;
+ this.SaveButton.Text = "Сохранить";
+ this.SaveButton.UseVisualStyleBackColor = true;
+ this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
+ //
+ // ButtonCancel
+ //
+ this.ButtonCancel.Location = new System.Drawing.Point(175, 100);
+ this.ButtonCancel.Name = "ButtonCancel";
+ this.ButtonCancel.Size = new System.Drawing.Size(97, 29);
+ this.ButtonCancel.TabIndex = 5;
+ this.ButtonCancel.Text = "Отмена";
+ this.ButtonCancel.UseVisualStyleBackColor = true;
+ this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FromSellJewel
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(284, 141);
+ this.Controls.Add(this.ButtonCancel);
+ this.Controls.Add(this.SaveButton);
+ this.Controls.Add(this.QuantityTextBox);
+ this.Controls.Add(this.JewelСomboBox);
+ this.Controls.Add(this.QuantityLabel);
+ this.Controls.Add(this.JewelLabel);
+ this.Name = "FromSellJewel";
+ this.Text = "Продать Изделие";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label JewelLabel;
+ private Label QuantityLabel;
+ private ComboBox JewelСomboBox;
+ private TextBox QuantityTextBox;
+ private Button SaveButton;
+ private Button ButtonCancel;
+ }
+}
\ No newline at end of file
diff --git a/JewelryStore/FormSellJewel.cs b/JewelryStore/FormSellJewel.cs
new file mode 100644
index 0000000..555e902
--- /dev/null
+++ b/JewelryStore/FormSellJewel.cs
@@ -0,0 +1,103 @@
+using JewelryStoreContracts.BusinessLogicsContracts;
+using JewelryStoreContracts.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 JewelryStore
+{
+ public partial class FormSellJewel : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IJewelLogic _logicJewel;
+ private readonly IStoreLogic _logicStore;
+ public FormSellJewel(ILogger logger, IJewelLogic logicJewel, IStoreLogic logicStore)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logicJewel = logicJewel;
+ _logicStore = logicStore;
+ LoadData();
+ }
+
+ private void FormSellJewel_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ _logger.LogInformation("Loading jewels for sale.");
+
+ try
+ {
+ var list = _logicJewel.ReadList(null);
+ if (list != null)
+ {
+ JewelСomboBox.DisplayMember = "JewelName";
+ JewelСomboBox.ValueMember = "Id";
+ JewelСomboBox.DataSource = list;
+ JewelСomboBox.SelectedItem = null;
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "List loading error.");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void SaveButton_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(QuantityTextBox.Text))
+ {
+ MessageBox.Show("Укажите количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ if (JewelСomboBox.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ _logger.LogInformation("Jewel sale.");
+
+ try
+ {
+ var operationResult = _logicStore.SellJewel(_logicJewel.ReadElement(new JewelSearchModel()
+ {
+ Id = Convert.ToInt32(JewelСomboBox.SelectedValue)
+ })!, Convert.ToInt32(QuantityTextBox.Text));
+
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при продаже изделия. Дополнительная информация в логах.");
+ }
+
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Jewel sale error.");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/JewelryStore/FormSellJewel.resx b/JewelryStore/FormSellJewel.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/JewelryStore/FormSellJewel.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/JewelryStore/FormStore.Designer.cs b/JewelryStore/FormStore.Designer.cs
new file mode 100644
index 0000000..92eca9e
--- /dev/null
+++ b/JewelryStore/FormStore.Designer.cs
@@ -0,0 +1,206 @@
+namespace JewelryStore
+{
+ partial class FormStore
+ {
+ ///
+ /// 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.StoreNameLabel = new System.Windows.Forms.Label();
+ this.StoreAdressLabel = new System.Windows.Forms.Label();
+ this.OpeningDateLabel = new System.Windows.Forms.Label();
+ this.NameComboBox = new System.Windows.Forms.ComboBox();
+ this.AdressTextBox = new System.Windows.Forms.TextBox();
+ this.DataGridView = new System.Windows.Forms.DataGridView();
+ this.JewelName = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.JewelPrice = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.JewelCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
+ this.SaveButton = new System.Windows.Forms.Button();
+ this.ButtonCancel = new System.Windows.Forms.Button();
+ this.OpeningDatePicker = new System.Windows.Forms.DateTimePicker();
+ this.VolumeNumericUpDown = new System.Windows.Forms.NumericUpDown();
+ this.JewelMaxCountLable = new System.Windows.Forms.Label();
+ ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)(this.VolumeNumericUpDown)).BeginInit();
+ this.SuspendLayout();
+ //
+ // StoreNameLabel
+ //
+ this.StoreNameLabel.AutoSize = true;
+ this.StoreNameLabel.Location = new System.Drawing.Point(12, 9);
+ this.StoreNameLabel.Name = "StoreNameLabel";
+ this.StoreNameLabel.Size = new System.Drawing.Size(119, 15);
+ this.StoreNameLabel.TabIndex = 0;
+ this.StoreNameLabel.Text = "Название магазина: ";
+ //
+ // StoreAdressLabel
+ //
+ this.StoreAdressLabel.AutoSize = true;
+ this.StoreAdressLabel.Location = new System.Drawing.Point(12, 40);
+ this.StoreAdressLabel.Name = "StoreAdressLabel";
+ this.StoreAdressLabel.Size = new System.Drawing.Size(100, 15);
+ this.StoreAdressLabel.TabIndex = 1;
+ this.StoreAdressLabel.Text = "Адрес магазина: ";
+ //
+ // OpeningDateLabel
+ //
+ this.OpeningDateLabel.AutoSize = true;
+ this.OpeningDateLabel.Location = new System.Drawing.Point(12, 72);
+ this.OpeningDateLabel.Name = "OpeningDateLabel";
+ this.OpeningDateLabel.Size = new System.Drawing.Size(93, 15);
+ this.OpeningDateLabel.TabIndex = 2;
+ this.OpeningDateLabel.Text = "Дата открытия: ";
+ //
+ // NameComboBox
+ //
+ this.NameComboBox.FormattingEnabled = true;
+ this.NameComboBox.Location = new System.Drawing.Point(137, 6);
+ this.NameComboBox.Name = "NameComboBox";
+ this.NameComboBox.Size = new System.Drawing.Size(174, 23);
+ this.NameComboBox.TabIndex = 3;
+ //
+ // AdressTextBox
+ //
+ this.AdressTextBox.Location = new System.Drawing.Point(137, 37);
+ this.AdressTextBox.Name = "AdressTextBox";
+ this.AdressTextBox.Size = new System.Drawing.Size(174, 23);
+ this.AdressTextBox.TabIndex = 4;
+ //
+ // DataGridView
+ //
+ this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.DataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
+ this.JewelName,
+ this.JewelPrice,
+ this.JewelCount});
+ this.DataGridView.Location = new System.Drawing.Point(12, 109);
+ this.DataGridView.Name = "DataGridView";
+ this.DataGridView.RowTemplate.Height = 25;
+ this.DataGridView.Size = new System.Drawing.Size(776, 288);
+ this.DataGridView.TabIndex = 6;
+ //
+ // JewelName
+ //
+ this.JewelName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
+ this.JewelName.HeaderText = "Название изделия";
+ this.JewelName.Name = "JewelName";
+ //
+ // JewelPrice
+ //
+ this.JewelPrice.HeaderText = "Цена";
+ this.JewelPrice.Name = "JewelPrice";
+ //
+ // JewelCount
+ //
+ this.JewelCount.HeaderText = "Количество";
+ this.JewelCount.Name = "JewelCount";
+ //
+ // SaveButton
+ //
+ this.SaveButton.Location = new System.Drawing.Point(552, 403);
+ this.SaveButton.Name = "SaveButton";
+ this.SaveButton.Size = new System.Drawing.Size(115, 35);
+ this.SaveButton.TabIndex = 7;
+ this.SaveButton.Text = "Сохранить";
+ this.SaveButton.UseVisualStyleBackColor = true;
+ this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
+ //
+ // ButtonCancel
+ //
+ this.ButtonCancel.Location = new System.Drawing.Point(673, 403);
+ this.ButtonCancel.Name = "ButtonCancel";
+ this.ButtonCancel.Size = new System.Drawing.Size(115, 35);
+ this.ButtonCancel.TabIndex = 8;
+ this.ButtonCancel.Text = "Отменить";
+ this.ButtonCancel.UseVisualStyleBackColor = true;
+ this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // OpeningDatePicker
+ //
+ this.OpeningDatePicker.Location = new System.Drawing.Point(137, 66);
+ this.OpeningDatePicker.Name = "OpeningDatePicker";
+ this.OpeningDatePicker.Size = new System.Drawing.Size(174, 23);
+ this.OpeningDatePicker.TabIndex = 9;
+ //
+ // VolumeNumericUpDown
+ //
+ this.VolumeNumericUpDown.Location = new System.Drawing.Point(486, 7);
+ this.VolumeNumericUpDown.Name = "VolumeNumericUpDown";
+ this.VolumeNumericUpDown.Size = new System.Drawing.Size(168, 23);
+ this.VolumeNumericUpDown.TabIndex = 10;
+ //
+ // JewelMaxCountLable
+ //
+ this.JewelMaxCountLable.AutoSize = true;
+ this.JewelMaxCountLable.Location = new System.Drawing.Point(340, 9);
+ this.JewelMaxCountLable.Name = "JewelMaxCountLable";
+ this.JewelMaxCountLable.Size = new System.Drawing.Size(140, 15);
+ this.JewelMaxCountLable.TabIndex = 11;
+ this.JewelMaxCountLable.Text = "Вместимость магазина: ";
+ //
+ // FormStore
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.JewelMaxCountLable);
+ this.Controls.Add(this.VolumeNumericUpDown);
+ this.Controls.Add(this.OpeningDatePicker);
+ this.Controls.Add(this.ButtonCancel);
+ this.Controls.Add(this.SaveButton);
+ this.Controls.Add(this.DataGridView);
+ this.Controls.Add(this.AdressTextBox);
+ this.Controls.Add(this.NameComboBox);
+ this.Controls.Add(this.OpeningDateLabel);
+ this.Controls.Add(this.StoreAdressLabel);
+ this.Controls.Add(this.StoreNameLabel);
+ this.Name = "FormStore";
+ this.Text = "Изделия магазина";
+ this.Load += new System.EventHandler(this.FormStore_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
+ ((System.ComponentModel.ISupportInitialize)(this.VolumeNumericUpDown)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label StoreNameLabel;
+ private Label StoreAdressLabel;
+ private Label OpeningDateLabel;
+ private ComboBox NameComboBox;
+ private TextBox AdressTextBox;
+ private DataGridView DataGridView;
+ private Button SaveButton;
+ private Button ButtonCancel;
+ private DataGridViewTextBoxColumn JewelName;
+ private DataGridViewTextBoxColumn JewelPrice;
+ private DataGridViewTextBoxColumn JewelCount;
+ private DateTimePicker OpeningDatePicker;
+ private NumericUpDown VolumeNumericUpDown;
+ private Label JewelMaxCountLable;
+ }
+}
diff --git a/JewelryStore/FormStore.cs b/JewelryStore/FormStore.cs
new file mode 100644
index 0000000..317952a
--- /dev/null
+++ b/JewelryStore/FormStore.cs
@@ -0,0 +1,130 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.BusinessLogicsContracts;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreDataModels.Models;
+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 JewelryStore
+{
+ public partial class FormStore : Form
+ {
+ private readonly IStoreLogic _logic;
+ private readonly ILogger _logger;
+ private int? _id;
+ private Dictionary _listStores;
+ public int Id { set { _id = value; } }
+
+ public FormStore(ILogger logger, IStoreLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _listStores = new();
+ _logic = logic;
+ }
+
+ private void SaveButton_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(NameComboBox.Text))
+ {
+ MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (string.IsNullOrEmpty(AdressTextBox.Text))
+ {
+ MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _logger.LogInformation("Сохранение магазина");
+ try
+ {
+ var model = new StoreBindingModel
+ {
+ Id = _id ?? 0,
+ StoreName = NameComboBox.Text,
+ StoreAdress = AdressTextBox.Text,
+ OpeningDate = OpeningDatePicker.Value.Date,
+ JewelMaxCount = (int)VolumeNumericUpDown.Value
+ };
+ var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
+ if (!operationResult)
+ {
+ throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
+ }
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения магазина");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+
+ private void FormStore_Load(object sender, EventArgs e)
+ {
+ if (_id.HasValue)
+ {
+ _logger.LogInformation("Загрузка магазина");
+ try
+ {
+ var view = _logic.ReadElement(new StoreSearchModel
+ {
+ Id = _id.Value
+ });
+ if (view != null)
+ {
+ NameComboBox.Text = view.StoreName;
+ AdressTextBox.Text = view.StoreAdress;
+ OpeningDatePicker.Text = view.OpeningDate.ToString();
+ VolumeNumericUpDown.Value = view.JewelMaxCount;
+ _listStores = view.StoreJewels ?? new Dictionary();
+ LoadData();
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки магазина");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
+ MessageBoxIcon.Error);
+ }
+ }
+ }
+ private void LoadData(bool extendDate = true)
+ {
+ _logger.LogInformation("Загрузка изделий магазина");
+ try
+ {
+ if (_listStores != null)
+ {
+ DataGridView.Rows.Clear();
+ foreach (var elem in _listStores)
+ {
+ DataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.JewelName, elem.Value.Item2 });
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки изделий магазина");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+}
diff --git a/JewelryStore/FormStore.resx b/JewelryStore/FormStore.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/JewelryStore/FormStore.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/JewelryStore/FormStoreReplenishment.Designer.cs b/JewelryStore/FormStoreReplenishment.Designer.cs
new file mode 100644
index 0000000..4399d2e
--- /dev/null
+++ b/JewelryStore/FormStoreReplenishment.Designer.cs
@@ -0,0 +1,142 @@
+namespace JewelryStore
+{
+ partial class FormStoreReplenishment
+ {
+ ///
+ /// 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.StoreNameLabel = new System.Windows.Forms.Label();
+ this.JewelNameLabel = new System.Windows.Forms.Label();
+ this.CountLabel = new System.Windows.Forms.Label();
+ this.StoreNameComboBox = new System.Windows.Forms.ComboBox();
+ this.JewelNameComboBox = new System.Windows.Forms.ComboBox();
+ this.CountTextBox = new System.Windows.Forms.TextBox();
+ this.SaveButton = new System.Windows.Forms.Button();
+ this.ButtonCancel = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // StoreNameLabel
+ //
+ this.StoreNameLabel.AutoSize = true;
+ this.StoreNameLabel.Location = new System.Drawing.Point(12, 9);
+ this.StoreNameLabel.Name = "StoreNameLabel";
+ this.StoreNameLabel.Size = new System.Drawing.Size(119, 15);
+ this.StoreNameLabel.TabIndex = 0;
+ this.StoreNameLabel.Text = "Название магазина: ";
+ //
+ // JewelNameLabel
+ //
+ this.JewelNameLabel.AutoSize = true;
+ this.JewelNameLabel.Location = new System.Drawing.Point(12, 37);
+ this.JewelNameLabel.Name = "JewelNameLabel";
+ this.JewelNameLabel.Size = new System.Drawing.Size(112, 15);
+ this.JewelNameLabel.TabIndex = 1;
+ this.JewelNameLabel.Text = "Название изделия: ";
+ //
+ // CountLabel
+ //
+ this.CountLabel.AutoSize = true;
+ this.CountLabel.Location = new System.Drawing.Point(12, 66);
+ this.CountLabel.Name = "CountLabel";
+ this.CountLabel.Size = new System.Drawing.Size(78, 15);
+ this.CountLabel.TabIndex = 2;
+ this.CountLabel.Text = "Количество: ";
+ //
+ // StoreNameComboBox
+ //
+ this.StoreNameComboBox.FormattingEnabled = true;
+ this.StoreNameComboBox.Location = new System.Drawing.Point(137, 6);
+ this.StoreNameComboBox.Name = "StoreNameComboBox";
+ this.StoreNameComboBox.Size = new System.Drawing.Size(149, 23);
+ this.StoreNameComboBox.TabIndex = 3;
+ //
+ // JewelNameComboBox
+ //
+ this.JewelNameComboBox.FormattingEnabled = true;
+ this.JewelNameComboBox.Location = new System.Drawing.Point(137, 35);
+ this.JewelNameComboBox.Name = "JewelNameComboBox";
+ this.JewelNameComboBox.Size = new System.Drawing.Size(149, 23);
+ this.JewelNameComboBox.TabIndex = 4;
+ //
+ // CountTextBox
+ //
+ this.CountTextBox.Location = new System.Drawing.Point(137, 64);
+ this.CountTextBox.Name = "CountTextBox";
+ this.CountTextBox.Size = new System.Drawing.Size(149, 23);
+ this.CountTextBox.TabIndex = 5;
+ //
+ // SaveButton
+ //
+ this.SaveButton.Location = new System.Drawing.Point(130, 108);
+ this.SaveButton.Name = "SaveButton";
+ this.SaveButton.Size = new System.Drawing.Size(75, 23);
+ this.SaveButton.TabIndex = 6;
+ this.SaveButton.Text = "Сохранить";
+ this.SaveButton.UseVisualStyleBackColor = true;
+ this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
+ //
+ // ButtonCancel
+ //
+ this.ButtonCancel.Location = new System.Drawing.Point(211, 108);
+ this.ButtonCancel.Name = "ButtonCancel";
+ this.ButtonCancel.Size = new System.Drawing.Size(75, 23);
+ this.ButtonCancel.TabIndex = 7;
+ this.ButtonCancel.Text = "Отмена";
+ this.ButtonCancel.UseVisualStyleBackColor = true;
+ this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
+ //
+ // FormStoreReplenishment
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(300, 150);
+ this.Controls.Add(this.ButtonCancel);
+ this.Controls.Add(this.SaveButton);
+ this.Controls.Add(this.CountTextBox);
+ this.Controls.Add(this.JewelNameComboBox);
+ this.Controls.Add(this.StoreNameComboBox);
+ this.Controls.Add(this.CountLabel);
+ this.Controls.Add(this.JewelNameLabel);
+ this.Controls.Add(this.StoreNameLabel);
+ this.Name = "FormStoreReplenishment";
+ this.Text = "Пополнение магазина";
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private Label StoreNameLabel;
+ private Label JewelNameLabel;
+ private Label CountLabel;
+ private ComboBox StoreNameComboBox;
+ private ComboBox JewelNameComboBox;
+ private TextBox CountTextBox;
+ private Button SaveButton;
+ private Button ButtonCancel;
+ }
+}
\ No newline at end of file
diff --git a/JewelryStore/FormStoreReplenishment.cs b/JewelryStore/FormStoreReplenishment.cs
new file mode 100644
index 0000000..b478d0f
--- /dev/null
+++ b/JewelryStore/FormStoreReplenishment.cs
@@ -0,0 +1,104 @@
+using JewelryStoreContracts.BusinessLogicsContracts;
+using JewelryStoreContracts.ViewModels;
+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 JewelryStore
+{
+ public partial class FormStoreReplenishment : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IStoreLogic _storeLogic;
+ private readonly IJewelLogic _jewelLogic;
+ private readonly List? _listStores;
+ private readonly List? _listJewels;
+ public FormStoreReplenishment(ILogger logger, IStoreLogic storeLogic, IJewelLogic jewelLogic)
+ {
+ InitializeComponent();
+ _storeLogic = storeLogic;
+ _jewelLogic = jewelLogic;
+ _logger = logger;
+ _listStores = storeLogic.ReadList(null);
+ if (_listStores != null)
+ {
+ StoreNameComboBox.DisplayMember = "StoreName";
+ StoreNameComboBox.ValueMember = "Id";
+ StoreNameComboBox.DataSource = _listStores;
+ StoreNameComboBox.SelectedItem = null;
+ }
+
+ _listJewels = jewelLogic.ReadList(null);
+ if (_listJewels != null)
+ {
+ JewelNameComboBox.DisplayMember = "JewelName";
+ JewelNameComboBox.ValueMember = "Id";
+ JewelNameComboBox.DataSource = _listJewels;
+ JewelNameComboBox.SelectedItem = null;
+ }
+ }
+
+ private void SaveButton_Click(object sender, EventArgs e)
+ {
+ if (StoreNameComboBox.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ if (JewelNameComboBox.SelectedValue == null)
+ {
+ MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+
+ _logger.LogInformation("Добавление изделия в магазин");
+
+ try
+ {
+ var jewel = _jewelLogic.ReadElement(new()
+ {
+ Id = (int)JewelNameComboBox.SelectedValue
+ });
+
+ if (jewel == null)
+ {
+ throw new Exception("Не найдено изделие. Дополнительная информация в логах.");
+ }
+
+ var resultOperation = _storeLogic.AddJewel(
+ model: new() { Id = (int)StoreNameComboBox.SelectedValue },
+ jewel: jewel,
+ quantity: Convert.ToInt32(CountTextBox.Text)
+ );
+
+ if (!resultOperation)
+ {
+ throw new Exception("Ошибка при добавлении. Дополнительная информация в логах.");
+ }
+
+ MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
+ DialogResult = DialogResult.OK;
+ Close();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка сохранения изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e)
+ {
+ DialogResult = DialogResult.Cancel;
+ Close();
+ }
+ }
+}
diff --git a/JewelryStore/FormStoreReplenishment.resx b/JewelryStore/FormStoreReplenishment.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/JewelryStore/FormStoreReplenishment.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/JewelryStore/FormStores.Designer.cs b/JewelryStore/FormStores.Designer.cs
new file mode 100644
index 0000000..56e0205
--- /dev/null
+++ b/JewelryStore/FormStores.Designer.cs
@@ -0,0 +1,114 @@
+namespace JewelryStore
+{
+ partial class FormStores
+ {
+ ///
+ /// 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.DataGridView = new System.Windows.Forms.DataGridView();
+ this.AddButton = new System.Windows.Forms.Button();
+ this.ChangeButton = new System.Windows.Forms.Button();
+ this.DeleteButton = new System.Windows.Forms.Button();
+ this.UpdateButton = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
+ this.SuspendLayout();
+ //
+ // DataGridView
+ //
+ this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ this.DataGridView.Location = new System.Drawing.Point(1, 1);
+ this.DataGridView.Name = "DataGridView";
+ this.DataGridView.RowTemplate.Height = 25;
+ this.DataGridView.Size = new System.Drawing.Size(550, 447);
+ this.DataGridView.TabIndex = 0;
+ //
+ // AddButton
+ //
+ this.AddButton.Location = new System.Drawing.Point(585, 12);
+ this.AddButton.Name = "AddButton";
+ this.AddButton.Size = new System.Drawing.Size(121, 40);
+ this.AddButton.TabIndex = 1;
+ this.AddButton.Text = "Добавить";
+ this.AddButton.UseVisualStyleBackColor = true;
+ this.AddButton.Click += new System.EventHandler(this.AddButton_Click);
+ //
+ // ChangeButton
+ //
+ this.ChangeButton.Location = new System.Drawing.Point(585, 67);
+ this.ChangeButton.Name = "ChangeButton";
+ this.ChangeButton.Size = new System.Drawing.Size(121, 40);
+ this.ChangeButton.TabIndex = 2;
+ this.ChangeButton.Text = "Изменить";
+ this.ChangeButton.UseVisualStyleBackColor = true;
+ this.ChangeButton.Click += new System.EventHandler(this.ChangeButton_Click);
+ //
+ // DeleteButton
+ //
+ this.DeleteButton.Location = new System.Drawing.Point(585, 122);
+ this.DeleteButton.Name = "DeleteButton";
+ this.DeleteButton.Size = new System.Drawing.Size(121, 40);
+ this.DeleteButton.TabIndex = 3;
+ this.DeleteButton.Text = "Удалить";
+ this.DeleteButton.UseVisualStyleBackColor = true;
+ this.DeleteButton.Click += new System.EventHandler(this.DeleteButton_Click);
+ //
+ // UpdateButton
+ //
+ this.UpdateButton.Location = new System.Drawing.Point(585, 179);
+ this.UpdateButton.Name = "UpdateButton";
+ this.UpdateButton.Size = new System.Drawing.Size(121, 40);
+ this.UpdateButton.TabIndex = 4;
+ this.UpdateButton.Text = "Обновить";
+ this.UpdateButton.UseVisualStyleBackColor = true;
+ this.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
+ //
+ // FormStores
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(718, 450);
+ this.Controls.Add(this.UpdateButton);
+ this.Controls.Add(this.DeleteButton);
+ this.Controls.Add(this.ChangeButton);
+ this.Controls.Add(this.AddButton);
+ this.Controls.Add(this.DataGridView);
+ this.Name = "FormStores";
+ this.Text = "Магазины";
+ this.Load += new System.EventHandler(this.FormStores_Load);
+ ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private DataGridView DataGridView;
+ private Button AddButton;
+ private Button ChangeButton;
+ private Button DeleteButton;
+ private Button UpdateButton;
+ }
+}
\ No newline at end of file
diff --git a/JewelryStore/FormStores.cs b/JewelryStore/FormStores.cs
new file mode 100644
index 0000000..3ce73b0
--- /dev/null
+++ b/JewelryStore/FormStores.cs
@@ -0,0 +1,122 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.BusinessLogicsContracts;
+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 JewelryStore
+{
+ public partial class FormStores : Form
+ {
+ private readonly ILogger _logger;
+ private readonly IStoreLogic _logic;
+ public FormStores(ILogger logger, IStoreLogic logic)
+ {
+ InitializeComponent();
+ _logger = logger;
+ _logic = logic;
+ }
+
+ private void FormStores_Load(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void LoadData()
+ {
+ try
+ {
+ var list = _logic.ReadList(null);
+
+ if (list != null)
+ {
+ DataGridView.DataSource = list;
+ DataGridView.Columns["Id"].Visible = false;
+ DataGridView.Columns["StoreName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
+ DataGridView.Columns["StoreJewels"].Visible = false;
+ }
+
+ _logger.LogInformation("Загрузка магазинов");
+
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка загрузки магазинов");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void UpdateButton_Click(object sender, EventArgs e)
+ {
+ LoadData();
+ }
+
+ private void DeleteButton_Click(object sender, EventArgs e)
+ {
+ if (DataGridView.SelectedRows.Count == 1)
+ {
+ if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ int id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
+ _logger.LogInformation("Удаление магазина");
+
+ try
+ {
+ if (!_logic.Delete(new StoreBindingModel
+ {
+ Id = id
+ }))
+ {
+ throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
+ }
+
+ LoadData();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError(ex, "Ошибка удаления изделия");
+ MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
+ }
+
+ private void ChangeButton_Click(object sender, EventArgs e)
+ {
+ if (DataGridView.SelectedRows.Count == 1)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormStore));
+
+ if (service is FormStore form)
+ {
+ form.Id = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Id"].Value);
+
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+
+ private void AddButton_Click(object sender, EventArgs e)
+ {
+ var service = Program.ServiceProvider?.GetService(typeof(FormStore));
+
+ if (service is FormStore form)
+ {
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ LoadData();
+ }
+ }
+ }
+ }
+}
diff --git a/JewelryStore/FormStores.resx b/JewelryStore/FormStores.resx
new file mode 100644
index 0000000..1af7de1
--- /dev/null
+++ b/JewelryStore/FormStores.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/JewelryStore/ImplementationExtensions/JewelryStoreContracts.dll b/JewelryStore/ImplementationExtensions/JewelryStoreContracts.dll
new file mode 100644
index 0000000..859206b
Binary files /dev/null and b/JewelryStore/ImplementationExtensions/JewelryStoreContracts.dll differ
diff --git a/JewelryStore/ImplementationExtensions/JewelryStoreDataModels.dll b/JewelryStore/ImplementationExtensions/JewelryStoreDataModels.dll
new file mode 100644
index 0000000..3f9f8b4
Binary files /dev/null and b/JewelryStore/ImplementationExtensions/JewelryStoreDataModels.dll differ
diff --git a/JewelryStore/ImplementationExtensions/JewelryStoreDatabaseImplement.dll b/JewelryStore/ImplementationExtensions/JewelryStoreDatabaseImplement.dll
new file mode 100644
index 0000000..79e0958
Binary files /dev/null and b/JewelryStore/ImplementationExtensions/JewelryStoreDatabaseImplement.dll differ
diff --git a/JewelryStore/ImplementationExtensions/JewelryStoreFileImplement.dll b/JewelryStore/ImplementationExtensions/JewelryStoreFileImplement.dll
new file mode 100644
index 0000000..8db93ad
Binary files /dev/null and b/JewelryStore/ImplementationExtensions/JewelryStoreFileImplement.dll differ
diff --git a/JewelryStore/ImplementationExtensions/JewelryStoreListImplement.dll b/JewelryStore/ImplementationExtensions/JewelryStoreListImplement.dll
new file mode 100644
index 0000000..548602d
Binary files /dev/null and b/JewelryStore/ImplementationExtensions/JewelryStoreListImplement.dll differ
diff --git a/JewelryStore/JewelryStore.csproj b/JewelryStore/JewelryStore.csproj
index 90bafab..8a1c665 100644
--- a/JewelryStore/JewelryStore.csproj
+++ b/JewelryStore/JewelryStore.csproj
@@ -8,14 +8,20 @@
enable
+
+
+
+
+
-
+
+
diff --git a/JewelryStore/JewelryStore.sln b/JewelryStore/JewelryStore.sln
index 08fec75..478a62b 100644
--- a/JewelryStore/JewelryStore.sln
+++ b/JewelryStore/JewelryStore.sln
@@ -5,13 +5,15 @@ VisualStudioVersion = 17.4.33122.133
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStore", "JewelryStore.csproj", "{F1AEB85A-E5E1-4B07-8D6B-E46870480FFA}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreContracts", "..\JewelryStoreContracts\JewelryStoreContracts.csproj", "{763B1FD7-7D30-4689-869C-1FEAD240B29B}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStoreContracts", "..\JewelryStoreContracts\JewelryStoreContracts.csproj", "{763B1FD7-7D30-4689-869C-1FEAD240B29B}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreDataModels", "..\JewelryStoreDataModels\JewelryStoreDataModels.csproj", "{84BF2156-F821-46F4-8EED-F371084C0129}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStoreDataModels", "..\JewelryStoreDataModels\JewelryStoreDataModels.csproj", "{84BF2156-F821-46F4-8EED-F371084C0129}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreBusinessLogic", "..\JewelryStoreBusinessLogic\JewelryStoreBusinessLogic.csproj", "{DA57067F-F3ED-4B1C-B56F-52856FC2E93D}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStoreBusinessLogic", "..\JewelryStoreBusinessLogic\JewelryStoreBusinessLogic.csproj", "{DA57067F-F3ED-4B1C-B56F-52856FC2E93D}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreListImplement", "..\JewelryStoreListImplement\JewelryStoreListImplement.csproj", "{B8C8AA30-FC16-4331-B456-CD16C3C97B25}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JewelryStoreListImplement", "..\JewelryStoreListImplement\JewelryStoreListImplement.csproj", "{B8C8AA30-FC16-4331-B456-CD16C3C97B25}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreFileImplement", "..\JewelryStoreFileImplement\JewelryStoreFileImplement.csproj", "{2906CD1C-4D78-4329-A2E9-8B67E624DD92}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -39,6 +41,10 @@ Global
{B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B8C8AA30-FC16-4331-B456-CD16C3C97B25}.Release|Any CPU.Build.0 = Release|Any CPU
+ {2906CD1C-4D78-4329-A2E9-8B67E624DD92}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {2906CD1C-4D78-4329-A2E9-8B67E624DD92}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {2906CD1C-4D78-4329-A2E9-8B67E624DD92}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {2906CD1C-4D78-4329-A2E9-8B67E624DD92}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs
index 4a4a47e..0da1940 100644
--- a/JewelryStore/Program.cs
+++ b/JewelryStore/Program.cs
@@ -1,7 +1,7 @@
using JewelryStoreContracts.BusinessLogicsContracts;
using JewelryStoreContracts.StoragesContracts;
using JewelryStoreBusinessLogic.BusinessLogics;
-using JewelryStoreListImplement.Implements;
+using JewelryStoreFileImplement.Implements;
using Microsoft.Extensions.DependencyInjection;
using System.Drawing;
@@ -15,21 +15,17 @@ namespace JewelryStore
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
- ///
- /// The main entry point for the application.
- ///
+
[STAThread]
static void Main()
{
- // To customize application configuration such as set high DPI
- //settings or default font,
- // see https://aka.ms/applicationconfiguration.
- ApplicationConfiguration.Initialize();
+ ApplicationConfiguration.Initialize();
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService());
}
+
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
@@ -40,9 +36,11 @@ namespace JewelryStore
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
services.AddTransient();
services.AddTransient();
services.AddTransient();
@@ -50,7 +48,10 @@ namespace JewelryStore
services.AddTransient();
services.AddTransient();
services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
+ services.AddTransient();
}
-
}
}
\ No newline at end of file
diff --git a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs
index 6bcfa52..3bd5242 100644
--- a/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs
+++ b/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs
@@ -22,80 +22,121 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
//«Выполняется»).
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
- public OrderLogic(ILogger logger, IOrderStorage orderStorage)
+ private readonly IStoreLogic _storeLogic;
+ private readonly IJewelStorage _jewelStorage;
+
+ public OrderLogic(ILogger logger, IOrderStorage orderStorage, IJewelStorage jewelStorage, IStoreLogic storeLogic)
{
_logger = logger;
_orderStorage = orderStorage;
+ _storeLogic = storeLogic;
+ _jewelStorage = jewelStorage;
}
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
- if (model.Status != OrderStatus.Неизвестен) return false;
+
+ if (model.Status != OrderStatus.Неизвестен)
+ {
+ _logger.LogWarning("Insert operation failed. Order status incorrect.");
+ return false;
+ }
+
model.Status = OrderStatus.Принят;
+
if (_orderStorage.Insert(model) == null)
{
+ model.Status = OrderStatus.Неизвестен;
_logger.LogWarning("Insert operation failed");
return false;
}
+
return true;
}
+ public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
+ {
+ var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
+
+ if (viewModel == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ if (viewModel.Status + 1 != newStatus)
+ {
+ _logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
+ return false;
+ }
+
+ model.Status = newStatus;
+
+ if (model.Status == OrderStatus.Готов)
+ {
+ model.DateImplement = DateTime.Now;
+
+ var jewel = _jewelStorage.GetElement(new() { Id = viewModel.JewelId });
+
+ if (jewel == null)
+ {
+ throw new ArgumentNullException(nameof(jewel));
+ }
+
+ if (!_storeLogic.AddJewel(jewel, viewModel.Count))
+ {
+ throw new Exception($"AddJewel operation failed. Store is full.");
+ }
+ }
+ else
+ {
+ model.DateImplement = viewModel.DateImplement;
+ }
+
+ CheckModel(model, false);
+
+ if (_orderStorage.Update(model) == null)
+ {
+ model.Status--;
+ _logger.LogWarning("Update operation failed");
+
+ return false;
+ }
+
+ return true;
+ }
+
+ public bool TakeOrderInWork(OrderBindingModel model)
+ {
+ return StatusUpdate(model, OrderStatus.Выполняется);
+ }
+
public bool DeliveryOrder(OrderBindingModel model)
{
- CheckModel(model);
- if (model.Status != OrderStatus.Готов) return false;
-
- model.Status = OrderStatus.Выдан;
- model.DateImplement = DateTime.Now;
- if (_orderStorage.Update(model) == null)
- {
- _logger.LogWarning("Update operation failed");
- return false;
- }
- return true;
+ return StatusUpdate(model, OrderStatus.Готов);
}
public bool FinishOrder(OrderBindingModel model)
{
- CheckModel(model);
- if (model.Status != OrderStatus.Выполняется) return false;
-
- model.Status = OrderStatus.Готов;
- if (_orderStorage.Update(model) == null)
- {
- _logger.LogWarning("Update operation failed");
- return false;
- }
- return true;
+ return StatusUpdate(model, OrderStatus.Выдан);
}
public List? ReadList(OrderSearchModel? model)
{
- _logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
+ _logger.LogInformation("Order. OrderId:{Id}", model?.Id);
+
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
+
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
+
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
- public bool TakeOrderInWork(OrderBindingModel model)
- {
- CheckModel(model);
- if (model.Status != OrderStatus.Принят) return false;
- model.Status = OrderStatus.Выполняется;
- if (_orderStorage.Update(model) == null)
- {
- _logger.LogWarning("Update operation failed");
- return false;
- }
- return true;
- }
-
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
@@ -110,12 +151,12 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
if (model.JewelId < 0)
{
- throw new ArgumentNullException("Некорректный идентификатор драгоценности", nameof(model.JewelId));
+ throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.JewelId));
}
if (model.Count <= 0)
{
- throw new ArgumentNullException("Количество драгоценностей в заказе должно быть больше 0", nameof(model.Count));
+ throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count));
}
if (model.Sum <= 0)
@@ -125,6 +166,5 @@ namespace JewelryStoreBusinessLogic.BusinessLogics
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. JewelId: { JewelId}", model.Id, model.Sum, model.JewelId);
}
-
}
}
diff --git a/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic .cs b/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic .cs
new file mode 100644
index 0000000..6fd95dc
--- /dev/null
+++ b/JewelryStoreBusinessLogic/BusinessLogics/StoreLogic .cs
@@ -0,0 +1,246 @@
+using Microsoft.Extensions.Logging;
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.BusinessLogicsContracts;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.StoragesContracts;
+using JewelryStoreDataModels.Models;
+using JewelryStoreContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreBusinessLogic.BusinessLogics
+{
+ public class StoreLogic : IStoreLogic
+ {
+ private readonly ILogger _logger;
+ private readonly IStoreStorage _storeStorage;
+ public StoreLogic(ILogger logger, IStoreStorage storeStorage)
+ {
+ _logger = logger;
+ _storeStorage = storeStorage;
+ }
+ public bool AddJewel(StoreSearchModel model, IJewelModel jewel, int quantity)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ if (quantity <= 0)
+ {
+ throw new ArgumentException("Количество изделий должно быть больше 0", nameof(quantity));
+ }
+
+ _logger.LogInformation("AddJewel. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id);
+ var element = _storeStorage.GetElement(model);
+
+ if (element == null)
+ {
+ _logger.LogWarning("AddJewel element not found");
+ return false;
+ }
+
+ if (element.JewelMaxCount - element.StoreJewels.Select(x => x.Value.Item2).Sum() < quantity)
+ {
+ throw new ArgumentNullException("Магазин переполнен", nameof(quantity));
+ }
+
+ _logger.LogInformation("AddJewel find. Id:{Id}", element.Id);
+
+ if (element.StoreJewels.TryGetValue(jewel.Id, out var pair))
+ {
+ element.StoreJewels[jewel.Id] = (jewel, quantity + pair.Item2);
+ _logger.LogInformation("AddJewel. Added {quantity} {jewel} to '{StoreName}' store", quantity, jewel.JewelName, element.StoreName);
+ }
+ else
+ {
+ element.StoreJewels[jewel.Id] = (jewel, quantity);
+ _logger.LogInformation("AddJewel. Added {quantity} new jewel {jewel} to '{StoreName}' store", quantity, jewel.JewelName, element.StoreName);
+ }
+
+ _storeStorage.Update(new()
+ {
+ Id = element.Id,
+ StoreAdress = element.StoreAdress,
+ StoreName = element.StoreName,
+ OpeningDate = element.OpeningDate,
+ JewelMaxCount = element.JewelMaxCount,
+ StoreJewels = element.StoreJewels,
+ });
+
+ return true;
+ }
+
+ public bool AddJewel(IJewelModel jewel, int quantity)
+ {
+ if (jewel == null)
+ {
+ throw new ArgumentNullException(nameof(jewel));
+ }
+
+ if (quantity <= 0)
+ {
+ throw new ArgumentException("Количество добавляемого изделия должно быть больше 0", nameof(quantity));
+ }
+
+ var freePlaces = _storeStorage.GetFullList()
+ .Select(x => x.JewelMaxCount - x.StoreJewels
+ .Select(p => p.Value.Item2).Sum()).Sum() - quantity;
+
+ if (freePlaces < 0)
+ {
+ _logger.LogInformation("AddJewel. Failed to add jewel to store. It's full.");
+ return false;
+ }
+
+ foreach (var store in _storeStorage.GetFullList())
+ {
+ var temp = Math.Min(quantity, store.JewelMaxCount - store.StoreJewels.Select(x => x.Value.Item2).Sum());
+
+ if (temp <= 0)
+ {
+ continue;
+ }
+
+ if (!AddJewel(new() { Id = store.Id }, jewel, temp))
+ {
+ _logger.LogWarning("An error occurred while adding jewel to stores");
+ return false;
+ }
+
+ quantity -= temp;
+
+ if (quantity == 0)
+ {
+ return true;
+ }
+ }
+ return true;
+ }
+
+ public bool Create(StoreBindingModel model)
+ {
+ CheckModel(model);
+ model.StoreJewels = new();
+
+ if (_storeStorage.Insert(model) == null)
+ {
+ _logger.LogWarning("Insert operation failed");
+ return false;
+ }
+
+ return true;
+ }
+
+ public bool Delete(StoreBindingModel model)
+ {
+ CheckModel(model, false);
+ _logger.LogInformation("Delete. Id:{Id}", model.Id);
+
+ if (_storeStorage.Delete(model) == null)
+ {
+ _logger.LogWarning("Delete operation failed");
+ return false;
+ }
+
+ return true;
+ }
+
+ public StoreViewModel? ReadElement(StoreSearchModel model)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ _logger.LogInformation("ReadElement. StoreName:{StoreName}.Id:{ Id}", model.StoreName, model.Id);
+ var element = _storeStorage.GetElement(model);
+
+ if (element == null)
+ {
+ _logger.LogWarning("ReadElement element not found");
+ return null;
+ }
+
+ _logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
+ return element;
+ }
+
+ public List? ReadList(StoreSearchModel? model)
+ {
+ _logger.LogInformation("ReadList. StoreName:{StoreName}.Id:{ Id} ", model?.StoreName, model?.Id);
+
+ var list = (model == null) ? _storeStorage.GetFullList() : _storeStorage.GetFilteredList(model);
+
+ if (list == null)
+ {
+ _logger.LogWarning("ReadList return null list");
+ return null;
+ }
+
+ _logger.LogInformation("ReadList. Count:{Count}", list.Count);
+ return list;
+ }
+
+ public bool SellJewel(IJewelModel jewel, int quantity)
+ {
+ return _storeStorage.SellJewel(jewel, quantity);
+ }
+
+ public bool Update(StoreBindingModel model)
+ {
+ CheckModel(model, false);
+
+ if (string.IsNullOrEmpty(model.StoreName))
+ {
+ throw new ArgumentNullException("Нет названия магазина", nameof(model.StoreName));
+ }
+
+ if (_storeStorage.Update(model) == null)
+ {
+ _logger.LogWarning("Update operation failed");
+ return false;
+ }
+ return true;
+ }
+
+ private void CheckModel(StoreBindingModel model, bool withParams = true)
+ {
+ if (model == null)
+ {
+ throw new ArgumentNullException(nameof(model));
+ }
+
+ if (!withParams)
+ {
+ return;
+ }
+
+ if (string.IsNullOrEmpty(model.StoreName))
+ {
+ throw new ArgumentNullException("Нет названия магазина", nameof(model.StoreName));
+ }
+
+ if (model.JewelMaxCount < 0)
+ {
+ throw new ArgumentException("Максимальное количество изделий в магазине не может быть меньше нуля", nameof(model.JewelMaxCount));
+ }
+
+ _logger.LogInformation("Store. StoreName:{0}.StoreAdress:{1}. Id: {2}", model.StoreName, model.StoreAdress, model.Id);
+
+ var element = _storeStorage.GetElement(new StoreSearchModel
+ {
+ StoreName = model.StoreName
+ });
+
+ if (element != null && element.Id != model.Id && element.StoreName == model.StoreName)
+ {
+ throw new InvalidOperationException("Магазин с таким названием уже есть");
+ }
+ }
+
+ }
+}
diff --git a/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj b/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj
index 7e1df35..d6db721 100644
--- a/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj
+++ b/JewelryStoreBusinessLogic/JewelryStoreBusinessLogic.csproj
@@ -1,4 +1,4 @@
-
+
net6.0
@@ -6,6 +6,10 @@
enable
+
+
+
+
diff --git a/JewelryStoreContracts/BindingModels/StoreBindingModel.cs b/JewelryStoreContracts/BindingModels/StoreBindingModel.cs
new file mode 100644
index 0000000..65186f1
--- /dev/null
+++ b/JewelryStoreContracts/BindingModels/StoreBindingModel.cs
@@ -0,0 +1,23 @@
+using JewelryStoreDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreContracts.BindingModels
+{
+ public class StoreBindingModel: IStoreModel
+ {
+ public string StoreName { get; set; } = string.Empty;
+ public string StoreAdress { get; set; } = string.Empty;
+
+ public DateTime OpeningDate { get; set; } = DateTime.Now;
+
+ public Dictionary StoreJewels { get; set; } = new();
+
+ public int Id { get; set; }
+
+ public int JewelMaxCount { get; set; }
+ }
+}
diff --git a/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs b/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs
new file mode 100644
index 0000000..f04fddb
--- /dev/null
+++ b/JewelryStoreContracts/BusinessLogicsContracts/IStoreLogic.cs
@@ -0,0 +1,24 @@
+using JewelryStoreContracts.BindingModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreDataModels.Models;
+
+namespace JewelryStoreContracts.BusinessLogicsContracts
+{
+ public interface IStoreLogic
+ {
+ List? ReadList(StoreSearchModel? model);
+ StoreViewModel? ReadElement(StoreSearchModel model);
+ bool Create(StoreBindingModel model);
+ bool Update(StoreBindingModel model);
+ bool Delete(StoreBindingModel model);
+ bool AddJewel(StoreSearchModel model, IJewelModel jewel, int quantity);
+ bool AddJewel(IJewelModel jewel, int quantity);
+ bool SellJewel(IJewelModel jewel, int quantity);
+ }
+}
diff --git a/JewelryStoreContracts/SearchModels/StoreSearchModel.cs b/JewelryStoreContracts/SearchModels/StoreSearchModel.cs
new file mode 100644
index 0000000..1ffd758
--- /dev/null
+++ b/JewelryStoreContracts/SearchModels/StoreSearchModel.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreContracts.SearchModels
+{
+ public class StoreSearchModel
+ {
+ public int? Id { get; set; }
+ public string? StoreName { get; set; }
+ }
+}
diff --git a/JewelryStoreContracts/StoragesContracts/IStoreStorage.cs b/JewelryStoreContracts/StoragesContracts/IStoreStorage.cs
new file mode 100644
index 0000000..c0e7dfd
--- /dev/null
+++ b/JewelryStoreContracts/StoragesContracts/IStoreStorage.cs
@@ -0,0 +1,23 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreContracts.StoragesContracts
+{
+ public interface IStoreStorage
+ {
+ List GetFullList();
+ List GetFilteredList(StoreSearchModel model);
+ StoreViewModel? GetElement(StoreSearchModel model);
+ StoreViewModel? Insert(StoreBindingModel model);
+ StoreViewModel? Update(StoreBindingModel model);
+ StoreViewModel? Delete(StoreBindingModel model);
+ bool SellJewel(IJewelModel model, int quantity);
+ }
+}
diff --git a/JewelryStoreContracts/ViewModels/StoreViewModel.cs b/JewelryStoreContracts/ViewModels/StoreViewModel.cs
new file mode 100644
index 0000000..e4acc5a
--- /dev/null
+++ b/JewelryStoreContracts/ViewModels/StoreViewModel.cs
@@ -0,0 +1,26 @@
+using JewelryStoreDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreContracts.ViewModels
+{
+ public class StoreViewModel : IStoreModel
+ {
+ public Dictionary StoreJewels { get; set; } = new();
+ public int Id { get; set; }
+
+ [DisplayName("Название магазина")]
+ public string StoreName { get; set; } = string.Empty;
+ [DisplayName("Адрес магазина")]
+ public string StoreAdress { get; set; } = string.Empty;
+ [DisplayName("Дата открытия")]
+ public DateTime OpeningDate { get; set; } = DateTime.Now;
+
+ [DisplayName("Вместимость магазина")]
+ public int JewelMaxCount { get; set; }
+ }
+}
diff --git a/JewelryStoreDataModels/Models/IStoreModel.cs b/JewelryStoreDataModels/Models/IStoreModel.cs
new file mode 100644
index 0000000..6bf1b79
--- /dev/null
+++ b/JewelryStoreDataModels/Models/IStoreModel.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreDataModels.Models
+{
+ public interface IStoreModel : IId
+ {
+ public string StoreName { get; }
+ public string StoreAdress { get; }
+ DateTime OpeningDate { get; }
+ Dictionary StoreJewels { get; }
+ public int JewelMaxCount { get; }
+ }
+}
diff --git a/JewelryStoreFileImplement/DataFileSingleton.cs b/JewelryStoreFileImplement/DataFileSingleton.cs
new file mode 100644
index 0000000..6146286
--- /dev/null
+++ b/JewelryStoreFileImplement/DataFileSingleton.cs
@@ -0,0 +1,61 @@
+using JewelryStoreFileImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace JewelryStoreFileImplement
+{
+ public class DataFileSingleton
+ {
+ private static DataFileSingleton? instance;
+ private readonly string ComponentFileName = "Component.xml";
+ private readonly string OrderFileName = "Order.xml";
+ private readonly string JewelFileName = "Jewel.xml";
+ private readonly string StoreFileName = "Store.xml";
+ public List Components { get; private set; }
+ public List Orders { get; private set; }
+ public List Jewels { get; private set; }
+ public List Stores { get; private set; }
+
+ public static DataFileSingleton GetInstance()
+ {
+ if (instance == null)
+ {
+ instance = new DataFileSingleton();
+ }
+ return instance;
+ }
+ public void SaveComponents() => SaveData(Components, ComponentFileName,"Components", x => x.GetXElement);
+ public void SaveJewels() => SaveData(Jewels, JewelFileName, "Jewels", x => x.GetXElement);
+ public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
+ public void SaveStores() => SaveData(Stores, StoreFileName, "Stores", x => x.GetXElement);
+
+ private DataFileSingleton()
+ {
+ Components = LoadData(ComponentFileName, "Component", x =>Component.Create(x)!)!;
+ Jewels = LoadData(JewelFileName, "Jewel", x => Jewel.Create(x)!)!;
+ Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
+ Stores = LoadData(StoreFileName, "Store", x => Store.Create(x)!)!;
+
+ }
+ private static List? LoadData(string filename, string xmlNodeName, Func selectFunction)
+ {
+ if (File.Exists(filename))
+ {
+ return
+ XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
+ }
+ return new List();
+ }
+ private static void SaveData(List data, string filename, string xmlNodeName, Func selectFunction)
+ {
+ if (data != null)
+ {
+ new XDocument(new XElement(xmlNodeName,data.Select(selectFunction).ToArray())).Save(filename);
+ }
+ }
+ }
+}
diff --git a/JewelryStoreFileImplement/Implements/ComponentStorage .cs b/JewelryStoreFileImplement/Implements/ComponentStorage .cs
new file mode 100644
index 0000000..11ec35c
--- /dev/null
+++ b/JewelryStoreFileImplement/Implements/ComponentStorage .cs
@@ -0,0 +1,88 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.StoragesContracts;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreFileImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreFileImplement.Implements
+{
+ public class ComponentStorage : IComponentStorage
+ {
+ private readonly DataFileSingleton _source;
+ public ComponentStorage()
+ {
+ _source = DataFileSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ return _source.Components.Select(x => x.GetViewModel).ToList();
+ }
+ public List GetFilteredList(ComponentSearchModel
+ model)
+ {
+ if (string.IsNullOrEmpty(model.ComponentName))
+ {
+ return new();
+ }
+ return _source.Components
+ .Where(x => x.ComponentName.Contains(model.ComponentName))
+ .Select(x => x.GetViewModel)
+ .ToList();
+
+ }
+ public ComponentViewModel? GetElement(ComponentSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ return _source.Components
+ .FirstOrDefault(x =>
+ (!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) ||
+ (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
+ }
+ public ComponentViewModel? Insert(ComponentBindingModel model)
+ {
+ model.Id = _source.Components.Count > 0 ? _source.Components.Max(x =>x.Id) + 1 : 1;
+ var newComponent = Component.Create(model);
+ if (newComponent == null)
+ {
+ return null;
+ }
+ _source.Components.Add(newComponent);
+ _source.SaveComponents();
+ return newComponent.GetViewModel;
+ }
+
+ public ComponentViewModel? Update(ComponentBindingModel model)
+ {
+ var component = _source.Components.FirstOrDefault(x => x.Id ==model.Id);
+ if (component == null)
+ {
+ return null;
+ }
+ component.Update(model);
+ _source.SaveComponents();
+ return component.GetViewModel;
+
+
+ }
+ public ComponentViewModel? Delete(ComponentBindingModel model)
+ {
+ var element = _source.Components.FirstOrDefault(x => x.Id ==model.Id);
+ if (element != null)
+ {
+ _source.Components.Remove(element);
+ _source.SaveComponents();
+ return element.GetViewModel;
+ }
+ return null;
+
+ }
+ }
+}
diff --git a/JewelryStoreFileImplement/Implements/JewelStorage.cs b/JewelryStoreFileImplement/Implements/JewelStorage.cs
new file mode 100644
index 0000000..5618d75
--- /dev/null
+++ b/JewelryStoreFileImplement/Implements/JewelStorage.cs
@@ -0,0 +1,88 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.StoragesContracts;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreFileImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreFileImplement.Implements
+{
+ public class JewelStorage : IJewelStorage // TODO Lab_2
+ {
+ private readonly DataFileSingleton _source;
+ public JewelStorage()
+ {
+ _source = DataFileSingleton.GetInstance();
+ }
+ public List GetFullList()
+ {
+ return _source.Jewels.Select(x => x.GetViewModel).ToList();
+ }
+ public List GetFilteredList(JewelSearchModel
+ model)
+ {
+ if (string.IsNullOrEmpty(model.JewelName))
+ {
+ return new();
+ }
+ return _source.Jewels
+ .Where(x => x.JewelName.Contains(model.JewelName))
+ .Select(x => x.GetViewModel)
+ .ToList();
+
+ }
+ public JewelViewModel? GetElement(JewelSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.JewelName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ return _source.Jewels
+ .FirstOrDefault(x =>
+ (!string.IsNullOrEmpty(model.JewelName) && x.JewelName == model.JewelName) ||
+ (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
+ }
+ public JewelViewModel? Insert(JewelBindingModel model)
+ {
+ model.Id = _source.Jewels.Count > 0 ? _source.Jewels.Max(x => x.Id) + 1 : 1;
+ var newJewel = Jewel.Create(model);
+ if (newJewel == null)
+ {
+ return null;
+ }
+ _source.Jewels.Add(newJewel);
+ _source.SaveJewels();
+ return newJewel.GetViewModel;
+ }
+
+ public JewelViewModel? Update(JewelBindingModel model)
+ {
+ var component = _source.Jewels.FirstOrDefault(x => x.Id == model.Id);
+ if (component == null)
+ {
+ return null;
+ }
+ component.Update(model);
+ _source.SaveJewels();
+ return component.GetViewModel;
+
+
+ }
+ public JewelViewModel? Delete(JewelBindingModel model)
+ {
+ var element = _source.Jewels.FirstOrDefault(x => x.Id == model.Id);
+ if (element != null)
+ {
+ _source.Jewels.Remove(element);
+ _source.SaveJewels();
+ return element.GetViewModel;
+ }
+ return null;
+
+ }
+ }
+}
diff --git a/JewelryStoreFileImplement/Implements/OrderStorage.cs b/JewelryStoreFileImplement/Implements/OrderStorage.cs
new file mode 100644
index 0000000..40ac71d
--- /dev/null
+++ b/JewelryStoreFileImplement/Implements/OrderStorage.cs
@@ -0,0 +1,94 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.StoragesContracts;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreFileImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreFileImplement.Implements
+{
+ public class OrderStorage : IOrderStorage // TODO Lab_2
+ {
+ private readonly DataFileSingleton source;
+
+ public OrderStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+
+ public OrderViewModel? Delete(OrderBindingModel model)
+ {
+ var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
+
+ if (element != null)
+ {
+ source.Orders.Remove(element);
+ source.SaveOrders();
+
+ return element.GetViewModel;
+ }
+
+ return null;
+ }
+
+ public OrderViewModel? GetElement(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+
+ return source.Orders.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
+ }
+
+ public List GetFilteredList(OrderSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return new();
+ }
+
+ return source.Orders.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
+ }
+
+ public List GetFullList()
+ {
+ return source.Orders.Select(x => x.GetViewModel).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 newOrder.GetViewModel;
+ }
+
+ public OrderViewModel? Update(OrderBindingModel model)
+ {
+ var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
+
+ if (order == null)
+ {
+ return null;
+ }
+
+ order.Update(model);
+ source.SaveOrders();
+
+ return order.GetViewModel;
+ }
+ }
+}
diff --git a/JewelryStoreFileImplement/Implements/StoreStorage.cs b/JewelryStoreFileImplement/Implements/StoreStorage.cs
new file mode 100644
index 0000000..143ed02
--- /dev/null
+++ b/JewelryStoreFileImplement/Implements/StoreStorage.cs
@@ -0,0 +1,114 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.StoragesContracts;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreDataModels.Models;
+using JewelryStoreFileImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreFileImplement.Implements
+{
+ public class StoreStorage : IStoreStorage
+ {
+ private readonly DataFileSingleton source;
+
+ public StoreStorage()
+ {
+ source = DataFileSingleton.GetInstance();
+ }
+
+ public StoreViewModel? Delete(StoreBindingModel model)
+ {
+ var element = source.Stores.FirstOrDefault(x => x.Id == model.Id);
+ if (element != null)
+ {
+ source.Stores.Remove(element);
+ source.SaveStores();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+
+ public StoreViewModel? GetElement(StoreSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.StoreName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ return source.Stores.FirstOrDefault(x =>
+ (!string.IsNullOrEmpty(model.StoreName) && x.StoreName ==
+ model.StoreName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
+ }
+
+ public List GetFilteredList(StoreSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.StoreName))
+ {
+ return new();
+ }
+ return source.Stores.Where(x =>
+ x.StoreName.Contains(model.StoreName)).Select(x => x.GetViewModel).ToList();
+ }
+
+ public List GetFullList()
+ {
+ return source.Stores.Select(x => x.GetViewModel).ToList();
+ }
+
+ public StoreViewModel? Insert(StoreBindingModel model)
+ {
+ model.Id = source.Stores.Count > 0 ? source.Stores.Max(x => x.Id) + 1 : 1;
+ var newStore = Store.Create(model);
+ if (newStore == null)
+ {
+ return null;
+ }
+ source.Stores.Add(newStore);
+ source.SaveStores();
+ return newStore.GetViewModel;
+ }
+
+ public bool SellJewel(IJewelModel model, int quantity)
+ {
+ if (source.Stores.Select(x => x.StoreJewels.FirstOrDefault(y => y.Key == model.Id).Value.Item2).Sum() < quantity)
+ {
+ return false;
+ }
+ foreach (var store in source.Stores.Where(x => x.StoreJewels.ContainsKey(model.Id)))
+ {
+ int QuantityInCurrentShop = store.StoreJewels[model.Id].Item2;
+ if (QuantityInCurrentShop <= quantity)
+ {
+ store.StoreJewels.Remove(model.Id);
+ quantity -= QuantityInCurrentShop;
+ }
+ else
+ {
+ store.StoreJewels[model.Id] = (store.StoreJewels[model.Id].Item1, QuantityInCurrentShop - quantity);
+ quantity = 0;
+ }
+ if (quantity == 0)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public StoreViewModel? Update(StoreBindingModel model)
+ {
+ var store = source.Stores.FirstOrDefault(x => x.Id == model.Id);
+ if (store == null)
+ {
+ return null;
+ }
+ store.Update(model);
+ source.SaveStores();
+ return store.GetViewModel;
+ }
+ }
+}
diff --git a/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj b/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj
new file mode 100644
index 0000000..783cc4d
--- /dev/null
+++ b/JewelryStoreFileImplement/JewelryStoreFileImplement.csproj
@@ -0,0 +1,14 @@
+
+
+
+ net6.0
+ enable
+ enable
+
+
+
+
+
+
+
+
diff --git a/JewelryStoreFileImplement/Models/Component.cs b/JewelryStoreFileImplement/Models/Component.cs
new file mode 100644
index 0000000..634fb12
--- /dev/null
+++ b/JewelryStoreFileImplement/Models/Component.cs
@@ -0,0 +1,71 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace JewelryStoreFileImplement.Models
+{
+ public class Component : IComponentModel
+ {
+ public int Id { get; private set; }
+ public string ComponentName { get; private set; } = string.Empty;
+ public double Cost { get; set; }
+
+ public static Component? Create(ComponentBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Component()
+ {
+ Id = model.Id,
+ ComponentName = model.ComponentName,
+ Cost = model.Cost
+ };
+ }
+
+ public static Component? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new Component()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ ComponentName = element.Element("ComponentName")!.Value,
+ Cost = Convert.ToDouble(element.Element("Cost")!.Value)
+ };
+ }
+
+
+ public void Update(ComponentBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ ComponentName = model.ComponentName;
+ Cost = model.Cost;
+ }
+ public ComponentViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ComponentName = ComponentName,
+ Cost = Cost
+ };
+
+ public XElement GetXElement => new("Component",
+ new XAttribute("Id", Id),
+ new XElement("ComponentName", ComponentName),
+ new XElement("Cost", Cost.ToString()));
+ }
+}
+
+
diff --git a/JewelryStoreFileImplement/Models/Jewel.cs b/JewelryStoreFileImplement/Models/Jewel.cs
new file mode 100644
index 0000000..0f171bd
--- /dev/null
+++ b/JewelryStoreFileImplement/Models/Jewel.cs
@@ -0,0 +1,95 @@
+using JewelryStoreDataModels.Models;
+using JewelryStoreContracts.ViewModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using JewelryStoreContracts.BindingModels;
+using System.Xml.Linq;
+
+namespace JewelryStoreFileImplement.Models
+{
+ public class Jewel: IJewelModel
+ {
+ public int Id { get; private set; }
+ public string JewelName { get; private set; } = string.Empty;
+ public double Price { get; private set; }
+ public Dictionary Components { get; private set; } = new();
+ private Dictionary? _productComponents = null;
+
+ public Dictionary JewelComponents
+ {
+ get
+ {
+ if (_productComponents == null)
+ {
+ var source = DataFileSingleton.GetInstance();
+ _productComponents = Components.ToDictionary(x => x.Key, y =>
+ ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!,
+ y.Value));
+ }
+ return _productComponents;
+ }
+ }
+
+ public static Jewel? Create(JewelBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Jewel()
+ {
+ Id = model.Id,
+ JewelName = model.JewelName,
+ Price = model.Price,
+ Components = model.JewelComponents.ToDictionary(x => x.Key, x
+ => x.Value.Item2)
+ };
+ }
+
+ public static Jewel? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new Jewel()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ JewelName = element.Element("JewelName")!.Value,
+ Price = Convert.ToDouble(element.Element("Price")!.Value),
+ Components =
+ element.Element("JewelComponents")!.Elements("JewelComponent").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x =>
+ Convert.ToInt32(x.Element("Value")?.Value))
+ };
+ }
+
+ public void Update(JewelBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ JewelName = model.JewelName;
+ Price = model.Price;
+ Components = model.JewelComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
+ _productComponents = null;
+ }
+ public JewelViewModel GetViewModel => new()
+ {
+ Id = Id,
+ JewelName = JewelName,
+ Price = Price,
+ JewelComponents = JewelComponents
+ };
+ public XElement GetXElement => new("Jewel",
+ new XAttribute("Id", Id),
+ new XElement("JewelName", JewelName),
+ new XElement("Price", Price.ToString()),
+ new XElement("JewelComponents", Components.Select(x =>new XElement("JewelComponent",new XElement("Key", x.Key),
+ new XElement("Value", x.Value))).ToArray()));
+
+ }
+}
diff --git a/JewelryStoreFileImplement/Models/Order.cs b/JewelryStoreFileImplement/Models/Order.cs
new file mode 100644
index 0000000..fc8fa48
--- /dev/null
+++ b/JewelryStoreFileImplement/Models/Order.cs
@@ -0,0 +1,112 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreDataModels.Enums;
+using JewelryStoreDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace JewelryStoreFileImplement.Models
+{
+ public class Order : IOrderModel
+ {
+ public int JewelId { get; private set; }
+
+ public string JewelName { get; private set; } = string.Empty;
+
+ public int Count { get; private set; }
+
+ public double Sum { get; private set; }
+
+ public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
+
+ public DateTime DateCreate { get; private set; } = DateTime.Now;
+
+ public DateTime? DateImplement { get; private set; }
+
+ public int Id { get; private set; }
+
+ public static Order? Create(OrderBindingModel model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Order()
+ {
+ Id = model.Id,
+ JewelId = model.JewelId,
+ JewelName = model.JewelName,
+ Count = model.Count,
+ Sum = model.Sum,
+ Status = model.Status,
+ DateCreate = model.DateCreate,
+ DateImplement = model.DateImplement
+ };
+ }
+
+ public static Order? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+
+ var order = new Order()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ JewelId = Convert.ToInt32(element.Element("JewelId")!.Value),
+ JewelName = element.Element("JewelName")!.Value,
+ Count = Convert.ToInt32(element.Element("Count")!.Value),
+ Sum = Convert.ToDouble(element.Element("Sum")!.Value),
+ Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
+ DateCreate = DateTime.ParseExact(element.Element("DateCreate")!.Value, "G", null)
+ };
+
+ DateTime.TryParse(element.Element("DateImplement")!.Value, out DateTime dateImpl);
+ order.DateImplement = dateImpl;
+
+ return order;
+ }
+
+ public void Update(OrderBindingModel model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ JewelId = model.JewelId;
+ JewelName = model.JewelName;
+ Count = model.Count;
+ Sum = model.Sum;
+ Status = model.Status;
+ DateCreate = model.DateCreate;
+ DateImplement = model.DateImplement;
+ }
+
+ public OrderViewModel GetViewModel => new()
+ {
+ Id = Id,
+ JewelId = JewelId,
+ JewelName = JewelName,
+ Count = Count,
+ Sum = Sum,
+ Status = Status,
+ DateCreate = DateCreate,
+ DateImplement = DateImplement
+ };
+
+ public XElement GetXElement => new("Order",
+ new XAttribute("Id", Id),
+ new XElement("JewelName", JewelName),
+ new XElement("JewelId", JewelId.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()));
+ }
+}
diff --git a/JewelryStoreFileImplement/Models/Store.cs b/JewelryStoreFileImplement/Models/Store.cs
new file mode 100644
index 0000000..ddef9c2
--- /dev/null
+++ b/JewelryStoreFileImplement/Models/Store.cs
@@ -0,0 +1,107 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreDataModels.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace JewelryStoreFileImplement.Models
+{
+ public class Store : IStoreModel
+ {
+ public string StoreName { get; private set; } = string.Empty;
+ public string StoreAdress { get; private set; } = string.Empty;
+
+ public DateTime OpeningDate { get; private set; }
+ public Dictionary Jewels { get; private set; } = new();
+
+ public Dictionary _storeJewels = null;
+ public Dictionary StoreJewels
+ {
+ get
+ {
+ if (_storeJewels == null)
+ {
+ var source = DataFileSingleton.GetInstance();
+ _storeJewels = Jewels.ToDictionary(x => x.Key, y => ((source.Jewels.FirstOrDefault(z => z.Id == y.Key) as IJewelModel)!, y.Value));
+ }
+ return _storeJewels;
+ }
+ }
+
+ public int Id { get; private set; }
+
+ public int JewelMaxCount { get; private set; }
+
+ public static Store? Create(StoreBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Store()
+ {
+ Id = model.Id,
+ StoreName = model.StoreName,
+ StoreAdress = model.StoreAdress,
+ JewelMaxCount = model.JewelMaxCount,
+ OpeningDate = model.OpeningDate,
+ Jewels = model.StoreJewels.ToDictionary(x => x.Key, x => x.Value.Item2)
+ };
+ }
+ public static Store? Create(XElement element)
+ {
+ if (element == null)
+ {
+ return null;
+ }
+ return new()
+ {
+ Id = Convert.ToInt32(element.Attribute("Id")!.Value),
+ StoreName = element.Element("StoreName")!.Value,
+ StoreAdress = element.Element("StoreAdress")!.Value,
+ OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
+ JewelMaxCount = Convert.ToInt32(element.Element("JewelMaxCount")!.Value),
+ Jewels = element.Element("StoreJewels")!.Elements("Jewel").ToDictionary(
+ x => Convert.ToInt32(x.Element("Key")?.Value),
+ x => Convert.ToInt32(x.Element("Value")?.Value))
+ };
+ }
+ public void Update(StoreBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ StoreName = model.StoreName;
+ StoreAdress = model.StoreAdress;
+ OpeningDate = model.OpeningDate;
+ JewelMaxCount = model.JewelMaxCount;
+ Jewels = model.StoreJewels.ToDictionary(x => x.Key, x => x.Value.Item2);
+ _storeJewels = null;
+ }
+ public StoreViewModel GetViewModel => new()
+ {
+ Id = Id,
+ StoreName = StoreName,
+ StoreAdress = StoreAdress,
+ StoreJewels = StoreJewels,
+ OpeningDate = OpeningDate,
+ JewelMaxCount = JewelMaxCount,
+ };
+ public XElement GetXElement => new("Store",
+ new XAttribute("Id", Id),
+ new XElement("StoreName", StoreName),
+ new XElement("StoreAdress", StoreAdress),
+ new XElement("OpeningDate", OpeningDate),
+ new XElement("JewelMaxCount", JewelMaxCount),
+ new XElement("StoreJewels", Jewels
+ .Select(x => new XElement("Jewel",
+ new XElement("Key", x.Key),
+ new XElement("Value", x.Value))
+ ).ToArray()));
+ }
+}
diff --git a/JewelryStoreListImplement/DataListSingleton.cs b/JewelryStoreListImplement/DataListSingleton.cs
index 1b280c4..49ea268 100644
--- a/JewelryStoreListImplement/DataListSingleton.cs
+++ b/JewelryStoreListImplement/DataListSingleton.cs
@@ -13,11 +13,13 @@ namespace JewelryStoreListImplement
public List Components { get; set; }
public List Orders { get; set; }
public List Jewels { get; set; }
+ public List Stores { get; set; }
private DataListSingleton()
{
Components = new List();
Orders = new List();
Jewels = new List();
+ Stores = new List();
}
public static DataListSingleton GetInstance()
{
diff --git a/JewelryStoreListImplement/Implements/StoreStorage.cs b/JewelryStoreListImplement/Implements/StoreStorage.cs
new file mode 100644
index 0000000..46de38b
--- /dev/null
+++ b/JewelryStoreListImplement/Implements/StoreStorage.cs
@@ -0,0 +1,129 @@
+using JewelryStoreContracts.BindingModels;
+using JewelryStoreContracts.SearchModels;
+using JewelryStoreContracts.StoragesContracts;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreDataModels.Models;
+using JewelryStoreListImplement.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreListImplement.Implements
+{
+ public class StoreStorage: IStoreStorage
+ {
+ private readonly DataListSingleton _source;
+ public StoreStorage()
+ {
+ _source = DataListSingleton.GetInstance();
+ }
+ public StoreViewModel? Delete(StoreBindingModel model)
+ {
+ for (int i = 0; i < _source.Stores.Count; ++i)
+ {
+ if (_source.Stores[i].Id == model.Id)
+ {
+ var element = _source.Stores[i];
+ _source.Stores.RemoveAt(i);
+ return element.GetViewModel;
+ }
+ }
+ return null;
+ }
+
+ public StoreViewModel? GetElement(StoreSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.StoreName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+
+ foreach (var store in _source.Stores)
+ {
+ if ((!string.IsNullOrEmpty(model.StoreName) && store.StoreName == model.StoreName) || (model.Id.HasValue && store.Id == model.Id))
+ {
+ return store.GetViewModel;
+ }
+ }
+
+ return null;
+ }
+
+ public List GetFilteredList(StoreSearchModel model)
+ {
+ var result = new List();
+
+ if (string.IsNullOrEmpty(model.StoreName))
+ {
+ return result;
+ }
+
+ foreach (var store in _source.Stores)
+ {
+ if (store.StoreName.Contains(model.StoreName))
+ {
+ result.Add(store.GetViewModel);
+ }
+ }
+
+ return result;
+ }
+
+ public List GetFullList()
+ {
+ var result = new List();
+
+ foreach (var store in _source.Stores)
+ {
+ result.Add(store.GetViewModel);
+ }
+
+ return result;
+ }
+
+ public StoreViewModel? Insert(StoreBindingModel model)
+ {
+ model.Id = 1;
+
+ foreach (var store in _source.Stores)
+ {
+ if (model.Id <= store.Id)
+ {
+ model.Id = store.Id + 1;
+ }
+ }
+
+ var newStore = Store.Create(model);
+
+ if (newStore == null)
+ {
+ return null;
+ }
+
+ _source.Stores.Add(newStore);
+
+ return newStore.GetViewModel;
+ }
+
+ public bool SellJewel(IJewelModel model, int quantity)
+ {
+ throw new NotImplementedException();
+ }
+
+ public StoreViewModel? Update(StoreBindingModel model)
+ {
+ foreach (var store in _source.Stores)
+ {
+ if (store.Id == model.Id)
+ {
+ store.Update(model);
+ return store.GetViewModel;
+ }
+ }
+
+ return null;
+ }
+ }
+}
diff --git a/JewelryStoreListImplement/Models/Store.cs b/JewelryStoreListImplement/Models/Store.cs
new file mode 100644
index 0000000..aa22c3e
--- /dev/null
+++ b/JewelryStoreListImplement/Models/Store.cs
@@ -0,0 +1,62 @@
+using JewelryStoreDataModels.Models;
+using JewelryStoreContracts.ViewModels;
+using JewelryStoreContracts.BindingModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace JewelryStoreListImplement.Models
+{
+ public class Store : IStoreModel
+ {
+ public string StoreName { get; private set; } = string.Empty;
+ public string StoreAdress { get; private set; } = string.Empty;
+
+ public DateTime OpeningDate { get; private set; }
+
+ public Dictionary StoreJewels { get; private set; } = new();
+
+ public int Id { get; private set; }
+
+ public static Store? Create(StoreBindingModel? model)
+ {
+ if (model == null)
+ {
+ return null;
+ }
+ return new Store()
+ {
+ Id = model.Id,
+ StoreName = model.StoreName,
+ StoreAdress = model.StoreAdress,
+ OpeningDate = model.OpeningDate,
+ StoreJewels = new()
+ };
+ }
+
+ public void Update(StoreBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+ StoreName = model.StoreName;
+ StoreAdress = model.StoreAdress;
+ OpeningDate = model.OpeningDate;
+ StoreJewels = model.StoreJewels;
+ }
+
+ public StoreViewModel GetViewModel => new()
+ {
+ Id = Id,
+ StoreName = StoreName,
+ StoreAdress = StoreAdress,
+ OpeningDate = OpeningDate,
+ StoreJewels = StoreJewels
+ };
+
+ public int JewelMaxCount => throw new NotImplementedException();
+ }
+}