From 67cf4fa5b416d0efdaf3ab72502e6029db1e23fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A2=D0=B0=D1=82=D1=8C=D1=8F=D0=BD=D0=B0=20=D0=90=D1=80?= =?UTF-8?q?=D1=82=D0=B0=D0=BC=D0=BE=D0=BD=D0=BE=D0=B2=D0=B0?= Date: Wed, 17 May 2023 03:35:13 +0400 Subject: [PATCH] =?UTF-8?q?4=20=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BeautySalon/FormMain.Designer.cs | 12 +- BeautySalon/FormMain.cs | 9 ++ BeautySalon/FormTests.Designer.cs | 135 +++++++++++++++++- BeautySalon/FormTests.cs | 45 ++++-- BeautySalon/FormTests.resx | 62 +------- BeautySalon/Program.cs | 3 +- .../BusinessLogics/MasterLogic.cs | 11 ++ .../Implements/MasterStorage.cs | 79 ++++++++++ .../Implements/ServiceStorage.cs | 4 +- .../BusinessLogicsContracts/IMasterLogic.cs | 2 + .../StoragesContracts/IMasterStorage.cs | 2 + 11 files changed, 285 insertions(+), 79 deletions(-) diff --git a/BeautySalon/FormMain.Designer.cs b/BeautySalon/FormMain.Designer.cs index ad6bc7e..ba1c33d 100644 --- a/BeautySalon/FormMain.Designer.cs +++ b/BeautySalon/FormMain.Designer.cs @@ -36,6 +36,7 @@ this.dataGridView = new System.Windows.Forms.DataGridView(); this.buttonCreateVisit = new System.Windows.Forms.Button(); this.buttonRef = new System.Windows.Forms.Button(); + this.тестToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); this.SuspendLayout(); @@ -43,7 +44,8 @@ // menuStrip1 // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - 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(1078, 24); @@ -110,6 +112,13 @@ this.buttonRef.UseVisualStyleBackColor = true; this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click); // + // тестToolStripMenuItem + // + this.тестToolStripMenuItem.Name = "тестToolStripMenuItem"; + this.тестToolStripMenuItem.Size = new System.Drawing.Size(42, 20); + this.тестToolStripMenuItem.Text = "Тест"; + this.тестToolStripMenuItem.Click += new System.EventHandler(this.ТестToolStripMenuItem_Click); + // // FormMain // this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); @@ -141,5 +150,6 @@ private DataGridView dataGridView; private Button buttonCreateVisit; private Button buttonRef; + private ToolStripMenuItem тестToolStripMenuItem; } } \ No newline at end of file diff --git a/BeautySalon/FormMain.cs b/BeautySalon/FormMain.cs index a00c8e3..23d1296 100644 --- a/BeautySalon/FormMain.cs +++ b/BeautySalon/FormMain.cs @@ -85,5 +85,14 @@ namespace BeautySalon MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } } + + private void ТестToolStripMenuItem_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormTests)); + if (service is FormTests form) + { + form.ShowDialog(); + } + } } } diff --git a/BeautySalon/FormTests.Designer.cs b/BeautySalon/FormTests.Designer.cs index 4755b4d..f6fb5f9 100644 --- a/BeautySalon/FormTests.Designer.cs +++ b/BeautySalon/FormTests.Designer.cs @@ -28,12 +28,141 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); + this.buttonInsertTest = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.textBoxInsertTime = new System.Windows.Forms.TextBox(); + this.buttonReadTest = new System.Windows.Forms.Button(); + this.textBoxReadTime = new System.Windows.Forms.TextBox(); + this.label3 = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); + this.numericUpDownInsert = new System.Windows.Forms.NumericUpDown(); + this.numericUpDownRead = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).BeginInit(); + this.SuspendLayout(); + // + // buttonInsertTest + // + this.buttonInsertTest.Location = new System.Drawing.Point(12, 12); + this.buttonInsertTest.Name = "buttonInsertTest"; + this.buttonInsertTest.Size = new System.Drawing.Size(86, 61); + this.buttonInsertTest.TabIndex = 0; + this.buttonInsertTest.Text = "Тест вставки"; + this.buttonInsertTest.UseVisualStyleBackColor = true; + this.buttonInsertTest.Click += new System.EventHandler(this.ButtonInsertTest_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(104, 12); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(156, 15); + this.label1.TabIndex = 1; + this.label1.Text = "Введите кол-во элементов:"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(104, 53); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(146, 15); + this.label2.TabIndex = 3; + this.label2.Text = "Итоговое время запроса:"; + // + // textBoxInsertTime + // + this.textBoxInsertTime.Location = new System.Drawing.Point(266, 50); + this.textBoxInsertTime.Name = "textBoxInsertTime"; + this.textBoxInsertTime.ReadOnly = true; + this.textBoxInsertTime.Size = new System.Drawing.Size(100, 23); + this.textBoxInsertTime.TabIndex = 4; + // + // buttonReadTest + // + this.buttonReadTest.Location = new System.Drawing.Point(12, 106); + this.buttonReadTest.Name = "buttonReadTest"; + this.buttonReadTest.Size = new System.Drawing.Size(86, 56); + this.buttonReadTest.TabIndex = 5; + this.buttonReadTest.Text = "Тест чтения"; + this.buttonReadTest.UseVisualStyleBackColor = true; + this.buttonReadTest.Click += new System.EventHandler(this.ButtonReadTest_Click); + // + // textBoxReadTime + // + this.textBoxReadTime.Location = new System.Drawing.Point(266, 144); + this.textBoxReadTime.Name = "textBoxReadTime"; + this.textBoxReadTime.ReadOnly = true; + this.textBoxReadTime.Size = new System.Drawing.Size(100, 23); + this.textBoxReadTime.TabIndex = 9; + // + // label3 + // + this.label3.AutoSize = true; + this.label3.Location = new System.Drawing.Point(104, 147); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(146, 15); + this.label3.TabIndex = 8; + this.label3.Text = "Итоговое время запроса:"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(104, 106); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(156, 15); + this.label4.TabIndex = 6; + this.label4.Text = "Введите кол-во элементов:"; + // + // numericUpDownInsert + // + this.numericUpDownInsert.Location = new System.Drawing.Point(266, 10); + this.numericUpDownInsert.Name = "numericUpDownInsert"; + this.numericUpDownInsert.Size = new System.Drawing.Size(100, 23); + this.numericUpDownInsert.TabIndex = 10; + // + // numericUpDownRead + // + this.numericUpDownRead.Location = new System.Drawing.Point(266, 104); + this.numericUpDownRead.Name = "numericUpDownRead"; + this.numericUpDownRead.Size = new System.Drawing.Size(100, 23); + this.numericUpDownRead.TabIndex = 11; + // + // FormTests + // + this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormTests"; + this.ClientSize = new System.Drawing.Size(383, 182); + this.Controls.Add(this.numericUpDownRead); + this.Controls.Add(this.numericUpDownInsert); + this.Controls.Add(this.textBoxReadTime); + this.Controls.Add(this.label3); + this.Controls.Add(this.label4); + this.Controls.Add(this.buttonReadTest); + this.Controls.Add(this.textBoxInsertTime); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.buttonInsertTest); + this.Name = "FormTests"; + this.Text = "Тесты запросов к бд"; + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private Button buttonInsertTest; + private Label label1; + private Label label2; + private TextBox textBoxInsertTime; + private Button buttonReadTest; + private TextBox textBoxReadTime; + private Label label3; + private Label label4; + private NumericUpDown numericUpDownInsert; + private NumericUpDown numericUpDownRead; } } \ No newline at end of file diff --git a/BeautySalon/FormTests.cs b/BeautySalon/FormTests.cs index 5365914..2251a6e 100644 --- a/BeautySalon/FormTests.cs +++ b/BeautySalon/FormTests.cs @@ -1,20 +1,45 @@ -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 BeautySalonContracts.BusinessLogicsContracts; namespace BeautySalon { public partial class FormTests : Form { - public FormTests() + private readonly IMasterLogic _masterLogic; + public FormTests(IMasterLogic masterLogic) { InitializeComponent(); + _masterLogic = masterLogic; + numericUpDownInsert.Minimum = 1; + numericUpDownInsert.Maximum = 1000000; + numericUpDownRead.Minimum = 1; + numericUpDownRead.Maximum = 1000000; + } + + private void ButtonInsertTest_Click(object sender, EventArgs e) + { + try + { + var result = _masterLogic.TestInsertList(Convert.ToInt32(numericUpDownInsert.Value)); + + textBoxInsertTime.Text = result; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + + private void ButtonReadTest_Click(object sender, EventArgs e) + { + try + { + var result = _masterLogic.TestReadList(Convert.ToInt32(numericUpDownRead.Value)); + textBoxReadTime.Text = result; + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); + } } } } diff --git a/BeautySalon/FormTests.resx b/BeautySalon/FormTests.resx index 1af7de1..f298a7b 100644 --- a/BeautySalon/FormTests.resx +++ b/BeautySalon/FormTests.resx @@ -1,64 +1,4 @@ - - - + diff --git a/BeautySalon/Program.cs b/BeautySalon/Program.cs index 7e31b65..10185c1 100644 --- a/BeautySalon/Program.cs +++ b/BeautySalon/Program.cs @@ -47,7 +47,8 @@ namespace BeautySalon services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/BeautySalonBusinessLogic/BusinessLogics/MasterLogic.cs b/BeautySalonBusinessLogic/BusinessLogics/MasterLogic.cs index 4b1d9c5..1077e7c 100644 --- a/BeautySalonBusinessLogic/BusinessLogics/MasterLogic.cs +++ b/BeautySalonBusinessLogic/BusinessLogics/MasterLogic.cs @@ -4,6 +4,7 @@ using BeautySalonContracts.SearchModels; using BeautySalonContracts.StoragesContracts; using BeautySalonContracts.ViewModels; using Microsoft.Extensions.Logging; +using System; namespace BeautySalonBusinessLogic.BusinessLogics { @@ -103,5 +104,15 @@ namespace BeautySalonBusinessLogic.BusinessLogics throw new InvalidOperationException("Мастер с таким ФИО уже есть"); } } + + public string TestInsertList(int v) + { + return _masterStorage.TestInsertList(v); + } + + public string TestReadList(int v) + { + return _masterStorage.TestReadList(v); + } } } diff --git a/BeautySalonDatabaseImplement/Implements/MasterStorage.cs b/BeautySalonDatabaseImplement/Implements/MasterStorage.cs index 0c3ed96..382b715 100644 --- a/BeautySalonDatabaseImplement/Implements/MasterStorage.cs +++ b/BeautySalonDatabaseImplement/Implements/MasterStorage.cs @@ -5,6 +5,9 @@ using BeautySalonContracts.ViewModels; using BeautySalonDatabaseImplement; using BeautySalonDatabaseImplement.Models; using Microsoft.EntityFrameworkCore; +using System.Diagnostics; +using System; +using BeautySalonDataModels.Models; namespace BeautySalonDatabaseImplement.Implements { @@ -101,5 +104,81 @@ namespace BeautySalonDatabaseImplement.Implements } return null; } + + public string TestInsertList(int v) + { + var context = new BeautySalonDatabase(); + Stopwatch servicewatch = new(); + Random rnd = new Random(); + long[] res = new long[v * 2]; + + + for (int i = 0; i < v; ++i) + { + int rndId = rnd.Next(); + var model = new ServiceBindingModel + { + Id = rndId, + ServiceName = "Service" + rndId.ToString(), + Cost = rnd.Next(), + }; + context.Services.Add(Service.Create(model)); + servicewatch.Start(); + context.SaveChanges(); + servicewatch.Stop(); + res[i] = servicewatch.ElapsedMilliseconds; + } + + for (int i = 0; i < v; ++i) + { + int rndId = rnd.Next(); + var model = new MasterBindingModel + { + Id = rndId, + MasterFIO = "Master" + rndId.ToString(), + Wage = rnd.Next(), + }; + context.Masters.Add(Master.Create(context, model)); + servicewatch.Start(); + context.SaveChanges(); + servicewatch.Stop(); + res[i] = servicewatch.ElapsedMilliseconds; + } + + long sum = 0; + for (int i = 0; i < v; i++) + { + sum += res[i]; + } + int result = Convert.ToInt32(sum / v); + return result.ToString(); + } + + public string TestReadList(int v) + { + var context = new BeautySalonDatabase(); + Stopwatch servicewatch = new(); + long[] res = new long[v]; + + for (int i = 0; i < v; i++) + { + + servicewatch.Start(); + List list = context.Masters + .Include(x => x.Services) + .ThenInclude(x => x.Service).ToList() + .Select(x => x.GetViewModel).ToList(); + servicewatch.Stop(); + res[i] = servicewatch.ElapsedMilliseconds; + } + + long sum = 0; + for (int i = 0; i < v; i++) + { + sum += res[i]; + } + int result = Convert.ToInt32(sum / v); + return result.ToString(); + } } } diff --git a/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs b/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs index 8f7c594..92d9d74 100644 --- a/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs +++ b/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs @@ -2,9 +2,7 @@ using BeautySalonContracts.SearchModels; using BeautySalonContracts.StoragesContracts; using BeautySalonContracts.ViewModels; -using BeautySalonDatabaseImplement; using BeautySalonDatabaseImplement.Models; -using System.ServiceModel; namespace BeautySalonDatabaseImplement.Implements { @@ -78,6 +76,6 @@ namespace BeautySalonDatabaseImplement.Implements return element.GetViewModel; } return null; - } + } } } \ No newline at end of file diff --git a/BeauySalonContracts/BusinessLogicsContracts/IMasterLogic.cs b/BeauySalonContracts/BusinessLogicsContracts/IMasterLogic.cs index 7a6037d..985af39 100644 --- a/BeauySalonContracts/BusinessLogicsContracts/IMasterLogic.cs +++ b/BeauySalonContracts/BusinessLogicsContracts/IMasterLogic.cs @@ -11,5 +11,7 @@ namespace BeautySalonContracts.BusinessLogicsContracts bool Create(MasterBindingModel model); bool Update(MasterBindingModel model); bool Delete(MasterBindingModel model); + string TestInsertList(int v); + string TestReadList(int v); } } diff --git a/BeauySalonContracts/StoragesContracts/IMasterStorage.cs b/BeauySalonContracts/StoragesContracts/IMasterStorage.cs index d708b9d..8b4e470 100644 --- a/BeauySalonContracts/StoragesContracts/IMasterStorage.cs +++ b/BeauySalonContracts/StoragesContracts/IMasterStorage.cs @@ -12,5 +12,7 @@ namespace BeautySalonContracts.StoragesContracts MasterViewModel? Insert(MasterBindingModel model); MasterViewModel? Update(MasterBindingModel model); MasterViewModel? Delete(MasterBindingModel model); + string TestInsertList(int v); + string TestReadList(int v); } }