Готовая LabWork04.
This commit is contained in:
parent
2aed31b3c5
commit
0267589a31
@ -32,6 +32,8 @@
|
||||
textBoxCount = new TextBox();
|
||||
buttonStart = new Button();
|
||||
buttonCancel = new Button();
|
||||
label1 = new Label();
|
||||
textBoxTimeWork = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// labelCount
|
||||
@ -52,7 +54,7 @@
|
||||
//
|
||||
// buttonStart
|
||||
//
|
||||
buttonStart.Location = new Point(147, 87);
|
||||
buttonStart.Location = new Point(147, 162);
|
||||
buttonStart.Name = "buttonStart";
|
||||
buttonStart.Size = new Size(110, 29);
|
||||
buttonStart.TabIndex = 2;
|
||||
@ -62,7 +64,7 @@
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(281, 87);
|
||||
buttonCancel.Location = new Point(281, 162);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(94, 29);
|
||||
buttonCancel.TabIndex = 3;
|
||||
@ -70,11 +72,29 @@
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
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
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(429, 141);
|
||||
ClientSize = new Size(412, 220);
|
||||
Controls.Add(textBoxTimeWork);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonStart);
|
||||
Controls.Add(textBoxCount);
|
||||
@ -91,5 +111,7 @@
|
||||
private TextBox textBoxCount;
|
||||
private Button buttonStart;
|
||||
private Button buttonCancel;
|
||||
private Label label1;
|
||||
private TextBox textBoxTimeWork;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@ -40,27 +41,11 @@ namespace TransportCompany
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < Convert.ToInt32(textBoxCount.Text); i++)
|
||||
{
|
||||
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)],
|
||||
};
|
||||
ChangeList(_telephones);
|
||||
|
||||
var operationResult = _logicC.Create(model);
|
||||
ChangeList(_emails);
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
textBoxTimeWork.Text = _logicC.TestRandomCreate(Convert.ToInt32(textBoxCount.Text), _names, _surnames, _patronymics, _telephones, _emails);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -73,5 +58,13 @@ namespace TransportCompany
|
||||
DialogResult = DialogResult.Cancel;
|
||||
Close();
|
||||
}
|
||||
|
||||
private void ChangeList(string[] _strings)
|
||||
{
|
||||
for(int i = 0; i < _strings.Length; i++)
|
||||
{
|
||||
_strings[i] = Convert.ToString(rnd.Next(0, 800000)) + _strings[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,8 @@
|
||||
textBoxCount = new TextBox();
|
||||
buttonCreate = new Button();
|
||||
buttonCancel = new Button();
|
||||
label1 = new Label();
|
||||
textBoxCheckTest = new TextBox();
|
||||
SuspendLayout();
|
||||
//
|
||||
// labelClient
|
||||
@ -52,7 +54,7 @@
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Location = new Point(237, 91);
|
||||
buttonCreate.Location = new Point(237, 148);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(123, 29);
|
||||
buttonCreate.TabIndex = 2;
|
||||
@ -62,7 +64,7 @@
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Location = new Point(382, 91);
|
||||
buttonCancel.Location = new Point(382, 148);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(119, 29);
|
||||
buttonCancel.TabIndex = 3;
|
||||
@ -70,11 +72,29 @@
|
||||
buttonCancel.UseVisualStyleBackColor = true;
|
||||
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
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(548, 147);
|
||||
ClientSize = new Size(548, 215);
|
||||
Controls.Add(textBoxCheckTest);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(buttonCancel);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(textBoxCount);
|
||||
@ -91,5 +111,7 @@
|
||||
private TextBox textBoxCount;
|
||||
private Button buttonCreate;
|
||||
private Button buttonCancel;
|
||||
private Label label1;
|
||||
private TextBox textBoxCheckTest;
|
||||
}
|
||||
}
|
@ -16,8 +16,6 @@ namespace TransportCompany
|
||||
{
|
||||
public partial class FormRandomCreateTrucking : Form
|
||||
{
|
||||
Random rnd = new Random(DateTime.Now.ToString().GetHashCode());
|
||||
|
||||
private readonly IClientLogic _logicCl;
|
||||
|
||||
private readonly ITransportLogic _logicTransport;
|
||||
@ -28,10 +26,6 @@ namespace TransportCompany
|
||||
|
||||
private readonly ITruckingLogic _logic;
|
||||
|
||||
private int? _id;
|
||||
|
||||
public int Id { set { _id = value; } }
|
||||
|
||||
public FormRandomCreateTrucking(ILogger<FormRandomCreateTrucking> logger, ITruckingLogic logic, ICargoLogic logicCargo,
|
||||
IClientLogic logicCl, ITransportLogic logicTransport, ITransportationLogic logicTransportation)
|
||||
{
|
||||
@ -53,32 +47,7 @@ namespace TransportCompany
|
||||
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < Convert.ToInt32(textBoxCount.Text); i++)
|
||||
{
|
||||
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();
|
||||
}
|
||||
textBoxCheckTest.Text = _logic.TestRandomCreate(Convert.ToInt32(textBoxCount.Text), viewClient, viewCargo, viewTransport, viewTransportation);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -80,6 +80,12 @@ namespace TransportCompanyBusinessLogic.BusinessLogic
|
||||
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)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
@ -81,6 +81,11 @@ namespace TransportCompanyBusinessLogic.BusinessLogic
|
||||
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)
|
||||
{
|
||||
CheckModel(model);
|
||||
|
@ -17,6 +17,8 @@ namespace TransportCompanyContracts.BusinessLogicsContracts
|
||||
|
||||
bool Create(ClientBindingModel model);
|
||||
|
||||
string TestRandomCreate(int count, string[] _name, string[] _surname, string[] _patronymic, string[] _telephone, string[] _email);
|
||||
|
||||
bool Update(ClientBindingModel model);
|
||||
|
||||
bool Delete(ClientBindingModel model);
|
||||
|
@ -17,6 +17,8 @@ namespace TransportCompanyContracts.BusinessLogicsContracts
|
||||
|
||||
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 Delete(TruckingBindingModel model);
|
||||
|
@ -19,6 +19,8 @@ namespace TransportCompanyContracts.StoragesContracts
|
||||
|
||||
ClientViewModel? Insert(ClientBindingModel model);
|
||||
|
||||
string TestRandomInsert(int count, string[] _name, string[] _surname, string[] _patronymic, string[] _telephone, string[] _email);
|
||||
|
||||
ClientViewModel? Update(ClientBindingModel model);
|
||||
|
||||
ClientViewModel? Delete(ClientBindingModel model);
|
||||
|
@ -19,6 +19,8 @@ namespace TransportCompanyContracts.StoragesContracts
|
||||
|
||||
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? Delete(TruckingBindingModel model);
|
||||
|
@ -1,8 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using TransportCompanyContracts.BindingModels;
|
||||
using TransportCompanyContracts.SearchModels;
|
||||
using TransportCompanyContracts.StoragesContracts;
|
||||
@ -70,6 +73,44 @@ namespace TransportCompanyDatabaseImplements.Implements
|
||||
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)
|
||||
{
|
||||
using var context = new ElegevContext();
|
||||
|
@ -1,6 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -99,6 +100,49 @@ namespace TransportCompanyDatabaseImplements.Implements
|
||||
?.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)
|
||||
{
|
||||
using var context = new ElegevContext();
|
||||
|
Loading…
Reference in New Issue
Block a user