From 66094682db3336a81e9208334191faef7ed50c32 Mon Sep 17 00:00:00 2001 From: tellsense Date: Tue, 7 May 2024 20:51:31 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B8=20=D0=BD=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2?= =?UTF-8?q?=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ComponentEntity/ComponentBindingModel.cs | 15 ++ .../ComponentEntity/ComponentSearchModel.cs | 14 ++ .../ComponentEntity/ComponentViewModel.cs | 18 ++ SUBD/SUBD/ComponentEntity/IComponentLogic.cs | 17 ++ SUBD/SUBD/ComponentEntity/IComponentModel.cs | 16 ++ SUBD/SUBD/FormSushi.Designer.cs | 156 ------------ SUBD/SUBD/FormSushi.cs | 225 ------------------ SUBD/SUBD/Forms/FormComponent.Designer.cs | 116 +++++++++ SUBD/SUBD/Forms/FormComponent.cs | 87 +++++++ .../FormComponent.resx} | 0 SUBD/SUBD/Forms/FormComponents.Designer.cs | 108 +++++++++ SUBD/SUBD/Forms/FormComponents.cs | 107 +++++++++ SUBD/SUBD/Forms/FormComponents.resx | 120 ++++++++++ 13 files changed, 618 insertions(+), 381 deletions(-) create mode 100644 SUBD/SUBD/ComponentEntity/ComponentBindingModel.cs create mode 100644 SUBD/SUBD/ComponentEntity/ComponentSearchModel.cs create mode 100644 SUBD/SUBD/ComponentEntity/ComponentViewModel.cs create mode 100644 SUBD/SUBD/ComponentEntity/IComponentLogic.cs create mode 100644 SUBD/SUBD/ComponentEntity/IComponentModel.cs delete mode 100644 SUBD/SUBD/FormSushi.Designer.cs delete mode 100644 SUBD/SUBD/FormSushi.cs create mode 100644 SUBD/SUBD/Forms/FormComponent.Designer.cs create mode 100644 SUBD/SUBD/Forms/FormComponent.cs rename SUBD/SUBD/{FormSushi.resx => Forms/FormComponent.resx} (100%) create mode 100644 SUBD/SUBD/Forms/FormComponents.Designer.cs create mode 100644 SUBD/SUBD/Forms/FormComponents.cs create mode 100644 SUBD/SUBD/Forms/FormComponents.resx diff --git a/SUBD/SUBD/ComponentEntity/ComponentBindingModel.cs b/SUBD/SUBD/ComponentEntity/ComponentBindingModel.cs new file mode 100644 index 0000000..fbaa573 --- /dev/null +++ b/SUBD/SUBD/ComponentEntity/ComponentBindingModel.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SUBD.ComponentEntity +{ + public class ComponentBindingModel : IComponentModel + { + public int Id { get; set; } + public string ComponentName { get; set; } = string.Empty; + public double Cost { get; set; } + } +} diff --git a/SUBD/SUBD/ComponentEntity/ComponentSearchModel.cs b/SUBD/SUBD/ComponentEntity/ComponentSearchModel.cs new file mode 100644 index 0000000..39b02dd --- /dev/null +++ b/SUBD/SUBD/ComponentEntity/ComponentSearchModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SUBD.ComponentEntity +{ + public class ComponentSearchModel + { + public int? Id { get; set; } + public string? ComponentName { get; set; } + } +} diff --git a/SUBD/SUBD/ComponentEntity/ComponentViewModel.cs b/SUBD/SUBD/ComponentEntity/ComponentViewModel.cs new file mode 100644 index 0000000..2fe78f0 --- /dev/null +++ b/SUBD/SUBD/ComponentEntity/ComponentViewModel.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SUBD.ComponentEntity +{ + public class ComponentViewModel : IComponentModel + { + public int Id { get; set; } + [DisplayName("Название компонента")] + public string ComponentName { get; set; } = string.Empty; + [DisplayName("Цена")] + public double Cost { get; set; } + } +} diff --git a/SUBD/SUBD/ComponentEntity/IComponentLogic.cs b/SUBD/SUBD/ComponentEntity/IComponentLogic.cs new file mode 100644 index 0000000..972a8bc --- /dev/null +++ b/SUBD/SUBD/ComponentEntity/IComponentLogic.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SUBD.ComponentEntity +{ + public interface IComponentLogic + { + List? ReadList(ComponentSearchModel? model); + ComponentViewModel? ReadElement(ComponentSearchModel model); + bool Create(ComponentBindingModel model); + bool Update(ComponentBindingModel model); + bool Delete(ComponentBindingModel model); + } +} diff --git a/SUBD/SUBD/ComponentEntity/IComponentModel.cs b/SUBD/SUBD/ComponentEntity/IComponentModel.cs new file mode 100644 index 0000000..b7eab4a --- /dev/null +++ b/SUBD/SUBD/ComponentEntity/IComponentModel.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; + +namespace SUBD.ComponentEntity +{ + public interface IComponentModel + { + int Id { get; } + string ComponentName { get; } + double Cost { get; } + } +} diff --git a/SUBD/SUBD/FormSushi.Designer.cs b/SUBD/SUBD/FormSushi.Designer.cs deleted file mode 100644 index cf39809..0000000 --- a/SUBD/SUBD/FormSushi.Designer.cs +++ /dev/null @@ -1,156 +0,0 @@ -namespace SUBD -{ - partial class FormSushi - { - /// - /// 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() - { - buttonCreate = new Button(); - buttonUpdate = new Button(); - buttonDelete = new Button(); - buttonRefresh = new Button(); - dataGridView = new DataGridView(); - textBoxIn = new TextBox(); - textBox1 = new TextBox(); - labelSushi = new Label(); - labelCost = new Label(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // buttonCreate - // - buttonCreate.Location = new Point(647, 30); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(123, 56); - buttonCreate.TabIndex = 0; - buttonCreate.Text = "Создать"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += buttonCreate_Click; - // - // buttonUpdate - // - buttonUpdate.Location = new Point(647, 92); - buttonUpdate.Name = "buttonUpdate"; - buttonUpdate.Size = new Size(123, 56); - buttonUpdate.TabIndex = 1; - buttonUpdate.Text = "Изменить"; - buttonUpdate.UseVisualStyleBackColor = true; - buttonUpdate.Click += buttonUpdate_Click; - // - // buttonDelete - // - buttonDelete.Location = new Point(647, 154); - buttonDelete.Name = "buttonDelete"; - buttonDelete.Size = new Size(123, 56); - buttonDelete.TabIndex = 2; - buttonDelete.Text = "Удалить"; - buttonDelete.UseVisualStyleBackColor = true; - buttonDelete.Click += buttonDelete_Click; - // - // buttonRefresh - // - buttonRefresh.Location = new Point(647, 216); - buttonRefresh.Name = "buttonRefresh"; - buttonRefresh.Size = new Size(123, 56); - buttonRefresh.TabIndex = 3; - buttonRefresh.Text = "Обновить"; - buttonRefresh.UseVisualStyleBackColor = true; - buttonRefresh.Click += buttonRefresh_Click; - // - // dataGridView - // - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Location = new Point(12, 102); - dataGridView.Name = "dataGridView"; - dataGridView.Size = new Size(629, 336); - dataGridView.TabIndex = 4; - // - // textBoxIn - // - textBoxIn.Location = new Point(99, 30); - textBoxIn.Name = "textBoxIn"; - textBoxIn.Size = new Size(261, 23); - textBoxIn.TabIndex = 5; - // - // textBox1 - // - textBox1.Location = new Point(99, 63); - textBox1.Name = "textBox1"; - textBox1.Size = new Size(261, 23); - textBox1.TabIndex = 6; - // - // labelSushi - // - labelSushi.AutoSize = true; - labelSushi.Location = new Point(25, 33); - labelSushi.Name = "labelSushi"; - labelSushi.Size = new Size(42, 15); - labelSushi.TabIndex = 7; - labelSushi.Text = "Суши:"; - // - // labelCost - // - labelCost.AutoSize = true; - labelCost.Location = new Point(25, 66); - labelCost.Name = "labelCost"; - labelCost.Size = new Size(38, 15); - labelCost.TabIndex = 8; - labelCost.Text = "Цена:"; - // - // FormSushi - // - AutoScaleDimensions = new SizeF(7F, 15F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Controls.Add(labelCost); - Controls.Add(labelSushi); - Controls.Add(textBox1); - Controls.Add(textBoxIn); - Controls.Add(dataGridView); - Controls.Add(buttonRefresh); - Controls.Add(buttonDelete); - Controls.Add(buttonUpdate); - Controls.Add(buttonCreate); - Name = "FormSushi"; - Text = "SUBD4"; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private Button buttonCreate; - private Button buttonUpdate; - private Button buttonDelete; - private Button buttonRefresh; - private DataGridView dataGridView; - private TextBox textBoxIn; - private TextBox textBox1; - private Label labelSushi; - private Label labelCost; - } -} diff --git a/SUBD/SUBD/FormSushi.cs b/SUBD/SUBD/FormSushi.cs deleted file mode 100644 index 9ac1c94..0000000 --- a/SUBD/SUBD/FormSushi.cs +++ /dev/null @@ -1,225 +0,0 @@ -using System.Security.Cryptography; -using System.Windows.Forms; - -namespace SUBD -{ - public partial class FormSushi : Form - { - public FormSushi() - { - InitializeComponent(); - } - public FormSushi(ILogger logger, ISushiLogic logic) - { - InitializeComponent(); - _logger = logger; - _logic = logic; - _sushiComponents = new Dictionary(); - } - private void FormSushi_Load(object sender, EventArgs e) - { - var list = _logic.ReadList(null); - if (list != null) - { - dataGridView.AllowUserToAddRows = false; - DataGridViewTextBoxColumn Id = new DataGridViewTextBoxColumn(); - DataGridViewTextBoxColumn Component = new DataGridViewTextBoxColumn(); - DataGridViewTextBoxColumn Number = new DataGridViewTextBoxColumn(); - Component.HeaderText = ""; - Number.HeaderText = ""; - Number.Name = "Number"; - Id.Name = "Id"; - dataGridView.Columns.Add(Id); - dataGridView.Columns.Add(Number); - dataGridView.Columns.Add(Component); - dataGridView.Columns["Id"].Visible = false; - - dataGridView.Columns["Number"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; - } - if (_id.HasValue) - { - _logger.LogInformation(" "); - try - { - var view = _logic.ReadElement(new SushiSearchModel - { - Id = _id.Value - }); - if (view != null) - { - textBoxName.Text = view.SushiName; - textBoxPrice.Text = view.Price.ToString(); - _sushiComponents = view.SushiComponents ?? new - Dictionary(); - LoadData(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - private void LoadData() - { - _logger.LogInformation(" "); - try - { - if (_sushiComponents != null) - { - dataGridView.Rows.Clear(); - foreach (var pc in _sushiComponents) - { - dataGridView.Rows.Add(new object[] { pc.Key, pc.Value.Item1.ComponentName, pc.Value.Item2 }); - } - textBoxPrice.Text = CalcPrice().ToString(); - } - } - catch (Exception ex) - { - _logger.LogError(ex, " "); - MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - private void buttonCreate_Click(object sender, EventArgs e) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormSushiComponent)); - if (service is FormSushiComponent form) - { - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation(" : { ComponentName}- { Count}", form.ComponentModel.ComponentName, form.Count); - if (_sushiComponents.ContainsKey(form.Id)) - { - _sushiComponents[form.Id] = (form.ComponentModel, - form.Count); - } - else - { - _sushiComponents.Add(form.Id, (form.ComponentModel, - form.Count)); - } - LoadData(); - } - } - } - private void buttonUpdate_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - var service = - Program.ServiceProvider?.GetService(typeof(FormSushiComponent)); - if (service is FormSushiComponent form) - { - int id = - Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value); - form.Id = id; - form.Count = _sushiComponents[id].Item2; - if (form.ShowDialog() == DialogResult.OK) - { - if (form.ComponentModel == null) - { - return; - } - _logger.LogInformation(" : { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count); - _sushiComponents[form.Id] = (form.ComponentModel, form.Count); - LoadData(); - } - } - } - } - private void buttonDelete_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - if (MessageBox.Show(" ?", "", - MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) - { - try - { - _logger.LogInformation(" : { ComponentName} - { Count}", dataGridView.SelectedRows[0].Cells[1].Value); _sushiComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value)); - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "", - MessageBoxButtons.OK, MessageBoxIcon.Error); - } - LoadData(); - } - } - } - private void buttonRefresh_Click(object sender, EventArgs e) - { - LoadData(); - } - private void ButtonSave_Click(object sender, EventArgs e) - { - if (string.IsNullOrEmpty(textBoxName.Text)) - { - MessageBox.Show(" ", "", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - if (string.IsNullOrEmpty(textBoxPrice.Text)) - { - MessageBox.Show(" ", "", MessageBoxButtons.OK, - MessageBoxIcon.Error); - return; - } - if (_sushiComponents == null || _sushiComponents.Count == 0) - { - MessageBox.Show(" ", "", - MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - _logger.LogInformation(" "); - try - { - var model = new SushiBindingModel - { - Id = _id ?? 0, - SushiName = textBoxName.Text, - Price = Convert.ToDouble(textBoxPrice.Text), - SushiComponents = _sushiComponents - }; - 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); - } - } - private void ButtonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - Close(); - } - private double CalcPrice() - { - double price = 0; - foreach (var elem in _sushiComponents) - { - price += ((elem.Value.Item1?.Cost ?? 0) * elem.Value.Item2); - } - return Math.Round(price * 1.1, 2); - } - } -} diff --git a/SUBD/SUBD/Forms/FormComponent.Designer.cs b/SUBD/SUBD/Forms/FormComponent.Designer.cs new file mode 100644 index 0000000..f3c2c9d --- /dev/null +++ b/SUBD/SUBD/Forms/FormComponent.Designer.cs @@ -0,0 +1,116 @@ +namespace SUBD +{ + partial class FormComponent + { + /// + /// 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() + { + buttonCancel = new Button(); + buttonSave = new Button(); + textBoxName = new TextBox(); + textBoxCost = new TextBox(); + labelName = new Label(); + labelCost = new Label(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Location = new Point(25, 144); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(98, 37); + buttonCancel.TabIndex = 0; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // buttonSave + // + buttonSave.Location = new Point(319, 144); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(98, 37); + buttonSave.TabIndex = 1; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + // + // textBoxName + // + textBoxName.Location = new Point(89, 30); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(218, 23); + textBoxName.TabIndex = 2; + // + // textBoxCost + // + textBoxCost.Location = new Point(89, 80); + textBoxCost.Name = "textBoxCost"; + textBoxCost.Size = new Size(218, 23); + textBoxCost.TabIndex = 3; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(12, 30); + labelName.Name = "labelName"; + labelName.Size = new Size(62, 15); + labelName.TabIndex = 4; + labelName.Text = "Название:"; + // + // labelCost + // + labelCost.AutoSize = true; + labelCost.Location = new Point(12, 80); + labelCost.Name = "labelCost"; + labelCost.Size = new Size(38, 15); + labelCost.TabIndex = 5; + labelCost.Text = "Цена:"; + // + // FormComponent + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(429, 193); + Controls.Add(labelCost); + Controls.Add(labelName); + Controls.Add(textBoxCost); + Controls.Add(textBoxName); + Controls.Add(buttonSave); + Controls.Add(buttonCancel); + Name = "FormComponent"; + Text = "Компонент"; + Load += FormComponent_Load; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonCancel; + private Button buttonSave; + private TextBox textBoxName; + private TextBox textBoxCost; + private Label labelName; + private Label labelCost; + } +} \ No newline at end of file diff --git a/SUBD/SUBD/Forms/FormComponent.cs b/SUBD/SUBD/Forms/FormComponent.cs new file mode 100644 index 0000000..4e8edc7 --- /dev/null +++ b/SUBD/SUBD/Forms/FormComponent.cs @@ -0,0 +1,87 @@ +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 SUBD.ComponentEntity; + +namespace SUBD +{ + public partial class FormComponent : Form + { + private readonly IComponentLogic _logic; + private int? _id; + public int Id { set { _id = value; } } + public FormComponent(IComponentLogic logic) + { + InitializeComponent(); + _logic = logic; + } + private void FormComponent_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var view = _logic.ReadElement(new ComponentSearchModel + { + Id = + _id.Value + }); + if (view != null) + { + textBoxName.Text = view.ComponentName; + textBoxCost.Text = view.Cost.ToString(); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(textBoxName.Text)) + { + MessageBox.Show("Заполните название", "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + try + { + var model = new ComponentBindingModel + { + Id = _id ?? 0, + ComponentName = textBoxName.Text, + Cost = Convert.ToDouble(textBoxCost.Text) + }; + 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) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/SUBD/SUBD/FormSushi.resx b/SUBD/SUBD/Forms/FormComponent.resx similarity index 100% rename from SUBD/SUBD/FormSushi.resx rename to SUBD/SUBD/Forms/FormComponent.resx diff --git a/SUBD/SUBD/Forms/FormComponents.Designer.cs b/SUBD/SUBD/Forms/FormComponents.Designer.cs new file mode 100644 index 0000000..b636662 --- /dev/null +++ b/SUBD/SUBD/Forms/FormComponents.Designer.cs @@ -0,0 +1,108 @@ +namespace SUBD +{ + partial class FormComponents + { + /// + /// 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() + { + button1 = new Button(); + button2 = new Button(); + button3 = new Button(); + button4 = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // button1 + // + button1.Location = new Point(430, 24); + button1.Name = "button1"; + button1.Size = new Size(109, 68); + button1.TabIndex = 0; + button1.Text = "button1"; + button1.UseVisualStyleBackColor = true; + // + // button2 + // + button2.Location = new Point(430, 98); + button2.Name = "button2"; + button2.Size = new Size(109, 68); + button2.TabIndex = 1; + button2.Text = "button2"; + button2.UseVisualStyleBackColor = true; + // + // button3 + // + button3.Location = new Point(430, 172); + button3.Name = "button3"; + button3.Size = new Size(109, 68); + button3.TabIndex = 2; + button3.Text = "button3"; + button3.UseVisualStyleBackColor = true; + // + // button4 + // + button4.Location = new Point(430, 246); + button4.Name = "button4"; + button4.Size = new Size(109, 68); + button4.TabIndex = 3; + button4.Text = "button4"; + button4.UseVisualStyleBackColor = true; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Location = new Point(3, 3); + dataGridView.Name = "dataGridView"; + dataGridView.Size = new Size(421, 444); + dataGridView.TabIndex = 4; + // + // FormComponents + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(551, 450); + Controls.Add(dataGridView); + Controls.Add(button4); + Controls.Add(button3); + Controls.Add(button2); + Controls.Add(button1); + Name = "FormComponents"; + Text = "FormComponents"; + Load += FormComponents_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button button1; + private Button button2; + private Button button3; + private Button button4; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/SUBD/SUBD/Forms/FormComponents.cs b/SUBD/SUBD/Forms/FormComponents.cs new file mode 100644 index 0000000..3ee9057 --- /dev/null +++ b/SUBD/SUBD/Forms/FormComponents.cs @@ -0,0 +1,107 @@ +using SUBD.ComponentEntity; +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 SUBD +{ + public partial class FormComponents : Form + { + private readonly IComponentLogic _logic; + public FormComponents(IComponentLogic logic) + { + InitializeComponent(); + _logic = logic; + } + private void FormComponents_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["ComponentName"].AutoSizeMode = + DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + private void ButtonAdd_Click(object sender, EventArgs e) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (dataGridView.SelectedRows.Count == 1) + { + var service = + Program.ServiceProvider?.GetService(typeof(FormComponent)); + if (service is FormComponent form) + { + form.Id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + } + private void ButtonDel_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 ComponentBindingModel + { + Id = id + })) + { + throw new Exception("Ошибка при удалении. Дополнительная информация в логах."); + } + LoadData(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + } + private void ButtonRef_Click(object sender, EventArgs e) + { + LoadData(); + } + } +} diff --git a/SUBD/SUBD/Forms/FormComponents.resx b/SUBD/SUBD/Forms/FormComponents.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/SUBD/SUBD/Forms/FormComponents.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