PIbd-23_Firsov_KA_SUBD/Hotel/HotelView/FormMain.cs
2024-05-30 13:12:02 +04:00

228 lines
8.0 KiB
C#

using HotelAbstractions.Logic;
using HotelAbstractions.Models;
using HotelMongoDB;
namespace HotelView
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
}
private void HotelToolStrip_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormHotel));
if (service is FormHotel form)
{
form.ShowDialog();
}
}
private void RoomToolStrip_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormRoom));
if (service is FormRoom form)
{
form.ShowDialog();
}
}
private void ReservationToolStrip_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormReservation));
if (service is FormReservation form)
{
form.ShowDialog();
}
}
private void GuestToolStrip_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormGuest));
if (service is FormGuest form)
{
form.ShowDialog();
}
}
private void ServiceToolStrip_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormService));
if (service is FormService form)
{
form.ShowDialog();
}
}
private void ServiceCheckToolStrip_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormServiceCheck));
if (service is FormServiceCheck form)
{
form.ShowDialog();
}
}
private void add1000ToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(IHotelLogic));
if (service is IHotelLogic hotelLogic)
{
DateTime startTime = DateTime.Now;
for (int i = 0; i < 1000; i++)
{
Hotel hotel = new()
{
Id = i + 1000,
HotelName = "Название гостиницы " + i,
Address = "Адрес " + i,
CountStar = i,
CountRoom = i
};
hotelLogic.CreateId(hotel);
}
DateTime endTime = DateTime.Now;
labelTest.Text = $"Добавление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
}
}
private void get1000ToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(IHotelLogic));
if (service is IHotelLogic hotelLogic)
{
DateTime startTime = DateTime.Now;
for (int i =0; i < 1000; i++)
hotelLogic.Get(i + 1000);
DateTime endTime = DateTime.Now;
labelTest.Text = $"Получение 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
}
}
private void update1000ToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(IHotelLogic));
if (service is IHotelLogic hoteLogic)
{
DateTime startTime = DateTime.Now;
for (int i = 0; i < 1000; i++)
{
Hotel hotel = new()
{
Id = i + 1000,
HotelName = "Название гостиницы " + i + 2000,
Address = "Адрес " + i + 2000,
CountStar = i + 2000,
CountRoom = i + 2000
};
hoteLogic.Update(hotel);
}
DateTime endTime = DateTime.Now;
labelTest.Text = $"Обновление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
}
}
private void delete1000ToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(IHotelLogic));
if (service is IHotelLogic hoteLogic)
{
DateTime startTime = DateTime.Now;
for (int i = 0; i < 1000; i++)
{
hoteLogic.Delete(i + 1000);
}
DateTime endTime = DateTime.Now;
labelTest.Text = $"Удаление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
}
}
private void updateMongoDBToolStripMenuItem_Click(object sender, EventArgs e)
{
MongoDBImplement implementationMongoDB = new();
// Очищаем все¸
foreach (var it in implementationMongoDB.GetServiceChecks())
implementationMongoDB.DeleteServiceCheck(it.Id);
foreach (var it in implementationMongoDB.GetReservations())
implementationMongoDB.DeleteReservation(it.Id);
foreach (var it in implementationMongoDB.GetRooms())
implementationMongoDB.DeleteRoom(it.Id);
foreach (var it in implementationMongoDB.GetGuests())
implementationMongoDB.DeleteGuest(it.Id);
foreach (var it in implementationMongoDB.GetHotels())
implementationMongoDB.DeleteHotel(it.Id);
foreach (var it in implementationMongoDB.GetServices())
implementationMongoDB.DeleteService(it.Id);
foreach (var it in implementationMongoDB.GetSequence())
implementationMongoDB.DeleteSequence(it.Id);
// скачиваем из постгреса
List<Hotel> listHotel = null;
List<Guest> listGuest = null;
List<Service> listService = null;
List<Room> listRoom = null;
List<Reservation> listReservation = null;
List<ServiceCheck> listServiceCheck = null;
var service = Program.ServiceProvider?.GetService(typeof(IHotelLogic));
if (service is IHotelLogic hotelLogic)
listHotel = hotelLogic.GetAll();
service = Program.ServiceProvider?.GetService(typeof(IGuestLogic));
if (service is IGuestLogic guestLogic)
listGuest = guestLogic.GetAll();
service = Program.ServiceProvider?.GetService(typeof(IServiceLogic));
if (service is IServiceLogic serviceLogic)
listService = serviceLogic.GetAll();
service = Program.ServiceProvider?.GetService(typeof(IRoomLogic));
if (service is IRoomLogic roomLogic)
listRoom = roomLogic.GetAll();
service = Program.ServiceProvider?.GetService(typeof(IReservationLogic));
if (service is IReservationLogic reservationLogic)
listReservation = reservationLogic.GetAll();
service = Program.ServiceProvider?.GetService(typeof(IServiceCheckLogic));
if (service is IServiceCheckLogic serviceCheckLogic)
listServiceCheck = serviceCheckLogic.GetAll();
// вливаем данные монго дб
if (listHotel != null)
foreach (var it in listHotel)
implementationMongoDB.AddHotel(it);
if (listGuest != null)
foreach (var it in listGuest)
implementationMongoDB.AddGuest(it);
if (listService != null)
foreach (var it in listService)
implementationMongoDB.AddService(it);
if (listRoom != null)
foreach (var it in listRoom)
implementationMongoDB.AddRoom(it);
if (listReservation != null)
foreach (var it in listReservation)
implementationMongoDB.AddReservation(it);
if (listServiceCheck != null)
foreach (var it in listServiceCheck)
implementationMongoDB.AddServiceCheck(it);
}
private void MongoDB_CheckedChanged(object sender, EventArgs e)
{
Program.isPostgreSQL = !Program.isPostgreSQL;
}
}
}