Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
2d3407051a | ||
|
5a820377ca |
@ -3,11 +3,13 @@ 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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelAbstractions", "HotelAbstractions\HotelAbstractions.csproj", "{AD9AAD7D-EC52-40B5-A34A-8B80AD8618C8}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelAbstractions", "HotelAbstractions\HotelAbstractions.csproj", "{AD9AAD7D-EC52-40B5-A34A-8B80AD8618C8}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelDatabase", "HotelDatabase\HotelDatabase.csproj", "{AB783669-67D3-48DC-9930-D4A59F923E26}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HotelDatabase", "HotelDatabase\HotelDatabase.csproj", "{AB783669-67D3-48DC-9930-D4A59F923E26}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HotelView", "HotelView\HotelView.csproj", "{890038F3-3A65-4292-A852-E8536002E78E}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "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
|
||||||
@ -27,6 +29,10 @@ 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
|
||||||
|
18
Hotel/HotelMongoDB/HotelMongoDB.csproj
Normal file
18
Hotel/HotelMongoDB/HotelMongoDB.csproj
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<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>
|
35
Hotel/HotelMongoDB/Models/MongoGuest.cs
Normal file
35
Hotel/HotelMongoDB/Models/MongoGuest.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
Hotel/HotelMongoDB/Models/MongoHotel.cs
Normal file
33
Hotel/HotelMongoDB/Models/MongoHotel.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
33
Hotel/HotelMongoDB/Models/MongoReservation.cs
Normal file
33
Hotel/HotelMongoDB/Models/MongoReservation.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
41
Hotel/HotelMongoDB/Models/MongoRoom.cs
Normal file
41
Hotel/HotelMongoDB/Models/MongoRoom.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
29
Hotel/HotelMongoDB/Models/MongoService.cs
Normal file
29
Hotel/HotelMongoDB/Models/MongoService.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
Hotel/HotelMongoDB/Models/MongoServiceCheck.cs
Normal file
31
Hotel/HotelMongoDB/Models/MongoServiceCheck.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
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()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
Hotel/HotelMongoDB/Models/Sequence.cs
Normal file
20
Hotel/HotelMongoDB/Models/Sequence.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
240
Hotel/HotelMongoDB/MongoDBImplement.cs
Normal file
240
Hotel/HotelMongoDB/MongoDBImplement.cs
Normal file
@ -0,0 +1,240 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
Hotel/HotelMongoDB/StorageContracts/StorageModel.cs
Normal file
60
Hotel/HotelMongoDB/StorageContracts/StorageModel.cs
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
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())
|
||||||
};
|
};
|
||||||
|
|
||||||
_guestLogic.Create(newGuest);
|
if (Program.isPostgreSQL)
|
||||||
|
_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,9 +72,22 @@ 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;
|
||||||
|
|
||||||
foreach (var guest in guests)
|
if (Program.isPostgreSQL)
|
||||||
{
|
{
|
||||||
dataGridView.Rows.Add(guest.Id, guest.FIO, guest.PhoneNumber, guest.BirthDate, guest.PassportId, guest.Gender);
|
var guests = _guestLogic.GetAll();
|
||||||
|
|
||||||
|
foreach (var guest in guests)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(guest.Id, guest.FIO, guest.PhoneNumber, guest.BirthDate, guest.PassportId, guest.Gender);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var guests = _mongoLogic.GetGuests();
|
||||||
|
foreach (var guest in guests)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(guest.Id, guest.FIO, guest.PhoneNumber, guest.BirthDate, guest.PassportId, guest.Gender);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,19 +96,39 @@ namespace HotelView
|
|||||||
if (dataGridView.SelectedRows.Count > 0)
|
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)
|
||||||
|
|
||||||
Guest updatedGuest = new()
|
|
||||||
{
|
{
|
||||||
Id = guestId,
|
int guestId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
FIO = textBoxName.Text,
|
Guest updatedGuest = new()
|
||||||
PhoneNumber = textBoxPhone.Text,
|
{
|
||||||
BirthDate = ToDateOnly(dateTimePicker1.Value),
|
Id = guestId,
|
||||||
PassportId = textBoxPassport.Text,
|
FIO = textBoxName.Text,
|
||||||
Gender = (GenderEnum)Enum.Parse(typeof(GenderEnum), comboBox1.SelectedItem.ToString())
|
PhoneNumber = textBoxPhone.Text,
|
||||||
};
|
BirthDate = ToDateOnly(dateTimePicker1.Value),
|
||||||
|
PassportId = textBoxPassport.Text,
|
||||||
|
Gender = (GenderEnum)Enum.Parse(typeof(GenderEnum), comboBox1.SelectedItem.ToString())
|
||||||
|
};
|
||||||
|
|
||||||
|
_guestLogic.Update(updatedGuest);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string? guestId = selectedRow.Cells["Id"].Value.ToString();
|
||||||
|
|
||||||
|
MongoGuest updatedGuest = new()
|
||||||
|
{
|
||||||
|
Id = guestId,
|
||||||
|
FIO = textBoxName.Text,
|
||||||
|
PhoneNumber = textBoxPhone.Text,
|
||||||
|
BirthDate = dateTimePicker1.Value.ToString("d"),
|
||||||
|
PassportId = textBoxPassport.Text,
|
||||||
|
Gender = comboBox1.SelectedItem.ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
_mongoLogic.UpdateGuest(updatedGuest);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
_guestLogic.Update(updatedGuest);
|
|
||||||
|
|
||||||
LoadData();
|
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];
|
||||||
int guestId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
if (Program.isPostgreSQL)
|
||||||
|
{
|
||||||
|
int guestId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
_guestLogic.Delete(guestId);
|
_guestLogic.Delete(guestId);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
string? guestId = selectedRow?.Cells["Id"].Value.ToString();
|
||||||
|
|
||||||
|
_mongoLogic.DeleteGuest(guestId);
|
||||||
|
}
|
||||||
|
|
||||||
LoadData();
|
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)
|
||||||
|
|
||||||
Hotel updatedHotel = new()
|
|
||||||
{
|
{
|
||||||
Id = guestId,
|
int hotelId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
HotelName = textBoxName.Text,
|
|
||||||
Address = textBoxAddress.Text,
|
|
||||||
CountStar = (int)numericUpDownCountStar.Value,
|
|
||||||
CountRoom = (int)numericUpDownCountRoom.Value,
|
|
||||||
};
|
|
||||||
|
|
||||||
_guestLogic.Update(updatedHotel);
|
Hotel updatedHotel = new()
|
||||||
|
{
|
||||||
|
Id = hotelId,
|
||||||
|
HotelName = textBoxName.Text,
|
||||||
|
Address = textBoxAddress.Text,
|
||||||
|
CountStar = (int)numericUpDownCountStar.Value,
|
||||||
|
CountRoom = (int)numericUpDownCountRoom.Value,
|
||||||
|
};
|
||||||
|
|
||||||
|
_hotelLogic.Update(updatedHotel);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string? hotelId = selectedRow.Cells["Id"].Value.ToString();
|
||||||
|
|
||||||
|
MongoHotel updatedHotel = new()
|
||||||
|
{
|
||||||
|
Id = hotelId,
|
||||||
|
HotelName = textBoxName.Text,
|
||||||
|
Address = textBoxAddress.Text,
|
||||||
|
CountStar = numericUpDownCountStar.Value.ToString(),
|
||||||
|
CountRoom = numericUpDownCountRoom.Value.ToString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
_mongoLogic.UpdateHotel(updatedHotel);
|
||||||
|
}
|
||||||
|
|
||||||
LoadData();
|
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,
|
||||||
};
|
};
|
||||||
|
|
||||||
_reservationLogic.Create(newReservation);
|
if (Program.isPostgreSQL)
|
||||||
|
_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,18 +81,56 @@ 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;
|
||||||
|
|
||||||
comboBoxGuest.DataSource = _guestLogic.GetAll();
|
|
||||||
comboBoxGuest.DisplayMember = "Guest";
|
|
||||||
comboBoxGuest.ValueMember = "FIO";
|
|
||||||
|
|
||||||
comboBoxRoom.DataSource = _roomLogic.GetAll();
|
|
||||||
comboBoxRoom.DisplayMember = "Room";
|
|
||||||
comboBoxRoom.ValueMember = "Id";
|
|
||||||
|
|
||||||
foreach (var reservation in reservations)
|
|
||||||
|
if (Program.isPostgreSQL)
|
||||||
{
|
{
|
||||||
dataGridView.Rows.Add(reservation.Id, reservation.GuestId, _guestLogic.Get(reservation.GuestId)?.FIO, reservation.RoomId, _roomLogic.Get(reservation.RoomId)?.Id, reservation.ArrivalDate,
|
var reservations = _reservationLogic.GetAll();
|
||||||
reservation.DepartureDate, reservation.Price);
|
|
||||||
|
foreach (var reservation in reservations)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(reservation.Id,
|
||||||
|
reservation.GuestId,
|
||||||
|
_guestLogic.Get(reservation.GuestId)?.FIO,
|
||||||
|
reservation.RoomId,
|
||||||
|
_roomLogic.Get(reservation.RoomId)?.Id,
|
||||||
|
reservation.ArrivalDate,
|
||||||
|
reservation.DepartureDate,
|
||||||
|
reservation.Price);
|
||||||
|
}
|
||||||
|
comboBoxGuest.DataSource = _guestLogic.GetAll();
|
||||||
|
comboBoxGuest.DisplayMember = "Guest";
|
||||||
|
comboBoxGuest.ValueMember = "FIO";
|
||||||
|
|
||||||
|
comboBoxRoom.DataSource = _roomLogic.GetAll();
|
||||||
|
comboBoxRoom.DisplayMember = "Room";
|
||||||
|
comboBoxRoom.ValueMember = "Id";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var reservations = _mongoLogic.GetReservations();
|
||||||
|
|
||||||
|
foreach (var reservation in reservations)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(
|
||||||
|
reservation.Id,
|
||||||
|
reservation.GuestId,
|
||||||
|
_mongoLogic.GetGuestById(reservation.GuestId)?.FIO,
|
||||||
|
reservation.RoomId,
|
||||||
|
_mongoLogic.GetRoomById(reservation.RoomId)?.Id,
|
||||||
|
reservation.ArrivalDate,
|
||||||
|
reservation.DepartureDate,
|
||||||
|
reservation.Price);
|
||||||
|
}
|
||||||
|
comboBoxGuest.DataSource = _mongoLogic.GetGuests();
|
||||||
|
comboBoxGuest.DisplayMember = "Guest";
|
||||||
|
comboBoxGuest.ValueMember = "FIO";
|
||||||
|
|
||||||
|
comboBoxRoom.DataSource = _mongoLogic.GetRooms();
|
||||||
|
comboBoxRoom.DisplayMember = "Room";
|
||||||
|
comboBoxRoom.ValueMember = "Id";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,19 +139,38 @@ namespace HotelView
|
|||||||
if (dataGridView.SelectedRows.Count > 0)
|
if (dataGridView.SelectedRows.Count > 0)
|
||||||
{
|
{
|
||||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||||
int reservationId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
if (Program.isPostgreSQL)
|
||||||
|
|
||||||
Reservation updatedReservation = new()
|
|
||||||
{
|
{
|
||||||
Id = reservationId,
|
int reservationId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
GuestId = ((Guest?)comboBoxGuest.SelectedItem)?.Id ?? 0,
|
|
||||||
RoomId = ((Room?)comboBoxRoom.SelectedItem)?.Id ?? 0,
|
|
||||||
ArrivalDate = ToDateOnly(dateTimePickerArrival.Value),
|
|
||||||
DepartureDate = ToDateOnly(dateTimePickerDeparture.Value),
|
|
||||||
Price = (double)numericUpDownPrice.Value,
|
|
||||||
};
|
|
||||||
|
|
||||||
_reservationLogic.Update(updatedReservation);
|
Reservation updatedReservation = new()
|
||||||
|
{
|
||||||
|
Id = reservationId,
|
||||||
|
GuestId = ((Guest?)comboBoxGuest.SelectedItem)?.Id ?? 0,
|
||||||
|
RoomId = ((Room?)comboBoxRoom.SelectedItem)?.Id ?? 0,
|
||||||
|
ArrivalDate = ToDateOnly(dateTimePickerArrival.Value),
|
||||||
|
DepartureDate = ToDateOnly(dateTimePickerDeparture.Value),
|
||||||
|
Price = (double)numericUpDownPrice.Value,
|
||||||
|
};
|
||||||
|
|
||||||
|
_reservationLogic.Update(updatedReservation);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string? reservationId = selectedRow.Cells["Id"].Value.ToString();
|
||||||
|
|
||||||
|
MongoReservation updatedReservation = new()
|
||||||
|
{
|
||||||
|
Id = reservationId,
|
||||||
|
GuestId = _mongoLogic.GetMongoId("Guest", ((Guest?)comboBoxGuest.SelectedItem)?.Id.ToString() ?? String.Empty),
|
||||||
|
RoomId = _mongoLogic.GetMongoId("Room", ((Room?)comboBoxRoom.SelectedItem)?.Id.ToString() ?? String.Empty),
|
||||||
|
ArrivalDate = ToDateOnly(dateTimePickerArrival.Value).ToString(),
|
||||||
|
DepartureDate = ToDateOnly(dateTimePickerDeparture.Value).ToString(),
|
||||||
|
Price = numericUpDownPrice.Value.ToString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
_mongoLogic.UpdateReservation(updatedReservation);
|
||||||
|
}
|
||||||
|
|
||||||
LoadData();
|
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];
|
||||||
int reservationId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
if (Program.isPostgreSQL)
|
||||||
|
{
|
||||||
|
int reservationId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
_reservationLogic.Delete(reservationId);
|
_reservationLogic.Delete(reservationId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string? reservationId = selectedRow.Cells["Id"].Value.ToString();
|
||||||
|
|
||||||
|
_mongoLogic.DeleteRoom(reservationId);
|
||||||
|
}
|
||||||
|
|
||||||
LoadData();
|
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,14 +78,35 @@ 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";
|
|
||||||
|
|
||||||
foreach (var room in rooms)
|
if (Program.isPostgreSQL)
|
||||||
{
|
{
|
||||||
dataGridView.Rows.Add(room.Id, room.HotelId, _hotelLogic.Get(room.HotelId)?.HotelName, room.Category, room.CountPlace,
|
var rooms = _roomLogic.GetAll();
|
||||||
room.Flor, room.Number, room.Price);
|
|
||||||
|
foreach (var room in rooms)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(room.Id, room.HotelId, _hotelLogic.Get(room.HotelId)?.HotelName, room.Category, room.CountPlace,
|
||||||
|
room.Flor, room.Number, room.Price);
|
||||||
|
}
|
||||||
|
|
||||||
|
comboBoxHotel.DataSource = _hotelLogic.GetAll();
|
||||||
|
comboBoxHotel.DisplayMember = "Hotel";
|
||||||
|
comboBoxHotel.ValueMember = "HotelName";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var rooms = _mongoLogic.GetRooms();
|
||||||
|
|
||||||
|
foreach (var room in rooms)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(room.Id, room.HotelId, _mongoLogic.GetHotelById(room.HotelId)?.HotelName, room.Category, room.CountPlace,
|
||||||
|
room.Flor, room.Number, room.Price);
|
||||||
|
}
|
||||||
|
|
||||||
|
comboBoxHotel.DataSource = _mongoLogic.GetHotels();
|
||||||
|
comboBoxHotel.DisplayMember = "Hotel";
|
||||||
|
comboBoxHotel.ValueMember = "HotelName";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,20 +115,39 @@ namespace HotelView
|
|||||||
if (dataGridView.SelectedRows.Count > 0)
|
if (dataGridView.SelectedRows.Count > 0)
|
||||||
{
|
{
|
||||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||||
int roomId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
if (Program.isPostgreSQL)
|
||||||
|
|
||||||
Room updatedRoom = new()
|
|
||||||
{
|
{
|
||||||
Id = roomId,
|
int roomId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
HotelId = ((Hotel?)comboBoxHotel.SelectedItem)?.Id ?? 0,
|
|
||||||
Category = textBoxCategory.Text,
|
|
||||||
CountPlace = (int)numericUpDownCountPlace.Value,
|
|
||||||
Flor = (int)numericUpFlor.Value,
|
|
||||||
Number = textBoxNumber.Text,
|
|
||||||
Price = (int)numericUpDownPrice.Value,
|
|
||||||
};
|
|
||||||
|
|
||||||
_roomLogic.Update(updatedRoom);
|
Room updatedRoom = new()
|
||||||
|
{
|
||||||
|
Id = roomId,
|
||||||
|
HotelId = ((Hotel?)comboBoxHotel.SelectedItem)?.Id ?? 0,
|
||||||
|
Category = textBoxCategory.Text,
|
||||||
|
CountPlace = (int)numericUpDownCountPlace.Value,
|
||||||
|
Flor = (int)numericUpFlor.Value,
|
||||||
|
Number = textBoxNumber.Text,
|
||||||
|
Price = (int)numericUpDownPrice.Value,
|
||||||
|
};
|
||||||
|
|
||||||
|
_roomLogic.Update(updatedRoom);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
string? roomId = selectedRow.Cells["Id"].Value.ToString();
|
||||||
|
|
||||||
|
MongoRoom updatedRoom = new()
|
||||||
|
{
|
||||||
|
Id = roomId,
|
||||||
|
HotelId = _mongoLogic.GetMongoId("Hotel", ((Hotel?)comboBoxHotel.SelectedItem)?.Id.ToString() ?? String.Empty),
|
||||||
|
Category = textBoxCategory.Text,
|
||||||
|
CountPlace = numericUpDownCountPlace.Value.ToString(),
|
||||||
|
Flor = numericUpFlor.Value.ToString(),
|
||||||
|
Number = textBoxNumber.Text,
|
||||||
|
Price = numericUpDownPrice.Value.ToString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
_mongoLogic.UpdateRoom(updatedRoom);
|
||||||
|
}
|
||||||
|
|
||||||
LoadData();
|
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];
|
||||||
int roomId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
if (Program.isPostgreSQL)
|
||||||
|
{
|
||||||
|
int roomId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
_roomLogic.Delete(roomId);
|
_roomLogic.Delete(roomId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string? roomId = selectedRow.Cells["Id"].Value.ToString();
|
||||||
|
|
||||||
|
_mongoLogic.DeleteRoom(roomId);
|
||||||
|
}
|
||||||
|
|
||||||
LoadData();
|
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,27 +61,58 @@ 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;
|
||||||
|
|
||||||
foreach (var service in services)
|
if (Program.isPostgreSQL)
|
||||||
{
|
{
|
||||||
dataGridView.Rows.Add(service.Id, service.Name, service.Price);
|
var services = _serviceLogic.GetAll();
|
||||||
|
foreach (var service in services)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(service.Id, service.Name, service.Price);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
var services = _mongoLogic.GetServices();
|
||||||
|
foreach (var service in services)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(service.Id, service.Name, service.Price);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonUpdate_Click(object sender, EventArgs e)
|
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];
|
||||||
int serviceId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
if (!Program.isPostgreSQL)
|
||||||
|
|
||||||
Service updatedService = new()
|
|
||||||
{
|
{
|
||||||
Id = serviceId,
|
int serviceId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
Name = textBoxName.Text,
|
|
||||||
Price = (double)numericUpDownPrice.Value
|
Service updatedService = new()
|
||||||
};
|
{
|
||||||
|
Id = serviceId,
|
||||||
|
Name = textBoxName.Text,
|
||||||
|
Price = (double)numericUpDownPrice.Value
|
||||||
|
};
|
||||||
|
|
||||||
|
_serviceLogic.Update(updatedService);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
string? serviceId = selectedRow.Cells["Id"].Value.ToString();
|
||||||
|
|
||||||
|
MongoService mongoService = new()
|
||||||
|
{
|
||||||
|
Id = serviceId,
|
||||||
|
Name = textBoxName.Text,
|
||||||
|
Price = numericUpDownPrice.Value.ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
_mongoLogic.UpdateService(mongoService);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
_serviceLogic.Update(updatedService);
|
|
||||||
|
|
||||||
LoadData();
|
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];
|
||||||
int serviceId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
if (!Program.isPostgreSQL)
|
||||||
|
{
|
||||||
|
int serviceId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
_serviceLogic.Delete(serviceId);
|
_serviceLogic.Delete(serviceId);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
string? serviceId = selectedRow.Cells["Id"].Value.ToString();
|
||||||
|
|
||||||
|
_mongoLogic.DeleteService(serviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
LoadData();
|
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,13 +82,51 @@ namespace HotelView
|
|||||||
comboBoxService.DisplayMember = "Service";
|
comboBoxService.DisplayMember = "Service";
|
||||||
comboBoxService.ValueMember = "Name";
|
comboBoxService.ValueMember = "Name";
|
||||||
|
|
||||||
foreach (var serviceCheck in serviceChecks)
|
|
||||||
|
if (Program.isPostgreSQL)
|
||||||
{
|
{
|
||||||
dataGridView.Rows.Add(serviceCheck.Id,
|
var serviceChecks = _serviceCheckLogic.GetAll();
|
||||||
serviceCheck.ReservationId, _reservationLogic.Get(serviceCheck.ReservationId)?.Id,
|
|
||||||
serviceCheck.ServiceId, _serviceLogic.Get(serviceCheck.ServiceId)?.Name,
|
foreach (var serviceCheck in serviceChecks)
|
||||||
serviceCheck.Count,
|
{
|
||||||
serviceCheck.DateTime);
|
dataGridView.Rows.Add(serviceCheck.Id,
|
||||||
|
serviceCheck.ReservationId,
|
||||||
|
_reservationLogic.Get(serviceCheck.ReservationId)?.Id,
|
||||||
|
serviceCheck.ServiceId,
|
||||||
|
_serviceLogic.Get(serviceCheck.ServiceId)?.Name,
|
||||||
|
serviceCheck.Count,
|
||||||
|
serviceCheck.DateTime);
|
||||||
|
}
|
||||||
|
comboBoxReservation.DataSource = _reservationLogic.GetAll();
|
||||||
|
comboBoxReservation.DisplayMember = "Reservation";
|
||||||
|
comboBoxReservation.ValueMember = "Id";
|
||||||
|
|
||||||
|
comboBoxService.DataSource = _serviceLogic.GetAll();
|
||||||
|
comboBoxService.DisplayMember = "Service";
|
||||||
|
comboBoxService.ValueMember = "Name";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var serviceChecks = _mongoLogic.GetServiceChecks();
|
||||||
|
|
||||||
|
foreach (var serviceCheck in serviceChecks)
|
||||||
|
{
|
||||||
|
dataGridView.Rows.Add(
|
||||||
|
serviceCheck.Id,
|
||||||
|
serviceCheck.ReservationId,
|
||||||
|
_mongoLogic.GetReservationById(serviceCheck.ReservationId)?.Id,
|
||||||
|
serviceCheck.ServiceId,
|
||||||
|
_mongoLogic.GetServiceById(serviceCheck.ServiceId)?.Name,
|
||||||
|
serviceCheck.Count,
|
||||||
|
serviceCheck.DateTime);
|
||||||
|
}
|
||||||
|
comboBoxReservation.DataSource = _mongoLogic.GetReservations();
|
||||||
|
comboBoxReservation.DisplayMember = "Reservation";
|
||||||
|
comboBoxReservation.ValueMember = "Id";
|
||||||
|
|
||||||
|
comboBoxService.DataSource = _mongoLogic.GetServices();
|
||||||
|
comboBoxService.DisplayMember = "Service";
|
||||||
|
comboBoxService.ValueMember = "Name";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,18 +135,36 @@ namespace HotelView
|
|||||||
if (dataGridView.SelectedRows.Count > 0)
|
if (dataGridView.SelectedRows.Count > 0)
|
||||||
{
|
{
|
||||||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||||||
int serviceCheckId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
if (Program.isPostgreSQL)
|
||||||
|
|
||||||
ServiceCheck updatedServiceCheck = new()
|
|
||||||
{
|
{
|
||||||
Id = serviceCheckId,
|
int serviceCheckId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
ReservationId = ((Reservation?)comboBoxReservation.SelectedItem)?.Id ?? 0,
|
|
||||||
ServiceId = ((Service?)comboBoxService.SelectedItem)?.Id ?? 0,
|
|
||||||
Count = (int)numericUpDownCount.Value,
|
|
||||||
DateTime = dateTimePicker.Value,
|
|
||||||
};
|
|
||||||
|
|
||||||
_serviceCheckLogic.Update(updatedServiceCheck);
|
ServiceCheck updatedServiceCheck = new()
|
||||||
|
{
|
||||||
|
Id = serviceCheckId,
|
||||||
|
ReservationId = ((Reservation?)comboBoxReservation.SelectedItem)?.Id ?? 0,
|
||||||
|
ServiceId = ((Service?)comboBoxService.SelectedItem)?.Id ?? 0,
|
||||||
|
Count = (int)numericUpDownCount.Value,
|
||||||
|
DateTime = dateTimePicker.Value,
|
||||||
|
};
|
||||||
|
|
||||||
|
_serviceCheckLogic.Update(updatedServiceCheck);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string? serviceCheckId = selectedRow.Cells["Id"].Value.ToString();
|
||||||
|
|
||||||
|
MongoServiceCheck updatedServiceCheck = new()
|
||||||
|
{
|
||||||
|
Id = serviceCheckId,
|
||||||
|
ReservationId = _mongoLogic.GetMongoId("Reservation", ((Reservation?)comboBoxReservation.SelectedItem)?.Id.ToString() ?? String.Empty),
|
||||||
|
ServiceId = _mongoLogic.GetMongoId("Service", ((Service?)comboBoxService.SelectedItem)?.Id.ToString() ?? String.Empty),
|
||||||
|
Count = numericUpDownCount.Value.ToString(),
|
||||||
|
DateTime = dateTimePicker.Value.ToString(),
|
||||||
|
};
|
||||||
|
|
||||||
|
_mongoLogic.UpdateServiceCheck(updatedServiceCheck);
|
||||||
|
}
|
||||||
|
|
||||||
LoadData();
|
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];
|
||||||
int serviceCheckId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
if (Program.isPostgreSQL)
|
||||||
|
{
|
||||||
|
int serviceCheckId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||||||
|
|
||||||
_serviceCheckLogic.Delete(serviceCheckId);
|
_serviceCheckLogic.Delete(serviceCheckId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string? serviceCheckId = selectedRow.Cells["Id"].Value.ToString();
|
||||||
|
|
||||||
|
_mongoLogic.DeleteServiceCheck(serviceCheckId);
|
||||||
|
}
|
||||||
|
|
||||||
LoadData();
|
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