PIbd-21_Afanasev_S.S_SUBD_C.../ComputerFirm/Forms/FormMain.cs
2024-05-06 22:17:29 +04:00

154 lines
5.8 KiB
C#

using database;
using Microsoft.Extensions.DependencyInjection;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;
namespace Forms
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
private void deviceToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormDevice));
if (service is FormDevice form)
{
form.ShowDialog();
}
}
private void componentToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
if (service is FormComponent form)
{
form.ShowDialog();
}
}
private void employeesToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormEmployees));
if (service is FormEmployees form)
{
form.ShowDialog();
}
}
private void clientToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClient));
if (service is FormClient form)
{
form.ShowDialog();
}
}
private void orderToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormOrder));
if (service is FormOrder form)
{
form.ShowDialog();
}
}
private void serviceToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormService));
if (service is FormService form)
{
form.ShowDialog();
}
}
private void buttonTest_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(Abstractions));
if (service is Abstractions bd)
{
// Замените "GetClients" на метод вашего класса, который выполняет запрос к сущности
DateTime startTime = DateTime.Now;
var result = bd.GetClients(); // Выполняем запрос к сущности
DateTime endTime = DateTime.Now;
// Выводим время выполнения запроса в консоль
textBoxTest.Text = $"Время выполнения запроса: {(endTime - startTime).TotalMilliseconds} миллисекунд";
}
}
private void buttonTest2_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(Abstractions));
if (service is Abstractions bd)
{
DateTime startTime = DateTime.Now;
for (int i = 0; i < 1000; i++)
{
Employee employee = new Employee
{
Name = "Сотрудник " + i,
Surname = "Фамилия " + i,
Position = "Должность " + i,
Timework = "Время работы " + i,
Seniority = "Стаж " + i,
CostPerHour = i * 10
};
bd.AddEmployee(employee);
}
DateTime endTime = DateTime.Now;
textBoxTest2.Text = $"Добавление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
}
}
private void buttonTest3_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(Abstractions));
if (service is Abstractions bd)
{
DateTime startTime = DateTime.Now;
for (int i = 0; i < 1000; i++)
{
var employee = bd.GetEmployees();
int id = employee.Last().Id;
bd.DeleteEmployee(id);
}
DateTime endTime = DateTime.Now;
textBoxTest3.Text = $"Удаление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
}
}
/*
private Abstractions bd = new Implementation();
private void button1_Click(object sender, EventArgs e)
{
List<Branch> branches = bd.GetBranches();
// Очищаем dataGridView1 перед заполнением новыми данными
dataGridView1.Rows.Clear();
// Предварительно определяем столбцы, если это не было сделано ранее
if (dataGridView1.ColumnCount == 0)
{
dataGridView1.Columns.Add("Id", "ID");
dataGridView1.Columns.Add("Name", "Name");
dataGridView1.Columns.Add("Address", "Address");
dataGridView1.Columns.Add("Phone", "Phone");
dataGridView1.Columns.Add("WorkingHours", "Working Hours");
}
// Заполняем dataGridView1 данными из списка branches
foreach (Branch branch in branches)
{
dataGridView1.Rows.Add(branch.Id, branch.Name, branch.Address, branch.Phone, branch.WorkingHours);
}
}
*/
}
}