diff --git a/Diagramma/LabWork_2.vpp b/Diagramma/LabWork_2.vpp index cf7f519..8b1b4ce 100644 Binary files a/Diagramma/LabWork_2.vpp and b/Diagramma/LabWork_2.vpp differ diff --git a/Diagramma/LabWork_2.vpp.bak_002d b/Diagramma/LabWork_2.vpp.bak_002d new file mode 100644 index 0000000..3f89e06 Binary files /dev/null and b/Diagramma/LabWork_2.vpp.bak_002d differ diff --git a/Diagramma/LabWork_2.vpp.bak_003d b/Diagramma/LabWork_2.vpp.bak_003d new file mode 100644 index 0000000..f118afd Binary files /dev/null and b/Diagramma/LabWork_2.vpp.bak_003d differ diff --git a/Diagramma/LabWork_2.vpp.bak_004d b/Diagramma/LabWork_2.vpp.bak_004d new file mode 100644 index 0000000..9b62495 Binary files /dev/null and b/Diagramma/LabWork_2.vpp.bak_004d differ diff --git a/Diagramma/LabWork_2.vpp.bak_005d b/Diagramma/LabWork_2.vpp.bak_005d new file mode 100644 index 0000000..1430261 Binary files /dev/null and b/Diagramma/LabWork_2.vpp.bak_005d differ diff --git a/Diagramma/LabWork_2.vpp.bak_006d b/Diagramma/LabWork_2.vpp.bak_006d new file mode 100644 index 0000000..f61a485 Binary files /dev/null and b/Diagramma/LabWork_2.vpp.bak_006d differ diff --git a/ProjectOptika/Scripts/Entities/BundleOrder.cs b/ProjectOptika/Scripts/Entities/BundleOrder.cs index 324788b..8489777 100644 --- a/ProjectOptika/Scripts/Entities/BundleOrder.cs +++ b/ProjectOptika/Scripts/Entities/BundleOrder.cs @@ -6,15 +6,15 @@ public int AccessoriesID { get; private set; } - public int OrderID { get; private set; } + public double TotalCost { get; private set; } - public static BundleOrder CreateBundleOrder(int id, int accessoriesID, int orderID) + public static BundleOrder CreateBundleOrder(int id, int accessoriesID, double totalCost) { return new BundleOrder { ID = id, AccessoriesID = accessoriesID, - OrderID = orderID, + TotalCost = totalCost }; } } diff --git a/ProjectOptika/Scripts/Entities/Employee.cs b/ProjectOptika/Scripts/Entities/Employee.cs new file mode 100644 index 0000000..294a1cf --- /dev/null +++ b/ProjectOptika/Scripts/Entities/Employee.cs @@ -0,0 +1,31 @@ +using ProjectOptika.Scripts.Entities.Enums; + +namespace ProjectOptika.Scripts.Entities +{ + public class Employee + { + public int ID { get; private set; } + + public PositionEmployee PositionEmployee { get; private set; } + + public string FirstName { get; private set; } + + public string SecondName { get; private set; } + + public string Surname { get; private set; } + + public IEnumerable BundleOrder { get; private set; } + + public static Employee CreateEmployee(int id, PositionEmployee positionEmployee, string firstName, string secondName, string surname, IEnumerable bundleOrder) { + return new Employee + { + ID = id, + PositionEmployee = positionEmployee, + FirstName = firstName, + SecondName = secondName, + Surname = surname, + BundleOrder = bundleOrder + }; + } + } +} diff --git a/ProjectOptika/Scripts/Entities/Enums/PositionEmployee.cs b/ProjectOptika/Scripts/Entities/Enums/PositionEmployee.cs new file mode 100644 index 0000000..b0c4fce --- /dev/null +++ b/ProjectOptika/Scripts/Entities/Enums/PositionEmployee.cs @@ -0,0 +1,13 @@ +namespace ProjectOptika.Scripts.Entities.Enums +{ + [System.Flags] + public enum PositionEmployee + { + None = 0, + SeniorSalesman = 1, + Salesman = 2, + SellerCashier = 3, + Administrator = 4, + Accountant = 5 + } +} diff --git a/ProjectOptika/Scripts/Entities/ItemOrder.cs b/ProjectOptika/Scripts/Entities/ItemOrder.cs index 89f94fd..95bfc66 100644 --- a/ProjectOptika/Scripts/Entities/ItemOrder.cs +++ b/ProjectOptika/Scripts/Entities/ItemOrder.cs @@ -6,17 +6,14 @@ public int AccessoriesID { get; private set; } - public int OrderID { get; private set; } - public int Count { get; private set; } - public static ItemOrder CreateItemOrder (int id, int accessoriesID, int orderID, int count) + public static ItemOrder CreateItemOrder (int id, int accessoriesID, int count) { return new ItemOrder { ID = id, AccessoriesID = accessoriesID, - OrderID = orderID, Count = count }; } diff --git a/ProjectOptika/Scripts/Entities/Order.cs b/ProjectOptika/Scripts/Entities/Order.cs index fa7ffc9..40873a8 100644 --- a/ProjectOptika/Scripts/Entities/Order.cs +++ b/ProjectOptika/Scripts/Entities/Order.cs @@ -4,16 +4,22 @@ { public int ID { get; private set; } + public int EmployeeID { get; private set; } + public DateTime OrderDate { get; private set; } public double TotalCost { get; private set; } - public static Order CreateOrder(int id, double totalCost) + public IEnumerable ItemOrders { get; private set; } + + public static Order CreateOrder(int id, int employeeID, double totalCost, IEnumerable itemOrders) { return new Order { ID = id, + EmployeeID = employeeID, OrderDate = DateTime.Now, - TotalCost = totalCost + TotalCost = totalCost, + ItemOrders = itemOrders }; } } diff --git a/ProjectOptika/Scripts/Entities/Lens.cs b/ProjectOptika/Scripts/Entities/Specifications.cs similarity index 68% rename from ProjectOptika/Scripts/Entities/Lens.cs rename to ProjectOptika/Scripts/Entities/Specifications.cs index 4a34309..a6b1e83 100644 --- a/ProjectOptika/Scripts/Entities/Lens.cs +++ b/ProjectOptika/Scripts/Entities/Specifications.cs @@ -1,7 +1,9 @@ namespace ProjectOptika.Scripts.Entities { - public class Lens + public class Specifications { + public int ID { get; private set; } + public int AccessoriesID { get; private set; } public string Material { get; private set; } @@ -14,10 +16,11 @@ public double TimeProduction { get; private set; } - public static Lens CreateLens(int accessoriesID, string material, string astigmatism, string dioptericity, string originCountry, double timeProduction) + public static Specifications CreateSpecifications(int id, int accessoriesID, string material, string astigmatism, string dioptericity, string originCountry, double timeProduction) { - return new Lens + return new Specifications { + ID = id, AccessoriesID = accessoriesID, Material = material, Astigmatism = astigmatism, diff --git a/ProjectOptika/Scripts/Forms/FormAccessory.cs b/ProjectOptika/Scripts/Forms/FormAccessory.cs index 3a25904..16beaec 100644 --- a/ProjectOptika/Scripts/Forms/FormAccessory.cs +++ b/ProjectOptika/Scripts/Forms/FormAccessory.cs @@ -21,6 +21,15 @@ namespace ProjectOptika.Scripts.Forms if (accessory == null) throw new InvalidDataException(nameof(accessory)); _accessoriesID = accessory.ID; + textBoxBrand.Text = accessory.Brand; + textBoxName.Text = accessory.Name; + numericUpDownCost.Value = accessory.Cost; + numericUpDownAvailabilityStore.Value = accessory.AvailabilityStore; + numericUpDownStockAvailability.Value = accessory.StockAvailability; + dateTimePickerDeliveryDate.Value = accessory.DeliveryDate; + + comboBoxCategoryName.DataSource = Enum.GetValues(typeof(CategoryType)); + comboBoxCategoryName.SelectedIndex = (int)accessory.CategoryName; } catch (Exception ex) { @@ -36,12 +45,6 @@ namespace ProjectOptika.Scripts.Forms _accessoriesRepositories = accessoriesRepositories ?? throw new ArgumentNullException(nameof(accessoriesRepositories)); - - comboBoxCategoryName.Items.Clear(); - foreach (var i in Enum.GetValues(typeof(CategoryType))) - { - comboBoxCategoryName.Items.Add(i); - } } private void ButtonSave_Click(object sender, EventArgs e) diff --git a/ProjectOptika/Scripts/Forms/FormBundleOrder.Designer.cs b/ProjectOptika/Scripts/Forms/FormBundleOrder.Designer.cs index a8476c1..9021efa 100644 --- a/ProjectOptika/Scripts/Forms/FormBundleOrder.Designer.cs +++ b/ProjectOptika/Scripts/Forms/FormBundleOrder.Designer.cs @@ -28,94 +28,146 @@ /// private void InitializeComponent() { + comboBoxEmployee = new ComboBox(); + labelEmployee = new Label(); + groupBoxOrders = new GroupBox(); + dataGridView = new DataGridView(); + ColumnAccessories = new DataGridViewComboBoxColumn(); + ColumnCost = new DataGridViewTextBoxColumn(); buttonCancel = new Button(); buttonSave = new Button(); - labelOrderID = new Label(); - comboBoxOrderID = new ComboBox(); - labelAccessoriesID = new Label(); - comboBoxAccessoriesID = new ComboBox(); + labelTotalCost = new Label(); + numericUpDownTotalCost = new NumericUpDown(); + groupBoxOrders.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownTotalCost).BeginInit(); SuspendLayout(); // + // comboBoxEmployee + // + comboBoxEmployee.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxEmployee.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxEmployee.FormattingEnabled = true; + comboBoxEmployee.Location = new Point(101, 9); + comboBoxEmployee.Name = "comboBoxEmployee"; + comboBoxEmployee.Size = new Size(190, 28); + comboBoxEmployee.TabIndex = 7; + // + // labelEmployee + // + labelEmployee.AutoSize = true; + labelEmployee.Location = new Point(13, 12); + labelEmployee.Name = "labelEmployee"; + labelEmployee.Size = new Size(82, 20); + labelEmployee.TabIndex = 5; + labelEmployee.Text = "Сотрудник"; + // + // groupBoxOrders + // + groupBoxOrders.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBoxOrders.Controls.Add(dataGridView); + groupBoxOrders.Location = new Point(5, 98); + groupBoxOrders.Name = "groupBoxOrders"; + groupBoxOrders.Size = new Size(309, 294); + groupBoxOrders.TabIndex = 4; + groupBoxOrders.TabStop = false; + groupBoxOrders.Text = "Заказы"; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnAccessories, ColumnCost }); + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(3, 23); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(303, 268); + dataGridView.TabIndex = 0; + // + // ColumnAccessories + // + ColumnAccessories.HeaderText = "Аксессуар"; + ColumnAccessories.MinimumWidth = 6; + ColumnAccessories.Name = "ColumnAccessories"; + ColumnAccessories.Width = 125; + // + // ColumnCost + // + ColumnCost.HeaderText = "Стоимость"; + ColumnCost.MinimumWidth = 6; + ColumnCost.Name = "ColumnCost"; + ColumnCost.Width = 125; + // // buttonCancel // - buttonCancel.Location = new Point(186, 110); + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(213, 412); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(94, 29); - buttonCancel.TabIndex = 15; - buttonCancel.Text = "Отмена"; + buttonCancel.TabIndex = 8; + buttonCancel.Text = "Отменить"; buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; // // buttonSave // - buttonSave.Location = new Point(60, 110); + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(13, 412); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(94, 29); - buttonSave.TabIndex = 14; + buttonSave.TabIndex = 6; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; buttonSave.Click += ButtonSave_Click; // - // labelOrderID + // labelTotalCost // - labelOrderID.AutoSize = true; - labelOrderID.Location = new Point(12, 68); - labelOrderID.Name = "labelOrderID"; - labelOrderID.Size = new Size(73, 20); - labelOrderID.TabIndex = 13; - labelOrderID.Text = "ID заказа"; + labelTotalCost.AutoSize = true; + labelTotalCost.Location = new Point(12, 54); + labelTotalCost.Name = "labelTotalCost"; + labelTotalCost.Size = new Size(133, 20); + labelTotalCost.TabIndex = 9; + labelTotalCost.Text = "Общая стоимость"; // - // comboBoxOrderID + // numericUpDownTotalCost // - comboBoxOrderID.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxOrderID.FormattingEnabled = true; - comboBoxOrderID.Location = new Point(185, 65); - comboBoxOrderID.Name = "comboBoxOrderID"; - comboBoxOrderID.Size = new Size(155, 28); - comboBoxOrderID.TabIndex = 12; - // - // labelAccessoriesID - // - labelAccessoriesID.AutoSize = true; - labelAccessoriesID.Location = new Point(11, 15); - labelAccessoriesID.Name = "labelAccessoriesID"; - labelAccessoriesID.Size = new Size(156, 20); - labelAccessoriesID.TabIndex = 11; - labelAccessoriesID.Text = "Название аксуссуара"; - // - // comboBoxAccessoriesID - // - comboBoxAccessoriesID.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxAccessoriesID.FormattingEnabled = true; - comboBoxAccessoriesID.Location = new Point(185, 12); - comboBoxAccessoriesID.Name = "comboBoxAccessoriesID"; - comboBoxAccessoriesID.Size = new Size(155, 28); - comboBoxAccessoriesID.TabIndex = 10; + numericUpDownTotalCost.Location = new Point(164, 52); + numericUpDownTotalCost.Name = "numericUpDownTotalCost"; + numericUpDownTotalCost.Size = new Size(150, 27); + numericUpDownTotalCost.TabIndex = 10; // // FormBundleOrder // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(358, 163); + ClientSize = new Size(318, 450); + Controls.Add(numericUpDownTotalCost); + Controls.Add(labelTotalCost); + Controls.Add(comboBoxEmployee); + Controls.Add(labelEmployee); + Controls.Add(groupBoxOrders); Controls.Add(buttonCancel); Controls.Add(buttonSave); - Controls.Add(labelOrderID); - Controls.Add(comboBoxOrderID); - Controls.Add(labelAccessoriesID); - Controls.Add(comboBoxAccessoriesID); Name = "FormBundleOrder"; - Text = "BundleOrder"; + Text = "FormBundleOrder"; + groupBoxOrders.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownTotalCost).EndInit(); ResumeLayout(false); PerformLayout(); } #endregion + private ComboBox comboBoxEmployee; + private Label labelEmployee; + private GroupBox groupBoxOrders; + private DataGridView dataGridView; private Button buttonCancel; private Button buttonSave; - private Label labelOrderID; - private ComboBox comboBoxOrderID; - private Label labelAccessoriesID; - private ComboBox comboBoxAccessoriesID; + private DataGridViewComboBoxColumn ColumnAccessories; + private DataGridViewTextBoxColumn ColumnCost; + private Label labelTotalCost; + private NumericUpDown numericUpDownTotalCost; } } \ No newline at end of file diff --git a/ProjectOptika/Scripts/Forms/FormBundleOrder.cs b/ProjectOptika/Scripts/Forms/FormBundleOrder.cs index b0dabc3..cd457ff 100644 --- a/ProjectOptika/Scripts/Forms/FormBundleOrder.cs +++ b/ProjectOptika/Scripts/Forms/FormBundleOrder.cs @@ -5,70 +5,39 @@ namespace ProjectOptika.Scripts.Forms { public partial class FormBundleOrder : Form { + private IEmployeeRepositories _employeeRepositories; - private readonly IBundleOrderRepositories _bundleOrderRepositories; - - private int? _bundleOrderID; - - public int ID - { - set - { - try - { - var itemOrder = _bundleOrderRepositories.GetBundleOrderByID(value); - - if (itemOrder == null) throw new InvalidDataException(nameof(itemOrder)); - - _bundleOrderID = itemOrder.ID; - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - - public FormBundleOrder(IBundleOrderRepositories bundleOrderRepositories, IAccessoriesRepositories accessoriesRepositories, IOrderRepositories orderRepositories) + public FormBundleOrder(IEmployeeRepositories employeeRepositories, IAccessoriesRepositories accessoriesRepositories) { InitializeComponent(); + _employeeRepositories = employeeRepositories ?? + throw new ArgumentNullException(nameof(employeeRepositories)); - _bundleOrderRepositories = bundleOrderRepositories - ?? throw new ArgumentNullException(nameof(bundleOrderRepositories)); + comboBoxEmployee.DataSource = employeeRepositories.GetEmployees(); + comboBoxEmployee.DisplayMember = "ID"; + comboBoxEmployee.ValueMember = "ID"; - comboBoxAccessoriesID.DataSource = accessoriesRepositories.GetAccessories(); - comboBoxAccessoriesID.DisplayMember = "Name"; - comboBoxAccessoriesID.ValueMember = "ID"; - - comboBoxAccessoriesID.DataSource = orderRepositories.GetOrders(); - comboBoxAccessoriesID.DisplayMember = "ID"; - comboBoxAccessoriesID.ValueMember = "ID"; + ColumnAccessories.DataSource = accessoriesRepositories.GetAccessories(); + ColumnAccessories.DisplayMember = "Name"; + ColumnAccessories.ValueMember = "ID"; } private void ButtonSave_Click(object sender, EventArgs e) { try { - if (comboBoxAccessoriesID.SelectedIndex < 1 || comboBoxOrderID.SelectedIndex < 1) - { - throw new Exception("Имеются незаполненные данные"); - } + if (dataGridView.RowCount < 1 || comboBoxEmployee.SelectedIndex < 0) throw new Exception("Имеются не заполненные поля"); - if (_bundleOrderID.HasValue) - { - _bundleOrderRepositories.UpdateBundleOrder(CreateBundleOrder(_bundleOrderID.Value)); - } - else - { - _bundleOrderRepositories.CreateBundleOrder(CreateBundleOrder(0)); - } + var employee = _employeeRepositories.GetEmployeerByID((int)comboBoxEmployee.SelectedItem); + + _employeeRepositories.CreateEmployee(Employee.CreateEmployee(employee.ID, employee.PositionEmployee, employee.FirstName, employee.SecondName, employee.Surname, CreateListIBundleOrderFromDataGrid())); + + Close(); } catch (System.Exception ex) { - MessageBox.Show(ex.Message, "Ошибка при получении сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); } - Close(); } private void ButtonCancel_Click(object sender, EventArgs e) @@ -76,9 +45,21 @@ namespace ProjectOptika.Scripts.Forms Close(); } - private BundleOrder CreateBundleOrder(int id) + private List CreateListIBundleOrderFromDataGrid() { - return BundleOrder.CreateBundleOrder(id, (int)comboBoxAccessoriesID.SelectedValue, (int)comboBoxOrderID.SelectedValue); + var list = new List(); + + foreach (DataGridViewRow row in dataGridView.Rows) + { + if (row.Cells["ColumnAccessories"].Value == null || row.Cells["ColumnCost"].Value == null) + { + continue; + } + + list.Add(BundleOrder.CreateBundleOrder(0, Convert.ToInt32(row.Cells["ColumnAccessories"].Value), Convert.ToInt32(row.Cells["ColumnCost"].Value))); + } + + return list; } } } diff --git a/ProjectOptika/Scripts/Forms/FormBundleOrder.resx b/ProjectOptika/Scripts/Forms/FormBundleOrder.resx index af32865..95d9b3e 100644 --- a/ProjectOptika/Scripts/Forms/FormBundleOrder.resx +++ b/ProjectOptika/Scripts/Forms/FormBundleOrder.resx @@ -117,4 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + + + True + \ No newline at end of file diff --git a/ProjectOptika/Scripts/Forms/FormBundleOrders.Designer.cs b/ProjectOptika/Scripts/Forms/FormBundleOrders.Designer.cs deleted file mode 100644 index 3653f8b..0000000 --- a/ProjectOptika/Scripts/Forms/FormBundleOrders.Designer.cs +++ /dev/null @@ -1,126 +0,0 @@ -namespace ProjectOptika.Scripts.Forms -{ - partial class FormBundleOrders - { - /// - /// 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(); - buttonRemove = new Button(); - buttonUpdate = new Button(); - buttonAdd = new Button(); - dataGridView = new DataGridView(); - panel1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // panel1 - // - panel1.Controls.Add(buttonRemove); - panel1.Controls.Add(buttonUpdate); - panel1.Controls.Add(buttonAdd); - panel1.Dock = DockStyle.Right; - panel1.Location = new Point(696, 0); - panel1.Name = "panel1"; - panel1.Size = new Size(104, 450); - panel1.TabIndex = 8; - // - // buttonRemove - // - buttonRemove.BackgroundImage = Properties.Resources.Remove; - buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; - buttonRemove.Location = new Point(3, 166); - buttonRemove.Name = "buttonRemove"; - buttonRemove.Size = new Size(96, 71); - buttonRemove.TabIndex = 2; - buttonRemove.UseVisualStyleBackColor = true; - buttonRemove.Click += ButtonRemove_Click; - // - // buttonUpdate - // - buttonUpdate.BackgroundImage = Properties.Resources.Update; - buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; - buttonUpdate.Location = new Point(3, 89); - buttonUpdate.Name = "buttonUpdate"; - buttonUpdate.Size = new Size(96, 71); - buttonUpdate.TabIndex = 1; - buttonUpdate.UseVisualStyleBackColor = true; - buttonUpdate.Click += ButtonUpdate_Click; - // - // buttonAdd - // - buttonAdd.BackgroundImage = Properties.Resources.Add; - buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; - buttonAdd.Location = new Point(3, 12); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(96, 71); - buttonAdd.TabIndex = 0; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += ButtonAdd_Click; - // - // dataGridView - // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; - dataGridView.AllowUserToResizeColumns = false; - dataGridView.AllowUserToResizeRows = false; - dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Dock = DockStyle.Fill; - dataGridView.Location = new Point(0, 0); - dataGridView.MultiSelect = false; - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersVisible = false; - dataGridView.RowHeadersWidth = 51; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(800, 450); - dataGridView.TabIndex = 9; - // - // FormBundleOrders - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Controls.Add(panel1); - Controls.Add(dataGridView); - Name = "FormBundleOrders"; - Text = "FormBundleOrders"; - Load += Form_Load; - panel1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - } - - #endregion - - private Panel panel1; - private Button buttonRemove; - private Button buttonUpdate; - private Button buttonAdd; - private DataGridView dataGridView; - } -} \ No newline at end of file diff --git a/ProjectOptika/Scripts/Forms/FormBundleOrders.cs b/ProjectOptika/Scripts/Forms/FormBundleOrders.cs deleted file mode 100644 index 6c8de0d..0000000 --- a/ProjectOptika/Scripts/Forms/FormBundleOrders.cs +++ /dev/null @@ -1,97 +0,0 @@ -using ProjectOptika.Scripts.Repositories; -using Unity; - -namespace ProjectOptika.Scripts.Forms -{ - public partial class FormBundleOrders : Form - { - private readonly IUnityContainer _container; - - private readonly IBundleOrderRepositories _bundleOrderRepositories; - - public FormBundleOrders(IUnityContainer container, IBundleOrderRepositories bundleOrderRepositories) - { - InitializeComponent(); - - _container = container ?? - throw new ArgumentException(nameof(container)); - - _bundleOrderRepositories = bundleOrderRepositories ?? - throw new ArgumentException(nameof(bundleOrderRepositories)); - } - - private void Form_Load(object sender, EventArgs e) - { - try - { - LoadList(); - } - catch (System.Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void ButtonAdd_Click(object sender, EventArgs e) - { - try - { - _container.Resolve().ShowDialog(); - LoadList(); - } - catch (System.Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void ButtonUpdate_Click(object sender, EventArgs e) - { - if (!TryGetIdentifierFromSelectedRows(out var findID)) return; - - try - { - var form = _container.Resolve(); - form.ID = findID; - form.ShowDialog(); - LoadList(); - } - catch (System.Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void ButtonRemove_Click(object sender, EventArgs e) - { - if (!TryGetIdentifierFromSelectedRows(out var findID)) return; - - if (MessageBox.Show("Удалить запись?", "Удалить", MessageBoxButtons.YesNo) != DialogResult.Yes) return; - - try - { - _bundleOrderRepositories.DeleteItemOrder(findID); - LoadList(); - } - catch (System.Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void LoadList() => dataGridView.DataSource = _bundleOrderRepositories.GetBundleOrders(); - - private bool TryGetIdentifierFromSelectedRows(out int id) - { - id = 0; - if (dataGridView.SelectedRows.Count < 1) - { - MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - - id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ID"].Value); - return true; - } - } -} diff --git a/ProjectOptika/Scripts/Forms/FormEmployee.Designer.cs b/ProjectOptika/Scripts/Forms/FormEmployee.Designer.cs new file mode 100644 index 0000000..549d1ce --- /dev/null +++ b/ProjectOptika/Scripts/Forms/FormEmployee.Designer.cs @@ -0,0 +1,162 @@ +namespace ProjectOptika.Scripts.Forms +{ + partial class FormEmployee + { + /// + /// 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() + { + checkedListBoxPositionEmployee = new CheckedListBox(); + labelFirstName = new Label(); + textBoxFirstName = new TextBox(); + textBoxSecondName = new TextBox(); + labelSecondName = new Label(); + textBoxSurname = new TextBox(); + labelSurname = new Label(); + labelPositionEmployee = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); + SuspendLayout(); + // + // checkedListBoxPositionEmployee + // + checkedListBoxPositionEmployee.FormattingEnabled = true; + checkedListBoxPositionEmployee.Location = new Point(298, 45); + checkedListBoxPositionEmployee.Name = "checkedListBoxPositionEmployee"; + checkedListBoxPositionEmployee.Size = new Size(225, 180); + checkedListBoxPositionEmployee.TabIndex = 0; + // + // labelFirstName + // + labelFirstName.AutoSize = true; + labelFirstName.Location = new Point(12, 9); + labelFirstName.Name = "labelFirstName"; + labelFirstName.Size = new Size(39, 20); + labelFirstName.TabIndex = 1; + labelFirstName.Text = "Имя"; + // + // textBoxFirstName + // + textBoxFirstName.Location = new Point(109, 6); + textBoxFirstName.Name = "textBoxFirstName"; + textBoxFirstName.Size = new Size(125, 27); + textBoxFirstName.TabIndex = 2; + // + // textBoxSecondName + // + textBoxSecondName.Location = new Point(109, 54); + textBoxSecondName.Name = "textBoxSecondName"; + textBoxSecondName.Size = new Size(125, 27); + textBoxSecondName.TabIndex = 4; + // + // labelSecondName + // + labelSecondName.AutoSize = true; + labelSecondName.Location = new Point(12, 57); + labelSecondName.Name = "labelSecondName"; + labelSecondName.Size = new Size(72, 20); + labelSecondName.TabIndex = 3; + labelSecondName.Text = "Отчество"; + // + // textBoxSurname + // + textBoxSurname.Location = new Point(109, 105); + textBoxSurname.Name = "textBoxSurname"; + textBoxSurname.Size = new Size(125, 27); + textBoxSurname.TabIndex = 6; + // + // labelSurname + // + labelSurname.AutoSize = true; + labelSurname.Location = new Point(12, 108); + labelSurname.Name = "labelSurname"; + labelSurname.Size = new Size(74, 20); + labelSurname.TabIndex = 5; + labelSurname.Text = "Фимилия"; + // + // labelPositionEmployee + // + labelPositionEmployee.AutoSize = true; + labelPositionEmployee.Location = new Point(298, 13); + labelPositionEmployee.Name = "labelPositionEmployee"; + labelPositionEmployee.Size = new Size(86, 20); + labelPositionEmployee.TabIndex = 7; + labelPositionEmployee.Text = "Должность"; + // + // buttonCancel + // + buttonCancel.Location = new Point(151, 196); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 15; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(12, 196); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 14; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // FormEmployee + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(537, 255); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelPositionEmployee); + Controls.Add(textBoxSurname); + Controls.Add(labelSurname); + Controls.Add(textBoxSecondName); + Controls.Add(labelSecondName); + Controls.Add(textBoxFirstName); + Controls.Add(labelFirstName); + Controls.Add(checkedListBoxPositionEmployee); + Name = "FormEmployee"; + Text = "FormEmployee"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckedListBox checkedListBoxPositionEmployee; + private Label labelFirstName; + private TextBox textBoxFirstName; + private TextBox textBoxSecondName; + private Label labelSecondName; + private TextBox textBoxSurname; + private Label labelSurname; + private Label labelPositionEmployee; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/ProjectOptika/Scripts/Forms/FormEmployee.cs b/ProjectOptika/Scripts/Forms/FormEmployee.cs new file mode 100644 index 0000000..7c80605 --- /dev/null +++ b/ProjectOptika/Scripts/Forms/FormEmployee.cs @@ -0,0 +1,99 @@ +using ProjectOptika.Scripts.Entities.Enums; +using ProjectOptika.Scripts.Entities; +using ProjectOptika.Scripts.Repositories; + +namespace ProjectOptika.Scripts.Forms +{ + public partial class FormEmployee : Form + { + private readonly IEmployeeRepositories _employeeRepositories; + + private int? _employeeID; + + public int ID + { + set + { + try + { + var employee = _employeeRepositories.GetEmployeerByID(value); + + if (employee == null) throw new InvalidDataException(nameof(employee)); + + _employeeID = employee.ID; + textBoxFirstName.Text = employee.FirstName; + textBoxSecondName.Text = employee.SecondName; + textBoxSurname.Text = employee.Surname; + + foreach(PositionEmployee element in Enum.GetValues(typeof(PositionEmployee))) + { + if ((element & employee.PositionEmployee) != 0) + { + checkedListBoxPositionEmployee.SetItemChecked(checkedListBoxPositionEmployee.Items.IndexOf(element), true); + } + } + + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormEmployee(IEmployeeRepositories employeeRepositories) + { + InitializeComponent(); + + _employeeRepositories = employeeRepositories ?? + throw new ArgumentNullException(nameof(employeeRepositories)); + + foreach (var i in Enum.GetValues(typeof(PositionEmployee))) + { + checkedListBoxPositionEmployee.Items.Add(i); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrEmpty(textBoxSecondName.Text) || string.IsNullOrEmpty(textBoxSurname.Text) || string.IsNullOrEmpty(textBoxFirstName.Text)) + { + throw new Exception("Имеются незаполненные данные"); + } + + if (_employeeID.HasValue) + { + _employeeRepositories.UpdateEmployee(CreateEmployee(_employeeID.Value)); + } + else + { + _employeeRepositories.CreateEmployee(CreateEmployee(0)); + } + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + Close(); + } + + private Employee CreateEmployee(int id) + { + PositionEmployee positionEmployee = PositionEmployee.None; + foreach(var element in checkedListBoxPositionEmployee.CheckedItems) + { + positionEmployee |= (PositionEmployee)element; + } + + return Employee.CreateEmployee(id, positionEmployee, textBoxFirstName.Text, textBoxSecondName.Text, textBoxSurname.Text, null); + } + } +} diff --git a/ProjectOptika/Scripts/Forms/FormBundleOrders.resx b/ProjectOptika/Scripts/Forms/FormEmployee.resx similarity index 100% rename from ProjectOptika/Scripts/Forms/FormBundleOrders.resx rename to ProjectOptika/Scripts/Forms/FormEmployee.resx diff --git a/ProjectOptika/Scripts/Forms/FormOrders.Designer.cs b/ProjectOptika/Scripts/Forms/FormEmplyees.Designer.cs similarity index 97% rename from ProjectOptika/Scripts/Forms/FormOrders.Designer.cs rename to ProjectOptika/Scripts/Forms/FormEmplyees.Designer.cs index d0955f7..601ffd8 100644 --- a/ProjectOptika/Scripts/Forms/FormOrders.Designer.cs +++ b/ProjectOptika/Scripts/Forms/FormEmplyees.Designer.cs @@ -1,6 +1,6 @@ namespace ProjectOptika.Scripts.Forms { - partial class FormOrders + partial class FormEmplyees { /// /// Required designer variable. @@ -100,15 +100,15 @@ dataGridView.Size = new Size(800, 450); dataGridView.TabIndex = 7; // - // FormOrders + // FormEmplyees // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); Controls.Add(panel1); Controls.Add(dataGridView); - Name = "FormOrders"; - Text = "Заказ"; + Name = "FormEmplyees"; + Text = "FormEmplyees"; Load += Form_Load; panel1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); diff --git a/ProjectOptika/Scripts/Forms/FormOrders.cs b/ProjectOptika/Scripts/Forms/FormEmplyees.cs similarity index 73% rename from ProjectOptika/Scripts/Forms/FormOrders.cs rename to ProjectOptika/Scripts/Forms/FormEmplyees.cs index 5347ce1..a38cafe 100644 --- a/ProjectOptika/Scripts/Forms/FormOrders.cs +++ b/ProjectOptika/Scripts/Forms/FormEmplyees.cs @@ -1,23 +1,33 @@ using ProjectOptika.Scripts.Repositories; +using ProjectOptika.Scripts.Repositories.Implementations; +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 Unity; namespace ProjectOptika.Scripts.Forms { - public partial class FormOrders : Form + public partial class FormEmplyees : Form { private readonly IUnityContainer _container; - private readonly IOrderRepositories _orderRepositories; + private readonly IEmployeeRepositories _employeeRepositories; - public FormOrders(IUnityContainer container, IOrderRepositories orderRepositories) + public FormEmplyees(IUnityContainer container, IEmployeeRepositories employeeRepositories) { InitializeComponent(); _container = container ?? throw new ArgumentException(nameof(container)); - _orderRepositories = orderRepositories ?? - throw new ArgumentException(nameof(orderRepositories)); + _employeeRepositories = employeeRepositories ?? + throw new ArgumentException(nameof(employeeRepositories)); } private void Form_Load(object sender, EventArgs e) @@ -36,7 +46,7 @@ namespace ProjectOptika.Scripts.Forms { try { - _container.Resolve().ShowDialog(); + _container.Resolve().ShowDialog(); LoadList(); } catch (System.Exception ex) @@ -51,7 +61,7 @@ namespace ProjectOptika.Scripts.Forms try { - var form = _container.Resolve(); + var form = _container.Resolve(); form.ID = findID; form.ShowDialog(); LoadList(); @@ -70,7 +80,7 @@ namespace ProjectOptika.Scripts.Forms try { - _orderRepositories.DeleteOrder(findID); + _employeeRepositories.DeleteEmployee(findID); LoadList(); } catch (System.Exception ex) @@ -79,7 +89,7 @@ namespace ProjectOptika.Scripts.Forms } } - private void LoadList() => dataGridView.DataSource = _orderRepositories.GetOrders(); + private void LoadList() => dataGridView.DataSource = _employeeRepositories.GetEmployees(); private bool TryGetIdentifierFromSelectedRows(out int id) { diff --git a/ProjectOptika/Scripts/Forms/FormItemOrders.resx b/ProjectOptika/Scripts/Forms/FormEmplyees.resx similarity index 100% rename from ProjectOptika/Scripts/Forms/FormItemOrders.resx rename to ProjectOptika/Scripts/Forms/FormEmplyees.resx diff --git a/ProjectOptika/Scripts/Forms/FormItemOrder.Designer.cs b/ProjectOptika/Scripts/Forms/FormItemOrder.Designer.cs index 927a858..c7722f8 100644 --- a/ProjectOptika/Scripts/Forms/FormItemOrder.Designer.cs +++ b/ProjectOptika/Scripts/Forms/FormItemOrder.Designer.cs @@ -28,118 +28,122 @@ /// private void InitializeComponent() { - labelCount = new Label(); - numericUpDownCount = new NumericUpDown(); - comboBoxAccessoriesID = new ComboBox(); - labelAccessoriesID = new Label(); - labelOrderID = new Label(); - comboBoxOrderID = new ComboBox(); - buttonCancel = new Button(); + groupBoxOrders = new GroupBox(); + dataGridView = new DataGridView(); + ColumnAccessories = new DataGridViewComboBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + labelEmployee = new Label(); + comboBoxEmployee = new ComboBox(); buttonSave = new Button(); - ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); + buttonCancel = new Button(); + groupBoxOrders.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); SuspendLayout(); // - // labelCount + // groupBoxOrders // - labelCount.AutoSize = true; - labelCount.Location = new Point(12, 9); - labelCount.Name = "labelCount"; - labelCount.Size = new Size(90, 20); - labelCount.TabIndex = 0; - labelCount.Text = "Количество"; + groupBoxOrders.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBoxOrders.Controls.Add(dataGridView); + groupBoxOrders.Location = new Point(4, 53); + groupBoxOrders.Name = "groupBoxOrders"; + groupBoxOrders.Size = new Size(309, 336); + groupBoxOrders.TabIndex = 0; + groupBoxOrders.TabStop = false; + groupBoxOrders.Text = "Заказы"; // - // numericUpDownCount + // dataGridView // - numericUpDownCount.Location = new Point(187, 7); - numericUpDownCount.Name = "numericUpDownCount"; - numericUpDownCount.Size = new Size(154, 27); - numericUpDownCount.TabIndex = 1; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Columns.AddRange(new DataGridViewColumn[] { ColumnAccessories, ColumnCount }); + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(3, 23); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(303, 310); + dataGridView.TabIndex = 0; // - // comboBoxAccessoriesID + // ColumnAccessories // - comboBoxAccessoriesID.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxAccessoriesID.FormattingEnabled = true; - comboBoxAccessoriesID.Location = new Point(186, 60); - comboBoxAccessoriesID.Name = "comboBoxAccessoriesID"; - comboBoxAccessoriesID.Size = new Size(155, 28); - comboBoxAccessoriesID.TabIndex = 2; + ColumnAccessories.HeaderText = "Аксессуар"; + ColumnAccessories.MinimumWidth = 6; + ColumnAccessories.Name = "ColumnAccessories"; + ColumnAccessories.Width = 125; // - // labelAccessoriesID + // ColumnCount // - labelAccessoriesID.AutoSize = true; - labelAccessoriesID.Location = new Point(12, 63); - labelAccessoriesID.Name = "labelAccessoriesID"; - labelAccessoriesID.Size = new Size(156, 20); - labelAccessoriesID.TabIndex = 3; - labelAccessoriesID.Text = "Название аксуссуара"; + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.Width = 125; // - // labelOrderID + // labelEmployee // - labelOrderID.AutoSize = true; - labelOrderID.Location = new Point(13, 116); - labelOrderID.Name = "labelOrderID"; - labelOrderID.Size = new Size(73, 20); - labelOrderID.TabIndex = 5; - labelOrderID.Text = "ID заказа"; + labelEmployee.AutoSize = true; + labelEmployee.Location = new Point(12, 9); + labelEmployee.Name = "labelEmployee"; + labelEmployee.Size = new Size(82, 20); + labelEmployee.TabIndex = 1; + labelEmployee.Text = "Сотрудник"; // - // comboBoxOrderID + // comboBoxEmployee // - comboBoxOrderID.DropDownStyle = ComboBoxStyle.DropDownList; - comboBoxOrderID.FormattingEnabled = true; - comboBoxOrderID.Location = new Point(186, 113); - comboBoxOrderID.Name = "comboBoxOrderID"; - comboBoxOrderID.Size = new Size(155, 28); - comboBoxOrderID.TabIndex = 4; - // - // buttonCancel - // - buttonCancel.Location = new Point(187, 158); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(94, 29); - buttonCancel.TabIndex = 9; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += ButtonCancel_Click; + comboBoxEmployee.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxEmployee.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxEmployee.FormattingEnabled = true; + comboBoxEmployee.Location = new Point(100, 6); + comboBoxEmployee.Name = "comboBoxEmployee"; + comboBoxEmployee.Size = new Size(190, 28); + comboBoxEmployee.TabIndex = 2; // // buttonSave // - buttonSave.Location = new Point(61, 158); + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(12, 409); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(94, 29); - buttonSave.TabIndex = 8; + buttonSave.TabIndex = 1; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; buttonSave.Click += ButtonSave_Click; // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(212, 409); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // // FormItemOrder // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(349, 203); + ClientSize = new Size(318, 450); Controls.Add(buttonCancel); Controls.Add(buttonSave); - Controls.Add(labelOrderID); - Controls.Add(comboBoxOrderID); - Controls.Add(labelAccessoriesID); - Controls.Add(comboBoxAccessoriesID); - Controls.Add(numericUpDownCount); - Controls.Add(labelCount); + Controls.Add(comboBoxEmployee); + Controls.Add(labelEmployee); + Controls.Add(groupBoxOrders); Name = "FormItemOrder"; Text = "FormItemOrder"; - ((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit(); + groupBoxOrders.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); ResumeLayout(false); PerformLayout(); } #endregion - private Label labelCount; - private NumericUpDown numericUpDownCount; - private ComboBox comboBoxAccessoriesID; - private Label labelAccessoriesID; - private Label labelOrderID; - private ComboBox comboBoxOrderID; - private Button buttonCancel; + private GroupBox groupBoxOrders; + private Label labelEmployee; + private ComboBox comboBoxEmployee; + private DataGridView dataGridView; private Button buttonSave; + private Button buttonCancel; + private DataGridViewComboBoxColumn ColumnAccessories; + private DataGridViewTextBoxColumn ColumnCount; } } \ No newline at end of file diff --git a/ProjectOptika/Scripts/Forms/FormItemOrder.cs b/ProjectOptika/Scripts/Forms/FormItemOrder.cs index b831a88..d25ba30 100644 --- a/ProjectOptika/Scripts/Forms/FormItemOrder.cs +++ b/ProjectOptika/Scripts/Forms/FormItemOrder.cs @@ -5,69 +5,37 @@ namespace ProjectOptika.Scripts.Forms { public partial class FormItemOrder : Form { - private readonly IItemOrderRepositories _itemOrderRepositories; + private IOrderRepositories _orderRepositories; - private int? _itemOrderID; - - public int ID - { - set - { - try - { - var itemOrder = _itemOrderRepositories.GetItemOrderByID(value); - - if (itemOrder == null) throw new InvalidDataException(nameof(itemOrder)); - - _itemOrderID = itemOrder.ID; - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - - public FormItemOrder(IItemOrderRepositories itemOrderRepositories, IAccessoriesRepositories accessoriesRepositories, IOrderRepositories orderRepositories) + public FormItemOrder(IOrderRepositories orderRepositories, IEmployeeRepositories employeeRepositories, IAccessoriesRepositories accessoriesRepositories) { InitializeComponent(); - _itemOrderRepositories = itemOrderRepositories - ?? throw new ArgumentNullException(nameof(itemOrderRepositories)); + _orderRepositories = orderRepositories ?? + throw new ArgumentNullException(nameof(orderRepositories)); - comboBoxAccessoriesID.DataSource = accessoriesRepositories.GetAccessories(); - comboBoxAccessoriesID.DisplayMember = "Name"; - comboBoxAccessoriesID.ValueMember = "ID"; + comboBoxEmployee.DataSource = employeeRepositories.GetEmployees(); + comboBoxEmployee.DisplayMember = "FirstName"; + comboBoxEmployee.ValueMember = "ID"; - comboBoxAccessoriesID.DataSource = orderRepositories.GetOrders(); - comboBoxAccessoriesID.DisplayMember = "ID"; - comboBoxAccessoriesID.ValueMember = "ID"; + ColumnAccessories.DataSource = accessoriesRepositories.GetAccessories(); + ColumnAccessories.DisplayMember = "Name"; + ColumnAccessories.ValueMember = "ID"; } private void ButtonSave_Click(object sender, EventArgs e) { try { - if (comboBoxAccessoriesID.SelectedIndex < 1 || comboBoxOrderID.SelectedIndex < 1) - { - throw new Exception("Имеются незаполненные данные"); - } + if (dataGridView.RowCount < 1 || comboBoxEmployee.SelectedIndex < 0) throw new Exception("Имеются не заполненные поля"); + _orderRepositories.CreateOrder(Order.CreateOrder(0, (int)comboBoxEmployee.SelectedItem, 0, CreateListItemOrderFromDataGrid())); - if (_itemOrderID.HasValue) - { - _itemOrderRepositories.UpdateItemOrder(CreateItemOrder(_itemOrderID.Value)); - } - else - { - _itemOrderRepositories.CreateItemOrder(CreateItemOrder(0)); - } + Close(); } - catch (System.Exception ex) + catch(System.Exception ex) { - MessageBox.Show(ex.Message, "Ошибка при получении сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); } - Close(); } private void ButtonCancel_Click(object sender, EventArgs e) @@ -75,9 +43,21 @@ namespace ProjectOptika.Scripts.Forms Close(); } - private ItemOrder CreateItemOrder(int id) + private List CreateListItemOrderFromDataGrid() { - return ItemOrder.CreateItemOrder(id, (int)comboBoxAccessoriesID.SelectedValue, (int)comboBoxOrderID.SelectedValue, (int)numericUpDownCount.Value); + var list = new List(); + + foreach(DataGridViewRow row in dataGridView.Rows) + { + if (row.Cells["ColumnAccessories"].Value == null || row.Cells["ColumnCount"].Value == null) + { + continue; + } + + list.Add(ItemOrder.CreateItemOrder(0, Convert.ToInt32(row.Cells["ColumnAccessories"].Value), Convert.ToInt32(row.Cells["ColumnCount"].Value))); + } + + return list; } } } diff --git a/ProjectOptika/Scripts/Forms/FormItemOrder.resx b/ProjectOptika/Scripts/Forms/FormItemOrder.resx index af32865..987ae23 100644 --- a/ProjectOptika/Scripts/Forms/FormItemOrder.resx +++ b/ProjectOptika/Scripts/Forms/FormItemOrder.resx @@ -117,4 +117,16 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + True + + + True + + + True + + + True + \ No newline at end of file diff --git a/ProjectOptika/Scripts/Forms/FormItemOrders.Designer.cs b/ProjectOptika/Scripts/Forms/FormItemOrders.Designer.cs deleted file mode 100644 index f57864d..0000000 --- a/ProjectOptika/Scripts/Forms/FormItemOrders.Designer.cs +++ /dev/null @@ -1,126 +0,0 @@ -namespace ProjectOptika.Scripts.Forms -{ - partial class FormItemOrders - { - /// - /// 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(); - buttonRemove = new Button(); - buttonUpdate = new Button(); - buttonAdd = new Button(); - dataGridView = new DataGridView(); - panel1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // panel1 - // - panel1.Controls.Add(buttonRemove); - panel1.Controls.Add(buttonUpdate); - panel1.Controls.Add(buttonAdd); - panel1.Dock = DockStyle.Right; - panel1.Location = new Point(696, 0); - panel1.Name = "panel1"; - panel1.Size = new Size(104, 450); - panel1.TabIndex = 6; - // - // buttonRemove - // - buttonRemove.BackgroundImage = Properties.Resources.Remove; - buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; - buttonRemove.Location = new Point(3, 166); - buttonRemove.Name = "buttonRemove"; - buttonRemove.Size = new Size(96, 71); - buttonRemove.TabIndex = 2; - buttonRemove.UseVisualStyleBackColor = true; - buttonRemove.Click += ButtonRemove_Click; - // - // buttonUpdate - // - buttonUpdate.BackgroundImage = Properties.Resources.Update; - buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; - buttonUpdate.Location = new Point(3, 89); - buttonUpdate.Name = "buttonUpdate"; - buttonUpdate.Size = new Size(96, 71); - buttonUpdate.TabIndex = 1; - buttonUpdate.UseVisualStyleBackColor = true; - buttonUpdate.Click += ButtonUpdate_Click; - // - // buttonAdd - // - buttonAdd.BackgroundImage = Properties.Resources.Add; - buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; - buttonAdd.Location = new Point(3, 12); - buttonAdd.Name = "buttonAdd"; - buttonAdd.Size = new Size(96, 71); - buttonAdd.TabIndex = 0; - buttonAdd.UseVisualStyleBackColor = true; - buttonAdd.Click += ButtonAdd_Click; - // - // dataGridView - // - dataGridView.AllowUserToAddRows = false; - dataGridView.AllowUserToDeleteRows = false; - dataGridView.AllowUserToResizeColumns = false; - dataGridView.AllowUserToResizeRows = false; - dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Dock = DockStyle.Fill; - dataGridView.Location = new Point(0, 0); - dataGridView.MultiSelect = false; - dataGridView.Name = "dataGridView"; - dataGridView.ReadOnly = true; - dataGridView.RowHeadersVisible = false; - dataGridView.RowHeadersWidth = 51; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(800, 450); - dataGridView.TabIndex = 7; - // - // FormItemOrders - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); - Controls.Add(panel1); - Controls.Add(dataGridView); - Name = "FormItemOrders"; - Text = "FormItemOrders"; - Load += Form_Load; - panel1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - } - - #endregion - - private Panel panel1; - private Button buttonRemove; - private Button buttonUpdate; - private Button buttonAdd; - private DataGridView dataGridView; - } -} \ No newline at end of file diff --git a/ProjectOptika/Scripts/Forms/FormItemOrders.cs b/ProjectOptika/Scripts/Forms/FormItemOrders.cs deleted file mode 100644 index d04b9fb..0000000 --- a/ProjectOptika/Scripts/Forms/FormItemOrders.cs +++ /dev/null @@ -1,97 +0,0 @@ -using ProjectOptika.Scripts.Repositories; -using Unity; - -namespace ProjectOptika.Scripts.Forms -{ - public partial class FormItemOrders : Form - { - private readonly IUnityContainer _container; - - private readonly IItemOrderRepositories _itemOrderRepositories; - - public FormItemOrders(IUnityContainer container, IItemOrderRepositories itemOrderRepositories) - { - InitializeComponent(); - - _container = container ?? - throw new ArgumentException(nameof(container)); - - _itemOrderRepositories = itemOrderRepositories ?? - throw new ArgumentException(nameof(itemOrderRepositories)); - } - - private void Form_Load(object sender, EventArgs e) - { - try - { - LoadList(); - } - catch (System.Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void ButtonAdd_Click(object sender, EventArgs e) - { - try - { - _container.Resolve().ShowDialog(); - LoadList(); - } - catch (System.Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void ButtonUpdate_Click(object sender, EventArgs e) - { - if (!TryGetIdentifierFromSelectedRows(out var findID)) return; - - try - { - var form = _container.Resolve(); - form.ID = findID; - form.ShowDialog(); - LoadList(); - } - catch (System.Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void ButtonRemove_Click(object sender, EventArgs e) - { - if (!TryGetIdentifierFromSelectedRows(out var findID)) return; - - if (MessageBox.Show("Удалить запись?", "Удалить", MessageBoxButtons.YesNo) != DialogResult.Yes) return; - - try - { - _itemOrderRepositories.DeleteItemOrder(findID); - LoadList(); - } - catch (System.Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - - private void LoadList() => dataGridView.DataSource = _itemOrderRepositories.GetItemOrders(); - - private bool TryGetIdentifierFromSelectedRows(out int id) - { - id = 0; - if (dataGridView.SelectedRows.Count < 1) - { - MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); - return false; - } - - id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ID"].Value); - return true; - } - } -} diff --git a/ProjectOptika/Scripts/Forms/FormLen.cs b/ProjectOptika/Scripts/Forms/FormLen.cs deleted file mode 100644 index e638f2d..0000000 --- a/ProjectOptika/Scripts/Forms/FormLen.cs +++ /dev/null @@ -1,80 +0,0 @@ -using ProjectOptika.Scripts.Entities; -using ProjectOptika.Scripts.Repositories; - -namespace ProjectOptika.Scripts.Forms -{ - public partial class FormLen : Form - { - private readonly IAccessoriesRepositories _accessoriesRepositories; - private readonly ILensRepositories _lensRepositories; - - private int? _accessoriesID; - - public int ID - { - set - { - try - { - var accessories = _accessoriesRepositories.GetAccessoriesByID(value); - - if (accessories == null) throw new InvalidDataException(nameof(accessories)); - - _accessoriesID = accessories.ID; - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - - public FormLen(IAccessoriesRepositories accessoriesRepositories, ILensRepositories lensRepositories) - { - InitializeComponent(); - - _accessoriesRepositories = accessoriesRepositories - ?? throw new ArgumentNullException(nameof(accessoriesRepositories)); - - _lensRepositories = lensRepositories - ?? throw new ArgumentNullException(nameof(lensRepositories)); - } - - private void ButtonSave_Click(object sender, EventArgs e) - { - try - { - if (string.IsNullOrEmpty(textBoxMaterial.Text) || string.IsNullOrEmpty(textBoxAstigmatism.Text) || - string.IsNullOrEmpty(textBoxDioptericity.Text) || string.IsNullOrEmpty(textBoxOriginCountry.Text)) - { - throw new Exception("Имеются незаполненные данные"); - } - - if (_accessoriesID.HasValue) - { - _lensRepositories.UpdateLens(CreateLens(_accessoriesID.Value)); - } - else - { - _lensRepositories.CreateLens(CreateLens(0)); - } - } - catch (System.Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при получении сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - Close(); - } - - private void ButtonCancel_Click(object sender, EventArgs e) - { - Close(); - } - - private Lens CreateLens(int id) - { - return Lens.CreateLens(id, textBoxMaterial.Text, textBoxAstigmatism.Text, textBoxDioptericity.Text, textBoxOriginCountry.Text, (double)numericUpDownTimeProduction.Value); - } - } -} diff --git a/ProjectOptika/Scripts/Forms/FormOptika.Designer.cs b/ProjectOptika/Scripts/Forms/FormOptika.Designer.cs index bee1e97..b1083f1 100644 --- a/ProjectOptika/Scripts/Forms/FormOptika.Designer.cs +++ b/ProjectOptika/Scripts/Forms/FormOptika.Designer.cs @@ -31,8 +31,8 @@ menuStrip = new MenuStrip(); справочникиToolStripMenuItem = new ToolStripMenuItem(); accessoriesToolStripMenuItem = new ToolStripMenuItem(); - orderToolStripMenuItem = new ToolStripMenuItem(); lensToolStripMenuItem = new ToolStripMenuItem(); + сотрудникToolStripMenuItem = new ToolStripMenuItem(); оперToolStripMenuItem = new ToolStripMenuItem(); itemOrderToolStripMenuItem = new ToolStripMenuItem(); bundleOrderToolStripMenuItem = new ToolStripMenuItem(); @@ -52,7 +52,7 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { accessoriesToolStripMenuItem, orderToolStripMenuItem, lensToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { accessoriesToolStripMenuItem, lensToolStripMenuItem, сотрудникToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(117, 24); справочникиToolStripMenuItem.Text = "Справочники"; @@ -64,20 +64,20 @@ accessoriesToolStripMenuItem.Text = "Аксессуар"; accessoriesToolStripMenuItem.Click += AccessoriesToolStripMenuItem_Click; // - // orderToolStripMenuItem - // - orderToolStripMenuItem.Name = "orderToolStripMenuItem"; - orderToolStripMenuItem.Size = new Size(224, 26); - orderToolStripMenuItem.Text = "Заказ"; - orderToolStripMenuItem.Click += OrderToolStripMenuItem_Click; - // // lensToolStripMenuItem // lensToolStripMenuItem.Name = "lensToolStripMenuItem"; lensToolStripMenuItem.Size = new Size(224, 26); - lensToolStripMenuItem.Text = "Линзы"; + lensToolStripMenuItem.Text = "Характеристики"; lensToolStripMenuItem.Click += LensToolStripMenuItem_Click; // + // сотрудникToolStripMenuItem + // + сотрудникToolStripMenuItem.Name = "сотрудникToolStripMenuItem"; + сотрудникToolStripMenuItem.Size = new Size(224, 26); + сотрудникToolStripMenuItem.Text = "Сотрудник"; + сотрудникToolStripMenuItem.Click += EmplyeeToolStripMenuItem_Click; + // // оперToolStripMenuItem // оперToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { itemOrderToolStripMenuItem, bundleOrderToolStripMenuItem }); @@ -128,8 +128,8 @@ private ToolStripMenuItem отчетToolStripMenuItem; private ToolStripMenuItem accessoriesToolStripMenuItem; private ToolStripMenuItem itemOrderToolStripMenuItem; - private ToolStripMenuItem orderToolStripMenuItem; private ToolStripMenuItem lensToolStripMenuItem; private ToolStripMenuItem bundleOrderToolStripMenuItem; + private ToolStripMenuItem сотрудникToolStripMenuItem; } } diff --git a/ProjectOptika/Scripts/Forms/FormOptika.cs b/ProjectOptika/Scripts/Forms/FormOptika.cs index d599e3a..0ddfe24 100644 --- a/ProjectOptika/Scripts/Forms/FormOptika.cs +++ b/ProjectOptika/Scripts/Forms/FormOptika.cs @@ -11,7 +11,7 @@ namespace ProjectOptika { InitializeComponent(); - _container = container ?? + _container = container ?? throw new ArgumentNullException(nameof(container)); } @@ -27,23 +27,11 @@ namespace ProjectOptika } } - private void OrderToolStripMenuItem_Click(object sender, EventArgs e) - { - try - { - _container.Resolve().ShowDialog(); - } - catch (System.Exception ex) - { - MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - } - private void LensToolStripMenuItem_Click(object sender, EventArgs e) { try { - _container.Resolve().ShowDialog(); + _container.Resolve().ShowDialog(); } catch (System.Exception ex) { @@ -55,7 +43,7 @@ namespace ProjectOptika { try { - _container.Resolve().ShowDialog(); + _container.Resolve().ShowDialog(); } catch (System.Exception ex) { @@ -67,7 +55,19 @@ namespace ProjectOptika { try { - _container.Resolve().ShowDialog(); + _container.Resolve().ShowDialog(); + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void EmplyeeToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); } catch (System.Exception ex) { diff --git a/ProjectOptika/Scripts/Forms/FormOrder.Designer.cs b/ProjectOptika/Scripts/Forms/FormOrder.Designer.cs deleted file mode 100644 index 50b4348..0000000 --- a/ProjectOptika/Scripts/Forms/FormOrder.Designer.cs +++ /dev/null @@ -1,97 +0,0 @@ -namespace ProjectOptika.Scripts.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() - { - labelTotalCost = new Label(); - numericUpDownTotalCost = new NumericUpDown(); - buttonCancel = new Button(); - buttonSave = new Button(); - ((System.ComponentModel.ISupportInitialize)numericUpDownTotalCost).BeginInit(); - SuspendLayout(); - // - // labelTotalCost - // - labelTotalCost.AutoSize = true; - labelTotalCost.Location = new Point(11, 12); - labelTotalCost.Name = "labelTotalCost"; - labelTotalCost.Size = new Size(133, 20); - labelTotalCost.TabIndex = 1; - labelTotalCost.Text = "Общая стоимость"; - // - // numericUpDownTotalCost - // - numericUpDownTotalCost.Location = new Point(150, 12); - numericUpDownTotalCost.Name = "numericUpDownTotalCost"; - numericUpDownTotalCost.Size = new Size(180, 27); - numericUpDownTotalCost.TabIndex = 2; - // - // buttonCancel - // - buttonCancel.Location = new Point(150, 70); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(94, 29); - buttonCancel.TabIndex = 13; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - // - // buttonSave - // - buttonSave.Location = new Point(11, 70); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(94, 29); - buttonSave.TabIndex = 12; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - // - // FormOrder - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(342, 111); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(numericUpDownTotalCost); - Controls.Add(labelTotalCost); - Name = "FormOrder"; - Text = "Заказ"; - ((System.ComponentModel.ISupportInitialize)numericUpDownTotalCost).EndInit(); - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private Label labelOrderDate; - private Label labelTotalCost; - private NumericUpDown numericUpDownTotalCost; - private DateTimePicker dateTimePicker1; - private Button buttonCancel; - private Button buttonSave; - } -} \ No newline at end of file diff --git a/ProjectOptika/Scripts/Forms/FormOrder.cs b/ProjectOptika/Scripts/Forms/FormOrder.cs deleted file mode 100644 index 04bfa0c..0000000 --- a/ProjectOptika/Scripts/Forms/FormOrder.cs +++ /dev/null @@ -1,70 +0,0 @@ -using ProjectOptika.Scripts.Entities; -using ProjectOptika.Scripts.Repositories; - -namespace ProjectOptika.Scripts.Forms -{ - public partial class FormOrder : Form - { - private readonly IOrderRepositories _orderRepositories; - - private int? _orderID; - - public int ID - { - set - { - try - { - var accessory = _orderRepositories.GetOrderByID(value); - - if (accessory == null) throw new InvalidDataException(nameof(accessory)); - - _orderID = accessory.ID; - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); - return; - } - } - } - - public FormOrder(IOrderRepositories orderRepositories) - { - InitializeComponent(); - - _orderRepositories = orderRepositories - ?? throw new ArgumentNullException(nameof(orderRepositories)); - } - - private void ButtonSave_Click(object sender, EventArgs e) - { - try - { - if (_orderID.HasValue) - { - _orderRepositories.UpdateOrder(CreateOrder(_orderID.Value)); - } - else - { - _orderRepositories.CreateOrder(CreateOrder(0)); - } - } - catch (System.Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка при получении сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); - } - Close(); - } - - private void ButtonCancel_Click(object sender, EventArgs e) - { - Close(); - } - - private Order CreateOrder(int id) - { - return Order.CreateOrder(id, (double)numericUpDownTotalCost.Value); - } - } -} diff --git a/ProjectOptika/Scripts/Forms/FormOrder.resx b/ProjectOptika/Scripts/Forms/FormOrder.resx deleted file mode 100644 index af32865..0000000 --- a/ProjectOptika/Scripts/Forms/FormOrder.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/ProjectOptika/Scripts/Forms/FormOrders.resx b/ProjectOptika/Scripts/Forms/FormOrders.resx deleted file mode 100644 index af32865..0000000 --- a/ProjectOptika/Scripts/Forms/FormOrders.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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/ProjectOptika/Scripts/Forms/FormLen.Designer.cs b/ProjectOptika/Scripts/Forms/FormSpecification.Designer.cs similarity index 97% rename from ProjectOptika/Scripts/Forms/FormLen.Designer.cs rename to ProjectOptika/Scripts/Forms/FormSpecification.Designer.cs index f944d38..a022aa5 100644 --- a/ProjectOptika/Scripts/Forms/FormLen.Designer.cs +++ b/ProjectOptika/Scripts/Forms/FormSpecification.Designer.cs @@ -1,6 +1,6 @@ namespace ProjectOptika.Scripts.Forms { - partial class FormLen + partial class FormSpecification { /// /// Required designer variable. @@ -131,6 +131,7 @@ buttonCancel.TabIndex = 11; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; // // buttonSave // @@ -140,8 +141,9 @@ buttonSave.TabIndex = 10; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; // - // FormLen + // FormSpecification // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; @@ -158,7 +160,7 @@ Controls.Add(labelAstigmatism); Controls.Add(textBoxMaterial); Controls.Add(labelMaterial); - Name = "FormLen"; + Name = "FormSpecification"; Text = "Линзы"; ((System.ComponentModel.ISupportInitialize)numericUpDownTimeProduction).EndInit(); ResumeLayout(false); diff --git a/ProjectOptika/Scripts/Forms/FormSpecification.cs b/ProjectOptika/Scripts/Forms/FormSpecification.cs new file mode 100644 index 0000000..e59fb3a --- /dev/null +++ b/ProjectOptika/Scripts/Forms/FormSpecification.cs @@ -0,0 +1,83 @@ +using ProjectOptika.Scripts.Entities; +using ProjectOptika.Scripts.Repositories; + +namespace ProjectOptika.Scripts.Forms +{ + public partial class FormSpecification : Form + { + private readonly ISpecificationsRepositories _specificationsRepositories; + + private int? _specificationsID; + private int? _accessoriesID; + + public int ID + { + set + { + try + { + var specifications = _specificationsRepositories.GetSpecificationsByID(value); + + if (specifications == null) throw new InvalidDataException(nameof(specifications)); + + _specificationsID = specifications.ID; + _accessoriesID = specifications.AccessoriesID; + textBoxMaterial.Text = specifications.Material; + textBoxAstigmatism.Text = specifications.Astigmatism; + textBoxDioptericity.Text = specifications.Dioptericity; + textBoxOriginCountry.Text = specifications.OriginCountry; + numericUpDownTimeProduction.Value = (decimal)specifications.TimeProduction; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormSpecification(ISpecificationsRepositories specifications) + { + InitializeComponent(); + + _specificationsRepositories = specifications + ?? throw new ArgumentNullException(nameof(specifications)); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrEmpty(textBoxMaterial.Text) || string.IsNullOrEmpty(textBoxAstigmatism.Text) || + string.IsNullOrEmpty(textBoxDioptericity.Text) || string.IsNullOrEmpty(textBoxOriginCountry.Text)) + { + throw new Exception("Имеются незаполненные данные"); + } + + if (_specificationsID.HasValue) + { + _specificationsRepositories.UpdateSpecifications(CreateSpecifications(_specificationsID.Value, _accessoriesID.Value)); + } + else + { + _specificationsRepositories.CreateSpecifications(CreateSpecifications(0, 0)); + } + } + catch (System.Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + Close(); + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + Close(); + } + + private Specifications CreateSpecifications(int id, int accessoriesID) + { + return Specifications.CreateSpecifications(id, accessoriesID, textBoxMaterial.Text, textBoxAstigmatism.Text, textBoxDioptericity.Text, textBoxOriginCountry.Text, (double)numericUpDownTimeProduction.Value); + } + } +} diff --git a/ProjectOptika/Scripts/Forms/FormLen.resx b/ProjectOptika/Scripts/Forms/FormSpecification.resx similarity index 100% rename from ProjectOptika/Scripts/Forms/FormLen.resx rename to ProjectOptika/Scripts/Forms/FormSpecification.resx diff --git a/ProjectOptika/Scripts/Forms/FormLens.Designer.cs b/ProjectOptika/Scripts/Forms/FormSpecifications.Designer.cs similarity index 99% rename from ProjectOptika/Scripts/Forms/FormLens.Designer.cs rename to ProjectOptika/Scripts/Forms/FormSpecifications.Designer.cs index 40ff615..ef31d6c 100644 --- a/ProjectOptika/Scripts/Forms/FormLens.Designer.cs +++ b/ProjectOptika/Scripts/Forms/FormSpecifications.Designer.cs @@ -1,6 +1,6 @@ namespace ProjectOptika.Scripts.Forms { - partial class FormLens + partial class FormSpecifications { /// /// Required designer variable. diff --git a/ProjectOptika/Scripts/Forms/FormLens.cs b/ProjectOptika/Scripts/Forms/FormSpecifications.cs similarity index 85% rename from ProjectOptika/Scripts/Forms/FormLens.cs rename to ProjectOptika/Scripts/Forms/FormSpecifications.cs index 9da4c49..084d237 100644 --- a/ProjectOptika/Scripts/Forms/FormLens.cs +++ b/ProjectOptika/Scripts/Forms/FormSpecifications.cs @@ -3,13 +3,13 @@ using Unity; namespace ProjectOptika.Scripts.Forms { - public partial class FormLens : Form + public partial class FormSpecifications : Form { private readonly IUnityContainer _container; - private readonly ILensRepositories _lensRepositories; + private readonly ISpecificationsRepositories _lensRepositories; - public FormLens(IUnityContainer container, ILensRepositories lensRepositories) + public FormSpecifications(IUnityContainer container, ISpecificationsRepositories lensRepositories) { InitializeComponent(); @@ -36,7 +36,7 @@ namespace ProjectOptika.Scripts.Forms { try { - _container.Resolve().ShowDialog(); + _container.Resolve().ShowDialog(); LoadList(); } catch (System.Exception ex) @@ -51,7 +51,7 @@ namespace ProjectOptika.Scripts.Forms try { - var form = _container.Resolve(); + var form = _container.Resolve(); form.ID = findID; form.ShowDialog(); LoadList(); @@ -70,7 +70,7 @@ namespace ProjectOptika.Scripts.Forms try { - _lensRepositories.DeleteLens(findID); + _lensRepositories.DeleteSpecifications(findID); LoadList(); } catch (System.Exception ex) @@ -79,7 +79,7 @@ namespace ProjectOptika.Scripts.Forms } } - private void LoadList() => dataGridView.DataSource = _lensRepositories.GetLens(); + private void LoadList() => dataGridView.DataSource = _lensRepositories.GetSpecifications(); private bool TryGetIdentifierFromSelectedRows(out int id) { diff --git a/ProjectOptika/Scripts/Forms/FormLens.resx b/ProjectOptika/Scripts/Forms/FormSpecifications.resx similarity index 100% rename from ProjectOptika/Scripts/Forms/FormLens.resx rename to ProjectOptika/Scripts/Forms/FormSpecifications.resx diff --git a/ProjectOptika/Scripts/Program.cs b/ProjectOptika/Scripts/Program.cs index 7476a61..debd407 100644 --- a/ProjectOptika/Scripts/Program.cs +++ b/ProjectOptika/Scripts/Program.cs @@ -23,8 +23,8 @@ namespace ProjectOptika.Scripts container.RegisterType(); container.RegisterType(); - container.RegisterType(); - container.RegisterType(); + container.RegisterType(); + container.RegisterType(); container.RegisterType(); return container; diff --git a/ProjectOptika/Scripts/Repositories/IEmployeeRepositories.cs b/ProjectOptika/Scripts/Repositories/IEmployeeRepositories.cs new file mode 100644 index 0000000..c8a5583 --- /dev/null +++ b/ProjectOptika/Scripts/Repositories/IEmployeeRepositories.cs @@ -0,0 +1,17 @@ +using ProjectOptika.Scripts.Entities; + +namespace ProjectOptika.Scripts.Repositories +{ + public interface IEmployeeRepositories + { + IEnumerable GetEmployees(); + + Employee GetEmployeerByID(int id); + + void CreateEmployee(Employee employee); + + void UpdateEmployee(Employee employee); + + void DeleteEmployee(int id); + } +} diff --git a/ProjectOptika/Scripts/Repositories/IItemOrderRepositories.cs b/ProjectOptika/Scripts/Repositories/IItemOrderRepositories.cs deleted file mode 100644 index 25d9a0f..0000000 --- a/ProjectOptika/Scripts/Repositories/IItemOrderRepositories.cs +++ /dev/null @@ -1,17 +0,0 @@ -using ProjectOptika.Scripts.Entities; - -namespace ProjectOptika.Scripts.Repositories -{ - public interface IItemOrderRepositories - { - IEnumerable GetItemOrders(int? accessoriesID = null, int? orderID = null, int? count = null); - - ItemOrder GetItemOrderByID(int id); - - void CreateItemOrder(ItemOrder itemOrder); - - void UpdateItemOrder(ItemOrder itemOrder); - - void DeleteItemOrder(int id); - } -} diff --git a/ProjectOptika/Scripts/Repositories/ILensRepositories.cs b/ProjectOptika/Scripts/Repositories/ILensRepositories.cs deleted file mode 100644 index c9520b5..0000000 --- a/ProjectOptika/Scripts/Repositories/ILensRepositories.cs +++ /dev/null @@ -1,17 +0,0 @@ -using ProjectOptika.Scripts.Entities; - -namespace ProjectOptika.Scripts.Repositories -{ - public interface ILensRepositories - { - IEnumerable GetLens(); - - Lens GetLensByID(int id); - - void CreateLens(Lens order); - - void UpdateLens(Lens order); - - void DeleteLens(int id); - } -} diff --git a/ProjectOptika/Scripts/Repositories/ISpecificationsRepositories.cs b/ProjectOptika/Scripts/Repositories/ISpecificationsRepositories.cs new file mode 100644 index 0000000..3f977d6 --- /dev/null +++ b/ProjectOptika/Scripts/Repositories/ISpecificationsRepositories.cs @@ -0,0 +1,17 @@ +using ProjectOptika.Scripts.Entities; + +namespace ProjectOptika.Scripts.Repositories +{ + public interface ISpecificationsRepositories + { + IEnumerable GetSpecifications(); + + Specifications GetSpecificationsByID(int id); + + void CreateSpecifications(Specifications specifications); + + void UpdateSpecifications(Specifications specifications); + + void DeleteSpecifications(int id); + } +} diff --git a/ProjectOptika/Scripts/Repositories/Implementations/BundleOrderRepositories.cs b/ProjectOptika/Scripts/Repositories/Implementations/BundleOrderRepositories.cs index 44fae6f..9978d38 100644 --- a/ProjectOptika/Scripts/Repositories/Implementations/BundleOrderRepositories.cs +++ b/ProjectOptika/Scripts/Repositories/Implementations/BundleOrderRepositories.cs @@ -19,7 +19,7 @@ namespace ProjectOptika.Scripts.Repositories.Implementations public BundleOrder GetBundleOrderByID(int id) { - return BundleOrder.CreateBundleOrder(0,0,0); + return BundleOrder.CreateBundleOrder(0,0, 0.0); } public void UpdateBundleOrder(BundleOrder bundleOrder) diff --git a/ProjectOptika/Scripts/Repositories/Implementations/EmployeeRepositories.cs b/ProjectOptika/Scripts/Repositories/Implementations/EmployeeRepositories.cs new file mode 100644 index 0000000..7b8d965 --- /dev/null +++ b/ProjectOptika/Scripts/Repositories/Implementations/EmployeeRepositories.cs @@ -0,0 +1,29 @@ +using ProjectOptika.Scripts.Entities; + +namespace ProjectOptika.Scripts.Repositories.Implementations +{ + public class EmployeeRepositories : IEmployeeRepositories + { + public void CreateEmployee(Employee employee) + { + } + + public void DeleteEmployee(int id) + { + } + + public Employee GetEmployeerByID(int id) + { + return Employee.CreateEmployee(0, Entities.Enums.PositionEmployee.None, string.Empty, string.Empty, string.Empty, null); + } + + public IEnumerable GetEmployees() + { + return []; + } + + public void UpdateEmployee(Employee employee) + { + } + } +} diff --git a/ProjectOptika/Scripts/Repositories/Implementations/ItemOrderRepositories.cs b/ProjectOptika/Scripts/Repositories/Implementations/ItemOrderRepositories.cs deleted file mode 100644 index bb6f9b4..0000000 --- a/ProjectOptika/Scripts/Repositories/Implementations/ItemOrderRepositories.cs +++ /dev/null @@ -1,29 +0,0 @@ -using ProjectOptika.Scripts.Entities; - -namespace ProjectOptika.Scripts.Repositories.Implementations -{ - public class ItemOrderRepositories : IItemOrderRepositories - { - public void CreateItemOrder(ItemOrder itemOrder) - { - } - - public ItemOrder GetItemOrderByID(int id) - { - return ItemOrder.CreateItemOrder(0, 0, 0, 0); - } - - public IEnumerable GetItemOrders(int? accessoriesID = null, int? orderID = null, int? count = null) - { - return []; - } - - public void UpdateItemOrder(ItemOrder itemOrder) - { - } - - public void DeleteItemOrder(int id) - { - } - } -} diff --git a/ProjectOptika/Scripts/Repositories/Implementations/LensRepositories.cs b/ProjectOptika/Scripts/Repositories/Implementations/LensRepositories.cs deleted file mode 100644 index 40dc7f0..0000000 --- a/ProjectOptika/Scripts/Repositories/Implementations/LensRepositories.cs +++ /dev/null @@ -1,29 +0,0 @@ -using ProjectOptika.Scripts.Entities; - -namespace ProjectOptika.Scripts.Repositories.Implementations -{ - public class LensRepositories : ILensRepositories - { - public void CreateLens(Lens order) - { - } - - public void DeleteLens(int id) - { - } - - public IEnumerable GetLens() - { - return []; - } - - public Lens GetLensByID(int id) - { - return Lens.CreateLens(0, string.Empty, string.Empty, string.Empty, string.Empty, 0.0); - } - - public void UpdateLens(Lens order) - { - } - } -} diff --git a/ProjectOptika/Scripts/Repositories/Implementations/OrderRepositories.cs b/ProjectOptika/Scripts/Repositories/Implementations/OrderRepositories.cs index b7726ce..df9eadb 100644 --- a/ProjectOptika/Scripts/Repositories/Implementations/OrderRepositories.cs +++ b/ProjectOptika/Scripts/Repositories/Implementations/OrderRepositories.cs @@ -14,7 +14,7 @@ namespace ProjectOptika.Scripts.Repositories.Implementations public Order GetOrderByID(int id) { - return Order.CreateOrder(0, 0); + return Order.CreateOrder(0, 0, 0.0, null); } public IEnumerable GetOrders() diff --git a/ProjectOptika/Scripts/Repositories/Implementations/SpecificationsRepositories.cs b/ProjectOptika/Scripts/Repositories/Implementations/SpecificationsRepositories.cs new file mode 100644 index 0000000..eabfb21 --- /dev/null +++ b/ProjectOptika/Scripts/Repositories/Implementations/SpecificationsRepositories.cs @@ -0,0 +1,29 @@ +using ProjectOptika.Scripts.Entities; + +namespace ProjectOptika.Scripts.Repositories.Implementations +{ + public class SpecificationsRepositories : ISpecificationsRepositories + { + public void CreateSpecifications(Specifications order) + { + } + + public void DeleteSpecifications(int id) + { + } + + public IEnumerable GetSpecifications() + { + return []; + } + + public Specifications GetSpecificationsByID(int id) + { + return Specifications.CreateSpecifications(0, 0, string.Empty, string.Empty, string.Empty, string.Empty, 0.0); + } + + public void UpdateSpecifications(Specifications order) + { + } + } +}