diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs b/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs new file mode 100644 index 0000000..736c544 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Entities/AccessoiresOrder.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCompRepair.Entities; + +public class AccessoiresOrder +{ + public int Id { get; private set; } + + public int OrderId { get; private set; } + + public int Count { get; private set; } + + public static AccessoiresOrder CreateElement(int id, int orderId, int count) + { + return new AccessoiresOrder { Id = id, OrderId = orderId, Count = count}; + } +} diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/Accessories.cs b/ProjectCompRepair/ProjectCompRepair/Entities/Accessories.cs index 5e52205..b02a5a2 100644 --- a/ProjectCompRepair/ProjectCompRepair/Entities/Accessories.cs +++ b/ProjectCompRepair/ProjectCompRepair/Entities/Accessories.cs @@ -17,12 +17,13 @@ public class Accessories public double Price { get; private set; } - public static Accessories CreateEntity(int id, AccessoriesType accessoriesType, double price) + public static Accessories CreateEntity(int id, AccessoriesType accessoriesType, int count, double price) { return new Accessories { Id = id, AccessoriesType = accessoriesType, + Count = count, Price = price }; } diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/DeliveryToTheWarehouse.cs b/ProjectCompRepair/ProjectCompRepair/Entities/DeliveryToTheWarehouse.cs deleted file mode 100644 index 5f282c7..0000000 --- a/ProjectCompRepair/ProjectCompRepair/Entities/DeliveryToTheWarehouse.cs +++ /dev/null @@ -1,29 +0,0 @@ -using ProjectCompRepair.Entities.Enums; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectCompRepair.Entities; - -public class DeliveryToTheWarehouse -{ - public int Id { get; private set; } - - public DateTime Date { get; private set; } - - public AccessoriesType AccessoriesType { get; private set; } - public int Count { get; private set; } - - public static DeliveryToTheWarehouse CreateOperation(int id, AccessoriesType accessoriesType, int count) - { - return new DeliveryToTheWarehouse() - { - Id = id, - AccessoriesType = accessoriesType, - Date = DateTime.Now, - Count = count, - }; - } -} diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/Enums/AccessoriesType.cs b/ProjectCompRepair/ProjectCompRepair/Entities/Enums/AccessoriesType.cs index 8610aae..4d15cd7 100644 --- a/ProjectCompRepair/ProjectCompRepair/Entities/Enums/AccessoriesType.cs +++ b/ProjectCompRepair/ProjectCompRepair/Entities/Enums/AccessoriesType.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ProjectCompRepair.Entities.Enums; -[Flags] + public enum AccessoriesType { None = 0, @@ -15,8 +15,8 @@ public enum AccessoriesType AccessMemory = 2, - VideoCard = 4, + VideoCard = 3, - Cooler = 8 + Cooler = 4 } diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/Order.cs b/ProjectCompRepair/ProjectCompRepair/Entities/Order.cs index 1e38083..89561d1 100644 --- a/ProjectCompRepair/ProjectCompRepair/Entities/Order.cs +++ b/ProjectCompRepair/ProjectCompRepair/Entities/Order.cs @@ -9,19 +9,21 @@ namespace ProjectCompRepair.Entities; public class Order { public int Id { get; private set; } + public string Name { get; private set; } public string Coment { get; private set; } public DateTime Date { get; private set; } - public int CountAccessories { get; private set; } - - public int CountService { get; private set; } - public int MasterID { get; private set; } - public static Order CreateOperation(int id, string name, string coment, int countAccessories, int countService, int masterId) + public IEnumerable AccessoiresOrders { get; private set; } = []; + + public IEnumerable ServicesOrders { get; private set; } = []; + + + public static Order CreateElement(int id, string name, string coment, int masterId) { return new Order() { @@ -29,9 +31,8 @@ public class Order Name = name, Coment = coment, Date = DateTime.Now, - CountAccessories = countAccessories, - CountService = countService, MasterID = masterId + }; } } diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/Service.cs b/ProjectCompRepair/ProjectCompRepair/Entities/Service.cs index 1ea5d61..553d7e3 100644 --- a/ProjectCompRepair/ProjectCompRepair/Entities/Service.cs +++ b/ProjectCompRepair/ProjectCompRepair/Entities/Service.cs @@ -15,7 +15,7 @@ public class Service public double Price { get; private set; } - public static Service CreateOperation(int id, ServiceType serviceType, int count, double price) + public static Service CreateEntity(int id, ServiceType serviceType, double price) { return new Service { diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/ServicesOrder.cs b/ProjectCompRepair/ProjectCompRepair/Entities/ServicesOrder.cs new file mode 100644 index 0000000..d284ead --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Entities/ServicesOrder.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectCompRepair.Entities; + +public class ServicesOrder +{ + public int Id { get; private set; } + + public int OrderId { get; private set; } + + public int Count { get; private set; } + + public static ServicesOrder CreateElement(int id, int orderId, int count) + { + return new ServicesOrder { Id = id, OrderId = orderId, Count = count }; + } +} diff --git a/ProjectCompRepair/ProjectCompRepair/Entities/Warehouse.cs b/ProjectCompRepair/ProjectCompRepair/Entities/Warehouse.cs deleted file mode 100644 index cba6c35..0000000 --- a/ProjectCompRepair/ProjectCompRepair/Entities/Warehouse.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectCompRepair.Entities; - -public class Warehouse -{ - public int Id { get; private set; } - - public string Name { get; private set; } - - public int Capacity { get; private set; } - - public static Warehouse CreateEntity(int id, string name, int capacity) - { - return new Warehouse() - { - Id = id, - Name = name, - Capacity = capacity - }; - } -} diff --git a/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs index a17ca87..ecf1c97 100644 --- a/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs +++ b/ProjectCompRepair/ProjectCompRepair/Form1.Designer.cs @@ -30,91 +30,84 @@ { menuStrip = new MenuStrip(); справочникToolStripMenuItem = new ToolStripMenuItem(); - комплектующиеToolStripMenuItem = new ToolStripMenuItem(); - складToolStripMenuItem = new ToolStripMenuItem(); + AccossoriesToolStripMenuItem = new ToolStripMenuItem(); + MasterToolStripMenuItem = new ToolStripMenuItem(); + ServiceToolStripMenuItem = new ToolStripMenuItem(); операцииToolStripMenuItem = new ToolStripMenuItem(); - заказToolStripMenuItem = new ToolStripMenuItem(); + OrderToolStripMenuItem = new ToolStripMenuItem(); отчетыToolStripMenuItem = new ToolStripMenuItem(); - мастерToolStripMenuItem = new ToolStripMenuItem(); - завозНаСкладToolStripMenuItem = new ToolStripMenuItem(); - услугаToolStripMenuItem = new ToolStripMenuItem(); menuStrip.SuspendLayout(); SuspendLayout(); // // menuStrip // + menuStrip.ImageScalingSize = new Size(20, 20); menuStrip.Items.AddRange(new ToolStripItem[] { справочникToolStripMenuItem, операцииToolStripMenuItem, отчетыToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; - menuStrip.Size = new Size(784, 24); + menuStrip.Padding = new Padding(7, 3, 0, 3); + menuStrip.Size = new Size(896, 30); menuStrip.TabIndex = 0; menuStrip.Text = "menuStrip1"; // // справочникToolStripMenuItem // - справочникToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { комплектующиеToolStripMenuItem, складToolStripMenuItem, мастерToolStripMenuItem, услугаToolStripMenuItem }); + справочникToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { AccossoriesToolStripMenuItem, MasterToolStripMenuItem, ServiceToolStripMenuItem }); справочникToolStripMenuItem.Name = "справочникToolStripMenuItem"; - справочникToolStripMenuItem.Size = new Size(94, 20); + справочникToolStripMenuItem.Size = new Size(117, 24); справочникToolStripMenuItem.Text = "Справочники"; // - // комплектующиеToolStripMenuItem + // AccossoriesToolStripMenuItem // - комплектующиеToolStripMenuItem.Name = "комплектующиеToolStripMenuItem"; - комплектующиеToolStripMenuItem.Size = new Size(180, 22); - комплектующиеToolStripMenuItem.Text = "Комплектующие"; + AccossoriesToolStripMenuItem.Name = "AccossoriesToolStripMenuItem"; + AccossoriesToolStripMenuItem.Size = new Size(224, 26); + AccossoriesToolStripMenuItem.Text = "Комплектующие"; + AccossoriesToolStripMenuItem.Click += AccossoriesToolStripMenuItem_Click; // - // складToolStripMenuItem + // MasterToolStripMenuItem // - складToolStripMenuItem.Name = "складToolStripMenuItem"; - складToolStripMenuItem.Size = new Size(180, 22); - складToolStripMenuItem.Text = "Склад"; + MasterToolStripMenuItem.Name = "MasterToolStripMenuItem"; + MasterToolStripMenuItem.Size = new Size(224, 26); + MasterToolStripMenuItem.Text = "Мастер"; + MasterToolStripMenuItem.Click += MasterToolStripMenuItem_Click; + // + // ServiceToolStripMenuItem + // + ServiceToolStripMenuItem.Name = "ServiceToolStripMenuItem"; + ServiceToolStripMenuItem.Size = new Size(224, 26); + ServiceToolStripMenuItem.Text = "Услуга"; + ServiceToolStripMenuItem.Click += ServiceToolStripMenuItem_Click; // // операцииToolStripMenuItem // - операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заказToolStripMenuItem, завозНаСкладToolStripMenuItem }); + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { OrderToolStripMenuItem }); операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; - операцииToolStripMenuItem.Size = new Size(75, 20); + операцииToolStripMenuItem.Size = new Size(95, 24); операцииToolStripMenuItem.Text = "Операции"; // - // заказToolStripMenuItem + // OrderToolStripMenuItem // - заказToolStripMenuItem.Name = "заказToolStripMenuItem"; - заказToolStripMenuItem.Size = new Size(180, 22); - заказToolStripMenuItem.Text = "Заказ"; + OrderToolStripMenuItem.Name = "OrderToolStripMenuItem"; + OrderToolStripMenuItem.Size = new Size(224, 26); + OrderToolStripMenuItem.Text = "Заказ"; + OrderToolStripMenuItem.Click += OrderToolStripMenuItem_Click; // // отчетыToolStripMenuItem // отчетыToolStripMenuItem.Name = "отчетыToolStripMenuItem"; - отчетыToolStripMenuItem.Size = new Size(60, 20); + отчетыToolStripMenuItem.Size = new Size(73, 24); отчетыToolStripMenuItem.Text = "Отчеты"; // - // мастерToolStripMenuItem - // - мастерToolStripMenuItem.Name = "мастерToolStripMenuItem"; - мастерToolStripMenuItem.Size = new Size(180, 22); - мастерToolStripMenuItem.Text = "Мастер"; - // - // завозНаСкладToolStripMenuItem - // - завозНаСкладToolStripMenuItem.Name = "завозНаСкладToolStripMenuItem"; - завозНаСкладToolStripMenuItem.Size = new Size(180, 22); - завозНаСкладToolStripMenuItem.Text = "Завоз на склад"; - // - // услугаToolStripMenuItem - // - услугаToolStripMenuItem.Name = "услугаToolStripMenuItem"; - услугаToolStripMenuItem.Size = new Size(180, 22); - услугаToolStripMenuItem.Text = "Услуга"; - // // FormCompRepair // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; BackgroundImage = Properties.Resources.morskie_kamni_raznocvetnaya_galka; BackgroundImageLayout = ImageLayout.Stretch; - ClientSize = new Size(784, 411); + ClientSize = new Size(896, 548); Controls.Add(menuStrip); MainMenuStrip = menuStrip; + Margin = new Padding(3, 4, 3, 4); Name = "FormCompRepair"; StartPosition = FormStartPosition.CenterScreen; Text = "Фирма по ремонту техники"; @@ -128,13 +121,11 @@ private MenuStrip menuStrip; private ToolStripMenuItem справочникToolStripMenuItem; - private ToolStripMenuItem комплектующиеToolStripMenuItem; + private ToolStripMenuItem AccossoriesToolStripMenuItem; private ToolStripMenuItem операцииToolStripMenuItem; private ToolStripMenuItem отчетыToolStripMenuItem; - private ToolStripMenuItem складToolStripMenuItem; - private ToolStripMenuItem заказToolStripMenuItem; - private ToolStripMenuItem мастерToolStripMenuItem; - private ToolStripMenuItem услугаToolStripMenuItem; - private ToolStripMenuItem завозНаСкладToolStripMenuItem; + private ToolStripMenuItem OrderToolStripMenuItem; + private ToolStripMenuItem MasterToolStripMenuItem; + private ToolStripMenuItem ServiceToolStripMenuItem; } } diff --git a/ProjectCompRepair/ProjectCompRepair/Form1.cs b/ProjectCompRepair/ProjectCompRepair/Form1.cs index 0e80724..98f10b1 100644 --- a/ProjectCompRepair/ProjectCompRepair/Form1.cs +++ b/ProjectCompRepair/ProjectCompRepair/Form1.cs @@ -1,10 +1,65 @@ +using ProjectCompRepair.Forms; +using Unity; + namespace ProjectCompRepair { public partial class FormCompRepair : Form { - public FormCompRepair() + private readonly IUnityContainer _container; + public FormCompRepair(IUnityContainer container) { InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + } + + private void AccossoriesToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch(Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void MasterToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch(Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ServiceToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void OrderToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } } } diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.Designer.cs index de53791..d9d5320 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.Designer.cs +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.Designer.cs @@ -11,14 +11,6 @@ /// 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 @@ -33,99 +25,116 @@ labelPrice = new Label(); numericUpDownPrice = new NumericUpDown(); numericUpDownCount = new NumericUpDown(); - numericUpDownType = new NumericUpDown(); buttonCreate = new Button(); buttonCancel = new Button(); + comboBoxType = new ComboBox(); ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDownType).BeginInit(); SuspendLayout(); // // labelType // + labelType.Anchor = AnchorStyles.Right; labelType.AutoSize = true; - labelType.Location = new Point(46, 50); + labelType.Location = new Point(54, 75); labelType.Name = "labelType"; - labelType.Size = new Size(128, 15); + labelType.Size = new Size(158, 20); labelType.TabIndex = 0; labelType.Text = "Вид комплектующего"; // // labelCount // + labelCount.Anchor = AnchorStyles.Right; labelCount.AutoSize = true; - labelCount.Location = new Point(46, 108); + labelCount.Location = new Point(54, 152); labelCount.Name = "labelCount"; - labelCount.Size = new Size(79, 15); + labelCount.Size = new Size(98, 20); labelCount.TabIndex = 2; labelCount.Text = "Колличество"; // // labelPrice // + labelPrice.Anchor = AnchorStyles.Right; labelPrice.AutoSize = true; - labelPrice.Location = new Point(46, 167); + labelPrice.Location = new Point(54, 231); labelPrice.Name = "labelPrice"; - labelPrice.Size = new Size(35, 15); + labelPrice.Size = new Size(45, 20); labelPrice.TabIndex = 4; labelPrice.Text = "Цена"; // // numericUpDownPrice // + numericUpDownPrice.Anchor = AnchorStyles.Right; numericUpDownPrice.DecimalPlaces = 2; - numericUpDownPrice.Location = new Point(191, 165); + numericUpDownPrice.Location = new Point(252, 235); + numericUpDownPrice.Margin = new Padding(3, 4, 3, 4); numericUpDownPrice.Name = "numericUpDownPrice"; - numericUpDownPrice.Size = new Size(120, 23); + numericUpDownPrice.Size = new Size(119, 27); numericUpDownPrice.TabIndex = 5; // // numericUpDownCount // - numericUpDownCount.Location = new Point(191, 106); + numericUpDownCount.Anchor = AnchorStyles.Right; + numericUpDownCount.Location = new Point(252, 156); + numericUpDownCount.Margin = new Padding(3, 4, 3, 4); numericUpDownCount.Name = "numericUpDownCount"; - numericUpDownCount.Size = new Size(120, 23); + numericUpDownCount.Size = new Size(119, 27); numericUpDownCount.TabIndex = 6; // - // numericUpDownType - // - numericUpDownType.Location = new Point(191, 50); - numericUpDownType.Name = "numericUpDownType"; - numericUpDownType.Size = new Size(120, 23); - numericUpDownType.TabIndex = 7; - // // buttonCreate // - buttonCreate.Location = new Point(46, 297); + buttonCreate.AllowDrop = true; + buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreate.Location = new Point(53, 417); + buttonCreate.Margin = new Padding(3, 4, 3, 4); buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(75, 23); + buttonCreate.Size = new Size(98, 33); buttonCreate.TabIndex = 8; - buttonCreate.Text = "Создать"; + buttonCreate.Text = "Сохранить"; buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonSave_Click; // // buttonCancel // - buttonCancel.Location = new Point(236, 297); + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(310, 416); + buttonCancel.Margin = new Padding(3, 4, 3, 4); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(75, 23); + buttonCancel.Size = new Size(101, 31); buttonCancel.TabIndex = 10; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // comboBoxType + // + comboBoxType.FormattingEnabled = true; + comboBoxType.Location = new Point(250, 78); + comboBoxType.Name = "comboBoxType"; + comboBoxType.Size = new Size(151, 28); + comboBoxType.TabIndex = 11; // // FormAccessorie // - AutoScaleDimensions = new SizeF(7F, 15F); + AllowDrop = true; + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(346, 340); + AutoSizeMode = AutoSizeMode.GrowAndShrink; + AutoValidate = AutoValidate.EnableAllowFocusChange; + ClientSize = new Size(448, 478); + Controls.Add(comboBoxType); Controls.Add(buttonCancel); Controls.Add(buttonCreate); - Controls.Add(numericUpDownType); Controls.Add(numericUpDownCount); Controls.Add(numericUpDownPrice); Controls.Add(labelPrice); Controls.Add(labelCount); Controls.Add(labelType); + Margin = new Padding(3, 4, 3, 4); Name = "FormAccessorie"; Text = "Комплектующое"; ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); ((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit(); - ((System.ComponentModel.ISupportInitialize)numericUpDownType).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -137,9 +146,9 @@ private Label labelPrice; private NumericUpDown numericUpDownPrice; private NumericUpDown numericUpDownCount; - private NumericUpDown numericUpDownType; private Button buttonCreate; private Button buttonUpdate; private Button buttonCancel; + private ComboBox comboBoxType; } } \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.cs index 846db8b..73951d2 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.cs +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessorie.cs @@ -1,4 +1,8 @@ -using System; +using ProjectCompRepair.Entities; +using ProjectCompRepair.Entities.Enums; +using ProjectCompRepair.Repositories; +using ProjectCompRepair.Repositories.Implemantations; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -12,9 +16,73 @@ namespace ProjectCompRepair.Forms { public partial class FormAccessorie : Form { - public FormAccessorie() + private readonly IAccessoriesRepository _accessoriesRepository; + + private int? _accessorieId; + + public int Id + { + set + { + try + { + var accessorie = _accessoriesRepository.ReadAccessoriesById(value); + if (accessorie == null) + { + throw new InvalidOperationException(nameof(accessorie)); + } + + numericUpDownCount.Value = accessorie.Count; + numericUpDownPrice.Value = (int)accessorie.Price; + _accessorieId = value; + comboBoxType.SelectedItem = accessorie.AccessoriesType; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormAccessorie(IAccessoriesRepository accessoriesRepository) { InitializeComponent(); + _accessoriesRepository = accessoriesRepository ?? + throw new ArgumentNullException(nameof(accessoriesRepository)); + comboBoxType.DataSource = Enum.GetValues(typeof(AccessoriesType)); + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxType.SelectedIndex < 1 || numericUpDownPrice.Value == 0 || numericUpDownCount.Value == 0) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_accessorieId.HasValue) + { + _accessoriesRepository.UpdateAccessories(CreateAccessories(_accessorieId.Value)); + } + else + { + _accessoriesRepository.CreateAccessories(CreateAccessories(0)); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Accessories CreateAccessories(int id) + { + return Accessories.CreateEntity(id, (AccessoriesType)comboBoxType.SelectedItem! , (int)numericUpDownCount.Value, (double)numericUpDownPrice.Value); + } } } diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessories.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessories.Designer.cs new file mode 100644 index 0000000..69ca945 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessories.Designer.cs @@ -0,0 +1,117 @@ +namespace ProjectCompRepair.Forms +{ + partial class FormAccessories + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panelButtons = new Panel(); + buttonDel = new Button(); + buttonChange = new Button(); + buttonCreate = new Button(); + dataGridView = new DataGridView(); + panelButtons.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panelButtons + // + panelButtons.Controls.Add(buttonDel); + panelButtons.Controls.Add(buttonChange); + panelButtons.Controls.Add(buttonCreate); + panelButtons.Dock = DockStyle.Right; + panelButtons.Location = new Point(645, 0); + panelButtons.Name = "panelButtons"; + panelButtons.Size = new Size(155, 450); + panelButtons.TabIndex = 2; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.pngwing_com__7_; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(40, 255); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(94, 91); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonChange + // + buttonChange.BackgroundImage = Properties.Resources.pngwing_com__8_; + buttonChange.BackgroundImageLayout = ImageLayout.Stretch; + buttonChange.Location = new Point(40, 149); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(94, 89); + buttonChange.TabIndex = 1; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += ButtonChange_Click; + // + // buttonCreate + // + buttonCreate.BackgroundImage = Properties.Resources.pngwing_com__6_; + buttonCreate.BackgroundImageLayout = ImageLayout.Stretch; + buttonCreate.Location = new Point(40, 43); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(94, 88); + buttonCreate.TabIndex = 0; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(800, 450); + dataGridView.TabIndex = 3; + // + // FormAccessories + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(panelButtons); + Controls.Add(dataGridView); + Name = "FormAccessories"; + Text = "Комплектующие"; + Load += FormAccessories_Load; + panelButtons.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panelButtons; + private Button buttonDel; + private Button buttonChange; + private Button buttonCreate; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessories.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessories.cs new file mode 100644 index 0000000..0827de5 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessories.cs @@ -0,0 +1,115 @@ +using ProjectCompRepair.Repositories; +using ProjectCompRepair.Repositories.Implemantations; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Xml.Linq; +using Unity; + +namespace ProjectCompRepair.Forms +{ + public partial class FormAccessories : Form + { + + private readonly IUnityContainer _container; + + private readonly IAccessoriesRepository _accessoriesRepository; + + public FormAccessories(IUnityContainer container, IAccessoriesRepository accessoriesRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentException(nameof(container)); + _accessoriesRepository = accessoriesRepository + ?? throw new ArgumentException(nameof(accessoriesRepository)); + } + + private void FormAccessories_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void ButtonCreate_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonChange_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectRow(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 (!TryGetIdentifierFromSelectRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + + try + { + _accessoriesRepository.DeleteAccessories(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView.DataSource = _accessoriesRepository.ReadAccessories(); + + private bool TryGetIdentifierFromSelectRow(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/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessories.resx b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessories.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormAccessories.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/ProjectCompRepair/ProjectCompRepair/Forms/FormMaster.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormMaster.Designer.cs index 52ed8f3..56be5d1 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormMaster.Designer.cs +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormMaster.Designer.cs @@ -36,25 +36,30 @@ // // labelName // + labelName.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; labelName.AutoSize = true; - labelName.Location = new Point(27, 55); + labelName.Location = new Point(87, 73); labelName.Name = "labelName"; - labelName.Size = new Size(31, 15); + labelName.Size = new Size(39, 20); labelName.TabIndex = 0; labelName.Text = "Имя"; // // textBoxName // - textBoxName.Location = new Point(91, 55); + textBoxName.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + textBoxName.Location = new Point(160, 73); + textBoxName.Margin = new Padding(3, 4, 3, 4); textBoxName.Name = "textBoxName"; - textBoxName.Size = new Size(100, 23); + textBoxName.Size = new Size(114, 27); textBoxName.TabIndex = 1; // // buttonSave // - buttonSave.Location = new Point(27, 205); + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(31, 273); + buttonSave.Margin = new Padding(3, 4, 3, 4); buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(75, 23); + buttonSave.Size = new Size(97, 31); buttonSave.TabIndex = 2; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; @@ -62,9 +67,11 @@ // // buttonCancel // - buttonCancel.Location = new Point(133, 206); + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(208, 275); + buttonCancel.Margin = new Padding(3, 4, 3, 4); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(75, 23); + buttonCancel.Size = new Size(86, 31); buttonCancel.TabIndex = 3; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; @@ -72,13 +79,14 @@ // // FormMaster // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(241, 253); + ClientSize = new Size(331, 337); Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(textBoxName); Controls.Add(labelName); + Margin = new Padding(3, 4, 3, 4); Name = "FormMaster"; StartPosition = FormStartPosition.CenterScreen; Text = "Мастер"; diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormMasters.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormMasters.Designer.cs index 2d2dba3..80ad9c9 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormMasters.Designer.cs +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormMasters.Designer.cs @@ -28,33 +28,22 @@ /// private void InitializeComponent() { - panelButtons = new Panel(); buttonDel = new Button(); buttonChange = new Button(); buttonCreate = new Button(); dataGridView = new DataGridView(); - panelButtons.SuspendLayout(); + panelButtons = new Panel(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + panelButtons.SuspendLayout(); SuspendLayout(); // - // panelButtons - // - panelButtons.Controls.Add(buttonDel); - panelButtons.Controls.Add(buttonChange); - panelButtons.Controls.Add(buttonCreate); - panelButtons.Dock = DockStyle.Right; - panelButtons.Location = new Point(598, 0); - panelButtons.Name = "panelButtons"; - panelButtons.Size = new Size(202, 450); - panelButtons.TabIndex = 0; - // // buttonDel // buttonDel.BackgroundImage = Properties.Resources.pngwing_com__7_; buttonDel.BackgroundImageLayout = ImageLayout.Stretch; - buttonDel.Location = new Point(77, 193); + buttonDel.Location = new Point(40, 255); buttonDel.Name = "buttonDel"; - buttonDel.Size = new Size(61, 57); + buttonDel.Size = new Size(94, 91); buttonDel.TabIndex = 2; buttonDel.UseVisualStyleBackColor = true; buttonDel.Click += ButtonDel_Click; @@ -63,9 +52,9 @@ // buttonChange.BackgroundImage = Properties.Resources.pngwing_com__8_; buttonChange.BackgroundImageLayout = ImageLayout.Stretch; - buttonChange.Location = new Point(77, 104); + buttonChange.Location = new Point(40, 149); buttonChange.Name = "buttonChange"; - buttonChange.Size = new Size(61, 59); + buttonChange.Size = new Size(94, 89); buttonChange.TabIndex = 1; buttonChange.UseVisualStyleBackColor = true; buttonChange.Click += ButtonChange_Click; @@ -74,48 +63,56 @@ // buttonCreate.BackgroundImage = Properties.Resources.pngwing_com__6_; buttonCreate.BackgroundImageLayout = ImageLayout.Stretch; - buttonCreate.Location = new Point(77, 12); + buttonCreate.Location = new Point(40, 43); buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(61, 63); + buttonCreate.Size = new Size(94, 88); buttonCreate.TabIndex = 0; buttonCreate.UseVisualStyleBackColor = true; buttonCreate.Click += ButtonCreate_Click; // // dataGridView // - 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.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(598, 450); - dataGridView.TabIndex = 1; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(551, 403); + dataGridView.TabIndex = 3; + // + // panelButtons + // + panelButtons.Controls.Add(buttonDel); + panelButtons.Controls.Add(buttonChange); + panelButtons.Controls.Add(buttonCreate); + panelButtons.Dock = DockStyle.Right; + panelButtons.Location = new Point(551, 0); + panelButtons.Name = "panelButtons"; + panelButtons.Size = new Size(155, 403); + panelButtons.TabIndex = 2; // // FormMasters // - AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(800, 450); + ClientSize = new Size(706, 403); Controls.Add(dataGridView); Controls.Add(panelButtons); + Margin = new Padding(3, 4, 3, 4); Name = "FormMasters"; - Text = "FormMasters"; + Text = "Мастера"; Load += FormMasters_Load; - panelButtons.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + panelButtons.ResumeLayout(false); ResumeLayout(false); } #endregion - private Panel panelButtons; private Button buttonDel; private Button buttonChange; private Button buttonCreate; private DataGridView dataGridView; + private Panel panelButtons; } } \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormMasters.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormMasters.cs index 393a525..be8f989 100644 --- a/ProjectCompRepair/ProjectCompRepair/Forms/FormMasters.cs +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormMasters.cs @@ -22,9 +22,9 @@ namespace ProjectCompRepair.Forms { InitializeComponent(); _container = container ?? - throw new ArgumentException(nameof(masterRepository)); + throw new ArgumentException(nameof(container)); _masterRepository = masterRepository - ?? throw new ArgumentException(nameof(_masterRepository)); + ?? throw new ArgumentException(nameof(masterRepository)); } private void FormMasters_Load(object sender, EventArgs e) { diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.Designer.cs new file mode 100644 index 0000000..c53dc9e --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.Designer.cs @@ -0,0 +1,259 @@ +namespace ProjectCompRepair.Forms +{ + partial class FormOrder + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + labelName = new Label(); + labelComent = new Label(); + textBoxComent = new TextBox(); + textBoxName = new TextBox(); + labelDate = new Label(); + dateTimePicker = new DateTimePicker(); + comboBoxMaster = new ComboBox(); + labelMaster = new Label(); + buttonSave = new Button(); + buttonCancel = new Button(); + groupBox1 = new GroupBox(); + dataGridViewAccessories = new DataGridView(); + ColumnAccessories = new DataGridViewComboBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + groupBoxServices = new GroupBox(); + dataGridViewServices = new DataGridView(); + ColumnService = new DataGridViewComboBoxColumn(); + ColumnCountServ = new DataGridViewTextBoxColumn(); + groupBox1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewAccessories).BeginInit(); + groupBoxServices.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewServices).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(19, 35); + labelName.Name = "labelName"; + labelName.Size = new Size(77, 20); + labelName.TabIndex = 0; + labelName.Text = "Название"; + // + // labelComent + // + labelComent.AutoSize = true; + labelComent.Location = new Point(19, 109); + labelComent.Name = "labelComent"; + labelComent.Size = new Size(79, 20); + labelComent.TabIndex = 1; + labelComent.Text = "Описание"; + // + // textBoxComent + // + textBoxComent.Location = new Point(208, 81); + textBoxComent.Multiline = true; + textBoxComent.Name = "textBoxComent"; + textBoxComent.Size = new Size(125, 72); + textBoxComent.TabIndex = 2; + // + // textBoxName + // + textBoxName.Location = new Point(208, 28); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(125, 27); + textBoxName.TabIndex = 3; + // + // labelDate + // + labelDate.AutoSize = true; + labelDate.Location = new Point(19, 192); + labelDate.Name = "labelDate"; + labelDate.Size = new Size(183, 20); + labelDate.TabIndex = 4; + labelDate.Text = "Дата регистрации заказа"; + // + // dateTimePicker + // + dateTimePicker.Location = new Point(208, 192); + dateTimePicker.Name = "dateTimePicker"; + dateTimePicker.Size = new Size(192, 27); + dateTimePicker.TabIndex = 5; + // + // comboBoxMaster + // + comboBoxMaster.FormattingEnabled = true; + comboBoxMaster.Location = new Point(208, 254); + comboBoxMaster.Name = "comboBoxMaster"; + comboBoxMaster.Size = new Size(151, 28); + comboBoxMaster.TabIndex = 6; + // + // labelMaster + // + labelMaster.AutoSize = true; + labelMaster.Location = new Point(21, 262); + labelMaster.Name = "labelMaster"; + labelMaster.Size = new Size(60, 20); + labelMaster.TabIndex = 7; + labelMaster.Text = "Мастер"; + // + // buttonSave + // + buttonSave.Location = new Point(35, 389); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 8; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(1077, 389); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 9; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // groupBox1 + // + groupBox1.Controls.Add(dataGridViewAccessories); + groupBox1.Location = new Point(449, 35); + groupBox1.Name = "groupBox1"; + groupBox1.Size = new Size(309, 247); + groupBox1.TabIndex = 10; + groupBox1.TabStop = false; + groupBox1.Text = "Комплектующие"; + // + // dataGridViewAccessories + // + dataGridViewAccessories.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewAccessories.Columns.AddRange(new DataGridViewColumn[] { ColumnAccessories, ColumnCount }); + dataGridViewAccessories.Dock = DockStyle.Fill; + dataGridViewAccessories.Location = new Point(3, 23); + dataGridViewAccessories.Name = "dataGridViewAccessories"; + dataGridViewAccessories.RowHeadersWidth = 51; + dataGridViewAccessories.Size = new Size(303, 221); + dataGridViewAccessories.TabIndex = 0; + // + // ColumnAccessories + // + ColumnAccessories.HeaderText = "Экземпляр"; + ColumnAccessories.MinimumWidth = 6; + ColumnAccessories.Name = "ColumnAccessories"; + ColumnAccessories.Width = 125; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.MinimumWidth = 6; + ColumnCount.Name = "ColumnCount"; + ColumnCount.Width = 125; + // + // groupBoxServices + // + groupBoxServices.Controls.Add(dataGridViewServices); + groupBoxServices.Location = new Point(789, 35); + groupBoxServices.Name = "groupBoxServices"; + groupBoxServices.Size = new Size(310, 247); + groupBoxServices.TabIndex = 11; + groupBoxServices.TabStop = false; + groupBoxServices.Text = "Услуги"; + // + // dataGridViewServices + // + dataGridViewServices.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewServices.Columns.AddRange(new DataGridViewColumn[] { ColumnService, ColumnCountServ }); + dataGridViewServices.Dock = DockStyle.Fill; + dataGridViewServices.Location = new Point(3, 23); + dataGridViewServices.Name = "dataGridViewServices"; + dataGridViewServices.RowHeadersWidth = 51; + dataGridViewServices.Size = new Size(304, 221); + dataGridViewServices.TabIndex = 0; + // + // ColumnService + // + ColumnService.HeaderText = "Услуга"; + ColumnService.MinimumWidth = 6; + ColumnService.Name = "ColumnService"; + ColumnService.Width = 125; + // + // ColumnCountServ + // + ColumnCountServ.HeaderText = "Количество"; + ColumnCountServ.MinimumWidth = 6; + ColumnCountServ.Name = "ColumnCountServ"; + ColumnCountServ.Width = 125; + // + // FormOrder + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1183, 430); + Controls.Add(groupBoxServices); + Controls.Add(groupBox1); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelMaster); + Controls.Add(comboBoxMaster); + Controls.Add(dateTimePicker); + Controls.Add(labelDate); + Controls.Add(textBoxName); + Controls.Add(textBoxComent); + Controls.Add(labelComent); + Controls.Add(labelName); + Name = "FormOrder"; + Text = "Заказ"; + groupBox1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewAccessories).EndInit(); + groupBoxServices.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewServices).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelName; + private Label labelComent; + private TextBox textBoxComent; + private TextBox textBoxName; + private Label labelDate; + private DateTimePicker dateTimePicker; + private ComboBox comboBoxMaster; + private Label labelMaster; + private Button buttonSave; + private Button buttonCancel; + private GroupBox groupBox1; + private DataGridView dataGridViewAccessories; + private GroupBox groupBoxServices; + private DataGridView dataGridViewServices; + private DataGridViewComboBoxColumn ColumnAccessories; + private DataGridViewTextBoxColumn ColumnCount; + private DataGridViewComboBoxColumn ColumnService; + private DataGridViewTextBoxColumn ColumnCountServ; + } +} \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.cs new file mode 100644 index 0000000..2aa9ce2 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.cs @@ -0,0 +1,119 @@ +using ProjectCompRepair.Entities; +using ProjectCompRepair.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 ProjectCompRepair.Forms; + +public partial class FormOrder : Form +{ + private readonly IOrderRepository _orderRepository; + + private int? _orderId; + + public int Id + { + set + { + try + { + var order = _orderRepository.ReadOrderById(value); + if (order == null) + { + throw new InvalidOperationException(nameof(order)); + } + + textBoxName.Text = order.Name; + textBoxComent.Text = order.Coment; + dateTimePicker.Value = order.Date; + _orderId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormOrder(IOrderRepository orderRepository, IMasterRepository masterRepository, IAccessoriesRepository accessoriesRepository, IServiceRepository serviceRepository) + { + InitializeComponent(); + _orderRepository = orderRepository ?? + throw new ArgumentNullException(nameof(orderRepository)); + + comboBoxMaster.DataSource = masterRepository.ReadMaster(); + comboBoxMaster.ValueMember = "Id"; + comboBoxMaster.DisplayMember = "Name"; + + ColumnAccessories.DataSource = accessoriesRepository.ReadAccessories(); + ColumnAccessories.DisplayMember = "AccessoriesType"; + ColumnAccessories.ValueMember = "Id"; + + ColumnService.DataSource = serviceRepository.ReadService(); + ColumnService.DisplayMember = "ServiceType"; + ColumnService.ValueMember = "Id"; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if(dataGridViewAccessories.RowCount < 1 || comboBoxMaster.SelectedIndex < 0 || dataGridViewServices.RowCount < 1) + { + throw new Exception("Имеются незаполненые поля"); + } + _orderRepository.CreateOrder(Order.CreateElement(0, textBoxName.Text, textBoxComent.Text, (int)comboBoxMaster.SelectedValue!)); + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private List CreateListAccessoiresOrderFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridViewAccessories.Rows) + { + if (row.Cells["ColumnAccessoires"].Value == null || + row.Cells["ColumnCount"].Value == null) + { + continue; + } + list.Add(AccessoiresOrder.CreateElement(0, + Convert.ToInt32(row.Cells["ColumnAccessoires"].Value), + Convert.ToInt32(row.Cells["ColumnCount"].Value))); + } + return list; + } + + private List CreateListServicesOrderFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridViewAccessories.Rows) + { + if (row.Cells["ColumnServices"].Value == null || + row.Cells["ColumnCountServices"].Value == null) + { + continue; + } + list.Add(ServicesOrder.CreateElement(0, + Convert.ToInt32(row.Cells["ColumnAccessoires"].Value), + Convert.ToInt32(row.Cells["ColumnCount"].Value))); + } + return list; + } + +} diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.resx b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.resx new file mode 100644 index 0000000..3fa5b7f --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrder.resx @@ -0,0 +1,144 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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 + + + True + + + True + + + True + + + True + + \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormOrders.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrders.Designer.cs new file mode 100644 index 0000000..fb0ed62 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrders.Designer.cs @@ -0,0 +1,117 @@ +namespace ProjectCompRepair.Forms +{ + partial class FormOrders + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + buttonDel = new Button(); + buttonChange = new Button(); + buttonCreate = new Button(); + dataGridView = new DataGridView(); + panelButtons = new Panel(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + panelButtons.SuspendLayout(); + SuspendLayout(); + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.pngwing_com__7_; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(40, 255); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(94, 91); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonChange + // + buttonChange.BackgroundImage = Properties.Resources.pngwing_com__8_; + buttonChange.BackgroundImageLayout = ImageLayout.Stretch; + buttonChange.Location = new Point(40, 149); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(94, 89); + buttonChange.TabIndex = 1; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += ButtonChange_Click; + // + // buttonCreate + // + buttonCreate.BackgroundImage = Properties.Resources.pngwing_com__6_; + buttonCreate.BackgroundImageLayout = ImageLayout.Stretch; + buttonCreate.Location = new Point(40, 43); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(94, 88); + buttonCreate.TabIndex = 0; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(545, 400); + dataGridView.TabIndex = 3; + // + // panelButtons + // + panelButtons.Controls.Add(buttonDel); + panelButtons.Controls.Add(buttonChange); + panelButtons.Controls.Add(buttonCreate); + panelButtons.Dock = DockStyle.Right; + panelButtons.Location = new Point(545, 0); + panelButtons.Name = "panelButtons"; + panelButtons.Size = new Size(155, 400); + panelButtons.TabIndex = 2; + // + // FormOrders + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(700, 400); + Controls.Add(dataGridView); + Controls.Add(panelButtons); + Name = "FormOrders"; + Text = "Заказы"; + Load += FormOrder_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + panelButtons.ResumeLayout(false); + ResumeLayout(false); + } + + #endregion + + private Button buttonDel; + private Button buttonChange; + private Button buttonCreate; + private DataGridView dataGridView; + private Panel panelButtons; + } +} \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormOrders.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrders.cs new file mode 100644 index 0000000..589bda8 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrders.cs @@ -0,0 +1,114 @@ +using ProjectCompRepair.Repositories; +using ProjectCompRepair.Repositories.Implemantations; +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 ProjectCompRepair.Forms; + +public partial class FormOrders : Form +{ + private readonly IUnityContainer _container; + + private readonly IOrderRepository _orderRepository; + + public FormOrders(IUnityContainer container, IOrderRepository orderRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentException(nameof(container)); + _orderRepository = orderRepository + ?? throw new ArgumentException(nameof(orderRepository)); + } + private void FormOrder_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void ButtonCreate_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonChange_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectRow(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 (!TryGetIdentifierFromSelectRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + + try + { + _orderRepository.DeleteOrder(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView.DataSource = _orderRepository.ReadOrder(); + + private bool TryGetIdentifierFromSelectRow(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/ProjectCompRepair/ProjectCompRepair/Forms/FormOrders.resx b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrders.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormOrders.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormService.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormService.Designer.cs new file mode 100644 index 0000000..2965025 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormService.Designer.cs @@ -0,0 +1,122 @@ +namespace ProjectCompRepair.Forms +{ + partial class FormService + { + /// + /// 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() + { + labelType = new Label(); + labelPrice = new Label(); + checkedListBoxType = new CheckedListBox(); + numericUpDownPrice = new NumericUpDown(); + buttonSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit(); + SuspendLayout(); + // + // labelType + // + labelType.AutoSize = true; + labelType.Location = new Point(38, 70); + labelType.Name = "labelType"; + labelType.Size = new Size(83, 20); + labelType.TabIndex = 0; + labelType.Text = "Тип услуги"; + // + // labelPrice + // + labelPrice.AutoSize = true; + labelPrice.Location = new Point(38, 217); + labelPrice.Name = "labelPrice"; + labelPrice.Size = new Size(45, 20); + labelPrice.TabIndex = 1; + labelPrice.Text = "Цена"; + // + // checkedListBoxType + // + checkedListBoxType.FormattingEnabled = true; + checkedListBoxType.Location = new Point(145, 49); + checkedListBoxType.Name = "checkedListBoxType"; + checkedListBoxType.Size = new Size(230, 114); + checkedListBoxType.TabIndex = 3; + // + // numericUpDownPrice + // + numericUpDownPrice.DecimalPlaces = 2; + numericUpDownPrice.Location = new Point(145, 217); + numericUpDownPrice.Maximum = new decimal(new int[] { 100000, 0, 0, 0 }); + numericUpDownPrice.Name = "numericUpDownPrice"; + numericUpDownPrice.Size = new Size(230, 27); + numericUpDownPrice.TabIndex = 4; + // + // buttonSave + // + buttonSave.Location = new Point(38, 324); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(94, 29); + buttonSave.TabIndex = 5; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(281, 324); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 29); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormService + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(424, 393); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(numericUpDownPrice); + Controls.Add(checkedListBoxType); + Controls.Add(labelPrice); + Controls.Add(labelType); + Name = "FormService"; + Text = "Услуга"; + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label labelType; + private Label labelPrice; + private CheckedListBox checkedListBoxType; + private NumericUpDown numericUpDownPrice; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormService.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormService.cs new file mode 100644 index 0000000..28d3bf3 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormService.cs @@ -0,0 +1,119 @@ +using ProjectCompRepair.Entities; +using ProjectCompRepair.Entities.Enums; +using ProjectCompRepair.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 ProjectCompRepair.Forms +{ + public partial class FormService : Form + { + private readonly IServiceRepository _serviceRepository; + + private int? _service; + + public int Id + { + set + { + try + { + var service = _serviceRepository.ReadServiceById(value); + if (service == null) + { + throw new InvalidOperationException(nameof(service)); + } + + + foreach(ServiceType elem in Enum.GetValues(typeof(ServiceType))) + { + if((elem & service.ServiceType) != 0) + { + checkedListBoxType.SetItemChecked(checkedListBoxType.Items.IndexOf(elem), true); + } + } + + _service = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + public FormService(IServiceRepository serviceRepository) + { + InitializeComponent(); + _serviceRepository = serviceRepository ?? + throw new ArgumentNullException(nameof(serviceRepository)); + + foreach(var elem in Enum.GetValues(typeof(ServiceType))) + { + checkedListBoxType.Items.Add(elem); + } + } + + public FormService(IServiceRepository serviceRepository, int id) : this(serviceRepository) + { + InitializeComponent(); + + try + { + var service = _serviceRepository.ReadServiceById(id); + if (service == null) + { + throw new ArgumentNullException(nameof(serviceRepository)); + } + } + catch(Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (checkedListBoxType.CheckedItems.Count == 0) + { + throw new Exception("Имеются незаполненные поля"); + } + if (_service.HasValue) + { + _serviceRepository.UpdateService(CreateService(_service.Value)); + } + else + { + _serviceRepository.CreateService(CreateService(0)); + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Service CreateService(int id) + { + ServiceType serviceType = ServiceType.None; + foreach(var elem in checkedListBoxType.CheckedItems) + { + serviceType |= (ServiceType)elem; + } + return Service.CreateEntity(id, serviceType, (double)numericUpDownPrice.Value); + } + + } +} diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormService.resx b/ProjectCompRepair/ProjectCompRepair/Forms/FormService.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormService.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/ProjectCompRepair/ProjectCompRepair/Forms/FormServices.Designer.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormServices.Designer.cs new file mode 100644 index 0000000..fd1de50 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormServices.Designer.cs @@ -0,0 +1,118 @@ +namespace ProjectCompRepair.Forms +{ + partial class FormServices + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panelButtons = new Panel(); + buttonDel = new Button(); + buttonChange = new Button(); + buttonCreate = new Button(); + dataGridView = new DataGridView(); + panelButtons.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // panelButtons + // + panelButtons.Controls.Add(buttonDel); + panelButtons.Controls.Add(buttonChange); + panelButtons.Controls.Add(buttonCreate); + panelButtons.Dock = DockStyle.Right; + panelButtons.Location = new Point(536, 0); + panelButtons.Name = "panelButtons"; + panelButtons.Size = new Size(155, 450); + panelButtons.TabIndex = 0; + // + // buttonDel + // + buttonDel.BackgroundImage = Properties.Resources.pngwing_com__7_; + buttonDel.BackgroundImageLayout = ImageLayout.Stretch; + buttonDel.Location = new Point(40, 255); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(94, 91); + buttonDel.TabIndex = 2; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonChange + // + buttonChange.BackgroundImage = Properties.Resources.pngwing_com__8_; + buttonChange.BackgroundImageLayout = ImageLayout.Stretch; + buttonChange.Location = new Point(40, 149); + buttonChange.Name = "buttonChange"; + buttonChange.Size = new Size(94, 89); + buttonChange.TabIndex = 1; + buttonChange.UseVisualStyleBackColor = true; + buttonChange.Click += ButtonChange_Click; + // + // buttonCreate + // + buttonCreate.BackgroundImage = Properties.Resources.pngwing_com__6_; + buttonCreate.BackgroundImageLayout = ImageLayout.Stretch; + buttonCreate.Location = new Point(40, 43); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(94, 88); + buttonCreate.TabIndex = 0; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += ButtonCreate_Click; + // + // dataGridView + // + dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView.Dock = DockStyle.Fill; + dataGridView.Location = new Point(0, 0); + dataGridView.Name = "dataGridView"; + dataGridView.RowHeadersWidth = 51; + dataGridView.Size = new Size(536, 450); + dataGridView.TabIndex = 1; + // + // FormServices + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(691, 450); + Controls.Add(dataGridView); + Controls.Add(panelButtons); + Name = "FormServices"; + SizeGripStyle = SizeGripStyle.Hide; + Text = "Услуги"; + Load += FormService_Load; + panelButtons.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panelButtons; + private Button buttonDel; + private Button buttonChange; + private Button buttonCreate; + private DataGridView dataGridView; + } +} \ No newline at end of file diff --git a/ProjectCompRepair/ProjectCompRepair/Forms/FormServices.cs b/ProjectCompRepair/ProjectCompRepair/Forms/FormServices.cs new file mode 100644 index 0000000..4412c17 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormServices.cs @@ -0,0 +1,111 @@ +using ProjectCompRepair.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 ProjectCompRepair.Forms +{ + public partial class FormServices : Form + { + private readonly IUnityContainer _container; + + private readonly IServiceRepository _serviceRepository; + + public FormServices(IUnityContainer container, IServiceRepository serviceRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentException(nameof(container)); + _serviceRepository = serviceRepository + ?? throw new ArgumentException(nameof(serviceRepository)); + } + private void FormService_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + + } + private void ButtonCreate_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonChange_Click(object sender, EventArgs e) + { + if (!TryGetIdentifierFromSelectRow(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 (!TryGetIdentifierFromSelectRow(out var findId)) + { + return; + } + if (MessageBox.Show("Удалить запись", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + + try + { + _serviceRepository.DeleteService(findId); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при удалении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridView.DataSource = _serviceRepository.ReadService(); + + private bool TryGetIdentifierFromSelectRow(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/ProjectCompRepair/ProjectCompRepair/Forms/FormServices.resx b/ProjectCompRepair/ProjectCompRepair/Forms/FormServices.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectCompRepair/ProjectCompRepair/Forms/FormServices.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/ProjectCompRepair/ProjectCompRepair/Program.cs b/ProjectCompRepair/ProjectCompRepair/Program.cs index 82ab2b4..3acb23a 100644 --- a/ProjectCompRepair/ProjectCompRepair/Program.cs +++ b/ProjectCompRepair/ProjectCompRepair/Program.cs @@ -16,7 +16,7 @@ namespace ProjectCompRepair // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormCompRepair()); + Application.Run(CreateContainer().Resolve()); } private static IUnityContainer CreateContainer() @@ -27,7 +27,7 @@ namespace ProjectCompRepair container.RegisterType(); container.RegisterType(); container.RegisterType(); - container.RegisterType(); + return container; } diff --git a/ProjectCompRepair/ProjectCompRepair/Repositories/IWarehouseRepository.cs b/ProjectCompRepair/ProjectCompRepair/Repositories/IWarehouseRepository.cs deleted file mode 100644 index 3f2325d..0000000 --- a/ProjectCompRepair/ProjectCompRepair/Repositories/IWarehouseRepository.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using ProjectCompRepair.Entities; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectCompRepair.Repositories; - -public interface IWarehouseRepository -{ - IEnumerable ReadWarehouse(); - - Warehouse ReadWarehouseById(int id); - - void CreateWarehouse(Warehouse warehouse); - - void UpdateWarehouse(Warehouse warehouse); - - void DeleteWarehouse(int id); -} - diff --git a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesRepository.cs b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesRepository.cs index 59fb33c..0df9c6b 100644 --- a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesRepository.cs +++ b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/AccessoriesRepository.cs @@ -26,7 +26,7 @@ public class AccessoriesRepository : IAccessoriesRepository public Accessories ReadAccessoriesById(int id) { - return Accessories.CreateEntity(0, 0, 0); + return Accessories.CreateEntity(0, 0, 0, 0); } public void UpdateAccessories(Accessories accessories) diff --git a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/OrderRepository.cs b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/OrderRepository.cs index 811da19..41dad7d 100644 --- a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/OrderRepository.cs +++ b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/OrderRepository.cs @@ -26,7 +26,7 @@ public class OrderRepository : IOrderRepository public Order ReadOrderById(int id) { - return Order.CreateOperation(0, string.Empty, string.Empty, 0, 0, 0); + return Order.CreateElement(0, string.Empty, string.Empty, 0); } public void UpdateOrder(Order order) diff --git a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/ServiceRepository.cs b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/ServiceRepository.cs index 6ec9e72..5b0e277 100644 --- a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/ServiceRepository.cs +++ b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/ServiceRepository.cs @@ -26,7 +26,7 @@ public class ServiceRepository : IServiceRepository public Service ReadServiceById(int id) { - return Service.CreateOperation(0, 0, 0, 0); + return Service.CreateEntity(0, Entities.Enums.ServiceType.None, 0); } public void UpdateService(Service service) diff --git a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/WarehouseRepository.cs b/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/WarehouseRepository.cs deleted file mode 100644 index e2568ac..0000000 --- a/ProjectCompRepair/ProjectCompRepair/Repositories/Implemantations/WarehouseRepository.cs +++ /dev/null @@ -1,36 +0,0 @@ -using ProjectCompRepair.Entities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ProjectCompRepair.Repositories.Implemantations; - -public class WarehouseRepository : IWarehouseRepository -{ - public void CreateWarehouse(Warehouse warehouse) - { - - } - - public void DeleteWarehouse(int id) - { - - } - - public IEnumerable ReadWarehouse() - { - return []; - } - - public Warehouse ReadWarehouseById(int id) - { - return Warehouse.CreateEntity(0, string.Empty, 0); - } - - public void UpdateWarehouse(Warehouse warehouse) - { - - } -}