diff --git a/SushiBar/Clients/FormClients.Designer.cs b/SushiBar/Clients/FormClients.Designer.cs new file mode 100644 index 0000000..2d70e2e --- /dev/null +++ b/SushiBar/Clients/FormClients.Designer.cs @@ -0,0 +1,90 @@ +namespace SushiBarView.Clients +{ + 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(); + buttonRefresh = new Button(); + buttonDelete = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = Color.MintCream; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Left; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(569, 450); + dataGridView.TabIndex = 0; + // + // buttonRefresh + // + buttonRefresh.Location = new Point(620, 34); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(134, 50); + buttonRefresh.TabIndex = 1; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonDelete + // + buttonDelete.Location = new Point(620, 111); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(134, 50); + buttonDelete.TabIndex = 2; + buttonDelete.Text = "Удалить"; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // FormClients + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + BackColor = Color.Beige; + ClientSize = new Size(800, 450); + Controls.Add(buttonDelete); + Controls.Add(buttonRefresh); + Controls.Add(dataGridView); + Name = "FormClients"; + Text = "Клиенты"; + Load += FormClients_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Button buttonRefresh; + private Button buttonDelete; + } +} \ No newline at end of file diff --git a/SushiBar/Clients/FormClients.cs b/SushiBar/Clients/FormClients.cs new file mode 100644 index 0000000..1965211 --- /dev/null +++ b/SushiBar/Clients/FormClients.cs @@ -0,0 +1,88 @@ +using Microsoft.Extensions.Logging; +using SushiBarContracts.BindingModel; +using SushiBarContracts.BusinessLogicsContracts; +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 SushiBarView.Clients +{ + public partial class FormClients : Form + { + private readonly ILogger _logger; + private readonly IClientLogic _clientLogic; + + public FormClients(ILogger logger, IClientLogic logic) + { + _logger = logger; + _clientLogic = logic; + InitializeComponent(); + } + + private void FormClients_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void LoadData() + { + try + { + var list = _clientLogic.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.Message, "Ошибка загрузки клиентов"); + MessageBox.Show(ex.Message, "Ошибка загрузки клиентов"); + } + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if(dataGridView.SelectedRows.Count == 1) + { + if (MessageBox.Show("Вы серьезно хотите удалить клиента? :_) та за что...", "Вопрос", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) + { + try + { + int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + _logger.LogInformation($"Удален клиент под номером {id}"); + + if (!_clientLogic.Delete(new ClientBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch(Exception ex) + { + MessageBox.Show(ex.Message, "Не удалось удалить клиента"); + _logger.LogError(ex.Message, "Не удалось удалить клиента"); + } + } + } + } + + private void buttonRefresh_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} \ No newline at end of file diff --git a/SushiBar/Clients/FormClients.resx b/SushiBar/Clients/FormClients.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SushiBar/Clients/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