laba8 complete
This commit is contained in:
parent
5a820377ca
commit
2d3407051a
1
Hotel/HotelView/FormGuest.Designer.cs
generated
1
Hotel/HotelView/FormGuest.Designer.cs
generated
@ -135,6 +135,7 @@
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(478, 448);
|
||||
dataGridView.TabIndex = 14;
|
||||
dataGridView.CellClick += DataGridView_CellClick;
|
||||
//
|
||||
// comboBox1
|
||||
//
|
||||
|
@ -1,5 +1,7 @@
|
||||
using HotelAbstractions.Logic;
|
||||
using HotelAbstractions.Models;
|
||||
using HotelMongoDB.Models;
|
||||
using HotelMongoDB.StorageContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -16,10 +18,12 @@ namespace HotelView
|
||||
public partial class FormGuest : Form
|
||||
{
|
||||
private readonly IGuestLogic _guestLogic;
|
||||
public FormGuest(IGuestLogic guestLogic)
|
||||
private readonly StorageModel _mongoLogic;
|
||||
public FormGuest(IGuestLogic guestLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_guestLogic = guestLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
private void FormGuest_Load(object sender, EventArgs e)
|
||||
@ -38,14 +42,16 @@ namespace HotelView
|
||||
Gender = (GenderEnum)Enum.Parse(typeof(GenderEnum), comboBox1.SelectedItem.ToString())
|
||||
};
|
||||
|
||||
_guestLogic.Create(newGuest);
|
||||
if (Program.isPostgreSQL)
|
||||
_guestLogic.Create(newGuest);
|
||||
else
|
||||
_mongoLogic.AddGuest(newGuest);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
private void LoadData()
|
||||
{
|
||||
comboBox1.DataSource = Enum.GetValues(typeof(GenderEnum));
|
||||
var guests = _guestLogic.GetAll();
|
||||
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
@ -66,9 +72,22 @@ namespace HotelView
|
||||
dataGridView.Columns["PassportId"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["Gender"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
|
||||
foreach (var guest in guests)
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
dataGridView.Rows.Add(guest.Id, guest.FIO, guest.PhoneNumber, guest.BirthDate, guest.PassportId, guest.Gender);
|
||||
var guests = _guestLogic.GetAll();
|
||||
|
||||
foreach (var guest in guests)
|
||||
{
|
||||
dataGridView.Rows.Add(guest.Id, guest.FIO, guest.PhoneNumber, guest.BirthDate, guest.PassportId, guest.Gender);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var guests = _mongoLogic.GetGuests();
|
||||
foreach (var guest in guests)
|
||||
{
|
||||
dataGridView.Rows.Add(guest.Id, guest.FIO, guest.PhoneNumber, guest.BirthDate, guest.PassportId, guest.Gender);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -77,19 +96,39 @@ namespace HotelView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int guestId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
Guest updatedGuest = new()
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
Id = guestId,
|
||||
FIO = textBoxName.Text,
|
||||
PhoneNumber = textBoxPhone.Text,
|
||||
BirthDate = ToDateOnly(dateTimePicker1.Value),
|
||||
PassportId = textBoxPassport.Text,
|
||||
Gender = (GenderEnum)Enum.Parse(typeof(GenderEnum), comboBox1.SelectedItem.ToString())
|
||||
};
|
||||
int guestId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
Guest updatedGuest = new()
|
||||
{
|
||||
Id = guestId,
|
||||
FIO = textBoxName.Text,
|
||||
PhoneNumber = textBoxPhone.Text,
|
||||
BirthDate = ToDateOnly(dateTimePicker1.Value),
|
||||
PassportId = textBoxPassport.Text,
|
||||
Gender = (GenderEnum)Enum.Parse(typeof(GenderEnum), comboBox1.SelectedItem.ToString())
|
||||
};
|
||||
|
||||
_guestLogic.Update(updatedGuest);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? guestId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
MongoGuest updatedGuest = new()
|
||||
{
|
||||
Id = guestId,
|
||||
FIO = textBoxName.Text,
|
||||
PhoneNumber = textBoxPhone.Text,
|
||||
BirthDate = dateTimePicker1.Value.ToString("d"),
|
||||
PassportId = textBoxPassport.Text,
|
||||
Gender = comboBox1.SelectedItem.ToString()
|
||||
};
|
||||
|
||||
_mongoLogic.UpdateGuest(updatedGuest);
|
||||
}
|
||||
|
||||
|
||||
_guestLogic.Update(updatedGuest);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
@ -104,9 +143,17 @@ namespace HotelView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int guestId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int guestId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_guestLogic.Delete(guestId);
|
||||
_guestLogic.Delete(guestId);
|
||||
} else
|
||||
{
|
||||
string? guestId = selectedRow?.Cells["Id"].Value.ToString();
|
||||
|
||||
_mongoLogic.DeleteGuest(guestId);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
1
Hotel/HotelView/FormHotel.Designer.cs
generated
1
Hotel/HotelView/FormHotel.Designer.cs
generated
@ -54,6 +54,7 @@
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(478, 448);
|
||||
dataGridView.TabIndex = 0;
|
||||
dataGridView.CellClick += DataGridView_CellClick;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
|
@ -1,5 +1,7 @@
|
||||
using HotelAbstractions.Logic;
|
||||
using HotelAbstractions.Models;
|
||||
using HotelMongoDB.Models;
|
||||
using HotelMongoDB.StorageContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -14,11 +16,13 @@ namespace HotelView
|
||||
{
|
||||
public partial class FormHotel : Form
|
||||
{
|
||||
private readonly IHotelLogic _guestLogic;
|
||||
public FormHotel(IHotelLogic guestLogic)
|
||||
private readonly IHotelLogic _hotelLogic;
|
||||
private readonly StorageModel _mongoLogic;
|
||||
public FormHotel(IHotelLogic hotelLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_guestLogic = guestLogic;
|
||||
_hotelLogic = hotelLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
private void FormHotel_Load(object sender, EventArgs e)
|
||||
@ -36,15 +40,16 @@ namespace HotelView
|
||||
CountRoom = (int)numericUpDownCountRoom.Value,
|
||||
};
|
||||
|
||||
_guestLogic.Create(newHotel);
|
||||
if (Program.isPostgreSQL)
|
||||
_hotelLogic.Create(newHotel);
|
||||
else
|
||||
_mongoLogic.AddHotel(newHotel);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
var guests = _guestLogic.GetAll();
|
||||
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
if (dataGridView.ColumnCount == 0)
|
||||
@ -62,9 +67,22 @@ namespace HotelView
|
||||
dataGridView.Columns["CountStar"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["CountRoom"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
|
||||
foreach (var guest in guests)
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
dataGridView.Rows.Add(guest.Id, guest.HotelName, guest.Address, guest.CountStar, guest.CountRoom);
|
||||
var hotels = _hotelLogic.GetAll();
|
||||
|
||||
foreach (var hotel in hotels)
|
||||
{
|
||||
dataGridView.Rows.Add(hotel.Id, hotel.HotelName, hotel.Address, hotel.CountStar, hotel.CountRoom);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var hotels = _mongoLogic.GetHotels();
|
||||
foreach (var hotel in hotels)
|
||||
{
|
||||
dataGridView.Rows.Add(hotel.Id, hotel.HotelName, hotel.Address, hotel.CountStar, hotel.CountRoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,24 +91,42 @@ namespace HotelView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int guestId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
Hotel updatedHotel = new()
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
Id = guestId,
|
||||
HotelName = textBoxName.Text,
|
||||
Address = textBoxAddress.Text,
|
||||
CountStar = (int)numericUpDownCountStar.Value,
|
||||
CountRoom = (int)numericUpDownCountRoom.Value,
|
||||
};
|
||||
int hotelId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_guestLogic.Update(updatedHotel);
|
||||
Hotel updatedHotel = new()
|
||||
{
|
||||
Id = hotelId,
|
||||
HotelName = textBoxName.Text,
|
||||
Address = textBoxAddress.Text,
|
||||
CountStar = (int)numericUpDownCountStar.Value,
|
||||
CountRoom = (int)numericUpDownCountRoom.Value,
|
||||
};
|
||||
|
||||
_hotelLogic.Update(updatedHotel);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? hotelId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
MongoHotel updatedHotel = new()
|
||||
{
|
||||
Id = hotelId,
|
||||
HotelName = textBoxName.Text,
|
||||
Address = textBoxAddress.Text,
|
||||
CountStar = numericUpDownCountStar.Value.ToString(),
|
||||
CountRoom = numericUpDownCountRoom.Value.ToString(),
|
||||
};
|
||||
|
||||
_mongoLogic.UpdateHotel(updatedHotel);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Пожалуйста, выберите гостинницу, информацию о которой необходимо обновить");
|
||||
MessageBox.Show("Пожалуйста, выберите hotel, информацию о котором необходимо обновить");
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,15 +135,24 @@ namespace HotelView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int guestId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int hotelId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_guestLogic.Delete(guestId);
|
||||
_hotelLogic.Delete(hotelId);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? hotelId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
_mongoLogic.DeleteHotel(hotelId);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Пожалуйста, выберите гостинницу, информацию о которой необходимо удалить");
|
||||
MessageBox.Show("Пожалуйста, выберите hotel, информацию о котором необходимо удалить");
|
||||
}
|
||||
}
|
||||
|
||||
|
33
Hotel/HotelView/FormMain.Designer.cs
generated
33
Hotel/HotelView/FormMain.Designer.cs
generated
@ -42,6 +42,8 @@
|
||||
create1000ToolStripMenuItem = new ToolStripMenuItem();
|
||||
update1000ToolStripMenuItem = new ToolStripMenuItem();
|
||||
delete1000ToolStripMenuItem = new ToolStripMenuItem();
|
||||
обновитьMongoDBToolStripMenuItem = new ToolStripMenuItem();
|
||||
checkBoxMongo = new CheckBox();
|
||||
menuStrip3.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -116,7 +118,7 @@
|
||||
//
|
||||
// замерыВремениToolStripMenuItem
|
||||
//
|
||||
замерыВремениToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { get1000ToolStripMenuItem, create1000ToolStripMenuItem, update1000ToolStripMenuItem, delete1000ToolStripMenuItem });
|
||||
замерыВремениToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { get1000ToolStripMenuItem, create1000ToolStripMenuItem, update1000ToolStripMenuItem, delete1000ToolStripMenuItem, обновитьMongoDBToolStripMenuItem });
|
||||
замерыВремениToolStripMenuItem.Name = "замерыВремениToolStripMenuItem";
|
||||
замерыВремениToolStripMenuItem.Size = new Size(144, 24);
|
||||
замерыВремениToolStripMenuItem.Text = "Замеры времени";
|
||||
@ -124,36 +126,55 @@
|
||||
// get1000ToolStripMenuItem
|
||||
//
|
||||
get1000ToolStripMenuItem.Name = "get1000ToolStripMenuItem";
|
||||
get1000ToolStripMenuItem.Size = new Size(177, 26);
|
||||
get1000ToolStripMenuItem.Size = new Size(233, 26);
|
||||
get1000ToolStripMenuItem.Text = "Get 1000";
|
||||
get1000ToolStripMenuItem.Click += get1000ToolStripMenuItem_Click;
|
||||
//
|
||||
// create1000ToolStripMenuItem
|
||||
//
|
||||
create1000ToolStripMenuItem.Name = "create1000ToolStripMenuItem";
|
||||
create1000ToolStripMenuItem.Size = new Size(177, 26);
|
||||
create1000ToolStripMenuItem.Size = new Size(233, 26);
|
||||
create1000ToolStripMenuItem.Text = "Create 1000";
|
||||
create1000ToolStripMenuItem.Click += add1000ToolStripMenuItem_Click;
|
||||
//
|
||||
// update1000ToolStripMenuItem
|
||||
//
|
||||
update1000ToolStripMenuItem.Name = "update1000ToolStripMenuItem";
|
||||
update1000ToolStripMenuItem.Size = new Size(177, 26);
|
||||
update1000ToolStripMenuItem.Size = new Size(233, 26);
|
||||
update1000ToolStripMenuItem.Text = "Update 1000";
|
||||
update1000ToolStripMenuItem.Click += update1000ToolStripMenuItem_Click;
|
||||
//
|
||||
// delete1000ToolStripMenuItem
|
||||
//
|
||||
delete1000ToolStripMenuItem.Name = "delete1000ToolStripMenuItem";
|
||||
delete1000ToolStripMenuItem.Size = new Size(177, 26);
|
||||
delete1000ToolStripMenuItem.Size = new Size(233, 26);
|
||||
delete1000ToolStripMenuItem.Text = "Delete 1000";
|
||||
delete1000ToolStripMenuItem.Click += delete1000ToolStripMenuItem_Click;
|
||||
//
|
||||
// обновитьMongoDBToolStripMenuItem
|
||||
//
|
||||
обновитьMongoDBToolStripMenuItem.Name = "обновитьMongoDBToolStripMenuItem";
|
||||
обновитьMongoDBToolStripMenuItem.Size = new Size(233, 26);
|
||||
обновитьMongoDBToolStripMenuItem.Text = "Обновить MongoDB";
|
||||
обновитьMongoDBToolStripMenuItem.Click += updateMongoDBToolStripMenuItem_Click;
|
||||
//
|
||||
// checkBoxMongo
|
||||
//
|
||||
checkBoxMongo.AutoSize = true;
|
||||
checkBoxMongo.Location = new Point(579, 55);
|
||||
checkBoxMongo.Name = "checkBoxMongo";
|
||||
checkBoxMongo.Size = new Size(198, 24);
|
||||
checkBoxMongo.TabIndex = 8;
|
||||
checkBoxMongo.Text = "Ипользовать MongoDB ";
|
||||
checkBoxMongo.UseVisualStyleBackColor = true;
|
||||
checkBoxMongo.CheckedChanged += MongoDB_CheckedChanged;
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(checkBoxMongo);
|
||||
Controls.Add(labelTest);
|
||||
Controls.Add(menuStrip3);
|
||||
Name = "FormMain";
|
||||
@ -179,5 +200,7 @@
|
||||
private ToolStripMenuItem roomToolStripMenuItem;
|
||||
private ToolStripMenuItem reservationToolStripMenuItem;
|
||||
private ToolStripMenuItem serviceCheckToolStripMenuItem;
|
||||
private ToolStripMenuItem обновитьMongoDBToolStripMenuItem;
|
||||
private CheckBox checkBoxMongo;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
using HotelAbstractions.Logic;
|
||||
using HotelAbstractions.Logic;
|
||||
using HotelAbstractions.Models;
|
||||
using HotelMongoDB;
|
||||
|
||||
namespace HotelView
|
||||
{
|
||||
@ -76,8 +77,8 @@ namespace HotelView
|
||||
Hotel hotel = new()
|
||||
{
|
||||
Id = i + 1000,
|
||||
HotelName = "Название гостиницы " + i,
|
||||
Address = "Адрес " + i,
|
||||
HotelName = "Название гостиницы " + i,
|
||||
Address = "Адрес " + i,
|
||||
CountStar = i,
|
||||
CountRoom = i
|
||||
};
|
||||
@ -85,7 +86,7 @@ namespace HotelView
|
||||
}
|
||||
DateTime endTime = DateTime.Now;
|
||||
|
||||
labelTest.Text = $"Добавление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
|
||||
labelTest.Text = $"Добавление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +100,7 @@ namespace HotelView
|
||||
hotelLogic.Get(i + 1000);
|
||||
DateTime endTime = DateTime.Now;
|
||||
|
||||
labelTest.Text = $"Получение 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
|
||||
labelTest.Text = $"Получение 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
|
||||
}
|
||||
}
|
||||
|
||||
@ -114,8 +115,8 @@ namespace HotelView
|
||||
Hotel hotel = new()
|
||||
{
|
||||
Id = i + 1000,
|
||||
HotelName = "Название гостиницы " + i + 2000,
|
||||
Address = "Адрес " + i + 2000,
|
||||
HotelName = "Название гостиницы " + i + 2000,
|
||||
Address = "Адрес " + i + 2000,
|
||||
CountStar = i + 2000,
|
||||
CountRoom = i + 2000
|
||||
};
|
||||
@ -123,7 +124,7 @@ namespace HotelView
|
||||
}
|
||||
DateTime endTime = DateTime.Now;
|
||||
|
||||
labelTest.Text = $"Обновление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
|
||||
labelTest.Text = $"Обновление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,8 +140,88 @@ namespace HotelView
|
||||
}
|
||||
DateTime endTime = DateTime.Now;
|
||||
|
||||
labelTest.Text = $"Удаление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
1
Hotel/HotelView/FormReservation.Designer.cs
generated
1
Hotel/HotelView/FormReservation.Designer.cs
generated
@ -119,6 +119,7 @@
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(696, 451);
|
||||
dataGridView.TabIndex = 49;
|
||||
dataGridView.CellClick += DataGridView_CellClick;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
|
@ -1,5 +1,7 @@
|
||||
using HotelAbstractions.Logic;
|
||||
using HotelAbstractions.Models;
|
||||
using HotelMongoDB.Models;
|
||||
using HotelMongoDB.StorageContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -17,12 +19,14 @@ namespace HotelView
|
||||
private readonly IReservationLogic _reservationLogic;
|
||||
private readonly IGuestLogic _guestLogic;
|
||||
private readonly IRoomLogic _roomLogic;
|
||||
public FormReservation(IReservationLogic reservationLogic, IGuestLogic guestLogic, IRoomLogic roomLogic)
|
||||
private readonly StorageModel _mongoLogic;
|
||||
public FormReservation(IReservationLogic reservationLogic, IGuestLogic guestLogic, IRoomLogic roomLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_reservationLogic = reservationLogic;
|
||||
_guestLogic = guestLogic;
|
||||
_roomLogic = roomLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
private void FormReservation_Load(object sender, EventArgs e)
|
||||
@ -41,14 +45,17 @@ namespace HotelView
|
||||
Price = (int)numericUpDownPrice.Value,
|
||||
};
|
||||
|
||||
_reservationLogic.Create(newReservation);
|
||||
if (Program.isPostgreSQL)
|
||||
_reservationLogic.Create(newReservation);
|
||||
else
|
||||
_mongoLogic.AddReservation(newReservation);
|
||||
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
var reservations = _reservationLogic.GetAll();
|
||||
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
@ -74,18 +81,56 @@ namespace HotelView
|
||||
dataGridView.Columns["DepartureDate"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
|
||||
dataGridView.Columns["Price"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
|
||||
|
||||
comboBoxGuest.DataSource = _guestLogic.GetAll();
|
||||
comboBoxGuest.DisplayMember = "Guest";
|
||||
comboBoxGuest.ValueMember = "FIO";
|
||||
|
||||
|
||||
comboBoxRoom.DataSource = _roomLogic.GetAll();
|
||||
comboBoxRoom.DisplayMember = "Room";
|
||||
comboBoxRoom.ValueMember = "Id";
|
||||
|
||||
foreach (var reservation in reservations)
|
||||
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
dataGridView.Rows.Add(reservation.Id, reservation.GuestId, _guestLogic.Get(reservation.GuestId)?.FIO, reservation.RoomId, _roomLogic.Get(reservation.RoomId)?.Id, reservation.ArrivalDate,
|
||||
reservation.DepartureDate, reservation.Price);
|
||||
var reservations = _reservationLogic.GetAll();
|
||||
|
||||
foreach (var reservation in reservations)
|
||||
{
|
||||
dataGridView.Rows.Add(reservation.Id,
|
||||
reservation.GuestId,
|
||||
_guestLogic.Get(reservation.GuestId)?.FIO,
|
||||
reservation.RoomId,
|
||||
_roomLogic.Get(reservation.RoomId)?.Id,
|
||||
reservation.ArrivalDate,
|
||||
reservation.DepartureDate,
|
||||
reservation.Price);
|
||||
}
|
||||
comboBoxGuest.DataSource = _guestLogic.GetAll();
|
||||
comboBoxGuest.DisplayMember = "Guest";
|
||||
comboBoxGuest.ValueMember = "FIO";
|
||||
|
||||
comboBoxRoom.DataSource = _roomLogic.GetAll();
|
||||
comboBoxRoom.DisplayMember = "Room";
|
||||
comboBoxRoom.ValueMember = "Id";
|
||||
}
|
||||
else
|
||||
{
|
||||
var reservations = _mongoLogic.GetReservations();
|
||||
|
||||
foreach (var reservation in reservations)
|
||||
{
|
||||
dataGridView.Rows.Add(
|
||||
reservation.Id,
|
||||
reservation.GuestId,
|
||||
_mongoLogic.GetGuestById(reservation.GuestId)?.FIO,
|
||||
reservation.RoomId,
|
||||
_mongoLogic.GetRoomById(reservation.RoomId)?.Id,
|
||||
reservation.ArrivalDate,
|
||||
reservation.DepartureDate,
|
||||
reservation.Price);
|
||||
}
|
||||
comboBoxGuest.DataSource = _mongoLogic.GetGuests();
|
||||
comboBoxGuest.DisplayMember = "Guest";
|
||||
comboBoxGuest.ValueMember = "FIO";
|
||||
|
||||
comboBoxRoom.DataSource = _mongoLogic.GetRooms();
|
||||
comboBoxRoom.DisplayMember = "Room";
|
||||
comboBoxRoom.ValueMember = "Id";
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,19 +139,38 @@ namespace HotelView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int reservationId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
Reservation updatedReservation = new()
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
Id = reservationId,
|
||||
GuestId = ((Guest?)comboBoxGuest.SelectedItem)?.Id ?? 0,
|
||||
RoomId = ((Room?)comboBoxRoom.SelectedItem)?.Id ?? 0,
|
||||
ArrivalDate = ToDateOnly(dateTimePickerArrival.Value),
|
||||
DepartureDate = ToDateOnly(dateTimePickerDeparture.Value),
|
||||
Price = (double)numericUpDownPrice.Value,
|
||||
};
|
||||
int reservationId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_reservationLogic.Update(updatedReservation);
|
||||
Reservation updatedReservation = new()
|
||||
{
|
||||
Id = reservationId,
|
||||
GuestId = ((Guest?)comboBoxGuest.SelectedItem)?.Id ?? 0,
|
||||
RoomId = ((Room?)comboBoxRoom.SelectedItem)?.Id ?? 0,
|
||||
ArrivalDate = ToDateOnly(dateTimePickerArrival.Value),
|
||||
DepartureDate = ToDateOnly(dateTimePickerDeparture.Value),
|
||||
Price = (double)numericUpDownPrice.Value,
|
||||
};
|
||||
|
||||
_reservationLogic.Update(updatedReservation);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? reservationId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
MongoReservation updatedReservation = new()
|
||||
{
|
||||
Id = reservationId,
|
||||
GuestId = _mongoLogic.GetMongoId("Guest", ((Guest?)comboBoxGuest.SelectedItem)?.Id.ToString() ?? String.Empty),
|
||||
RoomId = _mongoLogic.GetMongoId("Room", ((Room?)comboBoxRoom.SelectedItem)?.Id.ToString() ?? String.Empty),
|
||||
ArrivalDate = ToDateOnly(dateTimePickerArrival.Value).ToString(),
|
||||
DepartureDate = ToDateOnly(dateTimePickerDeparture.Value).ToString(),
|
||||
Price = numericUpDownPrice.Value.ToString(),
|
||||
};
|
||||
|
||||
_mongoLogic.UpdateReservation(updatedReservation);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
@ -121,9 +185,18 @@ namespace HotelView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int reservationId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int reservationId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_reservationLogic.Delete(reservationId);
|
||||
_reservationLogic.Delete(reservationId);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? reservationId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
_mongoLogic.DeleteRoom(reservationId);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
1
Hotel/HotelView/FormRoom.Designer.cs
generated
1
Hotel/HotelView/FormRoom.Designer.cs
generated
@ -154,6 +154,7 @@
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(910, 451);
|
||||
dataGridView.TabIndex = 14;
|
||||
dataGridView.CellClick += DataGridView_CellClick;
|
||||
//
|
||||
// labelAuthor
|
||||
//
|
||||
|
@ -1,5 +1,7 @@
|
||||
using HotelAbstractions.Logic;
|
||||
using HotelAbstractions.Models;
|
||||
using HotelMongoDB.Models;
|
||||
using HotelMongoDB.StorageContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -16,11 +18,13 @@ namespace HotelView
|
||||
{
|
||||
private readonly IRoomLogic _roomLogic;
|
||||
private readonly IHotelLogic _hotelLogic;
|
||||
public FormRoom(IRoomLogic roomLogic, IHotelLogic hotelLogic)
|
||||
private readonly StorageModel _mongoLogic;
|
||||
public FormRoom(IRoomLogic roomLogic, IHotelLogic hotelLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_roomLogic = roomLogic;
|
||||
_hotelLogic = hotelLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
private void FormRoom_Load(object sender, EventArgs e)
|
||||
@ -39,15 +43,16 @@ namespace HotelView
|
||||
Number = textBoxNumber.Text,
|
||||
Price = (int)numericUpDownPrice.Value,
|
||||
};
|
||||
|
||||
_roomLogic.Create(newRoom);
|
||||
if (Program.isPostgreSQL)
|
||||
_roomLogic.Create(newRoom);
|
||||
else
|
||||
_mongoLogic.AddRoom(newRoom);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
var rooms = _roomLogic.GetAll();
|
||||
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
@ -73,14 +78,35 @@ namespace HotelView
|
||||
dataGridView.Columns["Number"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
|
||||
dataGridView.Columns["Price"].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
|
||||
|
||||
comboBoxHotel.DataSource = _hotelLogic.GetAll();
|
||||
comboBoxHotel.DisplayMember = "Hotel";
|
||||
comboBoxHotel.ValueMember = "HotelName";
|
||||
|
||||
|
||||
foreach (var room in rooms)
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
dataGridView.Rows.Add(room.Id, room.HotelId, _hotelLogic.Get(room.HotelId)?.HotelName, room.Category, room.CountPlace,
|
||||
room.Flor, room.Number, room.Price);
|
||||
var rooms = _roomLogic.GetAll();
|
||||
|
||||
foreach (var room in rooms)
|
||||
{
|
||||
dataGridView.Rows.Add(room.Id, room.HotelId, _hotelLogic.Get(room.HotelId)?.HotelName, room.Category, room.CountPlace,
|
||||
room.Flor, room.Number, room.Price);
|
||||
}
|
||||
|
||||
comboBoxHotel.DataSource = _hotelLogic.GetAll();
|
||||
comboBoxHotel.DisplayMember = "Hotel";
|
||||
comboBoxHotel.ValueMember = "HotelName";
|
||||
}
|
||||
else
|
||||
{
|
||||
var rooms = _mongoLogic.GetRooms();
|
||||
|
||||
foreach (var room in rooms)
|
||||
{
|
||||
dataGridView.Rows.Add(room.Id, room.HotelId, _mongoLogic.GetHotelById(room.HotelId)?.HotelName, room.Category, room.CountPlace,
|
||||
room.Flor, room.Number, room.Price);
|
||||
}
|
||||
|
||||
comboBoxHotel.DataSource = _mongoLogic.GetHotels();
|
||||
comboBoxHotel.DisplayMember = "Hotel";
|
||||
comboBoxHotel.ValueMember = "HotelName";
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,20 +115,39 @@ namespace HotelView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int roomId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
Room updatedRoom = new()
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
Id = roomId,
|
||||
HotelId = ((Hotel?)comboBoxHotel.SelectedItem)?.Id ?? 0,
|
||||
Category = textBoxCategory.Text,
|
||||
CountPlace = (int)numericUpDownCountPlace.Value,
|
||||
Flor = (int)numericUpFlor.Value,
|
||||
Number = textBoxNumber.Text,
|
||||
Price = (int)numericUpDownPrice.Value,
|
||||
};
|
||||
int roomId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_roomLogic.Update(updatedRoom);
|
||||
Room updatedRoom = new()
|
||||
{
|
||||
Id = roomId,
|
||||
HotelId = ((Hotel?)comboBoxHotel.SelectedItem)?.Id ?? 0,
|
||||
Category = textBoxCategory.Text,
|
||||
CountPlace = (int)numericUpDownCountPlace.Value,
|
||||
Flor = (int)numericUpFlor.Value,
|
||||
Number = textBoxNumber.Text,
|
||||
Price = (int)numericUpDownPrice.Value,
|
||||
};
|
||||
|
||||
_roomLogic.Update(updatedRoom);
|
||||
} else
|
||||
{
|
||||
string? roomId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
MongoRoom updatedRoom = new()
|
||||
{
|
||||
Id = roomId,
|
||||
HotelId = _mongoLogic.GetMongoId("Hotel", ((Hotel?)comboBoxHotel.SelectedItem)?.Id.ToString() ?? String.Empty),
|
||||
Category = textBoxCategory.Text,
|
||||
CountPlace = numericUpDownCountPlace.Value.ToString(),
|
||||
Flor = numericUpFlor.Value.ToString(),
|
||||
Number = textBoxNumber.Text,
|
||||
Price = numericUpDownPrice.Value.ToString(),
|
||||
};
|
||||
|
||||
_mongoLogic.UpdateRoom(updatedRoom);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
@ -117,9 +162,18 @@ namespace HotelView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int roomId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int roomId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_roomLogic.Delete(roomId);
|
||||
_roomLogic.Delete(roomId);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? roomId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
_mongoLogic.DeleteRoom(roomId);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
1
Hotel/HotelView/FormService.Designer.cs
generated
1
Hotel/HotelView/FormService.Designer.cs
generated
@ -112,6 +112,7 @@
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(478, 448);
|
||||
dataGridView.TabIndex = 14;
|
||||
dataGridView.CellClick += DataGridView_CellClick;
|
||||
//
|
||||
// FormService
|
||||
//
|
||||
|
@ -1,5 +1,7 @@
|
||||
using HotelAbstractions.Logic;
|
||||
using HotelAbstractions.Models;
|
||||
using HotelMongoDB.Models;
|
||||
using HotelMongoDB.StorageContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -15,10 +17,12 @@ namespace HotelView
|
||||
public partial class FormService : Form
|
||||
{
|
||||
private readonly IServiceLogic _serviceLogic;
|
||||
public FormService(IServiceLogic serviceLogic)
|
||||
private readonly StorageModel _mongoLogic;
|
||||
public FormService(IServiceLogic serviceLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_serviceLogic = serviceLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
private void FormService_Load(object sender, EventArgs e)
|
||||
@ -33,15 +37,16 @@ namespace HotelView
|
||||
Name = textBoxName.Text,
|
||||
Price = (double)numericUpDownPrice.Value,
|
||||
};
|
||||
|
||||
_serviceLogic.Create(newService);
|
||||
if (Program.isPostgreSQL)
|
||||
_serviceLogic.Create(newService);
|
||||
else
|
||||
_mongoLogic.AddService(newService);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
var services = _serviceLogic.GetAll();
|
||||
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
@ -56,27 +61,58 @@ namespace HotelView
|
||||
dataGridView.Columns["Name"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
dataGridView.Columns["Price"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
|
||||
foreach (var service in services)
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
dataGridView.Rows.Add(service.Id, service.Name, service.Price);
|
||||
var services = _serviceLogic.GetAll();
|
||||
foreach (var service in services)
|
||||
{
|
||||
dataGridView.Rows.Add(service.Id, service.Name, service.Price);
|
||||
}
|
||||
} else
|
||||
{
|
||||
var services = _mongoLogic.GetServices();
|
||||
foreach (var service in services)
|
||||
{
|
||||
dataGridView.Rows.Add(service.Id, service.Name, service.Price);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int serviceId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
Service updatedService = new()
|
||||
if (!Program.isPostgreSQL)
|
||||
{
|
||||
Id = serviceId,
|
||||
Name = textBoxName.Text,
|
||||
Price = (double)numericUpDownPrice.Value
|
||||
};
|
||||
int serviceId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
Service updatedService = new()
|
||||
{
|
||||
Id = serviceId,
|
||||
Name = textBoxName.Text,
|
||||
Price = (double)numericUpDownPrice.Value
|
||||
};
|
||||
|
||||
_serviceLogic.Update(updatedService);
|
||||
} else
|
||||
{
|
||||
string? serviceId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
MongoService mongoService = new()
|
||||
{
|
||||
Id = serviceId,
|
||||
Name = textBoxName.Text,
|
||||
Price = numericUpDownPrice.Value.ToString()
|
||||
};
|
||||
|
||||
_mongoLogic.UpdateService(mongoService);
|
||||
|
||||
}
|
||||
|
||||
_serviceLogic.Update(updatedService);
|
||||
|
||||
LoadData();
|
||||
}
|
||||
@ -91,9 +127,18 @@ namespace HotelView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int serviceId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
if (!Program.isPostgreSQL)
|
||||
{
|
||||
int serviceId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_serviceLogic.Delete(serviceId);
|
||||
_serviceLogic.Delete(serviceId);
|
||||
} else
|
||||
{
|
||||
string? serviceId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
_mongoLogic.DeleteService(serviceId);
|
||||
}
|
||||
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
1
Hotel/HotelView/FormServiceCheck.Designer.cs
generated
1
Hotel/HotelView/FormServiceCheck.Designer.cs
generated
@ -151,6 +151,7 @@
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.Size = new Size(609, 446);
|
||||
dataGridView.TabIndex = 63;
|
||||
dataGridView.CellClick += DataGridView_CellClick;
|
||||
//
|
||||
// FormServiceCheck
|
||||
//
|
||||
|
@ -1,5 +1,7 @@
|
||||
using HotelAbstractions.Logic;
|
||||
using HotelAbstractions.Models;
|
||||
using HotelMongoDB.Models;
|
||||
using HotelMongoDB.StorageContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -17,12 +19,14 @@ namespace HotelView
|
||||
private readonly IServiceCheckLogic _serviceCheckLogic;
|
||||
private readonly IReservationLogic _reservationLogic;
|
||||
private readonly IServiceLogic _serviceLogic;
|
||||
public FormServiceCheck(IServiceCheckLogic serviceCheckLogic, IReservationLogic reservationLogic, IServiceLogic serviceLogic)
|
||||
private readonly StorageModel _mongoLogic;
|
||||
public FormServiceCheck(IServiceCheckLogic serviceCheckLogic, IReservationLogic reservationLogic, IServiceLogic serviceLogic, StorageModel mongoLogic)
|
||||
{
|
||||
InitializeComponent();
|
||||
_serviceCheckLogic = serviceCheckLogic;
|
||||
_reservationLogic = reservationLogic;
|
||||
_serviceLogic = serviceLogic;
|
||||
_mongoLogic = mongoLogic;
|
||||
}
|
||||
|
||||
private void FormServiceCheck_Load(object sender, EventArgs e)
|
||||
@ -47,7 +51,6 @@ namespace HotelView
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
var serviceChecks = _serviceCheckLogic.GetAll();
|
||||
|
||||
dataGridView.Rows.Clear();
|
||||
|
||||
@ -79,13 +82,51 @@ namespace HotelView
|
||||
comboBoxService.DisplayMember = "Service";
|
||||
comboBoxService.ValueMember = "Name";
|
||||
|
||||
foreach (var serviceCheck in serviceChecks)
|
||||
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
dataGridView.Rows.Add(serviceCheck.Id,
|
||||
serviceCheck.ReservationId, _reservationLogic.Get(serviceCheck.ReservationId)?.Id,
|
||||
serviceCheck.ServiceId, _serviceLogic.Get(serviceCheck.ServiceId)?.Name,
|
||||
serviceCheck.Count,
|
||||
serviceCheck.DateTime);
|
||||
var serviceChecks = _serviceCheckLogic.GetAll();
|
||||
|
||||
foreach (var serviceCheck in serviceChecks)
|
||||
{
|
||||
dataGridView.Rows.Add(serviceCheck.Id,
|
||||
serviceCheck.ReservationId,
|
||||
_reservationLogic.Get(serviceCheck.ReservationId)?.Id,
|
||||
serviceCheck.ServiceId,
|
||||
_serviceLogic.Get(serviceCheck.ServiceId)?.Name,
|
||||
serviceCheck.Count,
|
||||
serviceCheck.DateTime);
|
||||
}
|
||||
comboBoxReservation.DataSource = _reservationLogic.GetAll();
|
||||
comboBoxReservation.DisplayMember = "Reservation";
|
||||
comboBoxReservation.ValueMember = "Id";
|
||||
|
||||
comboBoxService.DataSource = _serviceLogic.GetAll();
|
||||
comboBoxService.DisplayMember = "Service";
|
||||
comboBoxService.ValueMember = "Name";
|
||||
}
|
||||
else
|
||||
{
|
||||
var serviceChecks = _mongoLogic.GetServiceChecks();
|
||||
|
||||
foreach (var serviceCheck in serviceChecks)
|
||||
{
|
||||
dataGridView.Rows.Add(
|
||||
serviceCheck.Id,
|
||||
serviceCheck.ReservationId,
|
||||
_mongoLogic.GetReservationById(serviceCheck.ReservationId)?.Id,
|
||||
serviceCheck.ServiceId,
|
||||
_mongoLogic.GetServiceById(serviceCheck.ServiceId)?.Name,
|
||||
serviceCheck.Count,
|
||||
serviceCheck.DateTime);
|
||||
}
|
||||
comboBoxReservation.DataSource = _mongoLogic.GetReservations();
|
||||
comboBoxReservation.DisplayMember = "Reservation";
|
||||
comboBoxReservation.ValueMember = "Id";
|
||||
|
||||
comboBoxService.DataSource = _mongoLogic.GetServices();
|
||||
comboBoxService.DisplayMember = "Service";
|
||||
comboBoxService.ValueMember = "Name";
|
||||
}
|
||||
}
|
||||
|
||||
@ -94,18 +135,36 @@ namespace HotelView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int serviceCheckId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
ServiceCheck updatedServiceCheck = new()
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
Id = serviceCheckId,
|
||||
ReservationId = ((Reservation?)comboBoxReservation.SelectedItem)?.Id ?? 0,
|
||||
ServiceId = ((Service?)comboBoxService.SelectedItem)?.Id ?? 0,
|
||||
Count = (int)numericUpDownCount.Value,
|
||||
DateTime = dateTimePicker.Value,
|
||||
};
|
||||
int serviceCheckId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_serviceCheckLogic.Update(updatedServiceCheck);
|
||||
ServiceCheck updatedServiceCheck = new()
|
||||
{
|
||||
Id = serviceCheckId,
|
||||
ReservationId = ((Reservation?)comboBoxReservation.SelectedItem)?.Id ?? 0,
|
||||
ServiceId = ((Service?)comboBoxService.SelectedItem)?.Id ?? 0,
|
||||
Count = (int)numericUpDownCount.Value,
|
||||
DateTime = dateTimePicker.Value,
|
||||
};
|
||||
|
||||
_serviceCheckLogic.Update(updatedServiceCheck);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? serviceCheckId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
MongoServiceCheck updatedServiceCheck = new()
|
||||
{
|
||||
Id = serviceCheckId,
|
||||
ReservationId = _mongoLogic.GetMongoId("Reservation", ((Reservation?)comboBoxReservation.SelectedItem)?.Id.ToString() ?? String.Empty),
|
||||
ServiceId = _mongoLogic.GetMongoId("Service", ((Service?)comboBoxService.SelectedItem)?.Id.ToString() ?? String.Empty),
|
||||
Count = numericUpDownCount.Value.ToString(),
|
||||
DateTime = dateTimePicker.Value.ToString(),
|
||||
};
|
||||
|
||||
_mongoLogic.UpdateServiceCheck(updatedServiceCheck);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
@ -120,9 +179,18 @@ namespace HotelView
|
||||
if (dataGridView.SelectedRows.Count > 0)
|
||||
{
|
||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||
int serviceCheckId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
if (Program.isPostgreSQL)
|
||||
{
|
||||
int serviceCheckId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||
|
||||
_serviceCheckLogic.Delete(serviceCheckId);
|
||||
_serviceCheckLogic.Delete(serviceCheckId);
|
||||
}
|
||||
else
|
||||
{
|
||||
string? serviceCheckId = selectedRow.Cells["Id"].Value.ToString();
|
||||
|
||||
_mongoLogic.DeleteServiceCheck(serviceCheckId);
|
||||
}
|
||||
|
||||
LoadData();
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HotelAbstractions\HotelAbstractions.csproj" />
|
||||
<ProjectReference Include="..\HotelDatabase\HotelDatabase.csproj" />
|
||||
<ProjectReference Include="..\HotelMongoDB\HotelMongoDB.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -3,6 +3,8 @@ using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using HotelAbstractions.Logic;
|
||||
using HotelDatabase.Implement;
|
||||
using HotelMongoDB.StorageContracts;
|
||||
using HotelMongoDB;
|
||||
|
||||
namespace HotelView
|
||||
{
|
||||
@ -11,6 +13,8 @@ namespace HotelView
|
||||
private static ServiceProvider? _serviceProvider;
|
||||
public static ServiceProvider? ServiceProvider => _serviceProvider;
|
||||
|
||||
public static bool isPostgreSQL = true;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
@ -35,6 +39,8 @@ namespace HotelView
|
||||
services.AddTransient<IServiceCheckLogic, ServiceCheckImplement>();
|
||||
services.AddTransient<IServiceLogic, ServiceImplement>();
|
||||
|
||||
services.AddTransient<StorageModel, MongoDBImplement>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormHotel>();
|
||||
services.AddTransient<FormGuest>();
|
||||
|
Loading…
Reference in New Issue
Block a user