diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs index 0e7c108..d906146 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.Designer.cs @@ -32,6 +32,8 @@ GuidesToolStripMenuItem = new ToolStripMenuItem(); ComponentsToolStripMenuItem = new ToolStripMenuItem(); ManufacturesToolStripMenuItem = new ToolStripMenuItem(); + ShopsToolStripMenuItem = new ToolStripMenuItem(); + SupplyМагазинаToolStripMenuItem = new ToolStripMenuItem(); dataGridView = new DataGridView(); buttonCreateOrder = new Button(); buttonRefresh = new Button(); @@ -44,48 +46,67 @@ // // menuStrip // + menuStrip.ImageScalingSize = new Size(24, 24); menuStrip.Items.AddRange(new ToolStripItem[] { GuidesToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(1011, 24); + menuStrip.Padding = new Padding(9, 3, 0, 3); + menuStrip.Size = new Size(1444, 35); menuStrip.TabIndex = 0; menuStrip.Text = "Меню"; // // GuidesToolStripMenuItem // - GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem }); + GuidesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ComponentsToolStripMenuItem, ManufacturesToolStripMenuItem, ShopsToolStripMenuItem, SupplyМагазинаToolStripMenuItem }); GuidesToolStripMenuItem.Name = "GuidesToolStripMenuItem"; - GuidesToolStripMenuItem.Size = new Size(94, 20); + GuidesToolStripMenuItem.Size = new Size(139, 29); GuidesToolStripMenuItem.Text = "Справочники"; // // ComponentsToolStripMenuItem // ComponentsToolStripMenuItem.Name = "ComponentsToolStripMenuItem"; - ComponentsToolStripMenuItem.Size = new Size(181, 22); + ComponentsToolStripMenuItem.Size = new Size(296, 34); ComponentsToolStripMenuItem.Text = "Компоненты"; ComponentsToolStripMenuItem.Click += ComponentsStripMenuItem_Click; // // ManufacturesToolStripMenuItem // ManufacturesToolStripMenuItem.Name = "ManufacturesToolStripMenuItem"; - ManufacturesToolStripMenuItem.Size = new Size(181, 22); + ManufacturesToolStripMenuItem.Size = new Size(296, 34); ManufacturesToolStripMenuItem.Text = "Кузнечные изделия"; ManufacturesToolStripMenuItem.Click += ManufacturesStripMenuItem_Click; // + // ShopsToolStripMenuItem + // + ShopsToolStripMenuItem.Name = "ShopsToolStripMenuItem"; + ShopsToolStripMenuItem.Size = new Size(296, 34); + ShopsToolStripMenuItem.Text = "Магазины"; + ShopsToolStripMenuItem.Click += ShopsToolStripMenuItem_Click; + // + // SupplyМагазинаToolStripMenuItem + // + SupplyМагазинаToolStripMenuItem.Name = "SupplyМагазинаToolStripMenuItem"; + SupplyМагазинаToolStripMenuItem.Size = new Size(296, 34); + SupplyМагазинаToolStripMenuItem.Text = "Пополнение магазина"; + SupplyМагазинаToolStripMenuItem.Click += SupplyМагазинаToolStripMenuItem_Click; + // // dataGridView // dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(0, 23); + dataGridView.Location = new Point(0, 38); + dataGridView.Margin = new Padding(4, 5, 4, 5); dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; dataGridView.RowTemplate.Height = 25; - dataGridView.Size = new Size(847, 427); + dataGridView.Size = new Size(1210, 712); dataGridView.TabIndex = 1; // // buttonCreateOrder // - buttonCreateOrder.Location = new Point(853, 38); + buttonCreateOrder.Location = new Point(1219, 63); + buttonCreateOrder.Margin = new Padding(4, 5, 4, 5); buttonCreateOrder.Name = "buttonCreateOrder"; - buttonCreateOrder.Size = new Size(148, 31); + buttonCreateOrder.Size = new Size(211, 52); buttonCreateOrder.TabIndex = 2; buttonCreateOrder.Text = "Создать заказ"; buttonCreateOrder.UseVisualStyleBackColor = true; @@ -93,9 +114,10 @@ // // buttonRefresh // - buttonRefresh.Location = new Point(853, 186); + buttonRefresh.Location = new Point(1219, 310); + buttonRefresh.Margin = new Padding(4, 5, 4, 5); buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(148, 31); + buttonRefresh.Size = new Size(211, 52); buttonRefresh.TabIndex = 3; buttonRefresh.Text = "Обновить список"; buttonRefresh.UseVisualStyleBackColor = true; @@ -103,9 +125,10 @@ // // buttonIssued // - buttonIssued.Location = new Point(853, 149); + buttonIssued.Location = new Point(1219, 248); + buttonIssued.Margin = new Padding(4, 5, 4, 5); buttonIssued.Name = "buttonIssued"; - buttonIssued.Size = new Size(148, 31); + buttonIssued.Size = new Size(211, 52); buttonIssued.TabIndex = 4; buttonIssued.Text = "Заказ выдан"; buttonIssued.UseVisualStyleBackColor = true; @@ -113,9 +136,10 @@ // // buttonReady // - buttonReady.Location = new Point(853, 112); + buttonReady.Location = new Point(1219, 187); + buttonReady.Margin = new Padding(4, 5, 4, 5); buttonReady.Name = "buttonReady"; - buttonReady.Size = new Size(148, 31); + buttonReady.Size = new Size(211, 52); buttonReady.TabIndex = 5; buttonReady.Text = "Заказ готов"; buttonReady.UseVisualStyleBackColor = true; @@ -123,9 +147,10 @@ // // buttonTakeInWork // - buttonTakeInWork.Location = new Point(853, 75); + buttonTakeInWork.Location = new Point(1219, 125); + buttonTakeInWork.Margin = new Padding(4, 5, 4, 5); buttonTakeInWork.Name = "buttonTakeInWork"; - buttonTakeInWork.Size = new Size(148, 31); + buttonTakeInWork.Size = new Size(211, 52); buttonTakeInWork.TabIndex = 6; buttonTakeInWork.Text = "Отдать на выполнение"; buttonTakeInWork.UseVisualStyleBackColor = true; @@ -133,9 +158,9 @@ // // FormMain // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(1011, 450); + ClientSize = new Size(1444, 750); Controls.Add(buttonTakeInWork); Controls.Add(buttonReady); Controls.Add(buttonIssued); @@ -144,6 +169,7 @@ Controls.Add(dataGridView); Controls.Add(menuStrip); MainMenuStrip = menuStrip; + Margin = new Padding(4, 5, 4, 5); Name = "FormMain"; StartPosition = FormStartPosition.CenterParent; Text = "Кузница"; @@ -167,5 +193,7 @@ private Button buttonIssued; private Button buttonReady; private Button buttonTakeInWork; + private ToolStripMenuItem ShopsToolStripMenuItem; + private ToolStripMenuItem SupplyМагазинаToolStripMenuItem; } } \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs index 7174015..b3d272d 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormMain.cs @@ -163,5 +163,23 @@ namespace BlacksmithWorkshop { LoadData(); } + + private void ShopsToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + + private void SupplyМагазинаToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); + if (service is FormSupply form) + { + form.ShowDialog(); + } + } } } diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs new file mode 100644 index 0000000..1fe8340 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.Designer.cs @@ -0,0 +1,193 @@ +namespace BlacksmithWorkshop +{ + partial class FormShop + { + /// + /// 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() + { + labelName = new Label(); + labelAddress = new Label(); + labelDate = new Label(); + textBoxName = new TextBox(); + textBoxAddress = new TextBox(); + dateTimePicker = new DateTimePicker(); + dataGridView = new DataGridView(); + buttonSave = new Button(); + buttonCancel = new Button(); + ColumnId = new DataGridViewTextBoxColumn(); + ColumnName = new DataGridViewTextBoxColumn(); + ColumnPrice = new DataGridViewTextBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(24, 21); + labelName.Name = "labelName"; + labelName.Size = new Size(90, 25); + labelName.TabIndex = 0; + labelName.Text = "Название"; + // + // labelAddress + // + labelAddress.AutoSize = true; + labelAddress.Location = new Point(24, 72); + labelAddress.Name = "labelAddress"; + labelAddress.Size = new Size(62, 25); + labelAddress.TabIndex = 1; + labelAddress.Text = "Адрес"; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(24, 117); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(135, 25); + labelDate.TabIndex = 2; + labelDate.Text = "Дата открытия:"; + // + // textBoxName + // + textBoxName.Location = new Point(204, 15); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(230, 31); + textBoxName.TabIndex = 3; + // + // textBoxAddress + // + textBoxAddress.Location = new Point(204, 66); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(230, 31); + textBoxAddress.TabIndex = 4; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(204, 117); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(230, 31); + dateTimePicker.TabIndex = 5; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnId, ColumnName, ColumnPrice, ColumnCount }); + dataGridView.Location = new Point(24, 177); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 33; + dataGridView.Size = new Size(780, 434); + dataGridView.TabIndex = 6; + // + // buttonSave + // + buttonSave.Location = new Point(24, 652); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(165, 51); + buttonSave.TabIndex = 7; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(217, 652); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(165, 51); + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // ColumnId + // + ColumnId.HeaderText = ""; + ColumnId.MinimumWidth = 8; + ColumnId.Name = "ColumnId"; + ColumnId.Visible = false; + ColumnId.Width = 150; + // + // ColumnName + // + ColumnName.HeaderText = "Изделие"; + ColumnName.MinimumWidth = 8; + ColumnName.Name = "ColumnName"; + ColumnName.Width = 426; + // + // ColumnPrice + // + ColumnPrice.HeaderText = "Цена"; + ColumnPrice.MinimumWidth = 8; + ColumnPrice.Name = "ColumnPrice"; + ColumnPrice.Width = 150; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 8; + ColumnCount.Name = "ColumnCount"; + ColumnCount.Width = 150; + // + // FormShop + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(836, 750); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(dataGridView); + Controls.Add(dateTimePicker); + Controls.Add(textBoxAddress); + Controls.Add(textBoxName); + Controls.Add(labelDate); + Controls.Add(labelAddress); + Controls.Add(labelName); + Name = "FormShop"; + Text = "Магазин"; + Load += FormShop_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelAddress; + private Label labelDate; + private TextBox textBoxName; + private TextBox textBoxAddress; + private DateTimePicker dateTimePicker; + private DataGridView dataGridView; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewTextBoxColumn ColumnId; + private DataGridViewTextBoxColumn ColumnName; + private DataGridViewTextBoxColumn ColumnPrice; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs new file mode 100644 index 0000000..d859ac7 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.cs @@ -0,0 +1,128 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopDataModels.Models; +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.Logging; +//using NLog; +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 BlacksmithWorkshop +{ + public partial class FormShop : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public int? _id; + private Dictionary _manufactures; + + public FormShop(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + _manufactures = new(); + } + + private void FormShop_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + _logger.LogInformation("Загрузка магазина"); + try + { + var shop = _logic.ReadElement(new ShopSearchModel { Id = _id }); + if (shop != null) + { + textBoxName.Text = shop.ShopName; + textBoxAddress.Text = shop.Address; + dateTimePicker.Text = shop.OpeningDate.ToString(); + _manufactures = shop.ShopManufactures; + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void LoadData() + { + _logger.LogInformation("Загрузка товаров магазина"); + try + { + if (_manufactures != null) + { + foreach (var manufactures in _manufactures) + { + dataGridView.Rows.Add(new object[] { manufactures.Key, manufactures.Value.Item1.ManufactureName, + manufactures.Value.Item1.Price, manufactures.Value.Item2 }); + } + } + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки изделий магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (string.IsNullOrEmpty(textBoxAddress.Text)) + { + MessageBox.Show("Заполните адрес", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + _logger.LogInformation("Сохранение магазина"); + try + { + var model = new ShopBindingModel + { + Id = _id ?? 0, + ShopName = textBoxName.Text, + Address = textBoxAddress.Text, + OpeningDate = dateTimePicker.Value.Date, + ShopManufactures = _manufactures + }; + var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model); + if (!operationResult) + { + throw new Exception("Ошибка при сохранении. Дополнительная информация в логах."); + } + MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка сохранения магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx new file mode 100644 index 0000000..b0c7c5d --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShop.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs new file mode 100644 index 0000000..dec8bba --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.Designer.cs @@ -0,0 +1,114 @@ +namespace BlacksmithWorkshop +{ + partial class FormShops + { + /// + /// 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() + { + dataGridView = new DataGridView(); + buttonAdd = new Button(); + buttonUpdate = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 2); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.RowTemplate.Height = 33; + dataGridView.Size = new Size(829, 751); + dataGridView.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.Location = new Point(910, 46); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(173, 58); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(910, 129); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(173, 58); + buttonUpdate.TabIndex = 2; + buttonUpdate.Text = "Изменить"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(910, 212); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(173, 58); + buttonDelete.TabIndex = 3; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(910, 300); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(173, 58); + buttonRefresh.TabIndex = 4; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // FormShops + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1143, 750); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormShops"; + Text = "Магазины"; + Load += FormShops_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonUpdate; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs new file mode 100644 index 0000000..18161b0 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.cs @@ -0,0 +1,117 @@ +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; +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using Microsoft.VisualBasic.Logging; +//using NLog; + +namespace BlacksmithWorkshop +{ + public partial class FormShops : Form + { + private readonly ILogger _logger; + private readonly IShopLogic _logic; + public FormShops(ILogger logger, IShopLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormShops_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null); + if (list != null) + { + dataGridView.DataSource = list; + dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["ShopName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["Address"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["OpeningDate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ShopManufactures"].Visible = false; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShop)); + if (service is FormShop form) + { + form._id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление магазина"); + try + { + if (!_logic.Delete(new ShopBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления магазина"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormShops.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/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs new file mode 100644 index 0000000..36502f8 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.Designer.cs @@ -0,0 +1,106 @@ +namespace BlacksmithWorkshop +{ + partial class FormSupply + { + /// + /// 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() + { + ShopComboBox = new ComboBox(); + ManufactureComboBox = new ComboBox(); + CountTextBox = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // ShopComboBox + // + ShopComboBox.FormattingEnabled = true; + ShopComboBox.Location = new Point(12, 12); + ShopComboBox.Name = "ShopComboBox"; + ShopComboBox.Size = new Size(318, 33); + ShopComboBox.TabIndex = 0; + // + // ManufactureComboBox + // + ManufactureComboBox.FormattingEnabled = true; + ManufactureComboBox.Location = new Point(348, 12); + ManufactureComboBox.Name = "ManufactureComboBox"; + ManufactureComboBox.Size = new Size(318, 33); + ManufactureComboBox.TabIndex = 1; + // + // CountTextBox + // + CountTextBox.Location = new Point(689, 14); + CountTextBox.Name = "CountTextBox"; + CountTextBox.Size = new Size(318, 31); + CountTextBox.TabIndex = 2; + // + // buttonSave + // + buttonSave.Location = new Point(240, 78); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(173, 44); + buttonSave.TabIndex = 3; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(430, 78); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(173, 44); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormSupply + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1010, 145); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(CountTextBox); + Controls.Add(ManufactureComboBox); + Controls.Add(ShopComboBox); + Name = "FormSupply"; + Text = "Пополнение магазина"; + Load += FormSupply_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox ShopComboBox; + private ComboBox ManufactureComboBox; + private TextBox CountTextBox; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs new file mode 100644 index 0000000..599fd9a --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.cs @@ -0,0 +1,153 @@ +using BlacksmithWorkshopContracts.BusinessLogicsContracts; +using BlacksmithWorkshopContracts.SearchModels; +using BlacksmithWorkshopContracts.ViewModels; +using BlacksmithWorkshopDataModels.Models; +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 BlacksmithWorkshop +{ + public partial class FormSupply : Form + { + private readonly List? _manufactureList; + private readonly List? _shopsList; + IShopLogic _shopLogic; + IManufactureLogic _manufactureLogic; + + public int ShopId + { + get + { + return Convert.ToInt32(ShopComboBox.SelectedValue); + } + set + { + ShopComboBox.SelectedValue = value; + } + } + public int ManufactureId + { + get + { + return Convert.ToInt32(ManufactureComboBox.SelectedValue); + } + set + { + ManufactureComboBox.SelectedValue = value; + } + } + public IManufactureModel? ManufactureModel + { + get + { + if (_manufactureList == null) + { + return null; + } + foreach (var elem in _manufactureList) + { + if (elem.Id == ManufactureId) + { + return elem; + } + } + return null; + } + } + public int Count + { + get { return Convert.ToInt32(CountTextBox.Text); } + set { CountTextBox.Text = value.ToString(); } + } + + public FormSupply(IManufactureLogic ManufactureLogic, IShopLogic shopLogic) + { + InitializeComponent(); + _shopLogic = shopLogic; + _manufactureLogic = ManufactureLogic; + _manufactureList = ManufactureLogic.ReadList(null); + _shopsList = shopLogic.ReadList(null); + if (_manufactureList != null) + { + ManufactureComboBox.DisplayMember = "ManufactureName"; + ManufactureComboBox.ValueMember = "Id"; + ManufactureComboBox.DataSource = _manufactureList; + ManufactureComboBox.SelectedItem = null; + } + if (_shopsList != null) + { + ShopComboBox.DisplayMember = "ShopName"; + ShopComboBox.ValueMember = "Id"; + ShopComboBox.DataSource = _shopsList; + ShopComboBox.SelectedItem = null; + } + } + + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) + { + + } + + private void FormSupply_Load(object sender, EventArgs e) + { + + } + + private void buttonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(CountTextBox.Text)) + { + MessageBox.Show("Заполните поле Количество", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (ManufactureComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите кузнечное изделие", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + if (ShopComboBox.SelectedValue == null) + { + MessageBox.Show("Выберите магазин", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + int count = Convert.ToInt32(CountTextBox.Text); + bool res = _shopLogic.ReplenishManufactures( + new ShopSearchModel() { Id = Convert.ToInt32(ShopComboBox.SelectedValue) }, + _manufactureLogic.ReadElement(new() { Id = Convert.ToInt32(ManufactureComboBox.SelectedValue) }), + count + ); + if (!res) + { + throw new Exception("Ошибка при пополнении. Дополнительная информация в логах"); + } + MessageBox.Show("Пополнение прошло успешно"); + DialogResult = DialogResult.OK; + Close(); + + } + catch (Exception) + { + MessageBox.Show("Ошибка пополнения"); + return; + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormSupply.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/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs index 65045db..81e1e01 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -40,6 +40,8 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); @@ -47,6 +49,9 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file