5 лаба

This commit is contained in:
Danil Markov 2023-04-26 22:45:20 +04:00
parent d03000c592
commit b45a47f5a4
29 changed files with 313 additions and 29 deletions

View File

@ -36,6 +36,7 @@
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.buttonCancel = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button(); this.buttonAdd = new System.Windows.Forms.Button();
this.buttonTestAdd = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// textBoxPhoneNumber // textBoxPhoneNumber
@ -106,11 +107,22 @@
this.buttonAdd.UseVisualStyleBackColor = true; this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
// //
// buttonTestAdd
//
this.buttonTestAdd.Location = new System.Drawing.Point(176, 11);
this.buttonTestAdd.Name = "buttonTestAdd";
this.buttonTestAdd.Size = new System.Drawing.Size(75, 54);
this.buttonTestAdd.TabIndex = 28;
this.buttonTestAdd.Text = "Добавить 1000 филиалов";
this.buttonTestAdd.UseVisualStyleBackColor = true;
this.buttonTestAdd.Click += new System.EventHandler(this.buttonTestAdd_Click);
//
// FormCreateBranch // FormCreateBranch
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(263, 155); this.ClientSize = new System.Drawing.Size(263, 155);
this.Controls.Add(this.buttonTestAdd);
this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonAdd); this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.textBoxPhoneNumber); this.Controls.Add(this.textBoxPhoneNumber);
@ -139,5 +151,6 @@
private Label label1; private Label label1;
private Button buttonCancel; private Button buttonCancel;
private Button buttonAdd; private Button buttonAdd;
private Button buttonTestAdd;
} }
} }

View File

@ -1,6 +1,8 @@
using CarRentContracts.BindingModels; using CarRentBusinessLogic.BusinessLogics;
using CarRentContracts.BindingModels;
using CarRentContracts.BusinessLogicContracts; using CarRentContracts.BusinessLogicContracts;
using CarRentContracts.SearchModels; using CarRentContracts.SearchModels;
using ClientRentBusinessLogic.BusinessLogics;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -98,5 +100,17 @@ namespace CarRent
} }
} }
} }
private void buttonTestAdd_Click(object sender, EventArgs e)
{
try
{
_branchLogic.BranchInsertList(1000);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
} }
} }

View File

@ -44,6 +44,7 @@
this.buttonAdd = new System.Windows.Forms.Button(); this.buttonAdd = new System.Windows.Forms.Button();
this.buttonCancel = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button();
this.dateTimePicker = new System.Windows.Forms.DateTimePicker(); this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
this.buttonTestAdd = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// label1 // label1
@ -179,11 +180,22 @@
this.dateTimePicker.Size = new System.Drawing.Size(145, 23); this.dateTimePicker.Size = new System.Drawing.Size(145, 23);
this.dateTimePicker.TabIndex = 16; this.dateTimePicker.TabIndex = 16;
// //
// buttonTestAdd
//
this.buttonTestAdd.Location = new System.Drawing.Point(180, 185);
this.buttonTestAdd.Name = "buttonTestAdd";
this.buttonTestAdd.Size = new System.Drawing.Size(75, 54);
this.buttonTestAdd.TabIndex = 29;
this.buttonTestAdd.Text = "Добавить 1000 машин";
this.buttonTestAdd.UseVisualStyleBackColor = true;
this.buttonTestAdd.Click += new System.EventHandler(this.buttonTestAdd_Click);
//
// FormCreateCar // FormCreateCar
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(267, 323); this.ClientSize = new System.Drawing.Size(267, 323);
this.Controls.Add(this.buttonTestAdd);
this.Controls.Add(this.dateTimePicker); this.Controls.Add(this.dateTimePicker);
this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonAdd); this.Controls.Add(this.buttonAdd);
@ -226,5 +238,6 @@
private Button buttonAdd; private Button buttonAdd;
private Button buttonCancel; private Button buttonCancel;
private DateTimePicker dateTimePicker; private DateTimePicker dateTimePicker;
private Button buttonTestAdd;
} }
} }

View File

@ -142,5 +142,17 @@ namespace CarRent
} }
} }
} }
private void buttonTestAdd_Click(object sender, EventArgs e)
{
try
{
_carLogic.CarInsertList(1000, _branchLogic.ReadList(null));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
} }
} }

View File

@ -40,6 +40,7 @@
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.buttonCancel = new System.Windows.Forms.Button(); this.buttonCancel = new System.Windows.Forms.Button();
this.buttonAdd = new System.Windows.Forms.Button(); this.buttonAdd = new System.Windows.Forms.Button();
this.buttonTestAdd = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// textBoxDriveLicense // textBoxDriveLicense
@ -143,11 +144,22 @@
this.buttonAdd.UseVisualStyleBackColor = true; this.buttonAdd.UseVisualStyleBackColor = true;
this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click); this.buttonAdd.Click += new System.EventHandler(this.buttonAdd_Click);
// //
// buttonTestAdd
//
this.buttonTestAdd.Location = new System.Drawing.Point(176, 97);
this.buttonTestAdd.Name = "buttonTestAdd";
this.buttonTestAdd.Size = new System.Drawing.Size(75, 54);
this.buttonTestAdd.TabIndex = 30;
this.buttonTestAdd.Text = "Добавить 50 клиентов";
this.buttonTestAdd.UseVisualStyleBackColor = true;
this.buttonTestAdd.Click += new System.EventHandler(this.buttonTestAdd_Click);
//
// FormCreateClient // FormCreateClient
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(263, 237); this.ClientSize = new System.Drawing.Size(263, 237);
this.Controls.Add(this.buttonTestAdd);
this.Controls.Add(this.buttonCancel); this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonAdd); this.Controls.Add(this.buttonAdd);
this.Controls.Add(this.textBoxDriveLicense); this.Controls.Add(this.textBoxDriveLicense);
@ -182,5 +194,6 @@
private Label label1; private Label label1;
private Button buttonCancel; private Button buttonCancel;
private Button buttonAdd; private Button buttonAdd;
private Button buttonTestAdd;
} }
} }

View File

@ -118,5 +118,17 @@ namespace CarRent
} }
} }
} }
private void buttonTestAdd_Click(object sender, EventArgs e)
{
try
{
_clientLogic.ClientInsertList(50);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
} }
} }

View File

@ -86,7 +86,7 @@ namespace CarRent
Id = _id ?? 0, Id = _id ?? 0,
StartDate = DateTime.SpecifyKind(dateTimePickerStart.Value, DateTimeKind.Utc), StartDate = DateTime.SpecifyKind(dateTimePickerStart.Value, DateTimeKind.Utc),
EndDate = DateTime.SpecifyKind(dateTimePickerEnd.Value, DateTimeKind.Utc), EndDate = DateTime.SpecifyKind(dateTimePickerEnd.Value, DateTimeKind.Utc),
RentalCost = Convert.ToInt32(textBoxCost.Text), RentalCost = Convert.ToInt32(Math.Round(Convert.ToDouble(textBoxCost.Text))),
ClientId = Convert.ToInt32(comboBoxClient.SelectedValue), ClientId = Convert.ToInt32(comboBoxClient.SelectedValue),
CarId = Convert.ToInt32(comboBoxCar.SelectedValue), CarId = Convert.ToInt32(comboBoxCar.SelectedValue),
}; };

View File

@ -35,9 +35,9 @@
this.филиалыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.филиалыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.автомобилиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.автомобилиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.тестыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.comboBoxClientsEmail = new System.Windows.Forms.ComboBox(); this.comboBoxClientsEmail = new System.Windows.Forms.ComboBox();
this.buttonAddReview = new System.Windows.Forms.Button(); this.buttonAddReview = new System.Windows.Forms.Button();
this.тестыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout(); this.menuStrip1.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
@ -106,6 +106,13 @@
this.клиентыToolStripMenuItem.Text = "Клиенты"; this.клиентыToolStripMenuItem.Text = "Клиенты";
this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click); this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click);
// //
// тестыToolStripMenuItem
//
this.тестыToolStripMenuItem.Name = естыToolStripMenuItem";
this.тестыToolStripMenuItem.Size = new System.Drawing.Size(51, 20);
this.тестыToolStripMenuItem.Text = "Тесты";
this.тестыToolStripMenuItem.Click += new System.EventHandler(this.testsToolStripMenuItem_Click);
//
// comboBoxClientsEmail // comboBoxClientsEmail
// //
this.comboBoxClientsEmail.FormattingEnabled = true; this.comboBoxClientsEmail.FormattingEnabled = true;
@ -113,6 +120,7 @@
this.comboBoxClientsEmail.Name = "comboBoxClientsEmail"; this.comboBoxClientsEmail.Name = "comboBoxClientsEmail";
this.comboBoxClientsEmail.Size = new System.Drawing.Size(121, 23); this.comboBoxClientsEmail.Size = new System.Drawing.Size(121, 23);
this.comboBoxClientsEmail.TabIndex = 14; this.comboBoxClientsEmail.TabIndex = 14;
this.comboBoxClientsEmail.SelectedIndexChanged += new System.EventHandler(this.comboBoxClientsEmail_SelectedIndexChanged);
// //
// buttonAddReview // buttonAddReview
// //
@ -124,13 +132,6 @@
this.buttonAddReview.UseVisualStyleBackColor = true; this.buttonAddReview.UseVisualStyleBackColor = true;
this.buttonAddReview.Click += new System.EventHandler(this.buttonAddReview_Click); this.buttonAddReview.Click += new System.EventHandler(this.buttonAddReview_Click);
// //
// тестыToolStripMenuItem
//
this.тестыToolStripMenuItem.Name = естыToolStripMenuItem";
this.тестыToolStripMenuItem.Size = new System.Drawing.Size(51, 20);
this.тестыToolStripMenuItem.Text = "Тесты";
this.тестыToolStripMenuItem.Click += new System.EventHandler(this.testsToolStripMenuItem_Click);
//
// FormRentals // FormRentals
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);

View File

@ -1,4 +1,5 @@
using CarRentContracts.BusinessLogicContracts; using CarRentContracts.BusinessLogicContracts;
using CarRentContracts.SearchModels;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -32,6 +33,13 @@ namespace CarRent
var listClients = _clientLogic.ReadList(null); var listClients = _clientLogic.ReadList(null);
if (listClients != null)
{
comboBoxClientsEmail.DisplayMember = "Email";
comboBoxClientsEmail.ValueMember = "Id";
comboBoxClientsEmail.DataSource = listClients;
comboBoxClientsEmail.SelectedItem = null;
}
if (list != null) if (list != null)
{ {
dataGridView.DataSource = list; dataGridView.DataSource = list;
@ -40,17 +48,21 @@ namespace CarRent
dataGridView.Columns["Id"].Visible = false; dataGridView.Columns["Id"].Visible = false;
} }
if (listClients != null)
{
comboBoxClientsEmail.DisplayMember = "Email";
comboBoxClientsEmail.ValueMember = "Id";
comboBoxClientsEmail.DataSource = listClients;
comboBoxClientsEmail.SelectedItem = null;
}
} }
catch (Exception ex) catch (Exception ex)
{} {}
} }
private void LoadData(int id)
{
var list = _rentalLogic.ReadList(new RentalSearchModel
{
ClientId = id,
});
dataGridView.DataSource = list;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["CarId"].Visible = false;
dataGridView.Columns["Id"].Visible = false;
}
private void филиалыToolStripMenuItem_Click(object sender, EventArgs e) private void филиалыToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var service = Program.ServiceProvider?.GetService(typeof(FormBranches)); var service = Program.ServiceProvider?.GetService(typeof(FormBranches));
@ -131,5 +143,10 @@ namespace CarRent
LoadData(); LoadData();
} }
} }
private void comboBoxClientsEmail_SelectedIndexChanged(object sender, EventArgs e)
{
LoadData(Convert.ToInt32(comboBoxClientsEmail.SelectedValue));
}
} }
} }

View File

@ -38,8 +38,14 @@
this.label4 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label();
this.numericUpDownInsert = new System.Windows.Forms.NumericUpDown(); this.numericUpDownInsert = new System.Windows.Forms.NumericUpDown();
this.numericUpDownRead = new System.Windows.Forms.NumericUpDown(); this.numericUpDownRead = new System.Windows.Forms.NumericUpDown();
this.buttonJoinQuery = new System.Windows.Forms.Button();
this.numericUpDownJoin = new System.Windows.Forms.NumericUpDown();
this.textBoxJoin = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownJoin)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
// //
// buttonInsertTest // buttonInsertTest
@ -128,11 +134,59 @@
this.numericUpDownRead.Size = new System.Drawing.Size(100, 23); this.numericUpDownRead.Size = new System.Drawing.Size(100, 23);
this.numericUpDownRead.TabIndex = 11; this.numericUpDownRead.TabIndex = 11;
// //
// buttonJoinQuery
//
this.buttonJoinQuery.Location = new System.Drawing.Point(12, 197);
this.buttonJoinQuery.Name = "buttonJoinQuery";
this.buttonJoinQuery.Size = new System.Drawing.Size(75, 74);
this.buttonJoinQuery.TabIndex = 12;
this.buttonJoinQuery.Text = "Тест сложного чтения (Join)";
this.buttonJoinQuery.UseVisualStyleBackColor = true;
this.buttonJoinQuery.Click += new System.EventHandler(this.buttonJoinQuery_Click);
//
// numericUpDownJoin
//
this.numericUpDownJoin.Location = new System.Drawing.Point(266, 195);
this.numericUpDownJoin.Name = "numericUpDownJoin";
this.numericUpDownJoin.Size = new System.Drawing.Size(100, 23);
this.numericUpDownJoin.TabIndex = 16;
//
// textBoxJoin
//
this.textBoxJoin.Location = new System.Drawing.Point(266, 235);
this.textBoxJoin.Name = "textBoxJoin";
this.textBoxJoin.ReadOnly = true;
this.textBoxJoin.Size = new System.Drawing.Size(100, 23);
this.textBoxJoin.TabIndex = 15;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(104, 238);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(146, 15);
this.label5.TabIndex = 14;
this.label5.Text = "Итоговое время запроса:";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(104, 197);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(156, 15);
this.label6.TabIndex = 13;
this.label6.Text = "Введите кол-во элементов:";
//
// FormTests // FormTests
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(383, 189); this.ClientSize = new System.Drawing.Size(383, 286);
this.Controls.Add(this.numericUpDownJoin);
this.Controls.Add(this.textBoxJoin);
this.Controls.Add(this.label5);
this.Controls.Add(this.label6);
this.Controls.Add(this.buttonJoinQuery);
this.Controls.Add(this.numericUpDownRead); this.Controls.Add(this.numericUpDownRead);
this.Controls.Add(this.numericUpDownInsert); this.Controls.Add(this.numericUpDownInsert);
this.Controls.Add(this.textBoxReadTime); this.Controls.Add(this.textBoxReadTime);
@ -147,6 +201,7 @@
this.Text = "Тесты запросов к бд"; this.Text = "Тесты запросов к бд";
((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownInsert)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDownRead)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDownJoin)).EndInit();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();
@ -164,5 +219,10 @@
private Label label4; private Label label4;
private NumericUpDown numericUpDownInsert; private NumericUpDown numericUpDownInsert;
private NumericUpDown numericUpDownRead; private NumericUpDown numericUpDownRead;
private Button buttonJoinQuery;
private NumericUpDown numericUpDownJoin;
private TextBox textBoxJoin;
private Label label5;
private Label label6;
} }
} }

View File

@ -30,6 +30,8 @@ namespace CarRent
numericUpDownInsert.Maximum = 1000000; numericUpDownInsert.Maximum = 1000000;
numericUpDownRead.Minimum = 0; numericUpDownRead.Minimum = 0;
numericUpDownRead.Maximum = 1000000; numericUpDownRead.Maximum = 1000000;
numericUpDownJoin.Minimum = 0;
numericUpDownJoin.Maximum = 1000000;
} }
private void buttonInsertTest_Click(object sender, EventArgs e) private void buttonInsertTest_Click(object sender, EventArgs e)
@ -60,5 +62,18 @@ namespace CarRent
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
} }
} }
private void buttonJoinQuery_Click(object sender, EventArgs e)
{
try
{
var result = _rentalLogic.TestJoinReadList(Convert.ToInt32(numericUpDownJoin.Value));
textBoxJoin.Text = result;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
} }
} }

View File

@ -18,6 +18,10 @@ namespace CarRentBusinessLogic.BusinessLogics
{ {
_branchStorage = branchStorage; _branchStorage = branchStorage;
} }
public void BranchInsertList(int num)
{
_branchStorage.BranchInsertList(num);
}
public List<BranchViewModel>? ReadList(BranchSearchModel? model) public List<BranchViewModel>? ReadList(BranchSearchModel? model)
{ {
var list = model == null ? _branchStorage.GetFullList() : var list = model == null ? _branchStorage.GetFullList() :

View File

@ -18,6 +18,10 @@ namespace CarRentBusinessLogic.BusinessLogics
{ {
_carStorage = CarStorage; _carStorage = CarStorage;
} }
public void CarInsertList(int num, List<BranchViewModel> branches)
{
_carStorage.CarInsertList(num, branches);
}
public List<CarViewModel>? ReadList(CarSearchModel? model) public List<CarViewModel>? ReadList(CarSearchModel? model)
{ {
var list = model == null ? _carStorage.GetFullList() : var list = model == null ? _carStorage.GetFullList() :

View File

@ -13,15 +13,19 @@ namespace ClientRentBusinessLogic.BusinessLogics
{ {
public class ClientLogic : IClientLogic public class ClientLogic : IClientLogic
{ {
private readonly IClientStorage _ClientStorage; private readonly IClientStorage _clientStorage;
public ClientLogic(IClientStorage ClientStorage) public ClientLogic(IClientStorage ClientStorage)
{ {
_ClientStorage = ClientStorage; _clientStorage = ClientStorage;
}
public void ClientInsertList(int num)
{
_clientStorage.ClientInsertList(num);
} }
public List<ClientViewModel>? ReadList(ClientSearchModel? model) public List<ClientViewModel>? ReadList(ClientSearchModel? model)
{ {
var list = model == null ? _ClientStorage.GetFullList() : var list = model == null ? _clientStorage.GetFullList() :
_ClientStorage.GetFilteredList(model); _clientStorage.GetFilteredList(model);
if (list == null) if (list == null)
{ {
return null; return null;
@ -34,7 +38,7 @@ namespace ClientRentBusinessLogic.BusinessLogics
{ {
throw new ArgumentNullException(nameof(model)); throw new ArgumentNullException(nameof(model));
} }
var element = _ClientStorage.GetElement(model); var element = _clientStorage.GetElement(model);
if (element == null) if (element == null)
{ {
return null; return null;
@ -44,7 +48,7 @@ namespace ClientRentBusinessLogic.BusinessLogics
public bool Create(ClientBindingModel model) public bool Create(ClientBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (_ClientStorage.Insert(model) == null) if (_clientStorage.Insert(model) == null)
{ {
return false; return false;
} }
@ -53,7 +57,7 @@ namespace ClientRentBusinessLogic.BusinessLogics
public bool Update(ClientBindingModel model) public bool Update(ClientBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (_ClientStorage.Update(model) == null) if (_clientStorage.Update(model) == null)
{ {
return false; return false;
} }
@ -62,7 +66,7 @@ namespace ClientRentBusinessLogic.BusinessLogics
public bool Delete(ClientBindingModel model) public bool Delete(ClientBindingModel model)
{ {
CheckModel(model, false); CheckModel(model, false);
if (_ClientStorage.Delete(model) == null) if (_clientStorage.Delete(model) == null)
{ {
return false; return false;
} }
@ -104,7 +108,7 @@ namespace ClientRentBusinessLogic.BusinessLogics
nameof(model.DriveLicenseNumber)); nameof(model.DriveLicenseNumber));
} }
var element = _ClientStorage.GetElement( var element = _clientStorage.GetElement(
new ClientSearchModel new ClientSearchModel
{ {
DriveLicenseNumber = model.DriveLicenseNumber DriveLicenseNumber = model.DriveLicenseNumber

View File

@ -28,6 +28,10 @@ namespace CarRentBusinessLogic.BusinessLogics
{ {
return _rentalStorage.TestReadList(num); return _rentalStorage.TestReadList(num);
} }
public string TestJoinReadList(int num)
{
return _rentalStorage.TestJoinReadList(num);
}
public List<RentalViewModel>? ReadList(RentalSearchModel? model) public List<RentalViewModel>? ReadList(RentalSearchModel? model)
{ {
var list = model == null ? _rentalStorage.GetFullList() : var list = model == null ? _rentalStorage.GetFullList() :

View File

@ -16,5 +16,6 @@ namespace CarRentContracts.BusinessLogicContracts
bool Create(BranchBindingModel model); bool Create(BranchBindingModel model);
bool Update(BranchBindingModel model); bool Update(BranchBindingModel model);
bool Delete(BranchBindingModel model); bool Delete(BranchBindingModel model);
void BranchInsertList(int num);
} }
} }

View File

@ -16,5 +16,6 @@ namespace CarRentContracts.BusinessLogicContracts
bool Create(CarBindingModel model); bool Create(CarBindingModel model);
bool Update(CarBindingModel model); bool Update(CarBindingModel model);
bool Delete(CarBindingModel model); bool Delete(CarBindingModel model);
void CarInsertList(int num, List<BranchViewModel> branches);
} }
} }

View File

@ -16,5 +16,6 @@ namespace CarRentContracts.BusinessLogicContracts
bool Create(ClientBindingModel model); bool Create(ClientBindingModel model);
bool Update(ClientBindingModel model); bool Update(ClientBindingModel model);
bool Delete(ClientBindingModel model); bool Delete(ClientBindingModel model);
void ClientInsertList(int num);
} }
} }

View File

@ -20,5 +20,6 @@ namespace CarRentContracts.BusinessLogicContracts
List<ClientViewModel> clients, List<ClientViewModel> clients,
List<CarViewModel> cars); List<CarViewModel> cars);
string TestReadList(int num); string TestReadList(int num);
string TestJoinReadList(int num);
} }
} }

View File

@ -17,5 +17,6 @@ namespace CarRentContracts.StoragesContracts
BranchViewModel? Insert(BranchBindingModel model); BranchViewModel? Insert(BranchBindingModel model);
BranchViewModel? Update(BranchBindingModel model); BranchViewModel? Update(BranchBindingModel model);
BranchViewModel? Delete(BranchBindingModel model); BranchViewModel? Delete(BranchBindingModel model);
void BranchInsertList(int num);
} }
} }

View File

@ -17,5 +17,6 @@ namespace CarRentContracts.StoragesContracts
CarViewModel? Insert(CarBindingModel model); CarViewModel? Insert(CarBindingModel model);
CarViewModel? Update(CarBindingModel model); CarViewModel? Update(CarBindingModel model);
CarViewModel? Delete(CarBindingModel model); CarViewModel? Delete(CarBindingModel model);
void CarInsertList(int num, List<BranchViewModel> branches);
} }
} }

View File

@ -17,5 +17,6 @@ namespace CarRentContracts.StoragesContracts
ClientViewModel? Insert(ClientBindingModel model); ClientViewModel? Insert(ClientBindingModel model);
ClientViewModel? Update(ClientBindingModel model); ClientViewModel? Update(ClientBindingModel model);
ClientViewModel? Delete(ClientBindingModel model); ClientViewModel? Delete(ClientBindingModel model);
void ClientInsertList(int num);
} }
} }

View File

@ -21,5 +21,6 @@ namespace CarRentContracts.StoragesContracts
List<ClientViewModel> clients, List<ClientViewModel> clients,
List<CarViewModel> cars); List<CarViewModel> cars);
string TestReadList(int num); string TestReadList(int num);
string TestJoinReadList(int num);
} }
} }

View File

@ -14,6 +14,8 @@ namespace CarRentContracts.ViewModels
public string ClientName { get; set; } = string.Empty; public string ClientName { get; set; } = string.Empty;
[DisplayName("Фамилия")] [DisplayName("Фамилия")]
public string ClientSurname { get; set; } = string.Empty; public string ClientSurname { get; set; } = string.Empty;
[DisplayName("Номер автомобиля")]
public string LicensePlate { get; set; } = string.Empty;
[DisplayName("Дата начала аренды")] [DisplayName("Дата начала аренды")]
public DateTime StartDate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc); public DateTime StartDate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
[DisplayName("Дата конца аренды")] [DisplayName("Дата конца аренды")]

View File

@ -5,6 +5,7 @@ using CarRentContracts.ViewModels;
using CarRentDatabase.Models; using CarRentDatabase.Models;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Numerics; using System.Numerics;
using System.Text; using System.Text;
@ -14,6 +15,23 @@ namespace CarRentDatabase.Implements
{ {
public class BranchStorage : IBranchStorage public class BranchStorage : IBranchStorage
{ {
public void BranchInsertList(int num)
{
Random rnd = new Random();
using var context = new CarRentDatabase();
for (int i = 0; i < num; ++i)
{
var model = new BranchBindingModel
{
Id = 0,
Name = rnd.Next(1000).ToString(),
Address = rnd.Next(1000).ToString(),
PhoneNumber = rnd.Next(1000).ToString(),
};
context.Branches.Add(Branch.Create(model));
}
context.SaveChanges();
}
public BranchViewModel? GetElement(BranchSearchModel model) public BranchViewModel? GetElement(BranchSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)

View File

@ -28,7 +28,27 @@ namespace CarRentDatabase.Implements
(model.Id.HasValue && x.Id == model.Id)) (model.Id.HasValue && x.Id == model.Id))
?.GetViewModel; ?.GetViewModel;
} }
public void CarInsertList(int num, List<BranchViewModel> branches)
{
Random rnd = new Random();
using var context = new CarRentDatabase();
for (int i = 0; i < num; ++i)
{
var model = new CarBindingModel
{
Id = 0,
Brand = rnd.Next(1000).ToString(),
Model = rnd.Next(1000).ToString(),
YearOfManuf = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc),
Color = rnd.Next(1000).ToString(),
LicensePlate = rnd.Next(1000).ToString(),
RentalCostPerHour = rnd.Next(1000),
BranchId = branches[rnd.Next(branches.Count)].Id,
};
context.Cars.Add(Car.Create(model));
}
context.SaveChanges();
}
public List<CarViewModel> GetFilteredList(CarSearchModel model) public List<CarViewModel> GetFilteredList(CarSearchModel model)
{ {
using var context = new CarRentDatabase(); using var context = new CarRentDatabase();

View File

@ -13,6 +13,25 @@ namespace CarRentDatabase.Implements
{ {
public class ClientStorage : IClientStorage public class ClientStorage : IClientStorage
{ {
public void ClientInsertList(int num)
{
Random rnd = new Random();
using var context = new CarRentDatabase();
for (int i = 0; i < num; ++i)
{
var model = new ClientBindingModel
{
Id = 0,
Name = rnd.Next(1000).ToString(),
Surname = rnd.Next(1000).ToString(),
PhoneNumber = rnd.Next(1000).ToString(),
Email = rnd.Next(1000).ToString(),
DriveLicenseNumber = rnd.Next(1000).ToString(),
};
context.Clients.Add(Client.Create(model));
}
context.SaveChanges();
}
public ClientViewModel? GetElement(ClientSearchModel model) public ClientViewModel? GetElement(ClientSearchModel model)
{ {
if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue) if (string.IsNullOrEmpty(model.Name) && !model.Id.HasValue)

View File

@ -60,6 +60,36 @@ namespace CarRentDatabase.Implements
return stopwatch.ElapsedMilliseconds.ToString(); return stopwatch.ElapsedMilliseconds.ToString();
} }
public string TestJoinReadList(int num)
{
using var context = new CarRentDatabase();
Stopwatch stopwatch = new();
stopwatch.Start();
var list = context.Rentals
.Include(x => x.Car)
.Include(x => x.Client)
.Join(context.Clients,
r => r.ClientId,
c => c.Id,
(r, c) => new { Rental = r, Client = c })
.Join(context.Cars,
rc => rc.Rental.CarId,
car => car.Id,
(rc, car) => new { rc.Rental, rc.Client, Car = car })
.Select(rc => new
{
Rental = rc.Rental.GetViewModel,
Client = rc.Client.GetViewModel,
Car = rc.Car.GetViewModel,
})
.Take(num)
.ToList();
stopwatch.Stop();
return stopwatch.ElapsedMilliseconds.ToString();
}
public RentalViewModel? GetElement(RentalSearchModel model) public RentalViewModel? GetElement(RentalSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.Id.HasValue)
@ -77,7 +107,7 @@ namespace CarRentDatabase.Implements
public List<RentalViewModel> GetFilteredList(RentalSearchModel model) public List<RentalViewModel> GetFilteredList(RentalSearchModel model)
{ {
if (!model.Id.HasValue) if (!model.Id.HasValue && !model.ClientId.HasValue)
{ {
return new(); return new();
} }

View File

@ -65,6 +65,7 @@ namespace CarRentDatabase.Models
Id = Id, Id = Id,
ClientName = Client == null ? string.Empty : Client.Name, ClientName = Client == null ? string.Empty : Client.Name,
ClientSurname = Client == null ? string.Empty : Client.Surname, ClientSurname = Client == null ? string.Empty : Client.Surname,
LicensePlate = Car == null ? string.Empty : Car.LicensePlate,
StartDate = StartDate, StartDate = StartDate,
EndDate = EndDate, EndDate = EndDate,
RentalCost = RentalCost, RentalCost = RentalCost,