diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClient.Designer.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClient.Designer.cs
new file mode 100644
index 0000000..db53746
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClient.Designer.cs
@@ -0,0 +1,163 @@
+namespace ProjectConfectionaryFactory.Forms
+{
+ partial class FormClient
+ {
+ ///
+ /// 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();
+ textBoxClientName = new TextBox();
+ label3 = new Label();
+ label2 = new Label();
+ label1 = new Label();
+ textBoxClientSurname = new TextBox();
+ label4 = new Label();
+ textBoxAddress = new TextBox();
+ maskedTextBoxPhone = new MaskedTextBox();
+ SuspendLayout();
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(297, 216);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 15;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += ButtonCancel_Click;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(216, 216);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 14;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += ButtonSave_Click;
+ //
+ // textBoxClientName
+ //
+ textBoxClientName.Location = new Point(115, 30);
+ textBoxClientName.Name = "textBoxClientName";
+ textBoxClientName.Size = new Size(207, 23);
+ textBoxClientName.TabIndex = 11;
+ //
+ // label3
+ //
+ label3.AutoSize = true;
+ label3.Location = new Point(66, 161);
+ label3.Name = "label3";
+ label3.Size = new Size(43, 15);
+ label3.TabIndex = 10;
+ label3.Text = "Адрес:";
+ //
+ // label2
+ //
+ label2.AutoSize = true;
+ label2.Location = new Point(51, 117);
+ label2.Name = "label2";
+ label2.Size = new Size(58, 15);
+ label2.TabIndex = 9;
+ label2.Text = "Телефон:";
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(75, 33);
+ label1.Name = "label1";
+ label1.Size = new Size(34, 15);
+ label1.TabIndex = 8;
+ label1.Text = "Имя:";
+ //
+ // textBoxClientSurname
+ //
+ textBoxClientSurname.Location = new Point(115, 71);
+ textBoxClientSurname.Name = "textBoxClientSurname";
+ textBoxClientSurname.Size = new Size(207, 23);
+ textBoxClientSurname.TabIndex = 17;
+ //
+ // label4
+ //
+ label4.AutoSize = true;
+ label4.Location = new Point(48, 74);
+ label4.Name = "label4";
+ label4.Size = new Size(61, 15);
+ label4.TabIndex = 16;
+ label4.Text = "Фамилия:";
+ //
+ // textBoxAddress
+ //
+ textBoxAddress.Location = new Point(115, 158);
+ textBoxAddress.Name = "textBoxAddress";
+ textBoxAddress.Size = new Size(207, 23);
+ textBoxAddress.TabIndex = 18;
+ //
+ // maskedTextBoxPhone
+ //
+ maskedTextBoxPhone.Location = new Point(115, 114);
+ maskedTextBoxPhone.Mask = "+7 (999) 000-0000";
+ maskedTextBoxPhone.Name = "maskedTextBoxPhone";
+ maskedTextBoxPhone.Size = new Size(207, 23);
+ maskedTextBoxPhone.TabIndex = 19;
+ //
+ // FormClient
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(384, 251);
+ Controls.Add(maskedTextBoxPhone);
+ Controls.Add(textBoxAddress);
+ Controls.Add(textBoxClientSurname);
+ Controls.Add(label4);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(textBoxClientName);
+ Controls.Add(label3);
+ Controls.Add(label2);
+ Controls.Add(label1);
+ Name = "FormClient";
+ StartPosition = FormStartPosition.CenterParent;
+ Text = "Клиент";
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Button buttonCancel;
+ private Button buttonSave;
+ private TextBox textBoxClientName;
+ private Label label3;
+ private Label label2;
+ private Label label1;
+ private TextBox textBoxClientSurname;
+ private Label label4;
+ private TextBox textBoxAddress;
+ private MaskedTextBox maskedTextBoxPhone;
+ }
+}
\ No newline at end of file
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClient.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClient.cs
new file mode 100644
index 0000000..76bbdf9
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClient.cs
@@ -0,0 +1,72 @@
+using ProjectConfectionaryFactory.Entities;
+using ProjectConfectionaryFactory.Repositories;
+
+namespace ProjectConfectionaryFactory.Forms
+{
+ public partial class FormClient : Form
+ {
+ private readonly IClientRepository _clientRepository;
+
+ private int? _clientId;
+
+ public int Id
+ {
+ set
+ {
+ try
+ {
+ var client = _clientRepository.ReadClientById(value);
+ if (client == null)
+ {
+ throw new InvalidDataException(nameof(client));
+ }
+ textBoxClientName.Text = client.Name;
+ textBoxClientSurname.Text = client.Surname;
+ maskedTextBoxPhone.Text = client.Phone.ToString();
+ textBoxAddress.Text = client.Address;
+ _clientId = value;
+ }
+ catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
+ }
+ }
+
+ public FormClient(IClientRepository clientRepository)
+ {
+ InitializeComponent();
+ _clientRepository = clientRepository ?? throw new ArgumentNullException(nameof(clientRepository));
+ }
+
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (string.IsNullOrWhiteSpace(textBoxClientName.Text) || string.IsNullOrWhiteSpace(textBoxClientSurname.Text) || string.IsNullOrWhiteSpace(maskedTextBoxPhone.Text) || string.IsNullOrWhiteSpace(textBoxAddress.Text))
+ {
+ throw new Exception("Имеются незаполненные поля");
+ }
+ if (_clientId.HasValue)
+ {
+ _clientRepository.UpdateClient(CreateClient(_clientId.Value));
+ }
+ else
+ {
+ _clientRepository.CreateClient(CreateClient(0));
+ }
+ Close();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e) => Close();
+
+ private Client CreateClient(int id) => Client.CreateEntity(
+ id,
+ textBoxClientName.Text,
+ textBoxClientSurname.Text,
+ Double.Parse(maskedTextBoxPhone.Text),
+ textBoxAddress.Text);
+ }
+}
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClient.resx b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClient.resx
new file mode 100644
index 0000000..8b2ff64
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClient.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/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClients.Designer.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClients.Designer.cs
new file mode 100644
index 0000000..16b9ef2
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClients.Designer.cs
@@ -0,0 +1,122 @@
+namespace ProjectConfectionaryFactory.Forms
+{
+ 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()
+ {
+ dataGridViewData = new DataGridView();
+ buttonUpdate = new Button();
+ buttonDelete = new Button();
+ buttonAdd = new Button();
+ panel1 = new Panel();
+ ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
+ panel1.SuspendLayout();
+ SuspendLayout();
+ //
+ // dataGridViewData
+ //
+ dataGridViewData.AllowUserToAddRows = false;
+ dataGridViewData.AllowUserToDeleteRows = false;
+ dataGridViewData.AllowUserToResizeColumns = false;
+ dataGridViewData.AllowUserToResizeRows = false;
+ dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
+ dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridViewData.Dock = DockStyle.Fill;
+ dataGridViewData.Location = new Point(0, 0);
+ dataGridViewData.MultiSelect = false;
+ dataGridViewData.Name = "dataGridViewData";
+ dataGridViewData.ReadOnly = true;
+ dataGridViewData.RowHeadersVisible = false;
+ dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridViewData.Size = new Size(709, 450);
+ dataGridViewData.TabIndex = 3;
+ //
+ // buttonUpdate
+ //
+ buttonUpdate.BackgroundImage = Properties.Resources.Update;
+ buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonUpdate.Location = new Point(14, 83);
+ buttonUpdate.Name = "buttonUpdate";
+ buttonUpdate.Size = new Size(65, 65);
+ buttonUpdate.TabIndex = 1;
+ buttonUpdate.UseVisualStyleBackColor = true;
+ //
+ // buttonDelete
+ //
+ buttonDelete.BackgroundImage = Properties.Resources.Delete;
+ buttonDelete.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonDelete.Location = new Point(14, 154);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(65, 65);
+ buttonDelete.TabIndex = 1;
+ buttonDelete.UseVisualStyleBackColor = true;
+ //
+ // buttonAdd
+ //
+ buttonAdd.BackgroundImage = Properties.Resources.Add;
+ buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonAdd.Location = new Point(14, 12);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(65, 65);
+ buttonAdd.TabIndex = 0;
+ buttonAdd.UseVisualStyleBackColor = true;
+ //
+ // panel1
+ //
+ panel1.Controls.Add(buttonUpdate);
+ panel1.Controls.Add(buttonDelete);
+ panel1.Controls.Add(buttonAdd);
+ panel1.Dock = DockStyle.Right;
+ panel1.Location = new Point(709, 0);
+ panel1.Name = "panel1";
+ panel1.Size = new Size(91, 450);
+ panel1.TabIndex = 2;
+ //
+ // FormClients
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(dataGridViewData);
+ Controls.Add(panel1);
+ Name = "FormClients";
+ StartPosition = FormStartPosition.CenterParent;
+ Text = "Клиенты";
+ ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
+ panel1.ResumeLayout(false);
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private DataGridView dataGridViewData;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Button buttonAdd;
+ private Panel panel1;
+ }
+}
\ No newline at end of file
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClients.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClients.cs
new file mode 100644
index 0000000..0ff1f81
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClients.cs
@@ -0,0 +1,80 @@
+using ProjectConfectionaryFactory.Repositories;
+using Unity;
+
+namespace ProjectConfectionaryFactory.Forms
+{
+ public partial class FormClients : Form
+ {
+ private readonly IUnityContainer _container;
+ private readonly IClientRepository _clientRepository;
+ public FormClients(IUnityContainer container, IClientRepository clientRepository)
+ {
+ InitializeComponent();
+ _container = container ?? throw new ArgumentNullException(nameof(container));
+ _clientRepository = clientRepository ?? throw new ArgumentNullException(nameof(clientRepository));
+ }
+ private void FormClients_Load(object sender, EventArgs e)
+ {
+ try
+ {
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ _container.Resolve().ShowDialog();
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonUpdate_Click(object sender, EventArgs e)
+ {
+ if (!TryGetIdentifierFromSelectedRow(out var findId)) { return; }
+ try
+ {
+ var form = _container.Resolve();
+ form.Id = findId;
+ form.ShowDialog();
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonDelete_Click(object sender, EventArgs e)
+ {
+ if (!TryGetIdentifierFromSelectedRow(out var findId)) { return; }
+ if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; }
+ try
+ {
+ _clientRepository.DeleteClient(findId); LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void LoadList() => dataGridViewData.DataSource = _clientRepository.ReadClients();
+ private bool TryGetIdentifierFromSelectedRow(out int id)
+ {
+ id = 0;
+ if (dataGridViewData.SelectedRows.Count < 1)
+ {
+ MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return false;
+ }
+ id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
+ return true;
+ }
+ }
+}
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClients.resx b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormClients.resx
new file mode 100644
index 0000000..8b2ff64
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/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
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponent.Designer.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponent.Designer.cs
index 7858d60..cc06aeb 100644
--- a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponent.Designer.cs
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponent.Designer.cs
@@ -31,13 +31,13 @@
label1 = new Label();
label2 = new Label();
label3 = new Label();
- textBox1 = new TextBox();
- numericUpDown1 = new NumericUpDown();
- numericUpDown2 = new NumericUpDown();
- button1 = new Button();
- button2 = new Button();
- ((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit();
- ((System.ComponentModel.ISupportInitialize)numericUpDown2).BeginInit();
+ textBoxComponentName = new TextBox();
+ numericUpDownPrice = new NumericUpDown();
+ numericUpDownWeight = new NumericUpDown();
+ buttonSave = new Button();
+ buttonCancel = new Button();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
SuspendLayout();
//
// label1
@@ -48,7 +48,6 @@
label1.Size = new Size(132, 15);
label1.TabIndex = 0;
label1.Text = "Название компонента:";
- label1.Click += this.label1_Click;
//
// label2
//
@@ -68,70 +67,71 @@
label3.TabIndex = 2;
label3.Text = "Вес:";
//
- // textBox1
+ // textBoxComponentName
//
- textBox1.Location = new Point(150, 35);
- textBox1.Name = "textBox1";
- textBox1.Size = new Size(207, 23);
- textBox1.TabIndex = 3;
+ textBoxComponentName.Location = new Point(150, 35);
+ textBoxComponentName.Name = "textBoxComponentName";
+ textBoxComponentName.Size = new Size(207, 23);
+ textBoxComponentName.TabIndex = 3;
//
- // numericUpDown1
+ // numericUpDownPrice
//
- numericUpDown1.DecimalPlaces = 2;
- numericUpDown1.Location = new Point(150, 82);
- numericUpDown1.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
- numericUpDown1.Name = "numericUpDown1";
- numericUpDown1.Size = new Size(96, 23);
- numericUpDown1.TabIndex = 4;
- numericUpDown1.Value = new decimal(new int[] { 1, 0, 0, 131072 });
+ numericUpDownPrice.DecimalPlaces = 2;
+ numericUpDownPrice.Location = new Point(150, 82);
+ numericUpDownPrice.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
+ numericUpDownPrice.Name = "numericUpDownPrice";
+ numericUpDownPrice.Size = new Size(96, 23);
+ numericUpDownPrice.TabIndex = 4;
+ numericUpDownPrice.Value = new decimal(new int[] { 1, 0, 0, 131072 });
//
- // numericUpDown2
+ // numericUpDownWeight
//
- numericUpDown2.DecimalPlaces = 3;
- numericUpDown2.Location = new Point(150, 128);
- numericUpDown2.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
- numericUpDown2.Name = "numericUpDown2";
- numericUpDown2.Size = new Size(96, 23);
- numericUpDown2.TabIndex = 5;
- numericUpDown2.Value = new decimal(new int[] { 1, 0, 0, 196608 });
+ numericUpDownWeight.DecimalPlaces = 3;
+ numericUpDownWeight.Location = new Point(150, 128);
+ numericUpDownWeight.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
+ numericUpDownWeight.Name = "numericUpDownWeight";
+ numericUpDownWeight.Size = new Size(96, 23);
+ numericUpDownWeight.TabIndex = 5;
+ numericUpDownWeight.Value = new decimal(new int[] { 1, 0, 0, 196608 });
//
- // button1
+ // buttonSave
//
- button1.Location = new Point(211, 200);
- button1.Name = "button1";
- button1.Size = new Size(75, 23);
- button1.TabIndex = 6;
- button1.Text = "Сохранить";
- button1.UseVisualStyleBackColor = true;
- button1.Click += this.button1_Click;
+ buttonSave.Location = new Point(211, 200);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 6;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += ButtonSave_Click;
//
- // button2
+ // buttonCancel
//
- button2.Location = new Point(292, 200);
- button2.Name = "button2";
- button2.Size = new Size(75, 23);
- button2.TabIndex = 7;
- button2.Text = "Отмена";
- button2.UseVisualStyleBackColor = true;
+ buttonCancel.Location = new Point(292, 200);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 7;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += ButtonCancel_Click;
//
// FormComponent
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
- ClientSize = new Size(379, 235);
- Controls.Add(button2);
- Controls.Add(button1);
- Controls.Add(numericUpDown2);
- Controls.Add(numericUpDown1);
- Controls.Add(textBox1);
+ ClientSize = new Size(384, 236);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(numericUpDownWeight);
+ Controls.Add(numericUpDownPrice);
+ Controls.Add(textBoxComponentName);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(label1);
Name = "FormComponent";
StartPosition = FormStartPosition.CenterParent;
Text = "Компонент";
- ((System.ComponentModel.ISupportInitialize)numericUpDown1).EndInit();
- ((System.ComponentModel.ISupportInitialize)numericUpDown2).EndInit();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
ResumeLayout(false);
PerformLayout();
}
@@ -141,10 +141,10 @@
private Label label1;
private Label label2;
private Label label3;
- private TextBox textBox1;
- private NumericUpDown numericUpDown1;
- private NumericUpDown numericUpDown2;
- private Button button1;
- private Button button2;
+ private TextBox textBoxComponentName;
+ private NumericUpDown numericUpDownPrice;
+ private NumericUpDown numericUpDownWeight;
+ private Button buttonSave;
+ private Button buttonCancel;
}
}
\ No newline at end of file
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponent.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponent.cs
index bae89e1..7bc34f8 100644
--- a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponent.cs
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponent.cs
@@ -1,20 +1,70 @@
-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 ProjectConfectionaryFactory.Entities;
+using ProjectConfectionaryFactory.Repositories;
namespace ProjectConfectionaryFactory.Forms
{
public partial class FormComponent : Form
{
- public FormComponent()
+ private readonly IComponentRepository _componentRepository;
+
+ private int? _componentId;
+
+ public int Id
+ {
+ set
+ {
+ try
+ {
+ var component = _componentRepository.ReadComponentById(value);
+ if (component == null)
+ {
+ throw new InvalidDataException(nameof(component));
+ }
+ textBoxComponentName.Text = component.Name;
+ numericUpDownPrice.Value = (decimal)component.Price;
+ numericUpDownWeight.Value = (decimal)component.Weight;
+ _componentId = value;
+ }
+ catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
+ }
+ }
+
+ public FormComponent(IComponentRepository componentRepository)
{
InitializeComponent();
+ _componentRepository = componentRepository ?? throw new ArgumentNullException(nameof(componentRepository));
}
+
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (string.IsNullOrWhiteSpace(textBoxComponentName.Text))
+ {
+ throw new Exception("Имеются незаполненные поля");
+ }
+ if (_componentId.HasValue)
+ {
+ _componentRepository.UpdateComponent(CreateComponent(_componentId.Value));
+ }
+ else
+ {
+ _componentRepository.CreateComponent(CreateComponent(0));
+ }
+ Close();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e) => Close();
+
+ private Component CreateComponent(int id) => Component.CreateEntity(
+ id,
+ textBoxComponentName.Text,
+ Convert.ToInt32(numericUpDownPrice.Value),
+ Convert.ToDouble(numericUpDownWeight.Value));
}
}
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponents.Designer.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponents.Designer.cs
new file mode 100644
index 0000000..31db440
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponents.Designer.cs
@@ -0,0 +1,126 @@
+namespace ProjectConfectionaryFactory.Forms
+{
+ 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()
+ {
+ panel1 = new Panel();
+ buttonUpdate = new Button();
+ buttonDelete = new Button();
+ buttonAdd = new Button();
+ dataGridViewData = new DataGridView();
+ panel1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
+ SuspendLayout();
+ //
+ // panel1
+ //
+ panel1.Controls.Add(buttonUpdate);
+ panel1.Controls.Add(buttonDelete);
+ panel1.Controls.Add(buttonAdd);
+ panel1.Dock = DockStyle.Right;
+ panel1.Location = new Point(709, 0);
+ panel1.Name = "panel1";
+ panel1.Size = new Size(91, 450);
+ panel1.TabIndex = 0;
+ //
+ // buttonUpdate
+ //
+ buttonUpdate.BackgroundImage = Properties.Resources.Update;
+ buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonUpdate.Location = new Point(14, 83);
+ buttonUpdate.Name = "buttonUpdate";
+ buttonUpdate.Size = new Size(65, 65);
+ buttonUpdate.TabIndex = 1;
+ buttonUpdate.UseVisualStyleBackColor = true;
+ buttonUpdate.Click += ButtonUpdate_Click;
+ //
+ // buttonDelete
+ //
+ buttonDelete.BackgroundImage = Properties.Resources.Delete;
+ buttonDelete.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonDelete.Location = new Point(14, 154);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(65, 65);
+ buttonDelete.TabIndex = 1;
+ buttonDelete.UseVisualStyleBackColor = true;
+ buttonDelete.Click += ButtonDelete_Click;
+ //
+ // buttonAdd
+ //
+ buttonAdd.BackgroundImage = Properties.Resources.Add;
+ buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonAdd.Location = new Point(14, 12);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(65, 65);
+ buttonAdd.TabIndex = 0;
+ buttonAdd.UseVisualStyleBackColor = true;
+ buttonAdd.Click += ButtonAdd_Click;
+ //
+ // dataGridViewData
+ //
+ dataGridViewData.AllowUserToAddRows = false;
+ dataGridViewData.AllowUserToDeleteRows = false;
+ dataGridViewData.AllowUserToResizeColumns = false;
+ dataGridViewData.AllowUserToResizeRows = false;
+ dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
+ dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridViewData.Dock = DockStyle.Fill;
+ dataGridViewData.Location = new Point(0, 0);
+ dataGridViewData.MultiSelect = false;
+ dataGridViewData.Name = "dataGridViewData";
+ dataGridViewData.ReadOnly = true;
+ dataGridViewData.RowHeadersVisible = false;
+ dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridViewData.Size = new Size(709, 450);
+ dataGridViewData.TabIndex = 1;
+ //
+ // FormComponents
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(dataGridViewData);
+ Controls.Add(panel1);
+ Name = "FormComponents";
+ StartPosition = FormStartPosition.CenterParent;
+ Text = "Компоненты";
+ Load += FormComponents_Load;
+ panel1.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private Panel panel1;
+ private Button buttonAdd;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private DataGridView dataGridViewData;
+ }
+}
\ No newline at end of file
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponents.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponents.cs
new file mode 100644
index 0000000..60d9995
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponents.cs
@@ -0,0 +1,80 @@
+using ProjectConfectionaryFactory.Repositories;
+using Unity;
+
+namespace ProjectConfectionaryFactory.Forms
+{
+ public partial class FormComponents : Form
+ {
+ private readonly IUnityContainer _container;
+ private readonly IComponentRepository _componentRepository;
+ public FormComponents(IUnityContainer container, IComponentRepository componentRepository)
+ {
+ InitializeComponent();
+ _container = container ?? throw new ArgumentNullException(nameof(container));
+ _componentRepository = componentRepository ?? throw new ArgumentNullException(nameof(componentRepository));
+ }
+ private void FormComponents_Load(object sender, EventArgs e)
+ {
+ try
+ {
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ _container.Resolve().ShowDialog();
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonUpdate_Click(object sender, EventArgs e)
+ {
+ if (!TryGetIdentifierFromSelectedRow(out var findId)) { return; }
+ try
+ {
+ var form = _container.Resolve();
+ form.Id = findId;
+ form.ShowDialog();
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonDelete_Click(object sender, EventArgs e)
+ {
+ if (!TryGetIdentifierFromSelectedRow(out var findId)) { return; }
+ if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; }
+ try
+ {
+ _componentRepository.DeleteComponent(findId); LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void LoadList() => dataGridViewData.DataSource = _componentRepository.ReadComponents();
+ private bool TryGetIdentifierFromSelectedRow(out int id)
+ {
+ id = 0;
+ if (dataGridViewData.SelectedRows.Count < 1)
+ {
+ MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return false;
+ }
+ id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
+ return true;
+ }
+ }
+}
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponents.resx b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormComponents.resx
new file mode 100644
index 0000000..8b2ff64
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/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
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrder.Designer.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrder.Designer.cs
new file mode 100644
index 0000000..1f80d67
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrder.Designer.cs
@@ -0,0 +1,143 @@
+namespace ProjectConfectionaryFactory.Forms
+{
+ partial class FormOrder
+ {
+ ///
+ /// 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()
+ {
+ label4 = new Label();
+ label1 = new Label();
+ checkBoxCompleted = new CheckBox();
+ comboBoxClient = new ComboBox();
+ buttonCancel = new Button();
+ buttonSave = new Button();
+ label2 = new Label();
+ dateTimePicker1 = new DateTimePicker();
+ SuspendLayout();
+ //
+ // label4
+ //
+ label4.AutoSize = true;
+ label4.Location = new Point(49, 64);
+ label4.Name = "label4";
+ label4.Size = new Size(67, 15);
+ label4.TabIndex = 18;
+ label4.Text = "Выполнен:";
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(67, 24);
+ label1.Name = "label1";
+ label1.Size = new Size(49, 15);
+ label1.TabIndex = 17;
+ label1.Text = "Клиент:";
+ //
+ // checkBoxCompleted
+ //
+ checkBoxCompleted.AutoSize = true;
+ checkBoxCompleted.Location = new Point(122, 65);
+ checkBoxCompleted.Name = "checkBoxCompleted";
+ checkBoxCompleted.Size = new Size(15, 14);
+ checkBoxCompleted.TabIndex = 19;
+ checkBoxCompleted.UseVisualStyleBackColor = true;
+ //
+ // comboBoxClient
+ //
+ comboBoxClient.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxClient.FormattingEnabled = true;
+ comboBoxClient.Location = new Point(122, 21);
+ comboBoxClient.Name = "comboBoxClient";
+ comboBoxClient.Size = new Size(210, 23);
+ comboBoxClient.TabIndex = 20;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(297, 150);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 22;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(216, 150);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 21;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ //
+ // label2
+ //
+ label2.AutoSize = true;
+ label2.Location = new Point(81, 104);
+ label2.Name = "label2";
+ label2.Size = new Size(35, 15);
+ label2.TabIndex = 23;
+ label2.Text = "Дата:";
+ //
+ // dateTimePicker1
+ //
+ dateTimePicker1.Enabled = false;
+ dateTimePicker1.Location = new Point(122, 98);
+ dateTimePicker1.Name = "dateTimePicker1";
+ dateTimePicker1.Size = new Size(200, 23);
+ dateTimePicker1.TabIndex = 24;
+ //
+ // FormOrder
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(384, 185);
+ Controls.Add(dateTimePicker1);
+ Controls.Add(label2);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(comboBoxClient);
+ Controls.Add(checkBoxCompleted);
+ Controls.Add(label4);
+ Controls.Add(label1);
+ Name = "FormOrder";
+ StartPosition = FormStartPosition.CenterParent;
+ Text = "Заказ";
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private Label label4;
+ private Label label1;
+ private CheckBox checkBoxCompleted;
+ private ComboBox comboBoxClient;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private Label label2;
+ private DateTimePicker dateTimePicker1;
+ }
+}
\ No newline at end of file
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrder.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrder.cs
new file mode 100644
index 0000000..b5ad9ce
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrder.cs
@@ -0,0 +1,70 @@
+using ProjectConfectionaryFactory.Entities;
+using ProjectConfectionaryFactory.Repositories;
+
+namespace ProjectConfectionaryFactory.Forms
+{
+ public partial class FormOrder : Form
+ {
+ private readonly IOrderRepository _orderRepository;
+
+ private int? _orderId;
+
+ public int Id
+ {
+ set
+ {
+ try
+ {
+ var order = _orderRepository.ReadOrderById(value);
+ if (order == null)
+ {
+ throw new InvalidDataException(nameof(order));
+ }
+ checkBoxCompleted.Enabled = order.Completed;
+ _orderId = value;
+ }
+ catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
+ }
+ }
+
+ public FormOrder(IOrderRepository orderRepository, IClientRepository clientRepository)
+ {
+ InitializeComponent();
+ _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
+ comboBoxClient.DataSource = clientRepository.ReadClients();
+ comboBoxClient.DisplayMember = "FirstName";
+ comboBoxClient.ValueMember = "Id";
+ }
+
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (comboBoxClient.SelectedIndex < 0 || !checkBoxCompleted.Checked)
+ {
+ throw new Exception("Имеются незаполненные поля");
+ }
+ if (_orderId.HasValue)
+ {
+ _orderRepository.UpdateOrder(CreateOrder(_orderId.Value));
+ }
+ else
+ {
+ _orderRepository.CreateOrder(CreateOrder(0));
+ }
+ Close();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e) => Close();
+
+ private Order CreateOrder(int id) => Order.CreateEntity(
+ id,
+ (int)comboBoxClient.SelectedValue!,
+ checkBoxCompleted.Checked);
+ }
+}
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrder.resx b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrder.resx
new file mode 100644
index 0000000..8b2ff64
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrder.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/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrders.Designer.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrders.Designer.cs
new file mode 100644
index 0000000..e9bed20
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrders.Designer.cs
@@ -0,0 +1,122 @@
+namespace ProjectConfectionaryFactory.Forms
+{
+ partial class FormOrders
+ {
+ ///
+ /// 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()
+ {
+ buttonAdd = new Button();
+ dataGridViewData = new DataGridView();
+ buttonUpdate = new Button();
+ buttonDelete = new Button();
+ panel1 = new Panel();
+ ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
+ panel1.SuspendLayout();
+ SuspendLayout();
+ //
+ // buttonAdd
+ //
+ buttonAdd.BackgroundImage = Properties.Resources.Add;
+ buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonAdd.Location = new Point(14, 12);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(65, 65);
+ buttonAdd.TabIndex = 0;
+ buttonAdd.UseVisualStyleBackColor = true;
+ //
+ // dataGridViewData
+ //
+ dataGridViewData.AllowUserToAddRows = false;
+ dataGridViewData.AllowUserToDeleteRows = false;
+ dataGridViewData.AllowUserToResizeColumns = false;
+ dataGridViewData.AllowUserToResizeRows = false;
+ dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
+ dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridViewData.Dock = DockStyle.Fill;
+ dataGridViewData.Location = new Point(0, 0);
+ dataGridViewData.MultiSelect = false;
+ dataGridViewData.Name = "dataGridViewData";
+ dataGridViewData.ReadOnly = true;
+ dataGridViewData.RowHeadersVisible = false;
+ dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridViewData.Size = new Size(709, 450);
+ dataGridViewData.TabIndex = 5;
+ //
+ // buttonUpdate
+ //
+ buttonUpdate.BackgroundImage = Properties.Resources.Update;
+ buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonUpdate.Location = new Point(14, 83);
+ buttonUpdate.Name = "buttonUpdate";
+ buttonUpdate.Size = new Size(65, 65);
+ buttonUpdate.TabIndex = 1;
+ buttonUpdate.UseVisualStyleBackColor = true;
+ //
+ // buttonDelete
+ //
+ buttonDelete.BackgroundImage = Properties.Resources.Delete;
+ buttonDelete.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonDelete.Location = new Point(14, 154);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(65, 65);
+ buttonDelete.TabIndex = 1;
+ buttonDelete.UseVisualStyleBackColor = true;
+ //
+ // panel1
+ //
+ panel1.Controls.Add(buttonUpdate);
+ panel1.Controls.Add(buttonDelete);
+ panel1.Controls.Add(buttonAdd);
+ panel1.Dock = DockStyle.Right;
+ panel1.Location = new Point(709, 0);
+ panel1.Name = "panel1";
+ panel1.Size = new Size(91, 450);
+ panel1.TabIndex = 4;
+ //
+ // FormOrders
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(dataGridViewData);
+ Controls.Add(panel1);
+ Name = "FormOrders";
+ StartPosition = FormStartPosition.CenterParent;
+ Text = "FormOrders";
+ ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
+ panel1.ResumeLayout(false);
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private Button buttonAdd;
+ private DataGridView dataGridViewData;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Panel panel1;
+ }
+}
\ No newline at end of file
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrders.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrders.cs
new file mode 100644
index 0000000..c0df07b
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrders.cs
@@ -0,0 +1,80 @@
+using ProjectConfectionaryFactory.Repositories;
+using Unity;
+
+namespace ProjectConfectionaryFactory.Forms
+{
+ public partial class FormOrders : Form
+ {
+ private readonly IUnityContainer _container;
+ private readonly IOrderRepository _orderRepository;
+ public FormOrders(IUnityContainer container, IOrderRepository orderRepository)
+ {
+ InitializeComponent();
+ _container = container ?? throw new ArgumentNullException(nameof(container));
+ _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository));
+ }
+ private void FormOrders_Load(object sender, EventArgs e)
+ {
+ try
+ {
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ _container.Resolve().ShowDialog();
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonUpdate_Click(object sender, EventArgs e)
+ {
+ if (!TryGetIdentifierFromSelectedRow(out var findId)) { return; }
+ try
+ {
+ var form = _container.Resolve();
+ form.Id = findId;
+ form.ShowDialog();
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonDelete_Click(object sender, EventArgs e)
+ {
+ if (!TryGetIdentifierFromSelectedRow(out var findId)) { return; }
+ if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; }
+ try
+ {
+ _orderRepository.DeleteOrder(findId); LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void LoadList() => dataGridViewData.DataSource = _orderRepository.ReadOrders();
+ private bool TryGetIdentifierFromSelectedRow(out int id)
+ {
+ id = 0;
+ if (dataGridViewData.SelectedRows.Count < 1)
+ {
+ MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return false;
+ }
+ id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
+ return true;
+ }
+ }
+}
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrders.resx b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrders.resx
new file mode 100644
index 0000000..8b2ff64
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormOrders.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/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProduct.Designer.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProduct.Designer.cs
new file mode 100644
index 0000000..b3b02f5
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProduct.Designer.cs
@@ -0,0 +1,145 @@
+namespace ProjectConfectionaryFactory.Forms
+{
+ partial class FormProduct
+ {
+ ///
+ /// 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()
+ {
+ numericUpDownPrice = new NumericUpDown();
+ textBoxProductName = new TextBox();
+ label2 = new Label();
+ label1 = new Label();
+ label3 = new Label();
+ buttonCancel = new Button();
+ buttonSave = new Button();
+ checkedListBoxConfectionaryType = new CheckedListBox();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit();
+ SuspendLayout();
+ //
+ // numericUpDownPrice
+ //
+ numericUpDownPrice.DecimalPlaces = 2;
+ numericUpDownPrice.Location = new Point(150, 208);
+ numericUpDownPrice.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
+ numericUpDownPrice.Name = "numericUpDownPrice";
+ numericUpDownPrice.Size = new Size(96, 23);
+ numericUpDownPrice.TabIndex = 8;
+ numericUpDownPrice.Value = new decimal(new int[] { 1, 0, 0, 131072 });
+ //
+ // textBoxProductName
+ //
+ textBoxProductName.Location = new Point(150, 161);
+ textBoxProductName.Name = "textBoxProductName";
+ textBoxProductName.Size = new Size(207, 23);
+ textBoxProductName.TabIndex = 7;
+ //
+ // label2
+ //
+ label2.AutoSize = true;
+ label2.Location = new Point(106, 210);
+ label2.Name = "label2";
+ label2.Size = new Size(38, 15);
+ label2.TabIndex = 6;
+ label2.Text = "Цена:";
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(29, 164);
+ label1.Name = "label1";
+ label1.Size = new Size(115, 15);
+ label1.TabIndex = 5;
+ label1.Text = "Название продукта:";
+ //
+ // label3
+ //
+ label3.AutoSize = true;
+ label3.Location = new Point(61, 31);
+ label3.Name = "label3";
+ label3.Size = new Size(83, 15);
+ label3.TabIndex = 9;
+ label3.Text = "Вид продукта:";
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(297, 286);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 11;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += ButtonCancel_Click;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(216, 286);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 10;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += ButtonSave_Click;
+ //
+ // checkedListBoxConfectionaryType
+ //
+ checkedListBoxConfectionaryType.FormattingEnabled = true;
+ checkedListBoxConfectionaryType.Location = new Point(150, 31);
+ checkedListBoxConfectionaryType.Name = "checkedListBoxConfectionaryType";
+ checkedListBoxConfectionaryType.Size = new Size(207, 112);
+ checkedListBoxConfectionaryType.TabIndex = 12;
+ //
+ // FormProduct
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(384, 321);
+ Controls.Add(checkedListBoxConfectionaryType);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(label3);
+ Controls.Add(numericUpDownPrice);
+ Controls.Add(textBoxProductName);
+ Controls.Add(label2);
+ Controls.Add(label1);
+ Name = "FormProduct";
+ StartPosition = FormStartPosition.CenterParent;
+ Text = "FormProduct";
+ ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+ private NumericUpDown numericUpDownPrice;
+ private TextBox textBoxProductName;
+ private Label label2;
+ private Label label1;
+ private Label label3;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private CheckedListBox checkedListBoxConfectionaryType;
+ }
+}
\ No newline at end of file
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProduct.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProduct.cs
new file mode 100644
index 0000000..5853ed5
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProduct.cs
@@ -0,0 +1,94 @@
+using Microsoft.VisualBasic.FileIO;
+using ProjectConfectionaryFactory.Entities;
+using ProjectConfectionaryFactory.Entities.Enums;
+using ProjectConfectionaryFactory.Repositories;
+
+namespace ProjectConfectionaryFactory.Forms
+{
+ public partial class FormProduct : Form
+ {
+ private readonly IProductRepository _productRepository;
+
+ private int? _productId;
+
+ public int Id
+ {
+ set
+ {
+ try
+ {
+ var product = _productRepository.ReadProductById(value);
+ if (product == null)
+ {
+ throw new InvalidDataException(nameof(product));
+ }
+ foreach (ConfectionaryType elem in Enum.GetValues(typeof(ConfectionaryType)))
+ {
+ if ((elem & product.ConfectionaryType) != 0)
+ {
+ checkedListBoxConfectionaryType.SetItemChecked(checkedListBoxConfectionaryType.Items.IndexOf(elem), true);
+ }
+ }
+ textBoxProductName.Text = product.Name;
+ numericUpDownPrice.Value = (decimal)product.Price;
+ _productId = value;
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ }
+ }
+
+ public FormProduct(IProductRepository productRepository)
+ {
+ InitializeComponent();
+ _productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
+ foreach (var elem in Enum.GetValues(typeof(ConfectionaryType)))
+ {
+ checkedListBoxConfectionaryType.Items.Add(elem);
+ }
+ }
+
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (checkedListBoxConfectionaryType.CheckedItems.Count == 0 || string.IsNullOrWhiteSpace(textBoxProductName.Text))
+ {
+ throw new Exception("Имеются незаполненные поля");
+ }
+ if (_productId.HasValue)
+ {
+ _productRepository.UpdateProduct(CreateProduct(_productId.Value));
+ }
+ else
+ {
+ _productRepository.CreateProduct(CreateProduct(0));
+ }
+ Close();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e) => Close();
+
+ private Product CreateProduct(int id)
+ {
+ ConfectionaryType confectionaryType = ConfectionaryType.None;
+ foreach (var elem in checkedListBoxConfectionaryType.CheckedItems)
+ {
+ confectionaryType |= (ConfectionaryType)elem;
+ }
+ return Product.CreateEntity(
+ id,
+ confectionaryType,
+ textBoxProductName.Text,
+ (double)numericUpDownPrice.Value);
+ }
+ }
+}
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProduct.resx b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProduct.resx
new file mode 100644
index 0000000..8b2ff64
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProduct.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/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProducts.Designer.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProducts.Designer.cs
new file mode 100644
index 0000000..2e20dff
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProducts.Designer.cs
@@ -0,0 +1,123 @@
+namespace ProjectConfectionaryFactory.Forms
+{
+ partial class FormProducts
+ {
+ ///
+ /// 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()
+ {
+ buttonUpdate = new Button();
+ buttonDelete = new Button();
+ buttonAdd = new Button();
+ dataGridViewData = new DataGridView();
+ panel1 = new Panel();
+ ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
+ panel1.SuspendLayout();
+ SuspendLayout();
+ //
+ // buttonUpdate
+ //
+ buttonUpdate.BackgroundImage = Properties.Resources.Update;
+ buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonUpdate.Location = new Point(14, 83);
+ buttonUpdate.Name = "buttonUpdate";
+ buttonUpdate.Size = new Size(65, 65);
+ buttonUpdate.TabIndex = 1;
+ buttonUpdate.UseVisualStyleBackColor = true;
+ //
+ // buttonDelete
+ //
+ buttonDelete.BackgroundImage = Properties.Resources.Delete;
+ buttonDelete.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonDelete.Location = new Point(14, 154);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(65, 65);
+ buttonDelete.TabIndex = 1;
+ buttonDelete.UseVisualStyleBackColor = true;
+ //
+ // buttonAdd
+ //
+ buttonAdd.BackgroundImage = Properties.Resources.Add;
+ buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonAdd.Location = new Point(14, 12);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(65, 65);
+ buttonAdd.TabIndex = 0;
+ buttonAdd.UseVisualStyleBackColor = true;
+ //
+ // dataGridViewData
+ //
+ dataGridViewData.AllowUserToAddRows = false;
+ dataGridViewData.AllowUserToDeleteRows = false;
+ dataGridViewData.AllowUserToResizeColumns = false;
+ dataGridViewData.AllowUserToResizeRows = false;
+ dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
+ dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridViewData.Dock = DockStyle.Fill;
+ dataGridViewData.Location = new Point(0, 0);
+ dataGridViewData.MultiSelect = false;
+ dataGridViewData.Name = "dataGridViewData";
+ dataGridViewData.ReadOnly = true;
+ dataGridViewData.RowHeadersVisible = false;
+ dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridViewData.Size = new Size(709, 450);
+ dataGridViewData.TabIndex = 3;
+ //
+ // panel1
+ //
+ panel1.Controls.Add(buttonUpdate);
+ panel1.Controls.Add(buttonDelete);
+ panel1.Controls.Add(buttonAdd);
+ panel1.Dock = DockStyle.Right;
+ panel1.Location = new Point(709, 0);
+ panel1.Name = "panel1";
+ panel1.Size = new Size(91, 450);
+ panel1.TabIndex = 2;
+ //
+ // FormProducts
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(dataGridViewData);
+ Controls.Add(panel1);
+ Name = "FormProducts";
+ StartPosition = FormStartPosition.CenterParent;
+ Text = "FormProducts";
+ Load += FormProducts_Load;
+ ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
+ panel1.ResumeLayout(false);
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Button buttonAdd;
+ private DataGridView dataGridViewData;
+ private Panel panel1;
+ }
+}
\ No newline at end of file
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProducts.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProducts.cs
new file mode 100644
index 0000000..7119186
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProducts.cs
@@ -0,0 +1,80 @@
+using ProjectConfectionaryFactory.Repositories;
+using Unity;
+
+namespace ProjectConfectionaryFactory.Forms
+{
+ public partial class FormProducts : Form
+ {
+ private readonly IUnityContainer _container;
+ private readonly IProductRepository _productRepository;
+ public FormProducts(IUnityContainer container, IProductRepository productRepository)
+ {
+ InitializeComponent();
+ _container = container ?? throw new ArgumentNullException(nameof(container));
+ _productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository));
+ }
+ private void FormProducts_Load(object sender, EventArgs e)
+ {
+ try
+ {
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ _container.Resolve().ShowDialog();
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonUpdate_Click(object sender, EventArgs e)
+ {
+ if (!TryGetIdentifierFromSelectedRow(out var findId)) { return; }
+ try
+ {
+ var form = _container.Resolve();
+ form.Id = findId;
+ form.ShowDialog();
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonDelete_Click(object sender, EventArgs e)
+ {
+ if (!TryGetIdentifierFromSelectedRow(out var findId)) { return; }
+ if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; }
+ try
+ {
+ _productRepository.DeleteProduct(findId); LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void LoadList() => dataGridViewData.DataSource = _productRepository.ReadProducts();
+ private bool TryGetIdentifierFromSelectedRow(out int id)
+ {
+ id = 0;
+ if (dataGridViewData.SelectedRows.Count < 1)
+ {
+ MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return false;
+ }
+ id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
+ return true;
+ }
+ }
+}
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProducts.resx b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProducts.resx
new file mode 100644
index 0000000..8b2ff64
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormProducts.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/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplier.Designer.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplier.Designer.cs
new file mode 100644
index 0000000..aa89789
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplier.Designer.cs
@@ -0,0 +1,141 @@
+namespace ProjectConfectionaryFactory.Forms
+{
+ partial class FormSupplier
+ {
+ ///
+ /// 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()
+ {
+ maskedTextBoxPhone = new MaskedTextBox();
+ textBoxAddress = new TextBox();
+ buttonCancel = new Button();
+ buttonSave = new Button();
+ textBoxSupplierName = new TextBox();
+ label3 = new Label();
+ label2 = new Label();
+ label1 = new Label();
+ SuspendLayout();
+ //
+ // maskedTextBoxPhone
+ //
+ maskedTextBoxPhone.Location = new Point(121, 56);
+ maskedTextBoxPhone.Mask = "+7 (999) 000-0000";
+ maskedTextBoxPhone.Name = "maskedTextBoxPhone";
+ maskedTextBoxPhone.Size = new Size(207, 23);
+ maskedTextBoxPhone.TabIndex = 27;
+ //
+ // textBoxAddress
+ //
+ textBoxAddress.Location = new Point(121, 93);
+ textBoxAddress.Name = "textBoxAddress";
+ textBoxAddress.Size = new Size(207, 23);
+ textBoxAddress.TabIndex = 26;
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(297, 156);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 25;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += ButtonCancel_Click;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(216, 156);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 24;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += ButtonSave_Click;
+ //
+ // textBoxSupplierName
+ //
+ textBoxSupplierName.Location = new Point(121, 20);
+ textBoxSupplierName.Name = "textBoxSupplierName";
+ textBoxSupplierName.Size = new Size(207, 23);
+ textBoxSupplierName.TabIndex = 23;
+ //
+ // label3
+ //
+ label3.AutoSize = true;
+ label3.Location = new Point(72, 96);
+ label3.Name = "label3";
+ label3.Size = new Size(43, 15);
+ label3.TabIndex = 22;
+ label3.Text = "Адрес:";
+ //
+ // label2
+ //
+ label2.AutoSize = true;
+ label2.Location = new Point(57, 59);
+ label2.Name = "label2";
+ label2.Size = new Size(58, 15);
+ label2.TabIndex = 21;
+ label2.Text = "Телефон:";
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(81, 23);
+ label1.Name = "label1";
+ label1.Size = new Size(34, 15);
+ label1.TabIndex = 20;
+ label1.Text = "Имя:";
+ //
+ // FormSupplier
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(384, 191);
+ Controls.Add(maskedTextBoxPhone);
+ Controls.Add(textBoxAddress);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(textBoxSupplierName);
+ Controls.Add(label3);
+ Controls.Add(label2);
+ Controls.Add(label1);
+ Name = "FormSupplier";
+ StartPosition = FormStartPosition.CenterParent;
+ Text = "FormSupplier";
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private MaskedTextBox maskedTextBoxPhone;
+ private TextBox textBoxAddress;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private TextBox textBoxSupplierName;
+ private Label label3;
+ private Label label2;
+ private Label label1;
+ }
+}
\ No newline at end of file
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplier.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplier.cs
new file mode 100644
index 0000000..78a0a36
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplier.cs
@@ -0,0 +1,70 @@
+using ProjectConfectionaryFactory.Entities;
+using ProjectConfectionaryFactory.Repositories;
+
+namespace ProjectConfectionaryFactory.Forms
+{
+ public partial class FormSupplier : Form
+ {
+ private readonly ISupplierRepository _supplierRepository;
+
+ private int? _supplierId;
+
+ public int Id
+ {
+ set
+ {
+ try
+ {
+ var supplier = _supplierRepository.ReadSupplierById(value);
+ if (supplier == null)
+ {
+ throw new InvalidDataException(nameof(supplier));
+ }
+ textBoxSupplierName.Text = supplier.Name;
+ maskedTextBoxPhone.Text = supplier.Phone.ToString();
+ textBoxAddress.Text = supplier.Address;
+ _supplierId = value;
+ }
+ catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
+ }
+ }
+
+ public FormSupplier(ISupplierRepository supplierRepository)
+ {
+ InitializeComponent();
+ _supplierRepository = supplierRepository ?? throw new ArgumentNullException(nameof(supplierRepository));
+ }
+
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (string.IsNullOrWhiteSpace(textBoxSupplierName.Text) || string.IsNullOrWhiteSpace(maskedTextBoxPhone.Text) || string.IsNullOrWhiteSpace(textBoxAddress.Text))
+ {
+ throw new Exception("Имеются незаполненные поля");
+ }
+ if (_supplierId.HasValue)
+ {
+ _supplierRepository.UpdateSupplier(CreateSupplier(_supplierId.Value));
+ }
+ else
+ {
+ _supplierRepository.CreateSupplier(CreateSupplier(0));
+ }
+ Close();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e) => Close();
+
+ private Supplier CreateSupplier(int id) => Supplier.CreateEntity(
+ id,
+ textBoxSupplierName.Text,
+ Double.Parse(maskedTextBoxPhone.Text),
+ textBoxAddress.Text);
+ }
+}
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplier.resx b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplier.resx
new file mode 100644
index 0000000..8b2ff64
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplier.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/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSuppliers.Designer.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSuppliers.Designer.cs
new file mode 100644
index 0000000..0ca9e36
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSuppliers.Designer.cs
@@ -0,0 +1,122 @@
+namespace ProjectConfectionaryFactory.Forms
+{
+ partial class FormSuppliers
+ {
+ ///
+ /// 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()
+ {
+ dataGridViewData = new DataGridView();
+ buttonUpdate = new Button();
+ buttonDelete = new Button();
+ buttonAdd = new Button();
+ panel1 = new Panel();
+ ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
+ panel1.SuspendLayout();
+ SuspendLayout();
+ //
+ // dataGridViewData
+ //
+ dataGridViewData.AllowUserToAddRows = false;
+ dataGridViewData.AllowUserToDeleteRows = false;
+ dataGridViewData.AllowUserToResizeColumns = false;
+ dataGridViewData.AllowUserToResizeRows = false;
+ dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
+ dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridViewData.Dock = DockStyle.Fill;
+ dataGridViewData.Location = new Point(0, 0);
+ dataGridViewData.MultiSelect = false;
+ dataGridViewData.Name = "dataGridViewData";
+ dataGridViewData.ReadOnly = true;
+ dataGridViewData.RowHeadersVisible = false;
+ dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridViewData.Size = new Size(709, 450);
+ dataGridViewData.TabIndex = 5;
+ //
+ // buttonUpdate
+ //
+ buttonUpdate.BackgroundImage = Properties.Resources.Update;
+ buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonUpdate.Location = new Point(14, 83);
+ buttonUpdate.Name = "buttonUpdate";
+ buttonUpdate.Size = new Size(65, 65);
+ buttonUpdate.TabIndex = 1;
+ buttonUpdate.UseVisualStyleBackColor = true;
+ //
+ // buttonDelete
+ //
+ buttonDelete.BackgroundImage = Properties.Resources.Delete;
+ buttonDelete.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonDelete.Location = new Point(14, 154);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(65, 65);
+ buttonDelete.TabIndex = 1;
+ buttonDelete.UseVisualStyleBackColor = true;
+ //
+ // buttonAdd
+ //
+ buttonAdd.BackgroundImage = Properties.Resources.Add;
+ buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonAdd.Location = new Point(14, 12);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(65, 65);
+ buttonAdd.TabIndex = 0;
+ buttonAdd.UseVisualStyleBackColor = true;
+ //
+ // panel1
+ //
+ panel1.Controls.Add(buttonUpdate);
+ panel1.Controls.Add(buttonDelete);
+ panel1.Controls.Add(buttonAdd);
+ panel1.Dock = DockStyle.Right;
+ panel1.Location = new Point(709, 0);
+ panel1.Name = "panel1";
+ panel1.Size = new Size(91, 450);
+ panel1.TabIndex = 4;
+ //
+ // FormSuppliers
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(dataGridViewData);
+ Controls.Add(panel1);
+ Name = "FormSuppliers";
+ StartPosition = FormStartPosition.CenterParent;
+ Text = "FormSuppliers";
+ ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
+ panel1.ResumeLayout(false);
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private DataGridView dataGridViewData;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Button buttonAdd;
+ private Panel panel1;
+ }
+}
\ No newline at end of file
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSuppliers.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSuppliers.cs
new file mode 100644
index 0000000..c8e4402
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSuppliers.cs
@@ -0,0 +1,80 @@
+using ProjectConfectionaryFactory.Repositories;
+using Unity;
+
+namespace ProjectConfectionaryFactory.Forms
+{
+ public partial class FormSuppliers : Form
+ {
+ private readonly IUnityContainer _container;
+ private readonly ISupplierRepository _supplierRepository;
+ public FormSuppliers(IUnityContainer container, ISupplierRepository supplierRepository)
+ {
+ InitializeComponent();
+ _container = container ?? throw new ArgumentNullException(nameof(container));
+ _supplierRepository = supplierRepository ?? throw new ArgumentNullException(nameof(supplierRepository));
+ }
+ private void FormSuppliers_Load(object sender, EventArgs e)
+ {
+ try
+ {
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ _container.Resolve().ShowDialog();
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonUpdate_Click(object sender, EventArgs e)
+ {
+ if (!TryGetIdentifierFromSelectedRow(out var findId)) { return; }
+ try
+ {
+ var form = _container.Resolve();
+ form.Id = findId;
+ form.ShowDialog();
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonDelete_Click(object sender, EventArgs e)
+ {
+ if (!TryGetIdentifierFromSelectedRow(out var findId)) { return; }
+ if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; }
+ try
+ {
+ _supplierRepository.DeleteSupplier(findId); LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void LoadList() => dataGridViewData.DataSource = _supplierRepository.ReadSuppliers();
+ private bool TryGetIdentifierFromSelectedRow(out int id)
+ {
+ id = 0;
+ if (dataGridViewData.SelectedRows.Count < 1)
+ {
+ MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return false;
+ }
+ id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
+ return true;
+ }
+ }
+}
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSuppliers.resx b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSuppliers.resx
new file mode 100644
index 0000000..8b2ff64
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSuppliers.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/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupply.Designer.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupply.Designer.cs
new file mode 100644
index 0000000..4d11f09
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupply.Designer.cs
@@ -0,0 +1,196 @@
+namespace ProjectConfectionaryFactory.Forms
+{
+ partial class FormSupply
+ {
+ ///
+ /// 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()
+ {
+ dateTimePicker1 = new DateTimePicker();
+ label2 = new Label();
+ buttonCancel = new Button();
+ buttonSave = new Button();
+ comboBoxSupplier = new ComboBox();
+ checkBoxCompleted = new CheckBox();
+ label4 = new Label();
+ label1 = new Label();
+ comboBoxComponent = new ComboBox();
+ label3 = new Label();
+ numericUpDownWeight = new NumericUpDown();
+ label5 = new Label();
+ ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).BeginInit();
+ SuspendLayout();
+ //
+ // dateTimePicker1
+ //
+ dateTimePicker1.Enabled = false;
+ dateTimePicker1.Location = new Point(108, 183);
+ dateTimePicker1.Name = "dateTimePicker1";
+ dateTimePicker1.Size = new Size(200, 23);
+ dateTimePicker1.TabIndex = 32;
+ //
+ // label2
+ //
+ label2.AutoSize = true;
+ label2.Location = new Point(67, 189);
+ label2.Name = "label2";
+ label2.Size = new Size(35, 15);
+ label2.TabIndex = 31;
+ label2.Text = "Дата:";
+ //
+ // buttonCancel
+ //
+ buttonCancel.Location = new Point(297, 251);
+ buttonCancel.Name = "buttonCancel";
+ buttonCancel.Size = new Size(75, 23);
+ buttonCancel.TabIndex = 30;
+ buttonCancel.Text = "Отмена";
+ buttonCancel.UseVisualStyleBackColor = true;
+ buttonCancel.Click += ButtonCancel_Click;
+ //
+ // buttonSave
+ //
+ buttonSave.Location = new Point(216, 251);
+ buttonSave.Name = "buttonSave";
+ buttonSave.Size = new Size(75, 23);
+ buttonSave.TabIndex = 29;
+ buttonSave.Text = "Сохранить";
+ buttonSave.UseVisualStyleBackColor = true;
+ buttonSave.Click += ButtonSave_Click;
+ //
+ // comboBoxSupplier
+ //
+ comboBoxSupplier.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxSupplier.FormattingEnabled = true;
+ comboBoxSupplier.Location = new Point(108, 25);
+ comboBoxSupplier.Name = "comboBoxSupplier";
+ comboBoxSupplier.Size = new Size(210, 23);
+ comboBoxSupplier.TabIndex = 28;
+ //
+ // checkBoxCompleted
+ //
+ checkBoxCompleted.AutoSize = true;
+ checkBoxCompleted.Location = new Point(108, 150);
+ checkBoxCompleted.Name = "checkBoxCompleted";
+ checkBoxCompleted.Size = new Size(15, 14);
+ checkBoxCompleted.TabIndex = 27;
+ checkBoxCompleted.UseVisualStyleBackColor = true;
+ //
+ // label4
+ //
+ label4.AutoSize = true;
+ label4.Location = new Point(35, 149);
+ label4.Name = "label4";
+ label4.Size = new Size(67, 15);
+ label4.TabIndex = 26;
+ label4.Text = "Выполнен:";
+ //
+ // label1
+ //
+ label1.AutoSize = true;
+ label1.Location = new Point(29, 28);
+ label1.Name = "label1";
+ label1.Size = new Size(73, 15);
+ label1.TabIndex = 25;
+ label1.Text = "Поставщик:";
+ //
+ // comboBoxComponent
+ //
+ comboBoxComponent.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxComponent.FormattingEnabled = true;
+ comboBoxComponent.Location = new Point(108, 66);
+ comboBoxComponent.Name = "comboBoxComponent";
+ comboBoxComponent.Size = new Size(210, 23);
+ comboBoxComponent.TabIndex = 34;
+ //
+ // label3
+ //
+ label3.AutoSize = true;
+ label3.Location = new Point(30, 69);
+ label3.Name = "label3";
+ label3.Size = new Size(72, 15);
+ label3.TabIndex = 33;
+ label3.Text = "Компонент:";
+ //
+ // numericUpDownWeight
+ //
+ numericUpDownWeight.DecimalPlaces = 3;
+ numericUpDownWeight.Location = new Point(108, 105);
+ numericUpDownWeight.Maximum = new decimal(new int[] { 100000, 0, 0, 0 });
+ numericUpDownWeight.Name = "numericUpDownWeight";
+ numericUpDownWeight.Size = new Size(96, 23);
+ numericUpDownWeight.TabIndex = 36;
+ numericUpDownWeight.Value = new decimal(new int[] { 1, 0, 0, 196608 });
+ //
+ // label5
+ //
+ label5.AutoSize = true;
+ label5.Location = new Point(73, 107);
+ label5.Name = "label5";
+ label5.Size = new Size(29, 15);
+ label5.TabIndex = 35;
+ label5.Text = "Вес:";
+ //
+ // FormSupply
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(384, 286);
+ Controls.Add(numericUpDownWeight);
+ Controls.Add(label5);
+ Controls.Add(comboBoxComponent);
+ Controls.Add(label3);
+ Controls.Add(dateTimePicker1);
+ Controls.Add(label2);
+ Controls.Add(buttonCancel);
+ Controls.Add(buttonSave);
+ Controls.Add(comboBoxSupplier);
+ Controls.Add(checkBoxCompleted);
+ Controls.Add(label4);
+ Controls.Add(label1);
+ Name = "FormSupply";
+ StartPosition = FormStartPosition.CenterParent;
+ Text = "FormSupply";
+ ((System.ComponentModel.ISupportInitialize)numericUpDownWeight).EndInit();
+ ResumeLayout(false);
+ PerformLayout();
+ }
+
+ #endregion
+
+ private DateTimePicker dateTimePicker1;
+ private Label label2;
+ private Button buttonCancel;
+ private Button buttonSave;
+ private ComboBox comboBoxSupplier;
+ private CheckBox checkBoxCompleted;
+ private Label label4;
+ private Label label1;
+ private ComboBox comboBoxComponent;
+ private Label label3;
+ private NumericUpDown numericUpDownWeight;
+ private Label label5;
+ }
+}
\ No newline at end of file
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupply.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupply.cs
new file mode 100644
index 0000000..7468840
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupply.cs
@@ -0,0 +1,76 @@
+using ProjectConfectionaryFactory.Entities;
+using ProjectConfectionaryFactory.Repositories;
+
+namespace ProjectConfectionaryFactory.Forms
+{
+ public partial class FormSupply : Form
+ {
+ private readonly ISupplyRepository _supplyRepository;
+
+ private int? _supplyId;
+
+ public int Id
+ {
+ set
+ {
+ try
+ {
+ var supply = _supplyRepository.ReadSupplyById(value);
+ if (supply == null)
+ {
+ throw new InvalidDataException(nameof(supply));
+ }
+ numericUpDownWeight.Value = (decimal)supply.Weight;
+ checkBoxCompleted.Enabled = supply.Completed;
+ _supplyId = value;
+ }
+ catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); return; }
+ }
+ }
+
+ public FormSupply(ISupplyRepository supplyRepository, ISupplierRepository supplierRepository, IComponentRepository componentRepository)
+ {
+ InitializeComponent();
+ _supplyRepository = supplyRepository ?? throw new ArgumentNullException(nameof(supplyRepository));
+ comboBoxSupplier.DataSource = supplierRepository.ReadSuppliers();
+ comboBoxSupplier.DisplayMember = "Name";
+ comboBoxSupplier.ValueMember = "Id";
+ comboBoxComponent.DataSource = componentRepository.ReadComponents();
+ comboBoxComponent.DisplayMember = "ComponentName";
+ comboBoxComponent.ValueMember = "Id";
+ }
+
+ private void ButtonSave_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ if (comboBoxSupplier.SelectedIndex < 0 || comboBoxComponent.SelectedIndex < 0 || !checkBoxCompleted.Checked)
+ {
+ throw new Exception("Имеются незаполненные поля");
+ }
+ if (_supplyId.HasValue)
+ {
+ _supplyRepository.UpdateSupply(CreateSupply(_supplyId.Value));
+ }
+ else
+ {
+ _supplyRepository.CreateSupply(CreateSupply(0));
+ }
+ Close();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+
+ private void ButtonCancel_Click(object sender, EventArgs e) => Close();
+
+ private Supply CreateSupply(int id) => Supply.CreateEntity(
+ id,
+ (int)comboBoxSupplier.SelectedValue!,
+ (int)comboBoxComponent.SelectedValue!,
+ Convert.ToDouble(numericUpDownWeight.Value),
+ checkBoxCompleted.Checked);
+ }
+}
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupply.resx b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupply.resx
new file mode 100644
index 0000000..8b2ff64
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupply.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/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplys.Designer.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplys.Designer.cs
new file mode 100644
index 0000000..e32340d
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplys.Designer.cs
@@ -0,0 +1,122 @@
+namespace ProjectConfectionaryFactory.Forms
+{
+ partial class FormSupplys
+ {
+ ///
+ /// 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()
+ {
+ dataGridViewData = new DataGridView();
+ buttonUpdate = new Button();
+ buttonDelete = new Button();
+ buttonAdd = new Button();
+ panel1 = new Panel();
+ ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit();
+ panel1.SuspendLayout();
+ SuspendLayout();
+ //
+ // dataGridViewData
+ //
+ dataGridViewData.AllowUserToAddRows = false;
+ dataGridViewData.AllowUserToDeleteRows = false;
+ dataGridViewData.AllowUserToResizeColumns = false;
+ dataGridViewData.AllowUserToResizeRows = false;
+ dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
+ dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
+ dataGridViewData.Dock = DockStyle.Fill;
+ dataGridViewData.Location = new Point(0, 0);
+ dataGridViewData.MultiSelect = false;
+ dataGridViewData.Name = "dataGridViewData";
+ dataGridViewData.ReadOnly = true;
+ dataGridViewData.RowHeadersVisible = false;
+ dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
+ dataGridViewData.Size = new Size(709, 450);
+ dataGridViewData.TabIndex = 7;
+ //
+ // buttonUpdate
+ //
+ buttonUpdate.BackgroundImage = Properties.Resources.Update;
+ buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonUpdate.Location = new Point(14, 83);
+ buttonUpdate.Name = "buttonUpdate";
+ buttonUpdate.Size = new Size(65, 65);
+ buttonUpdate.TabIndex = 1;
+ buttonUpdate.UseVisualStyleBackColor = true;
+ //
+ // buttonDelete
+ //
+ buttonDelete.BackgroundImage = Properties.Resources.Delete;
+ buttonDelete.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonDelete.Location = new Point(14, 154);
+ buttonDelete.Name = "buttonDelete";
+ buttonDelete.Size = new Size(65, 65);
+ buttonDelete.TabIndex = 1;
+ buttonDelete.UseVisualStyleBackColor = true;
+ //
+ // buttonAdd
+ //
+ buttonAdd.BackgroundImage = Properties.Resources.Add;
+ buttonAdd.BackgroundImageLayout = ImageLayout.Stretch;
+ buttonAdd.Location = new Point(14, 12);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(65, 65);
+ buttonAdd.TabIndex = 0;
+ buttonAdd.UseVisualStyleBackColor = true;
+ //
+ // panel1
+ //
+ panel1.Controls.Add(buttonUpdate);
+ panel1.Controls.Add(buttonDelete);
+ panel1.Controls.Add(buttonAdd);
+ panel1.Dock = DockStyle.Right;
+ panel1.Location = new Point(709, 0);
+ panel1.Name = "panel1";
+ panel1.Size = new Size(91, 450);
+ panel1.TabIndex = 6;
+ //
+ // FormSupplys
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(dataGridViewData);
+ Controls.Add(panel1);
+ Name = "FormSupplys";
+ StartPosition = FormStartPosition.CenterParent;
+ Text = "FormSupplys";
+ ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit();
+ panel1.ResumeLayout(false);
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private DataGridView dataGridViewData;
+ private Button buttonUpdate;
+ private Button buttonDelete;
+ private Button buttonAdd;
+ private Panel panel1;
+ }
+}
\ No newline at end of file
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplys.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplys.cs
new file mode 100644
index 0000000..1bfefee
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplys.cs
@@ -0,0 +1,80 @@
+using ProjectConfectionaryFactory.Repositories;
+using Unity;
+
+namespace ProjectConfectionaryFactory.Forms
+{
+ public partial class FormSupplys : Form
+ {
+ private readonly IUnityContainer _container;
+ private readonly ISupplyRepository _supplyRepository;
+ public FormSupplys(IUnityContainer container, ISupplyRepository supplyRepository)
+ {
+ InitializeComponent();
+ _container = container ?? throw new ArgumentNullException(nameof(container));
+ _supplyRepository = supplyRepository ?? throw new ArgumentNullException(nameof(supplyRepository));
+ }
+ private void FormSupplys_Load(object sender, EventArgs e)
+ {
+ try
+ {
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonAdd_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ _container.Resolve().ShowDialog();
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonUpdate_Click(object sender, EventArgs e)
+ {
+ if (!TryGetIdentifierFromSelectedRow(out var findId)) { return; }
+ try
+ {
+ var form = _container.Resolve();
+ form.Id = findId;
+ form.ShowDialog();
+ LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void ButtonDelete_Click(object sender, EventArgs e)
+ {
+ if (!TryGetIdentifierFromSelectedRow(out var findId)) { return; }
+ if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; }
+ try
+ {
+ _supplyRepository.DeleteSupply(findId); LoadList();
+ }
+ catch (Exception ex)
+ {
+ MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ private void LoadList() => dataGridViewData.DataSource = _supplyRepository.ReadSupplys();
+ private bool TryGetIdentifierFromSelectedRow(out int id)
+ {
+ id = 0;
+ if (dataGridViewData.SelectedRows.Count < 1)
+ {
+ MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return false;
+ }
+ id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["Id"].Value);
+ return true;
+ }
+ }
+}
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplys.resx b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplys.resx
new file mode 100644
index 0000000..8b2ff64
--- /dev/null
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Forms/FormSupplys.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/ProjectConfectionaryFactory/ProjectConfectionaryFactory/ProjectConfectionaryFactory.csproj b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/ProjectConfectionaryFactory.csproj
index 6734a77..accbdf0 100644
--- a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/ProjectConfectionaryFactory.csproj
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/ProjectConfectionaryFactory.csproj
@@ -27,8 +27,4 @@
-
-
-
-
\ No newline at end of file
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Properties/Resources.Designer.cs b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Properties/Resources.Designer.cs
index 285e3dd..b217fd3 100644
--- a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Properties/Resources.Designer.cs
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Properties/Resources.Designer.cs
@@ -60,6 +60,16 @@ namespace ProjectConfectionaryFactory.Properties {
}
}
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap Add {
+ get {
+ object obj = ResourceManager.GetObject("Add", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
///
/// Поиск локализованного ресурса типа System.Drawing.Bitmap.
///
@@ -69,5 +79,25 @@ namespace ProjectConfectionaryFactory.Properties {
return ((System.Drawing.Bitmap)(obj));
}
}
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap Delete {
+ get {
+ object obj = ResourceManager.GetObject("Delete", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
+
+ ///
+ /// Поиск локализованного ресурса типа System.Drawing.Bitmap.
+ ///
+ internal static System.Drawing.Bitmap Update {
+ get {
+ object obj = ResourceManager.GetObject("Update", resourceCulture);
+ return ((System.Drawing.Bitmap)(obj));
+ }
+ }
}
}
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Properties/Resources.resx b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Properties/Resources.resx
index cbb684f..d48d7ba 100644
--- a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Properties/Resources.resx
+++ b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Properties/Resources.resx
@@ -118,7 +118,16 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ ..\Resources\Delete.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
..\Resources\Croissant.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+ ..\Resources\Add.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
+
+ ..\Resources\Update.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
+
\ No newline at end of file
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Resources/Add.png b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Resources/Add.png
new file mode 100644
index 0000000..a1722f1
Binary files /dev/null and b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Resources/Add.png differ
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Resources/Delete.png b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Resources/Delete.png
new file mode 100644
index 0000000..fb02509
Binary files /dev/null and b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Resources/Delete.png differ
diff --git a/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Resources/Update.png b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Resources/Update.png
new file mode 100644
index 0000000..05f7434
Binary files /dev/null and b/ProjectConfectionaryFactory/ProjectConfectionaryFactory/Resources/Update.png differ