From b3ae7e1f76a288fdc8f9f096bf20adf69d0c12e3 Mon Sep 17 00:00:00 2001 From: abazov73 <92822431+abazov73@users.noreply.github.com> Date: Mon, 10 Apr 2023 14:24:22 +0400 Subject: [PATCH] Testing time --- .../BusinessLogics/OrderLogic.cs | 2 +- .../BusinessLogics/RandomGeneratorLogic.cs | 84 +++++++++++++++++++ .../IRandomGeneratorLogic.cs | 18 ++++ .../ConstructionCompanyDatabase.cs | 2 +- .../FormLogin.Designer.cs | 13 +++ .../ConstructionCompanyView/FormLogin.cs | 38 ++++++++- .../ConstructionCompanyView/Program.cs | 1 + 7 files changed, 154 insertions(+), 4 deletions(-) create mode 100644 ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/RandomGeneratorLogic.cs create mode 100644 ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IRandomGeneratorLogic.cs diff --git a/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/OrderLogic.cs b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/OrderLogic.cs index bc715fd..a3e8ff5 100644 --- a/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/OrderLogic.cs +++ b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/OrderLogic.cs @@ -34,7 +34,7 @@ namespace ConstructionCompanyBusinessLogic.BusinessLogics return null; } _logger.LogInformation("ReadList. Count:{Count}", list.Count); - return list; + return list.OrderBy(x => x.Id).ToList(); } public OrderViewModel? ReadElement(OrderSearchModel model) diff --git a/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/RandomGeneratorLogic.cs b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/RandomGeneratorLogic.cs new file mode 100644 index 0000000..61aba51 --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyBusiness/BusinessLogics/RandomGeneratorLogic.cs @@ -0,0 +1,84 @@ +using ConstructionCompanyContracts.BindingModels; +using ConstructionCompanyContracts.BusinessLogicContracts; +using ConstructionCompanyDataModels.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConstructionCompanyBusinessLogic.BusinessLogics +{ + public class RandomGeneratorLogic : IRandomGeneratorLogic + { + private readonly IMaterialLogic _material; + private readonly IEmployeeLogic _employee; + private readonly IPositionLogic _position; + private readonly IOrderLogic _order; + private readonly IMaterialOrderLogic _materialOrder; + private readonly IEmployeeOrderLogic _employeeOrder; + + public RandomGeneratorLogic(IMaterialLogic material, IEmployeeLogic employee, IPositionLogic position, IOrderLogic order, IMaterialOrderLogic materialOrder, IEmployeeOrderLogic employeeOrder) + { + _material = material; + _employee = employee; + _position = position; + _order = order; + _materialOrder = materialOrder; + _employeeOrder = employeeOrder; + } + + public void GenerateEmployees() + { + for (int i = 0; i < 70; i++) + { + _employee.Create(new EmployeeBindingModel { EmployeeName = "testEmp", PositionID = 1 }); + } + } + + public void GenerateEmployeesOrders() + { + for (int i = 2; i < 50; i++) + { + _employeeOrder.Create(new EmployeeOrderBindingModel { EmployeeId = i, OrderId = i }); + } + } + + public void GenerateMaterialOrders() + { + for (int i = 2; i < 40; i++) + { + _materialOrder.Create(new MaterialOrderBindingModel { MaterialId = i, OrderId = i, Quantity = 1}); + } + } + + public void GenerateMaterials() + { + for (int i = 0; i < 100; i++) + { + _material.Create(new MaterialBindingModel { MaterialName = "testMat", Quantity = 2000 }); + } + } + + public void GenerateOrders() + { + 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"}); + } + } + + public void GeneratePositions() + { + for (int i = 0; i < 15; i++) + { + _position.Create(new PositionBindingModel { PositionName = "testPos", Salary = 20000 }); + } + } + } +} diff --git a/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IRandomGeneratorLogic.cs b/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IRandomGeneratorLogic.cs new file mode 100644 index 0000000..0c75c1b --- /dev/null +++ b/ConstructionCompany/ConstructionCompanyContracts/BusinessLogicContracts/IRandomGeneratorLogic.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConstructionCompanyContracts.BusinessLogicContracts +{ + public interface IRandomGeneratorLogic + { + public void GenerateMaterials(); + public void GenerateOrders(); + public void GeneratePositions(); + public void GenerateEmployees(); + public void GenerateEmployeesOrders(); + public void GenerateMaterialOrders(); + } +} diff --git a/ConstructionCompany/ConstructionCompanyPsqlImplement/ConstructionCompanyDatabase.cs b/ConstructionCompany/ConstructionCompanyPsqlImplement/ConstructionCompanyDatabase.cs index abdebb9..07eed73 100644 --- a/ConstructionCompany/ConstructionCompanyPsqlImplement/ConstructionCompanyDatabase.cs +++ b/ConstructionCompany/ConstructionCompanyPsqlImplement/ConstructionCompanyDatabase.cs @@ -13,7 +13,7 @@ namespace ConstructionCompanyPsqlImplement { public class ConstructionCompanyDatabase { - static string connectionString = "Server=192.168.1.35;Port=5432;Database=ConstructionCompanyForwardEngineerd;User Id=postgres;Password=postgres;"; + static string connectionString = "Server=172.20.10.10;Port=5432;Database=ConstructionCompanyForwardEngineerd;User Id=postgres;Password=postgres;"; private static ConstructionCompanyDatabase? _instance; private List _materials = new List(); diff --git a/ConstructionCompany/ConstructionCompanyView/FormLogin.Designer.cs b/ConstructionCompany/ConstructionCompanyView/FormLogin.Designer.cs index 9445ede..a3c01b2 100644 --- a/ConstructionCompany/ConstructionCompanyView/FormLogin.Designer.cs +++ b/ConstructionCompany/ConstructionCompanyView/FormLogin.Designer.cs @@ -32,6 +32,7 @@ this.buttonWarehouse = new System.Windows.Forms.Button(); this.buttonManager = new System.Windows.Forms.Button(); this.buttonHR = new System.Windows.Forms.Button(); + this.buttonGenerate = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 @@ -74,12 +75,23 @@ this.buttonHR.UseVisualStyleBackColor = true; this.buttonHR.Click += new System.EventHandler(this.buttonHR_Click); // + // buttonGenerate + // + this.buttonGenerate.Location = new System.Drawing.Point(12, 309); + this.buttonGenerate.Name = "buttonGenerate"; + this.buttonGenerate.Size = new System.Drawing.Size(154, 29); + this.buttonGenerate.TabIndex = 4; + this.buttonGenerate.Text = "Создать компанию"; + this.buttonGenerate.UseVisualStyleBackColor = true; + this.buttonGenerate.Click += new System.EventHandler(this.buttonGenerate_Click); + // // FormLogin // this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.SystemColors.ActiveCaption; this.ClientSize = new System.Drawing.Size(784, 350); + this.Controls.Add(this.buttonGenerate); this.Controls.Add(this.buttonHR); this.Controls.Add(this.buttonManager); this.Controls.Add(this.buttonWarehouse); @@ -97,5 +109,6 @@ private Button buttonWarehouse; private Button buttonManager; private Button buttonHR; + private Button buttonGenerate; } } \ No newline at end of file diff --git a/ConstructionCompany/ConstructionCompanyView/FormLogin.cs b/ConstructionCompany/ConstructionCompanyView/FormLogin.cs index 6b7527c..51c97e4 100644 --- a/ConstructionCompany/ConstructionCompanyView/FormLogin.cs +++ b/ConstructionCompany/ConstructionCompanyView/FormLogin.cs @@ -1,7 +1,10 @@ -using System; +using ConstructionCompanyContracts.BusinessLogicContracts; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; +using System.Diagnostics; +using System.Diagnostics.Eventing.Reader; using System.Drawing; using System.Linq; using System.Text; @@ -12,9 +15,11 @@ namespace ConstructionCompanyView { public partial class FormLogin : Form { - public FormLogin() + private readonly IRandomGeneratorLogic _random; + public FormLogin(IRandomGeneratorLogic random) { InitializeComponent(); + _random = random; } private void buttonWarehouse_Click(object sender, EventArgs e) @@ -49,5 +54,34 @@ namespace ConstructionCompanyView this.Show(); } } + + 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(); + _random.GenerateMaterialOrders(); + stopwatch.Stop(); + long materialOrders = stopwatch.ElapsedMilliseconds; + MessageBox.Show($"materials={materials}, positions={positions}, employees={employees}, orders={orders}, materialOrders={materialOrders}, employeeOrders={employeesOrders}", "Результаты"); + } } } diff --git a/ConstructionCompany/ConstructionCompanyView/Program.cs b/ConstructionCompany/ConstructionCompanyView/Program.cs index 4d9c702..2eb54af 100644 --- a/ConstructionCompany/ConstructionCompanyView/Program.cs +++ b/ConstructionCompany/ConstructionCompanyView/Program.cs @@ -47,6 +47,7 @@ namespace ConstructionCompanyView services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient();