2 усложненная

This commit is contained in:
VictoriaPresnyakova 2023-06-16 22:01:12 +04:00
parent 7e33506003
commit e23105958f
9 changed files with 712 additions and 343 deletions

View File

@ -1,199 +1,211 @@
namespace JewelryStore namespace JewelryStore
{ {
partial class FormMain
{ partial class FormMain
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{ {
if (disposing && (components != null)) /// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{ {
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
/// <summary> /// <summary>
/// Required method for Designer support - do not modify /// Required method for Designer support - do not modify
/// the contents of this method with the code editor. /// the contents of this method with the code editor.
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.buttonReady = new System.Windows.Forms.Button(); this.MenuStrip = new System.Windows.Forms.MenuStrip();
this.dataGridView = new System.Windows.Forms.DataGridView(); this.СправочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonCreate = new System.Windows.Forms.Button(); this.ИзделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonToWork = new System.Windows.Forms.Button(); this.КомпонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonPut = new System.Windows.Forms.Button(); this.StoreToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonRefresh = new System.Windows.Forms.Button(); this.DataGridView = new System.Windows.Forms.DataGridView();
this.StoreReplenishment = new System.Windows.Forms.Button(); this.CreateOrderButton = new System.Windows.Forms.Button();
this.menuStrip = new System.Windows.Forms.MenuStrip(); this.TakeOrderInWorkButton = new System.Windows.Forms.Button();
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.OrderReadyButton = new System.Windows.Forms.Button();
this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.IssuedOrderButton = new System.Windows.Forms.Button();
this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.UpdateListButton = new System.Windows.Forms.Button();
this.StoreToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.StoreReplenishment = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SellJewelButton = new System.Windows.Forms.Button();
this.menuStrip.SuspendLayout(); this.MenuStrip.SuspendLayout();
this.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
// this.SuspendLayout();
// buttonReady //
// // MenuStrip
this.buttonReady.Location = new System.Drawing.Point(1273, 225); //
this.buttonReady.Name = "buttonReady"; this.MenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.buttonReady.Size = new System.Drawing.Size(215, 34); this.СправочникиToolStripMenuItem});
this.buttonReady.TabIndex = 3; this.MenuStrip.Location = new System.Drawing.Point(0, 0);
this.buttonReady.Text = "Заказ готов"; this.MenuStrip.Name = "MenuStrip";
this.buttonReady.UseVisualStyleBackColor = true; this.MenuStrip.Size = new System.Drawing.Size(865, 24);
this.buttonReady.Click += new System.EventHandler(this.buttonReady_Click); this.MenuStrip.TabIndex = 0;
// this.MenuStrip.Text = "menuStrip1";
// dataGridView //
// // СправочникиToolStripMenuItem
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; //
this.dataGridView.Location = new System.Drawing.Point(9, 52); this.СправочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.dataGridView.Name = "dataGridView"; this.ИзделияToolStripMenuItem,
this.dataGridView.RowHeadersWidth = 62; this.КомпонентыToolStripMenuItem,
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, 395);
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);
//
// StoreReplenishment
//
this.StoreReplenishment.Location = new System.Drawing.Point(1273, 469);
this.StoreReplenishment.Name = "StoreReplenishment";
this.StoreReplenishment.Size = new System.Drawing.Size(215, 31);
this.StoreReplenishment.TabIndex = 6;
this.StoreReplenishment.Text = "Пополнение магазина";
this.StoreReplenishment.UseVisualStyleBackColor = true;
this.StoreReplenishment.Click += new System.EventHandler(this.StoreReplenishment_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.StoreToolStripMenuItem}); this.StoreToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; this.СправочникиToolStripMenuItem.Name = "СправочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29); this.СправочникиToolStripMenuItem.Size = new System.Drawing.Size(94, 20);
this.справочникиToolStripMenuItem.Text = "Справочники"; this.СправочникиToolStripMenuItem.Text = "Cправочники";
// //
// компонентыToolStripMenuItem // ИзделияToolStripMenuItem
// //
this.компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem"; this.ИзделияToolStripMenuItem.Name = "ИзделияToolStripMenuItem";
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(270, 34); this.ИзделияToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.компонентыToolStripMenuItem.Text = "Компоненты"; this.ИзделияToolStripMenuItem.Text = "Изделия";
this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click); this.ИзделияToolStripMenuItem.Click += new System.EventHandler(this.ИзделияToolStripMenuItem_Click);
// //
// изделияToolStripMenuItem // КомпонентыToolStripMenuItem
// //
this.изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; this.КомпонентыToolStripMenuItem.Name = "КомпонентыToolStripMenuItem";
this.изделияToolStripMenuItem.Size = new System.Drawing.Size(270, 34); this.КомпонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.изделияToolStripMenuItem.Text = "Драгоценности"; this.КомпонентыToolStripMenuItem.Text = "Компоненты";
this.изделияToolStripMenuItem.Click += new System.EventHandler(this.драгоценностиToolStripMenuItem_Click); this.КомпонентыToolStripMenuItem.Click += new System.EventHandler(this.КомпонентыToolStripMenuItem_Click);
// //
// StoreToolStripMenuItem // StoreToolStripMenuItem
// //
this.StoreToolStripMenuItem.Name = "StoreToolStripMenuItem"; this.StoreToolStripMenuItem.Name = "StoreToolStripMenuItem";
this.StoreToolStripMenuItem.Size = new System.Drawing.Size(270, 34); this.StoreToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.StoreToolStripMenuItem.Text = "Магазины"; this.StoreToolStripMenuItem.Text = "Магазины";
this.StoreToolStripMenuItem.Click += new System.EventHandler(this.StoreToolStripMenuItem_Click); this.StoreToolStripMenuItem.Click += new System.EventHandler(this.StoreToolStripMenuItem_Click);
// //
// FormMain // DataGridView
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.DataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.DataGridView.Location = new System.Drawing.Point(0, 27);
this.ClientSize = new System.Drawing.Size(1530, 599); this.DataGridView.Name = "DataGridView";
this.Controls.Add(this.StoreReplenishment); this.DataGridView.RowTemplate.Height = 25;
this.Controls.Add(this.buttonRefresh); this.DataGridView.Size = new System.Drawing.Size(722, 421);
this.Controls.Add(this.buttonPut); this.DataGridView.TabIndex = 1;
this.Controls.Add(this.buttonReady); //
this.Controls.Add(this.buttonToWork); // CreateOrderButton
this.Controls.Add(this.buttonCreate); //
this.Controls.Add(this.dataGridView); this.CreateOrderButton.Location = new System.Drawing.Point(728, 28);
this.Controls.Add(this.menuStrip); this.CreateOrderButton.Name = "CreateOrderButton";
this.MainMenuStrip = this.menuStrip; this.CreateOrderButton.Size = new System.Drawing.Size(125, 33);
this.Name = "FormMain"; this.CreateOrderButton.TabIndex = 2;
this.Text = "Изготовление Драгоценностей"; this.CreateOrderButton.Text = "Создать заказ";
this.Load += new System.EventHandler(this.FormMain_Load); this.CreateOrderButton.UseVisualStyleBackColor = true;
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); this.CreateOrderButton.Click += new System.EventHandler(this.CreateOrderButton_Click);
this.menuStrip.ResumeLayout(false); //
this.menuStrip.PerformLayout(); // TakeOrderInWorkButton
this.ResumeLayout(false); //
this.PerformLayout(); 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 MenuStrip MenuStrip;
private Button buttonCreate; private ToolStripMenuItem СправочникиToolStripMenuItem;
private Button buttonToWork; private ToolStripMenuItem ИзделияToolStripMenuItem;
private Button buttonPut; private ToolStripMenuItem КомпонентыToolStripMenuItem;
private Button buttonRefresh; private DataGridView DataGridView;
private MenuStrip menuStrip; private Button CreateOrderButton;
private ToolStripMenuItem справочникиToolStripMenuItem; private Button TakeOrderInWorkButton;
private ToolStripMenuItem компонентыToolStripMenuItem; private Button OrderReadyButton;
private ToolStripMenuItem изделияToolStripMenuItem; private Button IssuedOrderButton;
private ToolStripMenuItem StoreToolStripMenuItem; private Button UpdateListButton;
private Button buttonReady; private ToolStripMenuItem StoreToolStripMenuItem;
private Button StoreReplenishment; private Button StoreReplenishment;
private Button SellJewelButton;
} }
} }

View File

@ -16,6 +16,7 @@ namespace JewelryStore
{ {
public partial class FormMain : Form public partial class FormMain : Form
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic; private readonly IOrderLogic _orderLogic;
@ -24,24 +25,26 @@ namespace JewelryStore
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_orderLogic = orderLogic; _orderLogic = orderLogic;
LoadData();
} }
private void FormMain_Load(object sender, EventArgs e) private void FormMain_Load(object sender, EventArgs e)
{ {
LoadData(); LoadData();
} }
private void LoadData() private void LoadData()
{ {
_logger.LogInformation("Загрузка заказов"); _logger.LogInformation("Загрузка заказов");
try try
{ {
var list = _orderLogic.ReadList(null); var list = _orderLogic.ReadList(null);
if (list != null) if (list != null)
{ {
dataGridView.DataSource = list; DataGridView.DataSource = list;
dataGridView.Columns["JewelId"].Visible = false; DataGridView.Columns["JewelId"].Visible = false;
} }
_logger.LogInformation("Загрузка заказов"); _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)); var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
if (service is FormComponents form) if (service is FormComponents form)
{ {
form.ShowDialog(); 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)); 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)); var service = Program.ServiceProvider?.GetService(typeof(FormCreateOrder));
if (service is FormCreateOrder form) if (service is FormCreateOrder form)
{ {
form.ShowDialog(); 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); _logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
try try
{ {
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
{ {
Id = id, Id = id,
JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), JewelId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["JewelId"].Value),
JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), JewelName = DataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), Status = Enum.Parse<OrderStatus>(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)
{ {
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
} }
LoadData(); LoadData();
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка передачи заказа в работу"); _logger.LogError(ex, "Ошибка передачи заказа в работу");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxIcon.Error);
} }
} }
} }
private void 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); _logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
try try
{ {
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
{ {
Id = id, Id = id,
JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), JewelId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["JewelId"].Value),
JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), JewelName = DataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), Status = Enum.Parse<OrderStatus>(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)
{ {
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
} }
LoadData(); LoadData();
} }
catch (Exception ex) catch (Exception ex)
@ -146,58 +155,49 @@ namespace JewelryStore
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); 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); _logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
try try
{ {
var operationResult = _orderLogic.DeliveryOrder(new var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
OrderBindingModel
{ {
Id = id, Id = id,
JewelId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["JewelId"].Value), JewelId = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["JewelId"].Value),
JewelName = dataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(), JewelName = DataGridView.SelectedRows[0].Cells["JewelName"].Value.ToString(),
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()), Status = Enum.Parse<OrderStatus>(DataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value), Count = Convert.ToInt32(DataGridView.SelectedRows[0].Cells["Count"].Value),
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()), Sum = double.Parse(DataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), DateCreate = DateTime.Parse(DataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
}); });
if (!operationResult) if (!operationResult)
{ {
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
} }
_logger.LogInformation("Заказ №{id} выдан", id); _logger.LogInformation("Заказ №{id} выдан", id);
LoadData(); LoadData();
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка отметки о выдачи заказа"); _logger.LogError(ex, "Ошибка отметки о выдачи заказа");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxIcon.Error);
} }
} }
} }
private void buttonRefresh_Click(object sender, EventArgs e) private void UpdateListButton_Click(object sender, EventArgs e)
{ {
LoadData(); LoadData();
} }
private void StoreToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormStores));
if (service is FormStores form)
{
form.ShowDialog();
}
}
private void StoreReplenishment_Click(object sender, EventArgs e) private void StoreReplenishment_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment)); var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment));
@ -207,5 +207,25 @@ namespace JewelryStore
form.ShowDialog(); 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();
}
}
} }
} }

120
JewelryStore/FormSellJewel.Designer.cs generated Normal file
View File

@ -0,0 +1,120 @@
namespace JewelryStore
{
partial class FormSellJewel
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.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;
}
}

View File

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

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -31,7 +31,7 @@
this.StoreNameLabel = new System.Windows.Forms.Label(); this.StoreNameLabel = new System.Windows.Forms.Label();
this.StoreAdressLabel = new System.Windows.Forms.Label(); this.StoreAdressLabel = new System.Windows.Forms.Label();
this.OpeningDateLabel = new System.Windows.Forms.Label(); this.OpeningDateLabel = new System.Windows.Forms.Label();
this.NameTextBox = new System.Windows.Forms.TextBox(); this.NameComboBox = new System.Windows.Forms.ComboBox();
this.AdressTextBox = new System.Windows.Forms.TextBox(); this.AdressTextBox = new System.Windows.Forms.TextBox();
this.DataGridView = new System.Windows.Forms.DataGridView(); this.DataGridView = new System.Windows.Forms.DataGridView();
this.JewelName = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.JewelName = new System.Windows.Forms.DataGridViewTextBoxColumn();
@ -40,53 +40,52 @@
this.SaveButton = new System.Windows.Forms.Button(); this.SaveButton = new System.Windows.Forms.Button();
this.ButtonCancel = new System.Windows.Forms.Button(); this.ButtonCancel = new System.Windows.Forms.Button();
this.OpeningDatePicker = new System.Windows.Forms.DateTimePicker(); this.OpeningDatePicker = new System.Windows.Forms.DateTimePicker();
this.VolumeNumericUpDown = new System.Windows.Forms.NumericUpDown();
this.JewelMaxCountLable = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.VolumeNumericUpDown)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// StoreNameLabel // StoreNameLabel
// //
this.StoreNameLabel.AutoSize = true; this.StoreNameLabel.AutoSize = true;
this.StoreNameLabel.Location = new System.Drawing.Point(17, 15); this.StoreNameLabel.Location = new System.Drawing.Point(12, 9);
this.StoreNameLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.StoreNameLabel.Name = "StoreNameLabel"; this.StoreNameLabel.Name = "StoreNameLabel";
this.StoreNameLabel.Size = new System.Drawing.Size(179, 25); this.StoreNameLabel.Size = new System.Drawing.Size(119, 15);
this.StoreNameLabel.TabIndex = 0; this.StoreNameLabel.TabIndex = 0;
this.StoreNameLabel.Text = "Название магазина: "; this.StoreNameLabel.Text = "Название магазина: ";
// //
// StoreAdressLabel // StoreAdressLabel
// //
this.StoreAdressLabel.AutoSize = true; this.StoreAdressLabel.AutoSize = true;
this.StoreAdressLabel.Location = new System.Drawing.Point(17, 67); this.StoreAdressLabel.Location = new System.Drawing.Point(12, 40);
this.StoreAdressLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.StoreAdressLabel.Name = "StoreAdressLabel"; this.StoreAdressLabel.Name = "StoreAdressLabel";
this.StoreAdressLabel.Size = new System.Drawing.Size(151, 25); this.StoreAdressLabel.Size = new System.Drawing.Size(100, 15);
this.StoreAdressLabel.TabIndex = 1; this.StoreAdressLabel.TabIndex = 1;
this.StoreAdressLabel.Text = "Адрес магазина: "; this.StoreAdressLabel.Text = "Адрес магазина: ";
// //
// OpeningDateLabel // OpeningDateLabel
// //
this.OpeningDateLabel.AutoSize = true; this.OpeningDateLabel.AutoSize = true;
this.OpeningDateLabel.Location = new System.Drawing.Point(17, 120); this.OpeningDateLabel.Location = new System.Drawing.Point(12, 72);
this.OpeningDateLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.OpeningDateLabel.Name = "OpeningDateLabel"; this.OpeningDateLabel.Name = "OpeningDateLabel";
this.OpeningDateLabel.Size = new System.Drawing.Size(140, 25); this.OpeningDateLabel.Size = new System.Drawing.Size(93, 15);
this.OpeningDateLabel.TabIndex = 2; this.OpeningDateLabel.TabIndex = 2;
this.OpeningDateLabel.Text = "Дата открытия: "; this.OpeningDateLabel.Text = "Дата открытия: ";
// //
// NameTextBox // NameComboBox
// //
this.NameTextBox.Location = new System.Drawing.Point(196, 10); this.NameComboBox.FormattingEnabled = true;
this.NameTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); this.NameComboBox.Location = new System.Drawing.Point(137, 6);
this.NameTextBox.Name = "NameTextBox"; this.NameComboBox.Name = "NameComboBox";
this.NameTextBox.Size = new System.Drawing.Size(247, 31); this.NameComboBox.Size = new System.Drawing.Size(174, 23);
this.NameTextBox.TabIndex = 3; this.NameComboBox.TabIndex = 3;
// //
// AdressTextBox // AdressTextBox
// //
this.AdressTextBox.Location = new System.Drawing.Point(196, 62); this.AdressTextBox.Location = new System.Drawing.Point(137, 37);
this.AdressTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.AdressTextBox.Name = "AdressTextBox"; this.AdressTextBox.Name = "AdressTextBox";
this.AdressTextBox.Size = new System.Drawing.Size(247, 31); this.AdressTextBox.Size = new System.Drawing.Size(174, 23);
this.AdressTextBox.TabIndex = 4; this.AdressTextBox.TabIndex = 4;
// //
// DataGridView // DataGridView
@ -96,41 +95,33 @@
this.JewelName, this.JewelName,
this.JewelPrice, this.JewelPrice,
this.JewelCount}); this.JewelCount});
this.DataGridView.Location = new System.Drawing.Point(17, 182); this.DataGridView.Location = new System.Drawing.Point(12, 109);
this.DataGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.DataGridView.Name = "DataGridView"; this.DataGridView.Name = "DataGridView";
this.DataGridView.RowHeadersWidth = 62;
this.DataGridView.RowTemplate.Height = 25; this.DataGridView.RowTemplate.Height = 25;
this.DataGridView.Size = new System.Drawing.Size(1109, 480); this.DataGridView.Size = new System.Drawing.Size(776, 288);
this.DataGridView.TabIndex = 6; this.DataGridView.TabIndex = 6;
// //
// JewelName // JewelName
// //
this.JewelName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; this.JewelName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.JewelName.HeaderText = "Название изделия"; this.JewelName.HeaderText = "Название изделия";
this.JewelName.MinimumWidth = 8;
this.JewelName.Name = "JewelName"; this.JewelName.Name = "JewelName";
// //
// JewelPrice // JewelPrice
// //
this.JewelPrice.HeaderText = "Цена"; this.JewelPrice.HeaderText = "Цена";
this.JewelPrice.MinimumWidth = 8;
this.JewelPrice.Name = "JewelPrice"; this.JewelPrice.Name = "JewelPrice";
this.JewelPrice.Width = 150;
// //
// JewelCount // JewelCount
// //
this.JewelCount.HeaderText = "Количество"; this.JewelCount.HeaderText = "Количество";
this.JewelCount.MinimumWidth = 8;
this.JewelCount.Name = "JewelCount"; this.JewelCount.Name = "JewelCount";
this.JewelCount.Width = 150;
// //
// SaveButton // SaveButton
// //
this.SaveButton.Location = new System.Drawing.Point(789, 672); this.SaveButton.Location = new System.Drawing.Point(552, 403);
this.SaveButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.SaveButton.Name = "SaveButton"; this.SaveButton.Name = "SaveButton";
this.SaveButton.Size = new System.Drawing.Size(164, 58); this.SaveButton.Size = new System.Drawing.Size(115, 35);
this.SaveButton.TabIndex = 7; this.SaveButton.TabIndex = 7;
this.SaveButton.Text = "Сохранить"; this.SaveButton.Text = "Сохранить";
this.SaveButton.UseVisualStyleBackColor = true; this.SaveButton.UseVisualStyleBackColor = true;
@ -138,10 +129,9 @@
// //
// ButtonCancel // ButtonCancel
// //
this.ButtonCancel.Location = new System.Drawing.Point(961, 672); this.ButtonCancel.Location = new System.Drawing.Point(673, 403);
this.ButtonCancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.ButtonCancel.Name = "ButtonCancel"; this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(164, 58); this.ButtonCancel.Size = new System.Drawing.Size(115, 35);
this.ButtonCancel.TabIndex = 8; this.ButtonCancel.TabIndex = 8;
this.ButtonCancel.Text = "Отменить"; this.ButtonCancel.Text = "Отменить";
this.ButtonCancel.UseVisualStyleBackColor = true; this.ButtonCancel.UseVisualStyleBackColor = true;
@ -149,31 +139,48 @@
// //
// OpeningDatePicker // OpeningDatePicker
// //
this.OpeningDatePicker.Location = new System.Drawing.Point(196, 110); this.OpeningDatePicker.Location = new System.Drawing.Point(137, 66);
this.OpeningDatePicker.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.OpeningDatePicker.Name = "OpeningDatePicker"; this.OpeningDatePicker.Name = "OpeningDatePicker";
this.OpeningDatePicker.Size = new System.Drawing.Size(247, 31); this.OpeningDatePicker.Size = new System.Drawing.Size(174, 23);
this.OpeningDatePicker.TabIndex = 9; this.OpeningDatePicker.TabIndex = 9;
// //
// VolumeNumericUpDown
//
this.VolumeNumericUpDown.Location = new System.Drawing.Point(486, 7);
this.VolumeNumericUpDown.Name = "VolumeNumericUpDown";
this.VolumeNumericUpDown.Size = new System.Drawing.Size(168, 23);
this.VolumeNumericUpDown.TabIndex = 10;
//
// 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 // FormStore
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1143, 750); 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.OpeningDatePicker);
this.Controls.Add(this.ButtonCancel); this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.SaveButton); this.Controls.Add(this.SaveButton);
this.Controls.Add(this.DataGridView); this.Controls.Add(this.DataGridView);
this.Controls.Add(this.AdressTextBox); this.Controls.Add(this.AdressTextBox);
this.Controls.Add(this.NameTextBox); this.Controls.Add(this.NameComboBox);
this.Controls.Add(this.OpeningDateLabel); this.Controls.Add(this.OpeningDateLabel);
this.Controls.Add(this.StoreAdressLabel); this.Controls.Add(this.StoreAdressLabel);
this.Controls.Add(this.StoreNameLabel); this.Controls.Add(this.StoreNameLabel);
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.Name = "FormStore"; this.Name = "FormStore";
this.Text = "Изделия магазина"; this.Text = "Изделия магазина";
this.Load += new System.EventHandler(this.FormStore_Load); this.Load += new System.EventHandler(this.FormStore_Load);
((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.DataGridView)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.VolumeNumericUpDown)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@ -184,7 +191,7 @@
private Label StoreNameLabel; private Label StoreNameLabel;
private Label StoreAdressLabel; private Label StoreAdressLabel;
private Label OpeningDateLabel; private Label OpeningDateLabel;
private TextBox NameTextBox; private ComboBox NameComboBox;
private TextBox AdressTextBox; private TextBox AdressTextBox;
private DataGridView DataGridView; private DataGridView DataGridView;
private Button SaveButton; private Button SaveButton;
@ -193,5 +200,7 @@
private DataGridViewTextBoxColumn JewelPrice; private DataGridViewTextBoxColumn JewelPrice;
private DataGridViewTextBoxColumn JewelCount; private DataGridViewTextBoxColumn JewelCount;
private DateTimePicker OpeningDatePicker; private DateTimePicker OpeningDatePicker;
private NumericUpDown VolumeNumericUpDown;
private Label JewelMaxCountLable;
} }
} }

View File

@ -1,5 +1,6 @@
using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BindingModels;
using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.BusinessLogicsContracts;
using JewelryStoreContracts.SearchModels;
using JewelryStoreContracts.ViewModels; using JewelryStoreContracts.ViewModels;
using JewelryStoreDataModels.Models; using JewelryStoreDataModels.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -17,78 +18,48 @@ namespace JewelryStore
{ {
public partial class FormStore : Form public partial class FormStore : Form
{ {
private readonly List<StoreViewModel>? _listStores;
private readonly IStoreLogic _logic; private readonly IStoreLogic _logic;
private readonly ILogger _logger; private readonly ILogger _logger;
public int Id { get; set; } private int? _id;
private Dictionary<int, (IJewelModel, int)> _listStores;
public int Id { set { _id = value; } }
public FormStore(ILogger<FormStore> logger, IStoreLogic logic) public FormStore(ILogger<FormStore> logger, IStoreLogic logic)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_listStores = logic.ReadList(null); _listStores = new();
_logic = logic; _logic = logic;
} }
private IStoreModel? GetStore(int id)
{
if (_listStores == null)
{
return null;
}
foreach (var elem in _listStores)
{
if (elem.Id == id)
{
return elem;
}
}
return null;
}
private void SaveButton_Click(object sender, EventArgs e) private void SaveButton_Click(object sender, EventArgs e)
{ {
if (string.IsNullOrEmpty(NameTextBox.Text)) if (string.IsNullOrEmpty(NameComboBox.Text))
{ {
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
if (string.IsNullOrEmpty(AdressTextBox.Text)) if (string.IsNullOrEmpty(AdressTextBox.Text))
{ {
MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return; return;
} }
_logger.LogInformation("Сохранение магазина"); _logger.LogInformation("Сохранение магазина");
try try
{ {
DateTime.TryParse(OpeningDatePicker.Text, out var dateTime); var model = new StoreBindingModel
StoreBindingModel model = new()
{ {
StoreName = NameTextBox.Text, Id = _id ?? 0,
StoreName = NameComboBox.Text,
StoreAdress = AdressTextBox.Text, StoreAdress = AdressTextBox.Text,
OpeningDate = dateTime OpeningDate = OpeningDatePicker.Value.Date,
JewelMaxCount = (int)VolumeNumericUpDown.Value
}; };
var vmodel = GetStore(Id); var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
bool operationResult = false;
if (vmodel != null)
{
model.Id = vmodel.Id;
operationResult = _logic.Update(model);
}
else
{
operationResult = _logic.Create(model);
}
if (!operationResult) if (!operationResult)
{ {
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
} }
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
Close(); Close();
@ -108,34 +79,52 @@ namespace JewelryStore
private void FormStore_Load(object sender, EventArgs e) private void FormStore_Load(object sender, EventArgs e)
{ {
LoadData(); if (_id.HasValue)
{
_logger.LogInformation("Загрузка магазина");
try
{
var view = _logic.ReadElement(new StoreSearchModel
{
Id = _id.Value
});
if (view != null)
{
NameComboBox.Text = view.StoreName;
AdressTextBox.Text = view.StoreAdress;
OpeningDatePicker.Text = view.OpeningDate.ToString();
VolumeNumericUpDown.Value = view.JewelMaxCount;
_listStores = view.StoreJewels ?? new Dictionary<int, (IJewelModel, int)>();
LoadData();
}
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка загрузки магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
} }
private void LoadData(bool extendDate = true) private void LoadData(bool extendDate = true)
{ {
_logger.LogInformation("Загрузка изделий магазина");
try try
{ {
var model = GetStore(extendDate ? Id : Convert.ToInt32(NameTextBox.Text)); if (_listStores != null)
if (model != null)
{ {
NameTextBox.Text = model.StoreName;
AdressTextBox.Text = model.StoreAdress;
OpeningDatePicker.Text = Convert.ToString(model.OpeningDate);
DataGridView.Rows.Clear(); DataGridView.Rows.Clear();
foreach (var el in model.StoreJewels.Values) foreach (var elem in _listStores)
{ {
DataGridView.Rows.Add(new object[] { el.Item1.JewelName, el.Item1.Price, el.Item2 }); DataGridView.Rows.Add(new object[] { elem.Key, elem.Value.Item1.JewelName, elem.Value.Item2 });
} }
} }
_logger.LogInformation("Загрузка магазинов");
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка загрузки магазинов"); _logger.LogError(ex, "Ошибка загрузки изделий магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxIcon.Error);
} }
} }
} }
} }

View File

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

View File

@ -15,21 +15,17 @@ namespace JewelryStore
{ {
private static ServiceProvider? _serviceProvider; private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider; public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread] [STAThread]
static void Main() 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(); var services = new ServiceCollection();
ConfigureServices(services); ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider(); _serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormMain>()); Application.Run(_serviceProvider.GetRequiredService<FormMain>());
} }
private static void ConfigureServices(ServiceCollection services) private static void ConfigureServices(ServiceCollection services)
{ {
services.AddLogging(option => services.AddLogging(option =>
@ -55,7 +51,7 @@ namespace JewelryStore
services.AddTransient<FormStores>(); services.AddTransient<FormStores>();
services.AddTransient<FormStore>(); services.AddTransient<FormStore>();
services.AddTransient<FormStoreReplenishment>(); services.AddTransient<FormStoreReplenishment>();
services.AddTransient<FormSellJewel>();
} }
} }
} }