By GokiSoft.com|
14:50 28/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
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
https://gokisoft.com/chuong-trinh-quan-ly-khach-san-develop-hotel-project-lap-trinh-c-lap-trinh-c-sharp.html
#Book.cs
using System;
using Hotels.Models;
using System.Collections.Generic;
namespace Hotels.Models
{
public class Book
{
public string CMTND { get; set; }
public string HotelCode { get; set; }
public string RoomNo { get; set; }
public DateTime CheckIn { get; set; }
public DateTime CheckOut { get; set; }
public Book()
{
}
public void Input(List<Customer> customers, List<Hotel> hotels) {
if(hotels.Count == 0) {
Console.WriteLine("Khong co du lieu!!!");
return;
}
Console.WriteLine("Nhap CMTND: ");
CMTND = Console.ReadLine();
bool isFind = false;
foreach(Customer customer in customers) {
if(customer.CMTND.Equals(CMTND)) {
isFind = true;
break;
}
}
if(!isFind) {
//nhap moi du lieu KH
Customer customer = new Customer();
customer.CMTND = CMTND;
customer.InputWithoutCMTND();
customers.Add(customer);
}
Console.WriteLine("Nhap Ma KS: ");
Hotel currentHotel = null;
for (; ;) {
foreach(Hotel hotel in hotels) {
Console.WriteLine("Ma KS: {0}, Ten KS: {1}", hotel.HotelCode, hotel.Name);
}
HotelCode = Console.ReadLine();
foreach (Hotel hotel in hotels)
{
if(hotel.HotelCode.Equals(HotelCode)) {
currentHotel = hotel;
break;
}
}
if(currentHotel != null) {
break;
}
Console.WriteLine("(Not Found) Nhap lai: ");
}
Console.WriteLine("Nhap Ma Phong: ");
if(currentHotel.RoomList.Count == 0) {
Console.WriteLine("KS khong cai dat phong!!!");
return;
}
for (; ;) {
foreach(Room room in currentHotel.RoomList) {
Console.WriteLine("Ma Phong: {0}, Ten Phong: {1}", room.RoomNo, room.RoomName);
}
isFind = false;
RoomNo = Console.ReadLine();
foreach (Room room in currentHotel.RoomList)
{
if(room.RoomNo.Equals(RoomNo)) {
isFind = true;
break;
}
}
if(isFind) {
break;
} else {
Console.WriteLine("(Not Found) Nhap lai: ");
}
}
Console.WriteLine("Ngay CheckIn (dd/mm/YYYY): ");
string dateTime = Console.ReadLine();
CheckIn = ConvertStringToDatetime(dateTime);
Console.WriteLine("Ngay CheckOut (dd/mm/YYYY): ");
dateTime = Console.ReadLine();
CheckOut = ConvertStringToDatetime(dateTime);
}
public DateTime ConvertStringToDatetime(string value) {
//string iString = "2005-05-05 22:12 PM";
DateTime oDate = DateTime.ParseExact(value, "dd/MM/yyyy", null);
return oDate;
}
}
}
#Customer.cs
using System;
namespace Hotels.Models
{
public class Customer
{
public string CMTND { get; set; }
public string Fullname { get; set; }
public string Age { get; set; }
public string Gender { get; set; }
public string Address { get; set; }
public Customer()
{
}
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 = Console.ReadLine();
Console.WriteLine("Nhap gioi tinh: ");
Gender = Console.ReadLine();
Console.WriteLine("Nhap dia chi: ");
Address = Console.ReadLine();
}
public void Display() {
Console.WriteLine("CMTND : {0}, Ten: {1}, Tuoi: {3}, Gioi tinh: {4}, Dia chi: {5}",
CMTND, Fullname, Age, Gender, Address);
}
}
}
#Hotel.cs
using System;
using System.Collections.Generic;
namespace Hotels.Models
{
public class Hotel
{
public string HotelCode { 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 ks: ");
HotelCode = Console.ReadLine();
Console.WriteLine("Nhap ten ks: ");
Name = Console.ReadLine();
Console.WriteLine("Nhap dia chi: ");
Address = Console.ReadLine();
Console.WriteLine("Nhap loai ks (VIP/Binh Dan):");
Type = Console.ReadLine();
for (;;) {
Room room = new Room();
room.Input();
RoomList.Add(room);
Console.WriteLine("Co tiep tuc nhap hay ko? Y/N: ");
string option = Console.ReadLine();
if(option.ToUpper().Equals("N")) {
break;
}
}
}
public void Display() {
Console.WriteLine("Ma KS: {0}, Ten KS: {1}, Dia Chi: {2}, Loai: {3}", HotelCode, Name, Address, Type);
foreach(Room room in RoomList) {
room.Display();
}
}
}
}
#Room.cs
using System;
namespace Hotels.Models
{
public class Room
{
public string RoomName { get; set; }
public float Price { get; set; }
public string RoomNo { get; set; }
public int PeopleMax { get; set; }
public int Floor { 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 gia: ");
Price = float.Parse(Console.ReadLine());
Console.WriteLine("Nhap so nguoi toi da: ");
PeopleMax = int.Parse(Console.ReadLine());
Console.WriteLine("Nhap tang: ");
Floor = int.Parse(Console.ReadLine());
}
public void Display() {
Console.WriteLine("Ma phong: {0}, ten phong: {1}, gia: {2}, so nguoi toi da: {3}, tang: {4}",
RoomNo, RoomName, Price, PeopleMax, Floor);
}
}
}
#Program.cs
using System;
using System.Collections.Generic;
using Hotels.Models;
namespace Hotels
{
class Program
{
static void Main(string[] args)
{
List<Customer> customers = new List<Customer>();
List<Hotel> hotels = new List<Hotel>();
List<Book> books = new List<Book>();
int choose;
do
{
ShowMenu();
choose = int.Parse(Console.ReadLine());
switch(choose) {
case 1:
InputHotel(hotels);
break;
case 2:
DisplayHotel(hotels);
break;
case 3:
Booking(customers, hotels, books);
break;
case 4:
FindBookingAvaiable(hotels, books);
break;
case 5:
break;
case 6:
break;
case 7:
Console.WriteLine("Thoat!!!");
break;
default:
Console.WriteLine("Nhap sai!!!");
break;
}
} while (choose != 7);
}
static void FindBookingAvaiable(List<Hotel> hotels, List<Book> books) {
if(hotels.Count == 0) {
Console.WriteLine("khong co data!!!");
return;
}
Hotel currentHotel = null;
for (; ; )
{
foreach (Hotel hotel in hotels)
{
Console.WriteLine("Ma KS: {0}, Ten KS: {1}", hotel.HotelCode, hotel.Name);
}
string HotelCode = Console.ReadLine();
foreach (Hotel hotel in hotels)
{
if (hotel.HotelCode.Equals(HotelCode))
{
currentHotel = hotel;
break;
}
}
if (currentHotel != null)
{
break;
}
Console.WriteLine("(Not Found) Nhap lai: ");
}
if(currentHotel.RoomList.Count == 0) {
Console.WriteLine("khong co data!!!");
return;
}
Console.WriteLine("Ngay CheckIn (dd/mm/YYYY): ");
string dateTime = Console.ReadLine();
DateTime CheckIn = DateTime.ParseExact(dateTime, "dd/MM/yyyy", null);
Console.WriteLine("Ngay CheckOut (dd/mm/YYYY): ");
dateTime = Console.ReadLine();
DateTime CheckOut = DateTime.ParseExact(dateTime, "dd/MM/yyyy", null);
//Tim kiem phong co the book
//Room => co the booking
//R001 => A1=>A2 & CheckIn => CheckOut : CheckIn > A2 hoac CheckOut < A1
foreach(Room room in currentHotel.RoomList) {
//Tim da danh sach booking cho phong room.
List<Book> currentBooking = new List<Book>();
foreach(Book book in books) {
if(book.HotelCode.Equals(currentHotel.HotelCode) && book.RoomNo.Equals(room.RoomNo)) {
currentBooking.Add(book);
}
}
//Kiem tra phong nay co kha nang book hay ko
bool isFind = false;
foreach(Book book in currentBooking) {
if(DateTime.Compare(book.CheckIn, CheckOut) > 0 || DateTime.Compare(book.CheckOut, CheckIn) < 0) {
//OK
} else {
isFind = true;
break;
}
}
if(!isFind) {
Console.WriteLine("Room No: {0}, Room Name: {1}", room.RoomNo, room.RoomName);
}
}
}
static void Booking(List<Customer> customers, List<Hotel> hotels, List<Book> books) {
Book book = new Book();
book.Input(customers, hotels);
books.Add(book);
}
static void DisplayHotel(List<Hotel> hotels) {
foreach(Hotel hotel in hotels) {
hotel.Display();
}
}
static void InputHotel(List<Hotel> hotels) {
for (; ;) {
Hotel hotel = new Hotel();
hotel.Input();
hotels.Add(hotel);
Console.WriteLine("Ban co tiep tuc nhap hay ko? Y/N:");
string option = Console.ReadLine();
if(option.ToUpper().Equals("N")) {
break;
}
}
}
static void ShowMenu() {
Console.WriteLine("1. Nhap thong tin KS");
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 KS");
Console.WriteLine("6. Tim kiem thong tin KH");
Console.WriteLine("7. Thoat");
Console.WriteLine("Choose: ");
}
}
}
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)