From ef50028365826373d24bd723e6fb841ad680e9f5 Mon Sep 17 00:00:00 2001 From: Zakharov_Rostislav Date: Sat, 10 Feb 2024 20:07:41 +0400 Subject: [PATCH] FormManufactures --- .../BlacksmithWorkshop/FormComponent.cs | 3 +- .../FormManufactures.Designer.cs | 113 +++++++++++++++++ .../BlacksmithWorkshop/FormManufactures.cs | 106 ++++++++++++++++ .../BlacksmithWorkshop/FormManufactures.resx | 120 ++++++++++++++++++ .../BlacksmithWorkshop/Program.cs | 4 +- 5 files changed, 342 insertions(+), 4 deletions(-) create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs create mode 100644 BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.resx diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.cs index 05fa8db..1cca08c 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormComponent.cs @@ -11,8 +11,7 @@ namespace BlacksmithWorkshop private readonly IComponentLogic _logic; private int? _id; public int Id { set { _id = value; } } - public FormComponent(ILogger logger, IComponentLogic - logic) + public FormComponent(ILogger logger, IComponentLogic logic) { InitializeComponent(); _logger = logger; diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs new file mode 100644 index 0000000..c211b94 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.Designer.cs @@ -0,0 +1,113 @@ +namespace BlacksmithWorkshop +{ + partial class FormManufactures + { + /// + /// 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(); + buttonChange = new Button(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(1, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowTemplate.Height = 25; + dataGridView.Size = new Size(468, 450); + dataGridView.TabIndex = 6; + // + // buttonAdd + // + buttonAdd.Location = new Point(489, 21); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(118, 29); + buttonAdd.TabIndex = 7; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += AddButton_Click; + // + // buttonChange + // + buttonChange.Location = new Point(489, 56); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(118, 29); + buttonChange.TabIndex = 8; + buttonChange.Text = "Изменить"; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += UpdateButton_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(489, 91); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(118, 29); + buttonDelete.TabIndex = 9; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += DeleteButton_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(489, 126); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(118, 29); + buttonRefresh.TabIndex = 10; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += RefreshButton_Click; + // + // FormManufactures + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(619, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(buttonChange); + Controls.Add(buttonAdd); + Controls.Add(dataGridView); + Name = "FormManufactures"; + Text = "Изделия"; + Load += FormManufactures_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonAdd; + private Button buttonChange; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs new file mode 100644 index 0000000..fd1fd92 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.cs @@ -0,0 +1,106 @@ +using BlacksmithWorkshopContracts.BindingModels; +using BlacksmithWorkshopContracts.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 BlacksmithWorkshop +{ + public partial class FormManufactures : Form + { + private readonly ILogger _logger; + private readonly IManufactureLogic _logic; + public FormManufactures(ILogger logger, IManufactureLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + private void FormManufactures_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["ManufactureName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + dataGridView.Columns["ManufactureComponents"].Visible = false; + } + _logger.LogInformation("Загрузка мороженого"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки мороженого"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void AddButton_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); + if (service is FormManufacture form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void UpdateButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = Program.ServiceProvider?.GetService(typeof(FormManufacture)); + if (service is FormManufacture form) + { + var tmp = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void DeleteButton_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation("Удаление мороженого"); + try + { + if (!_logic.Delete(new ManufactureBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления мороженого"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void RefreshButton_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.resx b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/BlacksmithWorkshop/BlacksmithWorkshop/FormManufactures.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 bd22a4b..72ed2a7 100644 --- a/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs +++ b/BlacksmithWorkshop/BlacksmithWorkshop/Program.cs @@ -41,10 +41,10 @@ namespace BlacksmithWorkshop services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file