diff --git a/ProjectGasStation/ProjectGasStation/Entities/Employee.cs b/ProjectGasStation/ProjectGasStation/Entities/Employee.cs new file mode 100644 index 0000000..e622083 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Entities/Employee.cs @@ -0,0 +1,22 @@ +using ProjectGasStation.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Entities; + +public class Employee +{ + public int Id { get; private set; } + + public string Name { get; private set; } = string.Empty; + + public EmployeePost EmployeePost { get; private set; } + + public static Employee CreateEntity(int id, string name, EmployeePost employeePost) + { + return new Employee { Id = id, Name = name ?? string.Empty, EmployeePost = employeePost }; + } +} diff --git a/ProjectGasStation/ProjectGasStation/Entities/Enums/EmployeePost.cs b/ProjectGasStation/ProjectGasStation/Entities/Enums/EmployeePost.cs new file mode 100644 index 0000000..63ea919 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Entities/Enums/EmployeePost.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Entities.Enums; +[Flags] +public enum EmployeePost +{ + None = 0, + + Cashier = 1, + + Fueler = 2, + + Manager = 4, + + Programmer = 8, + + Mechanic = 16 +} diff --git a/ProjectGasStation/ProjectGasStation/Entities/Enums/ProductType.cs b/ProjectGasStation/ProjectGasStation/Entities/Enums/ProductType.cs new file mode 100644 index 0000000..eab31cc --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Entities/Enums/ProductType.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Entities.Enums; + +public enum ProductType +{ + None = 0, + + Fuel = 1, + + MotorOil = 2, + + AutoChemicals = 3, + + AutoParts = 4, + + Tires = 5, +} diff --git a/ProjectGasStation/ProjectGasStation/Entities/Product.cs b/ProjectGasStation/ProjectGasStation/Entities/Product.cs new file mode 100644 index 0000000..8856f2f --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Entities/Product.cs @@ -0,0 +1,24 @@ +using ProjectGasStation.Entities.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Entities; + +public class Product +{ + public int Id { get; private set; } + + public string Name { get; private set; } = string.Empty; + + public double Price { get; private set; } + + public ProductType ProductType { get; private set; } + + public static Product CreateEntity(int id, string name, double price, ProductType productType) + { + return new Product { Id = id, Name = name ?? string.Empty, Price = price, ProductType = productType }; + } +} diff --git a/ProjectGasStation/ProjectGasStation/Entities/Purchase.cs b/ProjectGasStation/ProjectGasStation/Entities/Purchase.cs new file mode 100644 index 0000000..3948aa3 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Entities/Purchase.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Entities; + +public class Purchase +{ + public int Id { get; private set; } + + public int ProductId { get; private set; } + + public int SupplierId { get; private set; } + + public double Quantity { get; private set; } + + public DateTime PurchaseDate { get; private set; } + + public double Price { get; private set; } + + public static Purchase CreateOperation(int id, int productId, int supplierId, double quantity, DateTime purchaseDate, double price) + { + return new Purchase { Id = id, ProductId = productId, SupplierId = supplierId, Quantity = quantity, PurchaseDate = purchaseDate, Price = price }; + } +} diff --git a/ProjectGasStation/ProjectGasStation/Entities/Sale.cs b/ProjectGasStation/ProjectGasStation/Entities/Sale.cs new file mode 100644 index 0000000..1782cfd --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Entities/Sale.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Entities; + +public class Sale +{ + public int Id { get; private set; } + public int EmployeeId { get; private set; } + public DateTime SaleDate { get; private set;} + + public IEnumerable SaleProducts { get; private set; } = []; + public static Sale CreateOperation(int id, int employeeId, DateTime saleDate, IEnumerable saleProducts) + { + return new Sale + { + Id = id, + EmployeeId = employeeId, + SaleDate = saleDate, + SaleProducts = saleProducts + }; + } +} diff --git a/ProjectGasStation/ProjectGasStation/Entities/SaleProduct.cs b/ProjectGasStation/ProjectGasStation/Entities/SaleProduct.cs new file mode 100644 index 0000000..aa19cf7 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Entities/SaleProduct.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Entities; + +public class SaleProduct +{ + public int Id { get; private set; } + public int SaleID { get; private set; } + public int ProductID { get; private set;} + public double Quantity { get; private set; } + + + + public static SaleProduct CreateOperation(int id, int saleID, int productID, double quantity) + { + return new SaleProduct() { Id = id, SaleID = saleID, ProductID = productID, Quantity = quantity }; + } +} diff --git a/ProjectGasStation/ProjectGasStation/Entities/Supplier.cs b/ProjectGasStation/ProjectGasStation/Entities/Supplier.cs new file mode 100644 index 0000000..c9d35ad --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Entities/Supplier.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Entities; + +public class Supplier +{ + public int Id { get; private set; } + + public string Name { get; private set; } = string.Empty; + + public string INN { get; private set; } = string.Empty; + + public static Supplier CreateEntity(int id, string name, string INN) + { + return new Supplier { Id = id, Name = name, INN = INN }; + } +} diff --git a/ProjectGasStation/ProjectGasStation/Form1.Designer.cs b/ProjectGasStation/ProjectGasStation/Form1.Designer.cs deleted file mode 100644 index 1630d39..0000000 --- a/ProjectGasStation/ProjectGasStation/Form1.Designer.cs +++ /dev/null @@ -1,39 +0,0 @@ -namespace ProjectGasStation -{ - 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 - } -} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Form1.cs b/ProjectGasStation/ProjectGasStation/Form1.cs deleted file mode 100644 index d014f73..0000000 --- a/ProjectGasStation/ProjectGasStation/Form1.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace ProjectGasStation -{ - public partial class Form1 : Form - { - public Form1() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/FormGasStation.Designer.cs b/ProjectGasStation/ProjectGasStation/FormGasStation.Designer.cs new file mode 100644 index 0000000..40ca5bd --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/FormGasStation.Designer.cs @@ -0,0 +1,148 @@ +namespace ProjectGasStation +{ + partial class FormGasStation + { + /// + /// 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() + { + components = new System.ComponentModel.Container(); + contextMenuStrip = new ContextMenuStrip(components); + menuStrip1 = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + EmployeeToolStripMenuItem = new ToolStripMenuItem(); + ProductToolStripMenuItem = new ToolStripMenuItem(); + SupplierToolStripMenuItem = new ToolStripMenuItem(); + операцииToolStripMenuItem = new ToolStripMenuItem(); + SaleToolStripMenuItem = new ToolStripMenuItem(); + PurchaseToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); + menuStrip1.SuspendLayout(); + SuspendLayout(); + // + // contextMenuStrip + // + contextMenuStrip.ImageScalingSize = new Size(18, 18); + contextMenuStrip.Name = "contextMenuStrip"; + contextMenuStrip.Size = new Size(61, 4); + // + // menuStrip1 + // + menuStrip1.ImageScalingSize = new Size(18, 18); + menuStrip1.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip1.Location = new Point(0, 0); + menuStrip1.Name = "menuStrip1"; + menuStrip1.Size = new Size(784, 25); + menuStrip1.TabIndex = 1; + menuStrip1.Text = "menuStrip1"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { EmployeeToolStripMenuItem, ProductToolStripMenuItem, SupplierToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(99, 21); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // EmployeeToolStripMenuItem + // + EmployeeToolStripMenuItem.Name = "EmployeeToolStripMenuItem"; + EmployeeToolStripMenuItem.Size = new Size(198, 24); + EmployeeToolStripMenuItem.Text = "Сотрудники"; + EmployeeToolStripMenuItem.Click += EmployeeToolStripMenuItem_Click; + // + // ProductToolStripMenuItem + // + ProductToolStripMenuItem.Name = "ProductToolStripMenuItem"; + ProductToolStripMenuItem.Size = new Size(198, 24); + ProductToolStripMenuItem.Text = "Товары"; + ProductToolStripMenuItem.Click += ProductToolStripMenuItem_Click; + // + // SupplierToolStripMenuItem + // + SupplierToolStripMenuItem.Name = "SupplierToolStripMenuItem"; + SupplierToolStripMenuItem.Size = new Size(198, 24); + SupplierToolStripMenuItem.Text = "Поставщики"; + SupplierToolStripMenuItem.Click += SupplierToolStripMenuItem_Click; + // + // операцииToolStripMenuItem + // + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SaleToolStripMenuItem, PurchaseToolStripMenuItem }); + операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; + операцииToolStripMenuItem.Size = new Size(80, 21); + операцииToolStripMenuItem.Text = "Операции"; + // + // SaleToolStripMenuItem + // + SaleToolStripMenuItem.Name = "SaleToolStripMenuItem"; + SaleToolStripMenuItem.Size = new Size(198, 24); + SaleToolStripMenuItem.Text = "Продажа"; + SaleToolStripMenuItem.Click += SaleToolStripMenuItem_Click; + // + // PurchaseToolStripMenuItem + // + PurchaseToolStripMenuItem.Name = "PurchaseToolStripMenuItem"; + PurchaseToolStripMenuItem.Size = new Size(198, 24); + PurchaseToolStripMenuItem.Text = "Закупка"; + PurchaseToolStripMenuItem.Click += PurchaseToolStripMenuItem_Click; + // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(63, 21); + отчетыToolStripMenuItem.Text = "Отчеты"; + // + // FormGasStation + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + BackgroundImage = Properties.Resources.Union_76_Gas_Station; + BackgroundImageLayout = ImageLayout.Stretch; + ClientSize = new Size(784, 409); + Controls.Add(menuStrip1); + MainMenuStrip = menuStrip1; + Name = "FormGasStation"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Заправочная станция"; + menuStrip1.ResumeLayout(false); + menuStrip1.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private ContextMenuStrip contextMenuStrip; + private MenuStrip menuStrip1; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem операцииToolStripMenuItem; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem EmployeeToolStripMenuItem; + private ToolStripMenuItem ProductToolStripMenuItem; + private ToolStripMenuItem сменыToolStripMenuItem; + private ToolStripMenuItem SupplierToolStripMenuItem; + private ToolStripMenuItem SaleToolStripMenuItem; + private ToolStripMenuItem PurchaseToolStripMenuItem; + } +} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/FormGasStation.cs b/ProjectGasStation/ProjectGasStation/FormGasStation.cs new file mode 100644 index 0000000..7135178 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/FormGasStation.cs @@ -0,0 +1,74 @@ +using ProjectGasStation.Forms; +using Unity; + +namespace ProjectGasStation; + +public partial class FormGasStation : Form +{ + private readonly IUnityContainer _container; + public FormGasStation(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + } + + private void EmployeeToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ProductToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void SupplierToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void PurchaseToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void SaleToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } +} diff --git a/ProjectGasStation/ProjectGasStation/FormGasStation.resx b/ProjectGasStation/ProjectGasStation/FormGasStation.resx new file mode 100644 index 0000000..bed21a5 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/FormGasStation.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 + + + 17, 17 + + + 176, 17 + + \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormEmployee.Designer.cs b/ProjectGasStation/ProjectGasStation/Forms/FormEmployee.Designer.cs new file mode 100644 index 0000000..5a1fe2e --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormEmployee.Designer.cs @@ -0,0 +1,117 @@ +namespace ProjectGasStation.Forms +{ + partial class FormEmployee + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + label2 = new Label(); + textBoxName = new TextBox(); + checkedListBoxType = new CheckedListBox(); + buttonAdd = new Button(); + buttonCancel = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(52, 65); + labelName.Name = "labelName"; + labelName.Size = new Size(34, 17); + labelName.TabIndex = 0; + labelName.Text = "Имя"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(21, 155); + label2.Name = "label2"; + label2.Size = new Size(74, 17); + label2.TabIndex = 1; + label2.Text = "Должность"; + // + // textBoxName + // + textBoxName.Location = new Point(110, 62); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(150, 25); + textBoxName.TabIndex = 2; + // + // checkedListBoxType + // + checkedListBoxType.FormattingEnabled = true; + checkedListBoxType.Location = new Point(110, 155); + checkedListBoxType.Name = "checkedListBoxType"; + checkedListBoxType.Size = new Size(150, 104); + checkedListBoxType.TabIndex = 3; + // + // buttonAdd + // + buttonAdd.Location = new Point(52, 336); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(114, 40); + buttonAdd.TabIndex = 4; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += this.buttonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(227, 336); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(112, 40); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + // + // FormEmployee + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(415, 408); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(checkedListBoxType); + Controls.Add(textBoxName); + Controls.Add(label2); + Controls.Add(labelName); + Name = "FormEmployee"; + Text = "Employee"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label label2; + private TextBox textBoxName; + private CheckedListBox checkedListBoxType; + private Button buttonAdd; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormEmployee.cs b/ProjectGasStation/ProjectGasStation/Forms/FormEmployee.cs new file mode 100644 index 0000000..1cb3fc8 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormEmployee.cs @@ -0,0 +1,101 @@ +using ProjectGasStation.Entities; +using ProjectGasStation.Entities.Enums; +using ProjectGasStation.Implementations; +using ProjectGasStation.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 ProjectGasStation.Forms +{ + public partial class FormEmployee : Form + { + private readonly IEmployeeRepository _employeeRepository; + private int? _employeeId; + + public int Id + { + set + { + try + { + var employee = _employeeRepository.ReadEmployeeById(value); + if (employee == null) + { + throw new + InvalidDataException(nameof(employee)); + } + foreach (EmployeePost elem in Enum.GetValues(typeof(EmployeePost))) + { + if ((elem & employee.EmployeePost) != 0) + { + checkedListBoxType.SetItemChecked(checkedListBoxType.Items.IndexOf(elem), true); + } + } + textBoxName.Text = employee.Name; + _employeeId = value; + + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormEmployee(IEmployeeRepository employeeRepository) + { + InitializeComponent(); + _employeeRepository = employeeRepository ?? throw new ArgumentNullException(nameof(employeeRepository)); + + foreach(var elem in Enum.GetValues(typeof(EmployeePost))) + { + checkedListBoxType.Items.Add(elem); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + try + { + if (checkedListBoxType.CheckedItems.Count == 0 || + string.IsNullOrWhiteSpace(textBoxName.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_employeeId.HasValue) + { + _employeeRepository.UpdateEmployee(CreateEmployee(_employeeId.Value)); + } + else + { + _employeeRepository.CreateEmployee(CreateEmployee(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) => Close(); + private Employee CreateEmployee(int id) + { + EmployeePost employeePost = EmployeePost.None; + foreach (var elem in checkedListBoxType.CheckedItems) + { + employeePost |= (EmployeePost)elem; + } + + return Employee.CreateEntity(id, textBoxName.Text, employeePost); + } + } +} diff --git a/ProjectGasStation/ProjectGasStation/Form1.resx b/ProjectGasStation/ProjectGasStation/Forms/FormEmployee.resx similarity index 93% rename from ProjectGasStation/ProjectGasStation/Form1.resx rename to ProjectGasStation/ProjectGasStation/Forms/FormEmployee.resx index 1af7de1..af32865 100644 --- a/ProjectGasStation/ProjectGasStation/Form1.resx +++ b/ProjectGasStation/ProjectGasStation/Forms/FormEmployee.resx @@ -1,17 +1,17 @@  - diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormEmployees.Designer.cs b/ProjectGasStation/ProjectGasStation/Forms/FormEmployees.Designer.cs new file mode 100644 index 0000000..7e020a9 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormEmployees.Designer.cs @@ -0,0 +1,117 @@ +namespace ProjectGasStation.Forms +{ + partial class FormEmployees + { + /// + /// 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() + { + dataGridView = new DataGridView(); + panel1 = new Panel(); + buttonUpdate = new Button(); + buttonRemove = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + panel1.SuspendLayout(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 45; + dataGridView.Size = new Size(800, 450); + dataGridView.TabIndex = 0; + // + // panel1 + // + panel1.Controls.Add(buttonUpdate); + panel1.Controls.Add(buttonRemove); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(645, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(155, 450); + panel1.TabIndex = 1; + // + // buttonUpdate + // + buttonUpdate.BackgroundImage = Properties.Resources.edit; + buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpdate.Location = new Point(35, 300); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(83, 75); + buttonUpdate.TabIndex = 2; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonRemove + // + buttonRemove.BackgroundImage = Properties.Resources.minus; + buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; + buttonRemove.Location = new Point(35, 171); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(83, 75); + buttonRemove.TabIndex = 1; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.plus1; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(35, 47); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(83, 75); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // FormEmployees + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(panel1); + Controls.Add(dataGridView); + Name = "FormEmployees"; + Text = "FormEmployees"; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + panel1.ResumeLayout(false); + ResumeLayout(false); + Load += FormEmployees_Load; + } + + #endregion + + private DataGridView dataGridView; + private Panel panel1; + private Button buttonUpdate; + private Button buttonRemove; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormEmployees.cs b/ProjectGasStation/ProjectGasStation/Forms/FormEmployees.cs new file mode 100644 index 0000000..fbe8913 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormEmployees.cs @@ -0,0 +1,118 @@ +using ProjectGasStation.Entities.Enums; +using ProjectGasStation.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 ProjectGasStation.Forms +{ + public partial class FormEmployees : Form + { + private readonly IUnityContainer _container; + private readonly IEmployeeRepository _employeeRepository; + + + public FormEmployees(IUnityContainer container, IEmployeeRepository employeeRepository) + { + InitializeComponent(); + _container = container ?? + throw new + ArgumentNullException(nameof(container)); + _employeeRepository = employeeRepository ?? + throw new ArgumentNullException(nameof(employeeRepository)); + } + + private void FormEmployees_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView.DataSource = + _employeeRepository.ReadEmployees(); + 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; + } + + 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 buttonRemove_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", + MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _employeeRepository.DeleteEmployee(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormEmployees.resx b/ProjectGasStation/ProjectGasStation/Forms/FormEmployees.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormEmployees.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/ProjectGasStation/ProjectGasStation/Forms/FormProduct.Designer.cs b/ProjectGasStation/ProjectGasStation/Forms/FormProduct.Designer.cs new file mode 100644 index 0000000..c4498b6 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormProduct.Designer.cs @@ -0,0 +1,146 @@ +namespace ProjectGasStation.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() + { + labelName = new Label(); + labelPrice = new Label(); + labelProductType = new Label(); + textBoxProductName = new TextBox(); + numericUpDownProductPrice = new NumericUpDown(); + buttonSave = new Button(); + buttonCancel = new Button(); + comboBoxProductType = new ComboBox(); + ((System.ComponentModel.ISupportInitialize)numericUpDownProductPrice).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(26, 35); + labelName.Name = "labelName"; + labelName.Size = new Size(111, 17); + labelName.TabIndex = 0; + labelName.Text = "Название товара"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(26, 88); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(108, 17); + labelPrice.TabIndex = 1; + labelPrice.Text = "Цена за единицу"; + // + // labelProductType + // + labelProductType.AutoSize = true; + labelProductType.Location = new Point(26, 139); + labelProductType.Name = "labelProductType"; + labelProductType.Size = new Size(75, 17); + labelProductType.TabIndex = 2; + labelProductType.Text = "Тип товара"; + // + // textBoxProductName + // + textBoxProductName.Location = new Point(140, 35); + textBoxProductName.Name = "textBoxProductName"; + textBoxProductName.Size = new Size(100, 25); + textBoxProductName.TabIndex = 3; + // + // numericUpDownProductPrice + // + numericUpDownProductPrice.DecimalPlaces = 3; + numericUpDownProductPrice.Location = new Point(140, 88); + numericUpDownProductPrice.Minimum = new decimal(new int[] { 1, 0, 0, 196608 }); + numericUpDownProductPrice.Name = "numericUpDownProductPrice"; + numericUpDownProductPrice.Size = new Size(120, 25); + numericUpDownProductPrice.TabIndex = 5; + numericUpDownProductPrice.Value = new decimal(new int[] { 1, 0, 0, 196608 }); + // + // buttonSave + // + buttonSave.Location = new Point(41, 258); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(108, 41); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(203, 258); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(116, 41); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // comboBoxProductType + // + comboBoxProductType.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxProductType.FormattingEnabled = true; + comboBoxProductType.Location = new Point(139, 136); + comboBoxProductType.Name = "comboBoxProductType"; + comboBoxProductType.Size = new Size(121, 25); + comboBoxProductType.TabIndex = 8; + // + // FormProduct + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(358, 335); + Controls.Add(comboBoxProductType); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(numericUpDownProductPrice); + Controls.Add(textBoxProductName); + Controls.Add(labelProductType); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormProduct"; + Text = "Товар"; + ((System.ComponentModel.ISupportInitialize)numericUpDownProductPrice).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPrice; + private Label labelProductType; + private TextBox textBoxProductName; + private NumericUpDown numericUpDownProductPrice; + private Button buttonSave; + private Button buttonCancel; + private ComboBox comboBoxProductType; + } +} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormProduct.cs b/ProjectGasStation/ProjectGasStation/Forms/FormProduct.cs new file mode 100644 index 0000000..ccbdbda --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormProduct.cs @@ -0,0 +1,94 @@ +using ProjectGasStation.Entities; +using ProjectGasStation.Entities.Enums; +using ProjectGasStation.Implementations; +using ProjectGasStation.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 ProjectGasStation.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)); + } + + textBoxProductName.Text = product.Name; + numericUpDownProductPrice.Value = (decimal)product.Price; + comboBoxProductType.SelectedItem = product.ProductType; + _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)); + + comboBoxProductType.DataSource = Enum.GetValues(typeof(ProductType)); + } + + + + private void buttonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxProductName.Text) || comboBoxProductType.SelectedIndex < 1) + { + 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) => Product.CreateEntity(id, textBoxProductName.Text, (double)numericUpDownProductPrice.Value, (ProductType)comboBoxProductType.SelectedItem!); + } +} diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormProduct.resx b/ProjectGasStation/ProjectGasStation/Forms/FormProduct.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/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/ProjectGasStation/ProjectGasStation/Forms/FormProducts.Designer.cs b/ProjectGasStation/ProjectGasStation/Forms/FormProducts.Designer.cs new file mode 100644 index 0000000..9c4d607 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormProducts.Designer.cs @@ -0,0 +1,117 @@ +namespace ProjectGasStation.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(); + buttonUpdate = new Button(); + buttonDel = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonUpdate); + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(630, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(170, 450); + panel1.TabIndex = 0; + // + // buttonUpdate + // + buttonUpdate.BackgroundImage = Properties.Resources.edit; + buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpdate.Location = new Point(40, 309); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(83, 73); + buttonUpdate.TabIndex = 2; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.minus; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(40, 186); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(83, 73); + buttonDel.TabIndex = 1; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.plus1; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(40, 52); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(83, 73); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 45; + dataGridView.Size = new Size(630, 450); + dataGridView.TabIndex = 1; + // + // FormProducts + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormProducts"; + Text = "FormProducts"; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + Load += FormProducts_Load; + } + + #endregion + + private Panel panel1; + private Button buttonUpdate; + private Button buttonDel; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormProducts.cs b/ProjectGasStation/ProjectGasStation/Forms/FormProducts.cs new file mode 100644 index 0000000..4d24c14 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormProducts.cs @@ -0,0 +1,116 @@ +using ProjectGasStation.Implementations; +using ProjectGasStation.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 ProjectGasStation.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 LoadList() => dataGridView.DataSource = _productRepository.ReadProducts(); + + private void buttonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void 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 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/ProjectGasStation/ProjectGasStation/Forms/FormProducts.resx b/ProjectGasStation/ProjectGasStation/Forms/FormProducts.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/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/ProjectGasStation/ProjectGasStation/Forms/FormPurchase.Designer.cs b/ProjectGasStation/ProjectGasStation/Forms/FormPurchase.Designer.cs new file mode 100644 index 0000000..b18759e --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormPurchase.Designer.cs @@ -0,0 +1,196 @@ +namespace ProjectGasStation.Forms +{ + partial class FormPurchase + { + /// + /// 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() + { + labelProduct = new Label(); + labelSupplier = new Label(); + labelQuantity = new Label(); + dateTimePicker1 = new DateTimePicker(); + labelDate = new Label(); + labelPrice = new Label(); + numericUpDown1 = new NumericUpDown(); + numericUpDown2 = new NumericUpDown(); + comboBoxProduct = new ComboBox(); + comboBoxSupplier = new ComboBox(); + buttonAdd = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDown1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown2).BeginInit(); + SuspendLayout(); + // + // labelProduct + // + labelProduct.AutoSize = true; + labelProduct.Location = new Point(44, 39); + labelProduct.Name = "labelProduct"; + labelProduct.Size = new Size(45, 17); + labelProduct.TabIndex = 0; + labelProduct.Text = "Товар"; + // + // labelSupplier + // + labelSupplier.AutoSize = true; + labelSupplier.Location = new Point(46, 96); + labelSupplier.Name = "labelSupplier"; + labelSupplier.Size = new Size(74, 17); + labelSupplier.TabIndex = 1; + labelSupplier.Text = "Поставщик"; + // + // labelQuantity + // + labelQuantity.AutoSize = true; + labelQuantity.Location = new Point(46, 144); + labelQuantity.Name = "labelQuantity"; + labelQuantity.Size = new Size(82, 17); + labelQuantity.TabIndex = 2; + labelQuantity.Text = "Количество "; + // + // dateTimePicker1 + // + dateTimePicker1.Location = new Point(147, 242); + dateTimePicker1.Name = "dateTimePicker1"; + dateTimePicker1.Size = new Size(221, 25); + dateTimePicker1.TabIndex = 3; + dateTimePicker1.ValueChanged += dateTimePicker1_ValueChanged; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(44, 242); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(36, 17); + labelDate.TabIndex = 4; + labelDate.Text = "Дата"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(46, 197); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(39, 17); + labelPrice.TabIndex = 5; + labelPrice.Text = "Цена"; + // + // numericUpDown1 + // + numericUpDown1.DecimalPlaces = 2; + numericUpDown1.Location = new Point(147, 197); + numericUpDown1.Minimum = new decimal(new int[] { 1, 0, 0, 131072 }); + numericUpDown1.Name = "numericUpDown1"; + numericUpDown1.Size = new Size(132, 25); + numericUpDown1.TabIndex = 6; + numericUpDown1.Value = new decimal(new int[] { 1, 0, 0, 131072 }); + // + // numericUpDown2 + // + numericUpDown2.DecimalPlaces = 3; + numericUpDown2.Location = new Point(147, 144); + numericUpDown2.Minimum = new decimal(new int[] { 1, 0, 0, 196608 }); + numericUpDown2.Name = "numericUpDown2"; + numericUpDown2.Size = new Size(132, 25); + numericUpDown2.TabIndex = 7; + numericUpDown2.Value = new decimal(new int[] { 1, 0, 0, 196608 }); + // + // comboBoxProduct + // + comboBoxProduct.FormattingEnabled = true; + comboBoxProduct.Location = new Point(147, 39); + comboBoxProduct.Name = "comboBoxProduct"; + comboBoxProduct.Size = new Size(134, 25); + comboBoxProduct.TabIndex = 8; + // + // comboBoxSupplier + // + comboBoxSupplier.FormattingEnabled = true; + comboBoxSupplier.Location = new Point(147, 96); + comboBoxSupplier.Name = "comboBoxSupplier"; + comboBoxSupplier.Size = new Size(134, 25); + comboBoxSupplier.TabIndex = 9; + // + // buttonAdd + // + buttonAdd.Location = new Point(45, 388); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(123, 42); + buttonAdd.TabIndex = 10; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += this.buttonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(227, 388); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(115, 42); + buttonCancel.TabIndex = 11; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += this.buttonCancel_Click; + // + // FormPurchase + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(398, 485); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(comboBoxSupplier); + Controls.Add(comboBoxProduct); + Controls.Add(numericUpDown2); + Controls.Add(numericUpDown1); + Controls.Add(labelPrice); + Controls.Add(labelDate); + Controls.Add(dateTimePicker1); + Controls.Add(labelQuantity); + Controls.Add(labelSupplier); + Controls.Add(labelProduct); + Name = "FormPurchase"; + Text = "FormPurchases"; + ((System.ComponentModel.ISupportInitialize)numericUpDown1).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDown2).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelProduct; + private Label labelSupplier; + private Label labelQuantity; + private DateTimePicker dateTimePicker1; + private Label labelDate; + private Label labelPrice; + private NumericUpDown numericUpDown1; + private NumericUpDown numericUpDown2; + private ComboBox comboBoxProduct; + private ComboBox comboBoxSupplier; + private Button buttonAdd; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormPurchase.cs b/ProjectGasStation/ProjectGasStation/Forms/FormPurchase.cs new file mode 100644 index 0000000..b37101f --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormPurchase.cs @@ -0,0 +1,92 @@ +using ProjectGasStation.Entities; +using ProjectGasStation.Implementations; +using ProjectGasStation.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 ProjectGasStation.Forms +{ + public partial class FormPurchase : Form + { + private readonly IPurchaseRepository _purchaseRepository; + private int? _purchaseId; + + public int Id + { + set + { + try + { + var purchase = + _purchaseRepository.ReadPurchaseById(value); + if (purchase == null) + { + throw new + InvalidDataException(nameof(purchase)); + } + comboBoxProduct.SelectedIndex = purchase.ProductId; + comboBoxSupplier.SelectedIndex = purchase.SupplierId; + _purchaseId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormPurchase(IPurchaseRepository purchaseRepository, IProductRepository productRepository, ISupplierRepository supplierRepository) + { + InitializeComponent(); + + _purchaseRepository = purchaseRepository ?? throw new ArgumentNullException(nameof(purchaseRepository)); + + comboBoxProduct.DataSource = productRepository.ReadProducts(); + comboBoxProduct.DisplayMember = "Name"; + comboBoxProduct.ValueMember = "Id"; + + comboBoxSupplier.DataSource = supplierRepository.ReadSuppliers(); + comboBoxSupplier.DisplayMember = "Name"; + comboBoxSupplier.ValueMember = "Id"; + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + try + { + if (comboBoxProduct.SelectedIndex < 0 || comboBoxSupplier.SelectedIndex < 0 || dateTimePicker1.CustomFormat != " ") + { + throw new Exception("Имеются незаполненные поля"); + } + if (_purchaseId.HasValue) + { + _purchaseRepository.UpdatePurchase(CreatePurchase(_purchaseId.Value)); + } + else + { + _purchaseRepository.CreatePurchase(CreatePurchase(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void buttonCancel_Click(object sender, EventArgs e) => Close(); + + private Purchase CreatePurchase(int id) => Purchase.CreateOperation(id, comboBoxProduct.SelectedIndex, comboBoxSupplier.SelectedIndex, (double)numericUpDown2.Value, Convert.ToDateTime(dateTimePicker1), (double)numericUpDown1.Value); + private void dateTimePicker1_ValueChanged(object sender, EventArgs e) + { + + } + } +} diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormPurchase.resx b/ProjectGasStation/ProjectGasStation/Forms/FormPurchase.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormPurchase.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/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.Designer.cs b/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.Designer.cs new file mode 100644 index 0000000..083b929 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.Designer.cs @@ -0,0 +1,107 @@ +namespace ProjectGasStation.Forms +{ + partial class FormPurchases + { + /// + /// 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() + { + dataGridView1 = new DataGridView(); + panel1 = new Panel(); + buttonUpdate = new Button(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + panel1.SuspendLayout(); + SuspendLayout(); + // + // dataGridView1 + // + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Dock = DockStyle.Fill; + dataGridView1.Location = new Point(0, 0); + dataGridView1.Name = "dataGridView1"; + dataGridView1.RowHeadersWidth = 45; + dataGridView1.Size = new Size(800, 450); + dataGridView1.TabIndex = 0; + // + // panel1 + // + panel1.Controls.Add(buttonUpdate); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(647, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(153, 450); + panel1.TabIndex = 1; + // + // buttonUpdate + // + buttonUpdate.BackgroundImage = Properties.Resources.edit; + buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpdate.Location = new Point(32, 269); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(83, 75); + buttonUpdate.TabIndex = 1; + buttonUpdate.UseVisualStyleBackColor = true; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.plus1; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(32, 84); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(83, 75); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += this.buttonAdd_Click; + // + // FormPurchases + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(panel1); + Controls.Add(dataGridView1); + Name = "FormPurchases"; + Text = "FormPurchase"; + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + panel1.ResumeLayout(false); + ResumeLayout(false); + Load += FormPurchases_Load; + } + + private void F(object sender, EventArgs e) + { + throw new NotImplementedException(); + } + + #endregion + + private DataGridView dataGridView1; + private Panel panel1; + private Button buttonUpdate; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.cs b/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.cs new file mode 100644 index 0000000..1b96e0b --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.cs @@ -0,0 +1,84 @@ +using ProjectGasStation.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 ProjectGasStation.Forms; + +public partial class FormPurchases : Form +{ + private readonly IUnityContainer _container; + private readonly IPurchaseRepository _purchaseRepository; + public FormPurchases(IUnityContainer container, IPurchaseRepository purchaseRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _purchaseRepository = purchaseRepository ?? throw new ArgumentNullException(nameof(_purchaseRepository)); + } + + private void FormPurchases_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView1.DataSource = _purchaseRepository.ReadPurchases(); + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView1.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value); + return true; + } +} + diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.resx b/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormPurchases.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/ProjectGasStation/ProjectGasStation/Forms/FormSale.Designer.cs b/ProjectGasStation/ProjectGasStation/Forms/FormSale.Designer.cs new file mode 100644 index 0000000..5663350 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormSale.Designer.cs @@ -0,0 +1,153 @@ +namespace ProjectGasStation.Forms +{ + partial class FormSale + { + /// + /// 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() + { + labelEmployee = new Label(); + dateTimePicker1 = new DateTimePicker(); + label1 = new Label(); + dataGridView1 = new DataGridView(); + ColumnProduct = new DataGridViewComboBoxColumn(); + ColumnQuantity = new DataGridViewTextBoxColumn(); + buttonAdd = new Button(); + buttonCancel = new Button(); + comboBoxEmployee = new ComboBox(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + SuspendLayout(); + // + // labelEmployee + // + labelEmployee.AutoSize = true; + labelEmployee.Location = new Point(12, 29); + labelEmployee.Name = "labelEmployee"; + labelEmployee.Size = new Size(70, 17); + labelEmployee.TabIndex = 0; + labelEmployee.Text = "Сотрудник"; + // + // dateTimePicker1 + // + dateTimePicker1.Location = new Point(58, 73); + dateTimePicker1.Name = "dateTimePicker1"; + dateTimePicker1.Size = new Size(221, 25); + dateTimePicker1.TabIndex = 1; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(12, 73); + label1.Name = "label1"; + label1.Size = new Size(36, 17); + label1.TabIndex = 2; + label1.Text = "Дата"; + // + // dataGridView1 + // + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Columns.AddRange(new DataGridViewColumn[] { ColumnProduct, ColumnQuantity }); + dataGridView1.Location = new Point(12, 197); + dataGridView1.Name = "dataGridView1"; + dataGridView1.RowHeadersWidth = 45; + dataGridView1.Size = new Size(267, 329); + dataGridView1.TabIndex = 3; + // + // ColumnProduct + // + ColumnProduct.HeaderText = "Товар"; + ColumnProduct.MinimumWidth = 6; + ColumnProduct.Name = "ColumnProduct"; + ColumnProduct.Resizable = DataGridViewTriState.True; + ColumnProduct.SortMode = DataGridViewColumnSortMode.Automatic; + ColumnProduct.Width = 110; + // + // ColumnQuantity + // + ColumnQuantity.HeaderText = "Количество"; + ColumnQuantity.MinimumWidth = 6; + ColumnQuantity.Name = "ColumnQuantity"; + ColumnQuantity.Width = 110; + // + // buttonAdd + // + buttonAdd.Location = new Point(12, 555); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(115, 43); + buttonAdd.TabIndex = 4; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(164, 555); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(115, 43); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // comboBoxEmployee + // + comboBoxEmployee.FormattingEnabled = true; + comboBoxEmployee.Location = new Point(88, 29); + comboBoxEmployee.Name = "comboBoxEmployee"; + comboBoxEmployee.Size = new Size(193, 25); + comboBoxEmployee.TabIndex = 6; + // + // FormSale + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(293, 622); + Controls.Add(comboBoxEmployee); + Controls.Add(buttonCancel); + Controls.Add(buttonAdd); + Controls.Add(dataGridView1); + Controls.Add(label1); + Controls.Add(dateTimePicker1); + Controls.Add(labelEmployee); + Name = "FormSale"; + Text = "FormSale"; + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelEmployee; + private DateTimePicker dateTimePicker1; + private Label label1; + private DataGridView dataGridView1; + private Button buttonAdd; + private Button buttonCancel; + private ComboBox comboBoxEmployee; + private DataGridViewComboBoxColumn ColumnProduct; + private DataGridViewTextBoxColumn ColumnQuantity; + } +} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormSale.cs b/ProjectGasStation/ProjectGasStation/Forms/FormSale.cs new file mode 100644 index 0000000..5ad36d2 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormSale.cs @@ -0,0 +1,65 @@ +using ProjectGasStation.Entities; +using ProjectGasStation.Implementations; +using ProjectGasStation.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 ProjectGasStation.Forms; + +public partial class FormSale : Form +{ + private readonly ISaleRepository _saleRepository; + public FormSale(ISaleRepository saleRepository, IProductRepository productRepository, IEmployeeRepository employeeRepository) + { + InitializeComponent(); + _saleRepository = saleRepository ?? throw new ArgumentNullException(nameof(saleRepository)); + + //comboBoxEmployee.DataSource = employeeRepository.ReadEmployees(); + //comboBoxEmployee.DisplayMember = "Name"; + //comboBoxEmployee.ValueMember = "Id"; + + //ColumnProduct.DataSource = productRepository.ReadProducts(); + //ColumnProduct.DisplayMember = "ServiceType"; + //ColumnProduct.ValueMember = "Id"; + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + if (dataGridView1.RowCount < 1 || comboBoxEmployee.SelectedIndex < 0 || dateTimePicker1.CustomFormat != " ") + { + throw new Exception("Имеются незаполненны поля"); + } + try + { + _saleRepository.CreateSale(Sale.CreateOperation(0, comboBoxEmployee.SelectedIndex, dateTimePicker1.Value, CreateListServiceFromDataGrid())); + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) => Close(); + + private List CreateListServiceFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridView1.Rows) + { + if (row.Cells["ColumService"].Value == null || row.Cells["ColumQuantity"].Value == null || row.Cells["ColumnExecutionDate"].Value == null) + { + continue; + } + list.Add(SaleProduct.CreateOperation(0, 0, Convert.ToInt32(row.Cells["ColumnProduct"].Value), Convert.ToDouble(row.Cells["ColumnQuantity"].Value))); + } + return list; + } +} diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormSale.resx b/ProjectGasStation/ProjectGasStation/Forms/FormSale.resx new file mode 100644 index 0000000..3307e71 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormSale.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/ProjectGasStation/ProjectGasStation/Forms/FormSales.Designer.cs b/ProjectGasStation/ProjectGasStation/Forms/FormSales.Designer.cs new file mode 100644 index 0000000..1f58170 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormSales.Designer.cs @@ -0,0 +1,89 @@ +namespace ProjectGasStation.Forms +{ + partial class FormSales + { + /// + /// 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(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(626, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(174, 450); + panel1.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.plus1; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(42, 50); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(96, 94); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 45; + dataGridView.Size = new Size(626, 450); + dataGridView.TabIndex = 1; + // + // FormSales + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormSales"; + Text = "Sales"; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + Load += FormSales_Load; + } + + #endregion + + private Panel panel1; + private DataGridView dataGridView; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormSales.cs b/ProjectGasStation/ProjectGasStation/Forms/FormSales.cs new file mode 100644 index 0000000..0341ce3 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormSales.cs @@ -0,0 +1,63 @@ +using ProjectGasStation.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 ProjectGasStation.Forms; + +public partial class FormSales : Form +{ + private readonly IUnityContainer _container; + private readonly ISaleRepository _saleRepository; + public FormSales(IUnityContainer container, ISaleRepository saleRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _saleRepository = saleRepository ?? throw new ArgumentNullException(nameof(saleRepository)); + } + + private void FormSales_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadList() => dataGridView.DataSource = _saleRepository.ReadSales(); + + 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/ProjectGasStation/ProjectGasStation/Forms/FormSales.resx b/ProjectGasStation/ProjectGasStation/Forms/FormSales.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormSales.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/ProjectGasStation/ProjectGasStation/Forms/FormSupplier.Designer.cs b/ProjectGasStation/ProjectGasStation/Forms/FormSupplier.Designer.cs new file mode 100644 index 0000000..02ae29e --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormSupplier.Designer.cs @@ -0,0 +1,128 @@ +namespace ProjectGasStation.Forms +{ + partial class FormSupplier + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + label1 = new Label(); + labelINN = new Label(); + textBoxName = new TextBox(); + textBoxINN = new TextBox(); + buttonAdd = new Button(); + button2 = new Button(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(43, 63); + labelName.Name = "labelName"; + labelName.Size = new Size(65, 17); + labelName.TabIndex = 0; + labelName.Text = "Название"; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(43, 125); + label1.Name = "label1"; + label1.Size = new Size(0, 17); + label1.TabIndex = 1; + // + // labelINN + // + labelINN.AutoSize = true; + labelINN.Location = new Point(49, 119); + labelINN.Name = "labelINN"; + labelINN.Size = new Size(36, 17); + labelINN.TabIndex = 2; + labelINN.Text = "ИНН"; + // + // textBoxName + // + textBoxName.Location = new Point(144, 65); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(110, 25); + textBoxName.TabIndex = 3; + // + // textBoxINN + // + textBoxINN.Location = new Point(145, 116); + textBoxINN.Name = "textBoxINN"; + textBoxINN.Size = new Size(110, 25); + textBoxINN.TabIndex = 4; + // + // buttonAdd + // + buttonAdd.Location = new Point(25, 243); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(97, 32); + buttonAdd.TabIndex = 5; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // button2 + // + button2.Location = new Point(170, 243); + button2.Name = "button2"; + button2.Size = new Size(97, 32); + button2.TabIndex = 6; + button2.Text = "Отмена"; + button2.UseVisualStyleBackColor = true; + button2.Click += button2_Click; + // + // FormSupplier + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(299, 307); + Controls.Add(button2); + Controls.Add(buttonAdd); + Controls.Add(textBoxINN); + Controls.Add(textBoxName); + Controls.Add(labelINN); + Controls.Add(label1); + Controls.Add(labelName); + Name = "FormSupplier"; + Text = "FormSupplier"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label label1; + private Label labelINN; + private TextBox textBoxName; + private TextBox textBoxINN; + private Button buttonAdd; + private Button button2; + } +} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormSupplier.cs b/ProjectGasStation/ProjectGasStation/Forms/FormSupplier.cs new file mode 100644 index 0000000..d4cd1ac --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormSupplier.cs @@ -0,0 +1,77 @@ +using ProjectGasStation.Entities; +using ProjectGasStation.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 ProjectGasStation.Forms +{ + public partial class FormSupplier : Form + { + private readonly ISupplierRepository _supplierRepository; + private int? _supplierId; + + public int Id + { + set + { + try + { + var supplier = _supplierRepository.ReadSupplierById(value); + if (supplier == null) + { + throw new InvalidDataException(nameof(supplier)); + } + textBoxName.Text = supplier.Name; + textBoxINN.Text = supplier.INN; + _supplierId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormSupplier(ISupplierRepository supplierRepository) + { + InitializeComponent(); + _supplierRepository = supplierRepository ?? throw new ArgumentNullException(nameof(supplierRepository)); + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxName.Text) || string.IsNullOrWhiteSpace(textBoxINN.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_supplierId.HasValue) + { + _supplierRepository.UpdateSupplier(CreateSupplier(_supplierId.Value)); + } + else + { + _supplierRepository.CreateSupplier(CreateSupplier(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void button2_Click(object sender, EventArgs e) => Close(); + + private Supplier CreateSupplier(int id) => Supplier.CreateEntity(id, textBoxName.Text, textBoxINN.Text); + } +} diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormSupplier.resx b/ProjectGasStation/ProjectGasStation/Forms/FormSupplier.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormSupplier.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.Designer.cs b/ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.Designer.cs new file mode 100644 index 0000000..4a146a5 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.Designer.cs @@ -0,0 +1,117 @@ +namespace ProjectGasStation.Forms +{ + partial class FormSuppliers + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new Panel(); + buttonUpdate = new Button(); + buttonRemove = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonUpdate); + panel1.Controls.Add(buttonRemove); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(660, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(140, 450); + panel1.TabIndex = 0; + // + // buttonUpdate + // + buttonUpdate.BackgroundImage = Properties.Resources.edit; + buttonUpdate.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpdate.Location = new Point(30, 282); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(83, 73); + buttonUpdate.TabIndex = 2; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonRemove + // + buttonRemove.BackgroundImage = Properties.Resources.minus; + buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; + buttonRemove.Location = new Point(30, 167); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(83, 73); + buttonRemove.TabIndex = 1; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.plus1; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(30, 46); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(83, 73); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 45; + dataGridView.Size = new Size(660, 450); + dataGridView.TabIndex = 1; + // + // FormSuppliers + // + AutoScaleDimensions = new SizeF(7F, 17F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormSuppliers"; + Text = "FormSuppliers"; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + Load += FormSuppliers_Load; + } + + #endregion + + private Panel panel1; + private Button buttonUpdate; + private Button buttonRemove; + private Button buttonAdd; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.cs b/ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.cs new file mode 100644 index 0000000..d25b92f --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.cs @@ -0,0 +1,107 @@ +using ProjectGasStation.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 ProjectGasStation.Forms +{ + public partial class FormSuppliers : Form + { + private readonly IUnityContainer _container; + private readonly ISupplierRepository _supplierRepository; + + public FormSuppliers(IUnityContainer container, ISupplierRepository supplierRepository) + { + InitializeComponent(); + _container = container ?? throw new ArgumentNullException(nameof(container)); + _supplierRepository = supplierRepository ?? throw new ArgumentNullException(nameof(supplierRepository)); + } + + private void FormSuppliers_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonRemove_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _supplierRepository.DeleteSupplier(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findId; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView.DataSource = _supplierRepository.ReadSuppliers(); + + 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/ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.resx b/ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Forms/FormSuppliers.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Implementations/EmployeeRepository.cs b/ProjectGasStation/ProjectGasStation/Implementations/EmployeeRepository.cs new file mode 100644 index 0000000..f51b52f --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Implementations/EmployeeRepository.cs @@ -0,0 +1,38 @@ +using ProjectGasStation.Entities; +using ProjectGasStation.Entities.Enums; +using ProjectGasStation.Repositories; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Implementations; + +public class EmployeeRepository : IEmployeeRepository +{ + public void CreateEmployee(Employee employee) + { + + } + + public void DeleteEmployee(int id) + { + + } + + public Employee ReadEmployeeById(int id) + { + return Employee.CreateEntity(0, string.Empty, EmployeePost.None); + } + + public IEnumerable ReadEmployees() + { + return []; + } + + public void UpdateEmployee(Employee employee) + { + + } +} diff --git a/ProjectGasStation/ProjectGasStation/Implementations/ProductRepository.cs b/ProjectGasStation/ProjectGasStation/Implementations/ProductRepository.cs new file mode 100644 index 0000000..602964b --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Implementations/ProductRepository.cs @@ -0,0 +1,38 @@ +using ProjectGasStation.Entities; +using ProjectGasStation.Entities.Enums; +using ProjectGasStation.Repositories; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Implementations; + +public class ProductRepository : IProductRepository +{ + public void CreateProduct(Product product) + { + + } + + public void DeleteProduct(int id) + { + + } + + public Product ReadProductById(int id) + { + return Product.CreateEntity(0, string.Empty, 0, ProductType.None); + } + + public IEnumerable ReadProducts() + { + return []; + } + + public void UpdateProduct(Product product) + { + + } +} diff --git a/ProjectGasStation/ProjectGasStation/Implementations/PurchaseRepository.cs b/ProjectGasStation/ProjectGasStation/Implementations/PurchaseRepository.cs new file mode 100644 index 0000000..09764b5 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Implementations/PurchaseRepository.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ProjectGasStation.Entities; +using ProjectGasStation.Repositories; + +namespace ProjectGasStation.Implementations; + +public class PurchaseRepository : IPurchaseRepository +{ + public void CreatePurchase(Purchase purchase) + { + + } + + public IEnumerable ReadPurchases(DateTime? dateFrom = null, DateTime? dateTo = null, int? supplierId = null, int? productId = null) + { + return []; + } + + public void UpdatePurchase(Purchase purchase) + { + + } + + public Purchase ReadPurchaseById(int id) + { + return null; + } + +} diff --git a/ProjectGasStation/ProjectGasStation/Implementations/SaleRepository.cs b/ProjectGasStation/ProjectGasStation/Implementations/SaleRepository.cs new file mode 100644 index 0000000..58b7267 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Implementations/SaleRepository.cs @@ -0,0 +1,22 @@ +using ProjectGasStation.Entities; +using ProjectGasStation.Repositories; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Implementations; + +public class SaleRepository : ISaleRepository +{ + public void CreateSale(Sale sale) + { + + } + + public IEnumerable ReadSales(DateTime? dateFrom = null, DateTime? dateTo = null, int? employeeId = null) + { + return []; + } +} diff --git a/ProjectGasStation/ProjectGasStation/Implementations/SupplierRepository.cs b/ProjectGasStation/ProjectGasStation/Implementations/SupplierRepository.cs new file mode 100644 index 0000000..334659f --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Implementations/SupplierRepository.cs @@ -0,0 +1,37 @@ +using ProjectGasStation.Entities; +using ProjectGasStation.Repositories; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Implementations; + +public class SupplierRepository : ISupplierRepository +{ + public void CreateSupplier(Supplier supplier) + { + + } + + public void DeleteSupplier(int id) + { + + } + + public Supplier ReadSupplierById(int id) + { + return Supplier.CreateEntity(0, string.Empty, string.Empty); + } + + public IEnumerable ReadSuppliers() + { + return []; + } + + public void UpdateSupplier(Supplier supplier) + { + + } +} diff --git a/ProjectGasStation/ProjectGasStation/Program.cs b/ProjectGasStation/ProjectGasStation/Program.cs index 9830769..7c2017e 100644 --- a/ProjectGasStation/ProjectGasStation/Program.cs +++ b/ProjectGasStation/ProjectGasStation/Program.cs @@ -1,3 +1,7 @@ +using ProjectGasStation.Implementations; +using ProjectGasStation.Repositories; +using Unity; + namespace ProjectGasStation { internal static class Program @@ -11,7 +15,20 @@ namespace ProjectGasStation // 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(CreateUnityContainer().Resolve()); + } + + private static IUnityContainer CreateUnityContainer() + { + 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/ProjectGasStation/ProjectGasStation/ProjectGasStation.csproj b/ProjectGasStation/ProjectGasStation/ProjectGasStation.csproj index b57c89e..67310ea 100644 --- a/ProjectGasStation/ProjectGasStation/ProjectGasStation.csproj +++ b/ProjectGasStation/ProjectGasStation/ProjectGasStation.csproj @@ -2,10 +2,29 @@ WinExe - net6.0-windows + net8.0-windows7.0 enable true enable + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Properties/Resources.Designer.cs b/ProjectGasStation/ProjectGasStation/Properties/Resources.Designer.cs new file mode 100644 index 0000000..0126d75 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Properties/Resources.Designer.cs @@ -0,0 +1,113 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace ProjectGasStation.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("ProjectGasStation.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 edit { + get { + object obj = ResourceManager.GetObject("edit", 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 plus { + get { + object obj = ResourceManager.GetObject("plus", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap plus1 { + get { + object obj = ResourceManager.GetObject("plus1", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap Union_76_Gas_Station { + get { + object obj = ResourceManager.GetObject("Union_76_Gas_Station", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/ProjectGasStation/ProjectGasStation/Properties/Resources.resx b/ProjectGasStation/ProjectGasStation/Properties/Resources.resx new file mode 100644 index 0000000..3dcc74b --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Properties/Resources.resx @@ -0,0 +1,136 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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\plus.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\plus.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Union_76_Gas_Station.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\edit.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/ProjectGasStation/ProjectGasStation/Repositories/IEmployeeRepository.cs b/ProjectGasStation/ProjectGasStation/Repositories/IEmployeeRepository.cs new file mode 100644 index 0000000..4a99eee --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Repositories/IEmployeeRepository.cs @@ -0,0 +1,21 @@ +using ProjectGasStation.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Repositories; + +public interface IEmployeeRepository +{ + IEnumerable ReadEmployees(); + + Employee ReadEmployeeById(int id); + + void CreateEmployee(Employee employee); + + void UpdateEmployee(Employee employee); + + void DeleteEmployee(int id); +} diff --git a/ProjectGasStation/ProjectGasStation/Repositories/IProductRepository.cs b/ProjectGasStation/ProjectGasStation/Repositories/IProductRepository.cs new file mode 100644 index 0000000..2356649 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Repositories/IProductRepository.cs @@ -0,0 +1,21 @@ +using ProjectGasStation.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.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/ProjectGasStation/ProjectGasStation/Repositories/IPurchaseRepository.cs b/ProjectGasStation/ProjectGasStation/Repositories/IPurchaseRepository.cs new file mode 100644 index 0000000..8ae2c68 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Repositories/IPurchaseRepository.cs @@ -0,0 +1,18 @@ +using ProjectGasStation.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Repositories; + +public interface IPurchaseRepository +{ + IEnumerable ReadPurchases(DateTime? dateFrom = null, DateTime? dateTo = null, int? supplierId = null, int? productId = null); + + Purchase ReadPurchaseById(int id); + void CreatePurchase(Purchase purchase); + + void UpdatePurchase(Purchase purchase); +} diff --git a/ProjectGasStation/ProjectGasStation/Repositories/ISaleRepository.cs b/ProjectGasStation/ProjectGasStation/Repositories/ISaleRepository.cs new file mode 100644 index 0000000..ed92a80 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Repositories/ISaleRepository.cs @@ -0,0 +1,17 @@ +using ProjectGasStation.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Repositories; + +public interface ISaleRepository +{ + IEnumerable ReadSales(DateTime? dateFrom = null, DateTime? dateTo = null, int? employeeId = null); + + + void CreateSale(Sale sale); + +} diff --git a/ProjectGasStation/ProjectGasStation/Repositories/ISupplierRepository.cs b/ProjectGasStation/ProjectGasStation/Repositories/ISupplierRepository.cs new file mode 100644 index 0000000..cc7eb95 --- /dev/null +++ b/ProjectGasStation/ProjectGasStation/Repositories/ISupplierRepository.cs @@ -0,0 +1,21 @@ +using ProjectGasStation.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectGasStation.Repositories; + +public interface ISupplierRepository +{ + IEnumerable ReadSuppliers(); + + Supplier ReadSupplierById(int id); + + void CreateSupplier(Supplier supplier); + + void UpdateSupplier(Supplier supplier); + + void DeleteSupplier(int id); +} diff --git a/ProjectGasStation/ProjectGasStation/Resources/Union_76_Gas_Station.jpg b/ProjectGasStation/ProjectGasStation/Resources/Union_76_Gas_Station.jpg new file mode 100644 index 0000000..94de535 Binary files /dev/null and b/ProjectGasStation/ProjectGasStation/Resources/Union_76_Gas_Station.jpg differ diff --git a/ProjectGasStation/ProjectGasStation/Resources/edit.png b/ProjectGasStation/ProjectGasStation/Resources/edit.png new file mode 100644 index 0000000..769aabd Binary files /dev/null and b/ProjectGasStation/ProjectGasStation/Resources/edit.png differ diff --git a/ProjectGasStation/ProjectGasStation/Resources/minus.jpg b/ProjectGasStation/ProjectGasStation/Resources/minus.jpg new file mode 100644 index 0000000..1a42e9c Binary files /dev/null and b/ProjectGasStation/ProjectGasStation/Resources/minus.jpg differ diff --git a/ProjectGasStation/ProjectGasStation/Resources/plus.jpg b/ProjectGasStation/ProjectGasStation/Resources/plus.jpg new file mode 100644 index 0000000..b766719 Binary files /dev/null and b/ProjectGasStation/ProjectGasStation/Resources/plus.jpg differ