Готовая LabWork04.

This commit is contained in:
Programmist73 2023-04-26 11:31:32 +04:00
parent 2aed31b3c5
commit 0267589a31
12 changed files with 412 additions and 302 deletions

View File

@ -32,6 +32,8 @@
textBoxCount = new TextBox(); textBoxCount = new TextBox();
buttonStart = new Button(); buttonStart = new Button();
buttonCancel = new Button(); buttonCancel = new Button();
label1 = new Label();
textBoxTimeWork = new TextBox();
SuspendLayout(); SuspendLayout();
// //
// labelCount // labelCount
@ -52,7 +54,7 @@
// //
// buttonStart // buttonStart
// //
buttonStart.Location = new Point(147, 87); buttonStart.Location = new Point(147, 162);
buttonStart.Name = "buttonStart"; buttonStart.Name = "buttonStart";
buttonStart.Size = new Size(110, 29); buttonStart.Size = new Size(110, 29);
buttonStart.TabIndex = 2; buttonStart.TabIndex = 2;
@ -62,7 +64,7 @@
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(281, 87); buttonCancel.Location = new Point(281, 162);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(94, 29); buttonCancel.Size = new Size(94, 29);
buttonCancel.TabIndex = 3; buttonCancel.TabIndex = 3;
@ -70,11 +72,29 @@
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click; buttonCancel.Click += ButtonCancel_Click;
// //
// label1
//
label1.AutoSize = true;
label1.Location = new Point(21, 101);
label1.Name = "label1";
label1.Size = new Size(113, 20);
label1.TabIndex = 4;
label1.Text = "Время работы:";
//
// textBoxTimeWork
//
textBoxTimeWork.Location = new Point(158, 98);
textBoxTimeWork.Name = "textBoxTimeWork";
textBoxTimeWork.Size = new Size(217, 27);
textBoxTimeWork.TabIndex = 5;
//
// FormRandomCreateClient // FormRandomCreateClient
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(429, 141); ClientSize = new Size(412, 220);
Controls.Add(textBoxTimeWork);
Controls.Add(label1);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonStart); Controls.Add(buttonStart);
Controls.Add(textBoxCount); Controls.Add(textBoxCount);
@ -91,5 +111,7 @@
private TextBox textBoxCount; private TextBox textBoxCount;
private Button buttonStart; private Button buttonStart;
private Button buttonCancel; private Button buttonCancel;
private Label label1;
private TextBox textBoxTimeWork;
} }
} }

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Data; using System.Data;
using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -40,27 +41,11 @@ namespace TransportCompany
{ {
try try
{ {
for (int i = 0; i < Convert.ToInt32(textBoxCount.Text); i++) ChangeList(_telephones);
{
var model = new ClientBindingModel
{
Id = 0,
Name = _names[rnd.Next(0, _names.Length)],
Surname = _surnames[rnd.Next(0, _surnames.Length)],
Patronymic = _patronymics[rnd.Next(0, _patronymics.Length)],
Telephone = _telephones[rnd.Next(0, _telephones.Length)] + Convert.ToString(rnd.Next(0, 800000)),
Email = Convert.ToString(rnd.Next(0, 800000)) + _emails[rnd.Next(0, _emails.Length)],
};
var operationResult = _logicC.Create(model); ChangeList(_emails);
if (!operationResult) textBoxTimeWork.Text = _logicC.TestRandomCreate(Convert.ToInt32(textBoxCount.Text), _names, _surnames, _patronymics, _telephones, _emails);
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
Close();
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -73,5 +58,13 @@ namespace TransportCompany
DialogResult = DialogResult.Cancel; DialogResult = DialogResult.Cancel;
Close(); Close();
} }
private void ChangeList(string[] _strings)
{
for(int i = 0; i < _strings.Length; i++)
{
_strings[i] = Convert.ToString(rnd.Next(0, 800000)) + _strings[i];
}
}
} }
} }

View File

@ -32,6 +32,8 @@
textBoxCount = new TextBox(); textBoxCount = new TextBox();
buttonCreate = new Button(); buttonCreate = new Button();
buttonCancel = new Button(); buttonCancel = new Button();
label1 = new Label();
textBoxCheckTest = new TextBox();
SuspendLayout(); SuspendLayout();
// //
// labelClient // labelClient
@ -52,7 +54,7 @@
// //
// buttonCreate // buttonCreate
// //
buttonCreate.Location = new Point(237, 91); buttonCreate.Location = new Point(237, 148);
buttonCreate.Name = "buttonCreate"; buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(123, 29); buttonCreate.Size = new Size(123, 29);
buttonCreate.TabIndex = 2; buttonCreate.TabIndex = 2;
@ -62,7 +64,7 @@
// //
// buttonCancel // buttonCancel
// //
buttonCancel.Location = new Point(382, 91); buttonCancel.Location = new Point(382, 148);
buttonCancel.Name = "buttonCancel"; buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(119, 29); buttonCancel.Size = new Size(119, 29);
buttonCancel.TabIndex = 3; buttonCancel.TabIndex = 3;
@ -70,11 +72,29 @@
buttonCancel.UseVisualStyleBackColor = true; buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += ButtonCancel_Click; buttonCancel.Click += ButtonCancel_Click;
// //
// label1
//
label1.AutoSize = true;
label1.Location = new Point(32, 99);
label1.Name = "label1";
label1.Size = new Size(145, 20);
label1.TabIndex = 4;
label1.Text = "Время добавления:";
//
// textBoxCheckTest
//
textBoxCheckTest.Location = new Point(221, 96);
textBoxCheckTest.Name = "textBoxCheckTest";
textBoxCheckTest.Size = new Size(280, 27);
textBoxCheckTest.TabIndex = 5;
//
// FormRandomCreateTrucking // FormRandomCreateTrucking
// //
AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleDimensions = new SizeF(8F, 20F);
AutoScaleMode = AutoScaleMode.Font; AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(548, 147); ClientSize = new Size(548, 215);
Controls.Add(textBoxCheckTest);
Controls.Add(label1);
Controls.Add(buttonCancel); Controls.Add(buttonCancel);
Controls.Add(buttonCreate); Controls.Add(buttonCreate);
Controls.Add(textBoxCount); Controls.Add(textBoxCount);
@ -91,5 +111,7 @@
private TextBox textBoxCount; private TextBox textBoxCount;
private Button buttonCreate; private Button buttonCreate;
private Button buttonCancel; private Button buttonCancel;
private Label label1;
private TextBox textBoxCheckTest;
} }
} }

View File

@ -16,8 +16,6 @@ namespace TransportCompany
{ {
public partial class FormRandomCreateTrucking : Form public partial class FormRandomCreateTrucking : Form
{ {
Random rnd = new Random(DateTime.Now.ToString().GetHashCode());
private readonly IClientLogic _logicCl; private readonly IClientLogic _logicCl;
private readonly ITransportLogic _logicTransport; private readonly ITransportLogic _logicTransport;
@ -28,10 +26,6 @@ namespace TransportCompany
private readonly ITruckingLogic _logic; private readonly ITruckingLogic _logic;
private int? _id;
public int Id { set { _id = value; } }
public FormRandomCreateTrucking(ILogger<FormRandomCreateTrucking> logger, ITruckingLogic logic, ICargoLogic logicCargo, public FormRandomCreateTrucking(ILogger<FormRandomCreateTrucking> logger, ITruckingLogic logic, ICargoLogic logicCargo,
IClientLogic logicCl, ITransportLogic logicTransport, ITransportationLogic logicTransportation) IClientLogic logicCl, ITransportLogic logicTransport, ITransportationLogic logicTransportation)
{ {
@ -53,32 +47,7 @@ namespace TransportCompany
try try
{ {
for (int i = 0; i < Convert.ToInt32(textBoxCount.Text); i++) textBoxCheckTest.Text = _logic.TestRandomCreate(Convert.ToInt32(textBoxCount.Text), viewClient, viewCargo, viewTransport, viewTransportation);
{
DateTime dateStart = new DateTime(rnd.Next(1991, 2023), rnd.Next(1, 12), rnd.Next(1, 28));
DateTime dateEnd = dateStart.AddDays(20);
var model = new TruckingBindingModel
{
Id = 0,
ClientId = viewClient[rnd.Next(0, viewClient.Count)].Id,
CargoId = viewCargo[rnd.Next(0, viewCargo.Count)].Id,
TransportId = viewTransport[rnd.Next(0, viewTransport.Count)].Id,
TransportationId = viewTransportation[rnd.Next(0, viewTransportation.Count)].Id,
DateStart = dateStart,
DateEnd = dateEnd,
Price = viewClient.Count * rnd.Next(100, 5000)
};
var operationResult = _logic.Create(model);
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
Close();
}
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@ -80,6 +80,12 @@ namespace TransportCompanyBusinessLogic.BusinessLogic
return true; return true;
} }
public string TestRandomCreate(int count, string[] _name, string[] _surname, string[] _patronymic, string[] _telephone, string[] _email)
{
return _clientStorage.TestRandomInsert(count, _name, _surname, _patronymic, _telephone, _email);
}
public bool Update(ClientBindingModel model) public bool Update(ClientBindingModel model)
{ {
CheckModel(model); CheckModel(model);

View File

@ -81,6 +81,11 @@ namespace TransportCompanyBusinessLogic.BusinessLogic
return true; return true;
} }
public string TestRandomCreate(int count, List<ClientViewModel> clients, List<CargoViewModel> cargos, List<TransportViewModel> transports, List<TransportationViewModel> transportations)
{
return _truckingStorage.TestRandomInsert(count, clients, cargos, transports, transportations);
}
public bool Update(TruckingBindingModel model) public bool Update(TruckingBindingModel model)
{ {
CheckModel(model); CheckModel(model);

View File

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

View File

@ -17,6 +17,8 @@ namespace TransportCompanyContracts.BusinessLogicsContracts
bool Create(TruckingBindingModel model); bool Create(TruckingBindingModel model);
string TestRandomCreate(int count, List<ClientViewModel> clients, List<CargoViewModel> cargos, List<TransportViewModel> transports, List<TransportationViewModel> transportations);
bool Update(TruckingBindingModel model); bool Update(TruckingBindingModel model);
bool Delete(TruckingBindingModel model); bool Delete(TruckingBindingModel model);

View File

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

View File

@ -19,6 +19,8 @@ namespace TransportCompanyContracts.StoragesContracts
TruckingViewModel? Insert(TruckingBindingModel model); TruckingViewModel? Insert(TruckingBindingModel model);
string TestRandomInsert(int count, List<ClientViewModel> clients, List<CargoViewModel> cargos, List<TransportViewModel> transports, List<TransportationViewModel> transportations);
TruckingViewModel? Update(TruckingBindingModel model); TruckingViewModel? Update(TruckingBindingModel model);
TruckingViewModel? Delete(TruckingBindingModel model); TruckingViewModel? Delete(TruckingBindingModel model);

View File

@ -1,8 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Net;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq;
using TransportCompanyContracts.BindingModels; using TransportCompanyContracts.BindingModels;
using TransportCompanyContracts.SearchModels; using TransportCompanyContracts.SearchModels;
using TransportCompanyContracts.StoragesContracts; using TransportCompanyContracts.StoragesContracts;
@ -70,6 +73,44 @@ namespace TransportCompanyDatabaseImplements.Implements
return newClient.GetViewModel; return newClient.GetViewModel;
} }
//метод для замера вставки большого кол-ва клиентов в бд
public string TestRandomInsert(int count, string[] _name, string[] _surname, string[] _patronymic, string[] _telephone, string[] _email)
{
using var context = new ElegevContext();
Random rnd = new Random(DateTime.Now.ToString().GetHashCode());
int lastId = context.Clients.Count() > 0 ? context.Clients.Max(x => x.Id) + 1 : 1;
for (int i = 0; i < count; i++)
{
var model = new Client
{
Id = lastId,
Name = _name[rnd.Next(0, _name.Length)],
Surname = _surname[rnd.Next(0, _surname.Length)],
Patronymic = _patronymic[rnd.Next(0, _patronymic.Length)],
Telephone = _telephone[rnd.Next(0, _telephone.Length)],
Email = _email[rnd.Next(0, _email.Length)],
};
lastId++;
context.Clients.Add(model);
}
//старт замера времени добавления в бд
Stopwatch stopwatch = new();
stopwatch.Start();
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

@ -1,6 +1,7 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -99,6 +100,49 @@ namespace TransportCompanyDatabaseImplements.Implements
?.GetViewModel; ?.GetViewModel;
} }
//метод для замера вставки большого кол-ва клиентов в бд
public string TestRandomInsert(int count, List<ClientViewModel> clients, List<CargoViewModel> cargos, List<TransportViewModel> transports, List<TransportationViewModel> transportations)
{
using var context = new ElegevContext();
Random rnd = new Random(DateTime.Now.ToString().GetHashCode());
int lastId = context.Truckings.Count() > 0 ? context.Truckings.Max(x => x.Id) + 1 : 1;
for (int i = 0; i < count; i++)
{
DateTime dateStart = new(rnd.Next(1991, 2023), rnd.Next(1, 12), rnd.Next(1, 28));
DateTime dateEnd = dateStart.AddDays(20);
var model = new Trucking
{
Id = lastId,
ClientId = clients[rnd.Next(0, clients.Count)].Id,
CargoId = cargos[rnd.Next(0, cargos.Count)].Id,
TransportId = transports[rnd.Next(0, transports.Count)].Id,
TransportationId = transportations[rnd.Next(0, transportations.Count)].Id,
DateStart = dateStart,
DateEnd = dateEnd,
Price = clients.Count * rnd.Next(100, 5000)
};
lastId++;
context.Truckings.Add(model);
}
//старт замера времени добавления в бд
Stopwatch stopwatch = new();
stopwatch.Start();
context.SaveChanges();
stopwatch.Stop();
return stopwatch.ElapsedMilliseconds.ToString();
}
public TruckingViewModel? Update(TruckingBindingModel model) public TruckingViewModel? Update(TruckingBindingModel model)
{ {
using var context = new ElegevContext(); using var context = new ElegevContext();