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