By GokiSoft.com|
14:07 02/10/2021|
C Sharp
[Video] Chương trình quản lý khách sạn - Develop Hotel Project - Lập Trình C# - Lập Trình C Sharp - AAHN-C2009G
Chương trình quản lý khách sạn - Develop Hotel Project - Lập Trình C# - Lập Trình C Sharp
#Booking.cs
using System;
using BT1460.Utils;
namespace BT1460.Models
{
public class Booking
{
public string HotelNo { get; set; }
public string RoomNo { get; set; }
public string CMTND { get; set; }
public DateTime CheckIn { get; set; }
public DateTime CheckOut { get; set; }
public Booking()
{
}
public void Input()
{
if(DataController.getInstance().HotelList.Count == 0)
{
return;
}
bool isFind = false;
Console.WriteLine("Nhap ma khach san: ");
Hotel currentHotel = null;
while(true)
{
HotelNo = Console.ReadLine();
isFind = false;
foreach(Hotel hotel in DataController.getInstance().HotelList)
{
if(hotel.HotelNo == HotelNo)
{
currentHotel = hotel;
isFind = true;
break;
}
}
if(!isFind)
{
Console.WriteLine("Nhap lai: ");
} else
{
break;
}
}
Console.WriteLine("Nhap ma phong: ");
while (true)
{
RoomNo = Console.ReadLine();
isFind = false;
foreach (Room room in currentHotel.RoomList)
{
if (room.RoomNo == RoomNo)
{
isFind = true;
break;
}
}
if (!isFind)
{
Console.WriteLine("Nhap lai: ");
}
else
{
break;
}
}
Console.WriteLine("Nhap CMTND: ");
CMTND = Console.ReadLine();
isFind = false;
foreach(Customer customer in DataController.getInstance().CustomerList)
{
if(customer.CMTND == CMTND)
{
isFind = true;
break;
}
}
if(!isFind)
{
Customer customer = new Customer(CMTND);
customer.InputWithoutCMTND();
DataController.getInstance().CustomerList.Add(customer);
}
Console.WriteLine("Nhap ngay nhan (yyyy-MM-dd HH:mm:ss): ");
CheckIn = Utility.ConvertStringToDateTime(Console.ReadLine());
Console.WriteLine("Nhap ngay tra (yyyy-MM-dd HH:mm:ss): ");
CheckOut = Utility.ConvertStringToDateTime(Console.ReadLine());
}
public void Display()
{
Console.WriteLine("Ma KS: {0}, ma phong: {1}, CMTND: {2}, " +
"Ngay nhan: {3}, ngay tra: {4}", HotelNo, RoomNo, CMTND,
Utility.ConvertDateTimeToString(CheckIn), Utility.ConvertDateTimeToString(CheckOut));
}
}
}
#Customer.cs
using System;
namespace BT1460.Models
{
public class Customer
{
public string Fullname { get; set; }
public int Age { get; set; }
public string CMTND { get; set; }
public string Gender { get; set; }
public string Address { get; set; }
public Customer()
{
}
public Customer(string cmtnd)
{
CMTND = cmtnd;
}
public Customer(string fullname, int age, string cmtnd, string gender, string address)
{
Fullname = fullname;
Age = age;
CMTND = cmtnd;
Gender = gender;
Address = address;
}
public void Input()
{
Console.WriteLine("Nhap CMTND: ");
CMTND = Console.ReadLine();
InputWithoutCMTND();
}
public void InputWithoutCMTND()
{
Console.WriteLine("Nhap ten: ");
Fullname = Console.ReadLine();
Console.WriteLine("Nhap tuoi: ");
Age = int.Parse(Console.ReadLine());
Console.WriteLine("Nhap gioi tinh: ");
Gender = Console.ReadLine();
Console.WriteLine("Nhap dia chi: ");
Address = Console.ReadLine();
}
public void Display()
{
Console.WriteLine("Ten: {0}, tuoi: {1}, cmtnd: {2}, gioi tinh: {3}, dia chi: {4}", Fullname, Age, CMTND, Gender, Address);
}
}
}
#DataController.cs
using System;
using System.Collections.Generic;
namespace BT1460.Models
{
public class DataController
{
public List<Customer> CustomerList { get; set; }
public List<Hotel> HotelList { get; set; }
public List<Booking> BookingList { get; set; }
public static DataController instance = null;
private DataController()
{
CustomerList = new List<Customer>();
HotelList = new List<Hotel>();
BookingList = new List<Booking>();
}
public static DataController getInstance()
{
if(instance == null)
{
instance = new DataController();
}
return instance;
}
public Hotel FindHotel(string hotelNo)
{
foreach(Hotel hotel in HotelList)
{
if(hotel.HotelNo == hotelNo)
{
return hotel;
}
}
return null;
}
}
}
#Hotel.cs
using System;
using System.Collections.Generic;
using BT1460.Models;
namespace BT1460.Models
{
public class Hotel
{
public string HotelNo { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Type { get; set; }
public List<Room> RoomList { get; set; }
public Hotel()
{
RoomList = new List<Room>();
}
public void Input()
{
Console.WriteLine("Nhap ma khach san: ");
HotelNo = Console.ReadLine();
Console.WriteLine("Nhap ten khach san: ");
Name = Console.ReadLine();
Console.WriteLine("Nhap dia chi: ");
Address = Console.ReadLine();
Console.WriteLine("Nhap loai: ");
Type = Console.ReadLine();
Console.WriteLine("Nhap so phong: ");
int N = int.Parse(Console.ReadLine());
for(int i=0;i<N;i++)
{
Room room = new Room();
room.Input();
RoomList.Add(room);
}
}
public void DisplayAll ()
{
Console.WriteLine("Ten KS: {0}, ma ks: {1}, dia chi: {2}, loai: {3}",
Name, HotelNo, Address, Type);
Console.WriteLine("Danh sach phong: ");
foreach(Room room in RoomList)
{
room.Display();
}
}
public void Display()
{
Console.WriteLine("Ten KS: {0}, ma ks: {1}, dia chi: {2}, loai: {3}",
Name, HotelNo, Address, Type);
}
Room findRoom(string roomNo)
{
foreach(Room room in RoomList)
{
if(room.RoomNo == roomNo)
{
return room;
}
}
return null;
}
public int CalculateProfit(List<Booking> bookings)
{
int profit = 0;
foreach(Booking booking in bookings)
{
if(booking.HotelNo == HotelNo)
{
Room room = findRoom(booking.RoomNo);
if(room != null)
{
profit += room.Price;
}
}
}
return profit;
}
public void ShowRoomAvailable(List<Booking> bookings)
{
Display();
Console.WriteLine("Danh sach phong trong: ");
foreach(Room room in RoomList)
{
if(CheckAvailable(bookings, room))
{
room.Display();
}
}
}
bool CheckAvailable(List<Booking> bookings, Room room)
{
foreach(Booking booking in bookings)
{
if(booking.HotelNo == HotelNo && booking.RoomNo == room.RoomNo)
{
return false;
}
}
return true;
}
}
}
#Room.cs
using System;
namespace BT1460.Models
{
public class Room
{
public string RoomNo { get; set; }
public string RoomName { get; set; }
public int Floor { get; set; }
public int NumMax { get; set; }
public int Price { get; set; }
public Room()
{
}
public void Input()
{
Console.WriteLine("Nhap ma phong: ");
RoomNo = Console.ReadLine();
Console.WriteLine("Nhap ten phong: ");
RoomName = Console.ReadLine();
Console.WriteLine("Nhap tang: ");
Floor = int.Parse(Console.ReadLine());
Console.WriteLine("Nhap so nguoi toi da: ");
NumMax = int.Parse(Console.ReadLine());
Console.WriteLine("Nhap gia: ");
Price = int.Parse(Console.ReadLine());
}
public void Display()
{
Console.WriteLine("Ma phong: {0}, ten phong: {1}, " +
"tang: {2}, so nguoi toi da: {3}, " +
"gia tien: {4}", RoomNo, RoomName, Floor, NumMax, Price);
}
}
}
#Utility.cs
using System;
using System.Globalization;
namespace BT1460.Utils
{
public class Utility
{
/**
* Format: yyyy-MM-dd HH:mm:ss
*/
public static DateTime ConvertStringToDateTime(String str)
{
DateTime outputDateTimeValue;
if (DateTime.TryParseExact(str, "yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out outputDateTimeValue))
{
return outputDateTimeValue;
}
return new DateTime();
}
/**
* Format: yyyy-MM-dd HH:mm:ss
*/
public static string ConvertDateTimeToString(DateTime dateTime)
{
return dateTime.ToString("yyyy-MM-dd HH:mm:ss");
}
}
}
#Program.cs
using System;
using BT1460.Models;
using BT1460.Utils;
using System.Collections.Generic;
namespace BT1460
{
class Program
{
//1. Quan ly khach hang
//2. Quan ly dc KS
//3. Quan ly dc booking
static void Main(string[] args)
{
int choose;
do
{
ShowMenu();
choose = int.Parse(Console.ReadLine());
switch(choose)
{
case 1:
InputHotel();
break;
case 2:
DisplayHotel();
break;
case 3:
InputBooking();
break;
case 4:
FindRoomAvailable();
break;
case 5:
CalculateProfit();
break;
case 6:
SearchCustomerByCMNTD();
break;
case 7:
Console.WriteLine("Thoat!!!");
break;
default:
Console.WriteLine("Nhap sai!!!");
break;
}
} while (choose != 7);
}
private static void FindRoomAvailable()
{
Console.WriteLine("Nhap ngay nhan (yyyy-MM-dd HH:mm:ss): ");
DateTime checkIn = Utility.ConvertStringToDateTime(Console.ReadLine());
Console.WriteLine("Nhap ngay tra (yyyy-MM-dd HH:mm:ss): ");
DateTime checkOut = Utility.ConvertStringToDateTime(Console.ReadLine());
//Book -> CheckIn (checkIn & checkOut) || CheckOut (checkIn & checkOut)
List<Booking> bookList = new List<Booking>();
foreach(Booking booking in DataController.getInstance().BookingList)
{
if(booking.CheckIn >= checkIn && booking.CheckIn <= checkOut)
{
bookList.Add(booking);
} else if (booking.CheckOut >= checkIn && booking.CheckOut <= checkOut)
{
bookList.Add(booking);
}
}
//Hien thi danh sach phong con trong:
foreach(Hotel hotel in DataController.getInstance().HotelList)
{
hotel.ShowRoomAvailable(bookList);
}
}
private static void SearchCustomerByCMNTD()
{
Console.WriteLine("Nhap CMTND can tim: ");
string cmntd = Console.ReadLine();
List<Hotel> list = new List<Hotel>();
foreach(Booking booking in DataController.getInstance().BookingList)
{
if(booking.CMTND == cmntd)
{
Hotel hotel = DataController.getInstance().FindHotel(booking.HotelNo);
if(hotel != null && !list.Contains(hotel))
{
list.Add(hotel);
}
}
}
Console.WriteLine("Danh sach KS ma KH toi: ");
foreach(Hotel hotel in list)
{
hotel.Display();
}
}
private static void CalculateProfit()
{
foreach(Hotel hotel in DataController.getInstance().HotelList)
{
int profit = hotel.CalculateProfit(DataController.getInstance().BookingList);
Console.WriteLine("KS: {0}, ma ks: {1}, doanh thu: {2}", hotel.Name, hotel.HotelNo, profit);
}
}
private static void InputBooking()
{
Console.WriteLine("Nhap thong tin dat phong: ");
Booking booking = new Booking();
booking.Input();
DataController.getInstance().BookingList.Add(booking);
}
private static void DisplayHotel()
{
Console.WriteLine("Thong tin KS:");
foreach(Hotel hotel in DataController.getInstance().HotelList)
{
hotel.Display();
}
}
private static void InputHotel()
{
Console.WriteLine("Nhap so khach san can them: ");
int N = int.Parse(Console.ReadLine());
for(int i=0;i<N;i++)
{
Hotel hotel = new Hotel();
hotel.Input();
DataController.getInstance().HotelList.Add(hotel);
}
}
static void ShowMenu()
{
Console.WriteLine("1. Nhap thong tin khach san");
Console.WriteLine("2. Hien thi thong tin KS");
Console.WriteLine("3. Dat phong");
Console.WriteLine("4. Tim phong trong");
Console.WriteLine("5. Thong ke doanh thu");
Console.WriteLine("6. Tim kiem KH");
Console.WriteLine("7. Thoat");
Console.WriteLine("Chon: ");
}
}
}
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)