Compare commits

..

No commits in common. "labWork#8" and "main" have entirely different histories.

27 changed files with 142 additions and 1137 deletions

View File

@ -3,13 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.9.34728.123 VisualStudioVersion = 17.9.34728.123
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelAbstractions", "HotelAbstractions\HotelAbstractions.csproj", "{AD9AAD7D-EC52-40B5-A34A-8B80AD8618C8}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelAbstractions", "HotelAbstractions\HotelAbstractions.csproj", "{AD9AAD7D-EC52-40B5-A34A-8B80AD8618C8}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelDatabase", "HotelDatabase\HotelDatabase.csproj", "{AB783669-67D3-48DC-9930-D4A59F923E26}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelDatabase", "HotelDatabase\HotelDatabase.csproj", "{AB783669-67D3-48DC-9930-D4A59F923E26}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelView", "HotelView\HotelView.csproj", "{890038F3-3A65-4292-A852-E8536002E78E}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelView", "HotelView\HotelView.csproj", "{890038F3-3A65-4292-A852-E8536002E78E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelMongoDB", "HotelMongoDB\HotelMongoDB.csproj", "{7B1D9606-7E6B-46D9-A3A2-8624969BEE68}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -29,10 +27,6 @@ Global
{890038F3-3A65-4292-A852-E8536002E78E}.Debug|Any CPU.Build.0 = Debug|Any CPU {890038F3-3A65-4292-A852-E8536002E78E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{890038F3-3A65-4292-A852-E8536002E78E}.Release|Any CPU.ActiveCfg = Release|Any CPU {890038F3-3A65-4292-A852-E8536002E78E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{890038F3-3A65-4292-A852-E8536002E78E}.Release|Any CPU.Build.0 = Release|Any CPU {890038F3-3A65-4292-A852-E8536002E78E}.Release|Any CPU.Build.0 = Release|Any CPU
{7B1D9606-7E6B-46D9-A3A2-8624969BEE68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B1D9606-7E6B-46D9-A3A2-8624969BEE68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B1D9606-7E6B-46D9-A3A2-8624969BEE68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B1D9606-7E6B-46D9-A3A2-8624969BEE68}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -1,18 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Bson" Version="2.25.0" />
<PackageReference Include="MongoDB.Driver" Version="2.25.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HotelAbstractions\HotelAbstractions.csproj" />
</ItemGroup>
</Project>

View File

@ -1,35 +0,0 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HotelAbstractions.Models;
namespace HotelMongoDB.Models
{
public class MongoGuest
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string FIO { get; set; } = string.Empty;
public string PhoneNumber { get; set; } = string.Empty;
public string BirthDate { get; set; } = string.Empty;
public string PassportId { get; set; } = string.Empty;
public string Gender { get; set; } = string.Empty;
public MongoGuest(HotelAbstractions.Models.Guest model)
{
FIO = model.FIO;
PhoneNumber = model.PhoneNumber;
BirthDate = model.BirthDate.ToString("d");
PassportId = model.PassportId;
Gender = model.Gender.ToString();
}
public MongoGuest()
{
}
}
}

View File

@ -1,33 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
namespace HotelMongoDB.Models
{
public class MongoHotel
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string HotelName { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public string CountStar { get; set; } = string.Empty;
public string CountRoom { get; set; } = string.Empty;
public MongoHotel(HotelAbstractions.Models.Hotel model)
{
HotelName = model.HotelName;
Address = model.Address;
CountStar = model.CountStar.ToString();
CountRoom = model.CountRoom.ToString();
}
public MongoHotel()
{
}
}
}

View File

@ -1,33 +0,0 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HotelMongoDB.Models
{
public class MongoReservation
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string GuestId { get; set; } = string.Empty;
public string RoomId { get; set; } = string.Empty;
public string ArrivalDate { get; set; } = string.Empty;
public string DepartureDate { get; set; } = string.Empty;
public string Price { get; set; } = string.Empty;
public MongoReservation(HotelAbstractions.Models.Reservation model, string guest_id, string room_id)
{
GuestId = guest_id;
RoomId = room_id;
ArrivalDate = model.ArrivalDate.ToString("d");
DepartureDate = model.DepartureDate.ToString("d");
Price = model.Price.ToString();
}
public MongoReservation()
{
}
}
}

View File

@ -1,41 +0,0 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HotelMongoDB.Models
{
public class MongoRoom
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string HotelId { get; set; } = string.Empty;
public string Category { get; set; } = string.Empty;
public string CountPlace { get; set; } = string.Empty;
public string Flor { get; set; } = string.Empty;
public string Number { get; set; } = string.Empty;
public string Price { get; set; } = string.Empty;
public MongoRoom(HotelAbstractions.Models.Room model, string hotel_id)
{
HotelId = hotel_id;
Category = model.Category;
CountPlace = model.CountPlace.ToString();
Flor = model.Flor.ToString();
Number = model.Number;
Price = model.Price.ToString();
}
public MongoRoom()
{
}
}
}

View File

@ -1,29 +0,0 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HotelMongoDB.Models
{
public class MongoService
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string Name { get; set; } = string.Empty;
public string Price { get; set; } = string.Empty;
public MongoService(HotelAbstractions.Models.Service model)
{
Name = model.Name;
Price = model.Price.ToString();
}
public MongoService()
{
}
}
}

View File

@ -1,31 +0,0 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HotelMongoDB.Models
{
public class MongoServiceCheck
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string ReservationId { get; set; } = string.Empty;
public string ServiceId { get; set; } = string.Empty;
public string Count { get; set; } = string.Empty;
public string DateTime { get; set; } = string.Empty;
public MongoServiceCheck(HotelAbstractions.Models.ServiceCheck model, string reservation_id, string service_id)
{
ReservationId = reservation_id;
ServiceId = service_id;
Count = model.Count.ToString();
DateTime = model.DateTime.ToString();
}
public MongoServiceCheck()
{
}
}
}

View File

@ -1,20 +0,0 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HotelMongoDB.Models
{
public class Sequence
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; } = string.Empty;
public string Sql_id { get; set; } = string.Empty;
public string Mongo_id { get; set; } = string.Empty;
public string Table_name { get; set; } = string.Empty;
}
}

View File

@ -1,240 +0,0 @@
using HotelMongoDB.StorageContracts;
using System.Xml.Linq;
using MongoDB.Driver;
using HotelMongoDB.Models;
using HotelAbstractions.Models;
namespace HotelMongoDB
{
public class MongoDBImplement : StorageModel
{
private IMongoDatabase _database;
private IMongoCollection<MongoHotel> _hotelCollection;
private IMongoCollection<MongoRoom> _roomCollection;
private IMongoCollection<MongoGuest> _guestCollection;
private IMongoCollection<MongoService> _serviceCollection;
private IMongoCollection<MongoReservation> _reservationCollection;
private IMongoCollection<MongoServiceCheck> _serviceCheckCollection;
private IMongoCollection<Sequence> _sequenceCollection;
public MongoDBImplement()
{
var client = new MongoClient("mongodb://localhost:27017");
_database = client.GetDatabase("hoteldb");
_hotelCollection = _database.GetCollection<MongoHotel>("hotel");
_roomCollection = _database.GetCollection<MongoRoom>("room");
_guestCollection = _database.GetCollection<MongoGuest>("guest");
_serviceCollection = _database.GetCollection<MongoService>("service");
_reservationCollection = _database.GetCollection<MongoReservation>("reservation");
_serviceCheckCollection = _database.GetCollection<MongoServiceCheck>("service_check");
_sequenceCollection = _database.GetCollection<Sequence>("sequence");
}
// hotel
public override void AddHotel(Hotel hotel)
{
var art = new MongoHotel(hotel);
_hotelCollection.InsertOne(art);
var seq = new Sequence { Sql_id = hotel.Id.ToString(), Mongo_id = art.Id, Table_name = "hotel" };
_sequenceCollection.InsertOne(seq);
}
public override List<MongoHotel> GetHotels()
{
return _hotelCollection.Find(_ => true).ToList();
}
public override MongoHotel GetHotelById(string id)
{
return _hotelCollection.Find(hotel => hotel.Id == id).FirstOrDefault();
}
public override void UpdateHotel(MongoHotel hotel)
{
_hotelCollection.ReplaceOne(c => c.Id == hotel.Id, hotel);
}
public override void DeleteHotel(string id)
{
_hotelCollection.DeleteOne(hotel => hotel.Id == id);
}
// Room
public override void AddRoom(Room room)
{
string hotel_id = GetMongoId("hotel", room.HotelId.ToString());
var art = new MongoRoom(room, hotel_id);
_roomCollection.InsertOne(art);
var seq = new Sequence { Sql_id = room.Id.ToString(), Mongo_id = art.Id, Table_name = "room" };
_sequenceCollection.InsertOne(seq);
}
public override List<MongoRoom> GetRooms()
{
return _roomCollection.Find(_ => true).ToList();
}
public override MongoRoom GetRoomById(string id)
{
return _roomCollection.Find(room => room.Id == id).FirstOrDefault();
}
public override void UpdateRoom(MongoRoom room)
{
_roomCollection.ReplaceOne(c => c.Id == room.Id, room);
}
public override void DeleteRoom(string id)
{
_roomCollection.DeleteOne(room => room.Id == id);
}
// Guest
public override void AddGuest(Guest guest)
{
var cat = new MongoGuest(guest);
_guestCollection.InsertOne(cat);
var seq = new Sequence { Sql_id = guest.Id.ToString(), Mongo_id = cat.Id, Table_name = "guest" };
_sequenceCollection.InsertOne(seq);
}
public override List<MongoGuest> GetGuests()
{
return _guestCollection.Find(_ => true).ToList();
}
public override MongoGuest GetGuestById(string id)
{
return _guestCollection.Find(guest => guest.Id == id).FirstOrDefault();
}
public override void UpdateGuest(MongoGuest guest)
{
_guestCollection.ReplaceOne(r => r.Id == guest.Id, guest);
}
public override void DeleteGuest(string id)
{
_guestCollection.DeleteOne(guest => guest.Id == id);
}
// Service
public override void AddService(Service service)
{
var cat = new MongoService(service);
_serviceCollection.InsertOne(cat);
var seq = new Sequence { Sql_id = service.Id.ToString(), Mongo_id = cat.Id, Table_name = "service" };
_sequenceCollection.InsertOne(seq);
}
public override List<MongoService> GetServices()
{
return _serviceCollection.Find(_ => true).ToList();
}
public override MongoService GetServiceById(string id)
{
return _serviceCollection.Find(model => model.Id == id).FirstOrDefault();
}
public override void UpdateService(MongoService service)
{
_serviceCollection.ReplaceOne(m => m.Id == service.Id, service);
}
public override void DeleteService(string id)
{
_serviceCollection.DeleteOne(model => model.Id == id);
}
// Reservation
public override void AddReservation(Reservation reservation)
{
string room_id = GetMongoId("room", reservation.RoomId.ToString());
string guest_id = GetMongoId("guest", reservation.GuestId.ToString());
var art = new MongoReservation(reservation, guest_id, room_id);
_reservationCollection.InsertOne(art);
var seq = new Sequence { Sql_id = reservation.Id.ToString(), Mongo_id = art.Id, Table_name = "reservation" };
_sequenceCollection.InsertOne(seq);
}
public override List<MongoReservation> GetReservations()
{
return _reservationCollection.Find(_ => true).ToList();
}
public override MongoReservation GetReservationById(string id)
{
return _reservationCollection.Find(Reservation => Reservation.Id == id).FirstOrDefault();
}
public override void UpdateReservation(MongoReservation Reservation)
{
_reservationCollection.ReplaceOne(b => b.Id == Reservation.Id, Reservation);
}
public override void DeleteReservation(string id)
{
_reservationCollection.DeleteOne(Reservation => Reservation.Id == id);
}
// ServiceCheck
public override void AddServiceCheck(ServiceCheck serviceCheck)
{
string reservation_id = GetMongoId("reservation", serviceCheck.ReservationId.ToString());
string service_id = GetMongoId("service", serviceCheck.ServiceId.ToString());
var art = new MongoServiceCheck(serviceCheck, reservation_id, service_id);
_serviceCheckCollection.InsertOne(art);
var seq = new Sequence { Sql_id = serviceCheck.Id.ToString(), Mongo_id = art.Id, Table_name = "service_check" };
_sequenceCollection.InsertOne(seq);
}
public override List<MongoServiceCheck> GetServiceChecks()
{
return _serviceCheckCollection.Find(_ => true).ToList();
}
public override MongoServiceCheck GetServiceCheckById(string id)
{
return _serviceCheckCollection.Find(ServiceCheck => ServiceCheck.Id == id).FirstOrDefault();
}
public override void UpdateServiceCheck(MongoServiceCheck ServiceCheck)
{
_serviceCheckCollection.ReplaceOne(b => b.Id == ServiceCheck.Id, ServiceCheck);
}
public override void DeleteServiceCheck(string id)
{
_serviceCheckCollection.DeleteOne(ServiceCheck => ServiceCheck.Id == id);
}
public List<Sequence> GetSequence()
{
return _sequenceCollection.Find(_ => true).ToList();
}
public override string GetMongoId(string tableName, string sqlId)
{
var sequence = _sequenceCollection.Find(s => s.Table_name == tableName && s.Sql_id == sqlId).FirstOrDefault();
return sequence?.Mongo_id ?? string.Empty;
}
public void DeleteSequence(string id)
{
_sequenceCollection.DeleteOne(Sequence => Sequence.Id == id);
}
}
}

View File

@ -1,60 +0,0 @@
using HotelAbstractions.Models;
using HotelMongoDB.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HotelMongoDB.StorageContracts
{
public abstract class StorageModel
{
// Hotel
public abstract void AddHotel(Hotel hotel);
public abstract List<MongoHotel> GetHotels();
public abstract MongoHotel GetHotelById(string id);
public abstract void UpdateHotel(MongoHotel hotel);
public abstract void DeleteHotel(string id);
// Room
public abstract void AddRoom(Room room);
public abstract List<MongoRoom> GetRooms();
public abstract MongoRoom GetRoomById(string id);
public abstract void UpdateRoom(MongoRoom room);
public abstract void DeleteRoom(string id);
// Guest
public abstract void AddGuest(Guest guest);
public abstract List<MongoGuest> GetGuests();
public abstract MongoGuest GetGuestById(string id);
public abstract void UpdateGuest(MongoGuest guest);
public abstract void DeleteGuest(string id);
// Service
public abstract void AddService(Service service);
public abstract List<MongoService> GetServices();
public abstract MongoService GetServiceById(string id);
public abstract void UpdateService(MongoService service);
public abstract void DeleteService(string id);
// Reservation
public abstract void AddReservation(Reservation reservation);
public abstract List<MongoReservation> GetReservations();
public abstract MongoReservation GetReservationById(string id);
public abstract void UpdateReservation(MongoReservation reservation);
public abstract void DeleteReservation(string id);
// ServiceCheck
public abstract void AddServiceCheck(ServiceCheck serviceCheck);
public abstract List<MongoServiceCheck> GetServiceChecks();
public abstract MongoServiceCheck GetServiceCheckById(string id);
public abstract void UpdateServiceCheck(MongoServiceCheck serviceCheck);
public abstract void DeleteServiceCheck(string id);
public abstract string GetMongoId(string tableName, string sqlId);
}
}

View File

@ -135,7 +135,6 @@
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
// //

View File

@ -1,7 +1,5 @@
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;
@ -18,12 +16,10 @@ namespace HotelView
public partial class FormGuest : Form public partial class FormGuest : Form
{ {
private readonly IGuestLogic _guestLogic; private readonly IGuestLogic _guestLogic;
private readonly StorageModel _mongoLogic; public FormGuest(IGuestLogic guestLogic)
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)
@ -42,16 +38,14 @@ 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();
@ -72,33 +66,19 @@ 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,
@ -110,25 +90,6 @@ 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();
} }
@ -143,17 +104,9 @@ 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();
} }

View File

@ -54,7 +54,6 @@
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
// //

View File

@ -1,7 +1,5 @@
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,13 +14,11 @@ namespace HotelView
{ {
public partial class FormHotel : Form public partial class FormHotel : Form
{ {
private readonly IHotelLogic _hotelLogic; private readonly IHotelLogic _guestLogic;
private readonly StorageModel _mongoLogic; public FormHotel(IHotelLogic guestLogic)
public FormHotel(IHotelLogic hotelLogic, StorageModel mongoLogic)
{ {
InitializeComponent(); InitializeComponent();
_hotelLogic = hotelLogic; _guestLogic = guestLogic;
_mongoLogic = mongoLogic;
} }
private void FormHotel_Load(object sender, EventArgs e) private void FormHotel_Load(object sender, EventArgs e)
@ -40,16 +36,15 @@ namespace HotelView
CountRoom = (int)numericUpDownCountRoom.Value, CountRoom = (int)numericUpDownCountRoom.Value,
}; };
if (Program.isPostgreSQL) _guestLogic.Create(newHotel);
_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)
@ -67,22 +62,9 @@ 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;
if (Program.isPostgreSQL) foreach (var guest in guests)
{ {
var hotels = _hotelLogic.GetAll(); dataGridView.Rows.Add(guest.Id, guest.HotelName, guest.Address, guest.CountStar, guest.CountRoom);
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);
}
} }
} }
@ -91,42 +73,24 @@ 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 hotelId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
Hotel updatedHotel = new() Hotel updatedHotel = new()
{ {
Id = hotelId, Id = guestId,
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,
}; };
_hotelLogic.Update(updatedHotel); _guestLogic.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("Пожалуйста, выберите hotel, информацию о котором необходимо обновить"); MessageBox.Show("Пожалуйста, выберите гостинницу, информацию о которой необходимо обновить");
} }
} }
@ -135,24 +99,15 @@ 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 hotelId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
_hotelLogic.Delete(hotelId); _guestLogic.Delete(guestId);
}
else
{
string? hotelId = selectedRow.Cells["Id"].Value.ToString();
_mongoLogic.DeleteHotel(hotelId);
}
LoadData(); LoadData();
} }
else else
{ {
MessageBox.Show("Пожалуйста, выберите hotel, информацию о котором необходимо удалить"); MessageBox.Show("Пожалуйста, выберите гостинницу, информацию о которой необходимо удалить");
} }
} }

View File

@ -42,8 +42,6 @@
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();
// //
@ -118,7 +116,7 @@
// //
// замерыВремениToolStripMenuItem // замерыВремениToolStripMenuItem
// //
замерыВремениToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { get1000ToolStripMenuItem, create1000ToolStripMenuItem, update1000ToolStripMenuItem, delete1000ToolStripMenuItem, обновитьMongoDBToolStripMenuItem }); замерыВремениToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { get1000ToolStripMenuItem, create1000ToolStripMenuItem, update1000ToolStripMenuItem, delete1000ToolStripMenuItem });
замерыВремениToolStripMenuItem.Name = амерыВремениToolStripMenuItem"; замерыВремениToolStripMenuItem.Name = амерыВремениToolStripMenuItem";
замерыВремениToolStripMenuItem.Size = new Size(144, 24); замерыВремениToolStripMenuItem.Size = new Size(144, 24);
замерыВремениToolStripMenuItem.Text = "Замеры времени"; замерыВремениToolStripMenuItem.Text = "Замеры времени";
@ -126,55 +124,36 @@
// get1000ToolStripMenuItem // get1000ToolStripMenuItem
// //
get1000ToolStripMenuItem.Name = "get1000ToolStripMenuItem"; get1000ToolStripMenuItem.Name = "get1000ToolStripMenuItem";
get1000ToolStripMenuItem.Size = new Size(233, 26); get1000ToolStripMenuItem.Size = new Size(177, 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(233, 26); create1000ToolStripMenuItem.Size = new Size(177, 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(233, 26); update1000ToolStripMenuItem.Size = new Size(177, 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(233, 26); delete1000ToolStripMenuItem.Size = new Size(177, 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";
@ -200,7 +179,5 @@
private ToolStripMenuItem roomToolStripMenuItem; private ToolStripMenuItem roomToolStripMenuItem;
private ToolStripMenuItem reservationToolStripMenuItem; private ToolStripMenuItem reservationToolStripMenuItem;
private ToolStripMenuItem serviceCheckToolStripMenuItem; private ToolStripMenuItem serviceCheckToolStripMenuItem;
private ToolStripMenuItem обновитьMongoDBToolStripMenuItem;
private CheckBox checkBoxMongo;
} }
} }

View File

@ -1,6 +1,5 @@
using HotelAbstractions.Logic; using HotelAbstractions.Logic;
using HotelAbstractions.Models; using HotelAbstractions.Models;
using HotelMongoDB;
namespace HotelView namespace HotelView
{ {
@ -77,8 +76,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
}; };
@ -86,7 +85,7 @@ namespace HotelView
} }
DateTime endTime = DateTime.Now; DateTime endTime = DateTime.Now;
labelTest.Text = $"Добавление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд"; labelTest.Text = $"Добавление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
} }
} }
@ -100,7 +99,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} миллисекунд";
} }
} }
@ -115,8 +114,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
}; };
@ -124,7 +123,7 @@ namespace HotelView
} }
DateTime endTime = DateTime.Now; DateTime endTime = DateTime.Now;
labelTest.Text = $"Обновление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд"; labelTest.Text = $"Обновление 1000 строк выполнено за {(endTime - startTime).TotalMilliseconds} миллисекунд";
} }
} }
@ -140,88 +139,8 @@ 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;
}
} }
} }

View File

@ -119,7 +119,6 @@
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
// //

View File

@ -1,7 +1,5 @@
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;
@ -19,14 +17,12 @@ 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;
private readonly StorageModel _mongoLogic; public FormReservation(IReservationLogic reservationLogic, IGuestLogic guestLogic, IRoomLogic roomLogic)
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)
@ -45,17 +41,14 @@ 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();
@ -81,25 +74,6 @@ 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";
@ -107,30 +81,11 @@ 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( dataGridView.Rows.Add(reservation.Id, reservation.GuestId, _guestLogic.Get(reservation.GuestId)?.FIO, reservation.RoomId, _roomLogic.Get(reservation.RoomId)?.Id, reservation.ArrivalDate,
reservation.Id, reservation.DepartureDate, reservation.Price);
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";
} }
} }
@ -139,8 +94,6 @@ 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()
@ -154,23 +107,6 @@ 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();
} }
@ -185,18 +121,9 @@ 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();
} }

View File

@ -154,7 +154,6 @@
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
// //

View File

@ -1,7 +1,5 @@
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;
@ -18,13 +16,11 @@ namespace HotelView
{ {
private readonly IRoomLogic _roomLogic; private readonly IRoomLogic _roomLogic;
private readonly IHotelLogic _hotelLogic; private readonly IHotelLogic _hotelLogic;
private readonly StorageModel _mongoLogic; public FormRoom(IRoomLogic roomLogic, IHotelLogic hotelLogic)
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)
@ -43,16 +39,15 @@ 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();
@ -78,36 +73,15 @@ 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";
if (Program.isPostgreSQL) comboBoxHotel.ValueMember = "HotelName";
{
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)
@ -115,8 +89,6 @@ 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()
@ -131,23 +103,6 @@ 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();
} }
@ -162,18 +117,9 @@ 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();
} }

View File

@ -112,7 +112,6 @@
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
// //

View File

@ -1,7 +1,5 @@
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 +15,10 @@ namespace HotelView
public partial class FormService : Form public partial class FormService : Form
{ {
private readonly IServiceLogic _serviceLogic; private readonly IServiceLogic _serviceLogic;
private readonly StorageModel _mongoLogic; public FormService(IServiceLogic serviceLogic)
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)
@ -37,16 +33,15 @@ 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();
@ -61,33 +56,17 @@ 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) foreach (var service in services)
{ {
dataGridView.Rows.Add(service.Id, service.Name, service.Price); 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) 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()
@ -98,21 +77,6 @@ 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();
} }
@ -127,18 +91,9 @@ 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();
} }

View File

@ -151,7 +151,6 @@
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
// //

View File

@ -1,7 +1,5 @@
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;
@ -19,14 +17,12 @@ 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;
private readonly StorageModel _mongoLogic; public FormServiceCheck(IServiceCheckLogic serviceCheckLogic, IReservationLogic reservationLogic, IServiceLogic serviceLogic)
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)
@ -51,6 +47,7 @@ namespace HotelView
private void LoadData() private void LoadData()
{ {
var serviceChecks = _serviceCheckLogic.GetAll();
dataGridView.Rows.Clear(); dataGridView.Rows.Clear();
@ -82,52 +79,14 @@ 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, serviceCheck.ReservationId, _reservationLogic.Get(serviceCheck.ReservationId)?.Id,
_reservationLogic.Get(serviceCheck.ReservationId)?.Id, serviceCheck.ServiceId, _serviceLogic.Get(serviceCheck.ServiceId)?.Name,
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)
@ -135,8 +94,6 @@ 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()
@ -149,22 +106,6 @@ 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();
} }
@ -179,18 +120,9 @@ 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();
} }

View File

@ -16,7 +16,6 @@
<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>

View File

@ -3,8 +3,6 @@ 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
{ {
@ -13,8 +11,6 @@ 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>
@ -39,8 +35,6 @@ 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>();