diff --git a/ProjectWorkshop/Entities/Assembly.cs b/ProjectWorkshop/Entities/Assembly.cs index 3ad965c..03b006b 100644 --- a/ProjectWorkshop/Entities/Assembly.cs +++ b/ProjectWorkshop/Entities/Assembly.cs @@ -1,4 +1,6 @@ -namespace ProjectWorkshop.Entities; +using ProjectWorkshop.Entities.Enums; + +namespace ProjectWorkshop.Entities; public class Assembly { @@ -6,9 +8,9 @@ public class Assembly public int Count { get; private set; } - public string ProductType { get; private set; } = string.Empty; + public ProductType ProductType { get; private set; } - public static Assembly CreateEntity(int id, int count, string productType) + public static Assembly CreateElement(int id, int count, ProductType productType) { return new Assembly() { diff --git a/ProjectWorkshop/Entities/ProductAssembly.cs b/ProjectWorkshop/Entities/ProductAssembly.cs index 5264e6f..2563244 100644 --- a/ProjectWorkshop/Entities/ProductAssembly.cs +++ b/ProjectWorkshop/Entities/ProductAssembly.cs @@ -8,13 +8,16 @@ public class ProductAssembly public int Count { get; private set; } - public static ProductAssembly CreateOperation(int productID, int assemblyID, int count) + public IEnumerable ProductAssemblies { get; private set; } = []; + + public static ProductAssembly CreateOperation(int productID, int assemblyID, int count, IEnumerable productAssemblies) { return new ProductAssembly() { ProductId = productID, AssemblyID = assemblyID, - Count = count + Count = count, + ProductAssemblies = productAssemblies }; } } diff --git a/ProjectWorkshop/FormWorkshop.Designer.cs b/ProjectWorkshop/FormWorkshop.Designer.cs index 9c35e20..0858804 100644 --- a/ProjectWorkshop/FormWorkshop.Designer.cs +++ b/ProjectWorkshop/FormWorkshop.Designer.cs @@ -29,69 +29,74 @@ private void InitializeComponent() { menuStrip = new MenuStrip(); - справочникиToolStripMenuItem = new ToolStripMenuItem(); - сборщикиToolStripMenuItem = new ToolStripMenuItem(); - сборкиToolStripMenuItem = new ToolStripMenuItem(); - изделияToolStripMenuItem = new ToolStripMenuItem(); + manualToolStripMenuItem = new ToolStripMenuItem(); + AssemblersToolStripMenuItem = new ToolStripMenuItem(); + AssembliesToolStripMenuItem = new ToolStripMenuItem(); + ProductsToolStripMenuItem = new ToolStripMenuItem(); операцииToolStripMenuItem = new ToolStripMenuItem(); - сборкаToolStripMenuItem = new ToolStripMenuItem(); - ВыйтиНаСменуToolStripMenuItem = new ToolStripMenuItem(); + ProductAssemblyToolStripMenuItem = new ToolStripMenuItem(); + AssemblerShiftToolStripMenuItem = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); SuspendLayout(); // // menuStrip // - menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { manualToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Size = new Size(784, 24); menuStrip.TabIndex = 0; menuStrip.Text = "menuStrip"; // - // справочникиToolStripMenuItem + // manualToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { сборщикиToolStripMenuItem, сборкиToolStripMenuItem, изделияToolStripMenuItem }); - справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; - справочникиToolStripMenuItem.Size = new Size(94, 20); - справочникиToolStripMenuItem.Text = "Справочники"; + manualToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { AssemblersToolStripMenuItem, AssembliesToolStripMenuItem, ProductsToolStripMenuItem }); + manualToolStripMenuItem.Name = "manualToolStripMenuItem"; + manualToolStripMenuItem.Size = new Size(94, 20); + manualToolStripMenuItem.Text = "Справочники"; // - // сборщикиToolStripMenuItem + // AssemblersToolStripMenuItem // - сборщикиToolStripMenuItem.Name = "сборщикиToolStripMenuItem"; - сборщикиToolStripMenuItem.Size = new Size(134, 22); - сборщикиToolStripMenuItem.Text = "Сборщики"; + AssemblersToolStripMenuItem.Name = "AssemblersToolStripMenuItem"; + AssemblersToolStripMenuItem.Size = new Size(134, 22); + AssemblersToolStripMenuItem.Text = "Сборщики"; + AssemblersToolStripMenuItem.Click += AssemblersToolStripMenuItem_Click_1; // - // сборкиToolStripMenuItem + // AssembliesToolStripMenuItem // - сборкиToolStripMenuItem.Name = "сборкиToolStripMenuItem"; - сборкиToolStripMenuItem.Size = new Size(134, 22); - сборкиToolStripMenuItem.Text = "Сборки"; + AssembliesToolStripMenuItem.Name = "AssembliesToolStripMenuItem"; + AssembliesToolStripMenuItem.Size = new Size(134, 22); + AssembliesToolStripMenuItem.Text = "Сборки"; + AssembliesToolStripMenuItem.Click += AssembliesToolStripMenuItem_Click_1; // - // изделияToolStripMenuItem + // ProductsToolStripMenuItem // - изделияToolStripMenuItem.Name = "изделияToolStripMenuItem"; - изделияToolStripMenuItem.Size = new Size(134, 22); - изделияToolStripMenuItem.Text = "Изделия"; + ProductsToolStripMenuItem.Name = "ProductsToolStripMenuItem"; + ProductsToolStripMenuItem.Size = new Size(134, 22); + ProductsToolStripMenuItem.Text = "Изделия"; + ProductsToolStripMenuItem.Click += ProductsToolStripMenuItem_Click_1; // // операцииToolStripMenuItem // - операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { сборкаToolStripMenuItem, ВыйтиНаСменуToolStripMenuItem }); + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { ProductAssemblyToolStripMenuItem, AssemblerShiftToolStripMenuItem }); операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; операцииToolStripMenuItem.Size = new Size(75, 20); операцииToolStripMenuItem.Text = "Операции"; // - // сборкаToolStripMenuItem + // ProductAssemblyToolStripMenuItem // - сборкаToolStripMenuItem.Name = "сборкаToolStripMenuItem"; - сборкаToolStripMenuItem.Size = new Size(192, 22); - сборкаToolStripMenuItem.Text = "Сборка"; + ProductAssemblyToolStripMenuItem.Name = "ProductAssemblyToolStripMenuItem"; + ProductAssemblyToolStripMenuItem.Size = new Size(180, 22); + ProductAssemblyToolStripMenuItem.Text = "Сборка"; + ProductAssemblyToolStripMenuItem.Click += ProductAssemblyToolStripMenuItem_Click_1; // - // ВыйтиНаСменуToolStripMenuItem + // AssemblerShiftToolStripMenuItem // - ВыйтиНаСменуToolStripMenuItem.Name = "ВыйтиНаСменуToolStripMenuItem"; - ВыйтиНаСменуToolStripMenuItem.Size = new Size(180, 22); - ВыйтиНаСменуToolStripMenuItem.Text = "Выйти на Смену"; + AssemblerShiftToolStripMenuItem.Name = "AssemblerShiftToolStripMenuItem"; + AssemblerShiftToolStripMenuItem.Size = new Size(180, 22); + AssemblerShiftToolStripMenuItem.Text = "Выйти на Смену"; + AssemblerShiftToolStripMenuItem.Click += AssemblerShiftToolStripMenuItem_Click_1; // // отчетыToolStripMenuItem // @@ -120,13 +125,13 @@ #endregion private MenuStrip menuStrip; - private ToolStripMenuItem справочникиToolStripMenuItem; - private ToolStripMenuItem сборщикиToolStripMenuItem; - private ToolStripMenuItem сборкиToolStripMenuItem; - private ToolStripMenuItem изделияToolStripMenuItem; + private ToolStripMenuItem manualToolStripMenuItem; + private ToolStripMenuItem AssemblersToolStripMenuItem; + private ToolStripMenuItem AssembliesToolStripMenuItem; + private ToolStripMenuItem ProductsToolStripMenuItem; private ToolStripMenuItem операцииToolStripMenuItem; private ToolStripMenuItem отчетыToolStripMenuItem; - private ToolStripMenuItem сборкаToolStripMenuItem; - private ToolStripMenuItem ВыйтиНаСменуToolStripMenuItem; + private ToolStripMenuItem ProductAssemblyToolStripMenuItem; + private ToolStripMenuItem AssemblerShiftToolStripMenuItem; } } diff --git a/ProjectWorkshop/FormWorkshop.cs b/ProjectWorkshop/FormWorkshop.cs index ea437dc..ccad263 100644 --- a/ProjectWorkshop/FormWorkshop.cs +++ b/ProjectWorkshop/FormWorkshop.cs @@ -1,13 +1,78 @@ +using ProjectWorkshop.Forms; using ProjectWorkshop.Repositories; +using Unity; namespace ProjectWorkshop { public partial class FormWorkshop : Form { - - public FormWorkshop() + private readonly IUnityContainer _container; + + public FormWorkshop(IUnityContainer container) { InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + } + + private void AssemblersToolStripMenuItem_Click_1(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AssembliesToolStripMenuItem_Click_1(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ProductsToolStripMenuItem_Click_1(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ProductAssemblyToolStripMenuItem_Click_1(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void AssemblerShiftToolStripMenuItem_Click_1(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } } } diff --git a/ProjectWorkshop/Forms/FormAssemblerShifts.Designer.cs b/ProjectWorkshop/Forms/FormAssemblerShifts.Designer.cs new file mode 100644 index 0000000..4e1f08b --- /dev/null +++ b/ProjectWorkshop/Forms/FormAssemblerShifts.Designer.cs @@ -0,0 +1,97 @@ +namespace ProjectWorkshop.Forms +{ + partial class FormAssemblerShifts + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + dataGridView = new DataGridView(); + panel1 = new Panel(); + buttonAdd = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + panel1.SuspendLayout(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(647, 450); + dataGridView.TabIndex = 3; + // + // panel1 + // + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(647, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(153, 450); + panel1.TabIndex = 2; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.plus1; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(28, 25); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(100, 86); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // FormAssemblerShifts + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormAssemblerShifts"; + Text = "Смены сборщиков"; + Load += FormAssemblerShifts_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + panel1.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private DataGridView dataGridView; + private Panel panel1; + private Button buttonAdd; + } +} \ No newline at end of file diff --git a/ProjectWorkshop/Forms/FormAssemblerShifts.cs b/ProjectWorkshop/Forms/FormAssemblerShifts.cs new file mode 100644 index 0000000..1a63073 --- /dev/null +++ b/ProjectWorkshop/Forms/FormAssemblerShifts.cs @@ -0,0 +1,56 @@ +using ProjectWorkshop.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectWorkshop.Forms +{ + public partial class FormAssemblerShifts : Form + { + private readonly IUnityContainer _container; + + private readonly IAssemblerShiftRepository _assemblerShiftRepository; + public FormAssemblerShifts(IUnityContainer container, IAssemblerShiftRepository assemblerShiftRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _assemblerShiftRepository = assemblerShiftRepository ?? + throw new ArgumentNullException(nameof(assemblerShiftRepository)); + } + + private void FormAssemblerShifts_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView.DataSource = _assemblerShiftRepository.ReadAssemblerShifts(); + } +} diff --git a/ProjectWorkshop/Forms/FormAssemblerShifts.resx b/ProjectWorkshop/Forms/FormAssemblerShifts.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectWorkshop/Forms/FormAssemblerShifts.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/ProjectWorkshop/Forms/FormAssemblies.cs b/ProjectWorkshop/Forms/FormAssemblies.cs index 8e9f7c5..69d8f97 100644 --- a/ProjectWorkshop/Forms/FormAssemblies.cs +++ b/ProjectWorkshop/Forms/FormAssemblies.cs @@ -18,13 +18,13 @@ namespace ProjectWorkshop.Forms private readonly IUnityContainer _container; private readonly IAssemblyRepository _assemblyRepository; - public FormAssemblies(IUnityContainer container, IAssemblyRepository employeeRepository) + public FormAssemblies(IUnityContainer container, IAssemblyRepository assemblyRepository) { InitializeComponent(); _container = container ?? throw new ArgumentNullException(nameof(container)); - _assemblyRepository = employeeRepository ?? - throw new ArgumentNullException(nameof(employeeRepository)); + _assemblyRepository = assemblyRepository ?? + throw new ArgumentNullException(nameof(assemblyRepository)); } private void ButtonAdd_Click(object sender, EventArgs e) diff --git a/ProjectWorkshop/Forms/FormAssembly.Designer.cs b/ProjectWorkshop/Forms/FormAssembly.Designer.cs index 46dd5cf..57bf417 100644 --- a/ProjectWorkshop/Forms/FormAssembly.Designer.cs +++ b/ProjectWorkshop/Forms/FormAssembly.Designer.cs @@ -30,48 +30,41 @@ { labelCount = new Label(); labelProductType = new Label(); - textBoxProductType = new TextBox(); numericUpDownCount = new NumericUpDown(); buttonSave = new Button(); buttonCancel = new Button(); + checkedListBoxProductType = new CheckedListBox(); ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); SuspendLayout(); // // labelCount // labelCount.AutoSize = true; - labelCount.Location = new Point(113, 101); + labelCount.Location = new Point(58, 160); labelCount.Name = "labelCount"; - labelCount.Size = new Size(46, 15); + labelCount.Size = new Size(49, 15); labelCount.TabIndex = 0; - labelCount.Text = "Кол-во"; + labelCount.Text = "Кол-во:"; // // labelProductType // labelProductType.AutoSize = true; - labelProductType.Location = new Point(100, 51); + labelProductType.Location = new Point(58, 51); labelProductType.Name = "labelProductType"; - labelProductType.Size = new Size(74, 15); + labelProductType.Size = new Size(77, 15); labelProductType.TabIndex = 1; - labelProductType.Text = "Тип изделия"; - // - // textBoxProductType - // - textBoxProductType.Location = new Point(201, 48); - textBoxProductType.Name = "textBoxProductType"; - textBoxProductType.Size = new Size(116, 23); - textBoxProductType.TabIndex = 2; + labelProductType.Text = "Тип изделия:"; // // numericUpDownCount // - numericUpDownCount.Location = new Point(201, 99); + numericUpDownCount.Location = new Point(156, 158); numericUpDownCount.Name = "numericUpDownCount"; - numericUpDownCount.Size = new Size(116, 23); + numericUpDownCount.Size = new Size(195, 23); numericUpDownCount.TabIndex = 3; // // buttonSave // - buttonSave.Location = new Point(100, 169); + buttonSave.Location = new Point(74, 275); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(75, 23); buttonSave.TabIndex = 4; @@ -81,7 +74,7 @@ // // buttonCancel // - buttonCancel.Location = new Point(232, 169); + buttonCancel.Location = new Point(261, 275); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(75, 23); buttonCancel.TabIndex = 5; @@ -89,15 +82,23 @@ buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; // + // checkedListBoxProductType + // + checkedListBoxProductType.FormattingEnabled = true; + checkedListBoxProductType.Location = new Point(156, 41); + checkedListBoxProductType.Name = "checkedListBoxProductType"; + checkedListBoxProductType.Size = new Size(195, 94); + checkedListBoxProductType.TabIndex = 6; + // // FormAssembly // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(420, 220); + ClientSize = new Size(453, 366); + Controls.Add(checkedListBoxProductType); Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(numericUpDownCount); - Controls.Add(textBoxProductType); Controls.Add(labelProductType); Controls.Add(labelCount); Name = "FormAssembly"; @@ -112,9 +113,9 @@ private Label labelCount; private Label labelProductType; - private TextBox textBoxProductType; private NumericUpDown numericUpDownCount; private Button buttonSave; private Button buttonCancel; + private CheckedListBox checkedListBoxProductType; } } \ No newline at end of file diff --git a/ProjectWorkshop/Forms/FormAssembly.cs b/ProjectWorkshop/Forms/FormAssembly.cs index 8eed707..9e8aba1 100644 --- a/ProjectWorkshop/Forms/FormAssembly.cs +++ b/ProjectWorkshop/Forms/FormAssembly.cs @@ -1,4 +1,5 @@ using ProjectWorkshop.Entities; +using ProjectWorkshop.Entities.Enums; using ProjectWorkshop.Repositories; using System; using System.Collections.Generic; @@ -27,10 +28,17 @@ namespace ProjectWorkshop.Forms var assembly = _assemblyRepository.ReadAssemblyByID(value); if (assembly == null) { - throw new - InvalidDataException(nameof(assembly)); + throw new InvalidDataException(nameof(assembly)); } - textBoxProductType.Text = assembly.ProductType; + + foreach (ProductType elem in Enum.GetValues(typeof(ProductType))) + { + if ((elem & assembly.ProductType) != 0) + { + checkedListBoxProductType.SetItemChecked(checkedListBoxProductType.Items.IndexOf(elem), true); + } + } + numericUpDownCount.Value = assembly.Count; _assemblyId = value; } @@ -41,19 +49,23 @@ namespace ProjectWorkshop.Forms } } } - public FormAssembly() + public FormAssembly(IAssemblyRepository assemblyRepository) { InitializeComponent(); - InitializeComponent(); - _assemblyRepository = _assemblyRepository ?? - throw new ArgumentNullException(nameof(_assemblyRepository)); + _assemblyRepository = assemblyRepository ?? + throw new ArgumentNullException(nameof(assemblyRepository)); + + foreach (var elem in Enum.GetValues(typeof(ProductType))) + { + checkedListBoxProductType.Items.Add(elem); + } } private void ButtonSave_Click(object sender, EventArgs e) { try { - if (string.IsNullOrWhiteSpace(textBoxProductType.Text) || string.IsNullOrWhiteSpace(textBoxProductType.Text) || numericUpDownCount.Value < 1) + if (numericUpDownCount.Value < 1 || checkedListBoxProductType.CheckedItems.Count == 0) { throw new Exception("Имеются незаполненные поля"); } @@ -80,7 +92,15 @@ namespace ProjectWorkshop.Forms Close(); } - private Assembly CreateAssembly(int id) => - Assembly.CreateEntity(id, (int)numericUpDownCount.Value, textBoxProductType.Text); + private Assembly CreateAssembly(int id) + { + ProductType productType = ProductType.None; + foreach (var elem in checkedListBoxProductType.CheckedItems) + { + productType |= (ProductType)elem; + } + + return Assembly.CreateElement(id, (int)numericUpDownCount.Value, productType); + } } } diff --git a/ProjectWorkshop/Forms/FormAssesmblerShift.Designer.cs b/ProjectWorkshop/Forms/FormAssesmblerShift.Designer.cs new file mode 100644 index 0000000..ddab37d --- /dev/null +++ b/ProjectWorkshop/Forms/FormAssesmblerShift.Designer.cs @@ -0,0 +1,149 @@ +namespace ProjectWorkshop.Forms +{ + partial class FormAssesmblerShift + { + /// + /// 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() + { + labelWorkHours = new Label(); + numericUpDownWorkHours = new NumericUpDown(); + groupBox = new GroupBox(); + dataGridViewAssemblerShift = new DataGridView(); + ColumnAssembler = new DataGridViewComboBoxColumn(); + ColumnShift = new DataGridViewComboBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownWorkHours).BeginInit(); + groupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewAssemblerShift).BeginInit(); + SuspendLayout(); + // + // labelWorkHours + // + labelWorkHours.AutoSize = true; + labelWorkHours.Location = new Point(35, 33); + labelWorkHours.Name = "labelWorkHours"; + labelWorkHours.Size = new Size(111, 15); + labelWorkHours.TabIndex = 0; + labelWorkHours.Text = "Отработано часов:"; + // + // numericUpDownWorkHours + // + numericUpDownWorkHours.Location = new Point(198, 31); + numericUpDownWorkHours.Name = "numericUpDownWorkHours"; + numericUpDownWorkHours.Size = new Size(113, 23); + numericUpDownWorkHours.TabIndex = 1; + // + // groupBox + // + groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBox.Controls.Add(dataGridViewAssemblerShift); + groupBox.Location = new Point(35, 78); + groupBox.Name = "groupBox"; + groupBox.Size = new Size(280, 328); + groupBox.TabIndex = 3; + groupBox.TabStop = false; + groupBox.Text = "groupBox1"; + // + // dataGridViewAssemblerShift + // + dataGridViewAssemblerShift.AllowUserToResizeColumns = false; + dataGridViewAssemblerShift.AllowUserToResizeRows = false; + dataGridViewAssemblerShift.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewAssemblerShift.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewAssemblerShift.Columns.AddRange(new DataGridViewColumn[] { ColumnAssembler, ColumnShift }); + dataGridViewAssemblerShift.Dock = DockStyle.Fill; + dataGridViewAssemblerShift.Location = new Point(3, 19); + dataGridViewAssemblerShift.Name = "dataGridViewAssemblerShift"; + dataGridViewAssemblerShift.RowHeadersVisible = false; + dataGridViewAssemblerShift.Size = new Size(274, 306); + dataGridViewAssemblerShift.TabIndex = 3; + // + // ColumnAssembler + // + ColumnAssembler.HeaderText = "Сборщик"; + ColumnAssembler.Name = "ColumnAssembler"; + // + // ColumnShift + // + ColumnShift.HeaderText = "Смена"; + ColumnShift.Name = "ColumnShift"; + ColumnShift.Resizable = DataGridViewTriState.True; + ColumnShift.SortMode = DataGridViewColumnSortMode.Automatic; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom; + buttonSave.Location = new Point(53, 431); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom; + buttonCancel.Location = new Point(220, 431); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 5; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormAssesmblerShift + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(355, 466); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBox); + Controls.Add(numericUpDownWorkHours); + Controls.Add(labelWorkHours); + Name = "FormAssesmblerShift"; + Text = "Смена сборщика"; + ((System.ComponentModel.ISupportInitialize)numericUpDownWorkHours).EndInit(); + groupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewAssemblerShift).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelWorkHours; + private NumericUpDown numericUpDownWorkHours; + private GroupBox groupBox; + private DataGridView dataGridViewAssemblerShift; + private DataGridViewComboBoxColumn ColumnAssembler; + private DataGridViewComboBoxColumn ColumnShift; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectWorkshop/Forms/FormAssesmblerShift.cs b/ProjectWorkshop/Forms/FormAssesmblerShift.cs new file mode 100644 index 0000000..1143232 --- /dev/null +++ b/ProjectWorkshop/Forms/FormAssesmblerShift.cs @@ -0,0 +1,62 @@ +using ProjectWorkshop.Entities; +using ProjectWorkshop.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectWorkshop.Forms +{ + public partial class FormAssesmblerShift : Form + { + private readonly IAssemblerShiftRepository _assemblerShiftRepository; + + public FormAssesmblerShift(IAssemblerShiftRepository assemblerShiftRepository, IShiftRepository shiftRepository, + IAssemblerRepository assemblerRepository) + { + InitializeComponent(); + _assemblerShiftRepository = assemblerShiftRepository ?? + throw new ArgumentNullException(nameof(assemblerShiftRepository)); + + numericUpDownWorkHours.Value = 1; + + ColumnAssembler.DataSource = assemblerRepository.ReadAssemblers(); + ColumnAssembler.DisplayMember = "FullName"; + ColumnAssembler.ValueMember = "Id"; + + ColumnShift.DataSource = shiftRepository.ReadShifts(); + ColumnShift.DisplayMember = "Id"; + ColumnShift.ValueMember = "Id"; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (numericUpDownWorkHours.Value < 1 || dataGridViewAssemblerShift.RowCount < 1) + { + throw new Exception("Имеются незаполненные поля"); + } + _assemblerShiftRepository.CreateAssemblerShift(AssemblerShift.CreateOperation((int)numericUpDownWorkHours.Value, + Convert.ToInt32(ColumnAssembler.ValueMember), Convert.ToInt32(ColumnShift.ValueMember))); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + Close(); + } + } +} diff --git a/ProjectWorkshop/Forms/FormAssesmblerShift.resx b/ProjectWorkshop/Forms/FormAssesmblerShift.resx new file mode 100644 index 0000000..607f5ab --- /dev/null +++ b/ProjectWorkshop/Forms/FormAssesmblerShift.resx @@ -0,0 +1,132 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + \ No newline at end of file diff --git a/ProjectWorkshop/Forms/FormProduct.Designer.cs b/ProjectWorkshop/Forms/FormProduct.Designer.cs new file mode 100644 index 0000000..6642c40 --- /dev/null +++ b/ProjectWorkshop/Forms/FormProduct.Designer.cs @@ -0,0 +1,141 @@ +namespace ProjectWorkshop.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() + { + labelProductName = new Label(); + labelPrice = new Label(); + numericUpDownPrice = new NumericUpDown(); + textBoxProductName = new TextBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + comboBoxAssembler = new ComboBox(); + labelAssembler = new Label(); + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit(); + SuspendLayout(); + // + // labelProductName + // + labelProductName.AutoSize = true; + labelProductName.Location = new Point(33, 50); + labelProductName.Name = "labelProductName"; + labelProductName.Size = new Size(109, 15); + labelProductName.TabIndex = 1; + labelProductName.Text = "Название изделия:"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(49, 149); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(70, 15); + labelPrice.TabIndex = 2; + labelPrice.Text = "Стоимость:"; + // + // numericUpDownPrice + // + numericUpDownPrice.Location = new Point(159, 147); + numericUpDownPrice.Name = "numericUpDownPrice"; + numericUpDownPrice.Size = new Size(204, 23); + numericUpDownPrice.TabIndex = 3; + // + // textBoxProductName + // + textBoxProductName.Location = new Point(159, 47); + textBoxProductName.Name = "textBoxProductName"; + textBoxProductName.Size = new Size(204, 23); + textBoxProductName.TabIndex = 4; + // + // buttonSave + // + buttonSave.Location = new Point(75, 224); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(79, 27); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(253, 224); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(79, 27); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // comboBoxAssembler + // + comboBoxAssembler.FormattingEnabled = true; + comboBoxAssembler.Location = new Point(159, 97); + comboBoxAssembler.Name = "comboBoxAssembler"; + comboBoxAssembler.Size = new Size(204, 23); + comboBoxAssembler.TabIndex = 7; + // + // labelAssembler + // + labelAssembler.AutoSize = true; + labelAssembler.Location = new Point(49, 100); + labelAssembler.Name = "labelAssembler"; + labelAssembler.Size = new Size(63, 15); + labelAssembler.TabIndex = 8; + labelAssembler.Text = "Сборщик:"; + // + // FormProduct + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(440, 295); + Controls.Add(labelAssembler); + Controls.Add(comboBoxAssembler); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(textBoxProductName); + Controls.Add(numericUpDownPrice); + Controls.Add(labelPrice); + Controls.Add(labelProductName); + Name = "FormProduct"; + Text = "FormProduct"; + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + private Label labelProductName; + private Label labelPrice; + private NumericUpDown numericUpDownPrice; + private TextBox textBoxProductName; + private Button buttonSave; + private Button buttonCancel; + private ComboBox comboBoxAssembler; + private Label labelAssembler; + } +} \ No newline at end of file diff --git a/ProjectWorkshop/Forms/FormProduct.cs b/ProjectWorkshop/Forms/FormProduct.cs new file mode 100644 index 0000000..02dd4d3 --- /dev/null +++ b/ProjectWorkshop/Forms/FormProduct.cs @@ -0,0 +1,88 @@ +using ProjectWorkshop.Entities; +using ProjectWorkshop.Repositories; +using ProjectWorkshop.Repositories.Implementation; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectWorkshop.Forms +{ + public partial class FormProduct : Form + { + private readonly IProductRepository _productRepository; + + private int? _productID; + + public int Id + { + set + { + try + { + var product = _productRepository.ReadProductByID(value); + if (product != null) + { + throw new InvalidDataException(nameof(product)); + } + + textBoxProductName.Text = product.ProductName; + numericUpDownPrice.Value = (int)product.Price; + comboBoxAssembler.SelectedItem = product.AssemblerID; + _productID = value; + + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + public FormProduct(IProductRepository productRepository) + { + InitializeComponent(); + _productRepository = productRepository ?? + throw new ArgumentNullException(nameof(productRepository)); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (string.IsNullOrEmpty(textBoxProductName.Text)) + { + throw new Exception("Имеется незаполненное поле"); + } + + if (_productID.HasValue || comboBoxAssembler.Created) + { + _productRepository.UpdateProduct(CreateProduct(_productID.Value)); + } + else + { + _productRepository.CreateProduct(CreateProduct(0)); + } + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + Close(); + } + + private Product CreateProduct(int id) => Product.CreateEntity(id, textBoxProductName.Text, Convert.ToInt32(numericUpDownPrice.Value), + (int)comboBoxAssembler.SelectedItem!); + } +} diff --git a/ProjectWorkshop/Forms/FormProduct.resx b/ProjectWorkshop/Forms/FormProduct.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectWorkshop/Forms/FormProduct.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectWorkshop/Forms/FormProductAssemblies.Designer.cs b/ProjectWorkshop/Forms/FormProductAssemblies.Designer.cs new file mode 100644 index 0000000..09e777d --- /dev/null +++ b/ProjectWorkshop/Forms/FormProductAssemblies.Designer.cs @@ -0,0 +1,97 @@ +namespace ProjectWorkshop.Forms +{ + partial class FormProductAssemblies + { + /// + /// 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() + { + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1 = new Panel(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + panel1.SuspendLayout(); + SuspendLayout(); + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.plus1; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(28, 25); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(100, 86); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(647, 450); + dataGridView.TabIndex = 3; + // + // panel1 + // + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(647, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(153, 450); + panel1.TabIndex = 2; + // + // FormProductAssemblies + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormProductAssemblies"; + Text = "Сборки продуктов"; + Load += FormProductAssemblies_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + panel1.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private Button buttonAdd; + private DataGridView dataGridView; + private Panel panel1; + } +} \ No newline at end of file diff --git a/ProjectWorkshop/Forms/FormProductAssemblies.cs b/ProjectWorkshop/Forms/FormProductAssemblies.cs new file mode 100644 index 0000000..9e8147c --- /dev/null +++ b/ProjectWorkshop/Forms/FormProductAssemblies.cs @@ -0,0 +1,56 @@ +using ProjectWorkshop.Repositories; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectWorkshop.Forms +{ + public partial class FormProductAssemblies : Form + { + private readonly IUnityContainer _container; + + private readonly IProductAssemblyRepository _productAssemblyRepository; + public FormProductAssemblies(IUnityContainer container, IProductAssemblyRepository productAssemblyRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _productAssemblyRepository = productAssemblyRepository ?? + throw new ArgumentNullException(nameof(productAssemblyRepository)); + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView.DataSource = _productAssemblyRepository.ReadProductAssembly(); + + private void FormProductAssemblies_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/ProjectWorkshop/Forms/FormProductAssemblies.resx b/ProjectWorkshop/Forms/FormProductAssemblies.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectWorkshop/Forms/FormProductAssemblies.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/ProjectWorkshop/Forms/FormProductAssembly.Designer.cs b/ProjectWorkshop/Forms/FormProductAssembly.Designer.cs new file mode 100644 index 0000000..ed7cf79 --- /dev/null +++ b/ProjectWorkshop/Forms/FormProductAssembly.Designer.cs @@ -0,0 +1,146 @@ +namespace ProjectWorkshop.Forms +{ + partial class FormProductAssembly + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelProduct = new Label(); + comboBoxProduct = new ComboBox(); + groupBox = new GroupBox(); + dataGridViewProductAssembly = new DataGridView(); + ColumnProductType = new DataGridViewComboBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBox.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewProductAssembly).BeginInit(); + SuspendLayout(); + // + // labelProduct + // + labelProduct.AutoSize = true; + labelProduct.Location = new Point(12, 41); + labelProduct.Name = "labelProduct"; + labelProduct.Size = new Size(56, 15); + labelProduct.TabIndex = 0; + labelProduct.Text = "Изделие:"; + // + // comboBoxProduct + // + comboBoxProduct.FormattingEnabled = true; + comboBoxProduct.Location = new Point(95, 38); + comboBoxProduct.Name = "comboBoxProduct"; + comboBoxProduct.Size = new Size(214, 23); + comboBoxProduct.TabIndex = 1; + // + // groupBox + // + groupBox.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBox.Controls.Add(dataGridViewProductAssembly); + groupBox.Location = new Point(12, 86); + groupBox.Name = "groupBox"; + groupBox.Size = new Size(299, 368); + groupBox.TabIndex = 2; + groupBox.TabStop = false; + groupBox.Text = "groupBox1"; + // + // dataGridViewProductAssembly + // + dataGridViewProductAssembly.AllowUserToResizeColumns = false; + dataGridViewProductAssembly.AllowUserToResizeRows = false; + dataGridViewProductAssembly.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewProductAssembly.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewProductAssembly.Columns.AddRange(new DataGridViewColumn[] { ColumnProductType, ColumnCount }); + dataGridViewProductAssembly.Dock = DockStyle.Fill; + dataGridViewProductAssembly.Location = new Point(3, 19); + dataGridViewProductAssembly.Name = "dataGridViewProductAssembly"; + dataGridViewProductAssembly.RowHeadersVisible = false; + dataGridViewProductAssembly.Size = new Size(293, 346); + dataGridViewProductAssembly.TabIndex = 3; + // + // ColumnProductType + // + ColumnProductType.HeaderText = "Тип изделия"; + ColumnProductType.Name = "ColumnProductType"; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonSave.Location = new Point(46, 476); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 3; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(204, 476); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 4; + buttonCancel.Text = "Отменить"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormProductAssembly + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(348, 529); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(groupBox); + Controls.Add(comboBoxProduct); + Controls.Add(labelProduct); + Name = "FormProductAssembly"; + Text = "Сборка изделия"; + groupBox.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewProductAssembly).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelProduct; + private ComboBox comboBoxProduct; + private GroupBox groupBox; + private DataGridView dataGridViewProductAssembly; + private Button buttonSave; + private Button buttonCancel; + private DataGridViewComboBoxColumn ColumnProductType; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/ProjectWorkshop/Forms/FormProductAssembly.cs b/ProjectWorkshop/Forms/FormProductAssembly.cs new file mode 100644 index 0000000..005aede --- /dev/null +++ b/ProjectWorkshop/Forms/FormProductAssembly.cs @@ -0,0 +1,74 @@ +using ProjectWorkshop.Entities; +using ProjectWorkshop.Entities.Enums; +using ProjectWorkshop.Repositories; +using ProjectWorkshop.Repositories.Implementation; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ProjectWorkshop.Forms +{ + public partial class FormProductAssembly : Form + { + private readonly IProductAssemblyRepository _productAssemblyRepository; + public FormProductAssembly(IProductAssemblyRepository productAssemblyRepository, IProductRepository productRepository, + IAssemblyRepository assemblyRepository) + { + InitializeComponent(); + _productAssemblyRepository = productAssemblyRepository ?? + throw new ArgumentNullException(nameof(productAssemblyRepository)); + + comboBoxProduct.DataSource = productAssemblyRepository.ReadProductAssembly(); + + ColumnProductType.DataSource = assemblyRepository.ReadAssemblies(); + ColumnProductType.ValueMember = "Id"; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (dataGridViewProductAssembly.RowCount < 1 || comboBoxProduct.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненные поля"); + } + + _productAssemblyRepository.CreateProductAssembly(ProductAssembly.CreateOperation(0, (int)comboBoxProduct.SelectedValue!, 0, + CreateListAssemblyFromDataGrid())); + + Close(); + } + catch (Exception ex) { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + Close(); + } + + private List CreateListAssemblyFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridViewProductAssembly.Rows) + { + if (row.Cells["ColumnFeed"].Value == null || + row.Cells["ColumnCount"].Value == null) + { + continue; + } + list.Add(Assembly.CreateElement(0, + Convert.ToInt32(row.Cells["ColumnCount"].Value), + (ProductType)Convert.ToInt32(row.Cells["ColumnProductType"].Value))); + } + return list; + } + } + } diff --git a/ProjectWorkshop/Forms/FormProductAssembly.resx b/ProjectWorkshop/Forms/FormProductAssembly.resx new file mode 100644 index 0000000..31b0cb8 --- /dev/null +++ b/ProjectWorkshop/Forms/FormProductAssembly.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/ProjectWorkshop/Forms/FormProducts.Designer.cs b/ProjectWorkshop/Forms/FormProducts.Designer.cs new file mode 100644 index 0000000..964d89c --- /dev/null +++ b/ProjectWorkshop/Forms/FormProducts.Designer.cs @@ -0,0 +1,125 @@ +namespace ProjectWorkshop.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() + { + buttonDel = new Button(); + buttonUpd = new Button(); + buttonAdd = new Button(); + dataGridView = new DataGridView(); + panel1 = new Panel(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + panel1.SuspendLayout(); + SuspendLayout(); + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.minus; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(28, 288); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(100, 86); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonUpd + // + buttonUpd.BackgroundImage = Properties.Resources.pencil; + buttonUpd.BackgroundImageLayout = ImageLayout.Stretch; + buttonUpd.Location = new Point(28, 159); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(100, 86); + buttonUpd.TabIndex = 1; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonAdd + // + buttonAdd.BackgroundImage = Properties.Resources.plus; + buttonAdd.BackgroundImageLayout = ImageLayout.Stretch; + buttonAdd.Location = new Point(28, 25); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(100, 86); + buttonAdd.TabIndex = 0; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridView + // + dataGridView.AllowUserToAddRows = false; + dataGridView.AllowUserToDeleteRows = false; + dataGridView.AllowUserToResizeColumns = false; + dataGridView.AllowUserToResizeRows = false; + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.MultiSelect = false; + dataGridView.Name = "dataGridView"; + dataGridView.ReadOnly = true; + dataGridView.RowHeadersVisible = false; + dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView.Size = new Size(646, 450); + dataGridView.TabIndex = 3; + // + // panel1 + // + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(646, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(154, 450); + panel1.TabIndex = 2; + // + // FormProducts + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridView); + Controls.Add(panel1); + Name = "FormProducts"; + Text = "Изделия"; + Load += FormProducts_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + panel1.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private Button buttonDel; + private Button buttonUpd; + private Button buttonAdd; + private DataGridView dataGridView; + private Panel panel1; + } +} \ No newline at end of file diff --git a/ProjectWorkshop/Forms/FormProducts.cs b/ProjectWorkshop/Forms/FormProducts.cs new file mode 100644 index 0000000..abab5ce --- /dev/null +++ b/ProjectWorkshop/Forms/FormProducts.cs @@ -0,0 +1,111 @@ +using ProjectWorkshop.Repositories; +using ProjectWorkshop.Repositories.Implementation; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using Unity; + +namespace ProjectWorkshop.Forms +{ + public partial class FormProducts : Form + { + + private readonly IUnityContainer _container; + + private readonly IProductRepository _productRepository; + public FormProducts(IUnityContainer container, IProductRepository productRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _productRepository = productRepository ?? + throw new ArgumentNullException(nameof(productRepository)); + } + + private void FormProducts_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectedRow(out var findID)) + { + return; + } + try + { + var form = _container.Resolve(); + form.Id = findID; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (TryGetIdentifierFromSelectedRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + try + { + _productRepository.DeleteProduct(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView.DataSource = _productRepository.ReadProducts(); + + private bool TryGetIdentifierFromSelectedRow(out int id) + { + id = 0; + if (dataGridView.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + id = + Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value); + return true; + } + } +} diff --git a/ProjectWorkshop/Forms/FormProducts.resx b/ProjectWorkshop/Forms/FormProducts.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/ProjectWorkshop/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/ProjectWorkshop/Repositories/IAssemblerShiftRepository.cs b/ProjectWorkshop/Repositories/IAssemblerShiftRepository.cs index acc86b7..bab9971 100644 --- a/ProjectWorkshop/Repositories/IAssemblerShiftRepository.cs +++ b/ProjectWorkshop/Repositories/IAssemblerShiftRepository.cs @@ -3,7 +3,7 @@ namespace ProjectWorkshop.Repositories; public interface IAssemblerShiftRepository { - IEnumerable ReadProductAssembly(int? workHours = null, int? assemblerID = null, int? shiftID = null); + IEnumerable ReadAssemblerShifts(int? workHours = null, int? assemblerID = null, int? shiftID = null); void CreateAssemblerShift(AssemblerShift assemblerShift); diff --git a/ProjectWorkshop/Repositories/Implementation/AssemblerShiftRepository.cs b/ProjectWorkshop/Repositories/Implementation/AssemblerShiftRepository.cs index 086f936..c97716c 100644 --- a/ProjectWorkshop/Repositories/Implementation/AssemblerShiftRepository.cs +++ b/ProjectWorkshop/Repositories/Implementation/AssemblerShiftRepository.cs @@ -17,7 +17,7 @@ public class AssemblerShiftRepository : IAssemblerShiftRepository { } - public IEnumerable ReadProductAssembly(int? workHours = null, int? assemblerID = null, int? shiftID = null) + public IEnumerable ReadAssemblerShifts(int? workHours = null, int? assemblerID = null, int? shiftID = null) { return []; } diff --git a/ProjectWorkshop/Repositories/Implementation/AssemblyRepository.cs b/ProjectWorkshop/Repositories/Implementation/AssemblyRepository.cs index c7836ad..7d7bd6d 100644 --- a/ProjectWorkshop/Repositories/Implementation/AssemblyRepository.cs +++ b/ProjectWorkshop/Repositories/Implementation/AssemblyRepository.cs @@ -1,4 +1,5 @@ using ProjectWorkshop.Entities; +using ProjectWorkshop.Entities.Enums; using System; using System.Collections.Generic; using System.Linq; @@ -19,7 +20,7 @@ public class AssemblyRepository : IAssemblyRepository public Assembly ReadAssemblyByID(int id) { - return Assembly.CreateEntity(0, 0, string.Empty); + return Assembly.CreateElement(0, 0, 0); } public IEnumerable ReadAssemblies()