From 4fbeb3c6e6f121535f2291311865810748c74f67 Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Fri, 21 Apr 2023 19:48:18 +0400 Subject: [PATCH] Report + additional timing fixes --- .../BusinessLogics/MaterialLogic.cs | 12 ++ .../BusinessLogics/OrderLogic.cs | 2 +- .../BusinessLogics/RandomGeneratorLogic.cs | 25 ++-- .../BusinessLogicContracts/IMaterialLogic.cs | 1 + .../StorageContracts/IMaterialStorage.cs | 1 + .../ConstructionCompanyDatabase.cs | 42 ++++++- .../Implements/MaterialStorage.cs | 15 +++ .../Models/Material.cs | 9 ++ .../ConstructionCompanyView.csproj | 6 + .../FormEmployeeOrders.cs | 1 + .../ConstructionCompanyView/FormEmployees.cs | 1 + .../ConstructionCompanyView/FormLogin.cs | 49 ++++---- .../FormMaterialOrders.cs | 1 + .../ConstructionCompanyView/FormMaterials.cs | 1 + .../ConstructionCompanyView/FormPositions.cs | 1 + .../FormWarehouseMenu.Designer.cs | 12 +- .../FormWarehouseMenu.cs | 9 ++ .../FormWarehouseReport.Designer.cs | 116 ++++++++++++++++++ .../FormWarehouseReport.cs | 80 ++++++++++++ .../FormWarehouseReport.resx | 60 +++++++++ .../ConstructionCompanyView/Program.cs | 1 + 21 files changed, 407 insertions(+), 38 deletions(-) create mode 100644 ConstructionCompany/ConstructionCompanyView/FormWarehouseReport.Designer.cs create mode 100644 ConstructionCompany/ConstructionCompanyView/FormWarehouseReport.cs create mode 100644 ConstructionCompany/ConstructionCompanyView/FormWarehouseReport.resx diff --git a/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/MaterialLogic.cs b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/MaterialLogic.cs index d2e35f0..f7324f2 100644 --- a/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/MaterialLogic.cs +++ b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/MaterialLogic.cs @@ -106,5 +106,17 @@ namespace ConstructionCompanyBusinessLogic.BusinessLogics } _logger.LogInformation("Material. IngredietnName:{MaterialName}. Cost:{Quantity}. Id:{Id}", model.MaterialName, model.Quantity, model.Id); } + + public List? ReadEmployeesUsingMaterial(MaterialBindingModel model) + { + CheckModel(model, false); + var list = _materialStorage.GetEmployeesUsingMaterial(model); + if (list == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + return list; + } } } diff --git a/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/OrderLogic.cs b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/OrderLogic.cs index a3e8ff5..c9f8b6d 100644 --- a/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/OrderLogic.cs +++ b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/OrderLogic.cs @@ -26,7 +26,7 @@ namespace ConstructionCompanyBusinessLogic.BusinessLogics public List? ReadList(OrderSearchModel? model) { - _logger.LogInformation("ReadList. Adress:{Adress}. Id:{Id}", model?.Id); + _logger.LogInformation("ReadList. Id:{Id}", model?.Id); var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); if (list == null) { diff --git a/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/RandomGeneratorLogic.cs b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/RandomGeneratorLogic.cs index 61aba51..638f985 100644 --- a/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/RandomGeneratorLogic.cs +++ b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/RandomGeneratorLogic.cs @@ -30,7 +30,7 @@ namespace ConstructionCompanyBusinessLogic.BusinessLogics public void GenerateEmployees() { - for (int i = 0; i < 70; i++) + for (int i = 0; i < 400; i++) { _employee.Create(new EmployeeBindingModel { EmployeeName = "testEmp", PositionID = 1 }); } @@ -38,23 +38,31 @@ namespace ConstructionCompanyBusinessLogic.BusinessLogics public void GenerateEmployeesOrders() { - for (int i = 2; i < 50; i++) + for (int i = 0; i < 2000; i++) { - _employeeOrder.Create(new EmployeeOrderBindingModel { EmployeeId = i, OrderId = i }); + Random rand = new Random(); + int emp = rand.Next(1, 600); + int ord = rand.Next(1, 2000); + if (_employeeOrder.ReadList(null)?.FirstOrDefault(x => x.OrderId == ord && x.EmployeeId == emp) != null) continue; + _employeeOrder.Create(new EmployeeOrderBindingModel { EmployeeId = emp, OrderId = ord}); } } public void GenerateMaterialOrders() { - for (int i = 2; i < 40; i++) + for (int i = 0; i < 50; i++) { - _materialOrder.Create(new MaterialOrderBindingModel { MaterialId = i, OrderId = i, Quantity = 1}); + Random rand = new Random(); + int mat = rand.Next(1, 10); + int ord = rand.Next(1, 200); + if (_materialOrder.ReadList(null)?.FirstOrDefault(x => x.OrderId == ord && x.MaterialId == mat) != null) continue; + _materialOrder.Create(new MaterialOrderBindingModel { MaterialId = mat, OrderId = ord, Quantity = 1}); } } public void GenerateMaterials() { - for (int i = 0; i < 100; i++) + for (int i = 0; i < 1000; i++) { _material.Create(new MaterialBindingModel { MaterialName = "testMat", Quantity = 2000 }); } @@ -64,11 +72,6 @@ namespace ConstructionCompanyBusinessLogic.BusinessLogics { for (int i = 0; i < 2000; i++) { - if (i == 733) - { - i++; - i--; - } _order.CreateOrder(new OrderBindingModel { Description = "snfjknfjksfns", Adress = "dsdsdssd", Price=20000, Status=OrderStatus.Неизвестен, CustomerNumber="+7838347475"}); } } diff --git a/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IMaterialLogic.cs b/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IMaterialLogic.cs index 4e3ea15..cb4a700 100644 --- a/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IMaterialLogic.cs +++ b/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IMaterialLogic.cs @@ -13,6 +13,7 @@ namespace ConstructionCompanyContracts.BusinessLogicContracts { List? ReadList(MaterialSearchModel? model); MaterialViewModel? ReadElement(MaterialSearchModel model); + List? ReadEmployeesUsingMaterial(MaterialBindingModel model); bool Create(MaterialBindingModel model); bool Update(MaterialBindingModel model); bool Delete(MaterialBindingModel model); diff --git a/ConstructionCompany/ConstructionCompanyContracts/StorageContracts/IMaterialStorage.cs b/ConstructionCompany/ConstructionCompanyContracts/StorageContracts/IMaterialStorage.cs index 93d4f9d..f8f4bd5 100644 --- a/ConstructionCompany/ConstructionCompanyContracts/StorageContracts/IMaterialStorage.cs +++ b/ConstructionCompany/ConstructionCompanyContracts/StorageContracts/IMaterialStorage.cs @@ -13,6 +13,7 @@ namespace ConstructionCompanyContracts.StorageContracts { List GetFullList(); List GetFilteredList(MaterialSearchModel model); + List? GetEmployeesUsingMaterial(MaterialBindingModel model); MaterialViewModel? GetElement(MaterialSearchModel model); MaterialViewModel? Insert(MaterialBindingModel model); MaterialViewModel? Update(MaterialBindingModel model); diff --git a/ConstructionCompany/ConstructionCompanyPsqlImplement/ConstructionCompanyDatabase.cs b/ConstructionCompany/ConstructionCompanyPsqlImplement/ConstructionCompanyDatabase.cs index 07eed73..3960414 100644 --- a/ConstructionCompany/ConstructionCompanyPsqlImplement/ConstructionCompanyDatabase.cs +++ b/ConstructionCompany/ConstructionCompanyPsqlImplement/ConstructionCompanyDatabase.cs @@ -8,12 +8,14 @@ using ConstructionCompanyContracts.BindingModels; using Microsoft.EntityFrameworkCore; using Npgsql; using ConstructionCompanyDataModels.Enums; +using System.Diagnostics; +using Microsoft.Extensions.Logging; namespace ConstructionCompanyPsqlImplement { public class ConstructionCompanyDatabase { - static string connectionString = "Server=172.20.10.10;Port=5432;Database=ConstructionCompanyForwardEngineerd;User Id=postgres;Password=postgres;"; + static string connectionString = "Server=192.168.1.35;Port=5432;Database=ConstructionCompanyForwardEngineerd;User Id=postgres;Password=postgres;"; private static ConstructionCompanyDatabase? _instance; private List _materials = new List(); @@ -93,6 +95,22 @@ namespace ConstructionCompanyPsqlImplement connection.Close(); } + public List ExecuteReader(string commandString) + { + using var connection = new NpgsqlConnection(connectionString); + connection.Open(); + + using var commandMaterials = connection.CreateCommand(); + commandMaterials.CommandText = commandString; + using var reader = commandMaterials.ExecuteReader(); + List ids = new List(); + while (reader.Read()) + { + ids.Add(reader.GetInt32(0)); + } + return ids; + } + private void refreshDb() { _materials.Clear(); @@ -106,7 +124,11 @@ namespace ConstructionCompanyPsqlImplement using var commandMaterials = connection.CreateCommand(); commandMaterials.CommandText = "SELECT * FROM material;"; + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); using var readerMaterials = commandMaterials.ExecuteReader(); + stopwatch.Stop(); + long materialsTime = stopwatch.ElapsedMilliseconds; while (readerMaterials.Read()) { int id = readerMaterials.GetInt32(0); @@ -119,7 +141,10 @@ namespace ConstructionCompanyPsqlImplement using var commandPositions = connection.CreateCommand(); commandPositions.CommandText = "SELECT * FROM position;"; + stopwatch.Restart(); using var readerPositions = commandPositions.ExecuteReader(); + stopwatch.Stop(); + long positionsTime = stopwatch.ElapsedMilliseconds; while (readerPositions.Read()) { int id = readerPositions.GetInt32(0); @@ -132,7 +157,10 @@ namespace ConstructionCompanyPsqlImplement using var commandEmployees = connection.CreateCommand(); commandEmployees.CommandText = "SELECT * FROM employee;"; + stopwatch.Restart(); using var readerEmployees = commandEmployees.ExecuteReader(); + stopwatch.Stop(); + long employeesTime = stopwatch.ElapsedMilliseconds; while (readerEmployees.Read()) { int id = readerEmployees.GetInt32(0); @@ -145,7 +173,10 @@ namespace ConstructionCompanyPsqlImplement using var commandOrders = connection.CreateCommand(); commandOrders.CommandText = "SELECT * FROM \"order\";"; + stopwatch.Restart(); using var readerOrders = commandOrders.ExecuteReader(); + stopwatch.Stop(); + long ordersTime = stopwatch.ElapsedMilliseconds; while (readerOrders.Read()) { int id = readerOrders.GetInt32(0); @@ -186,8 +217,13 @@ namespace ConstructionCompanyPsqlImplement readerOrders.Close(); using var commandEmployeeOrders = connection.CreateCommand(); + commandEmployeeOrders.CommandText = "SELECT * FROM employee_order;"; + + stopwatch.Restart(); using var readerEmployeeOrders = commandEmployeeOrders.ExecuteReader(); + stopwatch.Stop(); + long employeeOrderTime = stopwatch.ElapsedMilliseconds; while (readerEmployeeOrders.Read()) { int employeeId = readerEmployeeOrders.GetInt32(0); @@ -199,7 +235,10 @@ namespace ConstructionCompanyPsqlImplement using var commandMaterialOrders = connection.CreateCommand(); commandMaterialOrders.CommandText = "SELECT * FROM material_order;"; + stopwatch.Restart(); using var readerMaterialOrders = commandMaterialOrders.ExecuteReader(); + stopwatch.Stop(); + long materialOrderTime = stopwatch.ElapsedMilliseconds; while (readerMaterialOrders.Read()) { int materialId = readerMaterialOrders.GetInt32(0); @@ -211,6 +250,7 @@ namespace ConstructionCompanyPsqlImplement readerMaterialOrders.Close(); connection.Close(); + } } } diff --git a/ConstructionCompany/ConstructionCompanyPsqlImplement/Implements/MaterialStorage.cs b/ConstructionCompany/ConstructionCompanyPsqlImplement/Implements/MaterialStorage.cs index d4580c7..e1a3e54 100644 --- a/ConstructionCompany/ConstructionCompanyPsqlImplement/Implements/MaterialStorage.cs +++ b/ConstructionCompany/ConstructionCompanyPsqlImplement/Implements/MaterialStorage.cs @@ -97,5 +97,20 @@ namespace ConstructionCompanyPsqlImplement.Implements _source.ExecuteSql(command); return deletedMaterial; } + public List? GetEmployeesUsingMaterial(MaterialBindingModel model) + { + var command = Material.GetEmployeeCommand(model); + if (string.IsNullOrEmpty(command)) + { + return null; + } + var employeesId = _source.ExecuteReader(command); + List employees = new List(); + foreach (var id in employeesId) + { + employees.Add(_source.Employees.First(x => x.Id == id).GetViewModel); + } + return employees; + } } } diff --git a/ConstructionCompany/ConstructionCompanyPsqlImplement/Models/Material.cs b/ConstructionCompany/ConstructionCompanyPsqlImplement/Models/Material.cs index 5100712..46f00d9 100644 --- a/ConstructionCompany/ConstructionCompanyPsqlImplement/Models/Material.cs +++ b/ConstructionCompany/ConstructionCompanyPsqlImplement/Models/Material.cs @@ -54,6 +54,15 @@ namespace ConstructionCompanyPsqlImplement.Models } return $"DELETE FROM material WHERE id = {model.Id}"; } + + public static string GetEmployeeCommand(MaterialBindingModel? model) + { + if (model == null) + { + return ""; + } + return $"SELECT e.id FROM employee e JOIN employee_order ON employee_order.employee_id = e.id JOIN \"order\" ON \"order\".id = employee_order.order_id JOIN material_order ON material_order.order_id = \"order\".id JOIN material mat ON mat.id = material_order.material_id WHERE mat.id = {model.Id};"; + } public void Update(MaterialBindingModel? model) { if (model == null) diff --git a/ConstructionCompany/ConstructionCompanyView/ConstructionCompanyView.csproj b/ConstructionCompany/ConstructionCompanyView/ConstructionCompanyView.csproj index 7d2b63a..48d2ba1 100644 --- a/ConstructionCompany/ConstructionCompanyView/ConstructionCompanyView.csproj +++ b/ConstructionCompany/ConstructionCompanyView/ConstructionCompanyView.csproj @@ -49,4 +49,10 @@ + + + Always + + + \ No newline at end of file diff --git a/ConstructionCompany/ConstructionCompanyView/FormEmployeeOrders.cs b/ConstructionCompany/ConstructionCompanyView/FormEmployeeOrders.cs index 80e773a..d92ccaa 100644 --- a/ConstructionCompany/ConstructionCompanyView/FormEmployeeOrders.cs +++ b/ConstructionCompany/ConstructionCompanyView/FormEmployeeOrders.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; diff --git a/ConstructionCompany/ConstructionCompanyView/FormEmployees.cs b/ConstructionCompany/ConstructionCompanyView/FormEmployees.cs index 1859462..e3a3c6d 100644 --- a/ConstructionCompany/ConstructionCompanyView/FormEmployees.cs +++ b/ConstructionCompany/ConstructionCompanyView/FormEmployees.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; diff --git a/ConstructionCompany/ConstructionCompanyView/FormLogin.cs b/ConstructionCompany/ConstructionCompanyView/FormLogin.cs index 51c97e4..80e0c2a 100644 --- a/ConstructionCompany/ConstructionCompanyView/FormLogin.cs +++ b/ConstructionCompany/ConstructionCompanyView/FormLogin.cs @@ -57,31 +57,32 @@ namespace ConstructionCompanyView private void buttonGenerate_Click(object sender, EventArgs e) { - Stopwatch stopwatch = new Stopwatch(); - stopwatch.Start(); - _random.GenerateMaterials(); - stopwatch.Stop(); - long materials = stopwatch.ElapsedMilliseconds; - stopwatch.Restart(); - _random.GeneratePositions(); - stopwatch.Stop(); - long positions = stopwatch.ElapsedMilliseconds; - stopwatch.Restart(); - _random.GenerateEmployees(); - stopwatch.Stop(); - long employees = stopwatch.ElapsedMilliseconds; - stopwatch.Restart(); - _random.GenerateOrders(); - stopwatch.Stop(); - long orders = stopwatch.ElapsedMilliseconds; - stopwatch.Restart(); - _random.GenerateEmployeesOrders(); - long employeesOrders = stopwatch.ElapsedMilliseconds; - stopwatch.Restart(); + //Stopwatch stopwatch = new Stopwatch(); + //stopwatch.Start(); + //_random.GenerateMaterials(); + //stopwatch.Stop(); + //long materials = stopwatch.ElapsedMilliseconds; + //stopwatch.Restart(); + //_random.GeneratePositions(); + //stopwatch.Stop(); + //long positions = stopwatch.ElapsedMilliseconds; + //stopwatch.Restart(); + //_random.GenerateEmployees(); + //stopwatch.Stop(); + //long employees = stopwatch.ElapsedMilliseconds; + //stopwatch.Restart(); + //_random.GenerateOrders(); + //stopwatch.Stop(); + //long orders = stopwatch.ElapsedMilliseconds; + //stopwatch.Restart(); + //_random.GenerateEmployeesOrders(); + //long employeesOrders = stopwatch.ElapsedMilliseconds; + //stopwatch.Restart(); _random.GenerateMaterialOrders(); - stopwatch.Stop(); - long materialOrders = stopwatch.ElapsedMilliseconds; - MessageBox.Show($"materials={materials}, positions={positions}, employees={employees}, orders={orders}, materialOrders={materialOrders}, employeeOrders={employeesOrders}", "Результаты"); + //stopwatch.Stop(); + //long materialOrders = stopwatch.ElapsedMilliseconds; + //MessageBox.Show($"materials={materials}, positions={positions}, employees={employees}, orders={orders}, materialOrders={materialOrders}, employeeOrders={employeesOrders}", "Результаты"); + MessageBox.Show("Готово!"); } } } diff --git a/ConstructionCompany/ConstructionCompanyView/FormMaterialOrders.cs b/ConstructionCompany/ConstructionCompanyView/FormMaterialOrders.cs index a2c60f8..d0b04bc 100644 --- a/ConstructionCompany/ConstructionCompanyView/FormMaterialOrders.cs +++ b/ConstructionCompany/ConstructionCompanyView/FormMaterialOrders.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; diff --git a/ConstructionCompany/ConstructionCompanyView/FormMaterials.cs b/ConstructionCompany/ConstructionCompanyView/FormMaterials.cs index 6ef1902..5520115 100644 --- a/ConstructionCompany/ConstructionCompanyView/FormMaterials.cs +++ b/ConstructionCompany/ConstructionCompanyView/FormMaterials.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; diff --git a/ConstructionCompany/ConstructionCompanyView/FormPositions.cs b/ConstructionCompany/ConstructionCompanyView/FormPositions.cs index f95697a..6eaf6cf 100644 --- a/ConstructionCompany/ConstructionCompanyView/FormPositions.cs +++ b/ConstructionCompany/ConstructionCompanyView/FormPositions.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; diff --git a/ConstructionCompany/ConstructionCompanyView/FormWarehouseMenu.Designer.cs b/ConstructionCompany/ConstructionCompanyView/FormWarehouseMenu.Designer.cs index 34530d1..04ff109 100644 --- a/ConstructionCompany/ConstructionCompanyView/FormWarehouseMenu.Designer.cs +++ b/ConstructionCompany/ConstructionCompanyView/FormWarehouseMenu.Designer.cs @@ -33,6 +33,7 @@ this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.материалыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.поставкиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.отчётОИспользованииToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.panel1.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); @@ -53,7 +54,8 @@ this.menuStrip1.ImageScalingSize = new System.Drawing.Size(20, 20); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.материалыToolStripMenuItem, - this.поставкиToolStripMenuItem}); + this.поставкиToolStripMenuItem, + this.отчётОИспользованииToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(542, 28); @@ -74,6 +76,13 @@ this.поставкиToolStripMenuItem.Text = "Поставки"; this.поставкиToolStripMenuItem.Click += new System.EventHandler(this.поставкиToolStripMenuItem_Click); // + // отчётОИспользованииToolStripMenuItem + // + this.отчётОИспользованииToolStripMenuItem.Name = "отчётОИспользованииToolStripMenuItem"; + this.отчётОИспользованииToolStripMenuItem.Size = new System.Drawing.Size(188, 24); + this.отчётОИспользованииToolStripMenuItem.Text = "Отчёт о использовании"; + this.отчётОИспользованииToolStripMenuItem.Click += new System.EventHandler(this.отчётОИспользованииToolStripMenuItem_Click); + // // FormWarehouseMenu // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); @@ -96,5 +105,6 @@ private MenuStrip menuStrip1; private ToolStripMenuItem материалыToolStripMenuItem; private ToolStripMenuItem поставкиToolStripMenuItem; + private ToolStripMenuItem отчётОИспользованииToolStripMenuItem; } } \ No newline at end of file diff --git a/ConstructionCompany/ConstructionCompanyView/FormWarehouseMenu.cs b/ConstructionCompany/ConstructionCompanyView/FormWarehouseMenu.cs index ea446cc..83c5606 100644 --- a/ConstructionCompany/ConstructionCompanyView/FormWarehouseMenu.cs +++ b/ConstructionCompany/ConstructionCompanyView/FormWarehouseMenu.cs @@ -35,5 +35,14 @@ namespace ConstructionCompanyView form.ShowDialog(); } } + + private void отчётОИспользованииToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormWarehouseReport)); + if (service is FormWarehouseReport form) + { + form.ShowDialog(); + } + } } } diff --git a/ConstructionCompany/ConstructionCompanyView/FormWarehouseReport.Designer.cs b/ConstructionCompany/ConstructionCompanyView/FormWarehouseReport.Designer.cs new file mode 100644 index 0000000..e8354d6 --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyView/FormWarehouseReport.Designer.cs @@ -0,0 +1,116 @@ +namespace ConstructionCompanyView +{ + partial class FormWarehouseReport + { + /// + /// 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() + { + this.dataGridView = new System.Windows.Forms.DataGridView(); + this.comboBoxMaterial = new System.Windows.Forms.ComboBox(); + this.buttonShow = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); + this.SuspendLayout(); + // + // dataGridView + // + this.dataGridView.BackgroundColor = System.Drawing.Color.White; + this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; + this.dataGridView.Location = new System.Drawing.Point(3, 26); + this.dataGridView.MultiSelect = false; + this.dataGridView.Name = "dataGridView"; + this.dataGridView.RowHeadersVisible = false; + this.dataGridView.RowHeadersWidth = 51; + this.dataGridView.RowTemplate.Height = 29; + this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; + this.dataGridView.Size = new System.Drawing.Size(489, 450); + this.dataGridView.TabIndex = 11; + // + // comboBoxMaterial + // + this.comboBoxMaterial.FormattingEnabled = true; + this.comboBoxMaterial.Location = new System.Drawing.Point(498, 55); + this.comboBoxMaterial.Name = "comboBoxMaterial"; + this.comboBoxMaterial.Size = new System.Drawing.Size(229, 28); + this.comboBoxMaterial.TabIndex = 12; + // + // buttonShow + // + this.buttonShow.Location = new System.Drawing.Point(498, 89); + this.buttonShow.Name = "buttonShow"; + this.buttonShow.Size = new System.Drawing.Size(134, 29); + this.buttonShow.TabIndex = 13; + this.buttonShow.Text = "Отобразить"; + this.buttonShow.UseVisualStyleBackColor = true; + this.buttonShow.Click += new System.EventHandler(this.buttonShow_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(498, 26); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(78, 20); + this.label1.TabIndex = 14; + this.label1.Text = "Материал"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(3, 3); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(68, 20); + this.label2.TabIndex = 15; + this.label2.Text = "Рабочие"; + // + // FormWarehouseReport + // + this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(743, 478); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.buttonShow); + this.Controls.Add(this.comboBoxMaterial); + this.Controls.Add(this.dataGridView); + this.Name = "FormWarehouseReport"; + this.Text = "FormWarehouseReport"; + this.Load += new System.EventHandler(this.FormWarehouseReport_Load); + ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private DataGridView dataGridView; + private ComboBox comboBoxMaterial; + private Button buttonShow; + private Label label1; + private Label label2; + } +} \ No newline at end of file diff --git a/ConstructionCompany/ConstructionCompanyView/FormWarehouseReport.cs b/ConstructionCompany/ConstructionCompanyView/FormWarehouseReport.cs new file mode 100644 index 0000000..1170be0 --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyView/FormWarehouseReport.cs @@ -0,0 +1,80 @@ +using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.BusinessLogicContracts; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Diagnostics; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace ConstructionCompanyView +{ + public partial class FormWarehouseReport : Form + { + private readonly IMaterialLogic _logic; + public FormWarehouseReport(IMaterialLogic logic) + { + InitializeComponent(); + _logic = logic; + } + + private void buttonShow_Click(object sender, EventArgs e) + { + if (comboBoxMaterial.SelectedValue == null) + { + MessageBox.Show("Выберите материал!"); + return; + } + try + { + var model = new MaterialBindingModel + { + Id = Convert.ToInt32(comboBoxMaterial.SelectedValue), + }; + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + var list = _logic.ReadEmployeesUsingMaterial(model); + stopwatch.Stop(); + MessageBox.Show(stopwatch.ElapsedMilliseconds.ToString(), "Готово. Время:"); + if (list != null) + { + dataGridView.DataSource = list; + //dataGridView.Columns["Id"].Visible = false; + dataGridView.Columns["PositionId"].Visible = false; + dataGridView.Columns["EmployeeName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void FormWarehouseReport_Load(object sender, EventArgs e) + { + LoadData(); + } + private void LoadData() + { + try + { + var list = _logic.ReadList(null).OrderBy(x => x.Id).ToList(); + if (list != null) + { + comboBoxMaterial.DisplayMember = "Id"; + comboBoxMaterial.ValueMember = "Id"; + comboBoxMaterial.DataSource = list; + comboBoxMaterial.SelectedItem = null; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } +} diff --git a/ConstructionCompany/ConstructionCompanyView/FormWarehouseReport.resx b/ConstructionCompany/ConstructionCompanyView/FormWarehouseReport.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyView/FormWarehouseReport.resx @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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/ConstructionCompany/ConstructionCompanyView/Program.cs b/ConstructionCompany/ConstructionCompanyView/Program.cs index 2eb54af..486074a 100644 --- a/ConstructionCompany/ConstructionCompanyView/Program.cs +++ b/ConstructionCompany/ConstructionCompanyView/Program.cs @@ -65,6 +65,7 @@ namespace ConstructionCompanyView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file