From b0b29a366dcb763e2779411f6c2fe46fdb0740a4 Mon Sep 17 00:00:00 2001 From: malimova Date: Wed, 1 May 2024 15:48:07 +0400 Subject: [PATCH] =?UTF-8?q?+=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=20=D1=81?= =?UTF-8?q?=D0=BF=D0=B8=D1=81=D0=BA=D0=B0=20=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConfectioneryView/FormClients.Designer.cs | 87 +++++++++++++ .../ConfectioneryView/FormClients.cs | 84 ++++++++++++ .../ConfectioneryView/FormClients.resx | 120 ++++++++++++++++++ 3 files changed, 291 insertions(+) create mode 100644 Confectionery/ConfectioneryView/FormClients.Designer.cs create mode 100644 Confectionery/ConfectioneryView/FormClients.cs create mode 100644 Confectionery/ConfectioneryView/FormClients.resx diff --git a/Confectionery/ConfectioneryView/FormClients.Designer.cs b/Confectionery/ConfectioneryView/FormClients.Designer.cs new file mode 100644 index 0000000..4ecb4f9 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormClients.Designer.cs @@ -0,0 +1,87 @@ +namespace ConfectioneryView +{ + partial class FormClients + { + /// + /// 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(); + buttonDelete = new Button(); + buttonRefresh = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = Color.AliceBlue; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(0, 1); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 62; + dataGridView.Size = new Size(738, 450); + dataGridView.TabIndex = 0; + // + // buttonDelete + // + buttonDelete.Location = new Point(771, 93); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(133, 49); + buttonDelete.TabIndex = 1; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(771, 183); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(133, 49); + buttonRefresh.TabIndex = 2; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // FormClients + // + AutoScaleDimensions = new SizeF(10F, 25F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(938, 450); + Controls.Add(buttonRefresh); + Controls.Add(buttonDelete); + Controls.Add(dataGridView); + Name = "FormClients"; + Text = "Список клиентов"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonDelete; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/Confectionery/ConfectioneryView/FormClients.cs b/Confectionery/ConfectioneryView/FormClients.cs new file mode 100644 index 0000000..a93ec53 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormClients.cs @@ -0,0 +1,84 @@ +using ConfectioneryContracts.BindingModels; +using ConfectioneryContracts.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 ConfectioneryView +{ + public partial class FormClients : Form + { + private readonly ILogger _logger; + + private readonly IClientLogic _logic; + + public FormClients(ILogger logger, IClientLogic logic) + { + InitializeComponent(); + _logger = logger; + _logic = logic; + } + + private void FormClients_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["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + _logger.LogInformation("Загрузка списка клиентов"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка загрузки списка клиентов"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + 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); + try + { + if (!_logic.Delete(new ClientBindingModel { Id = id })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + _logger.LogInformation("Удаление клиента"); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка удаления клиента"); + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + LoadData(); + } + } + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/Confectionery/ConfectioneryView/FormClients.resx b/Confectionery/ConfectioneryView/FormClients.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/Confectionery/ConfectioneryView/FormClients.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