From a8f37756f56abe415fdeebe02884a1174d3187ad Mon Sep 17 00:00:00 2001 From: Programmist73 Date: Wed, 26 Apr 2023 12:51:53 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9D=D1=83=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D1=8C=20=D1=82=D0=BE=D1=87=D0=BD=D0=BE=20=D1=84=D0=B8=D0=BD?= =?UTF-8?q?=D0=B0=D0=BB=D0=BE=D1=87=D0=BA=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormTimeCheck.Designer.cs | 117 ++++++++++++++++++ .../TransportCompany/FormTimeCheck.cs | 51 ++++++++ .../TransportCompany/FormTimeCheck.resx | 60 +++++++++ .../TransportCompany/FormTrucking.Designer.cs | 11 +- .../TransportCompany/FormTrucking.cs | 13 +- TransportCompany/TransportCompany/Program.cs | 1 + .../BusinessLogic/TruckingLogic.cs | 8 +- .../BusinessLogicsContracts/ITruckingLogic.cs | 4 +- .../StoragesContracts/ITruckingStorage.cs | 4 +- .../Implements/TruckingStorage.cs | 31 ++++- 10 files changed, 294 insertions(+), 6 deletions(-) create mode 100644 TransportCompany/TransportCompany/FormTimeCheck.Designer.cs create mode 100644 TransportCompany/TransportCompany/FormTimeCheck.cs create mode 100644 TransportCompany/TransportCompany/FormTimeCheck.resx diff --git a/TransportCompany/TransportCompany/FormTimeCheck.Designer.cs b/TransportCompany/TransportCompany/FormTimeCheck.Designer.cs new file mode 100644 index 0000000..0bde1a6 --- /dev/null +++ b/TransportCompany/TransportCompany/FormTimeCheck.Designer.cs @@ -0,0 +1,117 @@ +namespace TransportCompany +{ + partial class FormTimeCheck + { + /// + /// 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() + { + buttonStartTest = new Button(); + buttonCancel = new Button(); + label1 = new Label(); + textBoxCount = new TextBox(); + label2 = new Label(); + textBoxTimeWork = new TextBox(); + SuspendLayout(); + // + // buttonStartTest + // + buttonStartTest.Location = new Point(123, 22); + buttonStartTest.Name = "buttonStartTest"; + buttonStartTest.Size = new Size(257, 75); + buttonStartTest.TabIndex = 0; + buttonStartTest.Text = "Запуск теста"; + buttonStartTest.UseVisualStyleBackColor = true; + buttonStartTest.Click += ButtonStartTest_Click; + // + // buttonCancel + // + buttonCancel.Location = new Point(361, 241); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(94, 30); + buttonCancel.TabIndex = 1; + buttonCancel.Text = "Закрыть"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += ButtonCancel_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(25, 131); + label1.Name = "label1"; + label1.Size = new Size(230, 20); + label1.TabIndex = 2; + label1.Text = "Кол-во считываемых значений:"; + // + // textBoxCount + // + textBoxCount.Location = new Point(284, 128); + textBoxCount.Name = "textBoxCount"; + textBoxCount.Size = new Size(171, 27); + textBoxCount.TabIndex = 3; + // + // label2 + // + label2.AutoSize = true; + label2.Location = new Point(25, 186); + label2.Name = "label2"; + label2.Size = new Size(113, 20); + label2.TabIndex = 4; + label2.Text = "Время работы:"; + // + // textBoxTimeWork + // + textBoxTimeWork.Location = new Point(284, 183); + textBoxTimeWork.Name = "textBoxTimeWork"; + textBoxTimeWork.Size = new Size(171, 27); + textBoxTimeWork.TabIndex = 5; + // + // FormTimeCheck + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(480, 285); + Controls.Add(textBoxTimeWork); + Controls.Add(label2); + Controls.Add(textBoxCount); + Controls.Add(label1); + Controls.Add(buttonCancel); + Controls.Add(buttonStartTest); + Name = "FormTimeCheck"; + Text = "Тест скорости чтения записей перевозок"; + ResumeLayout(false); + PerformLayout(); + } + + #endregion + + private Button buttonStartTest; + private Button buttonCancel; + private Label label1; + private TextBox textBoxCount; + private Label label2; + private TextBox textBoxTimeWork; + } +} \ No newline at end of file diff --git a/TransportCompany/TransportCompany/FormTimeCheck.cs b/TransportCompany/TransportCompany/FormTimeCheck.cs new file mode 100644 index 0000000..11842b6 --- /dev/null +++ b/TransportCompany/TransportCompany/FormTimeCheck.cs @@ -0,0 +1,51 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using TransportCompanyBusinessLogic.BusinessLogic; +using TransportCompanyContracts.BusinessLogicsContracts; + +namespace TransportCompany +{ + //форма за измерения времени считывания значений + public partial class FormTimeCheck : Form + { + private readonly ITruckingLogic _truckingLogic; + + public FormTimeCheck(ITruckingLogic truckingLogic) + { + InitializeComponent(); + + _truckingLogic = truckingLogic; + } + + private void ButtonStartTest_Click(object sender, EventArgs e) + { + try + { + var result = _truckingLogic.TestReadList(); + + string[] parameters = result.Split(' '); + + textBoxCount.Text = parameters[0]; + + textBoxTimeWork.Text = parameters[1]; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; + Close(); + } + } +} diff --git a/TransportCompany/TransportCompany/FormTimeCheck.resx b/TransportCompany/TransportCompany/FormTimeCheck.resx new file mode 100644 index 0000000..f298a7b --- /dev/null +++ b/TransportCompany/TransportCompany/FormTimeCheck.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/TransportCompany/TransportCompany/FormTrucking.Designer.cs b/TransportCompany/TransportCompany/FormTrucking.Designer.cs index 936c291..9d4abca 100644 --- a/TransportCompany/TransportCompany/FormTrucking.Designer.cs +++ b/TransportCompany/TransportCompany/FormTrucking.Designer.cs @@ -44,6 +44,7 @@ label1 = new Label(); checkBoxSorted = new CheckBox(); checkBoxForFilterMode = new CheckBox(); + testTimeGetDataToolStripMenuItem = new ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); menuStrip.SuspendLayout(); SuspendLayout(); @@ -71,7 +72,7 @@ // menuStrip // menuStrip.ImageScalingSize = new Size(20, 20); - menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, rndGenerationToolStripMenuItem }); + menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, rndGenerationToolStripMenuItem, testTimeGetDataToolStripMenuItem }); menuStrip.Location = new Point(0, 0); menuStrip.Name = "menuStrip"; menuStrip.Padding = new Padding(6, 3, 0, 3); @@ -184,6 +185,13 @@ checkBoxForFilterMode.Text = "Включить режим фильтра"; checkBoxForFilterMode.UseVisualStyleBackColor = true; // + // testTimeGetDataToolStripMenuItem + // + testTimeGetDataToolStripMenuItem.Name = "testTimeGetDataToolStripMenuItem"; + testTimeGetDataToolStripMenuItem.Size = new Size(227, 24); + testTimeGetDataToolStripMenuItem.Text = "Тест скорости чтения данных"; + testTimeGetDataToolStripMenuItem.Click += TestTimeGetDataToolStripMenuItem_Click; + // // FormTrucking // AutoScaleDimensions = new SizeF(8F, 20F); @@ -239,5 +247,6 @@ private Label label1; private CheckBox checkBoxSorted; private CheckBox checkBoxForFilterMode; + private ToolStripMenuItem testTimeGetDataToolStripMenuItem; } } \ No newline at end of file diff --git a/TransportCompany/TransportCompany/FormTrucking.cs b/TransportCompany/TransportCompany/FormTrucking.cs index 382a5e7..72f7a75 100644 --- a/TransportCompany/TransportCompany/FormTrucking.cs +++ b/TransportCompany/TransportCompany/FormTrucking.cs @@ -150,7 +150,7 @@ namespace TransportCompany private void ComboBoxEmails_SelectedIndexChanged(object sender, EventArgs e) { - if(!checkBoxForFilterMode.Checked) + if (!checkBoxForFilterMode.Checked) { //dataGridView.DataSource = _truckingLogic.ReadList(null); LoadData(); @@ -165,5 +165,16 @@ namespace TransportCompany { dataGridView.DataSource = _truckingLogic.ReadList(null).OrderByDescending(x => x.Price).ToList(); } + + private void TestTimeGetDataToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTimeCheck)); + + if (service is FormTimeCheck form) + { + form.ShowDialog(); + LoadData(); + } + } } } \ No newline at end of file diff --git a/TransportCompany/TransportCompany/Program.cs b/TransportCompany/TransportCompany/Program.cs index 5211704..47e8b58 100644 --- a/TransportCompany/TransportCompany/Program.cs +++ b/TransportCompany/TransportCompany/Program.cs @@ -61,6 +61,7 @@ namespace TransportCompany services.AddTransient(); services.AddTransient(); services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogic/TruckingLogic.cs b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogic/TruckingLogic.cs index f048151..e5e47e9 100644 --- a/TransportCompany/TransportCompanyBusinessLogic/BusinessLogic/TruckingLogic.cs +++ b/TransportCompany/TransportCompanyBusinessLogic/BusinessLogic/TruckingLogic.cs @@ -44,7 +44,13 @@ namespace TransportCompanyBusinessLogic.BusinessLogic return list; } - public TruckingViewModel? ReadElement(TruckingSearchModel model) + //для замера времени считывания значений + public string? TestReadList() + { + return _truckingStorage.TestGetFullList(); + } + + public TruckingViewModel? ReadElement(TruckingSearchModel model) { if (model == null) { diff --git a/TransportCompany/TransportCompanyContracts/BusinessLogicsContracts/ITruckingLogic.cs b/TransportCompany/TransportCompanyContracts/BusinessLogicsContracts/ITruckingLogic.cs index dca9436..ab74567 100644 --- a/TransportCompany/TransportCompanyContracts/BusinessLogicsContracts/ITruckingLogic.cs +++ b/TransportCompany/TransportCompanyContracts/BusinessLogicsContracts/ITruckingLogic.cs @@ -13,7 +13,9 @@ namespace TransportCompanyContracts.BusinessLogicsContracts { List? ReadList(TruckingSearchModel? model); - TruckingViewModel? ReadElement(TruckingSearchModel model); + string? TestReadList(); + + TruckingViewModel? ReadElement(TruckingSearchModel model); bool Create(TruckingBindingModel model); diff --git a/TransportCompany/TransportCompanyContracts/StoragesContracts/ITruckingStorage.cs b/TransportCompany/TransportCompanyContracts/StoragesContracts/ITruckingStorage.cs index 0ca3d8a..6409ff9 100644 --- a/TransportCompany/TransportCompanyContracts/StoragesContracts/ITruckingStorage.cs +++ b/TransportCompany/TransportCompanyContracts/StoragesContracts/ITruckingStorage.cs @@ -13,7 +13,9 @@ namespace TransportCompanyContracts.StoragesContracts { List GetFullList(); - List GetFilteredList(TruckingSearchModel model); + string TestGetFullList(); + + List GetFilteredList(TruckingSearchModel model); TruckingViewModel? GetElement(TruckingSearchModel model); diff --git a/TransportCompany/TransportCompanyDatabaseImplements/Implements/TruckingStorage.cs b/TransportCompany/TransportCompanyDatabaseImplements/Implements/TruckingStorage.cs index 32090c5..3ba48fe 100644 --- a/TransportCompany/TransportCompanyDatabaseImplements/Implements/TruckingStorage.cs +++ b/TransportCompany/TransportCompanyDatabaseImplements/Implements/TruckingStorage.cs @@ -75,7 +75,36 @@ namespace TransportCompanyDatabaseImplements.Implements .ToList(); } - public TruckingViewModel? Insert(TruckingBindingModel model) + + public string TestGetFullList() + { + using var context = new ElegevContext(); + + string result = null; + + //для замера времени считывания из бд + Stopwatch stopwatch = new(); + + stopwatch.Start(); + + List list = context.Truckings + .Include(x => x.Transport) + .Include(x => x.Cargo) + .Include(x => x.Transportation) + .Include(x => x.Client) + .Select(x => x.GetViewModel) + .ToList(); + + stopwatch.Stop(); + + result = list.Count.ToString(); + + list.Clear(); + + return result + " " + stopwatch.ElapsedMilliseconds.ToString(); + } + + public TruckingViewModel? Insert(TruckingBindingModel model) { using var context = new ElegevContext();