diff --git a/GasStation/Entities/Enums/ProductType.cs b/GasStation/Entities/Enums/ProductType.cs new file mode 100644 index 0000000..89d1c15 --- /dev/null +++ b/GasStation/Entities/Enums/ProductType.cs @@ -0,0 +1,14 @@ +namespace GasStation.Entities.Enums; + +public enum ProductType +{ + None = 0 , + + Gas92 = 1 , + + Gas95 = 2 , + + Diesel = 3, + + Oil = 4 +} diff --git a/GasStation/Entities/Product.cs b/GasStation/Entities/Product.cs index 6c3790d..80d16d5 100644 --- a/GasStation/Entities/Product.cs +++ b/GasStation/Entities/Product.cs @@ -6,14 +6,20 @@ public class Product { public int Id { get; private set; } - public Gasmen Gasman { get; private set; } + public int Cost { get; private set; } - public static Product CreateProduct(int id, Gasmen gasman) + public Gasmen Gasmen { get; private set; } + + public ProductType ProductType { get; private set; } + + public static Product CreateProduct(int id, int cost ,Gasmen gasmen, ProductType productType) { return new Product { Id = id, - Gasman = gasman + Cost = cost, + Gasmen = gasmen, + ProductType = productType }; } } diff --git a/GasStation/FormGasstation.Designer.cs b/GasStation/FormGasstation.Designer.cs index fd0deb6..1442f50 100644 --- a/GasStation/FormGasstation.Designer.cs +++ b/GasStation/FormGasstation.Designer.cs @@ -30,13 +30,13 @@ { menuStrip1 = new MenuStrip(); справочникиToolStripMenuItem = new ToolStripMenuItem(); + GasmanToolStripMenuItem = new ToolStripMenuItem(); + SupplierToolStripMenuItem = new ToolStripMenuItem(); + ProductToolStripMenuItem = new ToolStripMenuItem(); операцииToolStripMenuItem = new ToolStripMenuItem(); + SupplyToolStripMenuItem = new ToolStripMenuItem(); + SellingToolStripMenuItem = new ToolStripMenuItem(); отчётыToolStripMenuItem = new ToolStripMenuItem(); - заправщикToolStripMenuItem = new ToolStripMenuItem(); - поставщикToolStripMenuItem = new ToolStripMenuItem(); - товарToolStripMenuItem = new ToolStripMenuItem(); - поставкаToolStripMenuItem = new ToolStripMenuItem(); - продажаToolStripMenuItem = new ToolStripMenuItem(); menuStrip1.SuspendLayout(); SuspendLayout(); // @@ -51,54 +51,59 @@ // // справочникиToolStripMenuItem // - справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { заправщикToolStripMenuItem, поставщикToolStripMenuItem, товарToolStripMenuItem }); + справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { GasmanToolStripMenuItem, SupplierToolStripMenuItem, ProductToolStripMenuItem }); справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem"; справочникиToolStripMenuItem.Size = new Size(94, 20); справочникиToolStripMenuItem.Text = "Справочники"; // + // GasmanToolStripMenuItem + // + GasmanToolStripMenuItem.Name = "GasmanToolStripMenuItem"; + GasmanToolStripMenuItem.Size = new Size(180, 22); + GasmanToolStripMenuItem.Text = "Заправщик"; + GasmanToolStripMenuItem.Click += GasmanToolStripMenuItem_Click; + // + // SupplierToolStripMenuItem + // + SupplierToolStripMenuItem.Name = "SupplierToolStripMenuItem"; + SupplierToolStripMenuItem.Size = new Size(180, 22); + SupplierToolStripMenuItem.Text = "Поставщик"; + SupplierToolStripMenuItem.Click += SupplierToolStripMenuItem_Click; + // + // ProductToolStripMenuItem + // + ProductToolStripMenuItem.Name = "ProductToolStripMenuItem"; + ProductToolStripMenuItem.Size = new Size(180, 22); + ProductToolStripMenuItem.Text = "Товар"; + ProductToolStripMenuItem.Click += ProductToolStripMenuItem_Click; + // // операцииToolStripMenuItem // - операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { поставкаToolStripMenuItem, продажаToolStripMenuItem }); + операцииToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { SupplyToolStripMenuItem, SellingToolStripMenuItem }); операцииToolStripMenuItem.Name = "операцииToolStripMenuItem"; операцииToolStripMenuItem.Size = new Size(75, 20); операцииToolStripMenuItem.Text = "Операции"; // + // SupplyToolStripMenuItem + // + SupplyToolStripMenuItem.Name = "SupplyToolStripMenuItem"; + SupplyToolStripMenuItem.Size = new Size(180, 22); + SupplyToolStripMenuItem.Text = "Поставка"; + SupplyToolStripMenuItem.Click += SupplyToolStripMenuItem_Click; + // + // SellingToolStripMenuItem + // + SellingToolStripMenuItem.Name = "SellingToolStripMenuItem"; + SellingToolStripMenuItem.Size = new Size(180, 22); + SellingToolStripMenuItem.Text = "Продажа"; + SellingToolStripMenuItem.Click += SellingToolStripMenuItem_Click; + // // отчётыToolStripMenuItem // отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem"; отчётыToolStripMenuItem.Size = new Size(60, 20); отчёты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 = "Товар"; - // - // поставкаToolStripMenuItem - // - поставкаToolStripMenuItem.Name = "поставкаToolStripMenuItem"; - поставкаToolStripMenuItem.Size = new Size(180, 22); - поставкаToolStripMenuItem.Text = "Поставка"; - // - // продажаToolStripMenuItem - // - продажаToolStripMenuItem.Name = "продажаToolStripMenuItem"; - продажаToolStripMenuItem.Size = new Size(180, 22); - продажаToolStripMenuItem.Text = "Продажа"; - // // FormGasStation // AutoScaleDimensions = new SizeF(7F, 15F); @@ -123,10 +128,10 @@ private ToolStripMenuItem справочникиToolStripMenuItem; private ToolStripMenuItem операцииToolStripMenuItem; private ToolStripMenuItem отчётыToolStripMenuItem; - private ToolStripMenuItem заправщикToolStripMenuItem; - private ToolStripMenuItem поставщикToolStripMenuItem; - private ToolStripMenuItem товарToolStripMenuItem; - private ToolStripMenuItem поставкаToolStripMenuItem; - private ToolStripMenuItem продажаToolStripMenuItem; + private ToolStripMenuItem GasmanToolStripMenuItem; + private ToolStripMenuItem SupplierToolStripMenuItem; + private ToolStripMenuItem ProductToolStripMenuItem; + private ToolStripMenuItem SupplyToolStripMenuItem; + private ToolStripMenuItem SellingToolStripMenuItem; } } diff --git a/GasStation/FormGasstation.cs b/GasStation/FormGasstation.cs index cf0982b..3d05cd9 100644 --- a/GasStation/FormGasstation.cs +++ b/GasStation/FormGasstation.cs @@ -1,10 +1,77 @@ +using GasStation.Forms; +using Unity; + namespace GasStation { public partial class FormGasStation : System.Windows.Forms.Form { - public FormGasStation() + private readonly IUnityContainer _container; + + public FormGasStation(IUnityContainer container) { InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + } + + private void GasmanToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void SupplierToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ProductToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void SupplyToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void SellingToolStripMenuItem_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } } } diff --git a/GasStation/Forms/FormGasman.Designer.cs b/GasStation/Forms/FormGasman.Designer.cs index b307769..58625fa 100644 --- a/GasStation/Forms/FormGasman.Designer.cs +++ b/GasStation/Forms/FormGasman.Designer.cs @@ -48,11 +48,11 @@ // labelNumber // labelNumber.AutoSize = true; - labelNumber.Location = new Point(52, 94); + labelNumber.Location = new Point(34, 89); labelNumber.Name = "labelNumber"; - labelNumber.Size = new Size(45, 15); + labelNumber.Size = new Size(101, 15); labelNumber.TabIndex = 1; - labelNumber.Text = "Номер"; + labelNumber.Text = "Номер телефона"; // // textBoxName // diff --git a/GasStation/Forms/FormGasman.cs b/GasStation/Forms/FormGasman.cs index 9fc1bc3..be060fa 100644 --- a/GasStation/Forms/FormGasman.cs +++ b/GasStation/Forms/FormGasman.cs @@ -24,7 +24,7 @@ namespace GasStation.Forms try { var gasman = _gasmanRepository.ReadGasmanByID(value); - if (gasman != null) + if (gasman == null) { throw new InvalidDataException(nameof(gasman)); } diff --git a/GasStation/Forms/FormProduct.Designer.cs b/GasStation/Forms/FormProduct.Designer.cs new file mode 100644 index 0000000..951a95f --- /dev/null +++ b/GasStation/Forms/FormProduct.Designer.cs @@ -0,0 +1,146 @@ +namespace GasStation.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() + { + label1 = new Label(); + label2 = new Label(); + label3 = new Label(); + numericUpDownCost = new NumericUpDown(); + comboBoxProduct = new ComboBox(); + checkedListBoxGasman = new CheckedListBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCost).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(43, 29); + label1.Name = "label1"; + label1.Size = new Size(70, 15); + label1.TabIndex = 0; + label1.Text = "Заправщик"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(43, 132); + label2.Name = "label2"; + label2.Size = new Size(39, 15); + label2.TabIndex = 1; + label2.Text = "Товар"; + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(47, 202); + label3.Name = "label3"; + label3.Size = new Size(67, 15); + label3.TabIndex = 2; + label3.Text = "Стоимость"; + // + // numericUpDownCost + // + numericUpDownCost.Location = new Point(193, 202); + numericUpDownCost.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); + numericUpDownCost.Name = "numericUpDownCost"; + numericUpDownCost.Size = new Size(156, 23); + numericUpDownCost.TabIndex = 3; + numericUpDownCost.Value = new decimal(new int[] { 1, 0, 0, 0 }); + // + // comboBoxProduct + // + comboBoxProduct.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxProduct.FormattingEnabled = true; + comboBoxProduct.Location = new Point(194, 132); + comboBoxProduct.Name = "comboBoxProduct"; + comboBoxProduct.Size = new Size(155, 23); + comboBoxProduct.TabIndex = 4; + // + // checkedListBoxGasman + // + checkedListBoxGasman.FormattingEnabled = true; + checkedListBoxGasman.Location = new Point(194, 29); + checkedListBoxGasman.Name = "checkedListBoxGasman"; + checkedListBoxGasman.Size = new Size(155, 76); + checkedListBoxGasman.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(47, 269); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(269, 269); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(80, 23); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormProduct + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(401, 314); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(checkedListBoxGasman); + Controls.Add(comboBoxProduct); + Controls.Add(numericUpDownCost); + Controls.Add(label3); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormProduct"; + Text = "Товар"; + ((System.ComponentModel.ISupportInitialize)numericUpDownCost).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private Label label3; + private NumericUpDown numericUpDownCost; + private ComboBox comboBoxProduct; + private CheckedListBox checkedListBoxGasman; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/GasStation/Forms/FormProduct.cs b/GasStation/Forms/FormProduct.cs new file mode 100644 index 0000000..25a2b27 --- /dev/null +++ b/GasStation/Forms/FormProduct.cs @@ -0,0 +1,94 @@ +using GasStation.Entities.Enums; +using GasStation.Repositories; +using GasStation.Entities; + +namespace GasStation.Forms +{ + public partial class FormProduct : Form + { + + private readonly IProductRepository _productRepository; + + private int? _productId; + + public FormProduct(IProductRepository productRepository) + { + InitializeComponent(); + _productRepository = productRepository ?? + throw new ArgumentNullException(nameof(productRepository)); + foreach (var elem in Enum.GetValues(typeof(Gasmen))) + { + checkedListBoxGasman.Items.Add(elem); + } + } + + public int ID + { + set + { + try + { + var product = _productRepository.ReadProductByID(value); + if (product == null) + { + throw new InvalidDataException(nameof(product)); + } + + foreach(Gasmen elem in Enum.GetValues(typeof(Gasmen))) + { + if ((elem & product.Gasmen) != 0) + { + checkedListBoxGasman.SetItemChecked(checkedListBoxGasman.Items.IndexOf(elem), true); + } + } + + checkedListBoxGasman.SelectedItem = product.Gasmen; + comboBoxProduct.SelectedItem = product.ProductType; + _productId = value; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (checkedListBoxGasman.CheckedItems.Count == 0) + { + throw new Exception("Имеются незаполненые поля"); + } + if (_productId.HasValue) + { + _productRepository.UpdateProduct(CreateProduct(_productId.Value)); + } + else + { + _productRepository.CreateProduct(CreateProduct(0)); + } + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private Product CreateProduct(int id) + { + Gasmen gasmen = Gasmen.None; + foreach (var elem in checkedListBoxGasman.CheckedItems) + { + gasmen |= (Gasmen)elem; + } + return Product.CreateProduct(id, Convert.ToInt32(numericUpDownCost.Value), gasmen, (ProductType)comboBoxProduct.SelectedItem!); + } + } +} diff --git a/GasStation/Forms/FormProduct.resx b/GasStation/Forms/FormProduct.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/GasStation/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/GasStation/Forms/FormProducts.Designer.cs b/GasStation/Forms/FormProducts.Designer.cs new file mode 100644 index 0000000..d1dab9b --- /dev/null +++ b/GasStation/Forms/FormProducts.Designer.cs @@ -0,0 +1,122 @@ +namespace GasStation.Forms +{ + partial class FormProducts + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new Panel(); + buttonUpd = new Button(); + buttonDel = new Button(); + buttonAdd = new Button(); + dataGridViewData = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonUpd); + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(657, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(143, 450); + panel1.TabIndex = 1; + // + // buttonUpd + // + buttonUpd.Location = new Point(35, 343); + buttonUpd.Name = "buttonUpd"; + buttonUpd.Size = new Size(75, 69); + buttonUpd.TabIndex = 3; + buttonUpd.Text = "Редактировать"; + buttonUpd.UseVisualStyleBackColor = true; + buttonUpd.Click += ButtonUpd_Click; + // + // buttonDel + // + buttonDel.Location = new Point(33, 188); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(77, 73); + buttonDel.TabIndex = 2; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(32, 30); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 73); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(657, 450); + dataGridViewData.TabIndex = 2; + // + // FormProducts + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormProducts"; + Text = "Товары"; + Load += FormProducts_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonUpd; + private Button buttonDel; + private Button buttonAdd; + private DataGridView dataGridViewData; + } +} \ No newline at end of file diff --git a/GasStation/Forms/FormProducts.cs b/GasStation/Forms/FormProducts.cs new file mode 100644 index 0000000..f69fe13 --- /dev/null +++ b/GasStation/Forms/FormProducts.cs @@ -0,0 +1,104 @@ +using GasStation.Repositories; +using Unity; + +namespace GasStation.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 ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIDFromSelectedRow(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 ButtonUpd_Click(object sender, EventArgs e) + { + if (!TryGetIDFromSelectedRow(out var findID)) + { + return; + } + + try + { + var form = _container.Resolve(); + form.ID = findID; + form.ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при изменении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private bool TryGetIDFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewData.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["ID"].Value); + return true; + } + + private void FormProducts_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewData.DataSource = _productRepository.ReadProduct(); + } +} diff --git a/GasStation/Forms/FormProducts.resx b/GasStation/Forms/FormProducts.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/GasStation/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/GasStation/Forms/FormSelling.Designer.cs b/GasStation/Forms/FormSelling.Designer.cs new file mode 100644 index 0000000..e136618 --- /dev/null +++ b/GasStation/Forms/FormSelling.Designer.cs @@ -0,0 +1,147 @@ +namespace GasStation.Forms +{ + partial class FormSelling + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + label1 = new Label(); + label2 = new Label(); + numericUpDownCount = new NumericUpDown(); + label3 = new Label(); + comboBoxGasman = new ComboBox(); + comboBoxProduct = new ComboBox(); + buttonSave = new Button(); + buttonCancel = new Button(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); + SuspendLayout(); + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(47, 35); + label1.Name = "label1"; + label1.Size = new Size(70, 15); + label1.TabIndex = 0; + label1.Text = "Заправщик"; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(47, 98); + label2.Name = "label2"; + label2.Size = new Size(39, 15); + label2.TabIndex = 1; + label2.Text = "Товар"; + // + // numericUpDownCount + // + numericUpDownCount.Location = new Point(149, 164); + numericUpDownCount.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); + numericUpDownCount.Name = "numericUpDownCount"; + numericUpDownCount.Size = new Size(120, 23); + numericUpDownCount.TabIndex = 2; + numericUpDownCount.Value = new decimal(new int[] { 1, 0, 0, 0 }); + // + // label3 + // + label3.AutoSize = true; + label3.Location = new Point(47, 172); + label3.Name = "label3"; + label3.Size = new Size(46, 15); + label3.TabIndex = 3; + label3.Text = "Кол-во"; + // + // comboBoxGasman + // + comboBoxGasman.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxGasman.FormattingEnabled = true; + comboBoxGasman.Location = new Point(147, 27); + comboBoxGasman.Name = "comboBoxGasman"; + comboBoxGasman.Size = new Size(121, 23); + comboBoxGasman.TabIndex = 4; + // + // comboBoxProduct + // + comboBoxProduct.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxProduct.FormattingEnabled = true; + comboBoxProduct.Location = new Point(148, 90); + comboBoxProduct.Name = "comboBoxProduct"; + comboBoxProduct.Size = new Size(121, 23); + comboBoxProduct.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(47, 238); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(75, 23); + buttonSave.TabIndex = 6; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(194, 238); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(75, 23); + buttonCancel.TabIndex = 7; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // FormSelling + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(336, 297); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(comboBoxProduct); + Controls.Add(comboBoxGasman); + Controls.Add(label3); + Controls.Add(numericUpDownCount); + Controls.Add(label2); + Controls.Add(label1); + Name = "FormSelling"; + Text = "Продажа"; + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Label label1; + private Label label2; + private NumericUpDown numericUpDownCount; + private Label label3; + private ComboBox comboBoxGasman; + private ComboBox comboBoxProduct; + private Button buttonSave; + private Button buttonCancel; + } +} \ No newline at end of file diff --git a/GasStation/Forms/FormSelling.cs b/GasStation/Forms/FormSelling.cs new file mode 100644 index 0000000..4a0ed59 --- /dev/null +++ b/GasStation/Forms/FormSelling.cs @@ -0,0 +1,51 @@ +using GasStation.Entities; +using GasStation.Repositories; +using GasStation.Repositories.Implementations; + + +namespace GasStation.Forms +{ + public partial class FormSelling : Form + { + private readonly ISellingRepository _sellingRepository; + + public FormSelling(ISellingRepository sellingRepository, IGasmanRepository gasmanRepository, IProductRepository productRepository) + { + InitializeComponent(); + _sellingRepository = sellingRepository ?? + throw new ArgumentNullException(nameof(sellingRepository)); + + comboBoxGasman.DataSource = gasmanRepository.ReadGasman(); + comboBoxGasman.DisplayMember = "GasmanName"; + comboBoxGasman.ValueMember = "ID"; + + comboBoxProduct.DataSource = productRepository.ReadProduct(); + comboBoxProduct.DisplayMember = "ProductName"; + comboBoxProduct.ValueMember = "ID"; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (comboBoxGasman.SelectedIndex < 0 || + comboBoxProduct.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненые поля"); + } + + _sellingRepository.CreateSelling(Selling.CreateSelling(0, (int)comboBoxGasman.SelectedValue!, + (int)comboBoxProduct.SelectedValue!, Convert.ToInt32(numericUpDownCount.Value))); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + } +} diff --git a/GasStation/Forms/FormSelling.resx b/GasStation/Forms/FormSelling.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/GasStation/Forms/FormSelling.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/GasStation/Forms/FormSellings.Designer.cs b/GasStation/Forms/FormSellings.Designer.cs new file mode 100644 index 0000000..50855bb --- /dev/null +++ b/GasStation/Forms/FormSellings.Designer.cs @@ -0,0 +1,96 @@ +namespace GasStation.Forms +{ + partial class FormSellings + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new Panel(); + buttonAdd = new Button(); + dataGridViewData = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(657, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(143, 450); + panel1.TabIndex = 2; + // + // buttonAdd + // + buttonAdd.Location = new Point(35, 166); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 73); + buttonAdd.TabIndex = 1; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(657, 450); + dataGridViewData.TabIndex = 3; + // + // FormSellings + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormSellings"; + Text = "Продажи"; + Load += FormSellings_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonAdd; + private DataGridView dataGridViewData; + } +} \ No newline at end of file diff --git a/GasStation/Forms/FormSellings.cs b/GasStation/Forms/FormSellings.cs new file mode 100644 index 0000000..756a85d --- /dev/null +++ b/GasStation/Forms/FormSellings.cs @@ -0,0 +1,49 @@ +using GasStation.Repositories; +using Unity; + +namespace GasStation.Forms +{ + public partial class FormSellings : Form + { + private readonly IUnityContainer _container; + + private readonly ISellingRepository _sellingRepository; + + public FormSellings(IUnityContainer container, ISellingRepository sellingRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _sellingRepository = sellingRepository ?? + throw new ArgumentNullException(nameof(sellingRepository)); + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewData.DataSource = _sellingRepository.ReadSelling(); + + private void FormSellings_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + } +} diff --git a/GasStation/Forms/FormSellings.resx b/GasStation/Forms/FormSellings.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/GasStation/Forms/FormSellings.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/GasStation/Forms/FormSupplier.Designer.cs b/GasStation/Forms/FormSupplier.Designer.cs index 85466e7..dc24570 100644 --- a/GasStation/Forms/FormSupplier.Designer.cs +++ b/GasStation/Forms/FormSupplier.Designer.cs @@ -28,19 +28,12 @@ /// private void InitializeComponent() { - textBoxSupplierName = new TextBox(); labelSupplier = new Label(); buttonSave = new Button(); buttonCancel = new Button(); + comboBoxSupplierName = new ComboBox(); SuspendLayout(); // - // textBoxSupplierName - // - textBoxSupplierName.Location = new Point(100, 12); - textBoxSupplierName.Name = "textBoxSupplierName"; - textBoxSupplierName.Size = new Size(290, 23); - textBoxSupplierName.TabIndex = 0; - // // labelSupplier // labelSupplier.AutoSize = true; @@ -70,15 +63,24 @@ buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; // + // comboBoxSupplierName + // + comboBoxSupplierName.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSupplierName.FormattingEnabled = true; + comboBoxSupplierName.Location = new Point(100, 12); + comboBoxSupplierName.Name = "comboBoxSupplierName"; + comboBoxSupplierName.Size = new Size(290, 23); + comboBoxSupplierName.TabIndex = 4; + // // FormSupplier // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(438, 122); + Controls.Add(comboBoxSupplierName); Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(labelSupplier); - Controls.Add(textBoxSupplierName); Name = "FormSupplier"; StartPosition = FormStartPosition.CenterParent; Text = "FormSupplier"; @@ -87,10 +89,9 @@ } #endregion - - private TextBox textBoxSupplierName; private Label labelSupplier; private Button buttonSave; private Button buttonCancel; + private ComboBox comboBoxSupplierName; } } \ No newline at end of file diff --git a/GasStation/Forms/FormSupplier.cs b/GasStation/Forms/FormSupplier.cs index e3b523e..b85b92c 100644 --- a/GasStation/Forms/FormSupplier.cs +++ b/GasStation/Forms/FormSupplier.cs @@ -16,12 +16,12 @@ namespace GasStation.Forms try { var supplier = _suppliarRepository.ReadSupplierByID(value); - if (supplier != null) + if (supplier == null) { throw new InvalidDataException(nameof(supplier)); } - textBoxSupplierName.Text = supplier.ProductName; + comboBoxSupplierName.DataSource = supplier.ProductName; _supplierId = value; } catch (Exception ex) @@ -43,7 +43,7 @@ namespace GasStation.Forms { try { - if (string.IsNullOrWhiteSpace(textBoxSupplierName.Text)) + if (comboBoxSupplierName.SelectedIndex < 1) { throw new Exception("Имеются незаполненые поля"); } @@ -64,7 +64,7 @@ namespace GasStation.Forms } } - private Supplier CreateSupplier(int id) => Supplier.CreateSupplier(id, textBoxSupplierName.Text); + private Supplier CreateSupplier(int id) => Supplier.CreateSupplier(id, comboBoxSupplierName.Text); private void ButtonCancel_Click(object sender, EventArgs e) => Close(); } diff --git a/GasStation/Forms/FormSupplies.Designer.cs b/GasStation/Forms/FormSupplies.Designer.cs new file mode 100644 index 0000000..2d3a373 --- /dev/null +++ b/GasStation/Forms/FormSupplies.Designer.cs @@ -0,0 +1,108 @@ +namespace GasStation.Forms +{ + partial class FormSupplies + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + panel1 = new Panel(); + buttonDel = new Button(); + buttonAdd = new Button(); + dataGridViewData = new DataGridView(); + panel1.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).BeginInit(); + SuspendLayout(); + // + // panel1 + // + panel1.Controls.Add(buttonDel); + panel1.Controls.Add(buttonAdd); + panel1.Dock = DockStyle.Right; + panel1.Location = new Point(630, 0); + panel1.Name = "panel1"; + panel1.Size = new Size(170, 450); + panel1.TabIndex = 1; + // + // buttonDel + // + buttonDel.Location = new Point(45, 296); + buttonDel.Name = "buttonDel"; + buttonDel.Size = new Size(77, 73); + buttonDel.TabIndex = 1; + buttonDel.Text = "Удалить"; + buttonDel.UseVisualStyleBackColor = true; + buttonDel.Click += ButtonDel_Click; + // + // buttonAdd + // + buttonAdd.Location = new Point(47, 41); + buttonAdd.Name = "buttonAdd"; + buttonAdd.Size = new Size(75, 73); + buttonAdd.TabIndex = 0; + buttonAdd.Text = "Добавить"; + buttonAdd.UseVisualStyleBackColor = true; + buttonAdd.Click += ButtonAdd_Click; + // + // dataGridViewData + // + dataGridViewData.AllowUserToAddRows = false; + dataGridViewData.AllowUserToDeleteRows = false; + dataGridViewData.AllowUserToResizeColumns = false; + dataGridViewData.AllowUserToResizeRows = false; + dataGridViewData.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewData.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewData.Dock = DockStyle.Fill; + dataGridViewData.Location = new Point(0, 0); + dataGridViewData.MultiSelect = false; + dataGridViewData.Name = "dataGridViewData"; + dataGridViewData.ReadOnly = true; + dataGridViewData.RowHeadersVisible = false; + dataGridViewData.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewData.Size = new Size(630, 450); + dataGridViewData.TabIndex = 2; + // + // FormSupplies + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(dataGridViewData); + Controls.Add(panel1); + Name = "FormSupplies"; + Load += FormSupplies_Load; + panel1.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewData).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel panel1; + private Button buttonDel; + private Button buttonAdd; + private DataGridView dataGridViewData; + } +} \ No newline at end of file diff --git a/GasStation/Forms/FormSupplies.cs b/GasStation/Forms/FormSupplies.cs new file mode 100644 index 0000000..c393032 --- /dev/null +++ b/GasStation/Forms/FormSupplies.cs @@ -0,0 +1,84 @@ +using GasStation.Repositories; +using Unity; + +namespace GasStation.Forms +{ + public partial class FormSupplies : Form + { + private readonly IUnityContainer _container; + + private readonly ISupplyRepository _supplyRepository; + + public FormSupplies(IUnityContainer container, ISupplyRepository supplyRepository) + { + InitializeComponent(); + _container = container ?? + throw new ArgumentNullException(nameof(container)); + _supplyRepository = supplyRepository ?? + throw new ArgumentNullException(nameof(supplyRepository)); + } + + private void ButtonAdd_Click(object sender, EventArgs e) + { + try + { + _container.Resolve().ShowDialog(); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при добавлении", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonDel_Click(object sender, EventArgs e) + { + if (!TryGetIDFromSelectedRow(out var findID)) + { + return; + } + + if (MessageBox.Show("Удалить запись?", "Удаление", MessageBoxButtons.YesNo) != DialogResult.Yes) + { + return; + } + + try + { + _supplyRepository.DeleteSupply(findID); + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка удаления", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void LoadList() => dataGridViewData.DataSource = _supplyRepository.ReadSupply(); + + private void FormSupplies_Load(object sender, EventArgs e) + { + try + { + LoadList(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при загрузке", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private bool TryGetIDFromSelectedRow(out int id) + { + id = 0; + if (dataGridViewData.SelectedRows.Count < 1) + { + MessageBox.Show("Нет выбранной записи", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + return false; + } + + id = Convert.ToInt32(dataGridViewData.SelectedRows[0].Cells["ID"].Value); + return true; + } + } +} diff --git a/GasStation/Forms/FormSupplies.resx b/GasStation/Forms/FormSupplies.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/GasStation/Forms/FormSupplies.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/GasStation/Forms/FormSupply.Designer.cs b/GasStation/Forms/FormSupply.Designer.cs new file mode 100644 index 0000000..01c8a40 --- /dev/null +++ b/GasStation/Forms/FormSupply.Designer.cs @@ -0,0 +1,148 @@ +namespace GasStation.Forms +{ + partial class FormSupply + { + /// + /// 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() + { + buttonSave = new Button(); + buttonCancel = new Button(); + labelSupplier = new Label(); + groupBoxSupply = new GroupBox(); + dataGridViewSupply = new DataGridView(); + ColumnProduct = new DataGridViewComboBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + comboBoxSupplier = new ComboBox(); + groupBoxSupply.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewSupply).BeginInit(); + SuspendLayout(); + // + // buttonSave + // + buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(21, 290); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(89, 24); + buttonSave.TabIndex = 1; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += ButtonSave_Click; + // + // buttonCancel + // + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(221, 290); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(92, 24); + buttonCancel.TabIndex = 2; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // labelSupplier + // + labelSupplier.AutoSize = true; + labelSupplier.Location = new Point(21, 23); + labelSupplier.Name = "labelSupplier"; + labelSupplier.Size = new Size(70, 15); + labelSupplier.TabIndex = 5; + labelSupplier.Text = "Поставщик"; + // + // groupBoxSupply + // + groupBoxSupply.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBoxSupply.Controls.Add(dataGridViewSupply); + groupBoxSupply.Location = new Point(21, 62); + groupBoxSupply.Name = "groupBoxSupply"; + groupBoxSupply.Size = new Size(292, 185); + groupBoxSupply.TabIndex = 6; + groupBoxSupply.TabStop = false; + groupBoxSupply.Text = "Поставки"; + // + // dataGridViewSupply + // + dataGridViewSupply.AllowUserToResizeColumns = false; + dataGridViewSupply.AllowUserToResizeRows = false; + dataGridViewSupply.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewSupply.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewSupply.Columns.AddRange(new DataGridViewColumn[] { ColumnProduct, ColumnCount }); + dataGridViewSupply.Dock = DockStyle.Fill; + dataGridViewSupply.Location = new Point(3, 19); + dataGridViewSupply.Name = "dataGridViewSupply"; + dataGridViewSupply.RowHeadersVisible = false; + dataGridViewSupply.Size = new Size(286, 163); + dataGridViewSupply.TabIndex = 0; + // + // ColumnProduct + // + ColumnProduct.HeaderText = "Товар"; + ColumnProduct.Name = "ColumnProduct"; + ColumnProduct.Resizable = DataGridViewTriState.True; + ColumnProduct.SortMode = DataGridViewColumnSortMode.Automatic; + // + // ColumnCount + // + ColumnCount.HeaderText = "Кол-во"; + ColumnCount.Name = "ColumnCount"; + // + // comboBoxSupplier + // + comboBoxSupplier.FormattingEnabled = true; + comboBoxSupplier.Location = new Point(97, 23); + comboBoxSupplier.Name = "comboBoxSupplier"; + comboBoxSupplier.Size = new Size(216, 23); + comboBoxSupplier.TabIndex = 7; + // + // FormSupply + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(435, 380); + Controls.Add(comboBoxSupplier); + Controls.Add(groupBoxSupply); + Controls.Add(labelSupplier); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Name = "FormSupply"; + Text = "Поставки"; + groupBoxSupply.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewSupply).EndInit(); + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonSave; + private Button buttonCancel; + private Label labelSupplier; + private GroupBox groupBoxSupply; + private DataGridView dataGridViewSupply; + private ComboBox comboBoxSupplier; + private DataGridViewComboBoxColumn ColumnProduct; + private DataGridViewTextBoxColumn ColumnCount; + } +} \ No newline at end of file diff --git a/GasStation/Forms/FormSupply.cs b/GasStation/Forms/FormSupply.cs new file mode 100644 index 0000000..b4abbc2 --- /dev/null +++ b/GasStation/Forms/FormSupply.cs @@ -0,0 +1,63 @@ +using GasStation.Repositories; +using GasStation.Entities; + +namespace GasStation.Forms +{ + public partial class FormSupply : Form + { + private readonly ISupplyRepository _supplyRepository; + + public FormSupply(ISupplyRepository supplyRepository, ISupplierRepository supplierRepository, IProductRepository productRepository) + { + InitializeComponent(); + _supplyRepository = supplyRepository ?? + throw new ArgumentNullException(nameof(supplyRepository)); + + comboBoxSupplier.DataSource = supplierRepository.ReadSupplier(); + comboBoxSupplier.DisplayMember = "SupplierName"; + comboBoxSupplier.ValueMember = "ID"; + + ColumnProduct.DataSource = productRepository.ReadProduct(); + ColumnProduct.DisplayMember = "Cost"; + ColumnProduct.ValueMember = "ID"; + } + + private void ButtonSave_Click(object sender, EventArgs e) + { + try + { + if (dataGridViewSupply.RowCount < 1 || + comboBoxSupplier.SelectedIndex < 0) + { + throw new Exception("Имеются незаполненые поля"); + } + + _supplyRepository.CreateSupply(Supply.CreateSupply(0, (int)comboBoxSupplier.SelectedValue!, 0, CreateListSellingFromDataGrid())); + + Close(); + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + return; + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private List CreateListSellingFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridViewSupply.Rows) + { + if (row.Cells["ColumnProduct"].Value == null || row.Cells["ColumnCount"].Value == null) + { + continue; + } + list.Add(SupplySupply.CreateSupply(0, Convert.ToInt32(row.Cells["ColumnCount"].Value))); + } + + return list; + } + } +} diff --git a/GasStation/Forms/FormSupply.resx b/GasStation/Forms/FormSupply.resx new file mode 100644 index 0000000..9746ebf --- /dev/null +++ b/GasStation/Forms/FormSupply.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/GasStation/Program.cs b/GasStation/Program.cs index cf073c0..7cecfb7 100644 --- a/GasStation/Program.cs +++ b/GasStation/Program.cs @@ -27,6 +27,7 @@ internal static class Program container.RegisterType(); container.RegisterType(); container.RegisterType(); + container.RegisterType(); return container; } diff --git a/GasStation/Repositories/IProductRepository.cs b/GasStation/Repositories/IProductRepository.cs new file mode 100644 index 0000000..24799db --- /dev/null +++ b/GasStation/Repositories/IProductRepository.cs @@ -0,0 +1,16 @@ +using GasStation.Entities; + +namespace GasStation.Repositories; + +public interface IProductRepository +{ + IEnumerable ReadProduct(); + + Product ReadProductByID(int id); + + void CreateProduct(Product product); + + void UpdateProduct(Product product); + + void DeleteProduct(int id); +} diff --git a/GasStation/Repositories/ISupplyRepository.cs b/GasStation/Repositories/ISupplyRepository.cs index 8e8758f..7c51bca 100644 --- a/GasStation/Repositories/ISupplyRepository.cs +++ b/GasStation/Repositories/ISupplyRepository.cs @@ -6,7 +6,7 @@ public interface ISupplyRepository { IEnumerable ReadSupply(DateTime? supplyDate = null, int? supplierID = null, int? productID = null); - void CreateSelling(Supply supply); + void CreateSupply(Supply supply); - void DeleteSelling(int id); + void DeleteSupply(int id); } diff --git a/GasStation/Repositories/Implementations/ProductRepository.cs b/GasStation/Repositories/Implementations/ProductRepository.cs new file mode 100644 index 0000000..35eea00 --- /dev/null +++ b/GasStation/Repositories/Implementations/ProductRepository.cs @@ -0,0 +1,29 @@ +using GasStation.Entities; +using GasStation.Entities.Enums; + +namespace GasStation.Repositories.Implementations; + +public class ProductRepository : IProductRepository +{ + public void CreateProduct(Product product) + { + } + + public void DeleteProduct(int id) + { + } + + public IEnumerable ReadProduct() + { + return []; + } + + public Product ReadProductByID(int id) + { + return Product.CreateProduct(0, 0, Gasmen.None, ProductType.None); + } + + public void UpdateProduct(Product product) + { + } +} diff --git a/GasStation/Repositories/Implementations/SupplyRepository.cs b/GasStation/Repositories/Implementations/SupplyRepository.cs index dce1020..b903e4f 100644 --- a/GasStation/Repositories/Implementations/SupplyRepository.cs +++ b/GasStation/Repositories/Implementations/SupplyRepository.cs @@ -4,11 +4,11 @@ namespace GasStation.Repositories.Implementations; public class SupplyRepository : ISupplyRepository { - public void CreateSelling(Supply supply) + public void CreateSupply(Supply supply) { } - public void DeleteSelling(int id) + public void DeleteSupply(int id) { }