PIbd-21_Shanygin_A.V_BaseData/Hotel/HotelView/FormMain.cs

286 lines
10 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelDatabaseImplement.Models;
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 System.Xml.Linq;
namespace HotelView
{
public partial class FormMain : Form
{
private readonly IBookingLogic _logic;
private readonly IRoomLogic _logicR;
private readonly IClientLogic _logicC;
public FormMain(IBookingLogic logic, IRoomLogic logicR, IClientLogic logicC)
{
InitializeComponent();
_logic = logic;
_logicR = logicR;
_logicC = logicC;
}
private void FormMain_Load(object sender, EventArgs e)
{
LoadData();
}
private void dataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void LoadData()
{
var _list = _logic.ReadList(null);
if (_list != null)
{
dataGridView.DataSource = _list;
dataGridView.Columns["RoomId"].Visible = false;
dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["Number"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["Surname"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
}
}
private void clientToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormClients));
if (service is FormClients form)
{
form.ShowDialog();
}
}
private void postToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormPosts));
if (service is FormPosts form)
{
form.ShowDialog();
}
}
private void workerToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormWorkers));
if (service is FormWorkers form)
{
form.ShowDialog();
}
}
private void roomToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormRooms));
if (service is FormRooms form)
{
form.ShowDialog();
}
}
private void buttonCreateBooking_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormBooking));
if (service is FormBooking form)
{
form.ShowDialog();
LoadData();
}
}
private void buttonTakeBookingInWork_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try
{
var operationResult = _logic.TakeBookingInWork(new BookingBindingModel
{
Id = id,
Status = Enum.Parse<HotelDataModels.Enums.AcceptanceStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonBookingReady_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try
{
var operationResult = _logic.FinishBooking(new BookingBindingModel
{
Id = id,
Status = Enum.Parse<HotelDataModels.Enums.AcceptanceStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Доп информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void buttonIssuedBooking_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
try
{
var operationResult = _logic.DeliveryBooking(new BookingBindingModel
{
Id = id,
Status = Enum.Parse<HotelDataModels.Enums.AcceptanceStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
});
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Доп информация в логах.");
}
LoadData();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
DateTime start = DateTime.Now;
var elementR = _logicR.ReadElement(new RoomSearchModel
{
Number = 1
});
var elementC = _logicC.ReadElement(new ClientSearchModel
{
Name = "Игооооорь"
});
for (int i = 0; i < 1000; i++)
{
var operationResult = _logic.Create(new BookingBindingModel
{
RoomId = elementR?.Id ?? 0,
ClientId = elementC?.Id ?? 0,
ArrivalDate = DateTime.Now,
DepartureDate = DateTime.Now,
NumberHoursSpent = 5,
Status = HotelDataModels.Enums.AcceptanceStatus.Неизвестен,
TotalCost =123
});
}
DateTime stop = DateTime.Now;
LoadData();
MessageBox.Show((stop - start).Milliseconds.ToString(), "Test", MessageBoxButtons.OK);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
DateTime start = DateTime.Now;
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
var element = _logic.ReadElement(new BookingSearchModel
{
Id = id
});
for (int i = id; i < id + 1000; i++)
{
var operationResult = _logic.Delete(new BookingBindingModel
{
Id = i,
});
}
DateTime stop = DateTime.Now;
LoadData();
MessageBox.Show((stop - start).Milliseconds.ToString(), "Test", MessageBoxButtons.OK);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private void button3_Click(object sender, EventArgs e)
{
try
{
DateTime start = DateTime.Now;
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
var element = _logic.ReadElement(new BookingSearchModel
{
Id = id
});
var elementR = _logicR.ReadElement(new RoomSearchModel
{
Number = 1
});
var elementC = _logicC.ReadElement(new ClientSearchModel
{
Name = "Игооооорь"
});
for (int i = id; i < id + 1000; i++)
{
var operationResult = _logic.Update(new BookingBindingModel
{
RoomId = elementR?.Id ?? 0,
ClientId = elementC?.Id ?? 0,
ArrivalDate = DateTime.Now,
DepartureDate = DateTime.Now,
NumberHoursSpent = 5,
Status = HotelDataModels.Enums.AcceptanceStatus.Неизвестен,
TotalCost = 100
});
}
DateTime stop = DateTime.Now;
LoadData();
MessageBox.Show((stop - start).Milliseconds.ToString(), "Test", MessageBoxButtons.OK);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}