From 5fc338cc39407e8adedb47995b41346af5c12ceb Mon Sep 17 00:00:00 2001 From: Glliza Date: Fri, 13 Dec 2024 11:09:20 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=82=D0=BE=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ShoeStore/Entities/Receipt.cs | 4 +- ShoeStore/Forms/FormReceipt.Designer.cs | 42 ++++++++++++++----- ShoeStore/Forms/FormReceipt.cs | 18 +++++++- ShoeStore/Forms/FormSale.cs | 1 + .../Implementations/ReceiptRepository.cs | 4 +- .../Implementations/SaleRepository.cs | 4 +- 6 files changed, 56 insertions(+), 17 deletions(-) diff --git a/ShoeStore/Entities/Receipt.cs b/ShoeStore/Entities/Receipt.cs index e5f0b5e..a23cea0 100644 --- a/ShoeStore/Entities/Receipt.cs +++ b/ShoeStore/Entities/Receipt.cs @@ -13,12 +13,12 @@ public class Receipt //public int ProductId { get; private set; } //public int StorageProductId { get; private set; } //public int ReceiptNumber {get; private set; } - public int ProductType { get; private set; } + public ProductType ProductType { get; private set; } public DateTime DateOfReceipt { get; private set; } public int NumberOfPairsReceived { get; private set; } //public int StorageSize { get; private set; } - public static Receipt CreateOperation(int id, int productType, int numberOfPairsReceived) + public static Receipt CreateOperation(int id, ProductType productType, int numberOfPairsReceived) { return new Receipt { diff --git a/ShoeStore/Forms/FormReceipt.Designer.cs b/ShoeStore/Forms/FormReceipt.Designer.cs index e69ed90..223f3d9 100644 --- a/ShoeStore/Forms/FormReceipt.Designer.cs +++ b/ShoeStore/Forms/FormReceipt.Designer.cs @@ -33,7 +33,9 @@ buttonCancel = new Button(); buttonSave = new Button(); label = new Label(); - comboBox1 = new ComboBox(); + comboBoxProdctType = new ComboBox(); + label1 = new Label(); + dateTimePickerDate = new DateTimePicker(); ((System.ComponentModel.ISupportInitialize)numericUpDownNumOfPairs).BeginInit(); SuspendLayout(); // @@ -76,26 +78,44 @@ // label // label.AutoSize = true; - label.Location = new Point(27, 69); + label.Location = new Point(27, 96); label.Name = "label"; label.Size = new Size(70, 15); label.TabIndex = 19; label.Text = "Тип товара:"; // - // comboBox1 + // comboBoxProdctType // - comboBox1.FormattingEnabled = true; - comboBox1.Location = new Point(246, 69); - comboBox1.Name = "comboBox1"; - comboBox1.Size = new Size(121, 23); - comboBox1.TabIndex = 20; + comboBoxProdctType.FormattingEnabled = true; + comboBoxProdctType.Location = new Point(246, 96); + comboBoxProdctType.Name = "comboBoxProdctType"; + comboBoxProdctType.Size = new Size(121, 23); + comboBoxProdctType.TabIndex = 20; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(27, 36); + label1.Name = "label1"; + label1.Size = new Size(35, 15); + label1.TabIndex = 22; + label1.Text = "Дата:"; + // + // dateTimePickerDate + // + dateTimePickerDate.Location = new Point(246, 36); + dateTimePickerDate.Name = "dateTimePickerDate"; + dateTimePickerDate.Size = new Size(132, 23); + dateTimePickerDate.TabIndex = 21; // // FormReceipt // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(398, 330); - Controls.Add(comboBox1); + Controls.Add(label1); + Controls.Add(dateTimePickerDate); + Controls.Add(comboBoxProdctType); Controls.Add(label); Controls.Add(buttonCancel); Controls.Add(buttonSave); @@ -114,6 +134,8 @@ private Button buttonCancel; private Button buttonSave; private Label label; - private ComboBox comboBox1; + private ComboBox comboBoxProdctType; + private Label label1; + private DateTimePicker dateTimePickerDate; } } \ No newline at end of file diff --git a/ShoeStore/Forms/FormReceipt.cs b/ShoeStore/Forms/FormReceipt.cs index 87c0ee7..150df42 100644 --- a/ShoeStore/Forms/FormReceipt.cs +++ b/ShoeStore/Forms/FormReceipt.cs @@ -1,4 +1,5 @@ using ShoeStore.Entities; +using ShoeStore.Entities.Enums; using ShoeStore.Repositories; using ShoeStore.Repositories.Implementations; using System; @@ -24,21 +25,36 @@ namespace ShoeStore.Froms InitializeComponent(); _receiptRepository = receiptRepository ?? throw new ArgumentNullException(nameof(receiptRepository)); + foreach (var elem in Enum.GetValues(typeof(ProductType))) + { + comboBoxProdctType.Items.Add(elem); + } + } private void buttonSave_Click(object sender, EventArgs e) { try { + ProductType productType = ProductType.None; + if (comboBoxProdctType.SelectedItem != null) + { + productType = (ProductType)Enum.Parse(typeof(ProductType), comboBoxProdctType.SelectedItem.ToString()); + } + else + { + throw new Exception("Не выбран тип продукта"); + } if (numericUpDownNumOfPairs.Value < 0) { throw new Exception("Имеются незаполненные поля"); } _receiptRepository.CreateReceipt(Receipt.CreateOperation( 0, - (int)comboBox1.SelectedValue!, + productType, Convert.ToInt32(numericUpDownNumOfPairs.Value))); Close(); + } catch (Exception ex) { diff --git a/ShoeStore/Forms/FormSale.cs b/ShoeStore/Forms/FormSale.cs index 34a2a28..0b0bf0d 100644 --- a/ShoeStore/Forms/FormSale.cs +++ b/ShoeStore/Forms/FormSale.cs @@ -25,6 +25,7 @@ public partial class FormSale : Form ColumnProduct.DataSource = productRepository.ReadProducts(); ColumnProduct.DisplayMember = "NameOfShoes"; ColumnProduct.ValueMember = "Id"; + } private void ButtonSave_Click_1(object sender, EventArgs e) diff --git a/ShoeStore/Repositories/Implementations/ReceiptRepository.cs b/ShoeStore/Repositories/Implementations/ReceiptRepository.cs index 1f33f1e..619501b 100644 --- a/ShoeStore/Repositories/Implementations/ReceiptRepository.cs +++ b/ShoeStore/Repositories/Implementations/ReceiptRepository.cs @@ -33,8 +33,8 @@ public class ReceiptRepository : IReceiptRepository try { using var connection = new NpgsqlConnection(_connectionString.ConnectionString); - var queryInsert = @"INSERT INTO Receipts (ProductType, NumberOfPairsReceived, Date) - VALUES (@ProductType, @NumberOfPairsReceived, @Date)"; + var queryInsert = @"INSERT INTO Receipts (ProductType, NumberOfPairsReceived, DateOfReceipt) + VALUES (@ProductType, @NumberOfPairsReceived, @DateOfReceipt)"; connection.Execute(queryInsert, receipt); } catch (Exception ex) diff --git a/ShoeStore/Repositories/Implementations/SaleRepository.cs b/ShoeStore/Repositories/Implementations/SaleRepository.cs index 5961c95..f8a2617 100644 --- a/ShoeStore/Repositories/Implementations/SaleRepository.cs +++ b/ShoeStore/Repositories/Implementations/SaleRepository.cs @@ -35,8 +35,8 @@ public class SaleRepository : ISaleRepository connection.Open(); using var transaction = connection.BeginTransaction(); var queryInsert = @" - INSERT INTO Sales (SalesNumber, Date) - VALUES (@SalesNumber, @Date); + INSERT INTO Sales (SalesNumber, DateOfSale) + VALUES (@SalesNumber, @DateOfSale); SELECT MAX(Id) FROM Sales"; var visitingId = connection.QueryFirst(queryInsert, sale, transaction); var querySubInsert = @"