diff --git a/Workshop/Entities/Cheque.cs b/Workshop/Entities/Cheque.cs new file mode 100644 index 0000000..316a994 --- /dev/null +++ b/Workshop/Entities/Cheque.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Workshop.Entities; + +public class Cheque +{ + public int Id { get; private set; } + public DateTime Date { get; private set; } + public double Sum { get; private set; } + public IEnumerable ChequeProduct { get; private set; } = []; + + public static Cheque CreateOperation(int id, int sum, IEnumerable products) + { + return new Cheque() + { + Id = id, + Sum = sum, + Date = DateTime.Now, + ChequeProduct = products + }; + + } + +} diff --git a/Workshop/Entities/ChequeProduct.cs b/Workshop/Entities/ChequeProduct.cs new file mode 100644 index 0000000..84389fb --- /dev/null +++ b/Workshop/Entities/ChequeProduct.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Workshop.Entities; +public class ChequeProduct +{ + public int ProductId { get; private set; } + public int ChequeId { get; private set; } + public int Amount { get; private set; } + public static ChequeProduct CreateEntity(int productid, int chequeid, int amount) + { + return new ChequeProduct + { + ProductId = productid, + ChequeId = chequeid, + Amount = amount + }; + } +} diff --git a/Workshop/Entities/Enums/MasterPosition.cs b/Workshop/Entities/Enums/MasterPosition.cs new file mode 100644 index 0000000..7ad4b80 --- /dev/null +++ b/Workshop/Entities/Enums/MasterPosition.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Workshop.Entities.Enums; + +public enum MasterPosition +{ + None = 0, + Intern = 1, + Master = 2 +} diff --git a/Workshop/Entities/Enums/ProductCategory.cs b/Workshop/Entities/Enums/ProductCategory.cs new file mode 100644 index 0000000..79e5b36 --- /dev/null +++ b/Workshop/Entities/Enums/ProductCategory.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Workshop.Entities.Enums; +[Flags] +public enum ProductCategory +{ + None = 0, + Furniture = 1, + Gifts = 2, + Kitchenware = 4, + Tools = 8 +} diff --git a/Workshop/Entities/Master.cs b/Workshop/Entities/Master.cs new file mode 100644 index 0000000..e1d13fb --- /dev/null +++ b/Workshop/Entities/Master.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Workshop.Entities.Enums; + +namespace Workshop.Entities; + +public class Master +{ + public int Id { get; private set; } + public string Name { get; private set; } = string.Empty; + public string LastName { get; private set; } = string.Empty; + public int Age { get; private set; } + public MasterPosition Position { get; private set; } + + public static Master CreateEntity(int id, string name, string lastName, int age, MasterPosition position) + { + return new Master + { + Id = id, + Name = name, + LastName = lastName, + Age = age, + Position = position + }; + } +} \ No newline at end of file diff --git a/Workshop/Entities/Material.cs b/Workshop/Entities/Material.cs new file mode 100644 index 0000000..b67a045 --- /dev/null +++ b/Workshop/Entities/Material.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Workshop.Entities; + +public class Material +{ + public int Id { get; private set; } + public string Name { get; private set; } = string.Empty; + public int WarehouseAmount { get; private set; } + public double Price { get; private set; } + public static Material CreateEntity(int id, string name, int warehouseAmount, double price) + { + return new Material + { + Id = id, + Name = name, + WarehouseAmount = warehouseAmount, + Price = price + }; + } +} diff --git a/Workshop/Entities/Product.cs b/Workshop/Entities/Product.cs new file mode 100644 index 0000000..b513024 --- /dev/null +++ b/Workshop/Entities/Product.cs @@ -0,0 +1,27 @@ +using System; +using Workshop.Entities; +using Workshop.Entities.Enums; + +public class Product +{ + public int Id { get; private set; } + public string Name { get; private set; } = string.Empty; + public double Price { get; private set; } + public int WarehouseAmount { get; private set; } + public ProductCategory Category { get; private set; } + public IEnumerable Materials { get; private set; } = []; + public static Product CreateEntity(int id, string name, double price, int warehouseAmount, + ProductCategory category, IEnumerable materials) + { + return new Product { + Id = id, + Name = name, + Price = price, + WarehouseAmount = warehouseAmount, + Category = category, + Materials = materials + }; + } + + +} diff --git a/Workshop/Entities/ProductCreate.cs b/Workshop/Entities/ProductCreate.cs new file mode 100644 index 0000000..26640f7 --- /dev/null +++ b/Workshop/Entities/ProductCreate.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Workshop.Entities.Enums; + +namespace Workshop.Entities; + +public class ProductCreate +{ + public int Id { get; private set; } + public int ProductId { get; private set; } + public int MasterId { get; private set; } + public DateTime CreatingDate { get; private set; } + public static ProductCreate CreateOperation(int id, int productid, int masterid) + { + return new ProductCreate + { + Id = id, + ProductId = productid, + MasterId = masterid, + CreatingDate = DateTime.Now + }; + } + +} diff --git a/Workshop/Entities/ProductMaterial.cs b/Workshop/Entities/ProductMaterial.cs new file mode 100644 index 0000000..b6debc0 --- /dev/null +++ b/Workshop/Entities/ProductMaterial.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Workshop.Entities; + +public class ProductMaterial +{ + public int ProductId { get; private set; } + public int MaterialId { get; private set; } + public int Count { get; private set; } + public static ProductMaterial CreateEntity(int productId, int materialId, int count) + { + return new ProductMaterial + { + ProductId = productId, + MaterialId = materialId, + Count = count + }; + } +} diff --git a/Workshop/FormWorkshop.Designer.cs b/Workshop/FormWorkshop.Designer.cs new file mode 100644 index 0000000..fb5150e --- /dev/null +++ b/Workshop/FormWorkshop.Designer.cs @@ -0,0 +1,137 @@ +namespace Workshop +{ + partial class FormWorkshop + { + /// + /// 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() + { + menuStrip = new MenuStrip(); + справочникиToolStripMenuItem = new ToolStripMenuItem(); + ProductstoolStripMenuItem = new ToolStripMenuItem(); + MastersToolStripMenuItem = new ToolStripMenuItem(); + MaterialsToolStripMenuItem = new ToolStripMenuItem(); + операцииToolStripMenuItem = new ToolStripMenuItem(); + ProductCreateToolStripMenuItem = new ToolStripMenuItem(); + ChequeToolStripMenuItem = new ToolStripMenuItem(); + отчетыToolStripMenuItem = new ToolStripMenuItem(); + menuStrip.SuspendLayout(); + SuspendLayout(); + // + // menuStrip + // + menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip.Location = new Point(0, 0); + menuStrip.Name = "menuStrip"; + menuStrip.Size = new Size(784, 24); + menuStrip.TabIndex = 0; + menuStrip.Text = "menuStrip"; + // + // справочникиToolStripMenuItem + // + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ProductstoolStripMenuItem, MastersToolStripMenuItem, MaterialsToolStripMenuItem }); + справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; + справочникиToolStripMenuItem.Size = new Size(94, 20); + справочникиToolStripMenuItem.Text = "Справочники"; + // + // ProductstoolStripMenuItem + // + ProductstoolStripMenuItem.Name = "ProductstoolStripMenuItem"; + ProductstoolStripMenuItem.Size = new Size(180, 22); + ProductstoolStripMenuItem.Text = "Изделия"; + ProductstoolStripMenuItem.Click += ProductstoolStripMenuItem_Click; + // + // MastersToolStripMenuItem + // + MastersToolStripMenuItem.Name = "MastersToolStripMenuItem"; + MastersToolStripMenuItem.Size = new Size(180, 22); + MastersToolStripMenuItem.Text = "Мастера"; + MastersToolStripMenuItem.Click += MastersToolStripMenuItem_Click; + // + // MaterialsToolStripMenuItem + // + MaterialsToolStripMenuItem.Name = "MaterialsToolStripMenuItem"; + MaterialsToolStripMenuItem.Size = new Size(180, 22); + MaterialsToolStripMenuItem.Text = "Материалы"; + MaterialsToolStripMenuItem.Click += MaterialsToolStripMenuItem_Click; + // + // операцииToolStripMenuItem + // + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ProductCreateToolStripMenuItem, ChequeToolStripMenuItem }); + операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; + операцииToolStripMenuItem.Size = new Size(75, 20); + операцииToolStripMenuItem.Text = "Операции"; + // + // ProductCreateToolStripMenuItem + // + ProductCreateToolStripMenuItem.Name = "ProductCreateToolStripMenuItem"; + ProductCreateToolStripMenuItem.Size = new Size(203, 22); + ProductCreateToolStripMenuItem.Text = "Создание изделия"; + ProductCreateToolStripMenuItem.Click += ProductCreateToolStripMenuItem_Click; + // + // ChequeToolStripMenuItem + // + ChequeToolStripMenuItem.Name = "ChequeToolStripMenuItem"; + ChequeToolStripMenuItem.Size = new Size(203, 22); + ChequeToolStripMenuItem.Text = "Продажа изделий (Чек)"; + ChequeToolStripMenuItem.Click += ChequeToolStripMenuItem_Click; + // + // отчетыToolStripMenuItem + // + отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; + отчетыToolStripMenuItem.Size = new Size(60, 20); + отчетыToolStripMenuItem.Text = "Отчеты"; + // + // FormWorkshop + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + BackgroundImage = Properties.Resources.st4_1; + BackgroundImageLayout = ImageLayout.Stretch; + ClientSize = new Size(784, 411); + Controls.Add(menuStrip); + MainMenuStrip = menuStrip; + Name = "FormWorkshop"; + StartPosition = FormStartPosition.CenterScreen; + Text = "Мастерская"; + menuStrip.ResumeLayout(false); + menuStrip.PerformLayout(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private MenuStrip menuStrip; + private ToolStripMenuItem справочникиToolStripMenuItem; + private ToolStripMenuItem ProductstoolStripMenuItem; + private ToolStripMenuItem операцииToolStripMenuItem; + private ToolStripMenuItem отчетыToolStripMenuItem; + private ToolStripMenuItem MastersToolStripMenuItem; + private ToolStripMenuItem MaterialsToolStripMenuItem; + private ToolStripMenuItem ProductCreateToolStripMenuItem; + private ToolStripMenuItem ChequeToolStripMenuItem; + } +} diff --git a/Workshop/FormWorkshop.cs b/Workshop/FormWorkshop.cs new file mode 100644 index 0000000..5ab0e9f --- /dev/null +++ b/Workshop/FormWorkshop.cs @@ -0,0 +1,77 @@ +using Unity; +using Workshop.Forms; + +namespace Workshop +{ + public partial class FormWorkshop : Form + { + private readonly IUnityContainer _container; + public FormWorkshop(IUnityContainer container) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + } + + private void ProductstoolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void MastersToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void MaterialsToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ProductCreateToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ChequeToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/Workshop/FormWorkshop.resx b/Workshop/FormWorkshop.resx new file mode 100644 index 0000000..31084d5 --- /dev/null +++ b/Workshop/FormWorkshop.resx @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 17, 17 + + \ No newline at end of file diff --git a/Workshop/Forms/FormCheque.Designer.cs b/Workshop/Forms/FormCheque.Designer.cs new file mode 100644 index 0000000..36423c6 --- /dev/null +++ b/Workshop/Forms/FormCheque.Designer.cs @@ -0,0 +1,172 @@ +namespace Workshop.Forms +{ + partial class FormCheque + { + /// + /// 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() + { + dateTimePickerDate = new DateTimePicker(); + labelData = new Label(); + labelSum = new Label(); + numericUpDownSum = new NumericUpDown(); + groupBoxProdCheq = new GroupBox(); + dataGridViewProducts = new DataGridView(); + ColumnProductName = new DataGridViewComboBoxColumn(); + ProductAmount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownSum).BeginInit(); + groupBoxProdCheq.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewProducts).BeginInit(); + SuspendLayout(); + // + // dateTimePickerDate + // + dateTimePickerDate.Enabled = false; + dateTimePickerDate.Location = new Point(144, 25); + dateTimePickerDate.Name = "dateTimePickerDate"; + dateTimePickerDate.Size = new Size(121, 23); + dateTimePickerDate.TabIndex = 5; + // + // labelData + // + labelData.AutoSize = true; + labelData.Location = new Point(38, 31); + labelData.Name = "labelData"; + labelData.Size = new Size(35, 15); + labelData.TabIndex = 4; + labelData.Text = "Дата:"; + // + // labelSum + // + labelSum.AutoSize = true; + labelSum.Location = new Point(38, 77); + labelSum.Name = "labelSum"; + labelSum.Size = new Size(45, 15); + labelSum.TabIndex = 6; + labelSum.Text = "Сумма"; + // + // numericUpDownSum + // + numericUpDownSum.Location = new Point(144, 75); + numericUpDownSum.Name = "numericUpDownSum"; + numericUpDownSum.Size = new Size(121, 23); + numericUpDownSum.TabIndex = 7; + // + // groupBoxProdCheq + // + groupBoxProdCheq.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBoxProdCheq.Controls.Add(dataGridViewProducts); + groupBoxProdCheq.Location = new Point(38, 128); + groupBoxProdCheq.Name = "groupBoxProdCheq"; + groupBoxProdCheq.Size = new Size(275, 251); + groupBoxProdCheq.TabIndex = 8; + groupBoxProdCheq.TabStop = false; + groupBoxProdCheq.Text = "Изделия"; + // + // dataGridViewProducts + // + dataGridViewProducts.AllowUserToResizeColumns = false; + dataGridViewProducts.AllowUserToResizeRows = false; + dataGridViewProducts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewProducts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewProducts.Columns.AddRange(new DataGridViewColumn[] { ColumnProductName, ProductAmount }); + dataGridViewProducts.Dock = DockStyle.Fill; + dataGridViewProducts.Location = new Point(3, 19); + dataGridViewProducts.MultiSelect = false; + dataGridViewProducts.Name = "dataGridViewProducts"; + dataGridViewProducts.RowHeadersVisible = false; + dataGridViewProducts.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewProducts.Size = new Size(269, 229); + dataGridViewProducts.TabIndex = 0; + // + // ColumnProductName + // + ColumnProductName.HeaderText = "Изделие"; + ColumnProductName.Name = "ColumnProductName"; + // + // ProductAmount + // + ProductAmount.HeaderText = "Количество"; + ProductAmount.Name = "ProductAmount"; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(72, 398); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 9; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(216, 398); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 10; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // FormCheque + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(359, 436); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBoxProdCheq); + Controls.Add(numericUpDownSum); + Controls.Add(labelSum); + Controls.Add(dateTimePickerDate); + Controls.Add(labelData); + Name = "FormCheque"; + Text = "Продажа"; + ((System.ComponentModel.ISupportInitialize)numericUpDownSum).EndInit(); + groupBoxProdCheq.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewProducts).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private DateTimePicker dateTimePickerDate; + private Label labelData; + private Label labelSum; + private NumericUpDown numericUpDownSum; + private GroupBox groupBoxProdCheq; + private Button buttonSave; + private Button buttonCancel; + private DataGridView dataGridViewProducts; + private DataGridViewComboBoxColumn ColumnProductName; + private DataGridViewTextBoxColumn ProductAmount; + } +} \ No newline at end of file diff --git a/Workshop/Forms/FormCheque.cs b/Workshop/Forms/FormCheque.cs new file mode 100644 index 0000000..33c126c --- /dev/null +++ b/Workshop/Forms/FormCheque.cs @@ -0,0 +1,61 @@ +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 Workshop.Entities; +using Workshop.Repositories; + +namespace Workshop.Forms +{ + public partial class FormCheque : Form + { + private IChequeRepository _chequeRepository; + public FormCheque(IChequeRepository chequeRepository, IProductRepository productRepository) + { + InitializeComponent(); + _chequeRepository = chequeRepository ?? + throw new ArgumentNullException(nameof(chequeRepository)); + ColumnProductName.DataSource = productRepository.ReadProducts(); + ColumnProductName.DisplayMember = "Name"; + ColumnProductName.ValueMember = "Id"; + } + + private void buttonSave_Click(object sender, EventArgs e) + { + try + { + if (dataGridViewProducts.RowCount < 2) + { + throw new Exception("Имеются незаполненные поля"); + } + _chequeRepository.CreateCheque(Cheque.CreateOperation(0, Convert.ToInt32(numericUpDownSum.Value), CreateListChequeProductsFromDataGrid())); + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonCancel_Click(object sender, EventArgs e) => Close(); + private List CreateListChequeProductsFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridViewProducts.Rows) + { + if (row.Cells["ColumnProductName"].Value == null || row.Cells["ColumnAmount"].Value == null) + { + continue; + } + list.Add(ChequeProduct.CreateEntity(Convert.ToInt32(row.Cells["ColumnProductName"].Value), 0, + Convert.ToInt32(row.Cells["ColumnAmount"].Value))); + } + return list; + } + } +} diff --git a/Workshop/Forms/FormCheque.resx b/Workshop/Forms/FormCheque.resx new file mode 100644 index 0000000..ce86aef --- /dev/null +++ b/Workshop/Forms/FormCheque.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/Workshop/Forms/FormCheques.Designer.cs b/Workshop/Forms/FormCheques.Designer.cs new file mode 100644 index 0000000..30afbce --- /dev/null +++ b/Workshop/Forms/FormCheques.Designer.cs @@ -0,0 +1,98 @@ +namespace Workshop.Forms +{ + partial class FormCheques + { + /// + /// 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() + { + panel = new Panel(); + buttonAdd = new Button(); + dataGridProductCreatings = new DataGridView(); + panel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridProductCreatings).BeginInit(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(buttonAdd); + panel.Dock = DockStyle.Right; + panel.Location = new Point(600, 0); + panel.Name = "panel"; + panel.Size = new Size(200, 450); + panel.TabIndex = 0; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Add; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(55, 39); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 75); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridProductCreatings + // + dataGridProductCreatings.AllowUserToAddRows = false; + dataGridProductCreatings.AllowUserToDeleteRows = false; + dataGridProductCreatings.AllowUserToResizeColumns = false; + dataGridProductCreatings.AllowUserToResizeRows = false; + dataGridProductCreatings.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridProductCreatings.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridProductCreatings.Dock = DockStyle.Fill; + dataGridProductCreatings.Location = new Point(0, 0); + dataGridProductCreatings.MultiSelect = false; + dataGridProductCreatings.Name = "dataGridProductCreatings"; + dataGridProductCreatings.ReadOnly = true; + dataGridProductCreatings.RowHeadersVisible = false; + dataGridProductCreatings.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridProductCreatings.Size = new Size(600, 450); + dataGridProductCreatings.TabIndex = 1; + // + // FormCheques + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridProductCreatings); + Controls.Add(panel); + Name = "FormCheques"; + StartPosition = FormStartPosition.CenterParent; + Text = "Изделия"; + Load += FormCheques_Load; + panel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridProductCreatings).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel; + private Button buttonAdd; + private DataGridView dataGridProductCreatings; + } +} \ No newline at end of file diff --git a/Workshop/Forms/FormCheques.cs b/Workshop/Forms/FormCheques.cs new file mode 100644 index 0000000..896302e --- /dev/null +++ b/Workshop/Forms/FormCheques.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Xml.Linq; +using Unity; +using Workshop.Repositories; +using Workshop.Repositories.Implementations; + +namespace Workshop.Forms +{ + public partial class FormCheques : Form + { + private readonly IUnityContainer _container; + private readonly IChequeRepository _chequeRepository; + public FormCheques(IUnityContainer container, IChequeRepository chequeRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _chequeRepository = chequeRepository ?? + throw new ArgumentNullException(nameof(chequeRepository)); + } + private void FormCheques_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() => dataGridProductCreatings.DataSource = _chequeRepository.ReadCheques(); + } +} diff --git a/Workshop/Forms/FormCheques.resx b/Workshop/Forms/FormCheques.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Workshop/Forms/FormCheques.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/Workshop/Forms/FormMaster.Designer.cs b/Workshop/Forms/FormMaster.Designer.cs new file mode 100644 index 0000000..ceda14a --- /dev/null +++ b/Workshop/Forms/FormMaster.Designer.cs @@ -0,0 +1,177 @@ +namespace Workshop.Forms +{ + partial class FormMaster + { + /// + /// 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() + { + labelCategory = new Label(); + labelAge = new Label(); + labelLastName = new Label(); + labelName = new Label(); + textBoxName = new TextBox(); + textBoxLastName = new TextBox(); + numericUpDownAge = new NumericUpDown(); + buttonCancel = new Button(); + buttonSave = new Button(); + label1 = new Label(); + comboBoxPosition = new ComboBox(); + ((System.ComponentModel.ISupportInitialize)numericUpDownAge).BeginInit(); + SuspendLayout(); + // + // labelCategory + // + labelCategory.AutoSize = true; + labelCategory.Location = new Point(35, 143); + labelCategory.Name = "labelCategory"; + labelCategory.Size = new Size(0, 15); + labelCategory.TabIndex = 7; + // + // labelAge + // + labelAge.AutoSize = true; + labelAge.Location = new Point(35, 108); + labelAge.Name = "labelAge"; + labelAge.Size = new Size(50, 15); + labelAge.TabIndex = 6; + labelAge.Text = "Возраст"; + // + // labelLastName + // + labelLastName.AutoSize = true; + labelLastName.Location = new Point(35, 72); + labelLastName.Name = "labelLastName"; + labelLastName.Size = new Size(58, 15); + labelLastName.TabIndex = 5; + labelLastName.Text = "Фамилия"; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(35, 37); + labelName.Name = "labelName"; + labelName.Size = new Size(31, 15); + labelName.TabIndex = 4; + labelName.Text = "Имя"; + // + // textBoxName + // + textBoxName.Location = new Point(177, 34); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(100, 23); + textBoxName.TabIndex = 8; + // + // textBoxLastName + // + textBoxLastName.Location = new Point(177, 69); + textBoxLastName.Name = "textBoxLastName"; + textBoxLastName.Size = new Size(100, 23); + textBoxLastName.TabIndex = 9; + // + // numericUpDownAge + // + numericUpDownAge.Location = new Point(177, 106); + numericUpDownAge.Minimum = new decimal(new int[] { 14, 0, 0, 0 }); + numericUpDownAge.Name = "numericUpDownAge"; + numericUpDownAge.Size = new Size(100, 23); + numericUpDownAge.TabIndex = 10; + numericUpDownAge.Value = new decimal(new int[] { 14, 0, 0, 0 }); + // + // buttonCancel + // + buttonCancel.Location = new Point(164, 196); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 12; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(50, 196); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 11; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(35, 143); + label1.Name = "label1"; + label1.Size = new Size(69, 15); + label1.TabIndex = 13; + label1.Text = "Должность"; + // + // comboBoxPosition + // + comboBoxPosition.FormattingEnabled = true; + comboBoxPosition.Location = new Point(177, 140); + comboBoxPosition.Name = "comboBoxPosition"; + comboBoxPosition.Size = new Size(121, 23); + comboBoxPosition.TabIndex = 14; + // + // FormMaster + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(339, 244); + Controls.Add(comboBoxPosition); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(numericUpDownAge); + Controls.Add(textBoxLastName); + Controls.Add(textBoxName); + Controls.Add(labelCategory); + Controls.Add(labelAge); + Controls.Add(labelLastName); + Controls.Add(labelName); + Name = "FormMaster"; + Text = "FormMaster"; + ((System.ComponentModel.ISupportInitialize)numericUpDownAge).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelCategory; + private Label labelAge; + private Label labelLastName; + private Label labelName; + private TextBox textBoxName; + private TextBox textBoxLastName; + private NumericUpDown numericUpDownAge; + private Button buttonCancel; + private Button buttonSave; + private Label label1; + private ComboBox comboBoxPosition; + } +} \ No newline at end of file diff --git a/Workshop/Forms/FormMaster.cs b/Workshop/Forms/FormMaster.cs new file mode 100644 index 0000000..213759d --- /dev/null +++ b/Workshop/Forms/FormMaster.cs @@ -0,0 +1,87 @@ +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 Workshop.Entities; +using Workshop.Entities.Enums; +using Workshop.Repositories; +using Workshop.Repositories.Implementations; + +namespace Workshop.Forms +{ + public partial class FormMaster : Form + { + private readonly IMasterRepository _masterRepository; + private int? _masterId; + public int Id + { + set + { + try + { + var master = _masterRepository.ReadMasterById(value); + if (master == null) + { + throw new InvalidDataException(nameof(master)); + } + textBoxName.Text = master.Name; + textBoxLastName.Text = master.LastName; + numericUpDownAge.Value = master.Age; + comboBoxPosition.SelectedItem = master.Position; + _masterId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormMaster(IMasterRepository masterRepository) + { + InitializeComponent(); + _masterRepository = masterRepository ?? + throw new ArgumentNullException(nameof(masterRepository)); + comboBoxPosition.DataSource = Enum.GetValues(typeof(MasterPosition)); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxName.Text) || string.IsNullOrWhiteSpace(textBoxLastName.Text) || + comboBoxPosition.SelectedIndex < 1) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_masterId.HasValue) + { + _masterRepository.UpdateMaster(CreateMaster(_masterId.Value)); + } + else + { + _masterRepository.CreateMaster(CreateMaster(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private Master CreateMaster(int id) + { + return Master.CreateEntity(id, + textBoxName.Text, + textBoxLastName.Text, + Convert.ToInt32(numericUpDownAge.Value), (MasterPosition)comboBoxPosition.SelectedItem!); + } + + private void buttonCancel_Click(object sender, EventArgs e) => Close(); + } +} diff --git a/Workshop/Forms/FormMaster.resx b/Workshop/Forms/FormMaster.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Workshop/Forms/FormMaster.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/Workshop/Forms/FormMasters.Designer.cs b/Workshop/Forms/FormMasters.Designer.cs new file mode 100644 index 0000000..d0cef8e --- /dev/null +++ b/Workshop/Forms/FormMasters.Designer.cs @@ -0,0 +1,126 @@ +namespace Workshop.Forms +{ + partial class FormMasters + { + /// + /// 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() + { + panel = new Panel(); + buttonEdit = new Button(); + buttonRemove = new Button(); + buttonAdd = new Button(); + dataGridViewMasters = new DataGridView(); + panel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewMasters).BeginInit(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(buttonEdit); + panel.Controls.Add(buttonRemove); + panel.Controls.Add(buttonAdd); + panel.Dock = DockStyle.Right; + panel.Location = new Point(600, 0); + panel.Name = "panel"; + panel.Size = new Size(200, 450); + panel.TabIndex = 0; + // + // buttonEdit + // + buttonEdit.BackgroundImage = Properties.Resources.Edit; + buttonEdit.BackgroundImageLayout = ImageLayout.Stretch; + buttonEdit.Location = new Point(55, 248); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(75, 75); + buttonEdit.TabIndex = 2; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += buttonEdit_Click; + // + // buttonRemove + // + buttonRemove.BackgroundImage = Properties.Resources.Remove; + buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; + buttonRemove.Location = new Point(55, 142); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(75, 75); + buttonRemove.TabIndex = 1; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Add; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(55, 39); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 75); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridViewMasters + // + dataGridViewMasters.AllowUserToAddRows = false; + dataGridViewMasters.AllowUserToDeleteRows = false; + dataGridViewMasters.AllowUserToResizeColumns = false; + dataGridViewMasters.AllowUserToResizeRows = false; + dataGridViewMasters.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewMasters.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewMasters.Dock = DockStyle.Fill; + dataGridViewMasters.Location = new Point(0, 0); + dataGridViewMasters.MultiSelect = false; + dataGridViewMasters.Name = "dataGridViewMasters"; + dataGridViewMasters.ReadOnly = true; + dataGridViewMasters.RowHeadersVisible = false; + dataGridViewMasters.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewMasters.Size = new Size(600, 450); + dataGridViewMasters.TabIndex = 1; + // + // FormMasters + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewMasters); + Controls.Add(panel); + Name = "FormMasters"; + StartPosition = FormStartPosition.CenterParent; + Text = "Изделия"; + Load += FormMasters_Load; + panel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewMasters).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel; + private Button buttonEdit; + private Button buttonRemove; + private Button buttonAdd; + private DataGridView dataGridViewMasters; + } +} \ No newline at end of file diff --git a/Workshop/Forms/FormMasters.cs b/Workshop/Forms/FormMasters.cs new file mode 100644 index 0000000..b07398e --- /dev/null +++ b/Workshop/Forms/FormMasters.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Xml.Linq; +using Unity; +using Workshop.Repositories; +using Workshop.Repositories.Implementations; + +namespace Workshop.Forms +{ + public partial class FormMasters : Form + { + private readonly IUnityContainer _container; + private readonly IMasterRepository _masterRepository; + public FormMasters(IUnityContainer container, IMasterRepository masterRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _masterRepository = masterRepository ?? + throw new ArgumentNullException(nameof(masterRepository)); + } + private void FormMasters_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) + { + } + try + { + _masterRepository.DeleteMaster(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonEdit_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 bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewMasters.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewMasters.SelectedRows[0].Cells["Id"].Value); + return true; + } + private void LoadList() => dataGridViewMasters.DataSource = _masterRepository.ReadMasters(); + + + } +} diff --git a/Workshop/Forms/FormMasters.resx b/Workshop/Forms/FormMasters.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Workshop/Forms/FormMasters.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/Workshop/Forms/FormMaterial.Designer.cs b/Workshop/Forms/FormMaterial.Designer.cs new file mode 100644 index 0000000..5628f7b --- /dev/null +++ b/Workshop/Forms/FormMaterial.Designer.cs @@ -0,0 +1,146 @@ +namespace Workshop.Forms +{ + partial class FormMaterial + { + /// + /// 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() + { + numericUpDownAmount = new NumericUpDown(); + numericUpDownPrice = new NumericUpDown(); + textBoxName = new TextBox(); + labelWHamount = new Label(); + labelPrice = new Label(); + labelName = new Label(); + buttonCancel = new Button(); + buttonSave = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownAmount).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit(); + SuspendLayout(); + // + // numericUpDownAmount + // + numericUpDownAmount.Location = new Point(201, 95); + numericUpDownAmount.Name = "numericUpDownAmount"; + numericUpDownAmount.Size = new Size(120, 23); + numericUpDownAmount.TabIndex = 12; + // + // numericUpDownPrice + // + numericUpDownPrice.DecimalPlaces = 2; + numericUpDownPrice.Location = new Point(201, 59); + numericUpDownPrice.Minimum = new decimal(new int[] { 1, 0, 0, 65536 }); + numericUpDownPrice.Name = "numericUpDownPrice"; + numericUpDownPrice.Size = new Size(120, 23); + numericUpDownPrice.TabIndex = 11; + numericUpDownPrice.Value = new decimal(new int[] { 1, 0, 0, 65536 }); + // + // textBoxName + // + textBoxName.Location = new Point(201, 23); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(100, 23); + textBoxName.TabIndex = 10; + // + // labelWHamount + // + labelWHamount.AutoSize = true; + labelWHamount.Location = new Point(34, 97); + labelWHamount.Name = "labelWHamount"; + labelWHamount.Size = new Size(128, 15); + labelWHamount.TabIndex = 9; + labelWHamount.Text = "Количество на складе"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(34, 61); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(35, 15); + labelPrice.TabIndex = 8; + labelPrice.Text = "Цена"; + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(34, 26); + labelName.Name = "labelName"; + labelName.Size = new Size(59, 15); + labelName.TabIndex = 7; + labelName.Text = "Название"; + // + // buttonCancel + // + buttonCancel.Location = new Point(191, 147); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 14; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // buttonSave + // + buttonSave.Location = new Point(77, 147); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 13; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // FormMaterial + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(360, 198); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(numericUpDownAmount); + Controls.Add(numericUpDownPrice); + Controls.Add(textBoxName); + Controls.Add(labelWHamount); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormMaterial"; + Text = "FormMaterial"; + ((System.ComponentModel.ISupportInitialize)numericUpDownAmount).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private NumericUpDown numericUpDownAmount; + private NumericUpDown numericUpDownPrice; + private TextBox textBoxName; + private Label labelWHamount; + private Label labelPrice; + private Label labelName; + private Button buttonCancel; + private Button buttonSave; + } +} \ No newline at end of file diff --git a/Workshop/Forms/FormMaterial.cs b/Workshop/Forms/FormMaterial.cs new file mode 100644 index 0000000..c7c5c9c --- /dev/null +++ b/Workshop/Forms/FormMaterial.cs @@ -0,0 +1,83 @@ +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 Workshop.Entities; +using Workshop.Entities.Enums; +using Workshop.Repositories; + +namespace Workshop.Forms +{ + public partial class FormMaterial : Form + { + private readonly IMaterialRepository _materialRepository; + private int? _materialId; + public int Id + { + set + { + try + { + var material = _materialRepository.ReadMaterialById(value); + if (material == null) + { + throw new InvalidDataException(nameof(material)); + } + textBoxName.Text = material.Name; + numericUpDownPrice.Value = (decimal)material.Price; + numericUpDownAmount.Value = material.WarehouseAmount; + _materialId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormMaterial(IMaterialRepository materialRepository) + { + InitializeComponent(); + _materialRepository = materialRepository ?? + throw new ArgumentNullException(nameof(materialRepository)); + } + + private void buttonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxName.Text)) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_materialId.HasValue) + { + _materialRepository.UpdateMaterial(CreateMaterial(_materialId.Value)); + } + else + { + _materialRepository.CreateMaterial(CreateMaterial(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private Material CreateMaterial(int id) + { + return Material.CreateEntity(id, + textBoxName.Text, + Convert.ToInt32(numericUpDownAmount.Value), + Convert.ToDouble(numericUpDownPrice.Value)); + } + + private void buttonCancel_Click(object sender, EventArgs e) => Close(); + } +} diff --git a/Workshop/Forms/FormMaterial.resx b/Workshop/Forms/FormMaterial.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Workshop/Forms/FormMaterial.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/Workshop/Forms/FormMaterials.Designer.cs b/Workshop/Forms/FormMaterials.Designer.cs new file mode 100644 index 0000000..acd15cb --- /dev/null +++ b/Workshop/Forms/FormMaterials.Designer.cs @@ -0,0 +1,126 @@ +namespace Workshop.Forms +{ + partial class FormMaterials + { + /// + /// 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() + { + panel = new Panel(); + buttonEdit = new Button(); + buttonRemove = new Button(); + buttonAdd = new Button(); + dataGridViewMaterials = new DataGridView(); + panel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewMaterials).BeginInit(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(buttonEdit); + panel.Controls.Add(buttonRemove); + panel.Controls.Add(buttonAdd); + panel.Dock = DockStyle.Right; + panel.Location = new Point(600, 0); + panel.Name = "panel"; + panel.Size = new Size(200, 450); + panel.TabIndex = 0; + // + // buttonEdit + // + buttonEdit.BackgroundImage = Properties.Resources.Edit; + buttonEdit.BackgroundImageLayout = ImageLayout.Stretch; + buttonEdit.Location = new Point(55, 248); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(75, 75); + buttonEdit.TabIndex = 2; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += buttonEdit_Click; + // + // buttonRemove + // + buttonRemove.BackgroundImage = Properties.Resources.Remove; + buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; + buttonRemove.Location = new Point(55, 142); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(75, 75); + buttonRemove.TabIndex = 1; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Add; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(55, 39); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 75); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridViewMaterials + // + dataGridViewMaterials.AllowUserToAddRows = false; + dataGridViewMaterials.AllowUserToDeleteRows = false; + dataGridViewMaterials.AllowUserToResizeColumns = false; + dataGridViewMaterials.AllowUserToResizeRows = false; + dataGridViewMaterials.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewMaterials.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewMaterials.Dock = DockStyle.Fill; + dataGridViewMaterials.Location = new Point(0, 0); + dataGridViewMaterials.MultiSelect = false; + dataGridViewMaterials.Name = "dataGridViewMaterials"; + dataGridViewMaterials.ReadOnly = true; + dataGridViewMaterials.RowHeadersVisible = false; + dataGridViewMaterials.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewMaterials.Size = new Size(600, 450); + dataGridViewMaterials.TabIndex = 1; + // + // FormMaterials + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewMaterials); + Controls.Add(panel); + Name = "FormMaterials"; + StartPosition = FormStartPosition.CenterParent; + Text = "Изделия"; + Load += FormMaterials_Load; + panel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewMaterials).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel; + private Button buttonEdit; + private Button buttonRemove; + private Button buttonAdd; + private DataGridView dataGridViewMaterials; + } +} \ No newline at end of file diff --git a/Workshop/Forms/FormMaterials.cs b/Workshop/Forms/FormMaterials.cs new file mode 100644 index 0000000..42f5b5b --- /dev/null +++ b/Workshop/Forms/FormMaterials.cs @@ -0,0 +1,107 @@ +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; +using Workshop.Entities; +using Workshop.Repositories; + +namespace Workshop.Forms +{ + public partial class FormMaterials : Form + { + private readonly IUnityContainer _container; + private readonly IMaterialRepository _materialRepository; + public FormMaterials(IUnityContainer container, IMaterialRepository materialRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _materialRepository = materialRepository ?? + throw new ArgumentNullException(nameof(materialRepository)); + } + private void FormMaterials_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) + { + } + try + { + _materialRepository.DeleteMaterial(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonEdit_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 bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewMaterials.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewMaterials.SelectedRows[0].Cells["Id"].Value); + return true; + } + private void LoadList() => dataGridViewMaterials.DataSource = _materialRepository.ReadMaterials(); + + } +} diff --git a/Workshop/Forms/FormMaterials.resx b/Workshop/Forms/FormMaterials.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Workshop/Forms/FormMaterials.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/Workshop/Forms/FormProduct.Designer.cs b/Workshop/Forms/FormProduct.Designer.cs new file mode 100644 index 0000000..d446178 --- /dev/null +++ b/Workshop/Forms/FormProduct.Designer.cs @@ -0,0 +1,220 @@ +namespace Workshop.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(); + labelWHamount = new Label(); + labelCategory = new Label(); + textBoxName = new TextBox(); + numericUpDownPrice = new NumericUpDown(); + numericUpDownAmount = new NumericUpDown(); + buttonSave = new Button(); + buttonCancel = new Button(); + checkedListBoxCategory = new CheckedListBox(); + groupBoxMaterials = new GroupBox(); + dataGridViewMaterials = new DataGridView(); + ColumnMaterial = new DataGridViewComboBoxColumn(); + ColumnAmount = new DataGridViewTextBoxColumn(); + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownAmount).BeginInit(); + groupBoxMaterials.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewMaterials).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(30, 24); + labelName.Name = "labelName"; + labelName.Size = new Size(59, 15); + labelName.TabIndex = 0; + labelName.Text = "Название"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(30, 59); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(35, 15); + labelPrice.TabIndex = 1; + labelPrice.Text = "Цена"; + // + // labelWHamount + // + labelWHamount.AutoSize = true; + labelWHamount.Location = new Point(30, 95); + labelWHamount.Name = "labelWHamount"; + labelWHamount.Size = new Size(128, 15); + labelWHamount.TabIndex = 2; + labelWHamount.Text = "Количество на складе"; + // + // labelCategory + // + labelCategory.AutoSize = true; + labelCategory.Location = new Point(30, 130); + labelCategory.Name = "labelCategory"; + labelCategory.Size = new Size(63, 15); + labelCategory.TabIndex = 3; + labelCategory.Text = "Категория"; + // + // textBoxName + // + textBoxName.Location = new Point(197, 21); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(100, 23); + textBoxName.TabIndex = 4; + // + // numericUpDownPrice + // + numericUpDownPrice.DecimalPlaces = 2; + numericUpDownPrice.Location = new Point(197, 57); + numericUpDownPrice.Minimum = new decimal(new int[] { 1, 0, 0, 65536 }); + numericUpDownPrice.Name = "numericUpDownPrice"; + numericUpDownPrice.Size = new Size(120, 23); + numericUpDownPrice.TabIndex = 5; + numericUpDownPrice.Value = new decimal(new int[] { 1, 0, 0, 65536 }); + // + // numericUpDownAmount + // + numericUpDownAmount.Location = new Point(197, 93); + numericUpDownAmount.Name = "numericUpDownAmount"; + numericUpDownAmount.Size = new Size(120, 23); + numericUpDownAmount.TabIndex = 6; + // + // buttonSave + // + buttonSave.Location = new Point(108, 223); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(222, 223); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // checkedListBoxCategory + // + checkedListBoxCategory.FormattingEnabled = true; + checkedListBoxCategory.Location = new Point(197, 122); + checkedListBoxCategory.Name = "checkedListBoxCategory"; + checkedListBoxCategory.Size = new Size(187, 76); + checkedListBoxCategory.TabIndex = 10; + // + // groupBoxMaterials + // + groupBoxMaterials.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBoxMaterials.Controls.Add(dataGridViewMaterials); + groupBoxMaterials.Location = new Point(418, 12); + groupBoxMaterials.Name = "groupBoxMaterials"; + groupBoxMaterials.Size = new Size(408, 233); + groupBoxMaterials.TabIndex = 11; + groupBoxMaterials.TabStop = false; + groupBoxMaterials.Text = "Материалы"; + // + // dataGridViewMaterials + // + dataGridViewMaterials.AllowUserToResizeColumns = false; + dataGridViewMaterials.AllowUserToResizeRows = false; + dataGridViewMaterials.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewMaterials.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewMaterials.Columns.AddRange(new DataGridViewColumn[] { ColumnMaterial, ColumnAmount }); + dataGridViewMaterials.Dock = DockStyle.Fill; + dataGridViewMaterials.Location = new Point(3, 19); + dataGridViewMaterials.MultiSelect = false; + dataGridViewMaterials.Name = "dataGridViewMaterials"; + dataGridViewMaterials.RowHeadersVisible = false; + dataGridViewMaterials.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewMaterials.Size = new Size(402, 211); + dataGridViewMaterials.TabIndex = 0; + // + // ColumnMaterial + // + ColumnMaterial.HeaderText = "Материал"; + ColumnMaterial.Name = "ColumnMaterial"; + // + // ColumnAmount + // + ColumnAmount.HeaderText = "Количество"; + ColumnAmount.Name = "ColumnAmount"; + // + // FormProduct + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(882, 257); + Controls.Add(groupBoxMaterials); + Controls.Add(checkedListBoxCategory); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(numericUpDownAmount); + Controls.Add(numericUpDownPrice); + Controls.Add(textBoxName); + Controls.Add(labelCategory); + Controls.Add(labelWHamount); + Controls.Add(labelPrice); + Controls.Add(labelName); + Name = "FormProduct"; + StartPosition = FormStartPosition.CenterParent; + Text = "FormProduct"; + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); + ((System.ComponentModel.ISupportInitialize)numericUpDownAmount).EndInit(); + groupBoxMaterials.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewMaterials).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelPrice; + private Label labelWHamount; + private Label labelCategory; + private TextBox textBoxName; + private NumericUpDown numericUpDownPrice; + private NumericUpDown numericUpDownAmount; + private Button buttonSave; + private Button buttonCancel; + private CheckedListBox checkedListBoxCategory; + private GroupBox groupBoxMaterials; + private DataGridView dataGridViewMaterials; + private DataGridViewComboBoxColumn ColumnMaterial; + private DataGridViewTextBoxColumn ColumnAmount; + } +} \ No newline at end of file diff --git a/Workshop/Forms/FormProduct.cs b/Workshop/Forms/FormProduct.cs new file mode 100644 index 0000000..bcc9822 --- /dev/null +++ b/Workshop/Forms/FormProduct.cs @@ -0,0 +1,120 @@ +using Microsoft.VisualBasic.FileIO; +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 Workshop.Entities; +using Workshop.Entities.Enums; +using Workshop.Repositories; + +namespace Workshop.Forms +{ + public partial class FormProduct : Form + { + private readonly IProductRepository _productRepository; + private int? _productId; + public int Id + { + set + { + try + { + var product = _productRepository.ReadProductById(value); + if (product == null) + { + throw new InvalidDataException(nameof(product)); + } + foreach (ProductCategory elem in Enum.GetValues(typeof(ProductCategory))) + { + if ((elem & product.Category) != 0) + { + checkedListBoxCategory.SetItemChecked(checkedListBoxCategory.Items.IndexOf(elem), true); + } + } + textBoxName.Text = product.Name; + numericUpDownPrice.Value = (decimal)product.Price; + numericUpDownAmount.Value = product.WarehouseAmount; + _productId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormProduct(IProductRepository productRepository, IMaterialRepository materialRepos) + { + InitializeComponent(); + _productRepository = productRepository ?? + throw new ArgumentNullException(nameof(productRepository)); + foreach (var el in Enum.GetValues(typeof(ProductCategory))) + { + checkedListBoxCategory.Items.Add(el); + } + ColumnMaterial.DataSource = materialRepos.ReadMaterials(); + ColumnMaterial.DisplayMember = "Name"; + ColumnMaterial.ValueMember = "Id"; + } + + private void buttonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrWhiteSpace(textBoxName.Text) || checkedListBoxCategory.CheckedItems.Count == 0 + || dataGridViewMaterials.RowCount < 2) + { + 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 Product CreateProduct(int id) + { + ProductCategory productCategory = ProductCategory.None; + foreach (var el in checkedListBoxCategory.CheckedItems) + { + productCategory |= (ProductCategory)el; + } + return Product.CreateEntity(id, + textBoxName.Text, + Convert.ToDouble(numericUpDownPrice.Value), + Convert.ToInt32(numericUpDownAmount.Value), + productCategory, + CreateListFromGridMaterial()); + } + private List CreateListFromGridMaterial() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridViewMaterials.Rows) + { + if (row.Cells["ColumnMaterial"].Value == null || row.Cells["ColumnAmount"].Value == null) + { + continue; + } + list.Add(ProductMaterial.CreateEntity(0, Convert.ToInt32(row.Cells["ColumnMaterial"].Value), + Convert.ToInt32(row.Cells["ColumnAmount"].Value))); + } + return list; + + } + private void buttonCancel_Click(object sender, EventArgs e) => Close(); + } +} diff --git a/Workshop/Forms/FormProduct.resx b/Workshop/Forms/FormProduct.resx new file mode 100644 index 0000000..b182ff2 --- /dev/null +++ b/Workshop/Forms/FormProduct.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/Workshop/Forms/FormProductCreate.Designer.cs b/Workshop/Forms/FormProductCreate.Designer.cs new file mode 100644 index 0000000..8b21b1c --- /dev/null +++ b/Workshop/Forms/FormProductCreate.Designer.cs @@ -0,0 +1,144 @@ +namespace Workshop.Forms +{ + partial class FormProductCreate + { + /// + /// 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() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + dateTimePickerDate = new DateTimePicker(); + comboBoxProduct = new ComboBox(); + comboBoxMaster = new ComboBox(); + buttonSave = new Button(); + buttonDel = new Button(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(47, 33); + label1.Name = "label1"; + label1.Size = new Size(53, 15); + label1.TabIndex = 0; + label1.Text = "Изделие"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(47, 77); + label2.Name = "label2"; + label2.Size = new Size(48, 15); + label2.TabIndex = 1; + label2.Text = "Мастер"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(47, 122); + label3.Name = "label3"; + label3.Size = new Size(35, 15); + label3.TabIndex = 2; + label3.Text = "Дата:"; + // + // dateTimePickerDate + // + dateTimePickerDate.Enabled = false; + dateTimePickerDate.Location = new Point(153, 116); + dateTimePickerDate.Name = "dateTimePickerDate"; + dateTimePickerDate.Size = new Size(121, 23); + dateTimePickerDate.TabIndex = 3; + // + // comboBoxProduct + // + comboBoxProduct.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxProduct.FormattingEnabled = true; + comboBoxProduct.Location = new Point(153, 30); + comboBoxProduct.Name = "comboBoxProduct"; + comboBoxProduct.Size = new Size(121, 23); + comboBoxProduct.TabIndex = 4; + // + // comboBoxMaster + // + comboBoxMaster.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxMaster.FormattingEnabled = true; + comboBoxMaster.Location = new Point(153, 74); + comboBoxMaster.Name = "comboBoxMaster"; + comboBoxMaster.Size = new Size(121, 23); + comboBoxMaster.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(61, 192); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // buttonDel + // + buttonDel.Location = new Point(177, 192); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(75, 23); + buttonDel.TabIndex = 7; + buttonDel.Text = "Отмена"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += buttonDel_Click; + // + // FormProductCreate + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(315, 259); + Controls.Add(buttonDel); + Controls.Add(buttonSave); + Controls.Add(comboBoxMaster); + Controls.Add(comboBoxProduct); + Controls.Add(dateTimePickerDate); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormProductCreate"; + Text = "FormProductCreate"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private DateTimePicker dateTimePickerDate; + private ComboBox comboBoxProduct; + private ComboBox comboBoxMaster; + private Button buttonSave; + private Button buttonDel; + } +} \ No newline at end of file diff --git a/Workshop/Forms/FormProductCreate.cs b/Workshop/Forms/FormProductCreate.cs new file mode 100644 index 0000000..0c95927 --- /dev/null +++ b/Workshop/Forms/FormProductCreate.cs @@ -0,0 +1,57 @@ +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 Workshop.Entities; +using Workshop.Repositories; + +namespace Workshop.Forms +{ + public partial class FormProductCreate : Form + { + private readonly IProductCreateRepository _createProductRepository; + public FormProductCreate(IProductCreateRepository productCreateRepository, IProductRepository productRepository, + IMasterRepository masterRepository) + { + InitializeComponent(); + _createProductRepository = productCreateRepository ?? + throw new ArgumentNullException(nameof(productCreateRepository)); + comboBoxProduct.DataSource = productRepository.ReadProducts(); + comboBoxProduct.DisplayMember = "Name"; + comboBoxProduct.ValueMember = "Id"; + + comboBoxMaster.DataSource = masterRepository.ReadMasters(); + comboBoxMaster.DisplayMember = "Name"; + comboBoxMaster.ValueMember = "Id"; + + } + + private void buttonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxProduct.SelectedIndex < 0 || comboBoxMaster.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + _createProductRepository.CreateProductCreate(ProductCreate.CreateOperation( + 0, + (int)comboBoxProduct.SelectedValue!, + (int)comboBoxMaster.SelectedValue!)); + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void buttonDel_Click(object sender, EventArgs e) => Close(); + } +} diff --git a/Workshop/Forms/FormProductCreate.resx b/Workshop/Forms/FormProductCreate.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Workshop/Forms/FormProductCreate.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/Workshop/Forms/FormProductCreatings.Designer.cs b/Workshop/Forms/FormProductCreatings.Designer.cs new file mode 100644 index 0000000..7ec2cce --- /dev/null +++ b/Workshop/Forms/FormProductCreatings.Designer.cs @@ -0,0 +1,112 @@ +namespace Workshop.Forms +{ + partial class FormProductCreatings + { + /// + /// 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() + { + panel = new Panel(); + buttonRemove = new Button(); + buttonAdd = new Button(); + dataGridProductCreatings = new DataGridView(); + panel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridProductCreatings).BeginInit(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(buttonRemove); + panel.Controls.Add(buttonAdd); + panel.Dock = DockStyle.Right; + panel.Location = new Point(600, 0); + panel.Name = "panel"; + panel.Size = new Size(200, 450); + panel.TabIndex = 0; + // + // buttonRemove + // + buttonRemove.BackgroundImage = Properties.Resources.Remove; + buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; + buttonRemove.Location = new Point(55, 142); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(75, 75); + buttonRemove.TabIndex = 1; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Add; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(55, 39); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 75); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridProductCreatings + // + dataGridProductCreatings.AllowUserToAddRows = false; + dataGridProductCreatings.AllowUserToDeleteRows = false; + dataGridProductCreatings.AllowUserToResizeColumns = false; + dataGridProductCreatings.AllowUserToResizeRows = false; + dataGridProductCreatings.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridProductCreatings.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridProductCreatings.Dock = DockStyle.Fill; + dataGridProductCreatings.Location = new Point(0, 0); + dataGridProductCreatings.MultiSelect = false; + dataGridProductCreatings.Name = "dataGridProductCreatings"; + dataGridProductCreatings.ReadOnly = true; + dataGridProductCreatings.RowHeadersVisible = false; + dataGridProductCreatings.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridProductCreatings.Size = new Size(600, 450); + dataGridProductCreatings.TabIndex = 1; + // + // FormProductCreatings + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridProductCreatings); + Controls.Add(panel); + Name = "FormProductCreatings"; + StartPosition = FormStartPosition.CenterParent; + Text = "Изделия"; + Load += FormProductCreatings_Load; + panel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridProductCreatings).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel; + private Button buttonRemove; + private Button buttonAdd; + private DataGridView dataGridProductCreatings; + } +} \ No newline at end of file diff --git a/Workshop/Forms/FormProductCreatings.cs b/Workshop/Forms/FormProductCreatings.cs new file mode 100644 index 0000000..9f25875 --- /dev/null +++ b/Workshop/Forms/FormProductCreatings.cs @@ -0,0 +1,85 @@ +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; +using Workshop.Repositories; + +namespace Workshop.Forms +{ + public partial class FormProductCreatings : Form + { + private readonly IUnityContainer _container; + private readonly IProductCreateRepository _productCreateRepository; + public FormProductCreatings(IUnityContainer container, IProductCreateRepository productCreateRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _productCreateRepository = productCreateRepository ?? + throw new ArgumentNullException(nameof(productCreateRepository)); + } + private void FormProductCreatings_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 + { + _productCreateRepository.DeleteProductCreate(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void LoadList() => dataGridProductCreatings.DataSource = _productCreateRepository.ReadProductCreates(); + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridProductCreatings.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridProductCreatings.SelectedRows[0].Cells["Id"].Value); + return true; + } + + } +} diff --git a/Workshop/Forms/FormProductCreatings.resx b/Workshop/Forms/FormProductCreatings.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Workshop/Forms/FormProductCreatings.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/Workshop/Forms/FormProducts.Designer.cs b/Workshop/Forms/FormProducts.Designer.cs new file mode 100644 index 0000000..a2bdfc7 --- /dev/null +++ b/Workshop/Forms/FormProducts.Designer.cs @@ -0,0 +1,126 @@ +namespace Workshop.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() + { + panel = new Panel(); + buttonEdit = new Button(); + buttonRemove = new Button(); + buttonAdd = new Button(); + dataGridViewProducts = new DataGridView(); + panel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewProducts).BeginInit(); + SuspendLayout(); + // + // panel + // + panel.Controls.Add(buttonEdit); + panel.Controls.Add(buttonRemove); + panel.Controls.Add(buttonAdd); + panel.Dock = DockStyle.Right; + panel.Location = new Point(600, 0); + panel.Name = "panel"; + panel.Size = new Size(200, 450); + panel.TabIndex = 0; + // + // buttonEdit + // + buttonEdit.BackgroundImage = Properties.Resources.Edit; + buttonEdit.BackgroundImageLayout = ImageLayout.Stretch; + buttonEdit.Location = new Point(55, 248); + buttonEdit.Name = "buttonEdit"; + buttonEdit.Size = new Size(75, 75); + buttonEdit.TabIndex = 2; + buttonEdit.UseVisualStyleBackColor = true; + buttonEdit.Click += buttonEdit_Click; + // + // buttonRemove + // + buttonRemove.BackgroundImage = Properties.Resources.Remove; + buttonRemove.BackgroundImageLayout = ImageLayout.Stretch; + buttonRemove.Location = new Point(55, 142); + buttonRemove.Name = "buttonRemove"; + buttonRemove.Size = new Size(75, 75); + buttonRemove.TabIndex = 1; + buttonRemove.UseVisualStyleBackColor = true; + buttonRemove.Click += buttonRemove_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.Add; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(55, 39); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 75); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += buttonAdd_Click; + // + // dataGridViewProducts + // + dataGridViewProducts.AllowUserToAddRows = false; + dataGridViewProducts.AllowUserToDeleteRows = false; + dataGridViewProducts.AllowUserToResizeColumns = false; + dataGridViewProducts.AllowUserToResizeRows = false; + dataGridViewProducts.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewProducts.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewProducts.Dock = DockStyle.Fill; + dataGridViewProducts.Location = new Point(0, 0); + dataGridViewProducts.MultiSelect = false; + dataGridViewProducts.Name = "dataGridViewProducts"; + dataGridViewProducts.ReadOnly = true; + dataGridViewProducts.RowHeadersVisible = false; + dataGridViewProducts.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewProducts.Size = new Size(600, 450); + dataGridViewProducts.TabIndex = 1; + // + // FormProducts + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewProducts); + Controls.Add(panel); + Name = "FormProducts"; + StartPosition = FormStartPosition.CenterParent; + Text = "Изделия"; + Load += FormProducts_Load; + panel.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewProducts).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel; + private Button buttonEdit; + private Button buttonRemove; + private Button buttonAdd; + private DataGridView dataGridViewProducts; + } +} \ No newline at end of file diff --git a/Workshop/Forms/FormProducts.cs b/Workshop/Forms/FormProducts.cs new file mode 100644 index 0000000..d53e9e9 --- /dev/null +++ b/Workshop/Forms/FormProducts.cs @@ -0,0 +1,105 @@ +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; +using Workshop.Repositories; + +namespace Workshop.Forms +{ + public partial class FormProducts : Form + { + private readonly IUnityContainer _container; + private readonly IProductRepository _productRepository; + public FormProducts(IUnityContainer container, IProductRepository productRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _productRepository = productRepository ?? + throw new ArgumentNullException(nameof(productRepository)); + } + private void FormProducts_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void buttonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", + MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonRemove_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", + MessageBoxButtons.YesNo) != DialogResult.Yes) + { + } + try + { + _productRepository.DeleteProduct(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void buttonEdit_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 bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewProducts.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = Convert.ToInt32(dataGridViewProducts.SelectedRows[0].Cells["Id"].Value); + return true; + } + private void LoadList() => dataGridViewProducts.DataSource = _productRepository.ReadProducts(); + } +} diff --git a/Workshop/Forms/FormProducts.resx b/Workshop/Forms/FormProducts.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/Workshop/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/Workshop/Program.cs b/Workshop/Program.cs new file mode 100644 index 0000000..7337a0e --- /dev/null +++ b/Workshop/Program.cs @@ -0,0 +1,31 @@ +using Unity; +using Unity.Lifetime; +using Workshop.Repositories; +using Workshop.Repositories.Implementations; +namespace Workshop +{ + internal static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + // To customize application configuration such as set high DPI settings or default font, + // see https://aka.ms/applicationconfiguration. + ApplicationConfiguration.Initialize(); + Application.Run(CreateContainer().Resolve()); + } + private static IUnityContainer CreateContainer() + { + var container = new UnityContainer(); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + container.RegisterType(new TransientLifetimeManager()); + return container; + } + } +} \ No newline at end of file diff --git a/Workshop/Properties/Resources.Designer.cs b/Workshop/Properties/Resources.Designer.cs new file mode 100644 index 0000000..6d3355c --- /dev/null +++ b/Workshop/Properties/Resources.Designer.cs @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +// +// Этот код создан программой. +// Исполняемая версия:4.0.30319.42000 +// +// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае +// повторной генерации кода. +// +//------------------------------------------------------------------------------ + +namespace Workshop.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("Workshop.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 Add { + get { + object obj = ResourceManager.GetObject("Add", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа 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 Remove { + get { + object obj = ResourceManager.GetObject("Remove", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + + /// + /// Поиск локализованного ресурса типа System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap st4_1 { + get { + object obj = ResourceManager.GetObject("st4-1", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + } +} diff --git a/Workshop/Properties/Resources.resx b/Workshop/Properties/Resources.resx new file mode 100644 index 0000000..0c0cbea --- /dev/null +++ b/Workshop/Properties/Resources.resx @@ -0,0 +1,133 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + ..\Resources\st4-1.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Add.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Edit.jpg;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + + ..\Resources\Remove1.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + \ No newline at end of file diff --git a/Workshop/Repositories/IChequeRepository.cs b/Workshop/Repositories/IChequeRepository.cs new file mode 100644 index 0000000..0da2c72 --- /dev/null +++ b/Workshop/Repositories/IChequeRepository.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Workshop.Entities; + +namespace Workshop.Repositories; + +public interface IChequeRepository +{ + IEnumerable ReadCheques(DateTime? dateFrom = null, DateTime? dateTo = null, int? chequeId = null); + void CreateCheque(Cheque cheque); + void DeleteCheque(int id); +} diff --git a/Workshop/Repositories/IMasterRepository.cs b/Workshop/Repositories/IMasterRepository.cs new file mode 100644 index 0000000..36c9979 --- /dev/null +++ b/Workshop/Repositories/IMasterRepository.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Workshop.Entities; + +namespace Workshop.Repositories; + +public interface IMasterRepository +{ + IEnumerable ReadMasters(); + Master ReadMasterById(int id); + void CreateMaster(Master Master); + void UpdateMaster(Master Master); + void DeleteMaster(int id); +} diff --git a/Workshop/Repositories/IMaterialRepository.cs b/Workshop/Repositories/IMaterialRepository.cs new file mode 100644 index 0000000..0eb4afa --- /dev/null +++ b/Workshop/Repositories/IMaterialRepository.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Workshop.Entities; + +namespace Workshop.Repositories; + +public interface IMaterialRepository +{ + IEnumerable ReadMaterials(); + Material ReadMaterialById(int id); + void CreateMaterial(Material Material); + void UpdateMaterial(Material Material); + void DeleteMaterial(int id); +} diff --git a/Workshop/Repositories/IProductCreateRepository.cs b/Workshop/Repositories/IProductCreateRepository.cs new file mode 100644 index 0000000..894df04 --- /dev/null +++ b/Workshop/Repositories/IProductCreateRepository.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Workshop.Entities; + +namespace Workshop.Repositories; + +public interface IProductCreateRepository +{ + IEnumerable ReadProductCreates(DateTime? dateFrom = null, DateTime? dateTo = null, int? productId = null, int? masterId = null); + void CreateProductCreate(ProductCreate productCreate); + void DeleteProductCreate(int id); +} diff --git a/Workshop/Repositories/IProductRepository.cs b/Workshop/Repositories/IProductRepository.cs new file mode 100644 index 0000000..28088bb --- /dev/null +++ b/Workshop/Repositories/IProductRepository.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Workshop.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/Workshop/Repositories/Implementations/ChequeRepository.cs b/Workshop/Repositories/Implementations/ChequeRepository.cs new file mode 100644 index 0000000..fda192f --- /dev/null +++ b/Workshop/Repositories/Implementations/ChequeRepository.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Workshop.Entities; +using Workshop.Repositories; + +namespace Workshop.Repositories.Implementations; + +internal class ChequeRepository : IChequeRepository +{ + public void CreateCheque(Cheque cheque) + { + } + + public void DeleteCheque(int id) + { + } + + public IEnumerable ReadCheques(DateTime? dateFrom = null, DateTime? dateTo = null, int? chequeId = null) + { + return []; + } +} diff --git a/Workshop/Repositories/Implementations/MasterRepository.cs b/Workshop/Repositories/Implementations/MasterRepository.cs new file mode 100644 index 0000000..7b6f2ea --- /dev/null +++ b/Workshop/Repositories/Implementations/MasterRepository.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Workshop.Entities; +using Workshop.Repositories; + +namespace Workshop.Repositories.Implementations; + +internal class MasterRepository : IMasterRepository +{ + public void CreateMaster(Master Master) + { + } + + public void DeleteMaster(int id) + { + } + + public Master ReadMasterById(int id) + { + return Master.CreateEntity(0, string.Empty, string.Empty, 0, Entities.Enums.MasterPosition.None); + } + + public IEnumerable ReadMasters() + { + return []; + } + + public void UpdateMaster(Master Master) + { + } +} diff --git a/Workshop/Repositories/Implementations/MaterialRepository.cs b/Workshop/Repositories/Implementations/MaterialRepository.cs new file mode 100644 index 0000000..ba9f8b1 --- /dev/null +++ b/Workshop/Repositories/Implementations/MaterialRepository.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Workshop.Entities; +using Workshop.Repositories; + +namespace Workshop.Repositories.Implementations; + +internal class MaterialRepository : IMaterialRepository +{ + public void CreateMaterial(Material Material) + { + } + + public void DeleteMaterial(int id) + { + } + + public Material ReadMaterialById(int id) + { + return Material.CreateEntity(0, string.Empty, 0, 0); + } + + public IEnumerable ReadMaterials() + { + return []; + } + + public void UpdateMaterial(Material Material) + { + } +} diff --git a/Workshop/Repositories/Implementations/ProductCreateRepository.cs b/Workshop/Repositories/Implementations/ProductCreateRepository.cs new file mode 100644 index 0000000..2d1d094 --- /dev/null +++ b/Workshop/Repositories/Implementations/ProductCreateRepository.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Workshop.Entities; +using Workshop.Repositories; + +namespace Workshop.Repositories.Implementations; + +internal class ProductCreateRepository : IProductCreateRepository +{ + public void CreateProductCreate(ProductCreate productCreate) + { + } + + public void DeleteProductCreate(int id) + { + } + + public IEnumerable ReadProductCreates(DateTime? dateFrom = null, DateTime? dateTo = null, int? productId = null, int? masterId = null) + { + return []; + } +} diff --git a/Workshop/Repositories/Implementations/ProductRepository.cs b/Workshop/Repositories/Implementations/ProductRepository.cs new file mode 100644 index 0000000..492f597 --- /dev/null +++ b/Workshop/Repositories/Implementations/ProductRepository.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Workshop.Repositories; + +namespace Workshop.Repositories.Implementations; + +internal class ProductRepository : IProductRepository +{ + public void CreateProduct(Product product) + { + } + + public void DeleteProduct(int id) + { + } + + public Product ReadProductById(int id) + { + return Product.CreateEntity(0, string.Empty, 0, 0, Entities.Enums.ProductCategory.None, []); + } + + public IEnumerable ReadProducts() + { + return []; + } + + public void UpdateProduct(Product product) + { + } +} diff --git a/Workshop/Resources/Add.png b/Workshop/Resources/Add.png new file mode 100644 index 0000000..3c735e7 Binary files /dev/null and b/Workshop/Resources/Add.png differ diff --git a/Workshop/Resources/Edit.jpg b/Workshop/Resources/Edit.jpg new file mode 100644 index 0000000..95cc215 Binary files /dev/null and b/Workshop/Resources/Edit.jpg differ diff --git a/Workshop/Resources/Remove.png b/Workshop/Resources/Remove.png new file mode 100644 index 0000000..be19e00 Binary files /dev/null and b/Workshop/Resources/Remove.png differ diff --git a/Workshop/Resources/Remove1.png b/Workshop/Resources/Remove1.png new file mode 100644 index 0000000..be19e00 Binary files /dev/null and b/Workshop/Resources/Remove1.png differ diff --git a/Workshop/Resources/st4-1.jpg b/Workshop/Resources/st4-1.jpg new file mode 100644 index 0000000..e131f34 Binary files /dev/null and b/Workshop/Resources/st4-1.jpg differ diff --git a/Workshop/Workshop.csproj b/Workshop/Workshop.csproj new file mode 100644 index 0000000..accbdf0 --- /dev/null +++ b/Workshop/Workshop.csproj @@ -0,0 +1,30 @@ + + + + WinExe + net8.0-windows + enable + true + enable + + + + + + + + + True + True + Resources.resx + + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + \ No newline at end of file diff --git a/Workshop/Workshop.sln b/Workshop/Workshop.sln new file mode 100644 index 0000000..3c8c67c --- /dev/null +++ b/Workshop/Workshop.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.11.35327.3 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Workshop", "Workshop.csproj", "{52C743B8-8D2C-46A2-A657-F84992C58400}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {52C743B8-8D2C-46A2-A657-F84992C58400}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {52C743B8-8D2C-46A2-A657-F84992C58400}.Debug|Any CPU.Build.0 = Debug|Any CPU + {52C743B8-8D2C-46A2-A657-F84992C58400}.Release|Any CPU.ActiveCfg = Release|Any CPU + {52C743B8-8D2C-46A2-A657-F84992C58400}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {1F4B0F8C-0C4F-48A3-B32A-BC9187E66866} + EndGlobalSection +EndGlobal