diff --git a/AircraftPlant/AircraftPlantView/FormMain.Designer.cs b/AircraftPlant/AircraftPlantView/FormMain.Designer.cs index e9b4f04..4eead6e 100644 --- a/AircraftPlant/AircraftPlantView/FormMain.Designer.cs +++ b/AircraftPlant/AircraftPlantView/FormMain.Designer.cs @@ -39,6 +39,7 @@ this.компонентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.изделияToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.buttonAddPlane = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -150,12 +151,24 @@ 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); + // + // buttonAddPlane + // + this.buttonAddPlane.Location = new System.Drawing.Point(811, 280); + this.buttonAddPlane.Name = "buttonAddPlane"; + this.buttonAddPlane.Size = new System.Drawing.Size(146, 23); + this.buttonAddPlane.TabIndex = 7; + this.buttonAddPlane.Text = "Пополнение магазина"; + this.buttonAddPlane.UseVisualStyleBackColor = true; + this.buttonAddPlane.Click += new System.EventHandler(this.buttonAddPlane_Click); // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(977, 401); + this.Controls.Add(this.buttonAddPlane); this.Controls.Add(this.ButtonRef); this.Controls.Add(this.ButtonIssuedOrder); this.Controls.Add(this.ButtonOrderReady); @@ -188,5 +201,6 @@ private ToolStripMenuItem компонентыToolStripMenuItem; private ToolStripMenuItem изделияToolStripMenuItem; private ToolStripMenuItem магазиныToolStripMenuItem; + private Button buttonAddPlane; } } \ No newline at end of file diff --git a/AircraftPlant/AircraftPlantView/FormMain.cs b/AircraftPlant/AircraftPlantView/FormMain.cs index ce50e8d..e9df26c 100644 --- a/AircraftPlant/AircraftPlantView/FormMain.cs +++ b/AircraftPlant/AircraftPlantView/FormMain.cs @@ -74,6 +74,19 @@ namespace AircraftPlantView } } /// + /// Показать список всех магазинов + /// + /// + /// + private void МагазиныToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormShops)); + if (service is FormShops form) + { + form.ShowDialog(); + } + } + /// /// Кнопка "Создать заказ" /// /// @@ -201,5 +214,18 @@ namespace AircraftPlantView MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + /// + /// Кнопка "Пополнение магазина" + /// + /// + /// + private void buttonAddPlane_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormSupply)); + if (service is FormSupply form) + { + form.ShowDialog(); + } + } } } diff --git a/AircraftPlant/AircraftPlantView/FormShops.Designer.cs b/AircraftPlant/AircraftPlantView/FormShops.Designer.cs new file mode 100644 index 0000000..c6c86a2 --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormShops.Designer.cs @@ -0,0 +1,114 @@ +namespace AircraftPlantView +{ + 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() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.buttonAdd = new System.Windows.Forms.Button(); + this.buttonUpdate = new System.Windows.Forms.Button(); + this.buttonDelete = new System.Windows.Forms.Button(); + this.buttonRefresh = new System.Windows.Forms.Button(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(0, 0); + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowTemplate.Height = 25; + this.dataGridView.Size = new System.Drawing.Size(495, 449); + this.dataGridView.TabIndex = 0; + // + // buttonAdd + // + this.buttonAdd.Location = new System.Drawing.Point(524, 22); + this.buttonAdd.Name = "buttonAdd"; + this.buttonAdd.Size = new System.Drawing.Size(75, 23); + this.buttonAdd.TabIndex = 1; + this.buttonAdd.Text = "Добавить"; + this.buttonAdd.UseVisualStyleBackColor = true; + this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); + // + // buttonUpdate + // + this.buttonUpdate.Location = new System.Drawing.Point(524, 71); + this.buttonUpdate.Name = "buttonUpdate"; + this.buttonUpdate.Size = new System.Drawing.Size(75, 23); + this.buttonUpdate.TabIndex = 2; + this.buttonUpdate.Text = "Изменить"; + this.buttonUpdate.UseVisualStyleBackColor = true; + this.buttonUpdate.Click += new System.EventHandler(this.buttonUpdate_Click); + // + // buttonDelete + // + this.buttonDelete.Location = new System.Drawing.Point(524, 123); + this.buttonDelete.Name = "buttonDelete"; + this.buttonDelete.Size = new System.Drawing.Size(75, 23); + this.buttonDelete.TabIndex = 3; + this.buttonDelete.Text = "Удалить"; + this.buttonDelete.UseVisualStyleBackColor = true; + this.buttonDelete.Click += new System.EventHandler(this.buttonDelete_Click); + // + // buttonRefresh + // + this.buttonRefresh.Location = new System.Drawing.Point(524, 174); + this.buttonRefresh.Name = "buttonRefresh"; + this.buttonRefresh.Size = new System.Drawing.Size(75, 23); + this.buttonRefresh.TabIndex = 4; + this.buttonRefresh.Text = "Обновить"; + this.buttonRefresh.UseVisualStyleBackColor = true; + this.buttonRefresh.Click += new System.EventHandler(this.buttonRefresh_Click); + // + // FormShops + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(624, 450); + this.Controls.Add(this.buttonRefresh); + this.Controls.Add(this.buttonDelete); + this.Controls.Add(this.buttonUpdate); + this.Controls.Add(this.buttonAdd); + this.Controls.Add(this.dataGridView); + this.Name = "FormShops"; + this.Text = "Магазины"; + this.Load += new System.EventHandler(this.FormShops_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.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/AircraftPlant/AircraftPlantView/FormShops.cs b/AircraftPlant/AircraftPlantView/FormShops.cs new file mode 100644 index 0000000..c14f592 --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormShops.cs @@ -0,0 +1,145 @@ +using AircraftPlantContracts.BindingModels; +using AircraftPlantContracts.BusinessLogicsContracts; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace AircraftPlantView +{ + /// + /// Форма для вывода всех магазинов + /// + 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 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(); + } + /// + /// Метод загрузки списка магазинов + /// + 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["ShopPlanes"].Visible = false; + } + _logger.LogInformation("Загрузка магазинов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки магазинов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/AircraftPlant/AircraftPlantView/FormShops.resx b/AircraftPlant/AircraftPlantView/FormShops.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/AircraftPlant/AircraftPlantView/FormShops.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file