diff --git a/GasStation/Entities/Enums/Gasmen.cs b/GasStation/Entities/Enums/Gasmen.cs deleted file mode 100644 index 8cb05d9..0000000 --- a/GasStation/Entities/Enums/Gasmen.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace GasStation.Entities.Enums; - -[Flags] -public enum Gasmen -{ - None = 0, - - Gasman1 = 1, - - Gasman2 = 2, - - Gasman3 = 4 -} diff --git a/GasStation/Entities/Enums/Post.cs b/GasStation/Entities/Enums/Post.cs new file mode 100644 index 0000000..c9de91d --- /dev/null +++ b/GasStation/Entities/Enums/Post.cs @@ -0,0 +1,11 @@ +namespace GasStation.Entities.Enums; + +[Flags] +public enum Post +{ + None = 0, + + Gasman = 1, + + Cashier = 2 +} diff --git a/GasStation/Entities/Enums/ProductType.cs b/GasStation/Entities/Enums/ProductType.cs index 89d1c15..f69ca8c 100644 --- a/GasStation/Entities/Enums/ProductType.cs +++ b/GasStation/Entities/Enums/ProductType.cs @@ -4,11 +4,9 @@ public enum ProductType { None = 0 , - Gas92 = 1 , + Gas = 1 , - Gas95 = 2 , + Oil = 2 , - Diesel = 3, - - Oil = 4 + Antifreeze = 3 } diff --git a/GasStation/Entities/Gasman.cs b/GasStation/Entities/Gasman.cs index 5d4f49e..bf0d062 100644 --- a/GasStation/Entities/Gasman.cs +++ b/GasStation/Entities/Gasman.cs @@ -1,4 +1,6 @@ -namespace GasStation.Entities; +using GasStation.Entities.Enums; + +namespace GasStation.Entities; public class Gasman { @@ -8,13 +10,16 @@ public class Gasman public string PhoneNumber { get; private set; } = string.Empty; - public static Gasman CreateGasman(int id, string gasmanName, string phoneNumber) + public Post Post { get; private set; } + + public static Gasman CreateGasman(int id, string gasmanName, string phoneNumber, Post post) { return new Gasman { Id = id, GasmanName = gasmanName, - PhoneNumber = phoneNumber + PhoneNumber = phoneNumber, + Post = post }; } } diff --git a/GasStation/Entities/Product.cs b/GasStation/Entities/Product.cs index 80d16d5..934c577 100644 --- a/GasStation/Entities/Product.cs +++ b/GasStation/Entities/Product.cs @@ -8,17 +8,14 @@ public class Product public int Cost { get; private set; } - public Gasmen Gasmen { get; private set; } - public ProductType ProductType { get; private set; } - public static Product CreateProduct(int id, int cost ,Gasmen gasmen, ProductType productType) + public static Product CreateProduct(int id, int cost, ProductType productType) { return new Product { Id = id, Cost = cost, - Gasmen = gasmen, ProductType = productType }; } diff --git a/GasStation/Entities/ProductSelling.cs b/GasStation/Entities/ProductSelling.cs new file mode 100644 index 0000000..58ef24c --- /dev/null +++ b/GasStation/Entities/ProductSelling.cs @@ -0,0 +1,20 @@ +namespace GasStation.Entities; + +public class ProductSelling +{ + public int Id { get; private set; } + + public int ProductID { get; private set; } + + public int Count { get; private set; } + + public static ProductSelling CreateSelling(int id, int productID, int count) + { + return new ProductSelling + { + Id = id, + ProductID = productID, + Count = count + }; + } +} diff --git a/GasStation/Entities/Selling.cs b/GasStation/Entities/Selling.cs index 08c15ea..033282e 100644 --- a/GasStation/Entities/Selling.cs +++ b/GasStation/Entities/Selling.cs @@ -6,21 +6,21 @@ public class Selling public int GasmanId { get; private set; } - public int ProductID { get; private set; } - public int Count { get; private set; } + public IEnumerable ProdutcSellings { get; private set; } = []; + public DateTime SellingDateTime { get; private set; } - public static Selling CreateSelling(int id, int gasmanId, int productID, int count) + public static Selling CreateSelling(int id, int gasmanId, int count, IEnumerable produtcSellings) { return new Selling { Id = id, GasmanId = gasmanId, - ProductID = productID, Count = count, - SellingDateTime = DateTime.Now + SellingDateTime = DateTime.Now, + ProdutcSellings = produtcSellings }; } } diff --git a/GasStation/Entities/Supply.cs b/GasStation/Entities/Supply.cs index 054171e..5cdcda7 100644 --- a/GasStation/Entities/Supply.cs +++ b/GasStation/Entities/Supply.cs @@ -8,19 +8,19 @@ public class Supply public int ProductID { get; private set; } + public int Count { get; private set; } + public DateTime SupplyDate { get; private set; } - public IEnumerable SupplySupplies { get; private set; } = []; - - public static Supply CreateSupply(int id, int supplierID, int productID, IEnumerable supplySupplies) + public static Supply CreateSupply(int id, int supplierID, int productID, int count) { return new Supply { Id = id, SupplierID = supplierID, ProductID = productID, - SupplyDate = DateTime.Now, - SupplySupplies = supplySupplies + Count = count, + SupplyDate = DateTime.Now }; } } diff --git a/GasStation/Entities/SupplySupply.cs b/GasStation/Entities/SupplySupply.cs deleted file mode 100644 index d4744dd..0000000 --- a/GasStation/Entities/SupplySupply.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace GasStation.Entities; - -public class SupplySupply -{ - public int Id { get; private set; } - - public int Count { get; private set; } - - public static SupplySupply CreateSupply(int id, int count) - { - return new SupplySupply - { - Id = id, - Count = count - }; - } -} diff --git a/GasStation/Forms/FormGasman.Designer.cs b/GasStation/Forms/FormGasman.Designer.cs index 58625fa..f2ba1a0 100644 --- a/GasStation/Forms/FormGasman.Designer.cs +++ b/GasStation/Forms/FormGasman.Designer.cs @@ -34,6 +34,8 @@ textBoxNumber = new TextBox(); buttonSave = new Button(); buttonCancel = new Button(); + label1 = new Label(); + checkedListBoxPost = new CheckedListBox(); SuspendLayout(); // // labelName @@ -70,7 +72,7 @@ // // buttonSave // - buttonSave.Location = new Point(52, 169); + buttonSave.Location = new Point(52, 243); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(75, 23); buttonSave.TabIndex = 4; @@ -80,7 +82,7 @@ // // buttonCancel // - buttonCancel.Location = new Point(219, 169); + buttonCancel.Location = new Point(219, 243); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(75, 23); buttonCancel.TabIndex = 5; @@ -88,11 +90,30 @@ buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(34, 133); + label1.Name = "label1"; + label1.Size = new Size(69, 15); + label1.TabIndex = 6; + label1.Text = "Должность"; + // + // checkedListBoxPost + // + checkedListBoxPost.FormattingEnabled = true; + checkedListBoxPost.Location = new Point(141, 133); + checkedListBoxPost.Name = "checkedListBoxPost"; + checkedListBoxPost.Size = new Size(153, 94); + checkedListBoxPost.TabIndex = 7; + // // FormGasman // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(421, 248); + ClientSize = new Size(421, 291); + Controls.Add(checkedListBoxPost); + Controls.Add(label1); Controls.Add(buttonCancel); Controls.Add(buttonSave); Controls.Add(textBoxNumber); @@ -113,5 +134,7 @@ private TextBox textBoxNumber; private Button buttonSave; private Button buttonCancel; + private Label label1; + private CheckedListBox checkedListBoxPost; } } \ No newline at end of file diff --git a/GasStation/Forms/FormGasman.cs b/GasStation/Forms/FormGasman.cs index be060fa..d30bdbe 100644 --- a/GasStation/Forms/FormGasman.cs +++ b/GasStation/Forms/FormGasman.cs @@ -1,4 +1,5 @@ using GasStation.Entities; +using GasStation.Entities.Enums; using GasStation.Repositories; @@ -15,6 +16,11 @@ namespace GasStation.Forms InitializeComponent(); _gasmanRepository = gasmanRepository ?? throw new ArgumentNullException(nameof(gasmanRepository)); + + foreach (var elem in Enum.GetValues(typeof(Post))) + { + checkedListBoxPost.Items.Add(elem); + } } public int ID @@ -29,6 +35,14 @@ namespace GasStation.Forms throw new InvalidDataException(nameof(gasman)); } + foreach (Post elem in Enum.GetValues(typeof(Post))) + { + if ((elem & gasman.Post) != 0) + { + checkedListBoxPost.SetItemChecked(checkedListBoxPost.Items.IndexOf(elem), true); + } + } + textBoxName.Text = gasman.GasmanName; textBoxNumber.Text = gasman.PhoneNumber; _gasmanId = value; @@ -46,7 +60,8 @@ namespace GasStation.Forms try { if (string.IsNullOrWhiteSpace(textBoxName.Text) || - string.IsNullOrWhiteSpace(textBoxNumber.Text)) + string.IsNullOrWhiteSpace(textBoxNumber.Text) || + checkedListBoxPost.Items.Count == 0) { throw new Exception("Имеются незаполненые поля"); } @@ -69,6 +84,15 @@ namespace GasStation.Forms private void ButtonCancel_Click(object sender, EventArgs e) => Close(); - private Gasman CreateGasman(int id) => Gasman.CreateGasman(id, textBoxName.Text, textBoxNumber.Text); + private Gasman CreateGasman(int id) + { + Post post = Post.None; + foreach (var elem in checkedListBoxPost.CheckedItems) + { + post |= (Post)elem; + } + + return Gasman.CreateGasman(id, textBoxName.Text, textBoxNumber.Text, post); + } } } diff --git a/GasStation/Forms/FormProduct.Designer.cs b/GasStation/Forms/FormProduct.Designer.cs index 951a95f..b779f44 100644 --- a/GasStation/Forms/FormProduct.Designer.cs +++ b/GasStation/Forms/FormProduct.Designer.cs @@ -28,30 +28,19 @@ /// 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.Location = new Point(33, 29); label2.Name = "label2"; label2.Size = new Size(39, 15); label2.TabIndex = 1; @@ -60,7 +49,7 @@ // label3 // label3.AutoSize = true; - label3.Location = new Point(47, 202); + label3.Location = new Point(33, 99); label3.Name = "label3"; label3.Size = new Size(67, 15); label3.TabIndex = 2; @@ -68,10 +57,10 @@ // // numericUpDownCost // - numericUpDownCost.Location = new Point(193, 202); + numericUpDownCost.Location = new Point(178, 99); numericUpDownCost.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); numericUpDownCost.Name = "numericUpDownCost"; - numericUpDownCost.Size = new Size(156, 23); + numericUpDownCost.Size = new Size(169, 23); numericUpDownCost.TabIndex = 3; numericUpDownCost.Value = new decimal(new int[] { 1, 0, 0, 0 }); // @@ -79,24 +68,16 @@ // comboBoxProduct.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxProduct.FormattingEnabled = true; - comboBoxProduct.Location = new Point(194, 132); + comboBoxProduct.Location = new Point(179, 29); comboBoxProduct.Name = "comboBoxProduct"; - comboBoxProduct.Size = new Size(155, 23); + comboBoxProduct.Size = new Size(168, 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.Location = new Point(33, 166); buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(75, 23); + buttonSave.Size = new Size(88, 25); buttonSave.TabIndex = 6; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; @@ -104,9 +85,9 @@ // // buttonCancel // - buttonCancel.Location = new Point(269, 269); + buttonCancel.Location = new Point(254, 166); buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(80, 23); + buttonCancel.Size = new Size(93, 25); buttonCancel.TabIndex = 7; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; @@ -116,15 +97,13 @@ // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(401, 314); + ClientSize = new Size(414, 246); 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(); @@ -133,13 +112,10 @@ } #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; } diff --git a/GasStation/Forms/FormProduct.cs b/GasStation/Forms/FormProduct.cs index 25a2b27..52c48db 100644 --- a/GasStation/Forms/FormProduct.cs +++ b/GasStation/Forms/FormProduct.cs @@ -2,93 +2,76 @@ using GasStation.Repositories; using GasStation.Entities; -namespace GasStation.Forms +namespace GasStation.Forms; + +public partial class FormProduct : Form { - public partial class FormProduct : Form + + private readonly IProductRepository _productRepository; + + private int? _productId; + + public FormProduct(IProductRepository productRepository) { + InitializeComponent(); + _productRepository = productRepository ?? + throw new ArgumentNullException(nameof(productRepository)); - private readonly IProductRepository _productRepository; + comboBoxProduct.DataSource = Enum.GetValues(typeof(ProductType)); + } - 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) + public int ID + { + set { try { - if (checkedListBoxGasman.CheckedItems.Count == 0) + var product = _productRepository.ReadProductByID(value); + if (product == null) { - throw new Exception("Имеются незаполненые поля"); + throw new InvalidDataException(nameof(product)); } - if (_productId.HasValue) - { - _productRepository.UpdateProduct(CreateProduct(_productId.Value)); - } - else - { - _productRepository.CreateProduct(CreateProduct(0)); - } - Close(); + + comboBoxProduct.SelectedItem = product.ProductType; + _productId = value; } catch (Exception ex) { - MessageBox.Show(ex.Message, "Ошибка при сохранении", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show(ex.Message, "Ошибка при получении данных", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } + } - private void ButtonCancel_Click(object sender, EventArgs e) => Close(); - - private Product CreateProduct(int id) + private void ButtonSave_Click(object sender, EventArgs e) + { + try { - Gasmen gasmen = Gasmen.None; - foreach (var elem in checkedListBoxGasman.CheckedItems) + if (comboBoxProduct.SelectedIndex < 1) { - gasmen |= (Gasmen)elem; + throw new Exception("Имеются незаполненые поля"); } - return Product.CreateProduct(id, Convert.ToInt32(numericUpDownCost.Value), gasmen, (ProductType)comboBoxProduct.SelectedItem!); + 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) => + Product.CreateProduct(id, Convert.ToInt32(numericUpDownCost.Value), + (ProductType)comboBoxProduct.SelectedItem!); + } diff --git a/GasStation/Forms/FormSelling.Designer.cs b/GasStation/Forms/FormSelling.Designer.cs index e136618..44dd24f 100644 --- a/GasStation/Forms/FormSelling.Designer.cs +++ b/GasStation/Forms/FormSelling.Designer.cs @@ -29,14 +29,15 @@ 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(); + groupBoxSelling = new GroupBox(); + dataGridViewSelling = new DataGridView(); + ColumnProduct = new DataGridViewComboBoxColumn(); + ColumnCount = new DataGridViewTextBoxColumn(); + groupBoxSelling.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)dataGridViewSelling).BeginInit(); SuspendLayout(); // // label1 @@ -48,54 +49,19 @@ 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.Location = new Point(147, 35); comboBoxGasman.Name = "comboBoxGasman"; - comboBoxGasman.Size = new Size(121, 23); + comboBoxGasman.Size = new Size(200, 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.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonSave.Location = new Point(47, 358); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(75, 23); buttonSave.TabIndex = 6; @@ -105,7 +71,8 @@ // // buttonCancel // - buttonCancel.Location = new Point(194, 238); + buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; + buttonCancel.Location = new Point(279, 358); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(75, 23); buttonCancel.TabIndex = 7; @@ -113,22 +80,59 @@ buttonCancel.UseVisualStyleBackColor = true; buttonCancel.Click += ButtonCancel_Click; // + // groupBoxSelling + // + groupBoxSelling.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + groupBoxSelling.Controls.Add(dataGridViewSelling); + groupBoxSelling.Location = new Point(47, 91); + groupBoxSelling.Name = "groupBoxSelling"; + groupBoxSelling.Size = new Size(307, 211); + groupBoxSelling.TabIndex = 8; + groupBoxSelling.TabStop = false; + groupBoxSelling.Text = "Продажа"; + // + // dataGridViewSelling + // + dataGridViewSelling.AllowUserToResizeColumns = false; + dataGridViewSelling.AllowUserToResizeRows = false; + dataGridViewSelling.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + dataGridViewSelling.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewSelling.Columns.AddRange(new DataGridViewColumn[] { ColumnProduct, ColumnCount }); + dataGridViewSelling.Dock = DockStyle.Fill; + dataGridViewSelling.Location = new Point(3, 19); + dataGridViewSelling.MultiSelect = false; + dataGridViewSelling.Name = "dataGridViewSelling"; + dataGridViewSelling.RowHeadersVisible = false; + dataGridViewSelling.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridViewSelling.Size = new Size(301, 189); + dataGridViewSelling.TabIndex = 0; + // + // ColumnProduct + // + ColumnProduct.HeaderText = "Товар"; + ColumnProduct.Name = "ColumnProduct"; + ColumnProduct.Resizable = DataGridViewTriState.True; + ColumnProduct.SortMode = DataGridViewColumnSortMode.Automatic; + // + // ColumnCount + // + ColumnCount.HeaderText = "Количество"; + ColumnCount.Name = "ColumnCount"; + // // FormSelling // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(336, 297); + ClientSize = new Size(458, 432); + Controls.Add(groupBoxSelling); 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(); + groupBoxSelling.ResumeLayout(false); + ((System.ComponentModel.ISupportInitialize)dataGridViewSelling).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -136,12 +140,12 @@ #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; + private GroupBox groupBoxSelling; + private DataGridView dataGridViewSelling; + private DataGridViewComboBoxColumn ColumnProduct; + private DataGridViewTextBoxColumn ColumnCount; } } \ No newline at end of file diff --git a/GasStation/Forms/FormSelling.cs b/GasStation/Forms/FormSelling.cs index 4a0ed59..41be98e 100644 --- a/GasStation/Forms/FormSelling.cs +++ b/GasStation/Forms/FormSelling.cs @@ -1,6 +1,5 @@ using GasStation.Entities; using GasStation.Repositories; -using GasStation.Repositories.Implementations; namespace GasStation.Forms @@ -19,9 +18,9 @@ namespace GasStation.Forms comboBoxGasman.DisplayMember = "GasmanName"; comboBoxGasman.ValueMember = "ID"; - comboBoxProduct.DataSource = productRepository.ReadProduct(); - comboBoxProduct.DisplayMember = "ProductName"; - comboBoxProduct.ValueMember = "ID"; + ColumnProduct.DataSource = productRepository.ReadProduct(); + ColumnProduct.DisplayMember = "ProductType"; + ColumnProduct.ValueMember = "ID"; } private void ButtonSave_Click(object sender, EventArgs e) @@ -29,13 +28,13 @@ namespace GasStation.Forms try { if (comboBoxGasman.SelectedIndex < 0 || - comboBoxProduct.SelectedIndex < 0) + dataGridViewSelling.RowCount < 1) { throw new Exception("Имеются незаполненые поля"); } _sellingRepository.CreateSelling(Selling.CreateSelling(0, (int)comboBoxGasman.SelectedValue!, - (int)comboBoxProduct.SelectedValue!, Convert.ToInt32(numericUpDownCount.Value))); + 0, CreateProductSellingsFromDataGrid())); Close(); } @@ -47,5 +46,23 @@ namespace GasStation.Forms } private void ButtonCancel_Click(object sender, EventArgs e) => Close(); + + private List CreateProductSellingsFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridViewSelling.Rows) + { + if (row.Cells["ColumnProduct"].Value == null || row.Cells["ColumnCount"].Value == null) + { + continue; + } + + list.Add(ProductSelling.CreateSelling(0, Convert.ToInt32(row.Cells["ColumnProduct"].Value), + Convert.ToInt32(row.Cells["ColumnCount"].Value))); + } + + return list; + } + } } diff --git a/GasStation/Forms/FormSelling.resx b/GasStation/Forms/FormSelling.resx index 8b2ff64..9746ebf 100644 --- a/GasStation/Forms/FormSelling.resx +++ b/GasStation/Forms/FormSelling.resx @@ -117,4 +117,16 @@ 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/Forms/FormSupply.Designer.cs b/GasStation/Forms/FormSupply.Designer.cs index 01c8a40..b52e1a4 100644 --- a/GasStation/Forms/FormSupply.Designer.cs +++ b/GasStation/Forms/FormSupply.Designer.cs @@ -31,19 +31,18 @@ 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(); + label1 = new Label(); + numericUpDownCount = new NumericUpDown(); + label2 = new Label(); + comboBoxProduct = new ComboBox(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).BeginInit(); SuspendLayout(); // // buttonSave // buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonSave.Location = new Point(21, 290); + buttonSave.Location = new Point(21, 236); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(89, 24); buttonSave.TabIndex = 1; @@ -54,7 +53,7 @@ // buttonCancel // buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; - buttonCancel.Location = new Point(221, 290); + buttonCancel.Location = new Point(221, 236); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(92, 24); buttonCancel.TabIndex = 2; @@ -71,65 +70,67 @@ 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.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxSupplier.FormattingEnabled = true; comboBoxSupplier.Location = new Point(97, 23); comboBoxSupplier.Name = "comboBoxSupplier"; comboBoxSupplier.Size = new Size(216, 23); comboBoxSupplier.TabIndex = 7; // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(21, 91); + label1.Name = "label1"; + label1.Size = new Size(66, 15); + label1.TabIndex = 8; + label1.Text = "Количесто"; + // + // numericUpDownCount + // + numericUpDownCount.Location = new Point(97, 89); + numericUpDownCount.Minimum = new decimal(new int[] { 1, 0, 0, 0 }); + numericUpDownCount.Name = "numericUpDownCount"; + numericUpDownCount.Size = new Size(216, 23); + numericUpDownCount.TabIndex = 9; + numericUpDownCount.Value = new decimal(new int[] { 1, 0, 0, 0 }); + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(21, 147); + label2.Name = "label2"; + label2.Size = new Size(39, 15); + label2.TabIndex = 10; + label2.Text = "Товар"; + // + // comboBoxProduct + // + comboBoxProduct.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxProduct.FormattingEnabled = true; + comboBoxProduct.Location = new Point(96, 147); + comboBoxProduct.Name = "comboBoxProduct"; + comboBoxProduct.Size = new Size(217, 23); + comboBoxProduct.TabIndex = 11; + // // FormSupply // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(435, 380); + ClientSize = new Size(435, 326); + Controls.Add(comboBoxProduct); + Controls.Add(label2); + Controls.Add(numericUpDownCount); + Controls.Add(label1); 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(); + ((System.ComponentModel.ISupportInitialize)numericUpDownCount).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -139,10 +140,10 @@ private Button buttonSave; private Button buttonCancel; private Label labelSupplier; - private GroupBox groupBoxSupply; - private DataGridView dataGridViewSupply; private ComboBox comboBoxSupplier; - private DataGridViewComboBoxColumn ColumnProduct; - private DataGridViewTextBoxColumn ColumnCount; + private Label label1; + private NumericUpDown numericUpDownCount; + private Label label2; + private ComboBox comboBoxProduct; } } \ No newline at end of file diff --git a/GasStation/Forms/FormSupply.cs b/GasStation/Forms/FormSupply.cs index b4abbc2..dfa4ee6 100644 --- a/GasStation/Forms/FormSupply.cs +++ b/GasStation/Forms/FormSupply.cs @@ -17,22 +17,23 @@ namespace GasStation.Forms comboBoxSupplier.DisplayMember = "SupplierName"; comboBoxSupplier.ValueMember = "ID"; - ColumnProduct.DataSource = productRepository.ReadProduct(); - ColumnProduct.DisplayMember = "Cost"; - ColumnProduct.ValueMember = "ID"; + comboBoxProduct.DataSource = productRepository.ReadProduct(); + comboBoxProduct.DisplayMember = "ProductType"; + comboBoxProduct.ValueMember = "ID"; } private void ButtonSave_Click(object sender, EventArgs e) { try { - if (dataGridViewSupply.RowCount < 1 || + if (comboBoxProduct.SelectedIndex < 0 || comboBoxSupplier.SelectedIndex < 0) { throw new Exception("Имеются незаполненые поля"); } - _supplyRepository.CreateSupply(Supply.CreateSupply(0, (int)comboBoxSupplier.SelectedValue!, 0, CreateListSellingFromDataGrid())); + _supplyRepository.CreateSupply(Supply.CreateSupply(0, (int)comboBoxSupplier.SelectedValue!, + (int)comboBoxProduct.SelectedValue!, Convert.ToInt32(numericUpDownCount.Value))); Close(); } @@ -45,19 +46,5 @@ namespace GasStation.Forms 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 index 9746ebf..8b2ff64 100644 --- a/GasStation/Forms/FormSupply.resx +++ b/GasStation/Forms/FormSupply.resx @@ -117,16 +117,4 @@ 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/Repositories/ISellingRepository.cs b/GasStation/Repositories/ISellingRepository.cs index 2371e57..8996d8c 100644 --- a/GasStation/Repositories/ISellingRepository.cs +++ b/GasStation/Repositories/ISellingRepository.cs @@ -4,7 +4,9 @@ namespace GasStation.Repositories; public interface ISellingRepository { - IEnumerable ReadSelling(DateTime? dateTime = null, int? count = null, int? productID = null, int? gasmanID = null); + IEnumerable ReadSelling(DateTime? dateTime = null, int? count = null, int? gasmanID = null); void CreateSelling(Selling selling); + + void DeleteSelling(int id); } diff --git a/GasStation/Repositories/ISupplyRepository.cs b/GasStation/Repositories/ISupplyRepository.cs index 7c51bca..c693ec7 100644 --- a/GasStation/Repositories/ISupplyRepository.cs +++ b/GasStation/Repositories/ISupplyRepository.cs @@ -4,7 +4,7 @@ namespace GasStation.Repositories; public interface ISupplyRepository { - IEnumerable ReadSupply(DateTime? supplyDate = null, int? supplierID = null, int? productID = null); + IEnumerable ReadSupply(DateTime? supplyDate = null, int? supplierID = null, int? productID = null, int? count = null); void CreateSupply(Supply supply); diff --git a/GasStation/Repositories/Implementations/GasmanRepository.cs b/GasStation/Repositories/Implementations/GasmanRepository.cs index d075ea5..43b35e9 100644 --- a/GasStation/Repositories/Implementations/GasmanRepository.cs +++ b/GasStation/Repositories/Implementations/GasmanRepository.cs @@ -1,4 +1,5 @@ using GasStation.Entities; +using GasStation.Entities.Enums; namespace GasStation.Repositories.Implementations; @@ -14,7 +15,7 @@ public class GasmanRepository : IGasmanRepository public Gasman ReadGasmanByID(int id) { - return Gasman.CreateGasman(0, string.Empty, string.Empty); + return Gasman.CreateGasman(0, string.Empty, string.Empty, Post.None); } public IEnumerable ReadGasman() diff --git a/GasStation/Repositories/Implementations/ProductRepository.cs b/GasStation/Repositories/Implementations/ProductRepository.cs index 35eea00..e7c03e6 100644 --- a/GasStation/Repositories/Implementations/ProductRepository.cs +++ b/GasStation/Repositories/Implementations/ProductRepository.cs @@ -20,7 +20,7 @@ public class ProductRepository : IProductRepository public Product ReadProductByID(int id) { - return Product.CreateProduct(0, 0, Gasmen.None, ProductType.None); + return Product.CreateProduct(0, 0, ProductType.None); } public void UpdateProduct(Product product) diff --git a/GasStation/Repositories/Implementations/SellingRepository.cs b/GasStation/Repositories/Implementations/SellingRepository.cs index 3c3e387..a712507 100644 --- a/GasStation/Repositories/Implementations/SellingRepository.cs +++ b/GasStation/Repositories/Implementations/SellingRepository.cs @@ -8,7 +8,11 @@ public class SellingRepository : ISellingRepository { } - public IEnumerable ReadSelling(DateTime? dateTime = null, int? count = null, int? productID = null, int? gasmanID = null) + public void DeleteSelling(int id) + { + } + + public IEnumerable ReadSelling(DateTime? dateTime = null, int? count = null, int? gasmanID = null) { return []; } diff --git a/GasStation/Repositories/Implementations/SupplyRepository.cs b/GasStation/Repositories/Implementations/SupplyRepository.cs index b903e4f..4373fb3 100644 --- a/GasStation/Repositories/Implementations/SupplyRepository.cs +++ b/GasStation/Repositories/Implementations/SupplyRepository.cs @@ -12,7 +12,7 @@ public class SupplyRepository : ISupplyRepository { } - public IEnumerable ReadSupply(DateTime? supplyDate = null, int? supplierID = null, int? productID = null) + public IEnumerable ReadSupply(DateTime? supplyDate = null, int? supplierID = null, int? productID = null, int? count = null) { return []; }