From e23105958ff4103c888d5c374b2b64dd736bb1ba Mon Sep 17 00:00:00 2001 From: VictoriaPresnyakova Date: Fri, 16 Jun 2023 22:01:12 +0400 Subject: [PATCH] =?UTF-8?q?2=20=D1=83=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JewelryStore/FormMain.Designer.cs | 384 +++++++++++++------------ JewelryStore/FormMain.cs | 122 ++++---- JewelryStore/FormSellJewel.Designer.cs | 120 ++++++++ JewelryStore/FormSellJewel.cs | 103 +++++++ JewelryStore/FormSellJewel.resx | 120 ++++++++ JewelryStore/FormStore.Designer.cs | 95 +++--- JewelryStore/FormStore.cs | 99 +++---- JewelryStore/FormStores.cs | 2 +- JewelryStore/Program.cs | 10 +- 9 files changed, 712 insertions(+), 343 deletions(-) create mode 100644 JewelryStore/FormSellJewel.Designer.cs create mode 100644 JewelryStore/FormSellJewel.cs create mode 100644 JewelryStore/FormSellJewel.resx diff --git a/JewelryStore/FormMain.Designer.cs b/JewelryStore/FormMain.Designer.cs index 06bd776..8b01902 100644 --- a/JewelryStore/FormMain.Designer.cs +++ b/JewelryStore/FormMain.Designer.cs @@ -1,199 +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.StoreReplenishment = 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(); - this.StoreToolStripMenuItem = 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, 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, + /// + /// 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(139, 29); - this.справочникиToolStripMenuItem.Text = "Справочники"; - // - // компонентыToolStripMenuItem - // - this.компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem"; - this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(270, 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(270, 34); - this.изделияToolStripMenuItem.Text = "Драгоценности"; - this.изделияToolStripMenuItem.Click += new System.EventHandler(this.драгоценностиToolStripMenuItem_Click); - // - // StoreToolStripMenuItem - // - this.StoreToolStripMenuItem.Name = "StoreToolStripMenuItem"; - this.StoreToolStripMenuItem.Size = new System.Drawing.Size(270, 34); - this.StoreToolStripMenuItem.Text = "Магазины"; - this.StoreToolStripMenuItem.Click += new System.EventHandler(this.StoreToolStripMenuItem_Click); - // - // FormMain - // - this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1530, 599); - this.Controls.Add(this.StoreReplenishment); - 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(); + 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 ToolStripMenuItem StoreToolStripMenuItem; - private Button buttonReady; - private Button StoreReplenishment; + 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 73b03ea..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,58 +155,49 @@ 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 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) { var service = Program.ServiceProvider?.GetService(typeof(FormStoreReplenishment)); @@ -207,5 +207,25 @@ namespace JewelryStore 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 index 6713844..92eca9e 100644 --- a/JewelryStore/FormStore.Designer.cs +++ b/JewelryStore/FormStore.Designer.cs @@ -31,7 +31,7 @@ this.StoreNameLabel = new System.Windows.Forms.Label(); this.StoreAdressLabel = 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.DataGridView = new System.Windows.Forms.DataGridView(); this.JewelName = new System.Windows.Forms.DataGridViewTextBoxColumn(); @@ -40,53 +40,52 @@ 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(17, 15); - this.StoreNameLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.StoreNameLabel.Location = new System.Drawing.Point(12, 9); 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.Text = "Название магазина: "; // // StoreAdressLabel // this.StoreAdressLabel.AutoSize = true; - this.StoreAdressLabel.Location = new System.Drawing.Point(17, 67); - this.StoreAdressLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.StoreAdressLabel.Location = new System.Drawing.Point(12, 40); 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.Text = "Адрес магазина: "; // // OpeningDateLabel // this.OpeningDateLabel.AutoSize = true; - this.OpeningDateLabel.Location = new System.Drawing.Point(17, 120); - this.OpeningDateLabel.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.OpeningDateLabel.Location = new System.Drawing.Point(12, 72); 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.Text = "Дата открытия: "; // - // NameTextBox + // NameComboBox // - this.NameTextBox.Location = new System.Drawing.Point(196, 10); - this.NameTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); - this.NameTextBox.Name = "NameTextBox"; - this.NameTextBox.Size = new System.Drawing.Size(247, 31); - this.NameTextBox.TabIndex = 3; + 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(196, 62); - this.AdressTextBox.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.AdressTextBox.Location = new System.Drawing.Point(137, 37); 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; // // DataGridView @@ -96,41 +95,33 @@ this.JewelName, this.JewelPrice, this.JewelCount}); - this.DataGridView.Location = new System.Drawing.Point(17, 182); - this.DataGridView.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.DataGridView.Location = new System.Drawing.Point(12, 109); this.DataGridView.Name = "DataGridView"; - this.DataGridView.RowHeadersWidth = 62; 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; // // JewelName // this.JewelName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; this.JewelName.HeaderText = "Название изделия"; - this.JewelName.MinimumWidth = 8; this.JewelName.Name = "JewelName"; // // JewelPrice // this.JewelPrice.HeaderText = "Цена"; - this.JewelPrice.MinimumWidth = 8; this.JewelPrice.Name = "JewelPrice"; - this.JewelPrice.Width = 150; // // JewelCount // this.JewelCount.HeaderText = "Количество"; - this.JewelCount.MinimumWidth = 8; this.JewelCount.Name = "JewelCount"; - this.JewelCount.Width = 150; // // SaveButton // - this.SaveButton.Location = new System.Drawing.Point(789, 672); - this.SaveButton.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.SaveButton.Location = new System.Drawing.Point(552, 403); 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.Text = "Сохранить"; this.SaveButton.UseVisualStyleBackColor = true; @@ -138,10 +129,9 @@ // // ButtonCancel // - this.ButtonCancel.Location = new System.Drawing.Point(961, 672); - this.ButtonCancel.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.ButtonCancel.Location = new System.Drawing.Point(673, 403); 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.Text = "Отменить"; this.ButtonCancel.UseVisualStyleBackColor = true; @@ -149,31 +139,48 @@ // // OpeningDatePicker // - this.OpeningDatePicker.Location = new System.Drawing.Point(196, 110); - this.OpeningDatePicker.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); + this.OpeningDatePicker.Location = new System.Drawing.Point(137, 66); 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; // + // 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(10F, 25F); + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); 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.ButtonCancel); this.Controls.Add(this.SaveButton); this.Controls.Add(this.DataGridView); this.Controls.Add(this.AdressTextBox); - this.Controls.Add(this.NameTextBox); + this.Controls.Add(this.NameComboBox); this.Controls.Add(this.OpeningDateLabel); this.Controls.Add(this.StoreAdressLabel); this.Controls.Add(this.StoreNameLabel); - this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5); 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(); @@ -184,7 +191,7 @@ private Label StoreNameLabel; private Label StoreAdressLabel; private Label OpeningDateLabel; - private TextBox NameTextBox; + private ComboBox NameComboBox; private TextBox AdressTextBox; private DataGridView DataGridView; private Button SaveButton; @@ -193,5 +200,7 @@ private DataGridViewTextBoxColumn JewelPrice; private DataGridViewTextBoxColumn JewelCount; private DateTimePicker OpeningDatePicker; + private NumericUpDown VolumeNumericUpDown; + private Label JewelMaxCountLable; } -} \ No newline at end of file +} diff --git a/JewelryStore/FormStore.cs b/JewelryStore/FormStore.cs index 609a132..317952a 100644 --- a/JewelryStore/FormStore.cs +++ b/JewelryStore/FormStore.cs @@ -1,5 +1,6 @@ using JewelryStoreContracts.BindingModels; using JewelryStoreContracts.BusinessLogicsContracts; +using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.ViewModels; using JewelryStoreDataModels.Models; using Microsoft.Extensions.Logging; @@ -17,78 +18,48 @@ namespace JewelryStore { public partial class FormStore : Form { - private readonly List? _listStores; private readonly IStoreLogic _logic; private readonly ILogger _logger; - public int Id { get; set; } + private int? _id; + private Dictionary _listStores; + public int Id { set { _id = value; } } public FormStore(ILogger logger, IStoreLogic logic) { InitializeComponent(); _logger = logger; - _listStores = logic.ReadList(null); + _listStores = new(); _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) { - if (string.IsNullOrEmpty(NameTextBox.Text)) + 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 { - DateTime.TryParse(OpeningDatePicker.Text, out var dateTime); - StoreBindingModel model = new() + var model = new StoreBindingModel { - StoreName = NameTextBox.Text, + Id = _id ?? 0, + StoreName = NameComboBox.Text, StoreAdress = AdressTextBox.Text, - OpeningDate = dateTime + OpeningDate = OpeningDatePicker.Value.Date, + JewelMaxCount = (int)VolumeNumericUpDown.Value }; - var vmodel = GetStore(Id); - bool operationResult = false; - - if (vmodel != null) - { - model.Id = vmodel.Id; - operationResult = _logic.Update(model); - } - else - { - operationResult = _logic.Create(model); - } - + 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(); @@ -108,34 +79,52 @@ namespace JewelryStore 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(); + LoadData(); + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } } private void LoadData(bool extendDate = true) { + _logger.LogInformation("Загрузка изделий магазина"); try { - var model = GetStore(extendDate ? Id : Convert.ToInt32(NameTextBox.Text)); - if (model != null) + if (_listStores != null) { - NameTextBox.Text = model.StoreName; - AdressTextBox.Text = model.StoreAdress; - OpeningDatePicker.Text = Convert.ToString(model.OpeningDate); 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) { - _logger.LogError(ex, "Ошибка загрузки магазинов"); - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } - - } } diff --git a/JewelryStore/FormStores.cs b/JewelryStore/FormStores.cs index 8c84e6e..3ce73b0 100644 --- a/JewelryStore/FormStores.cs +++ b/JewelryStore/FormStores.cs @@ -40,7 +40,7 @@ namespace JewelryStore DataGridView.DataSource = list; DataGridView.Columns["Id"].Visible = false; DataGridView.Columns["StoreName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - DataGridView.Columns["Jewels"].Visible = false; + DataGridView.Columns["StoreJewels"].Visible = false; } _logger.LogInformation("Загрузка магазинов"); diff --git a/JewelryStore/Program.cs b/JewelryStore/Program.cs index e302d57..0da1940 100644 --- a/JewelryStore/Program.cs +++ b/JewelryStore/Program.cs @@ -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(); var services = new ServiceCollection(); ConfigureServices(services); _serviceProvider = services.BuildServiceProvider(); Application.Run(_serviceProvider.GetRequiredService()); } + private static void ConfigureServices(ServiceCollection services) { services.AddLogging(option => @@ -55,7 +51,7 @@ namespace JewelryStore services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } - } } \ No newline at end of file