From dc2a6f84869e4da9417b8ca8e81d449887304c81 Mon Sep 17 00:00:00 2001 From: Glliza Date: Sat, 21 Dec 2024 21:15:47 +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/Employee.cs | 4 +-- ShoeStore/Entities/ProductSale.cs | 6 ++--- ShoeStore/Entities/Receipt.cs | 10 ++----- ShoeStore/Entities/Sale.cs | 6 ++--- ShoeStore/Forms/FormEmployee.cs | 4 ++- ShoeStore/Forms/FormReceipt.cs | 3 ++- ShoeStore/Forms/FormSale.Designer.cs | 26 +++++++++---------- ShoeStore/Forms/FormSale.cs | 24 ++++++++++++++--- .../Implementations/ProductRepository.cs | 2 +- .../Implementations/SaleRepository.cs | 2 +- 10 files changed, 51 insertions(+), 36 deletions(-) diff --git a/ShoeStore/Entities/Employee.cs b/ShoeStore/Entities/Employee.cs index 54af1f2..f6c8d6d 100644 --- a/ShoeStore/Entities/Employee.cs +++ b/ShoeStore/Entities/Employee.cs @@ -13,12 +13,12 @@ public class Employee public int NumberStorage { get; private set; } public int StorageSize { get; private set; } - public static Employee CreateEntity(int id, int numberStorage, int storageSize) + public static Employee CreateEntity(int id, DateTime date,int numberStorage, int storageSize) { return new Employee { Id = id, - Date = DateTime.Now, + Date = date, NumberStorage = numberStorage, StorageSize = storageSize }; diff --git a/ShoeStore/Entities/ProductSale.cs b/ShoeStore/Entities/ProductSale.cs index e1903d1..6f096fc 100644 --- a/ShoeStore/Entities/ProductSale.cs +++ b/ShoeStore/Entities/ProductSale.cs @@ -10,14 +10,14 @@ public class ProductSale { public int ProductId { get; private set; } public int SaleId { get; private set; } - public int Amount { get; private set; } + public int SalesNumber { get; private set; } - public static ProductSale CreateEntities(int productId, int saleId, int amount) + public static ProductSale CreateOperation(int productId, int saleId, int salesNumber) { return new ProductSale { ProductId = productId, SaleId = saleId, - Amount = amount + SalesNumber = salesNumber }; } } diff --git a/ShoeStore/Entities/Receipt.cs b/ShoeStore/Entities/Receipt.cs index a23cea0..2df168c 100644 --- a/ShoeStore/Entities/Receipt.cs +++ b/ShoeStore/Entities/Receipt.cs @@ -10,25 +10,19 @@ namespace ShoeStore.Entities; public class Receipt { public int Id { get; private set; } - //public int ProductId { get; private set; } - //public int StorageProductId { get; private set; } - //public int ReceiptNumber {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, ProductType productType, int numberOfPairsReceived) + public static Receipt CreateOperation(int id,ProductType productType, DateTime date,int numberOfPairsReceived) { return new Receipt { Id = id, ProductType = productType, - //StorageProductId = storageProductId, - //ReceiptNumber = receiptNumber, - DateOfReceipt = DateTime.Now, + DateOfReceipt = date, NumberOfPairsReceived = numberOfPairsReceived, - //StorageSize = storageSize }; } diff --git a/ShoeStore/Entities/Sale.cs b/ShoeStore/Entities/Sale.cs index da68ca1..299931d 100644 --- a/ShoeStore/Entities/Sale.cs +++ b/ShoeStore/Entities/Sale.cs @@ -19,14 +19,14 @@ public class Sale private set; } = []; - public static Sale CreateOperation (int id, int salesNumber) + public static Sale CreateOperation(int id, int salesNumber, DateTime date, IEnumerable product) { return new Sale { Id = id, - DateOfSale = DateTime.Now, + DateOfSale = date, SalesNumber = salesNumber, - //StorageSize = storageSize + Product = product }; } diff --git a/ShoeStore/Forms/FormEmployee.cs b/ShoeStore/Forms/FormEmployee.cs index 5b3a020..f0e1152 100644 --- a/ShoeStore/Forms/FormEmployee.cs +++ b/ShoeStore/Forms/FormEmployee.cs @@ -17,6 +17,7 @@ public partial class FormEmployee : Form { private readonly IEmployeeRepository _employeeRepository; private int? _employeeId; + private DateTime _originalDate; public int Id { @@ -31,6 +32,7 @@ public partial class FormEmployee : Form } numericUpDownNumStorage.Value = employee.NumberStorage; numericUpDownStorageSize.Value = (decimal)employee.StorageSize; + dateTimePickerDate.Value = employee.Date; _employeeId = value; } catch (Exception ex) @@ -77,6 +79,6 @@ public partial class FormEmployee : Form private void ButtonCancel_Click_1(object sender, EventArgs e) => Close(); - private Employee CreateEmployee(int id) => Employee.CreateEntity(id, Convert.ToInt32(numericUpDownNumStorage.Value), + private Employee CreateEmployee(int id) => Employee.CreateEntity(id, dateTimePickerDate.Value,Convert.ToInt32(numericUpDownNumStorage.Value), Convert.ToInt32(numericUpDownStorageSize.Value)); } diff --git a/ShoeStore/Forms/FormReceipt.cs b/ShoeStore/Forms/FormReceipt.cs index 150df42..6ec87f4 100644 --- a/ShoeStore/Forms/FormReceipt.cs +++ b/ShoeStore/Forms/FormReceipt.cs @@ -51,7 +51,8 @@ namespace ShoeStore.Froms } _receiptRepository.CreateReceipt(Receipt.CreateOperation( 0, - productType, + productType, + dateTimePickerDate.Value, Convert.ToInt32(numericUpDownNumOfPairs.Value))); Close(); diff --git a/ShoeStore/Forms/FormSale.Designer.cs b/ShoeStore/Forms/FormSale.Designer.cs index 1ce13d8..47c68ce 100644 --- a/ShoeStore/Forms/FormSale.Designer.cs +++ b/ShoeStore/Forms/FormSale.Designer.cs @@ -33,14 +33,14 @@ buttonSave = new Button(); buttonCancel = new Button(); panel1 = new Panel(); - dataGridView1 = new DataGridView(); + dataGridViewSale = new DataGridView(); ColumnProduct = new DataGridViewComboBoxColumn(); ColumnAmount = new DataGridViewTextBoxColumn(); label1 = new Label(); dateTimePickerDate = new DateTimePicker(); ((System.ComponentModel.ISupportInitialize)numericUpDownStorageSize).BeginInit(); panel1.SuspendLayout(); - ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + ((System.ComponentModel.ISupportInitialize)dataGridViewSale).BeginInit(); SuspendLayout(); // // label5 @@ -81,21 +81,21 @@ // // panel1 // - panel1.Controls.Add(dataGridView1); + panel1.Controls.Add(dataGridViewSale); panel1.Location = new Point(38, 200); panel1.Name = "panel1"; panel1.Size = new Size(289, 249); panel1.TabIndex = 14; // - // dataGridView1 + // dataGridViewSale // - dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView1.Columns.AddRange(new DataGridViewColumn[] { ColumnProduct, ColumnAmount }); - dataGridView1.Dock = DockStyle.Fill; - dataGridView1.Location = new Point(0, 0); - dataGridView1.Name = "dataGridView1"; - dataGridView1.Size = new Size(289, 249); - dataGridView1.TabIndex = 13; + dataGridViewSale.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridViewSale.Columns.AddRange(new DataGridViewColumn[] { ColumnProduct, ColumnAmount }); + dataGridViewSale.Dock = DockStyle.Fill; + dataGridViewSale.Location = new Point(0, 0); + dataGridViewSale.Name = "dataGridViewSale"; + dataGridViewSale.Size = new Size(289, 249); + dataGridViewSale.TabIndex = 13; // // ColumnProduct // @@ -139,7 +139,7 @@ Text = "FormSale"; ((System.ComponentModel.ISupportInitialize)numericUpDownStorageSize).EndInit(); panel1.ResumeLayout(false); - ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ((System.ComponentModel.ISupportInitialize)dataGridViewSale).EndInit(); ResumeLayout(false); PerformLayout(); } @@ -150,7 +150,7 @@ private Button buttonSave; private Button buttonCancel; private Panel panel1; - private DataGridView dataGridView1; + private DataGridView dataGridViewSale; private DataGridViewComboBoxColumn ColumnProduct; private DataGridViewTextBoxColumn ColumnAmount; private Label label1; diff --git a/ShoeStore/Forms/FormSale.cs b/ShoeStore/Forms/FormSale.cs index 0b0bf0d..c6d8627 100644 --- a/ShoeStore/Forms/FormSale.cs +++ b/ShoeStore/Forms/FormSale.cs @@ -1,4 +1,5 @@ using ShoeStore.Entities; +using ShoeStore.Entities.Enums; using ShoeStore.Repositories; using ShoeStore.Repositories.Implementations; using System; @@ -10,6 +11,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using Unity; namespace ShoeStore.Froms; @@ -37,10 +39,10 @@ public partial class FormSale : Form throw new Exception("Имеются незаполненные поля"); } + + _saleRepository.CreateSale(Sale.CreateOperation(0, Convert.ToInt32(numericUpDownStorageSize.Value), dateTimePickerDate.Value, CreateListProductSaleFromDataGrid())); + MessageBox.Show("Данные успешно добавлены!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information); - - _saleRepository.CreateSale(Sale.CreateOperation(0, Convert.ToInt32(numericUpDownStorageSize.Value))); - Close(); } catch (Exception ex) @@ -52,4 +54,20 @@ public partial class FormSale : Form private void ButtonCancel_Click_1(object sender, EventArgs e) => Close(); + private List CreateListProductSaleFromDataGrid() + { + var list = new List(); + foreach (DataGridViewRow row in dataGridViewSale.Rows) + { + if (row.Cells["ColumnProduct"].Value == null || + row.Cells["ColumnAmount"].Value == null) + { + continue; + } + list.Add(ProductSale.CreateOperation(Convert.ToInt32(row.Cells["ColumnProduct"].Value), 0, + Convert.ToInt32(row.Cells["ColumnAmount"].Value))); + } + return list; + } + } \ No newline at end of file diff --git a/ShoeStore/Repositories/Implementations/ProductRepository.cs b/ShoeStore/Repositories/Implementations/ProductRepository.cs index dc3a681..f155bfc 100644 --- a/ShoeStore/Repositories/Implementations/ProductRepository.cs +++ b/ShoeStore/Repositories/Implementations/ProductRepository.cs @@ -50,7 +50,7 @@ public class ProductRepository : IProductRepository { ProductID, elem.SaleId, - elem.Amount + elem.SalesNumber }, transaction); } transaction.Commit(); diff --git a/ShoeStore/Repositories/Implementations/SaleRepository.cs b/ShoeStore/Repositories/Implementations/SaleRepository.cs index f8a2617..87db365 100644 --- a/ShoeStore/Repositories/Implementations/SaleRepository.cs +++ b/ShoeStore/Repositories/Implementations/SaleRepository.cs @@ -48,7 +48,7 @@ public class SaleRepository : ISaleRepository { elem.ProductId, elem.SaleId, - elem.Amount + elem.SalesNumber }, transaction); } transaction.Commit();