diff --git a/FurnitureCompany/FurnitureCompany/Entities/Client.cs b/FurnitureCompany/FurnitureCompany/Entities/Client.cs new file mode 100644 index 0000000..cd724c5 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Entities/Client.cs @@ -0,0 +1,32 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Entities; + +public class Client +{ + public int Id { get; private set; } + + public string Name { get; private set; } = string.Empty; + + public string Address { get; private set; } = string.Empty; + + public int Age { get; private set; } + + public double Earnings { get; private set; } + + public static Client CreateEntity(int id, string name, string address, int age, double earnings) + { + return new Client + { + Id = id, + Name = name ?? string.Empty, + Address = address ?? string.Empty, + Age = age, + Earnings = earnings + }; + } +} diff --git a/FurnitureCompany/FurnitureCompany/Entities/Delivery.cs b/FurnitureCompany/FurnitureCompany/Entities/Delivery.cs new file mode 100644 index 0000000..9608fb5 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Entities/Delivery.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Entities; + +public class Delivery +{ + public int Id { get; private set; } + + public int WorkerId { get; private set; } + + public DateTime DateDelivery { get; private set; } + + public IEnumerable DeliveryProducts { get; private set; } = []; + + public static Delivery CreateOperation(int id, int workerId, IEnumerable deliveryProducts) + { + return new Delivery + { + Id = id, + WorkerId = workerId, + DateDelivery = DateTime.Now, + DeliveryProducts = deliveryProducts + }; + } +} diff --git a/FurnitureCompany/FurnitureCompany/Entities/DeliveryProduct.cs b/FurnitureCompany/FurnitureCompany/Entities/DeliveryProduct.cs new file mode 100644 index 0000000..eb07acf --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Entities/DeliveryProduct.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Entities; + +public class DeliveryProduct +{ + public int Id { get; private set; } + + public int ProductId { get; private set; } + + public int DeliveryId { get; private set; } + + public int Count { get; private set; } + + public static DeliveryProduct CreateElement(int id, int productId, int deliveryId, int count) + { + return new DeliveryProduct + { + Id = id, + ProductId = productId, + DeliveryId = deliveryId, + Count = count + }; + } +} diff --git a/FurnitureCompany/FurnitureCompany/Entities/Enums/Material.cs b/FurnitureCompany/FurnitureCompany/Entities/Enums/Material.cs new file mode 100644 index 0000000..87703c6 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Entities/Enums/Material.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Entities.Enums; + +[Flags] +public enum Material +{ + None = 0, + + Wood = 1, + + Stone = 2, + + Glass = 4, + + Metal = 8 +} diff --git a/FurnitureCompany/FurnitureCompany/Entities/Enums/WorkerPost.cs b/FurnitureCompany/FurnitureCompany/Entities/Enums/WorkerPost.cs new file mode 100644 index 0000000..e183877 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Entities/Enums/WorkerPost.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Entities.Enums; + +public enum WorkerPost +{ + None = 0, + + Beginner = 1, + + Advanced = 2, + + Professional = 3 +} diff --git a/FurnitureCompany/FurnitureCompany/Entities/Invoice.cs b/FurnitureCompany/FurnitureCompany/Entities/Invoice.cs new file mode 100644 index 0000000..a5cf261 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Entities/Invoice.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Entities; + +public class Invoice +{ + public int Id { get; private set; } + + public int WorkerId { get; private set; } + + public int ClientId { get; private set; } + + public int ProductId { get; private set; } + + public DateTime Date { get; private set; } + + public int CountProduct { get; private set; } + + public static Invoice CreateOperation(int id, int workerId, int clientId, int productId, int countProduct) + { + return new Invoice + { + Id = id, + WorkerId = workerId, + ClientId = clientId, + ProductId = productId, + Date = DateTime.Now, + CountProduct = countProduct + }; + } +} diff --git a/FurnitureCompany/FurnitureCompany/Entities/Product.cs b/FurnitureCompany/FurnitureCompany/Entities/Product.cs new file mode 100644 index 0000000..32e8e6c --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Entities/Product.cs @@ -0,0 +1,30 @@ +using FurnitureCompany.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Entities; + +public class Product +{ + public int Id { get; private set; } + + public string Name { get; private set; } = string.Empty; + + public Material Material { get; private set; } + + public double Price { get; private set; } + + public static Product CreateEntity(int id, Material material, string name, double price) + { + return new Product + { + Id = id, + Material = material, + Name = name ?? string.Empty, + Price = price + }; + } +} diff --git a/FurnitureCompany/FurnitureCompany/Entities/Worker.cs b/FurnitureCompany/FurnitureCompany/Entities/Worker.cs new file mode 100644 index 0000000..f1ccc7c --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Entities/Worker.cs @@ -0,0 +1,30 @@ +using FurnitureCompany.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Entities; + +public class Worker +{ + public int Id { get; private set; } + + public string FirstName { get; private set; } = string.Empty; + + public string LastName { get; private set; } = string.Empty; + + public WorkerPost WorkerPost { get; private set; } + + public static Worker CreateEntity(int id, string firstName, string lastName, WorkerPost workerPost) + { + return new Worker + { + Id = id, + FirstName = firstName ?? string.Empty, + LastName = lastName ?? string.Empty, + WorkerPost = workerPost + }; + } +} diff --git a/FurnitureCompany/FurnitureCompany/Form1.Designer.cs b/FurnitureCompany/FurnitureCompany/Form1.Designer.cs deleted file mode 100644 index 58f533a..0000000 --- a/FurnitureCompany/FurnitureCompany/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace FurnitureCompany -{ - 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/FurnitureCompany/FurnitureCompany/Form1.cs b/FurnitureCompany/FurnitureCompany/Form1.cs deleted file mode 100644 index 223c63b..0000000 --- a/FurnitureCompany/FurnitureCompany/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace FurnitureCompany -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} diff --git a/FurnitureCompany/FurnitureCompany/FormFurnitureCompany.Designer.cs b/FurnitureCompany/FurnitureCompany/FormFurnitureCompany.Designer.cs new file mode 100644 index 0000000..226092d --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/FormFurnitureCompany.Designer.cs @@ -0,0 +1,138 @@ +namespace FurnitureCompany +{ + partial class FormFurnitureCompany + { + /// + /// 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(); + WorkersToolStripMenuItem = new ToolStripMenuItem(); + ClientsToolStripMenuItem = new ToolStripMenuItem(); + ProductsToolStripMenuItem = new ToolStripMenuItem(); + операцииToolStripMenuItem = new ToolStripMenuItem(); + InvoicesToolStripMenuItem = new ToolStripMenuItem(); + DeliveryToolStripMenuItem = 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(782, 28); + menuStrip1.TabIndex = 0; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { WorkersToolStripMenuItem, ClientsToolStripMenuItem, ProductsToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(117, 24); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // WorkersToolStripMenuItem + // + WorkersToolStripMenuItem.Name = "WorkersToolStripMenuItem"; + WorkersToolStripMenuItem.Size = new Size(166, 26); + WorkersToolStripMenuItem.Text = "Работники"; + WorkersToolStripMenuItem.Click += WorkersToolStripMenuItem_Click; + // + // ClientsToolStripMenuItem + // + ClientsToolStripMenuItem.Name = "ClientsToolStripMenuItem"; + ClientsToolStripMenuItem.Size = new Size(166, 26); + ClientsToolStripMenuItem.Text = "Клиенты"; + ClientsToolStripMenuItem.Click += ClientsToolStripMenuItem_Click; + // + // ProductsToolStripMenuItem + // + ProductsToolStripMenuItem.Name = "ProductsToolStripMenuItem"; + ProductsToolStripMenuItem.Size = new Size(166, 26); + ProductsToolStripMenuItem.Text = "Изделия"; + ProductsToolStripMenuItem.Click += ProductsToolStripMenuItem_Click; + // + // операцииToolStripMenuItem + // + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { InvoicesToolStripMenuItem, DeliveryToolStripMenuItem }); + операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; + операцииToolStripMenuItem.Size = new Size(95, 24); + операцииToolStripMenuItem.Text = "Операции"; + // + // InvoicesToolStripMenuItem + // + InvoicesToolStripMenuItem.Name = "InvoicesToolStripMenuItem"; + InvoicesToolStripMenuItem.Size = new Size(233, 26); + InvoicesToolStripMenuItem.Text = "Оформление заказа"; + InvoicesToolStripMenuItem.Click += InvoicesToolStripMenuItem_Click; + // + // DeliveryToolStripMenuItem + // + DeliveryToolStripMenuItem.Name = "DeliveryToolStripMenuItem"; + DeliveryToolStripMenuItem.Size = new Size(233, 26); + DeliveryToolStripMenuItem.Text = "Доставка"; + DeliveryToolStripMenuItem.Click += DeliveryToolStripMenuItem_Click; + // + // отчётыToolStripMenuItem + // + отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; + отчётыToolStripMenuItem.Size = new Size(73, 24); + отчётыToolStripMenuItem.Text = "Отчёты"; + // + // FormFurnitureCompany + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + BackgroundImage = Properties.Resources._57435d62a4b6bbc87520597c0e8c4c3a; + BackgroundImageLayout = ImageLayout.Stretch; + ClientSize = new Size(782, 403); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormFurnitureCompany"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Мебельная компания"; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem WorkersToolStripMenuItem; + private ToolStripMenuItem ClientsToolStripMenuItem; + private ToolStripMenuItem ProductsToolStripMenuItem; + private ToolStripMenuItem операцииToolStripMenuItem; + private ToolStripMenuItem отчётыToolStripMenuItem; + private ToolStripMenuItem InvoicesToolStripMenuItem; + private ToolStripMenuItem DeliveryToolStripMenuItem; + } +} diff --git a/FurnitureCompany/FurnitureCompany/FormFurnitureCompany.cs b/FurnitureCompany/FurnitureCompany/FormFurnitureCompany.cs new file mode 100644 index 0000000..4ae0ee5 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/FormFurnitureCompany.cs @@ -0,0 +1,77 @@ +using FurnitureCompany.Forms; +using Unity; + +namespace FurnitureCompany +{ + public partial class FormFurnitureCompany : Form + { + private readonly IUnityContainer _container; + + public FormFurnitureCompany(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + } + + private void WorkersToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch(Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ClientsToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + 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 InvoicesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void DeliveryToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/FurnitureCompany/FurnitureCompany/FormFurnitureCompany.resx b/FurnitureCompany/FurnitureCompany/FormFurnitureCompany.resx new file mode 100644 index 0000000..b48baf1 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/FormFurnitureCompany.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/FurnitureCompany/FurnitureCompany/Forms/FormClient.Designer.cs b/FurnitureCompany/FurnitureCompany/Forms/FormClient.Designer.cs new file mode 100644 index 0000000..0287b57 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormClient.Designer.cs @@ -0,0 +1,172 @@ +namespace FurnitureCompany.Forms +{ + partial class FormClient + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelClientName = new Label(); + labelClientAddress = new Label(); + labelClientAge = new Label(); + textBoxClientName = new TextBox(); + textBoxClientAddress = new TextBox(); + labelClientEarnings = new Label(); + numericUpDownClientEarnings = new NumericUpDown(); + buttonSave = new Button(); + buttonCancel = new Button(); + numericUpDownClientAge = new NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)numericUpDownClientEarnings).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownClientAge).BeginInit(); + SuspendLayout(); + // + // labelClientName + // + labelClientName.AutoSize = true; + labelClientName.Location = new Point(46, 34); + labelClientName.Name = "labelClientName"; + labelClientName.Size = new Size(101, 20); + labelClientName.TabIndex = 0; + labelClientName.Text = "Имя клиента:"; + // + // labelClientAddress + // + labelClientAddress.AutoSize = true; + labelClientAddress.Location = new Point(46, 95); + labelClientAddress.Name = "labelClientAddress"; + labelClientAddress.Size = new Size(147, 20); + labelClientAddress.TabIndex = 1; + labelClientAddress.Text = "Адрес проживания:"; + // + // labelClientAge + // + labelClientAge.AutoSize = true; + labelClientAge.Location = new Point(46, 160); + labelClientAge.Name = "labelClientAge"; + labelClientAge.Size = new Size(67, 20); + labelClientAge.TabIndex = 2; + labelClientAge.Text = "Возраст:"; + // + // textBoxClientName + // + textBoxClientName.Location = new Point(212, 31); + textBoxClientName.Name = "textBoxClientName"; + textBoxClientName.Size = new Size(192, 27); + textBoxClientName.TabIndex = 3; + // + // textBoxClientAddress + // + textBoxClientAddress.Location = new Point(212, 92); + textBoxClientAddress.Name = "textBoxClientAddress"; + textBoxClientAddress.Size = new Size(192, 27); + textBoxClientAddress.TabIndex = 4; + // + // labelClientEarnings + // + labelClientEarnings.AutoSize = true; + labelClientEarnings.Location = new Point(46, 223); + labelClientEarnings.Name = "labelClientEarnings"; + labelClientEarnings.Size = new Size(71, 20); + labelClientEarnings.TabIndex = 6; + labelClientEarnings.Text = "Выручка:"; + // + // numericUpDownClientEarnings + // + numericUpDownClientEarnings.DecimalPlaces = 2; + numericUpDownClientEarnings.Location = new Point(212, 221); + numericUpDownClientEarnings.Maximum = new decimal(new int[] { 10000, 0, 0, 0 }); + numericUpDownClientEarnings.Minimum = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDownClientEarnings.Name = "numericUpDownClientEarnings"; + numericUpDownClientEarnings.Size = new Size(150, 27); + numericUpDownClientEarnings.TabIndex = 7; + numericUpDownClientEarnings.Value = new decimal(new int[] { 1, 0, 0, 131072 }); + // + // buttonSave + // + buttonSave.Location = new Point(99, 300); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(268, 300); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // numericUpDownClientAge + // + numericUpDownClientAge.Location = new Point(212, 158); + numericUpDownClientAge.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); + numericUpDownClientAge.Name = "numericUpDownClientAge"; + numericUpDownClientAge.Size = new Size(150, 27); + numericUpDownClientAge.TabIndex = 10; + numericUpDownClientAge.Value = new decimal(new int[] { 1, 0, 0, 0 }); + // + // FormClient + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(450, 365); + Controls.Add(numericUpDownClientAge); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(numericUpDownClientEarnings); + Controls.Add(labelClientEarnings); + Controls.Add(textBoxClientAddress); + Controls.Add(textBoxClientName); + Controls.Add(labelClientAge); + Controls.Add(labelClientAddress); + Controls.Add(labelClientName); + Name = "FormClient"; + StartPosition = FormStartPosition.CenterParent; + Text = "Клиент"; + ((System.ComponentModel.ISupportInitialize)numericUpDownClientEarnings).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownClientAge).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelClientName; + private Label labelClientAddress; + private Label labelClientAge; + private TextBox textBoxClientName; + private TextBox textBoxClientAddress; + private Label labelClientEarnings; + private NumericUpDown numericUpDownClientEarnings; + private Button buttonSave; + private Button buttonCancel; + private NumericUpDown numericUpDownClientAge; + } +} \ No newline at end of file diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormClient.cs b/FurnitureCompany/FurnitureCompany/Forms/FormClient.cs new file mode 100644 index 0000000..2436a64 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormClient.cs @@ -0,0 +1,88 @@ +using FurnitureCompany.Entities; +using FurnitureCompany.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FurnitureCompany.Forms +{ + public partial class FormClient : Form + { + private readonly IClientRepository _clientRepository; + + private int? _clientId; + + public int Id + { + set + { + try + { + var client = _clientRepository.ReadClientById(value); + if (client == null) + { + throw new InvalidDataException(nameof(client)); + } + + textBoxClientName.Text = client.Name; + textBoxClientAddress.Text = client.Address; + numericUpDownClientAge.Value = client.Age; + numericUpDownClientEarnings.Value = (decimal)client.Earnings; + _clientId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormClient(IClientRepository clientRepository) + { + InitializeComponent(); + _clientRepository = clientRepository ?? + throw new ArgumentNullException(nameof(clientRepository)); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxClientName.Text) || + string.IsNullOrWhiteSpace(textBoxClientAddress.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + + if(_clientId.HasValue) + { + _clientRepository.UpdateClient(CreateClient(_clientId.Value)); + } + else + { + _clientRepository.CreateClient(CreateClient(0)); + } + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Client CreateClient(int id) => Client.CreateEntity(id, + textBoxClientName.Text, textBoxClientAddress.Text, + Convert.ToInt32(numericUpDownClientAge.Value), + Convert.ToDouble(numericUpDownClientEarnings.Value)); + } +} diff --git a/FurnitureCompany/FurnitureCompany/Form1.resx b/FurnitureCompany/FurnitureCompany/Forms/FormClient.resx similarity index 92% rename from FurnitureCompany/FurnitureCompany/Form1.resx rename to FurnitureCompany/FurnitureCompany/Forms/FormClient.resx index 1af7de1..8b2ff64 100644 --- a/FurnitureCompany/FurnitureCompany/Form1.resx +++ b/FurnitureCompany/FurnitureCompany/Forms/FormClient.resx @@ -1,17 +1,17 @@  - diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormClients.Designer.cs b/FurnitureCompany/FurnitureCompany/Forms/FormClients.Designer.cs new file mode 100644 index 0000000..7c16ce2 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormClients.Designer.cs @@ -0,0 +1,127 @@ +namespace FurnitureCompany.Forms +{ + partial class FormClients + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new Panel(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridViewData = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(729, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(153, 403); + panel1.TabIndex = 0; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.minus; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(28, 234); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(94, 88); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources._58d48b2c9540b15afe3fa643; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(28, 116); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(94, 97); + buttonUpd.TabIndex = 1; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.png_clipart_plus_plus; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(28, 12); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 88); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.RowHeadersWidth = 51; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(729, 403); + dataGridViewData.TabIndex = 1; + // + // FormClients + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(882, 403); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormClients"; + StartPosition = FormStartPosition.CenterParent; + Text = "Клиенты"; + Load += FormClients_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridViewData; + } +} \ No newline at end of file diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormClients.cs b/FurnitureCompany/FurnitureCompany/Forms/FormClients.cs new file mode 100644 index 0000000..e724ed4 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormClients.cs @@ -0,0 +1,113 @@ +using FurnitureCompany.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace FurnitureCompany.Forms +{ + public partial class FormClients : Form + { + private readonly IUnityContainer _container; + + private readonly IClientRepository _clientRepository; + + public FormClients(IUnityContainer container, IClientRepository clientRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _clientRepository = clientRepository ?? + throw new ArgumentNullException(nameof(clientRepository)); + } + + private void FormClients_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch(Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void 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 + { + _clientRepository.DeleteClient(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewData.DataSource = _clientRepository.ReadClients(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewData.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["id"].Value); + return true; + } + } +} diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormClients.resx b/FurnitureCompany/FurnitureCompany/Forms/FormClients.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormClients.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormDelivery.Designer.cs b/FurnitureCompany/FurnitureCompany/Forms/FormDelivery.Designer.cs new file mode 100644 index 0000000..10b7fd6 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormDelivery.Designer.cs @@ -0,0 +1,152 @@ +namespace FurnitureCompany.Forms +{ + partial class FormDelivery + { + /// + /// 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() + { + comboBoxWorker = new ComboBox(); + labelWorkerId = new Label(); + groupBoxProducts = new GroupBox(); + dataGridViewProducts = new DataGridView(); + ColumnProduct = new DataGridViewComboBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBoxProducts.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewProducts).BeginInit(); + SuspendLayout(); + // + // comboBoxWorker + // + comboBoxWorker.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxWorker.FormattingEnabled = true; + comboBoxWorker.Location = new Point(150, 38); + comboBoxWorker.Name = "comboBoxWorker"; + comboBoxWorker.Size = new Size(189, 28); + comboBoxWorker.TabIndex = 6; + // + // labelWorkerId + // + labelWorkerId.AutoSize = true; + labelWorkerId.Location = new Point(54, 41); + labelWorkerId.Name = "labelWorkerId"; + labelWorkerId.Size = new Size(77, 20); + labelWorkerId.TabIndex = 5; + labelWorkerId.Text = "Работник:"; + // + // groupBoxProducts + // + groupBoxProducts.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBoxProducts.Controls.Add(dataGridViewProducts); + groupBoxProducts.Location = new Point(27, 92); + groupBoxProducts.Name = "groupBoxProducts"; + groupBoxProducts.Size = new Size(344, 295); + groupBoxProducts.TabIndex = 7; + groupBoxProducts.TabStop = false; + groupBoxProducts.Text = "Изделия"; + // + // dataGridViewProducts + // + dataGridViewProducts.AllowUserToResizeColumns = false; + dataGridViewProducts.AllowUserToResizeRows = false; + dataGridViewProducts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewProducts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewProducts.Columns.AddRange(new DataGridViewColumn[] { ColumnProduct, ColumnCount }); + dataGridViewProducts.Dock = DockStyle.Fill; + dataGridViewProducts.Location = new Point(3, 23); + dataGridViewProducts.MultiSelect = false; + dataGridViewProducts.Name = "dataGridViewProducts"; + dataGridViewProducts.RowHeadersVisible = false; + dataGridViewProducts.RowHeadersWidth = 51; + dataGridViewProducts.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewProducts.Size = new Size(338, 269); + dataGridViewProducts.TabIndex = 0; + // + // ColumnProduct + // + ColumnProduct.HeaderText = "Изделие"; + ColumnProduct.MinimumWidth = 6; + ColumnProduct.Name = "ColumnProduct"; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(69, 410); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(245, 410); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormDelivery + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(405, 466); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxProducts); + Controls.Add(comboBoxWorker); + Controls.Add(labelWorkerId); + Name = "FormDelivery"; + Text = "Доставка"; + groupBoxProducts.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewProducts).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxWorker; + private Label labelWorkerId; + private GroupBox groupBoxProducts; + private DataGridView dataGridViewProducts; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewComboBoxColumn ColumnProduct; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormDelivery.cs b/FurnitureCompany/FurnitureCompany/Forms/FormDelivery.cs new file mode 100644 index 0000000..114dfd2 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormDelivery.cs @@ -0,0 +1,77 @@ +using FurnitureCompany.Entities; +using FurnitureCompany.Repositories; +using FurnitureCompany.Repositories.Implementations; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FurnitureCompany.Forms +{ + public partial class FormDelivery : Form + { + private readonly IDeliveryRepository _deliveryRepository; + + public FormDelivery(IDeliveryRepository deliveryRepository, + IProductRepository productRepository, + IWorkerRepository workerRepository) + { + InitializeComponent(); + _deliveryRepository = deliveryRepository ?? + throw new ArgumentNullException(nameof(deliveryRepository)); + + comboBoxWorker.DataSource = workerRepository.ReadWorkers(); + comboBoxWorker.DisplayMember = "FirstName"; + comboBoxWorker.ValueMember = "Id"; + + ColumnProduct.DataSource = productRepository.ReadProducts(); + ColumnProduct.DisplayMember = "Name"; + ColumnProduct.ValueMember = "Id"; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (dataGridViewProducts.RowCount < 1 || + comboBoxWorker.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + + _deliveryRepository.CreateDelivery(Delivery.CreateOperation(0, + (int)comboBoxWorker.SelectedValue!, CreateListDeliveryProductFromDataGrid())); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private List CreateListDeliveryProductFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridViewProducts.Rows) + { + if (row.Cells["ColumnFeed"].Value == null || row.Cells["ColumnCount"].Value == null) + { + continue; + } + + list.Add(DeliveryProduct.CreateElement(0, Convert.ToInt32(row.Cells["ColumnFeed"].Value), + Convert.ToInt32(row.Cells["ColumnCount"].Value), 0)); + } + + return list; + } + } +} diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormDelivery.resx b/FurnitureCompany/FurnitureCompany/Forms/FormDelivery.resx new file mode 100644 index 0000000..f7cc2cb --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormDelivery.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/FurnitureCompany/FurnitureCompany/Forms/FormDeliverys.Designer.cs b/FurnitureCompany/FurnitureCompany/Forms/FormDeliverys.Designer.cs new file mode 100644 index 0000000..3d27f00 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormDeliverys.Designer.cs @@ -0,0 +1,112 @@ +namespace FurnitureCompany.Forms +{ + partial class FormDeliverys + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new Panel(); + buttonDel = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(590, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(210, 450); + panel1.TabIndex = 0; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.minus; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(64, 210); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(94, 86); + buttonDel.TabIndex = 1; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.png_clipart_plus_plus; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(64, 54); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 86); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.RowHeadersWidth = 51; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(590, 450); + dataGridView.TabIndex = 1; + // + // FormDeliverys + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormDeliverys"; + Text = "Доставка изделий"; + Load += FormDeliverys_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonAdd; + private Button buttonDel; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormDeliverys.cs b/FurnitureCompany/FurnitureCompany/Forms/FormDeliverys.cs new file mode 100644 index 0000000..2a2c46c --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormDeliverys.cs @@ -0,0 +1,95 @@ +using FurnitureCompany.Repositories; +using FurnitureCompany.Repositories.Implementations; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Xml.Linq; +using Unity; + +namespace FurnitureCompany.Forms +{ + public partial class FormDeliverys : Form + { + private readonly IUnityContainer _container; + + private readonly IDeliveryRepository _deliveryRepository; + + public FormDeliverys(IUnityContainer container, IDeliveryRepository deliveryRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _deliveryRepository = deliveryRepository ?? + throw new ArgumentNullException(nameof(deliveryRepository)); + } + + private void FormDeliverys_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 ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + + try + { + _deliveryRepository.DeleteDelivery(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView.DataSource = _deliveryRepository.ReadDeliverys(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["id"].Value); + return true; + } + } +} diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormDeliverys.resx b/FurnitureCompany/FurnitureCompany/Forms/FormDeliverys.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormDeliverys.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/FurnitureCompany/FurnitureCompany/Forms/FormInvoice.Designer.cs b/FurnitureCompany/FurnitureCompany/Forms/FormInvoice.Designer.cs new file mode 100644 index 0000000..9188ee8 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormInvoice.Designer.cs @@ -0,0 +1,173 @@ +namespace FurnitureCompany.Forms +{ + partial class FormInvoice + { + /// + /// 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() + { + labelProductId = new Label(); + labelWorkerId = new Label(); + labelClientId = new Label(); + comboBoxProduct = new ComboBox(); + comboBoxWorker = new ComboBox(); + comboBoxClient = new ComboBox(); + numericUpDownCountProduct = new NumericUpDown(); + labelCountProduct = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCountProduct).BeginInit(); + SuspendLayout(); + // + // labelProductId + // + labelProductId.AutoSize = true; + labelProductId.Location = new Point(47, 48); + labelProductId.Name = "labelProductId"; + labelProductId.Size = new Size(71, 20); + labelProductId.TabIndex = 0; + labelProductId.Text = "Изделие:"; + // + // labelWorkerId + // + labelWorkerId.AutoSize = true; + labelWorkerId.Location = new Point(47, 110); + labelWorkerId.Name = "labelWorkerId"; + labelWorkerId.Size = new Size(77, 20); + labelWorkerId.TabIndex = 1; + labelWorkerId.Text = "Работник:"; + // + // labelClientId + // + labelClientId.AutoSize = true; + labelClientId.Location = new Point(47, 174); + labelClientId.Name = "labelClientId"; + labelClientId.Size = new Size(61, 20); + labelClientId.TabIndex = 2; + labelClientId.Text = "Клиент:"; + // + // comboBoxProduct + // + comboBoxProduct.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxProduct.FormattingEnabled = true; + comboBoxProduct.Location = new Point(219, 45); + comboBoxProduct.Name = "comboBoxProduct"; + comboBoxProduct.Size = new Size(189, 28); + comboBoxProduct.TabIndex = 3; + // + // comboBoxWorker + // + comboBoxWorker.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxWorker.FormattingEnabled = true; + comboBoxWorker.Location = new Point(219, 107); + comboBoxWorker.Name = "comboBoxWorker"; + comboBoxWorker.Size = new Size(189, 28); + comboBoxWorker.TabIndex = 4; + // + // comboBoxClient + // + comboBoxClient.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxClient.FormattingEnabled = true; + comboBoxClient.Location = new Point(219, 171); + comboBoxClient.Name = "comboBoxClient"; + comboBoxClient.Size = new Size(189, 28); + comboBoxClient.TabIndex = 5; + // + // numericUpDownCountProduct + // + numericUpDownCountProduct.Location = new Point(219, 245); + numericUpDownCountProduct.Maximum = new decimal(new int[] { 1000, 0, 0, 0 }); + numericUpDownCountProduct.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); + numericUpDownCountProduct.Name = "numericUpDownCountProduct"; + numericUpDownCountProduct.Size = new Size(189, 27); + numericUpDownCountProduct.TabIndex = 6; + numericUpDownCountProduct.Value = new decimal(new int[] { 1, 0, 0, 0 }); + // + // labelCountProduct + // + labelCountProduct.AutoSize = true; + labelCountProduct.Location = new Point(47, 247); + labelCountProduct.Name = "labelCountProduct"; + labelCountProduct.Size = new Size(155, 20); + labelCountProduct.TabIndex = 7; + labelCountProduct.Text = "Количество изделий:"; + // + // buttonSave + // + buttonSave.Location = new Point(94, 327); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(270, 327); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormInvoice + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(462, 396); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelCountProduct); + Controls.Add(numericUpDownCountProduct); + Controls.Add(comboBoxClient); + Controls.Add(comboBoxWorker); + Controls.Add(comboBoxProduct); + Controls.Add(labelClientId); + Controls.Add(labelWorkerId); + Controls.Add(labelProductId); + Name = "FormInvoice"; + StartPosition = FormStartPosition.CenterParent; + Text = "Заказ"; + ((System.ComponentModel.ISupportInitialize)numericUpDownCountProduct).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelProductId; + private Label labelWorkerId; + private Label labelClientId; + private ComboBox comboBoxProduct; + private ComboBox comboBoxWorker; + private ComboBox comboBoxClient; + private NumericUpDown numericUpDownCountProduct; + private Label labelCountProduct; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormInvoice.cs b/FurnitureCompany/FurnitureCompany/Forms/FormInvoice.cs new file mode 100644 index 0000000..9e49f71 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormInvoice.cs @@ -0,0 +1,68 @@ +using FurnitureCompany.Entities.Enums; +using FurnitureCompany.Entities; +using FurnitureCompany.Repositories; +using FurnitureCompany.Repositories.Implementations; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FurnitureCompany.Forms +{ + public partial class FormInvoice : Form + { + private readonly IInvoiceRepository _invoiceRepository; + + public FormInvoice(IInvoiceRepository invoiceRepository, + IProductRepository productRepository, IWorkerRepository workerRepository, + IClientRepository clientRepository) + { + InitializeComponent(); + _invoiceRepository = invoiceRepository ?? + throw new ArgumentNullException(nameof(invoiceRepository)); + + comboBoxWorker.DataSource = workerRepository.ReadWorkers(); + comboBoxWorker.DisplayMember = "FirstName"; + comboBoxWorker.ValueMember = "Id"; + + comboBoxProduct.DataSource = productRepository.ReadProducts(); + comboBoxProduct.DisplayMember = "Name"; + comboBoxProduct.ValueMember = "Id"; + + comboBoxClient.DataSource = clientRepository.ReadClients(); + comboBoxClient.DisplayMember = "Name"; + comboBoxClient.ValueMember = "Id"; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxProduct.SelectedIndex < 0 || + comboBoxWorker.SelectedIndex < 0 || + comboBoxClient.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + + _invoiceRepository.CreateInvoice(Invoice.CreateOperation(0, + (int)comboBoxProduct.SelectedValue!, (int)comboBoxWorker.SelectedValue!, + (int)comboBoxClient.SelectedValue!, + Convert.ToInt32(numericUpDownCountProduct.Value))); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + } +} diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormInvoice.resx b/FurnitureCompany/FurnitureCompany/Forms/FormInvoice.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormInvoice.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/FurnitureCompany/FurnitureCompany/Forms/FormInvoices.Designer.cs b/FurnitureCompany/FurnitureCompany/Forms/FormInvoices.Designer.cs new file mode 100644 index 0000000..07ea961 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormInvoices.Designer.cs @@ -0,0 +1,99 @@ +namespace FurnitureCompany.Forms +{ + partial class FormInvoices + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new Panel(); + buttonAdd = new Button(); + dataGridViewData = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(637, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(163, 450); + panel1.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.png_clipart_plus_plus; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(38, 48); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 91); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.RowHeadersWidth = 51; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(637, 450); + dataGridViewData.TabIndex = 1; + // + // FormInvoices + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormInvoices"; + StartPosition = FormStartPosition.CenterParent; + Text = "Оформление заказов"; + Load += FormInvoices_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonAdd; + private DataGridView dataGridViewData; + } +} \ No newline at end of file diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormInvoices.cs b/FurnitureCompany/FurnitureCompany/Forms/FormInvoices.cs new file mode 100644 index 0000000..cca3a96 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormInvoices.cs @@ -0,0 +1,59 @@ +using FurnitureCompany.Repositories; +using FurnitureCompany.Repositories.Implementations; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Xml.Linq; +using Unity; + +namespace FurnitureCompany.Forms +{ + public partial class FormInvoices : Form + { + private readonly IUnityContainer _container; + + private readonly IInvoiceRepository _invoiceRepository; + + public FormInvoices(IUnityContainer container, IInvoiceRepository invoiceRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _invoiceRepository = invoiceRepository ?? + throw new ArgumentNullException(nameof(invoiceRepository)); + } + + private void FormInvoices_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() => dataGridViewData.DataSource = _invoiceRepository.ReadInvoices(); + } +} diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormInvoices.resx b/FurnitureCompany/FurnitureCompany/Forms/FormInvoices.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormInvoices.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/FurnitureCompany/FurnitureCompany/Forms/FormProduct.Designer.cs b/FurnitureCompany/FurnitureCompany/Forms/FormProduct.Designer.cs new file mode 100644 index 0000000..0fb4b78 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormProduct.Designer.cs @@ -0,0 +1,147 @@ +namespace FurnitureCompany.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() + { + checkedListBoxMaterial = new CheckedListBox(); + numericUpDownPrice = new NumericUpDown(); + buttonSave = new Button(); + buttonCancel = new Button(); + textBoxProductName = new TextBox(); + labelProductMaterial = new Label(); + labelProductName = new Label(); + labelProductPrice = new Label(); + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit(); + SuspendLayout(); + // + // checkedListBoxMaterial + // + checkedListBoxMaterial.FormattingEnabled = true; + checkedListBoxMaterial.Location = new Point(213, 53); + checkedListBoxMaterial.Name = "checkedListBoxMaterial"; + checkedListBoxMaterial.Size = new Size(224, 114); + checkedListBoxMaterial.TabIndex = 0; + // + // numericUpDownPrice + // + numericUpDownPrice.DecimalPlaces = 2; + numericUpDownPrice.Location = new Point(213, 245); + numericUpDownPrice.Maximum = new decimal(new int[] { 10000, 0, 0, 0 }); + numericUpDownPrice.Minimum = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDownPrice.Name = "numericUpDownPrice"; + numericUpDownPrice.Size = new Size(224, 27); + numericUpDownPrice.TabIndex = 1; + numericUpDownPrice.Value = new decimal(new int[] { 1, 0, 0, 131072 }); + // + // buttonSave + // + buttonSave.Location = new Point(109, 318); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 2; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(269, 318); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 3; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // textBoxProductName + // + textBoxProductName.Location = new Point(213, 199); + textBoxProductName.Name = "textBoxProductName"; + textBoxProductName.Size = new Size(224, 27); + textBoxProductName.TabIndex = 4; + // + // labelProductMaterial + // + labelProductMaterial.AutoSize = true; + labelProductMaterial.Location = new Point(47, 53); + labelProductMaterial.Name = "labelProductMaterial"; + labelProductMaterial.Size = new Size(142, 20); + labelProductMaterial.TabIndex = 5; + labelProductMaterial.Text = "Материал изделия:"; + // + // labelProductName + // + labelProductName.AutoSize = true; + labelProductName.Location = new Point(47, 202); + labelProductName.Name = "labelProductName"; + labelProductName.Size = new Size(80, 20); + labelProductName.TabIndex = 6; + labelProductName.Text = "Название:"; + // + // labelProductPrice + // + labelProductPrice.AutoSize = true; + labelProductPrice.Location = new Point(47, 247); + labelProductPrice.Name = "labelProductPrice"; + labelProductPrice.Size = new Size(48, 20); + labelProductPrice.TabIndex = 7; + labelProductPrice.Text = "Цена:"; + // + // FormProduct + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(486, 391); + Controls.Add(labelProductPrice); + Controls.Add(labelProductName); + Controls.Add(labelProductMaterial); + Controls.Add(textBoxProductName); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(numericUpDownPrice); + Controls.Add(checkedListBoxMaterial); + Name = "FormProduct"; + StartPosition = FormStartPosition.CenterParent; + Text = "Изделие"; + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private CheckedListBox checkedListBoxMaterial; + private NumericUpDown numericUpDownPrice; + private Button buttonSave; + private Button buttonCancel; + private TextBox textBoxProductName; + private Label labelProductMaterial; + private Label labelProductName; + private Label labelProductPrice; + } +} \ No newline at end of file diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormProduct.cs b/FurnitureCompany/FurnitureCompany/Forms/FormProduct.cs new file mode 100644 index 0000000..2d5366b --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormProduct.cs @@ -0,0 +1,108 @@ +using FurnitureCompany.Entities.Enums; +using FurnitureCompany.Entities; +using FurnitureCompany.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using FurnitureCompany.Repositories.Implementations; + +namespace FurnitureCompany.Forms +{ + public partial class FormProduct : Form + { + private readonly IProductRepository _productRepository; + + private int? _productId; + + public int Id + { + set + { + try + { + var product = _productRepository.ReadProductById(value); + if (product == null) + { + throw new InvalidDataException(nameof(product)); + } + + foreach (Material elem in Enum.GetValues(typeof(Material))) + { + if ((elem & product.Material) != 0) + { + checkedListBoxMaterial.SetItemChecked(checkedListBoxMaterial.Items.IndexOf(elem), true); + } + } + + textBoxProductName.Text = product.Name; + numericUpDownPrice.Value = (decimal)product.Price; + _productId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormProduct(IProductRepository productRepository) + { + InitializeComponent(); + _productRepository = productRepository ?? + throw new ArgumentNullException(nameof(productRepository)); + + foreach (var elem in Enum.GetValues(typeof(Material))) + { + checkedListBoxMaterial.Items.Add(elem); + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxProductName.Text) || + checkedListBoxMaterial.CheckedItems.Count == 0) + { + 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) + { + Material material = Material.None; + foreach (var elem in checkedListBoxMaterial.CheckedItems) + { + material |= (Material)elem; + } + + return Product.CreateEntity(id, material, textBoxProductName.Text, + Convert.ToDouble(numericUpDownPrice.Value)); + } + } +} diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormProduct.resx b/FurnitureCompany/FurnitureCompany/Forms/FormProduct.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/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/FurnitureCompany/FurnitureCompany/Forms/FormProducts.Designer.cs b/FurnitureCompany/FurnitureCompany/Forms/FormProducts.Designer.cs new file mode 100644 index 0000000..512ec54 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormProducts.Designer.cs @@ -0,0 +1,127 @@ +namespace FurnitureCompany.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() + { + panel1 = new Panel(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridViewData = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(695, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(187, 403); + panel1.TabIndex = 0; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.minus; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(48, 256); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(94, 90); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources._58d48b2c9540b15afe3fa643; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(48, 144); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(94, 90); + buttonUpd.TabIndex = 1; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.png_clipart_plus_plus; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(48, 29); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(94, 90); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.RowHeadersWidth = 51; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(695, 403); + dataGridViewData.TabIndex = 1; + // + // FormProducts + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(882, 403); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormProducts"; + StartPosition = FormStartPosition.CenterParent; + Text = "Изделия"; + Load += FormProducts_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridViewData; + } +} \ No newline at end of file diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormProducts.cs b/FurnitureCompany/FurnitureCompany/Forms/FormProducts.cs new file mode 100644 index 0000000..e2d99ae --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormProducts.cs @@ -0,0 +1,113 @@ +using FurnitureCompany.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace FurnitureCompany.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 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 + { + _productRepository.DeleteProduct(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewData.DataSource = _productRepository.ReadProducts(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewData.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["id"].Value); + return true; + } + } +} diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormProducts.resx b/FurnitureCompany/FurnitureCompany/Forms/FormProducts.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/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/FurnitureCompany/FurnitureCompany/Forms/FormWorker.Designer.cs b/FurnitureCompany/FurnitureCompany/Forms/FormWorker.Designer.cs new file mode 100644 index 0000000..b9b9835 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormWorker.Designer.cs @@ -0,0 +1,142 @@ +namespace FurnitureCompany.Forms +{ + partial class FormWorker + { + /// + /// 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() + { + comboBoxWorkerPost = new ComboBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + labelWorkerFirstName = new Label(); + labelWorkerLastName = new Label(); + labelWorkerPost = new Label(); + textBoxWorkerLastName = new TextBox(); + textBoxWorkerFirstName = new TextBox(); + SuspendLayout(); + // + // comboBoxWorkerPost + // + comboBoxWorkerPost.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxWorkerPost.FormattingEnabled = true; + comboBoxWorkerPost.Location = new Point(146, 173); + comboBoxWorkerPost.Name = "comboBoxWorkerPost"; + comboBoxWorkerPost.Size = new Size(179, 28); + comboBoxWorkerPost.TabIndex = 0; + // + // buttonSave + // + buttonSave.Location = new Point(60, 261); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 1; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(194, 261); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 2; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // labelWorkerFirstName + // + labelWorkerFirstName.AutoSize = true; + labelWorkerFirstName.Location = new Point(37, 53); + labelWorkerFirstName.Name = "labelWorkerFirstName"; + labelWorkerFirstName.Size = new Size(42, 20); + labelWorkerFirstName.TabIndex = 3; + labelWorkerFirstName.Text = "Имя:"; + // + // labelWorkerLastName + // + labelWorkerLastName.AutoSize = true; + labelWorkerLastName.Location = new Point(37, 113); + labelWorkerLastName.Name = "labelWorkerLastName"; + labelWorkerLastName.Size = new Size(76, 20); + labelWorkerLastName.TabIndex = 4; + labelWorkerLastName.Text = "Фамилия:"; + // + // labelWorkerPost + // + labelWorkerPost.AutoSize = true; + labelWorkerPost.Location = new Point(37, 176); + labelWorkerPost.Name = "labelWorkerPost"; + labelWorkerPost.Size = new Size(89, 20); + labelWorkerPost.TabIndex = 5; + labelWorkerPost.Text = "Должность:"; + // + // textBoxWorkerLastName + // + textBoxWorkerLastName.Location = new Point(146, 110); + textBoxWorkerLastName.Name = "textBoxWorkerLastName"; + textBoxWorkerLastName.Size = new Size(179, 27); + textBoxWorkerLastName.TabIndex = 6; + // + // textBoxWorkerFirstName + // + textBoxWorkerFirstName.Location = new Point(146, 50); + textBoxWorkerFirstName.Name = "textBoxWorkerFirstName"; + textBoxWorkerFirstName.Size = new Size(179, 27); + textBoxWorkerFirstName.TabIndex = 7; + // + // FormWorker + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(369, 340); + Controls.Add(textBoxWorkerFirstName); + Controls.Add(textBoxWorkerLastName); + Controls.Add(labelWorkerPost); + Controls.Add(labelWorkerLastName); + Controls.Add(labelWorkerFirstName); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(comboBoxWorkerPost); + Name = "FormWorker"; + StartPosition = FormStartPosition.CenterParent; + Text = "Работник"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ComboBox comboBoxWorkerPost; + private Button buttonSave; + private Button buttonCancel; + private Label labelWorkerFirstName; + private Label labelWorkerLastName; + private Label labelWorkerPost; + private TextBox textBoxWorkerLastName; + private TextBox textBoxWorkerFirstName; + } +} \ No newline at end of file diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormWorker.cs b/FurnitureCompany/FurnitureCompany/Forms/FormWorker.cs new file mode 100644 index 0000000..86611dd --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormWorker.cs @@ -0,0 +1,91 @@ +using FurnitureCompany.Entities; +using FurnitureCompany.Entities.Enums; +using FurnitureCompany.Repositories; +using FurnitureCompany.Repositories.Implementations; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FurnitureCompany.Forms +{ + public partial class FormWorker : Form + { + private readonly IWorkerRepository _workerRepository; + + private int? _workerId; + + public int Id + { + set + { + try + { + var worker = _workerRepository.ReadWorkerById(value); + if (worker == null) + { + throw new InvalidDataException(nameof(worker)); + } + + textBoxWorkerFirstName.Text = worker.FirstName; + textBoxWorkerLastName.Text = worker.LastName; + comboBoxWorkerPost.SelectedItem = worker.WorkerPost; + _workerId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormWorker(IWorkerRepository workerRepository) + { + InitializeComponent(); + _workerRepository = workerRepository ?? + throw new ArgumentNullException(nameof(workerRepository)); + + comboBoxWorkerPost.DataSource = Enum.GetValues(typeof(WorkerPost)); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxWorkerFirstName.Text) || + string.IsNullOrWhiteSpace(textBoxWorkerLastName.Text) || + comboBoxWorkerPost.SelectedIndex < 1) + { + throw new Exception("Имеются незаполненные поля"); + } + + if (_workerId.HasValue) + { + _workerRepository.UpdateWorker(CreateWorker(_workerId.Value)); + } + else + { + _workerRepository.CreateWorker(CreateWorker(0)); + } + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Worker CreateWorker(int id) => + Worker.CreateEntity(id, textBoxWorkerFirstName.Text, textBoxWorkerLastName.Text, + (WorkerPost)comboBoxWorkerPost.SelectedItem!); + } +} diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormWorker.resx b/FurnitureCompany/FurnitureCompany/Forms/FormWorker.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormWorker.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/FurnitureCompany/FurnitureCompany/Forms/FormWorkers.Designer.cs b/FurnitureCompany/FurnitureCompany/Forms/FormWorkers.Designer.cs new file mode 100644 index 0000000..474a3fa --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormWorkers.Designer.cs @@ -0,0 +1,127 @@ +namespace FurnitureCompany.Forms +{ + partial class FormWorkers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new Panel(); + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridViewData = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(699, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(183, 403); + panel1.TabIndex = 0; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.minus; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(40, 235); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(96, 84); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources._58d48b2c9540b15afe3fa643; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(40, 135); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(96, 84); + buttonUpd.TabIndex = 1; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.png_clipart_plus_plus; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(40, 34); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(96, 84); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.RowHeadersWidth = 51; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(699, 403); + dataGridViewData.TabIndex = 1; + // + // FormWorkers + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(882, 403); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormWorkers"; + StartPosition = FormStartPosition.CenterParent; + Text = "Работники"; + Load += FormWorkers_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridViewData; + } +} \ No newline at end of file diff --git a/FurnitureCompany/FurnitureCompany/Forms/FormWorkers.cs b/FurnitureCompany/FurnitureCompany/Forms/FormWorkers.cs new file mode 100644 index 0000000..03de2cf --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormWorkers.cs @@ -0,0 +1,113 @@ +using FurnitureCompany.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace FurnitureCompany.Forms +{ + public partial class FormWorkers : Form + { + private readonly IUnityContainer _container; + + private readonly IWorkerRepository _workerRepository; + + public FormWorkers(IUnityContainer container, IWorkerRepository workerRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _workerRepository = workerRepository ?? + throw new ArgumentNullException(nameof(workerRepository)); + } + + private void FormWorkers_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 + { + _workerRepository.DeleteWorker(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewData.DataSource = _workerRepository.ReadWorkers(); + + 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/FurnitureCompany/FurnitureCompany/Forms/FormWorkers.resx b/FurnitureCompany/FurnitureCompany/Forms/FormWorkers.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Forms/FormWorkers.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/FurnitureCompany/FurnitureCompany/FurnitureCompany.csproj b/FurnitureCompany/FurnitureCompany/FurnitureCompany.csproj index 663fdb8..accbdf0 100644 --- a/FurnitureCompany/FurnitureCompany/FurnitureCompany.csproj +++ b/FurnitureCompany/FurnitureCompany/FurnitureCompany.csproj @@ -8,4 +8,23 @@ enable + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/FurnitureCompany/FurnitureCompany/Program.cs b/FurnitureCompany/FurnitureCompany/Program.cs index c460ded..8783116 100644 --- a/FurnitureCompany/FurnitureCompany/Program.cs +++ b/FurnitureCompany/FurnitureCompany/Program.cs @@ -1,3 +1,7 @@ +using FurnitureCompany.Repositories; +using FurnitureCompany.Repositories.Implementations; +using Unity; + namespace FurnitureCompany { internal static class Program @@ -11,7 +15,20 @@ namespace FurnitureCompany // 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(); + container.RegisterType(); + container.RegisterType(); + container.RegisterType(); + container.RegisterType(); + + return container; } } } \ No newline at end of file diff --git a/FurnitureCompany/FurnitureCompany/Properties/Resources.Designer.cs b/FurnitureCompany/FurnitureCompany/Properties/Resources.Designer.cs new file mode 100644 index 0000000..97231b7 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace FurnitureCompany.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("FurnitureCompany.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 _57435d62a4b6bbc87520597c0e8c4c3a { + get { + object obj = ResourceManager.GetObject("57435d62a4b6bbc87520597c0e8c4c3a", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap _58d48b2c9540b15afe3fa643 { + get { + object obj = ResourceManager.GetObject("58d48b2c9540b15afe3fa643", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap minus { + get { + object obj = ResourceManager.GetObject("minus", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap png_clipart_plus_plus { + get { + object obj = ResourceManager.GetObject("png-clipart-plus-plus", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/FurnitureCompany/FurnitureCompany/Properties/Resources.resx b/FurnitureCompany/FurnitureCompany/Properties/Resources.resx new file mode 100644 index 0000000..fd39b97 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/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\minus.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\57435d62a4b6bbc87520597c0e8c4c3a.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\png-clipart-plus-plus.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\58d48b2c9540b15afe3fa643.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/FurnitureCompany/FurnitureCompany/Repositories/IClientRepository.cs b/FurnitureCompany/FurnitureCompany/Repositories/IClientRepository.cs new file mode 100644 index 0000000..e680543 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Repositories/IClientRepository.cs @@ -0,0 +1,21 @@ +using FurnitureCompany.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Repositories; + +public interface IClientRepository +{ + IEnumerable ReadClients(); + + Client ReadClientById(int id); + + void CreateClient(Client client); + + void UpdateClient(Client client); + + void DeleteClient(int id); +} diff --git a/FurnitureCompany/FurnitureCompany/Repositories/IDeliveryRepository.cs b/FurnitureCompany/FurnitureCompany/Repositories/IDeliveryRepository.cs new file mode 100644 index 0000000..ecd29f3 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Repositories/IDeliveryRepository.cs @@ -0,0 +1,18 @@ +using FurnitureCompany.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Repositories; + +public interface IDeliveryRepository +{ + IEnumerable ReadDeliverys(DateTime? dateFrom = null, DateTime? dateTo = null, int? productId = null, + int? workerId = null); + + void CreateDelivery(Delivery delivery); + + void DeleteDelivery(int id); +} diff --git a/FurnitureCompany/FurnitureCompany/Repositories/IInvoiceRepository.cs b/FurnitureCompany/FurnitureCompany/Repositories/IInvoiceRepository.cs new file mode 100644 index 0000000..892c882 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Repositories/IInvoiceRepository.cs @@ -0,0 +1,16 @@ +using FurnitureCompany.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Repositories; + +public interface IInvoiceRepository +{ + IEnumerable ReadInvoices(DateTime? dateFrom = null, DateTime? dateTo = null, int? productId = null, + int? workerId = null, int? clientId = null); + + void CreateInvoice(Invoice invoice); +} diff --git a/FurnitureCompany/FurnitureCompany/Repositories/IProductRepository.cs b/FurnitureCompany/FurnitureCompany/Repositories/IProductRepository.cs new file mode 100644 index 0000000..492a68c --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Repositories/IProductRepository.cs @@ -0,0 +1,21 @@ +using FurnitureCompany.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.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/FurnitureCompany/FurnitureCompany/Repositories/IWorkerRepository.cs b/FurnitureCompany/FurnitureCompany/Repositories/IWorkerRepository.cs new file mode 100644 index 0000000..aa8f8ec --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Repositories/IWorkerRepository.cs @@ -0,0 +1,21 @@ +using FurnitureCompany.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Repositories; + +public interface IWorkerRepository +{ + IEnumerable ReadWorkers(); + + Worker ReadWorkerById(int id); + + void CreateWorker(Worker worker); + + void UpdateWorker(Worker worker); + + void DeleteWorker(int id); +} diff --git a/FurnitureCompany/FurnitureCompany/Repositories/Implementations/ClientRepository.cs b/FurnitureCompany/FurnitureCompany/Repositories/Implementations/ClientRepository.cs new file mode 100644 index 0000000..41f436b --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Repositories/Implementations/ClientRepository.cs @@ -0,0 +1,33 @@ +using FurnitureCompany.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Repositories.Implementations; + +public class ClientRepository : IClientRepository +{ + public void CreateClient(Client client) + { + } + + public void DeleteClient(int id) + { + } + + public IEnumerable ReadClients() + { + return[]; + } + + public Client ReadClientById(int id) + { + return Client.CreateEntity(0, string.Empty, string.Empty, 0, 0); + } + + public void UpdateClient(Client client) + { + } +} diff --git a/FurnitureCompany/FurnitureCompany/Repositories/Implementations/DeliveryRepository.cs b/FurnitureCompany/FurnitureCompany/Repositories/Implementations/DeliveryRepository.cs new file mode 100644 index 0000000..11415e0 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Repositories/Implementations/DeliveryRepository.cs @@ -0,0 +1,24 @@ +using FurnitureCompany.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Repositories.Implementations; + +public class DeliveryRepository : IDeliveryRepository +{ + public void CreateDelivery(Delivery delivery) + { + } + + public void DeleteDelivery(int id) + { + } + + public IEnumerable ReadDeliverys(DateTime? dateFrom = null, DateTime? dateTo = null, int? productId = null, int? workerId = null) + { + return []; + } +} diff --git a/FurnitureCompany/FurnitureCompany/Repositories/Implementations/InvoiceRepository.cs b/FurnitureCompany/FurnitureCompany/Repositories/Implementations/InvoiceRepository.cs new file mode 100644 index 0000000..f1e0372 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Repositories/Implementations/InvoiceRepository.cs @@ -0,0 +1,20 @@ +using FurnitureCompany.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Repositories.Implementations; + +public class InvoiceRepository : IInvoiceRepository +{ + public void CreateInvoice(Invoice invoice) + { + } + + public IEnumerable ReadInvoices(DateTime? dateFrom = null, DateTime? dateTo = null, int? productId = null, int? workerId = null, int? clientId = null) + { + return []; + } +} diff --git a/FurnitureCompany/FurnitureCompany/Repositories/Implementations/ProductRepository.cs b/FurnitureCompany/FurnitureCompany/Repositories/Implementations/ProductRepository.cs new file mode 100644 index 0000000..4322cc4 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Repositories/Implementations/ProductRepository.cs @@ -0,0 +1,34 @@ +using FurnitureCompany.Entities; +using FurnitureCompany.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Repositories.Implementations; + +public class ProductRepository : IProductRepository +{ + public void CreateProduct(Product product) + { + } + + public void DeleteProduct(int id) + { + } + + public Product ReadProductById(int id) + { + return Product.CreateEntity(0, Material.None, string.Empty, 0); + } + + public IEnumerable ReadProducts() + { + return []; + } + + public void UpdateProduct(Product product) + { + } +} diff --git a/FurnitureCompany/FurnitureCompany/Repositories/Implementations/WorkerRepository.cs b/FurnitureCompany/FurnitureCompany/Repositories/Implementations/WorkerRepository.cs new file mode 100644 index 0000000..19c9e98 --- /dev/null +++ b/FurnitureCompany/FurnitureCompany/Repositories/Implementations/WorkerRepository.cs @@ -0,0 +1,34 @@ +using FurnitureCompany.Entities; +using FurnitureCompany.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FurnitureCompany.Repositories.Implementations; + +public class WorkerRepository : IWorkerRepository +{ + public void CreateWorker(Worker worker) + { + } + + public void DeleteWorker(int id) + { + } + + public Worker ReadWorkerById(int id) + { + return Worker.CreateEntity(0, string.Empty, string.Empty, WorkerPost.None); + } + + public IEnumerable ReadWorkers() + { + return []; + } + + public void UpdateWorker(Worker worker) + { + } +} diff --git a/FurnitureCompany/FurnitureCompany/Resources/57435d62a4b6bbc87520597c0e8c4c3a.jpg b/FurnitureCompany/FurnitureCompany/Resources/57435d62a4b6bbc87520597c0e8c4c3a.jpg new file mode 100644 index 0000000..1cbc179 Binary files /dev/null and b/FurnitureCompany/FurnitureCompany/Resources/57435d62a4b6bbc87520597c0e8c4c3a.jpg differ diff --git a/FurnitureCompany/FurnitureCompany/Resources/58d48b2c9540b15afe3fa643.png b/FurnitureCompany/FurnitureCompany/Resources/58d48b2c9540b15afe3fa643.png new file mode 100644 index 0000000..5028c7f Binary files /dev/null and b/FurnitureCompany/FurnitureCompany/Resources/58d48b2c9540b15afe3fa643.png differ diff --git a/FurnitureCompany/FurnitureCompany/Resources/minus.jpg b/FurnitureCompany/FurnitureCompany/Resources/minus.jpg new file mode 100644 index 0000000..7d810e0 Binary files /dev/null and b/FurnitureCompany/FurnitureCompany/Resources/minus.jpg differ diff --git a/FurnitureCompany/FurnitureCompany/Resources/png-clipart-plus-plus.png b/FurnitureCompany/FurnitureCompany/Resources/png-clipart-plus-plus.png new file mode 100644 index 0000000..b64bb1f Binary files /dev/null and b/FurnitureCompany/FurnitureCompany/Resources/png-clipart-plus-plus.png differ