Вроде всё готово и работает.

This commit is contained in:
Programmist73 2023-04-26 23:44:39 +04:00
parent a8f37756f5
commit a10ef889f9
14 changed files with 384 additions and 9 deletions

View File

@ -0,0 +1,135 @@
namespace TransportCompany
{
partial class FormCheckTimeJoin
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
textBoxFirstCheck = new TextBox();
groupBoxFirst = new GroupBox();
buttonCheckFirstJoin = new Button();
groupBoxSecond = new GroupBox();
textBoxSecondCheck = new TextBox();
buttonCheckSecondJoin = new Button();
buttonCancel = new Button();
groupBoxFirst.SuspendLayout();
groupBoxSecond.SuspendLayout();
SuspendLayout();
//
// textBoxFirstCheck
//
textBoxFirstCheck.Location = new Point(312, 42);
textBoxFirstCheck.Name = "textBoxFirstCheck";
textBoxFirstCheck.Size = new Size(228, 27);
textBoxFirstCheck.TabIndex = 0;
//
// groupBoxFirst
//
groupBoxFirst.Controls.Add(buttonCheckFirstJoin);
groupBoxFirst.Controls.Add(textBoxFirstCheck);
groupBoxFirst.Location = new Point(12, 12);
groupBoxFirst.Name = "groupBoxFirst";
groupBoxFirst.Size = new Size(580, 91);
groupBoxFirst.TabIndex = 1;
groupBoxFirst.TabStop = false;
groupBoxFirst.Text = "Для первого запроса";
//
// buttonCheckFirstJoin
//
buttonCheckFirstJoin.Location = new Point(65, 42);
buttonCheckFirstJoin.Name = "buttonCheckFirstJoin";
buttonCheckFirstJoin.Size = new Size(195, 29);
buttonCheckFirstJoin.TabIndex = 1;
buttonCheckFirstJoin.Text = "Произвести замер";
buttonCheckFirstJoin.UseVisualStyleBackColor = true;
buttonCheckFirstJoin.Click += ButtonCheckFirstJoin_Click;
//
// groupBoxSecond
//
groupBoxSecond.Controls.Add(textBoxSecondCheck);
groupBoxSecond.Controls.Add(buttonCheckSecondJoin);
groupBoxSecond.Location = new Point(12, 109);
groupBoxSecond.Name = "groupBoxSecond";
groupBoxSecond.Size = new Size(580, 95);
groupBoxSecond.TabIndex = 2;
groupBoxSecond.TabStop = false;
groupBoxSecond.Text = "Для второго запроса";
//
// textBoxSecondCheck
//
textBoxSecondCheck.Location = new Point(312, 41);
textBoxSecondCheck.Name = "textBoxSecondCheck";
textBoxSecondCheck.Size = new Size(228, 27);
textBoxSecondCheck.TabIndex = 1;
//
// buttonCheckSecondJoin
//
buttonCheckSecondJoin.Location = new Point(65, 41);
buttonCheckSecondJoin.Name = "buttonCheckSecondJoin";
buttonCheckSecondJoin.Size = new Size(195, 29);
buttonCheckSecondJoin.TabIndex = 0;
buttonCheckSecondJoin.Text = "Произвести замер";
buttonCheckSecondJoin.UseVisualStyleBackColor = true;
buttonCheckSecondJoin.Click += ButtonCheckSecondJoin_Click;
//
// buttonCancel
//
buttonCancel.Location = new Point(452, 220);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(140, 29);
buttonCancel.TabIndex = 3;
buttonCancel.Text = "Закрыть";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click;
//
// FormCheckTimeJoin
//
AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(604, 259);
Controls.Add(buttonCancel);
Controls.Add(groupBoxSecond);
Controls.Add(groupBoxFirst);
Name = "FormCheckTimeJoin";
Text = "Замер времени сложных запросов";
groupBoxFirst.ResumeLayout(false);
groupBoxFirst.PerformLayout();
groupBoxSecond.ResumeLayout(false);
groupBoxSecond.PerformLayout();
ResumeLayout(false);
}
#endregion
private TextBox textBoxFirstCheck;
private GroupBox groupBoxFirst;
private Button buttonCheckFirstJoin;
private GroupBox groupBoxSecond;
private TextBox textBoxSecondCheck;
private Button buttonCheckSecondJoin;
private Button buttonCancel;
}
}

View File

@ -0,0 +1,58 @@
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 TransportCompanyContracts.BusinessLogicsContracts;
namespace TransportCompany
{
public partial class FormCheckTimeJoin : Form
{
private readonly ITruckingLogic _truckingLogic;
private readonly IClientLogic _clientLogic;
public FormCheckTimeJoin(ITruckingLogic truckingLogic, IClientLogic clientLogic)
{
InitializeComponent();
_truckingLogic = truckingLogic;
_clientLogic = clientLogic;
}
private void ButtonCheckFirstJoin_Click(object sender, EventArgs e)
{
try
{
textBoxFirstCheck.Text = _truckingLogic.TestFirstJoin();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCheckSecondJoin_Click(object sender, EventArgs e)
{
try
{
textBoxSecondCheck.Text = _clientLogic.TestSecondJoin();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -39,12 +39,13 @@
rndGenerationToolStripMenuItem = new ToolStripMenuItem(); rndGenerationToolStripMenuItem = new ToolStripMenuItem();
generationClientsToolStripMenuItem = new ToolStripMenuItem(); generationClientsToolStripMenuItem = new ToolStripMenuItem();
generationTruckingsToolStripMenuItem = new ToolStripMenuItem(); generationTruckingsToolStripMenuItem = new ToolStripMenuItem();
testTimeGetDataToolStripMenuItem = new ToolStripMenuItem();
buttonUpdate = new Button(); buttonUpdate = new Button();
comboBoxEmails = new ComboBox(); comboBoxEmails = new ComboBox();
label1 = new Label(); label1 = new Label();
checkBoxSorted = new CheckBox(); checkBoxSorted = new CheckBox();
checkBoxForFilterMode = new CheckBox(); checkBoxForFilterMode = new CheckBox();
testTimeGetDataToolStripMenuItem = new ToolStripMenuItem(); testComplexQueriesToolStripMenuItem = new ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
menuStrip.SuspendLayout(); menuStrip.SuspendLayout();
SuspendLayout(); SuspendLayout();
@ -72,7 +73,7 @@
// menuStrip // menuStrip
// //
menuStrip.ImageScalingSize = new Size(20, 20); menuStrip.ImageScalingSize = new Size(20, 20);
menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, rndGenerationToolStripMenuItem, testTimeGetDataToolStripMenuItem }); menuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem, rndGenerationToolStripMenuItem, testTimeGetDataToolStripMenuItem, testComplexQueriesToolStripMenuItem });
menuStrip.Location = new Point(0, 0); menuStrip.Location = new Point(0, 0);
menuStrip.Name = "menuStrip"; menuStrip.Name = "menuStrip";
menuStrip.Padding = new Padding(6, 3, 0, 3); menuStrip.Padding = new Padding(6, 3, 0, 3);
@ -136,6 +137,13 @@
generationTruckingsToolStripMenuItem.Text = "Генерация перевозок"; generationTruckingsToolStripMenuItem.Text = "Генерация перевозок";
generationTruckingsToolStripMenuItem.Click += GenerationTruckingsToolStripMenuItem_Click; generationTruckingsToolStripMenuItem.Click += GenerationTruckingsToolStripMenuItem_Click;
// //
// testTimeGetDataToolStripMenuItem
//
testTimeGetDataToolStripMenuItem.Name = "testTimeGetDataToolStripMenuItem";
testTimeGetDataToolStripMenuItem.Size = new Size(227, 24);
testTimeGetDataToolStripMenuItem.Text = "Тест скорости чтения данных";
testTimeGetDataToolStripMenuItem.Click += TestTimeGetDataToolStripMenuItem_Click;
//
// buttonUpdate // buttonUpdate
// //
buttonUpdate.Location = new Point(1014, 138); buttonUpdate.Location = new Point(1014, 138);
@ -185,12 +193,12 @@
checkBoxForFilterMode.Text = "Включить режим фильтра"; checkBoxForFilterMode.Text = "Включить режим фильтра";
checkBoxForFilterMode.UseVisualStyleBackColor = true; checkBoxForFilterMode.UseVisualStyleBackColor = true;
// //
// testTimeGetDataToolStripMenuItem // testComplexQueriesToolStripMenuItem
// //
testTimeGetDataToolStripMenuItem.Name = "testTimeGetDataToolStripMenuItem"; testComplexQueriesToolStripMenuItem.Name = "testComplexQueriesToolStripMenuItem";
testTimeGetDataToolStripMenuItem.Size = new Size(227, 24); testComplexQueriesToolStripMenuItem.Size = new Size(188, 24);
testTimeGetDataToolStripMenuItem.Text = "Тест скорости чтения данных"; testComplexQueriesToolStripMenuItem.Text = "Тест сложных запросов";
testTimeGetDataToolStripMenuItem.Click += TestTimeGetDataToolStripMenuItem_Click; testComplexQueriesToolStripMenuItem.Click += TestComplexQueriesToolStripMenuItem_Click;
// //
// FormTrucking // FormTrucking
// //
@ -248,5 +256,6 @@
private CheckBox checkBoxSorted; private CheckBox checkBoxSorted;
private CheckBox checkBoxForFilterMode; private CheckBox checkBoxForFilterMode;
private ToolStripMenuItem testTimeGetDataToolStripMenuItem; private ToolStripMenuItem testTimeGetDataToolStripMenuItem;
private ToolStripMenuItem testComplexQueriesToolStripMenuItem;
} }
} }

View File

@ -176,5 +176,16 @@ namespace TransportCompany
LoadData(); LoadData();
} }
} }
private void TestComplexQueriesToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCheckTimeJoin));
if (service is FormCheckTimeJoin form)
{
form.ShowDialog();
LoadData();
}
}
} }
} }

View File

@ -62,6 +62,7 @@ namespace TransportCompany
services.AddTransient<FormRandomCreateClient>(); services.AddTransient<FormRandomCreateClient>();
services.AddTransient<FormRandomCreateTrucking>(); services.AddTransient<FormRandomCreateTrucking>();
services.AddTransient<FormTimeCheck>(); services.AddTransient<FormTimeCheck>();
services.AddTransient<FormCheckTimeJoin>();
} }
} }
} }

View File

@ -80,12 +80,18 @@ namespace TransportCompanyBusinessLogic.BusinessLogic
return true; return true;
} }
//для замера времени рандомного добавления
public string TestRandomCreate(int count, string[] _name, string[] _surname, string[] _patronymic, string[] _telephone, string[] _email) public string TestRandomCreate(int count, string[] _name, string[] _surname, string[] _patronymic, string[] _telephone, string[] _email)
{ {
return _clientStorage.TestRandomInsert(count, _name, _surname, _patronymic, _telephone, _email); return _clientStorage.TestRandomInsert(count, _name, _surname, _patronymic, _telephone, _email);
} }
//для проверки времени выполнения сложного запроса
public string TestSecondJoin()
{
return _clientStorage.SecondJoin();
}
public bool Update(ClientBindingModel model) public bool Update(ClientBindingModel model)
{ {
CheckModel(model); CheckModel(model);

View File

@ -92,6 +92,12 @@ namespace TransportCompanyBusinessLogic.BusinessLogic
return _truckingStorage.TestRandomInsert(count, clients, cargos, transports, transportations); return _truckingStorage.TestRandomInsert(count, clients, cargos, transports, transportations);
} }
//первый сложный запрос
public string? TestFirstJoin()
{
return _truckingStorage.FirstJoin();
}
public bool Update(TruckingBindingModel model) public bool Update(TruckingBindingModel model)
{ {
CheckModel(model); CheckModel(model);

View File

@ -19,6 +19,8 @@ namespace TransportCompanyContracts.BusinessLogicsContracts
string TestRandomCreate(int count, string[] _name, string[] _surname, string[] _patronymic, string[] _telephone, string[] _email); string TestRandomCreate(int count, string[] _name, string[] _surname, string[] _patronymic, string[] _telephone, string[] _email);
string TestSecondJoin();
bool Update(ClientBindingModel model); bool Update(ClientBindingModel model);
bool Delete(ClientBindingModel model); bool Delete(ClientBindingModel model);

View File

@ -15,6 +15,8 @@ namespace TransportCompanyContracts.BusinessLogicsContracts
string? TestReadList(); string? TestReadList();
string? TestFirstJoin();
TruckingViewModel? ReadElement(TruckingSearchModel model); TruckingViewModel? ReadElement(TruckingSearchModel model);
bool Create(TruckingBindingModel model); bool Create(TruckingBindingModel model);

View File

@ -21,6 +21,8 @@ namespace TransportCompanyContracts.StoragesContracts
string TestRandomInsert(int count, string[] _name, string[] _surname, string[] _patronymic, string[] _telephone, string[] _email); string TestRandomInsert(int count, string[] _name, string[] _surname, string[] _patronymic, string[] _telephone, string[] _email);
string SecondJoin();
ClientViewModel? Update(ClientBindingModel model); ClientViewModel? Update(ClientBindingModel model);
ClientViewModel? Delete(ClientBindingModel model); ClientViewModel? Delete(ClientBindingModel model);

View File

@ -15,6 +15,8 @@ namespace TransportCompanyContracts.StoragesContracts
string TestGetFullList(); string TestGetFullList();
string FirstJoin();
List<TruckingViewModel> GetFilteredList(TruckingSearchModel model); List<TruckingViewModel> GetFilteredList(TruckingSearchModel model);
TruckingViewModel? GetElement(TruckingSearchModel model); TruckingViewModel? GetElement(TruckingSearchModel model);

View File

@ -111,6 +111,46 @@ namespace TransportCompanyDatabaseImplements.Implements
return stopwatch.ElapsedMilliseconds.ToString(); return stopwatch.ElapsedMilliseconds.ToString();
} }
public string SecondJoin()
{
using var context = new ElegevContext();
Random rnd = new Random(DateTime.Now.ToString().GetHashCode());
//старт замера времени добавления в бд
Stopwatch stopwatch = new();
stopwatch.Start();
var secondJoin = from t in context.Set<Trucking>()
from c in context.Set<Client>().Where(c => c.Id == t.ClientId)
select new { c, t };
//ВСЁ ГОТОВО ДЛЯ СЛЕДУЮЩЕГО ЗАМЕРА
foreach (var element in secondJoin)
{
element.t.Update(new TruckingBindingModel
{
Id = element.t.Id,
ClientId = element.t.ClientId,
CargoId = element.t.CargoId,
Price = element.t.Price,
DateStart = element.t.DateStart.AddDays(-10),
DateEnd = element.t.DateEnd.AddDays(-10),
TransportationId = element.t.TransportationId,
TransportId = element.t.TransportId,
});
}
context.SaveChanges();
stopwatch.Stop();
return stopwatch.ElapsedMilliseconds.ToString();
}
public ClientViewModel? Update(ClientBindingModel model) public ClientViewModel? Update(ClientBindingModel model)
{ {
using var context = new ElegevContext(); using var context = new ElegevContext();

View File

@ -198,5 +198,46 @@ namespace TransportCompanyDatabaseImplements.Implements
throw; throw;
} }
} }
//первый сложный запрос
public string FirstJoin()
{
using var context = new ElegevContext();
Random rnd = new Random(DateTime.Now.ToString().GetHashCode());
//старт замера времени добавления в бд
Stopwatch stopwatch = new();
stopwatch.Start();
var firstJoin = from t in context.Set<Trucking>().Where(t => t.Price == 1200000.0)
from c in context.Set<Client>().Where(c => c.Id == t.ClientId)
select new { t, c };
//ВСЁ ГОТОВО ДЛЯ СЛЕДУЮЩЕГО ЗАМЕРА
// 999999.0
foreach (var element in firstJoin)
{
element.t.Update(new TruckingBindingModel
{
Id = element.t.Id,
ClientId = element.t.ClientId,
CargoId = element.t.CargoId,
Price = 999999.0,
DateStart = element.t.DateStart,
DateEnd = element.t.DateEnd,
TransportationId = element.t.TransportationId,
TransportId = element.t.TransportId,
});
}
context.SaveChanges();
stopwatch.Stop();
return stopwatch.ElapsedMilliseconds.ToString();
}
} }
} }