diff --git a/ProjectOpticsStore/ProjectOpticsStore/Entities/Customer.cs b/ProjectOpticsStore/ProjectOpticsStore/Entities/Customer.cs new file mode 100644 index 0000000..b82790a --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Entities/Customer.cs @@ -0,0 +1,16 @@ +namespace ProjectOpticsStore.Entities; + +public class Customer +{ + public int Id { get; private set; } + public string FullName { get; private set; } = string.Empty; + + public static Customer CreateEntity(int id, string fullName) + { + return new Customer + { + Id = id, + FullName = fullName ?? string.Empty + }; + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Entities/Enums/OrderStatusEnum.cs b/ProjectOpticsStore/ProjectOpticsStore/Entities/Enums/OrderStatusEnum.cs new file mode 100644 index 0000000..b1a26c4 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Entities/Enums/OrderStatusEnum.cs @@ -0,0 +1,10 @@ +namespace ProjectOpticsStore.Entities.Enums; + +public enum OrderStatusEnum +{ + None = 0, + Pending = 1, + Completed = 2, + Canceled = 3, + InProgress = 4 +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Entities/Enums/ProductTypeEnum.cs b/ProjectOpticsStore/ProjectOpticsStore/Entities/Enums/ProductTypeEnum.cs new file mode 100644 index 0000000..6db516e --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Entities/Enums/ProductTypeEnum.cs @@ -0,0 +1,13 @@ +namespace ProjectOpticsStore.Entities.Enums; + +[Flags] +public enum ProductTypeEnum +{ + None = 0, + Glasses = 1, + ContactLenses = 2, + Sunglasses = 4, + Frame = 8, + Cases = 16 +} + diff --git a/ProjectOpticsStore/ProjectOpticsStore/Entities/Order.cs b/ProjectOpticsStore/ProjectOpticsStore/Entities/Order.cs new file mode 100644 index 0000000..5d3a545 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Entities/Order.cs @@ -0,0 +1,26 @@ +using ProjectOpticsStore.Entities; +using ProjectOpticsStore.Entities.Enums; + +public class Order +{ + public int Id { get; private set; } + public int CustomerId { get; private set; } + public DateTime DateCreated { get; private set; } + + public OrderStatusEnum Status { get; private set; } = OrderStatusEnum.Pending; + + // Коллекция, описывающая связь "Order_Product" + public IEnumerable OrderProducts { get; private set; } = new List(); + + public static Order CreateOperation(int id, int customerId, IEnumerable orderProducts, OrderStatusEnum status = OrderStatusEnum.Pending) + { + return new Order + { + Id = id, + CustomerId = customerId, + DateCreated = DateTime.Now, + Status = status, + OrderProducts = orderProducts + }; + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Entities/Order_Product.cs b/ProjectOpticsStore/ProjectOpticsStore/Entities/Order_Product.cs new file mode 100644 index 0000000..86393cc --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Entities/Order_Product.cs @@ -0,0 +1,22 @@ +namespace ProjectOpticsStore.Entities; + +public class Order_Product +{ + public int Id { get; private set; } + public int OrderId { get; private set; } + public int ProductId { get; private set; } + public int Quantity { get; private set; } + + // Создание элемента связи + public static Order_Product CreateElement(int id, int orderId, int productId, int quantity) + { + return new Order_Product + { + Id = id, + OrderId = orderId, + ProductId = productId, + Quantity = quantity + }; + } +} + diff --git a/ProjectOpticsStore/ProjectOpticsStore/Entities/Product.cs b/ProjectOpticsStore/ProjectOpticsStore/Entities/Product.cs new file mode 100644 index 0000000..d80ea3b --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Entities/Product.cs @@ -0,0 +1,26 @@ +using ProjectOpticsStore.Entities.Enums; + +public class Product +{ + public int Id { get; private set; } + public ProductTypeEnum Type { get; private set; } + public double Power { get; private set; } + public int Price { get; private set; } + public int Store { get; private set; } + public float Thickness { get; private set; } + public string Disease { get; private set; } = string.Empty; + + public static Product CreateEntity(int id, ProductTypeEnum type, double power, int price, int store, float thickness, string disease) + { + return new Product + { + Id = id, + Type = type, + Power = power, + Price = price, + Store = store, + Thickness = thickness, + Disease = disease ?? string.Empty + }; + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Entities/Store.cs b/ProjectOpticsStore/ProjectOpticsStore/Entities/Store.cs new file mode 100644 index 0000000..cb2ca36 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Entities/Store.cs @@ -0,0 +1,16 @@ +namespace ProjectOpticsStore.Entities; + +public class Store +{ + public int Id { get; private set; } + public string Address { get; private set; } = string.Empty; + + public static Store CreateEntity(int id, string address) + { + return new Store + { + Id = id, + Address = address ?? string.Empty + }; + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Entities/Supply.cs b/ProjectOpticsStore/ProjectOpticsStore/Entities/Supply.cs new file mode 100644 index 0000000..4dfec73 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Entities/Supply.cs @@ -0,0 +1,23 @@ +namespace ProjectOpticsStore.Entities; + +public class Supply +{ + public int Id { get; private set; } + public int StoreId { get; private set; } + public DateTime OperationDate { get; private set; } + public int ProductId { get; private set; } // Связь многие-к-одному с товарами + public int Quantity { get; private set; } // Количество поставленного товара + + public static Supply CreateOperation(int id, int storeId, int productId, int quantity) + { + return new Supply + { + Id = id, + StoreId = storeId, + OperationDate = DateTime.Now, + ProductId = productId, + Quantity = quantity + }; + } +} + diff --git a/ProjectOpticsStore/ProjectOpticsStore/Form1.Designer.cs b/ProjectOpticsStore/ProjectOpticsStore/Form1.Designer.cs deleted file mode 100644 index bddcf42..0000000 --- a/ProjectOpticsStore/ProjectOpticsStore/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ProjectOpticsStore -{ - partial class Form1 - { - /// - /// 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() - { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "Form1"; - } - - #endregion - } -} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Form1.cs b/ProjectOpticsStore/ProjectOpticsStore/Form1.cs deleted file mode 100644 index a85a8c4..0000000 --- a/ProjectOpticsStore/ProjectOpticsStore/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ProjectOpticsStore -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/ProjectOpticsStore/ProjectOpticsStore/FormOpticsStore.Designer.cs b/ProjectOpticsStore/ProjectOpticsStore/FormOpticsStore.Designer.cs new file mode 100644 index 0000000..06fbc1c --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/FormOpticsStore.Designer.cs @@ -0,0 +1,138 @@ +namespace ProjectOpticsStore +{ + partial class FormOpticsStore + { + /// + /// 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() + { + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + товарыToolStripMenuItem = new ToolStripMenuItem(); + магазиныToolStripMenuItem = new ToolStripMenuItem(); + заказчикиToolStripMenuItem = new ToolStripMenuItem(); + операцииToolStripMenuItem = new ToolStripMenuItem(); + поставкаToolStripMenuItem = new ToolStripMenuItem(); + заказатьToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(20, 20); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(800, 28); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { товарыToolStripMenuItem, магазиныToolStripMenuItem, заказчикиToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // товарыToolStripMenuItem + // + товарыToolStripMenuItem.Name = "товарыToolStripMenuItem"; + товарыToolStripMenuItem.Size = new Size(224, 26); + товарыToolStripMenuItem.Text = "Товары"; + товарыToolStripMenuItem.Click += ProductsToolStripMenuItem_Click; + // + // магазиныToolStripMenuItem + // + магазиныToolStripMenuItem.Name = "магазиныToolStripMenuItem"; + магазиныToolStripMenuItem.Size = new Size(224, 26); + магазиныToolStripMenuItem.Text = "Магазины"; + магазиныToolStripMenuItem.Click += StoresToolStripMenuItem_Click; + // + // заказчикиToolStripMenuItem + // + заказчикиToolStripMenuItem.Name = "заказчикиToolStripMenuItem"; + заказчикиToolStripMenuItem.Size = new Size(224, 26); + заказчикиToolStripMenuItem.Text = "Заказчики"; + заказчикиToolStripMenuItem.Click += CustomersToolStripMenuItem_Click; + // + // операцииToolStripMenuItem + // + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { поставкаToolStripMenuItem, заказатьToolStripMenuItem }); + операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; + операцииToolStripMenuItem.Size = new Size(95, 24); + операцииToolStripMenuItem.Text = "Операции"; + // + // поставкаToolStripMenuItem + // + поставкаToolStripMenuItem.Name = "поставкаToolStripMenuItem"; + поставкаToolStripMenuItem.Size = new Size(164, 26); + поставкаToolStripMenuItem.Text = "Поставить"; + поставкаToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; + // + // заказатьToolStripMenuItem + // + заказатьToolStripMenuItem.Name = "заказатьToolStripMenuItem"; + заказатьToolStripMenuItem.Size = new Size(164, 26); + заказатьToolStripMenuItem.Text = "Заказать"; + заказатьToolStripMenuItem.Click += OrderToolStripMenuItem_Click; + // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(73, 24); + отчетыToolStripMenuItem.Text = "Отчеты"; + // + // FormOpticsStore + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + BackgroundImage = Properties.Resources.catwithglasses; + BackgroundImageLayout = ImageLayout.Stretch; + ClientSize = new Size(800, 450); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormOpticsStore"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Салон Оптики"; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem операцииToolStripMenuItem; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem товарыToolStripMenuItem; + private ToolStripMenuItem магазиныToolStripMenuItem; + private ToolStripMenuItem заказчикиToolStripMenuItem; + private ToolStripMenuItem поставкаToolStripMenuItem; + private ToolStripMenuItem заказатьToolStripMenuItem; + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/FormOpticsStore.cs b/ProjectOpticsStore/ProjectOpticsStore/FormOpticsStore.cs new file mode 100644 index 0000000..79e73ef --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/FormOpticsStore.cs @@ -0,0 +1,82 @@ +using ProjectOpticsStore.Forms; +using Unity; + +namespace ProjectOpticsStore; + +public partial class FormOpticsStore : Form +{ + private readonly IUnityContainer _container; + + public FormOpticsStore(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + // + private void ProductsToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void StoresToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void CustomersToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + // + private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void OrderToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ExitToolStripMenuItem_Click(object sender, EventArgs e) + { + Close(); + } +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/FormOpticsStore.resx b/ProjectOpticsStore/ProjectOpticsStore/FormOpticsStore.resx new file mode 100644 index 0000000..b48baf1 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/FormOpticsStore.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + 17, 17 + + \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomer.Designer.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomer.Designer.cs new file mode 100644 index 0000000..e600c0e --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomer.Designer.cs @@ -0,0 +1,97 @@ +namespace ProjectOpticsStore.Forms +{ + partial class FormCustomer + { + /// + /// 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() + { + textBoxFullName = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + labelFullName = new Label(); + SuspendLayout(); + // + // textBoxFullName + // + textBoxFullName.Location = new Point(209, 45); + textBoxFullName.Name = "textBoxFullName"; + textBoxFullName.Size = new Size(295, 27); + textBoxFullName.TabIndex = 0; + // + // buttonSave + // + buttonSave.Location = new Point(28, 240); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(124, 40); + buttonSave.TabIndex = 1; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(209, 240); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(124, 40); + buttonCancel.TabIndex = 2; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // labelFullName + // + labelFullName.AutoSize = true; + labelFullName.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204); + labelFullName.Location = new Point(28, 41); + labelFullName.Name = "labelFullName"; + labelFullName.Size = new Size(153, 28); + labelFullName.TabIndex = 3; + labelFullName.Text = "ФИО заказчика"; + // + // FormCustomer + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(527, 306); + Controls.Add(labelFullName); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxFullName); + Name = "FormCustomer"; + StartPosition = FormStartPosition.CenterParent; + Text = "Заказчик"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxFullName; + private Button buttonSave; + private Button buttonCancel; + private Label labelFullName; + } +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomer.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomer.cs new file mode 100644 index 0000000..5543fac --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomer.cs @@ -0,0 +1,72 @@ +using ProjectOpticsStore.Entities; +using ProjectOpticsStore.Repositories; + +namespace ProjectOpticsStore.Forms; + +public partial class FormCustomer : Form +{ + private readonly ICustomerRepository _customerRepository; + private int? _customerId; + + // Конструктор принимает экземпляр ICustomerRepository + public FormCustomer(ICustomerRepository customerRepository) + { + InitializeComponent(); + _customerRepository = customerRepository ?? throw new ArgumentNullException(nameof(customerRepository)); + } + + public int Id + { + set + { + try + { + var customer = _customerRepository.ReadCustomerById(value); + if (customer == null) + { + throw new InvalidDataException(nameof(customer)); + } + + textBoxFullName.Text = customer.FullName; + _customerId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxFullName.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + + if (_customerId.HasValue) + { + // Если редактируем существующего клиента + _customerRepository.UpdateCustomer(CreateCustomer(_customerId.Value)); + } + else + { + // Если создаем нового клиента + _customerRepository.CreateCustomer(CreateCustomer(0)); + } + + Close(); // Закрываем форму после сохранения + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + // Метод для создания объекта Customer + private Customer CreateCustomer(int id) => Customer.CreateEntity(id, textBoxFullName.Text); +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Form1.resx b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomer.resx similarity index 92% rename from ProjectOpticsStore/ProjectOpticsStore/Form1.resx rename to ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomer.resx index 1af7de1..8b2ff64 100644 --- a/ProjectOpticsStore/ProjectOpticsStore/Form1.resx +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomer.resx @@ -1,17 +1,17 @@  - diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomers.Designer.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomers.Designer.cs new file mode 100644 index 0000000..12090e8 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomers.Designer.cs @@ -0,0 +1,123 @@ +namespace ProjectOpticsStore.Forms +{ + partial class FormCustomers + { + /// + /// 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() + { + panelButtons = new Panel(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridViewData = new DataGridView(); + panelButtons.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + SuspendLayout(); + // + // panelButtons + // + panelButtons.Controls.Add(buttonDel); + panelButtons.Controls.Add(buttonUpd); + panelButtons.Controls.Add(buttonAdd); + panelButtons.Dock = DockStyle.Right; + panelButtons.Location = new Point(650, 0); + panelButtons.Name = "panelButtons"; + panelButtons.Size = new Size(150, 450); + panelButtons.TabIndex = 1; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.Button_Delete; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(20, 323); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(113, 100); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources.Button_Edit; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(20, 174); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(113, 100); + buttonUpd.TabIndex = 1; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Button_Add; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(20, 26); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(113, 100); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = 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.RowHeadersWidth = 51; + dataGridViewData.Size = new Size(650, 450); + dataGridViewData.TabIndex = 2; + // + // FormCustomers + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewData); + Controls.Add(panelButtons); + Name = "FormCustomers"; + StartPosition = FormStartPosition.CenterParent; + Text = "Заказчики"; + Load += FormCustomers_Load; + panelButtons.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + ResumeLayout(false); + } + + #endregion + private Panel panelButtons; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridViewData; + } +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomers.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomers.cs new file mode 100644 index 0000000..fb421c0 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomers.cs @@ -0,0 +1,100 @@ +using ProjectOpticsStore.Repositories; +using Unity; + +namespace ProjectOpticsStore.Forms; + + +public partial class FormCustomers : Form +{ + private readonly IUnityContainer _container; + private readonly ICustomerRepository _customerRepository; + + public FormCustomers(IUnityContainer container, ICustomerRepository customerRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _customerRepository = customerRepository ?? throw new ArgumentNullException(nameof(customerRepository)); + } + + private void FormCustomers_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 ButtonUpd_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 ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _customerRepository.DeleteCustomer(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() + { + dataGridViewData.DataSource = _customerRepository.ReadCustomers(); + } + + 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/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomers.resx b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomers.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormCustomers.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/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrder.Designer.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrder.Designer.cs new file mode 100644 index 0000000..eaf2425 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrder.Designer.cs @@ -0,0 +1,192 @@ +namespace ProjectOpticsStore.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() + { + ButtonSave = new Button(); + ButtonCancel = new Button(); + comboBoxCustomer = new ComboBox(); + label1 = new Label(); + label2 = new Label(); + dateTimePickerOrderDate = new DateTimePicker(); + label3 = new Label(); + comboBoxStatus = new ComboBox(); + dataGridViewProducts = new DataGridView(); + ColumnProduct = new DataGridViewComboBoxColumn(); + ColumnQuantity = new DataGridViewTextBoxColumn(); + groupBox1 = new GroupBox(); + ((System.ComponentModel.ISupportInitialize)dataGridViewProducts).BeginInit(); + groupBox1.SuspendLayout(); + SuspendLayout(); + // + // ButtonSave + // + ButtonSave.Location = new Point(32, 499); + ButtonSave.Name = "ButtonSave"; + ButtonSave.Size = new Size(133, 45); + ButtonSave.TabIndex = 6; + ButtonSave.Text = "Сохранить"; + ButtonSave.UseVisualStyleBackColor = true; + ButtonSave.Click += ButtonSave_Click; + // + // ButtonCancel + // + ButtonCancel.Location = new Point(291, 499); + ButtonCancel.Name = "ButtonCancel"; + ButtonCancel.Size = new Size(133, 45); + ButtonCancel.TabIndex = 7; + ButtonCancel.Text = "Отмена"; + ButtonCancel.UseVisualStyleBackColor = true; + ButtonCancel.Click += ButtonCancel_Click; + // + // comboBoxCustomer + // + comboBoxCustomer.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxCustomer.FormattingEnabled = true; + comboBoxCustomer.Location = new Point(139, 12); + comboBoxCustomer.Name = "comboBoxCustomer"; + comboBoxCustomer.Size = new Size(288, 28); + comboBoxCustomer.TabIndex = 8; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(29, 15); + label1.Name = "label1"; + label1.Size = new Size(71, 20); + label1.TabIndex = 9; + label1.Text = "Заказчик"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(29, 73); + label2.Name = "label2"; + label2.Size = new Size(86, 20); + label2.TabIndex = 10; + label2.Text = "ДатаВремя"; + // + // dateTimePickerOrderDate + // + dateTimePickerOrderDate.Enabled = false; + dateTimePickerOrderDate.Location = new Point(139, 68); + dateTimePickerOrderDate.Name = "dateTimePickerOrderDate"; + dateTimePickerOrderDate.Size = new Size(288, 27); + dateTimePickerOrderDate.TabIndex = 11; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(29, 128); + label3.Name = "label3"; + label3.Size = new Size(52, 20); + label3.TabIndex = 12; + label3.Text = "Статус"; + // + // comboBoxStatus + // + comboBoxStatus.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStatus.FormattingEnabled = true; + comboBoxStatus.Location = new Point(139, 125); + comboBoxStatus.Name = "comboBoxStatus"; + comboBoxStatus.Size = new Size(288, 28); + comboBoxStatus.TabIndex = 13; + // + // dataGridViewProducts + // + dataGridViewProducts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewProducts.Columns.AddRange(new DataGridViewColumn[] { ColumnProduct, ColumnQuantity }); + dataGridViewProducts.Dock = DockStyle.Fill; + dataGridViewProducts.Location = new Point(3, 23); + dataGridViewProducts.Name = "dataGridViewProducts"; + dataGridViewProducts.RowHeadersVisible = false; + dataGridViewProducts.RowHeadersWidth = 51; + dataGridViewProducts.Size = new Size(392, 236); + dataGridViewProducts.TabIndex = 14; + // + // ColumnProduct + // + ColumnProduct.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnProduct.HeaderText = "Товар"; + ColumnProduct.MinimumWidth = 6; + ColumnProduct.Name = "ColumnProduct"; + // + // ColumnQuantity + // + ColumnQuantity.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + ColumnQuantity.HeaderText = "Количество"; + ColumnQuantity.MinimumWidth = 6; + ColumnQuantity.Name = "ColumnQuantity"; + // + // groupBox1 + // + groupBox1.Controls.Add(dataGridViewProducts); + groupBox1.Location = new Point(29, 191); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(398, 262); + groupBox1.TabIndex = 15; + groupBox1.TabStop = false; + groupBox1.Text = "Заказы"; + // + // FormOrder + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(455, 569); + Controls.Add(groupBox1); + Controls.Add(comboBoxStatus); + Controls.Add(label3); + Controls.Add(dateTimePickerOrderDate); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(comboBoxCustomer); + Controls.Add(ButtonCancel); + Controls.Add(ButtonSave); + Name = "FormOrder"; + Text = "Заказать товары"; + ((System.ComponentModel.ISupportInitialize)dataGridViewProducts).EndInit(); + groupBox1.ResumeLayout(false); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Button ButtonSave; + private Button ButtonCancel; + private ComboBox comboBoxCustomer; + private Label label1; + private Label label2; + private DateTimePicker dateTimePickerOrderDate; + private Label label3; + private ComboBox comboBoxStatus; + private DataGridView dataGridViewProducts; + private GroupBox groupBox1; + private DataGridViewComboBoxColumn ColumnProduct; + private DataGridViewTextBoxColumn ColumnQuantity; + } +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrder.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrder.cs new file mode 100644 index 0000000..7a107ad --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrder.cs @@ -0,0 +1,91 @@ +using ProjectOpticsStore.Entities.Enums; +using ProjectOpticsStore.Entities; +using ProjectOpticsStore.Repositories; + +namespace ProjectOpticsStore.Forms; + +public partial class FormOrder : Form +{ + private readonly IOrderRepository _orderRepository; + private readonly ICustomerRepository _customerRepository; + private readonly IProductRepository _productRepository; + + + public FormOrder(IOrderRepository orderRepository, ICustomerRepository customerRepository, IProductRepository productRepository) + { + InitializeComponent(); + _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); + _customerRepository = customerRepository ?? throw new ArgumentNullException(nameof(customerRepository)); + _productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository)); + + // Настройка ComboBox для выбора клиента + comboBoxCustomer.DataSource = _customerRepository.ReadCustomers() + .Select(c => new { c.Id }) + .ToList(); + comboBoxCustomer.DisplayMember = "Id"; + comboBoxCustomer.ValueMember = "Id"; + comboBoxCustomer.DropDownStyle = ComboBoxStyle.DropDownList; + + // Настройка ComboBox для выбора статуса заказа + comboBoxStatus.DataSource = Enum.GetValues(typeof(OrderStatusEnum)); + comboBoxStatus.DropDownStyle = ComboBoxStyle.DropDownList; + + dataGridViewProducts.AllowUserToAddRows = true; + dataGridViewProducts.AllowUserToDeleteRows = true; + + // Настройка DateTimePicker для даты заказа + dateTimePickerOrderDate.Value = DateTime.Now; + dateTimePickerOrderDate.Enabled = false; + } + + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(comboBoxCustomer.Text) || comboBoxStatus.SelectedItem == null || dataGridViewProducts.RowCount < 1) + { + throw new Exception("Имеются незаполненные поля"); + } + + var customerId = (int)comboBoxCustomer.SelectedValue!; + var status = (OrderStatusEnum)comboBoxStatus.SelectedItem!; + var orderProducts = CreateOrderProductsFromDataGrid(); + + var order = Order.CreateOperation(0, customerId, orderProducts, status); + _orderRepository.CreateOrder(order); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + Close(); + } + + private List CreateOrderProductsFromDataGrid() + { + var list = new List(); + + foreach (DataGridViewRow row in dataGridViewProducts.Rows) + { + // Пропускаем строку, если не указаны значения для продукта или количества + if (row.Cells["ColumnProduct"].Value == null || row.Cells["ColumnQuantity"].Value == null) + continue; + + // Получаем значения из ячеек + var productId = Convert.ToInt32(row.Cells["ColumnProduct"].Value); + var quantity = Convert.ToInt32(row.Cells["ColumnQuantity"].Value); + + // Используем метод CreateElement для создания объектов Order_Product + list.Add(Order_Product.CreateElement(0, 0, productId, quantity)); + } + + return list; + } +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrder.resx b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrder.resx new file mode 100644 index 0000000..70d9360 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrder.resx @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrders.Designer.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrders.Designer.cs new file mode 100644 index 0000000..8c8ba74 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrders.Designer.cs @@ -0,0 +1,108 @@ +namespace ProjectOpticsStore.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() + { + panelButtons = new Panel(); + buttonDel = new Button(); + buttonAdd = new Button(); + dataGridViewOrders = new DataGridView(); + panelButtons.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewOrders).BeginInit(); + SuspendLayout(); + // + // panelButtons + // + panelButtons.Controls.Add(buttonDel); + panelButtons.Controls.Add(buttonAdd); + panelButtons.Dock = DockStyle.Right; + panelButtons.Location = new Point(650, 0); + panelButtons.Name = "panelButtons"; + panelButtons.Size = new Size(150, 450); + panelButtons.TabIndex = 2; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.Button_Delete; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(20, 323); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(113, 100); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Button_Add; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(20, 26); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(113, 100); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewOrders + // + dataGridViewOrders.AllowUserToAddRows = false; + dataGridViewOrders.AllowUserToDeleteRows = false; + dataGridViewOrders.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewOrders.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewOrders.Dock = DockStyle.Fill; + dataGridViewOrders.Location = new Point(0, 0); + dataGridViewOrders.MultiSelect = false; + dataGridViewOrders.Name = "dataGridViewOrders"; + dataGridViewOrders.ReadOnly = true; + dataGridViewOrders.RowHeadersVisible = false; + dataGridViewOrders.RowHeadersWidth = 51; + dataGridViewOrders.Size = new Size(650, 450); + dataGridViewOrders.TabIndex = 3; + // + // FormOrders + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewOrders); + Controls.Add(panelButtons); + Name = "FormOrders"; + Text = "Заказать товары"; + Load += FormOrders_Load; + panelButtons.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewOrders).EndInit(); + ResumeLayout(false); + } + + #endregion + private Panel panelButtons; + private Button buttonDel; + private Button buttonAdd; + private DataGridView dataGridViewOrders; + } +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrders.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrders.cs new file mode 100644 index 0000000..5b6f721 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrders.cs @@ -0,0 +1,91 @@ +using ProjectOpticsStore.Repositories; +namespace ProjectOpticsStore.Forms; + +public partial class FormOrders : Form +{ + private readonly IOrderRepository _orderRepository; + private readonly ICustomerRepository _customerRepository; + private readonly IProductRepository _productRepository; + + public FormOrders(IOrderRepository orderRepository, ICustomerRepository customerRepository, IProductRepository productRepository) + { + InitializeComponent(); + _orderRepository = orderRepository ?? throw new ArgumentNullException(nameof(orderRepository)); + _customerRepository = customerRepository ?? throw new ArgumentNullException(nameof(customerRepository)); + _productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository)); + } + // Загрузка списка заказов при загрузке формы + 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 + { + // Передаем все три зависимости в конструктор FormOrder + using (var form = new FormOrder(_orderRepository, _customerRepository, _productRepository)) + { + form.ShowDialog(); + } + LoadList(); // Перезагружаем список после добавления + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + // Кнопка для удаления выбранного заказа + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var orderId)) + { + return; + } + + if (MessageBox.Show("Удалить заказ?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + + try + { + _orderRepository.DeleteOrder(orderId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + // Метод для загрузки списка заказов в DataGridView + private void LoadList() + { + dataGridViewOrders.DataSource = _orderRepository.ReadOrders(); + } + + // Метод для получения идентификатора заказа из выбранной строки в DataGridView + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewOrders.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + id = Convert.ToInt32(dataGridViewOrders.SelectedRows[0].Cells["Id"].Value); + return true; + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrders.resx b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormOrders.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/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/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProduct.Designer.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProduct.Designer.cs new file mode 100644 index 0000000..b920a82 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProduct.Designer.cs @@ -0,0 +1,209 @@ +namespace ProjectOpticsStore.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() + { + buttonSave = new Button(); + buttonCancel = new Button(); + checkedListBoxProductType = new CheckedListBox(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + label5 = new Label(); + label6 = new Label(); + textBoxPower = new TextBox(); + textBoxPrice = new TextBox(); + textBoxThickness = new TextBox(); + textBoxDisease = new TextBox(); + comboBoxStore = new ComboBox(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Location = new Point(32, 493); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(124, 40); + buttonSave.TabIndex = 2; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(201, 493); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(124, 40); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // checkedListBoxProductType + // + checkedListBoxProductType.FormattingEnabled = true; + checkedListBoxProductType.Location = new Point(157, 22); + checkedListBoxProductType.Name = "checkedListBoxProductType"; + checkedListBoxProductType.Size = new Size(254, 114); + checkedListBoxProductType.TabIndex = 4; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(32, 22); + label1.Name = "label1"; + label1.Size = new Size(90, 20); + label1.TabIndex = 5; + label1.Text = "Тип товара:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(32, 171); + label2.Name = "label2"; + label2.Size = new Size(85, 20); + label2.TabIndex = 6; + label2.Text = "Мощность:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(32, 227); + label3.Name = "label3"; + label3.Size = new Size(48, 20); + label3.TabIndex = 7; + label3.Text = "Цена:"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(32, 287); + label4.Name = "label4"; + label4.Size = new Size(97, 20); + label4.TabIndex = 8; + label4.Text = "ID магазина:"; + // + // label5 + // + label5.AutoSize = true; + label5.Location = new Point(32, 352); + label5.Name = "label5"; + label5.Size = new Size(122, 20); + label5.TabIndex = 9; + label5.Text = "Толщина (чево):"; + // + // label6 + // + label6.AutoSize = true; + label6.Location = new Point(32, 406); + label6.Name = "label6"; + label6.Size = new Size(70, 20); + label6.TabIndex = 10; + label6.Text = "Болезнь:"; + // + // textBoxPower + // + textBoxPower.Location = new Point(157, 168); + textBoxPower.Name = "textBoxPower"; + textBoxPower.Size = new Size(254, 27); + textBoxPower.TabIndex = 11; + // + // textBoxPrice + // + textBoxPrice.Location = new Point(157, 224); + textBoxPrice.Name = "textBoxPrice"; + textBoxPrice.Size = new Size(254, 27); + textBoxPrice.TabIndex = 12; + // + // textBoxThickness + // + textBoxThickness.Location = new Point(157, 349); + textBoxThickness.Name = "textBoxThickness"; + textBoxThickness.Size = new Size(254, 27); + textBoxThickness.TabIndex = 14; + // + // textBoxDisease + // + textBoxDisease.Location = new Point(157, 406); + textBoxDisease.Multiline = true; + textBoxDisease.Name = "textBoxDisease"; + textBoxDisease.Size = new Size(254, 67); + textBoxDisease.TabIndex = 15; + // + // comboBoxStore + // + comboBoxStore.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStore.FormattingEnabled = true; + comboBoxStore.Location = new Point(157, 287); + comboBoxStore.Name = "comboBoxStore"; + comboBoxStore.Size = new Size(254, 28); + comboBoxStore.TabIndex = 16; + // + // FormProduct + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(436, 545); + Controls.Add(comboBoxStore); + Controls.Add(textBoxDisease); + Controls.Add(textBoxThickness); + Controls.Add(textBoxPrice); + Controls.Add(textBoxPower); + Controls.Add(label6); + Controls.Add(label5); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(checkedListBoxProductType); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "FormProduct"; + Text = "Так называемые товары"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private CheckedListBox checkedListBoxProductType; + private Label label1; + private Label label2; + private Label label3; + private Label label4; + private Label label5; + private Label label6; + private TextBox textBoxPower; + private TextBox textBoxPrice; + private TextBox textBoxThickness; + private TextBox textBoxDisease; + private ComboBox comboBoxStore; + } +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProduct.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProduct.cs new file mode 100644 index 0000000..3381bda --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProduct.cs @@ -0,0 +1,117 @@ +using ProjectOpticsStore.Entities; +using ProjectOpticsStore.Entities.Enums; +using ProjectOpticsStore.Repositories; +namespace ProjectOpticsStore.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)); + } + + // Заполнение значений CheckedListBox + foreach (ProductTypeEnum elem in Enum.GetValues(typeof(ProductTypeEnum))) + { + if ((elem & product.Type) != 0) + { + checkedListBoxProductType.SetItemChecked( + checkedListBoxProductType.Items.IndexOf(elem), true); + } + } + + // Заполнение текстовых полей + textBoxPower.Text = product.Power.ToString(); + textBoxPrice.Text = product.Price.ToString(); + comboBoxStore.Text = product.Store.ToString(); + textBoxThickness.Text = product.Thickness.ToString("F2"); + textBoxDisease.Text = product.Disease; + + _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)); + + // Заполнение CheckedListBox значениями перечисления + foreach (var elem in Enum.GetValues(typeof(ProductTypeEnum))) + { + checkedListBoxProductType.Items.Add(elem); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + // Проверка на заполненность всех обязательных полей + if (checkedListBoxProductType.CheckedItems.Count == 0 || + string.IsNullOrWhiteSpace(textBoxPower.Text) || + string.IsNullOrWhiteSpace(textBoxPrice.Text) || + string.IsNullOrWhiteSpace(comboBoxStore.Text) || + string.IsNullOrWhiteSpace(textBoxThickness.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) + { + // Сбор значений из CheckedListBox + ProductTypeEnum productType = ProductTypeEnum.None; + foreach (var elem in checkedListBoxProductType.CheckedItems) + { + productType |= (ProductTypeEnum)elem; + } + + // Создание сущности Product + return Product.CreateEntity( + id, + productType, + double.Parse(textBoxPower.Text), + int.Parse(textBoxPrice.Text), + int.Parse(comboBoxStore.Text), + float.Parse(textBoxThickness.Text), + textBoxDisease.Text + ); + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProduct.resx b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProduct.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/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/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProducts.Designer.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProducts.Designer.cs new file mode 100644 index 0000000..80299ff --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProducts.Designer.cs @@ -0,0 +1,122 @@ +namespace ProjectOpticsStore.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() + { + panelButtons = new Panel(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridViewProducts = new DataGridView(); + panelButtons.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewProducts).BeginInit(); + SuspendLayout(); + // + // panelButtons + // + panelButtons.Controls.Add(buttonDel); + panelButtons.Controls.Add(buttonUpd); + panelButtons.Controls.Add(buttonAdd); + panelButtons.Dock = DockStyle.Right; + panelButtons.Location = new Point(650, 0); + panelButtons.Name = "panelButtons"; + panelButtons.Size = new Size(150, 450); + panelButtons.TabIndex = 3; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.Button_Delete; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(20, 323); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(113, 100); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources.Button_Edit; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(20, 174); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(113, 100); + buttonUpd.TabIndex = 1; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Button_Add; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(20, 26); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(113, 100); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewProducts + // + dataGridViewProducts.AllowUserToAddRows = false; + dataGridViewProducts.AllowUserToDeleteRows = false; + dataGridViewProducts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewProducts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewProducts.Dock = DockStyle.Fill; + dataGridViewProducts.Location = new Point(0, 0); + dataGridViewProducts.MultiSelect = false; + dataGridViewProducts.Name = "dataGridViewProducts"; + dataGridViewProducts.ReadOnly = true; + dataGridViewProducts.RowHeadersVisible = false; + dataGridViewProducts.RowHeadersWidth = 51; + dataGridViewProducts.Size = new Size(650, 450); + dataGridViewProducts.TabIndex = 4; + // + // FormProducts + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewProducts); + Controls.Add(panelButtons); + Name = "FormProducts"; + Text = "Работа с товарами"; + Load += FormProducts_Load; + panelButtons.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewProducts).EndInit(); + ResumeLayout(false); + } + + #endregion + private Panel panelButtons; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridViewProducts; + } +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProducts.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProducts.cs new file mode 100644 index 0000000..24461b1 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProducts.cs @@ -0,0 +1,108 @@ +using ProjectOpticsStore.Entities; +using ProjectOpticsStore.Repositories; +using Unity; + +namespace ProjectOpticsStore.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 ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var productId)) + { + return; + } + + try + { + // Открытие формы редактирования существующего товара + var form = _container.Resolve(); + form.Id = productId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var productId)) + { + return; + } + + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + + try + { + // Удаление товара + _productRepository.DeleteProduct(productId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() + { + // Загрузка списка товаров в DataGridView + dataGridViewProducts.DataSource = _productRepository.ReadProducts().ToList(); + } + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewProducts.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + // Получение идентификатора выбранного товара + id = Convert.ToInt32(dataGridViewProducts.SelectedRows[0].Cells["Id"].Value); + return true; + } +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProducts.resx b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormProducts.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/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/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStore.Designer.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStore.Designer.cs new file mode 100644 index 0000000..052a254 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStore.Designer.cs @@ -0,0 +1,96 @@ +namespace ProjectOpticsStore.Forms +{ + partial class FormStore + { + /// + /// 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() + { + textBoxAddress = new TextBox(); + labelFullName = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // textBoxAddress + // + textBoxAddress.Location = new Point(134, 69); + textBoxAddress.Name = "textBoxAddress"; + textBoxAddress.Size = new Size(295, 27); + textBoxAddress.TabIndex = 1; + // + // labelFullName + // + labelFullName.AutoSize = true; + labelFullName.Font = new Font("Segoe UI", 12F, FontStyle.Regular, GraphicsUnit.Point, 204); + labelFullName.Location = new Point(22, 65); + labelFullName.Name = "labelFullName"; + labelFullName.Size = new Size(71, 28); + labelFullName.TabIndex = 4; + labelFullName.Text = "Адрес:"; + // + // buttonSave + // + buttonSave.Location = new Point(40, 278); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(124, 40); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(206, 278); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(124, 40); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormStore + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(469, 341); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelFullName); + Controls.Add(textBoxAddress); + Name = "FormStore"; + Text = "Магазины"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private TextBox textBoxAddress; + private Label labelFullName; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStore.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStore.cs new file mode 100644 index 0000000..fad22a5 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStore.cs @@ -0,0 +1,79 @@ +using ProjectOpticsStore.Entities; +using ProjectOpticsStore.Repositories; + +namespace ProjectOpticsStore.Forms; + +public partial class FormStore : Form +{ + private readonly IStoreRepository _storeRepository; + private int? _storeId; + + public int Id + { + set + { + try + { + // Загрузка данных магазина + var store = _storeRepository.ReadStoreById(value); + if (store == null) + { + throw new InvalidDataException(nameof(store)); + } + + textBoxAddress.Text = store.Address; + _storeId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormStore(IStoreRepository storeRepository) + { + InitializeComponent(); + _storeRepository = storeRepository ?? throw new ArgumentNullException(nameof(storeRepository)); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + // Проверка на заполненность обязательных полей + if (string.IsNullOrWhiteSpace(textBoxAddress.Text)) + { + throw new Exception("Адрес магазина не указан."); + } + + // Сохранение данных + if (_storeId.HasValue) + { + _storeRepository.UpdateStore(CreateStore(_storeId.Value)); + } + else + { + _storeRepository.CreateStore(CreateStore(0)); + } + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + Close(); + } + + private Store CreateStore(int id) + { + // Создание сущности Store + return Store.CreateEntity(id, textBoxAddress.Text); + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStore.resx b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStore.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStore.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/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStores.Designer.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStores.Designer.cs new file mode 100644 index 0000000..b8546b4 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStores.Designer.cs @@ -0,0 +1,122 @@ +namespace ProjectOpticsStore.Forms +{ + partial class FormStores + { + /// + /// 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() + { + panelButtons = new Panel(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridViewStores = new DataGridView(); + panelButtons.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewStores).BeginInit(); + SuspendLayout(); + // + // panelButtons + // + panelButtons.Controls.Add(buttonDel); + panelButtons.Controls.Add(buttonUpd); + panelButtons.Controls.Add(buttonAdd); + panelButtons.Dock = DockStyle.Right; + panelButtons.Location = new Point(650, 0); + panelButtons.Name = "panelButtons"; + panelButtons.Size = new Size(150, 450); + panelButtons.TabIndex = 4; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.Button_Delete; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(20, 323); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(113, 100); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources.Button_Edit; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(20, 174); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(113, 100); + buttonUpd.TabIndex = 1; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Button_Add; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(20, 26); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(113, 100); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewStores + // + dataGridViewStores.AllowUserToAddRows = false; + dataGridViewStores.AllowUserToDeleteRows = false; + dataGridViewStores.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewStores.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewStores.Dock = DockStyle.Fill; + dataGridViewStores.Location = new Point(0, 0); + dataGridViewStores.MultiSelect = false; + dataGridViewStores.Name = "dataGridViewStores"; + dataGridViewStores.ReadOnly = true; + dataGridViewStores.RowHeadersVisible = false; + dataGridViewStores.RowHeadersWidth = 51; + dataGridViewStores.Size = new Size(650, 450); + dataGridViewStores.TabIndex = 5; + // + // FormStores + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewStores); + Controls.Add(panelButtons); + Name = "FormStores"; + Text = "Так сказать магазины"; + Load += FormStores_Load; + panelButtons.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewStores).EndInit(); + ResumeLayout(false); + } + + #endregion + private Panel panelButtons; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridViewStores; + } +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStores.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStores.cs new file mode 100644 index 0000000..9781d27 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStores.cs @@ -0,0 +1,106 @@ +using ProjectOpticsStore.Entities; +using ProjectOpticsStore.Repositories; +using Unity; + +namespace ProjectOpticsStore.Forms; + +public partial class FormStores : Form +{ + private readonly IUnityContainer _container; + private readonly IStoreRepository _storeRepository; + + public FormStores(IUnityContainer container, IStoreRepository storeRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _storeRepository = storeRepository ?? throw new ArgumentNullException(nameof(storeRepository)); + } + + private void FormStores_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 ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var storeId)) + { + return; + } + + try + { + var form = _container.Resolve(); + form.Id = storeId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var storeId)) + { + return; + } + + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + + try + { + _storeRepository.DeleteStore(storeId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() + { + // Загрузка списка магазинов в DataGridView + dataGridViewStores.DataSource = _storeRepository.ReadStores().ToList(); + } + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewStores.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + // Получение идентификатора выбранного магазина + id = Convert.ToInt32(dataGridViewStores.SelectedRows[0].Cells["Id"].Value); + return true; + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStores.resx b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStores.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormStores.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/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupplies.Designer.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupplies.Designer.cs new file mode 100644 index 0000000..2945ac1 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupplies.Designer.cs @@ -0,0 +1,94 @@ +namespace ProjectOpticsStore.Forms +{ + partial class FormSupplies + { + /// + /// 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() + { + panelButtons = new Panel(); + buttonAdd = new Button(); + dataGridViewSupplies = new DataGridView(); + panelButtons.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewSupplies).BeginInit(); + SuspendLayout(); + // + // panelButtons + // + panelButtons.Controls.Add(buttonAdd); + panelButtons.Dock = DockStyle.Right; + panelButtons.Location = new Point(650, 0); + panelButtons.Name = "panelButtons"; + panelButtons.Size = new Size(150, 450); + panelButtons.TabIndex = 5; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Button_Add; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(20, 26); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(113, 100); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewSupplies + // + dataGridViewSupplies.AllowUserToAddRows = false; + dataGridViewSupplies.AllowUserToDeleteRows = false; + dataGridViewSupplies.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewSupplies.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewSupplies.Dock = DockStyle.Fill; + dataGridViewSupplies.Location = new Point(0, 0); + dataGridViewSupplies.MultiSelect = false; + dataGridViewSupplies.Name = "dataGridViewSupplies"; + dataGridViewSupplies.ReadOnly = true; + dataGridViewSupplies.RowHeadersVisible = false; + dataGridViewSupplies.RowHeadersWidth = 51; + dataGridViewSupplies.Size = new Size(650, 450); + dataGridViewSupplies.TabIndex = 6; + // + // FormSupplies + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewSupplies); + Controls.Add(panelButtons); + Name = "FormSupplies"; + Text = "Определенным образом поставка"; + Load += FormSupplies_Load; + panelButtons.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewSupplies).EndInit(); + ResumeLayout(false); + } + + #endregion + private Panel panelButtons; + private Button buttonAdd; + private DataGridView dataGridViewSupplies; + } +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupplies.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupplies.cs new file mode 100644 index 0000000..3701d1d --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupplies.cs @@ -0,0 +1,48 @@ + +using Unity; + +namespace ProjectOpticsStore.Forms; + +public partial class FormSupplies : Form +{ + private readonly IUnityContainer _container; + private readonly ISupplyRepository _supplyRepository; + + public FormSupplies(IUnityContainer container, ISupplyRepository supplyRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _supplyRepository = supplyRepository ?? throw new ArgumentNullException(nameof(supplyRepository)); + } + + private void FormSupplies_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 LoadList() + { + // Загрузка списка поставок в DataGridView + dataGridViewSupplies.DataSource = _supplyRepository.ReadSupplies().ToList(); + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupplies.resx b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupplies.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupplies.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/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupply.Designer.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupply.Designer.cs new file mode 100644 index 0000000..2b25c50 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupply.Designer.cs @@ -0,0 +1,168 @@ +namespace ProjectOpticsStore.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() + { + comboBoxStore = new ComboBox(); + comboBoxProduct = new ComboBox(); + numericUpDownQuantity = new NumericUpDown(); + dateTimePickerOperationDate = new DateTimePicker(); + buttonSave = new Button(); + buttonCancel = new Button(); + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + label4 = new Label(); + ((System.ComponentModel.ISupportInitialize)numericUpDownQuantity).BeginInit(); + SuspendLayout(); + // + // comboBoxStore + // + comboBoxStore.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStore.FormattingEnabled = true; + comboBoxStore.Location = new Point(148, 12); + comboBoxStore.Name = "comboBoxStore"; + comboBoxStore.Size = new Size(288, 28); + comboBoxStore.TabIndex = 9; + // + // comboBoxProduct + // + comboBoxProduct.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxProduct.FormattingEnabled = true; + comboBoxProduct.Location = new Point(148, 85); + comboBoxProduct.Name = "comboBoxProduct"; + comboBoxProduct.Size = new Size(288, 28); + comboBoxProduct.TabIndex = 10; + // + // numericUpDownQuantity + // + numericUpDownQuantity.Location = new Point(148, 157); + numericUpDownQuantity.Name = "numericUpDownQuantity"; + numericUpDownQuantity.Size = new Size(150, 27); + numericUpDownQuantity.TabIndex = 11; + // + // dateTimePickerOperationDate + // + dateTimePickerOperationDate.Enabled = false; + dateTimePickerOperationDate.Location = new Point(148, 233); + dateTimePickerOperationDate.Name = "dateTimePickerOperationDate"; + dateTimePickerOperationDate.Size = new Size(250, 27); + dateTimePickerOperationDate.TabIndex = 12; + // + // buttonSave + // + buttonSave.Location = new Point(44, 371); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(124, 40); + buttonSave.TabIndex = 13; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(204, 371); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(124, 40); + buttonCancel.TabIndex = 14; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(44, 15); + label1.Name = "label1"; + label1.Size = new Size(72, 20); + label1.TabIndex = 15; + label1.Text = "Магазин:"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(44, 85); + label2.Name = "label2"; + label2.Size = new Size(54, 20); + label2.TabIndex = 16; + label2.Text = "Товар:"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(44, 159); + label3.Name = "label3"; + label3.Size = new Size(93, 20); + label3.TabIndex = 17; + label3.Text = "Количество:"; + // + // label4 + // + label4.AutoSize = true; + label4.Location = new Point(44, 238); + label4.Name = "label4"; + label4.Size = new Size(89, 20); + label4.TabIndex = 18; + label4.Text = "ДатаВремя:"; + // + // FormSupply + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(598, 450); + Controls.Add(label4); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(dateTimePickerOperationDate); + Controls.Add(numericUpDownQuantity); + Controls.Add(comboBoxProduct); + Controls.Add(comboBoxStore); + Name = "FormSupply"; + Text = "Поставка"; + ((System.ComponentModel.ISupportInitialize)numericUpDownQuantity).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxStore; + private ComboBox comboBoxProduct; + private NumericUpDown numericUpDownQuantity; + private DateTimePicker dateTimePickerOperationDate; + private Button buttonSave; + private Button buttonCancel; + private Label label1; + private Label label2; + private Label label3; + private Label label4; + } +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupply.cs b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupply.cs new file mode 100644 index 0000000..b479f61 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupply.cs @@ -0,0 +1,67 @@ +using ProjectOpticsStore.Entities; +using ProjectOpticsStore.Repositories; + +namespace ProjectOpticsStore.Forms; + +public partial class FormSupply : Form +{ + private readonly ISupplyRepository _supplyRepository; + private readonly IStoreRepository _storeRepository; + private readonly IProductRepository _productRepository; + + public FormSupply(ISupplyRepository supplyRepository, IStoreRepository storeRepository, IProductRepository productRepository) + { + InitializeComponent(); + _supplyRepository = supplyRepository ?? throw new ArgumentNullException(nameof(supplyRepository)); + _storeRepository = storeRepository ?? throw new ArgumentNullException(nameof(storeRepository)); + _productRepository = productRepository ?? throw new ArgumentNullException(nameof(productRepository)); + + // Инициализация ComboBox для магазинов + comboBoxStore.DataSource = _storeRepository.ReadStores().ToList(); + comboBoxStore.DisplayMember = "Address"; + comboBoxStore.ValueMember = "Id"; + + // Инициализация ComboBox для товаров + comboBoxProduct.DataSource = _productRepository.ReadProducts().ToList(); + comboBoxProduct.DisplayMember = "Name"; + comboBoxProduct.ValueMember = "Id"; + + // Устанавливаем дату как текущую и блокируем редактирование + dateTimePickerOperationDate.Value = DateTime.Now; + dateTimePickerOperationDate.Enabled = false; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + // Проверка на заполненность полей + if (comboBoxStore.SelectedIndex < 0 || comboBoxProduct.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + + // Создание новой поставки + var supply = Supply.CreateOperation( + id: 0, // Новый объект, идентификатор пока 0 + storeId: (int)comboBoxStore.SelectedValue!, + productId: (int)comboBoxProduct.SelectedValue!, + quantity: (int)numericUpDownQuantity.Value + ); + + _supplyRepository.CreateSupply(supply); + + MessageBox.Show("Поставка успешно добавлена", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information); + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + Close(); + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupply.resx b/ProjectOpticsStore/ProjectOpticsStore/Forms/FormSupply.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/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/ProjectOpticsStore/ProjectOpticsStore/Program.cs b/ProjectOpticsStore/ProjectOpticsStore/Program.cs index 16b92ba..d5c6142 100644 --- a/ProjectOpticsStore/ProjectOpticsStore/Program.cs +++ b/ProjectOpticsStore/ProjectOpticsStore/Program.cs @@ -1,9 +1,14 @@ +using ProjectOpticsStore.Repositories; +using ProjectOpticsStore.Repositories.Implementations; +using Unity; +using Unity.Lifetime; + namespace ProjectOpticsStore { internal static class Program { /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] static void Main() @@ -11,7 +16,17 @@ namespace ProjectOpticsStore // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new Form1()); + Application.Run(CreateContainer().Resolve()); + } + private static IUnityContainer CreateContainer() + { + var container = new UnityContainer(); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + return container; } } } \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/ProjectOpticsStore.csproj b/ProjectOpticsStore/ProjectOpticsStore/ProjectOpticsStore.csproj index 663fdb8..e5042c8 100644 --- a/ProjectOpticsStore/ProjectOpticsStore/ProjectOpticsStore.csproj +++ b/ProjectOpticsStore/ProjectOpticsStore/ProjectOpticsStore.csproj @@ -8,4 +8,27 @@ enable + + + + + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Properties/DataSources/Order.datasource b/ProjectOpticsStore/ProjectOpticsStore/Properties/DataSources/Order.datasource new file mode 100644 index 0000000..a3b0189 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Properties/DataSources/Order.datasource @@ -0,0 +1,10 @@ + + + + Order, ProjectOpticsStore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Properties/Resources.Designer.cs b/ProjectOpticsStore/ProjectOpticsStore/Properties/Resources.Designer.cs new file mode 100644 index 0000000..90e0222 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ProjectOpticsStore.Properties { + using System; + + + /// + /// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д. + /// + // Этот класс создан автоматически классом StronglyTypedResourceBuilder + // с помощью такого средства, как ResGen или Visual Studio. + // Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen + // с параметром /str или перестройте свой проект VS. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ProjectOpticsStore.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Перезаписывает свойство CurrentUICulture текущего потока для всех + /// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Button_Add { + get { + object obj = ResourceManager.GetObject("Button_Add", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Button_Delete { + get { + object obj = ResourceManager.GetObject("Button_Delete", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Button_Edit { + get { + object obj = ResourceManager.GetObject("Button_Edit", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap catwithglasses { + get { + object obj = ResourceManager.GetObject("catwithglasses", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Properties/Resources.resx b/ProjectOpticsStore/ProjectOpticsStore/Properties/Resources.resx new file mode 100644 index 0000000..62dec7d --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + + ..\Resources\Button_Edit.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\catwithglasses.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Button_Add.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Button_Delete.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Repositories/ICustomerRepository.cs b/ProjectOpticsStore/ProjectOpticsStore/Repositories/ICustomerRepository.cs new file mode 100644 index 0000000..4818c15 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Repositories/ICustomerRepository.cs @@ -0,0 +1,12 @@ +using ProjectOpticsStore.Entities; + +namespace ProjectOpticsStore.Repositories; + +public interface ICustomerRepository +{ + IEnumerable ReadCustomers(); + Customer ReadCustomerById(int id); + void CreateCustomer(Customer customer); + void UpdateCustomer(Customer customer); + void DeleteCustomer(int id); +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Repositories/IOrderRepository.cs b/ProjectOpticsStore/ProjectOpticsStore/Repositories/IOrderRepository.cs new file mode 100644 index 0000000..0b0da2c --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Repositories/IOrderRepository.cs @@ -0,0 +1,12 @@ +namespace ProjectOpticsStore.Repositories; + +public interface IOrderRepository +{ + IEnumerable ReadOrders( + DateTime? dateFrom = null, + DateTime? dateTo = null, + int? customerId = null + ); + void CreateOrder(Order order); + void DeleteOrder(int id); +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Repositories/IProductRepository.cs b/ProjectOpticsStore/ProjectOpticsStore/Repositories/IProductRepository.cs new file mode 100644 index 0000000..0f99d1a --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Repositories/IProductRepository.cs @@ -0,0 +1,10 @@ +namespace ProjectOpticsStore.Repositories; + +public interface IProductRepository +{ + IEnumerable ReadProducts(); + Product ReadProductById(int id); + void CreateProduct(Product product); + void UpdateProduct(Product product); + void DeleteProduct(int id); +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Repositories/IStoreRepository.cs b/ProjectOpticsStore/ProjectOpticsStore/Repositories/IStoreRepository.cs new file mode 100644 index 0000000..c3c6d1d --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Repositories/IStoreRepository.cs @@ -0,0 +1,12 @@ +using ProjectOpticsStore.Entities; + +namespace ProjectOpticsStore.Repositories; + +public interface IStoreRepository +{ + IEnumerable ReadStores(); + Store ReadStoreById(int id); + void CreateStore(Store store); + void UpdateStore(Store store); + void DeleteStore(int id); +} \ No newline at end of file diff --git a/ProjectOpticsStore/ProjectOpticsStore/Repositories/ISupplyRepository.cs b/ProjectOpticsStore/ProjectOpticsStore/Repositories/ISupplyRepository.cs new file mode 100644 index 0000000..16be7fa --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Repositories/ISupplyRepository.cs @@ -0,0 +1,13 @@ +using ProjectOpticsStore.Entities; + +public interface ISupplyRepository +{ + IEnumerable ReadSupplies( + DateTime? dateFrom = null, + DateTime? dateTo = null, + int? storeId = null, + int? productId = null + ); + + void CreateSupply(Supply supply); +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/CustomerRepository.cs b/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/CustomerRepository.cs new file mode 100644 index 0000000..f70a461 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/CustomerRepository.cs @@ -0,0 +1,28 @@ +using ProjectOpticsStore.Entities; + +namespace ProjectOpticsStore.Repositories.Implementations; + +internal class CustomerRepository : ICustomerRepository +{ + public void CreateCustomer(Customer customer) + { + } + + public void DeleteCustomer(int id) + { + } + + public Customer ReadCustomerById(int id) + { + return Customer.CreateEntity(0, string.Empty); + } + + public IEnumerable ReadCustomers() + { + return []; + } + + public void UpdateCustomer(Customer customer) + { + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/OrderRepository.cs b/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/OrderRepository.cs new file mode 100644 index 0000000..be3008c --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/OrderRepository.cs @@ -0,0 +1,17 @@ +namespace ProjectOpticsStore.Repositories.Implementations; + +internal class OrderRepository : IOrderRepository +{ + public void CreateOrder(Order order) + { + } + + public void DeleteOrder(int id) + { + } + + public IEnumerable ReadOrders(DateTime? dateFrom = null, DateTime? dateTo = null, int? customerId = null) + { + return []; + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/ProductRepository.cs b/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/ProductRepository.cs new file mode 100644 index 0000000..2c312cd --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/ProductRepository.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectOpticsStore.Entities.Enums; + +namespace ProjectOpticsStore.Repositories.Implementations; + +internal class ProductRepository : IProductRepository +{ + public void CreateProduct(Product product) + { + } + + public void DeleteProduct(int id) + { + } + + public Product ReadProductById(int id) + { + return Product.CreateEntity(0, ProductTypeEnum.None, 0, 0, 0, 0, string.Empty); + } + + public IEnumerable ReadProducts() + { + return []; + } + + public void UpdateProduct(Product product) + { + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/StoreRepository.cs b/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/StoreRepository.cs new file mode 100644 index 0000000..f22c8a9 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/StoreRepository.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectOpticsStore.Entities; +using ProjectOpticsStore.Entities.Enums; +namespace ProjectOpticsStore.Repositories.Implementations; + +internal class StoreRepository : IStoreRepository +{ + public void CreateStore(Store store) + { + } + + public void DeleteStore(int id) + { + } + + public Store ReadStoreById(int id) + { + return Store.CreateEntity(0, string.Empty); + } + + public IEnumerable ReadStores() + { + return []; + } + + public void UpdateStore(Store store) + { + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/SupplyRepository.cs b/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/SupplyRepository.cs new file mode 100644 index 0000000..536ed71 --- /dev/null +++ b/ProjectOpticsStore/ProjectOpticsStore/Repositories/Implementations/SupplyRepository.cs @@ -0,0 +1,15 @@ +using ProjectOpticsStore.Entities; + +namespace ProjectOpticsStore.Repositories.Implementations; + +internal class SupplyRepository : ISupplyRepository +{ + public void CreateSupply(Supply supply) + { + } + + public IEnumerable ReadSupplies(DateTime? dateFrom = null, DateTime? dateTo = null, int? storeId = null, int? productId = null) + { + return []; + } +} diff --git a/ProjectOpticsStore/ProjectOpticsStore/Resources/Button_Add.png b/ProjectOpticsStore/ProjectOpticsStore/Resources/Button_Add.png new file mode 100644 index 0000000..0015091 Binary files /dev/null and b/ProjectOpticsStore/ProjectOpticsStore/Resources/Button_Add.png differ diff --git a/ProjectOpticsStore/ProjectOpticsStore/Resources/Button_Delete.png b/ProjectOpticsStore/ProjectOpticsStore/Resources/Button_Delete.png new file mode 100644 index 0000000..156cc9a Binary files /dev/null and b/ProjectOpticsStore/ProjectOpticsStore/Resources/Button_Delete.png differ diff --git a/ProjectOpticsStore/ProjectOpticsStore/Resources/Button_Edit.png b/ProjectOpticsStore/ProjectOpticsStore/Resources/Button_Edit.png new file mode 100644 index 0000000..016782f Binary files /dev/null and b/ProjectOpticsStore/ProjectOpticsStore/Resources/Button_Edit.png differ diff --git a/ProjectOpticsStore/ProjectOpticsStore/Resources/catwithglasses.jpg b/ProjectOpticsStore/ProjectOpticsStore/Resources/catwithglasses.jpg new file mode 100644 index 0000000..e578c7d Binary files /dev/null and b/ProjectOpticsStore/ProjectOpticsStore/Resources/catwithglasses.jpg differ