By GokiSoft.com| 10:34 12/10/2021|
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 BT1460

Xây dựng menu chương trình như sau

1. Nhập thông tin khách sạn

2. Hiển thị thông tin khách sạn

3. Đặt phong nghỉ

4. Tìm phòng còn trống

5. Thống kê doanh duy khách sạn

6. Tìm kiếm thông tin khách hàng.

7. Thoát chương trình

Yêu cầu :

1. Thiết kế lớp đối tượng khách hàng gồm các thuộc tính (Số CMTND, họ tên, tuổi, giới tính, quê quán)

- Thiết kế get/set cho thuộc tính

- Tạo hàm tạo ko đối và đầy đủ đối số

- Tạo hàm nhập và hiển thị thông tin

2. Thiết kế lớp Hotel gồm các thuộc tính : tên, địa chỉ, loại khách sạn (VIP, Bình dân,...), danh sách các Room, mã khách sạn


- Thiết kế get/set cho thuộc tính

- Tạo hàm tạo ko đối và đầy đủ đối số

- Tạo hàm nhập và hiển thị thông tin

3. Thiết kế lớp Room gồm các thuộc tính : Tên phòng, giá tiền, tầng, số người tối đa ở, mã phòng

- Thiết kế get/set cho thuộc tính

- Tạo hàm tạo ko đối và đầy đủ đối số

- Tạo hàm nhập và hiển thị thông tin

4. Thiết kế lớp Book gồm các thuộc tính : ngày book, ngày trả phòng, Số CMTND người book, mã khách sạn, mã phòng

Chú ý : Số CMTND -> nếu chưa tồn tại -> nhập thông tin KH đó

Mã khách sạn -> Nếu ko tồn tại, yêu cầu nhập đúng khách sạn đã có

Mã Phòng -> yêu cầu nhập đúng mã phòng của KH mà người dùng muốn book -> Nếu nhập sai, yêu cầu nhập đúng mới dừng.

Chú thích menu :

Khi người dùng chọn 1 : Hỏi người dùng số khách sạn cần nhập => Khi nhập mỗi khách sạn thì yêu cầu

- Nhập thông tin khách sạn đó

- Hỏi người dùng nhập số phòng cần nhập cho khách sạn đó => Nhập thông tin từng phòng

Khi người dùng chọn 2 : In toàn bộ thông tin liên quan tới KS

Khi người dùng chọn 3 : Nhập thông tin đặt phòng (Book)

Khi người dùng chọn 4: Nhập vào 1 ngày book và ngày trả phòng, in ra tất cả các phòng có thể đap ứng đc yêu cầu trên

Khi người dùng chọn 5 : In ra tổng tiền mà mỗi khách sạn kiếm được ra màn hình.

Khi người dùng chọn 6 : Nhập Số CMTND khách hàng => In ra tất cả các khách sạn mà khách hàng này đã tới.

Khi người dùng chọn 7 : Thoát chương trình.

Liên kết rút gọn:

https://gokisoft.com/1460

Bình luận

avatar
Hieu Ngo [community,C2009G]
2021-10-12 10:25:38


#Book.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLyKhachSan
{
    class Book
    {
        public DateTime BookDate { get; set; }
        public DateTime ReturnDate { get; set; }

        public string CMTND { get; set; }
        public string HotelId { get; set; }
        public string RoomId { get; set; }

        public Book() { }

        public Book(DateTime bookDate, DateTime returnDate, string cMTND, string hotelId, string roomId)
        {
            BookDate = bookDate;
            ReturnDate = returnDate;
            CMTND = cMTND;
            HotelId = hotelId;
            RoomId = roomId;
        }

        public void Input(List<KhachHang> customers, List<Hotel> hotels)
        {
            Console.WriteLine("Nhap so CMTND:");
            string cmtnd = Console.ReadLine();

            int check = 0;
            foreach(KhachHang khach in customers)
            {
                if(khach.CMTND == cmtnd)
                {
                    check++;
                    break;
                } 
            }
            if(check == 0)
            {
                Console.WriteLine("Khach hang khong ton tai, moi nhap thong tin khach hang");
                KhachHang khach = new KhachHang();
                khach.CMTND = cmtnd;
                khach.Input();
                customers.Add(khach);
            }
            DisplayHotel(hotels);
            Hotel hotel = null;
            while(true)
            {
                Console.WriteLine("Nhap ma khach san ban chon:");
                string id = Console.ReadLine();
                int check1 = 0;
                foreach(Hotel hotel1 in hotels)
                {
                    if(id == hotel1.HotelID)
                    {
                        check1++;
                        HotelId = id;
                        hotel = hotel1;
                        break;
                    }
                }
                if(check1 == 0)
                {
                    Console.WriteLine("Ma khach san khong ton tai");
                } else
                {
                    break; 
                }
            }
            DisplayRoom(hotel);
            while (true)
            {
                Console.WriteLine("Nhap ma phong ban chon:");
                string roomId = Console.ReadLine();
                string hotelId = HotelId;
                int check2 = 0;
                foreach (Hotel hotel1 in hotels)
                {
                    if (hotel1.HotelID == hotelId)
                    {
                        foreach (Room room in hotel1.RoomList)
                        {
                            if (room.RoomId == roomId)
                            {
                                check2++;
                                RoomId = roomId;
                                break;
                            }
                        }
                        break;
                    }
                }
                if(check2 == 0)
                {
                    Console.WriteLine("Ma phong khong ton tai");

                } else
                {
                    break;
                }
            }
            Console.WriteLine("Nhap ngay dat phong:");
            BookDate = Convert.ToDateTime(Console.ReadLine());
            Console.WriteLine("Nhap ngay tra phong:");
            ReturnDate = Convert.ToDateTime(Console.ReadLine());
        }

        public void DisplayHotel(List<Hotel> hotels)
        {
            foreach(Hotel hotel in hotels)
            {
                hotel.Display();
            }
        }

        public void DisplayRoom(Hotel hotel)
        {
            foreach(Room room in hotel.RoomList)
            {
                room.Display();
            }
        }
    }
}


#Hotel.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLyKhachSan
{
    class Hotel
    {
        public string Name { get; set; }
        public string Type { get; set; }
        public string Address { get; set; }
        public List<Room> RoomList { get; set; }
        public string HotelID { get; set; }

       

        public Hotel(string name, string type, string address, List<Room> roomList, string hotelId)
        {
            Name = name;
            Type = type;
            Address = address;
            RoomList = roomList;
            HotelID = hotelId;
        }

        public Hotel() {
            RoomList = new List<Room>();
        }

        public void Input()
        {
            Console.WriteLine("Nhap ma khach san:");
            HotelID = Console.ReadLine();
            Console.WriteLine("Nhap ten khach san:");
            Name = Console.ReadLine();
            Console.WriteLine("Nhap loai khach san:");
            Type = Console.ReadLine();
            Console.WriteLine("Nhap dia chi khach san:");
            Address = Console.ReadLine();
        }

        public void Display()
        {
            Console.WriteLine("Hotel ID: {0}, Hotel Name: {1}, Type: {2}, Address: {3}", HotelID, Name, Type, Address);
            Console.WriteLine("Room list:");
            foreach(Room room in RoomList)
            {
                room.Display();
            }
        }
    }
}


#KhachHang.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLyKhachSan
{
    class KhachHang
    {
        public string CMTND { get; set; }
        public string FullName { get; set; }
        public int Age { get; set; }
        public string Gender { get; set; }
        public string Address { get; set; }

        public KhachHang(string cMTND, string fullName, int age, string gender, string address)
        {
            CMTND = cMTND;
            FullName = fullName;
            Age = age;
            Gender = gender;
            Address = address;
        }
        public KhachHang() { }

        public void InputCMTND()
        {
            Console.WriteLine("Nhap CMTND:");
            CMTND = Console.ReadLine();
        }
         public void Input()
         {
            
            Console.WriteLine("Nhap ho va ten:");
            FullName = Console.ReadLine();
            Console.WriteLine("Nhap tuoi:");
            Age = Utility.ReadInt();
            Console.WriteLine("Nhap gioi tinh:");
            Gender = Console.ReadLine();
            Console.WriteLine("Nhap dia chi:");
            Address = Console.ReadLine();
         }

        public void Display()
        {
            Console.WriteLine("CMTND: {0}, Full Name: {1}, Age: {2}, Gender: {3}, Address: {4}", CMTND, FullName, Age, Gender, Address);
        }
    }
}


#Program.cs


using System;
using System.Collections.Generic;

namespace QuanLyKhachSan
{
    class Program
    {
        static void Main(string[] args)
        {
            int choose;
            do
            {
                Menu();
                choose = Utility.ReadInt();

                switch (choose)
                {
                    case 1:
                        InputHotel();
                        break;
                    case 2:
                        DisplayHotel();
                        break;
                    case 3:
                        Booking();
                        break;
                    case 4:
                        FindRoom();
                        break;
                    case 5:
                        TongTien();
                        break;
                    case 6:
                        FindCustomers();
                        break;
                    case 7:
                        return;
                    default:
                        Console.WriteLine("Nhap sai!!");
                        break;

                }


            } while (choose >= 1 && choose <= 7);
        }

        static void Menu()
        {
            Console.WriteLine("1.Nhap thong tin khach san");
            Console.WriteLine("2.Hien thi thong tin khach san");
            Console.WriteLine("3.Dat phong nghi");
            Console.WriteLine("4.Tim phonng trong");
            Console.WriteLine("5.Thong ke doanh duy khach san");
            Console.WriteLine("6.Tim kiem thong tin khach hang");
            Console.WriteLine("7.Thoat chuong trinh");
            Console.WriteLine("Choose:");
        }

        public static List<KhachHang> customers = new List<KhachHang>();
        public static List<Hotel> hotels = new List<Hotel>();
        public static List<Book> books = new List<Book>();

        static void InputHotel()
        {
            Console.WriteLine("Nhap so khach san can nhap thong tin:");
            int n = Utility.ReadInt();

            for(int i =0; i< n; i++)
            {
                Hotel hotel = new Hotel();
                hotel.Input();
                Console.WriteLine("Nhap vao so phong co trong khach san:");
                int numberOfRoom = Utility.ReadInt();
                for(int j =0; j< numberOfRoom; j++)
                {
                    Room room = new Room();
                    room.Input();
                    hotel.RoomList.Add(room);
                }
                hotels.Add(hotel);
            }
        }
        static void DisplayHotel()
        {
            if(hotels.Count == 0)
            {
                Console.WriteLine("Khong co thong tin khach san nao!!");
                return;
            }

            foreach(Hotel hotel in hotels)
            {
                hotel.Display();
            }
        }

        static void Booking()
        {
            Console.WriteLine("Nhap so phong can dat");
            int n = Utility.ReadInt();

            for(int i = 0; i <n; i++)
            {
                Book book = new Book();
                book.Input(customers, hotels);
                books.Add(book);
            }
        }

        static void FindRoom()
        {
            Console.WriteLine("Nhap vao ngay dat phong:");
            DateTime bd = Convert.ToDateTime(Console.ReadLine());
            Console.WriteLine("Nhap ngay tra phong:");
            DateTime rd = Convert.ToDateTime(Console.ReadLine());

            foreach(Book book in books)
            {
                if(bd.Equals(book.BookDate) && rd.Equals(book.ReturnDate))
                {
                    foreach(Hotel hotel in hotels)
                    {
                        foreach(Room room in hotel.RoomList)
                        {
                            Console.WriteLine("Khach san: {0}", hotel.Name);
                            room.Display();
                        }
                    }
                }
                                
            }
        }

        static void TongTien()
        {
            foreach(Hotel hotel in hotels)
            {
                float sum = 0;
                foreach (Room room in hotel.RoomList)
                {
                    sum += room.Price;
                }
                Console.WriteLine("Tong tien thu duoc cua khach san {0}: {1}", hotel.Name, sum);
            }
        }

        static void FindCustomers()
        {
            Console.WriteLine("Nhap so CMTND khach hang can tim:");
            string str = Console.ReadLine();
            foreach(KhachHang khach in customers)
            {
                if(str == khach.CMTND)
                {
                    Console.WriteLine("{0} da o nhung khach san", khach.FullName);
                } else
                {
                    Console.WriteLine("Khong co du lieu khach hang");
                }
            }
            foreach(Book book in books)
            {
                    if(str == book.CMTND)
                    {
                        foreach(Hotel hotel in hotels)
                        {
                            if(hotel.HotelID == book.HotelId)
                            {
                                Console.WriteLine("{0}", hotel.Name);
                            }
                        }
                    }
            }
        }
    }
}


#Room.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLyKhachSan
{
    class Room
    {
        public string Name { get; set; }
        public float Price { get; set; }
        public int Tang { get; set; }
        public int MaxPeople { get; set; }
        public string RoomId { get; set; }

        public Room() { }
        public Room(string name, float price, int tang, int maxPeople, string roomId)
        {
            Name = name;
            Price = price;
            Tang = tang;
            MaxPeople = maxPeople;
            RoomId = roomId;
        }

        public void Input()
        {
            Console.WriteLine("Nhap ma phong:");
            RoomId = Console.ReadLine();
            Console.WriteLine("Nhap ten phong:");
            Name = Console.ReadLine();
            Console.WriteLine("Nhap tang:");
            Tang = Utility.ReadInt();
            Console.WriteLine("Nhap so nguoi o toi da:");
            MaxPeople = Utility.ReadInt();
            Console.WriteLine("Nhap gia phong:");
            Price = float.Parse(Console.ReadLine());

        }

        public void Display()
        {
            Console.WriteLine("Room ID: {0}, Room Name: {1}, Ground: {2}, People: {3}, Price: {4}", RoomId, Name, Tang, MaxPeople, Price);
        }
    }
}


#Utility.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLyKhachSan
{
    public class Utility
    {
        public static int ReadInt()
        {
            while(true)
            {
                try
                {
                    int value = int.Parse(Console.ReadLine());
                    return value;
                } catch (Exception ex)
                {
                    Console.WriteLine("Nhap sai");
                }
            }
        }
    }
}


avatar
Hoàng Thiện Thanh [community,AAHN-C2009G]
2021-09-28 07:09:33


#Book.cs


using System;
using System.Collections.Generic;

public class Book
{
	public DateTime BookDate;
	public DateTime ReturnDate;
	private string cmtnd;
	public string CMTND { get { return this.cmtnd; } set {

			while (!IsNumber(value))
            {
				Console.WriteLine("Please enter only numbers");
				value = Console.ReadLine();
            }
			this.cmtnd = value;
			
		} }
	private string hotelCode;
	public string HotelCode
	{
		get { return this.hotelCode; }
		set
		{
			while (!IsNumber(value))
			{
				Console.WriteLine("Please enter only numbers");
				value = Console.ReadLine();
			}
			this.hotelCode = value;
		}
	}
	private string roomCode;
	public string RoomCode
	{
		get { return this.roomCode; }
		set
		{
			while (!IsNumber(value))
			{
				Console.WriteLine("Please enter only numbers");
				value = Console.ReadLine();
			}
			this.roomCode = value;
		}
	}
	public Book()
	{

	}

	public Book(DateTime BookDate, DateTime ReturnDate, string CMTND, string HotelCode, string RoomCode)
    {
		this.BookDate = BookDate;
		this.ReturnDate = ReturnDate;
		this.CMTND = CMTND;
		this.HotelCode = HotelCode;
		this.RoomCode = RoomCode;
    }

	public void input(List<Customer> customers, List<Hotel> hotels)
    {
		Console.WriteLine("Input CMTND of the Customer:");
		CMTND = Console.ReadLine();
        bool check = false;

		for (int i = 0; i < customers.Count; i++)
		{
			if (customers[i].CMTND.Equals(CMTND))
			{
				check = true;
				break;
			}
		}

		if (!check)
		{
			Console.WriteLine("Customer does not exist, please input new: ");
			Customer customer = new Customer();
			customer.CMTND = CMTND;
			customer.inputWithCMTND();
		}

		DisplayHotelMenu(hotels);
		Hotel hotel = null;
		while (true)
		{
			HotelCode = Console.ReadLine();
			check = false;
			for (int i = 0; i < hotels.Count; i++)
			{
				if (hotels[i].Id.Equals(HotelCode))
				{
					check = true;
					hotel = hotels[i];
					break;
				}
			}
			if (!check)
			{
				break;
			}
			else
			{
				Console.WriteLine("Input hotel code again!");
            }

        }

        DisplayRoomMenu(hotel);
		while (true)
		{
			RoomCode = Console.ReadLine();
			check = false;

			for (int i = 0; i < hotel.RoomList.Count; i++)
			{
				if (hotel.RoomList[i].RoomCode.Equals(RoomCode))
				{
					check = true;
					break;
				}
			}
			if (!check)
			{
				break;
			}
			else
			{
				Console.WriteLine("Nhap Lai Ma Phong Khach San!");
			}
		}
		Console.WriteLine("Input book date:");
		BookDate = Convert.ToDateTime(Console.ReadLine());
		Console.WriteLine("Input return date:");
		ReturnDate = Convert.ToDateTime(Console.ReadLine());

	}

    public void DisplayHotelMenu(List<Hotel> hotelList)
	{
		for (int i = 0; i < hotelList.Count; i++)
		{
			Console.WriteLine("{0}. - {1} - {2}", i + 1, hotelList[i].Name, hotelList[i].Id);

		}
		Console.WriteLine("Input the hotel code that need to be choosed: ");
	}
	public void DisplayRoomMenu(Hotel hotel)
	{
		for (int i = 0; i < hotel.RoomList.Count; i++)
		{
			Console.WriteLine("{0}. - {1} - {2}", i + 1, hotel.RoomList[i].RoomName, hotel.RoomList[i].RoomCode);

		}
		Console.WriteLine("Input the room code:");
	}

	static bool IsNumber(string value)
	{
		if (string.IsNullOrEmpty(value))
		{
			return false;
		}
		char[] c = value.ToCharArray();
		for (int i = 0; i < c.Length; i++)
		{
			if (!char.IsDigit(c[i]))
			{
				return false;
			}
		}

		return true;
	}
}


#Customer.cs


using System;
using System.Text.RegularExpressions;

public class Customer
{
	private string cmtnd;
	public string CMTND { get { return this.cmtnd; } set {
			string pat = @"[0-9]";
			var reg = new Regex(pat, RegexOptions.IgnoreCase);
			var match = reg.Match(value);

			while (match != null && !match.Success)
			{
				Console.WriteLine("CMTND need only number inputs");
				value = Console.ReadLine();
				return;
			}
			this.cmtnd = value;
		} }
	public string Name { get; set; }
	public DateTime Birthday { get; set; }
	private string gender;
	public string Gender { get { return this.gender; } set
		{
			string pat = @"(\w+)\s+(male)|(female)|(Male)|(Female)";
			var reg = new Regex(pat, RegexOptions.IgnoreCase);
			var match = reg.Match(value);

			while (match != null && !match.Success)
			{
				Console.WriteLine("Gender need only 'Male' or 'Female' inputs");
				value = Console.ReadLine();
				return;
			}
			this.gender = value;
		}
	}
	public string Address { get; set; }
	public Customer()
	{

	}

	public Customer(string CMTND, string Name, DateTime BirthDay, string Gender, string Address)
    {
		this.CMTND = CMTND;
		this.Name = Name;
		this.Birthday = BirthDay;
		this.Gender = Gender;
		this.Address = Address;
    }

	public string ToStringForDateTime(DateTime datetime)
	{
		string date_str = datetime.ToString("dd/MM/yyyy HH:mm:ss");
		return date_str;
	}

	public DateTime DateTimeString(string dateStr)
	{
		DateTime Date = Convert.ToDateTime(dateStr);

		return Date;
	}

	public void input()
    {
		Console.WriteLine("Input CMTND:");
		CMTND = Console.ReadLine();
		inputWithCMTND();
	}

	public void inputWithCMTND()
    {
		Console.WriteLine("Name:");
		Name = Console.ReadLine();

		Console.WriteLine("Birthday:");
		string str = Console.ReadLine();
		Birthday = DateTimeString(str);

		Console.WriteLine("Gender:");
		Gender = Console.ReadLine();

		Console.WriteLine("Address:");
		Address = Console.ReadLine();
	}

	public void display()
    {
		Console.WriteLine("Name: {0}\nCMTND: {1}\nAge: {2}\nGender:{3}\nAddress:{4}", Name, CMTND, 
			Birthday.Year - DateTime.Now.Year, Gender, Address);
    }
}


#Hotel.cs


using System;
using System.Collections.Generic;

public class Hotel
{
	public List<Room> RoomList { get; set; }
	public string Id { get; set; }
	public string Name { get; set; }

	public string Type { get; set; }

	public string Address { get; set; }
	public Hotel()
	{
		RoomList = new List<Room>();
	}

	public Hotel(List<Room> RoomList, string Id, string Name, string Type, string Address)
    {
		this.RoomList = RoomList;
		this.Id = Id;
		this.Name = Name;
		this.Type = Type;
		this.Address = Address;
    }

	public void input()
    {
		Console.WriteLine("Code of the Hotel:");
		Id = Console.ReadLine();
		Console.WriteLine("Name:");
		Name = Console.ReadLine();
		Console.WriteLine("Address:");
		Address = Console.ReadLine();
		Console.WriteLine("Hotel Type:");
		Type = Console.ReadLine();
		
	}

	public void display()
    {
		Console.WriteLine("Name: {0}, Address: {1}, Hotel Type: {2}, Hotel Code: {3}", Name, Address, Type, Id);
		Console.WriteLine("Room List:");
		foreach (Room room in RoomList)
        {
			room.display();
        }
    }

}


#Room.cs


using System;

public class Room
{
	private string roomName;
	public string RoomName { get { return roomName; } set { this.roomName = value; } }
	private float price;
	public float Price { get { return price; } set { this.price = value; } }
	private int floor;
	public int Floor { get { return floor; } set { this.floor = value; } }
	private int maxOccupants;
	public int MaxOccupants { get { return maxOccupants; } set { this.maxOccupants = value; } }
	public string RoomCode { get; set; }
	public Room()
	{

	}

	public Room(string RoomName, float Price, int Floor, int MaxOccupants, string RoomCode)
	{
		this.RoomName = RoomName;
		this.Price = Price;
		this.Floor = Floor;
		this.MaxOccupants = MaxOccupants;
		this.RoomCode = RoomCode;
	}

	public void input()
    {
		Console.WriteLine("Enter the Name of the Room: ");
		RoomName = Console.ReadLine();

		Console.WriteLine("Enter the Code of the Room: ");
		RoomCode = Console.ReadLine();

		Console.WriteLine("Enter the Floor: ");
		string f = Console.ReadLine();
		while (!IsNumber(f)){
			Console.WriteLine("This need to be numeric input.");
			f = Console.ReadLine();
		}
		Floor = int.Parse(f);

		Console.WriteLine("Enter the Price: ");
		string p = Console.ReadLine();
		while (!IsNumber(p))
		{
			Console.WriteLine("This need to be numeric input.");
			p = Console.ReadLine();
		}
		Price = float.Parse(p);

		Console.WriteLine("Enter the amount of peoples: ");
		string m = Console.ReadLine();
		while (!IsNumber(m))
		{
			Console.WriteLine("This need to be numeric input.");
			m = Console.ReadLine();
		}
		MaxOccupants = int.Parse(m);

	}

	public void display()
    {
		Console.WriteLine("\nRoom Name: {0}\nRoom Code: {1}\nFloor: {2}\nPrice: {3}\nNo.Peoples: {4}",
			RoomName, RoomCode, Floor, Price, MaxOccupants);
    }

	static bool IsNumber(string value)
	{
		if (string.IsNullOrEmpty(value))
		{
			return false;
		}
		char[] c = value.ToCharArray();
		for (int i = 0; i < c.Length; i++)
		{
			if (!char.IsDigit(c[i]))
			{
				return false;
			}
		}

		return true;
	}
}


#Program.cs


using System;
using System.Collections.Generic;

namespace HotelManagement
{
    class Program
    {
        public static List<Customer> Customers = new List<Customer>();
        public static List<Hotel> Hotels = new List<Hotel>();
        public static List<Book> Books = new List<Book>();
        static bool IsNumber(string value)
        {
            if(string.IsNullOrEmpty(value))
            {
                return false;
            }
            char[] c = value.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (!char.IsDigit(c[i]))
                {
                    return false;
                }
            }

            return true;
        }

        static void ShowMenu()
        {
            Console.WriteLine("1. Insert new Hotels\n" + 
                "2. Display Hotels\n" + 
                "3. New Booking\n" + 
                "4. Find Rooms by Book Date and Return Date\n" +
                "5. Total profits from each Hotels\n" +
                "6. Find Customer by CMTND\n" +
                "7. Exit");
        }

        static void InputHotels()
        {
            Console.WriteLine("Please input the number of hotels to add:");
            string input = Console.ReadLine();
            while (!IsNumber(input))
            {
                Console.WriteLine("Wrote a number");
                input = Console.ReadLine();   
            }
            int N = int.Parse(input);
            for (int i = 0; i < N; i++)
            {
                Hotel h = new Hotel();
                h.input();
                Console.WriteLine("Input the number of rooms to add: ");
                input = Console.ReadLine();
                while (!IsNumber(input))
                {
                    Console.WriteLine("Wrote a number");
                    input = Console.ReadLine();
                }
                int NN = int.Parse(input);
                for (int j = 0; j < NN; j++)
                {
                    Room r = new Room();
                    r.input();
                    h.RoomList.Add(r);
                }
                Hotels.Add(h);
            }

        }

        static void DisplayHotels()
        {
            if (Hotels.Count == 0)
            {
                return;
            }
            foreach(Hotel h in Hotels)
            {
                h.display();
            }
        }

        static void NewBooking()
        {
            if(Hotels.Count == 0)
            {
                return;
            }
            Console.WriteLine("Input how many Room Book to make: ");
            string input = Console.ReadLine();
            while (!IsNumber(input))
            {
                Console.WriteLine("Wrote a number");
                input = Console.ReadLine();
            }
            int N = int.Parse(input);
            for (int i = 0; i < N; i++)
            {
                Book b = new Book();
                b.input(Customers, Hotels);
                Books.Add(b);
            }
        }
        static void FindRooms()
        {
            if (Books.Count == 0 || Hotels.Count == 0)
            {
                return;
            }
            Console.WriteLine("Enter the Book Date: ");
            DateTime bd = Convert.ToDateTime(Console.ReadLine());
            Console.WriteLine("Enter the Return Date: ");
            DateTime rd = Convert.ToDateTime(Console.ReadLine());
            foreach(Book b in Books){
                foreach(Hotel h in Hotels)
                {
                    if (h.Id == b.HotelCode)
                    {
                        if (b.ReturnDate <= rd && b.BookDate >= bd)
                        {
                            b.DisplayRoomMenu(h);
                        }
                        
                    }
                }
                
            }
                    
        }

        static void ShowProfits()
        {
            if (Hotels.Count == 0)
            {
                return;
            }
            float TotalProfits = 0;
            foreach(Hotel h in Hotels)
            {
                float HotelProfit = 0;
                for (int i = 0; i < h.RoomList.Count; i++)
                {
                    HotelProfit += h.RoomList[i].Price;
                    TotalProfits += h.RoomList[i].Price;
                }
                Console.WriteLine("Profits generated by hotel {0}: {1}", h.Name, HotelProfit);
            }

        }
        static void FindCustomer()
        {
            if (Customers.Count == 0)
            {
                return;
            }

            Console.WriteLine("Enter CMTND:");
            string str = Console.ReadLine();
            foreach(Customer c in Customers)
            {
                if(c.CMTND == str)
                {
                    c.display();
                }
            }
        }
        static void Main(string[] args)
        {
            
            int choose;
            do
            {
                ShowMenu();
                var input = Console.ReadLine();
                while (!IsNumber(input))
                {
                    input = Console.ReadLine();
                }
                choose = int.Parse(input);
                switch (choose)
                {
                    case 1:
                        InputHotels();
                        break;
                    case 2:
                        DisplayHotels();
                        break;
                    case 3:
                        NewBooking();
                        break;
                    case 4:
                        FindRooms();
                        break;
                    case 5:
                        ShowProfits();
                        break;
                    case 6:
                        FindCustomer();
                        break;
                    case 7:
                        break;
                    default:
                        Console.WriteLine("Enter valid number input");
                        break;
                }

            } while(choose != 7);
        }
    }
}


avatar
Do Trung Duc [T2008A]
2021-06-03 08:55:59



using System;
using System.Collections.Generic;
using System.Text;

namespace DevelopHoteProject.Modal
{
    class Hotel
    {
        public List<Room> RoomList  { get; set; }
        public string Id { get; set; }
        public string Name { get; set; }

        public string Lever { get; set; }

        public string Address { get; set; }

        public Hotel() { }
    }
}


avatar
Do Trung Duc [T2008A]
2021-06-03 08:55:35



using System;
using System.Collections.Generic;
using System.Text;

namespace DevelopHoteProject.Modal
{
    class Customer
    {
        public string IdentifyNumber { get; set; }
        public string Name { get; set; }
        public DateTime Birthday { get; set; }

        public string Gender { get; set; }
        public string Address { get; set; }

        public Customer() { }

        public Customer(string IdentifyNumber, string Name, DateTime Birthday, string Gender, string Address)
        {
            this.IdentifyNumber = IdentifyNumber;
            this.Name = Name;
            this.Birthday = Birthday;
            this.Gender = Gender;
            this.Address = Address;
        }

        public void Input()
        {
            Console.WriteLine("Nhap so CMT Khach Hang:");
            IdentifyNumber = Console.ReadLine();

            Console.WriteLine("Nhap Ten Khach Hang:");
            Name = Console.ReadLine();

            Console.WriteLine("Nhap Ngay Sinh Khach Hang theo Ngay/Thang/Nam");
            string str = Console.ReadLine();
            Birthday = ToDateTimeFromString(str);

            Console.WriteLine("Nhap Gioi tinh Khach Hang:");
            Gender = Console.ReadLine();

            Console.WriteLine("Nhap Dia chi Khach Hang:");
            Address = Console.ReadLine();
        }

        public string ToStringFromDateTime(DateTime datetime)
        {
            string date_str = datetime.ToString("dd/MM/yyyy HH:mm:ss");
            return date_str;
        }

        public DateTime ToDateTimeFromString(string dateStr)
        {
            DateTime Date = DateTime.ParseExact(dateStr, "dd/MM/yyyy HH:mm:ss",
                                       System.Globalization.CultureInfo.InvariantCulture);

            return Date;
        }
    }
}


avatar
Do Trung Duc [T2008A]
2021-06-03 08:55:12



using System;
using System.Collections.Generic;
using DevelopHoteProject.Modal;

namespace DevelopHoteProject
{
    class Program
    {
        public static List<Hotel> HotelList = new List<Hotel>();
        public static List<Customer> CustomerList = new List<Customer>();
        public static List<Book> BookList = new List<Book>();
        static void Main(string[] args)
        {
   
        }
    }
}


avatar
Do Trung Duc [T2008A]
2021-06-03 08:55:12



using System;
using System.Collections.Generic;
using DevelopHoteProject.Modal;

namespace DevelopHoteProject
{
    class Program
    {
        public static List<Hotel> HotelList = new List<Hotel>();
        public static List<Customer> CustomerList = new List<Customer>();
        public static List<Book> BookList = new List<Book>();
        static void Main(string[] args)
        {
   
        }
    }
}


avatar
Do Trung Duc [T2008A]
2021-06-03 08:54:59



using System;
using System.Collections.Generic;
using System.Text;

namespace DevelopHoteProject.Modal
{   
    class Room
    {
        public string Id { get; set; }
        public string Name { get; set; }
        public float Price { get; set; }
        public int Floor { get; set; }
        public int MaxPeople { get; set; }

        public Room() { }

        public Room(string Id, string Name, float Price, int Floor, int MaxPeople)
        {
            this.Id = Id;
            this.Name = Name;
            this.Price = Price;
            this.Floor = Floor;
            this.MaxPeople = MaxPeople;
        }

        public void Input()
        {
            Console.WriteLine("Nhap so ID cua phong:");
            Id = Console.ReadLine();

            Console.WriteLine("Nhap Ten Phong:");
            Name = Console.ReadLine();

            Console.WriteLine("Nhap gia phong: ");
            float Price = float.Parse(Console.ReadLine());
            

            Console.WriteLine("Nhap Tang:");
           Floor = Int32.Parse(Console.ReadLine());

            Console.WriteLine("Nhap so nguoi toi da:");
            MaxPeople = Int32.Parse(Console.ReadLine());
        }


        public void Display()
        {
            Console.WriteLine("ID Phong: {0}, Ten Phong: {1}, Gia Phong: {2}, Tang: {3}, So nguoi toi da {4}", Id,Name, Price,Floor,MaxPeople);
        }
    }
}


avatar
Do Trung Duc [T2008A]
2021-06-03 08:49:25



using System;
using System.Collections.Generic;
using System.Text;

namespace DevelopHoteProject.Modal
{
    class Book
    {
        public DateTime CheckInTime { get; set; }
        public DateTime CheckOutTime { get; set; }
        public string IdentifyNumberBooker { get; set; }
        public string HotelBookId { get; set; }
        public string RoomBookId { get; set; }

        public Book() { }

        public void Input()
        {
          
                Console.WriteLine("Nhap thoi gian checkin Ngay/thang/nam/gio/phut/giay:");
                string strIn = Console.ReadLine();
                CheckInTime = ToDateTimeFromString(strIn);

                Console.WriteLine("Nhap thoi gian checkout Ngay/thang/nam/gio/phut/giay:");
                string strOut = Console.ReadLine();
                CheckOutTime = ToDateTimeFromString(strOut);

            while (true)
            {
                bool exitsbooker = false;
                Console.WriteLine("Nhap so CMT nguoi dat phong:");
                IdentifyNumberBooker = Console.ReadLine();
                foreach (Customer customer in Program.CustomerList)
                {
                    if(customer.IdentifyNumber == IdentifyNumberBooker)
                    {
                        exitsbooker = true;
                        break;
                    }
                }
                if(exitsbooker == true)
                {
                    break;
                }else
                {
                    Console.WriteLine("Khach hang chua ton tai trong he thon, de nghi nhap thong tin khach hang:");
                    Customer customer = new Customer();
                    customer.Input();
                    Program.CustomerList.Add(customer);
                    break;
                }
            }

          
           
            while (true)
            {
                bool CheckId = false;
                Console.WriteLine("Nhap Id khach san dat phong:");
                string id = Console.ReadLine();
                foreach(Hotel hotel in Program.HotelList)
                {
                    if (id == hotel.Id)
                    {
                        CheckId = true;
                        HotelBookId = id;
                        break;
                    }
                }
                if(CheckId ==  true)
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Nhap ID khach san sai, nhap lai:");
                }
            }


            while (true)
            {
                bool exitsIDRoom = false;
                Console.WriteLine("Nhap Id phong muon dat:");
                string idFind = Console.ReadLine();
                foreach (Hotel hotel in Program.HotelList)
                {
                    if(hotel.Id == HotelBookId)
                    {
                        foreach (Room room in hotel.RoomList)
                        {
                            if(room.Id == idFind)
                            {
                                RoomBookId = idFind;
                                exitsIDRoom = true;
                                break;
                            }
                        }
                    }
                }
                if(exitsIDRoom == true)
                {
                    break;
                }else
                {
                    Console.WriteLine("Khong co phong nao co dia chi Id phu hop, nhap lai:");
                }
                    
            }
           
            
        }

        public DateTime ToDateTimeFromString(string dateStr)
        {
            DateTime Date = DateTime.ParseExact(dateStr, "dd/MM/yyyy HH:mm:ss",
                                       System.Globalization.CultureInfo.InvariantCulture);

            return Date;
        }






    }
}


avatar
Nguyễn Tiến Đạt [T2008A]
2021-06-02 14:23:37


#Program.cs


using System;
using System.Collections.Generic;
using QuanLyKhachSan.Modals;

namespace QuanLyKhachSan
{
    class Program
    {
        static List<Customer> custommerList = new List<Customer>();
        static List<Hotel> hotelList = new List<Hotel>();
        static List<Book> bookList = new List<Book>();
        static void Main(string[] args)
        {
            int choose = 0;
            do
            {
                showMenu();
                choose = int.Parse(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        AddHotels();
                        break;
                    case 2:
                        DisplayHotels();
                        break;
                    case 3:
                        AddBook();
                        break;
                    case 4:
                        SearchRoom();
                        break;
                    case 5:
                        MoneyCheck();
                        break;
                    case 6:
                        CMNDCheck();
                        break;
                    case 7:
                        Console.WriteLine("Tam biet!!");
                        break;
                    default:
                        Console.WriteLine("Nhap sai!!");
                        break;
                }
            } while (choose != 7);
        }

        private static void CMNDCheck()
        {
            Console.WriteLine("Nhap CMND can tim:");
            string cmnd = Console.ReadLine();
            int check = 0;
            foreach (Customer customer in custommerList)
            {
                if (customer.cmt == cmnd)
                {
                    check++;
                    Console.WriteLine("{0} da di den khach san:", customer.name);
                    break;
                }
            }
            foreach (Book book in bookList)
            {
                if(book.cmt == cmnd)
                {
                    foreach (Hotel hotel in hotelList)
                    {
                        if (hotel.hotelCode == book.hotelCode)
                        {
                            Console.WriteLine("{0}", hotel.name);
                        }
                    }
                }
            }
            if (check == 0) Console.WriteLine("Khong tim thay nguoi can tim!!");
        }

        private static void MoneyCheck()
        {
            foreach (Hotel hotel in hotelList)
            {
                float sum = 0;
                foreach (Room room in hotel.roomList)
                {
                    sum += room.price;
                }
                Console.WriteLine("So tien khach san {0} thu duoc ve la: {1}", hotel.name, sum);
            }
        }

        private static void SearchRoom()
        {
            Console.WriteLine("Nhap ngay lay phong (dd/MM/yyyy):");
            string bookdayString = Console.ReadLine();
            Console.WriteLine("Nhap ngay tra phong (dd/MM/yyyy):");
            string renderdayString = Console.ReadLine();
            int check = 0;
            foreach (Book book in bookList)
            {
                string bookDay = book.bookDay.ToString("dd/MM/yyyy");
                string renderDay = book.renderDay.ToString("dd/MM/yyyy");
                if(bookdayString.Equals(bookDay) && renderdayString.Equals(renderDay))
                {
                    check++;
                    foreach (Hotel hotel in hotelList)
                    {
                        foreach (Room room in hotel.roomList)
                        {
                            if(room.roomCode == book.roomCode)
                            {
                                Console.WriteLine("Khach san: {0}", hotel.name);
                                room.display();
                            }
                        }
                    }
                }
            }
            if (check == 0) Console.WriteLine("Khong co phong nao thoa man!!");
        }

        private static void AddBook()
        {
            Book book = new Book();
            Console.WriteLine("Nhap so CMND:");
            string cmnd = Console.ReadLine();
            int check = 0;
            book.cmt = cmnd;
            foreach (Customer customer in custommerList)
            {
                if(customer.cmt == cmnd)
                {
                    check++;
                    break;
                }
            }
            if(check == 0)
            {
                Console.WriteLine("Khach hang khong ton tai, yeu cau nhap thong tin khach hang:");
                Customer customer = new Customer();
                customer.cmt = cmnd;
                customer.input();
                custommerList.Add(customer);
            }
            Console.WriteLine("Nhap ngay lay phong (dd/MM/yyyy):");
            string bookdayString = Console.ReadLine();
            DateTime bookDay = DateTime.ParseExact(bookdayString, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
            book.bookDay = bookDay;
            Console.WriteLine("Nhap ngay tra phong (dd/MM/yyyy):");
            string renderdayString = Console.ReadLine();
            DateTime renderDay = DateTime.ParseExact(renderdayString, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
            book.renderDay = renderDay;
            Console.WriteLine("Nhap ma khach san:");
            while (true)
            {
                string hotelCode = Console.ReadLine();
                int check1 = 0;
                foreach (Hotel hotel in hotelList)
                {
                    if(hotel.hotelCode == hotelCode)
                    {
                        check1++;
                        book.hotelCode = hotelCode;
                        break;
                    }
                }
                if (check1 == 0) Console.WriteLine("Khong tim thay khach san, vui long nhap lai:");
                else break;
            }
            Console.WriteLine("Nhap ma phong:");
            while (true)
            {
                string hotelCode = book.hotelCode;
                string roomCode = Console.ReadLine();
                int check1 = 0;
                foreach (Hotel hotel in hotelList)
                {
                    if (hotel.hotelCode == hotelCode)
                    {
                        foreach (Room room in hotel.roomList)
                        {
                            if(room.roomCode == roomCode)
                            {
                                check1++;
                                book.roomCode = roomCode;
                                break;
                            }
                        }
                        break;
                    }
                }
                if (check1 == 0) Console.WriteLine("Khong tim thay phong, vui long nhap lai:");
                else break;
            }
            bookList.Add(book);
        }

        private static void DisplayHotels()
        {
            for (int i = 0; i < hotelList.Count; i++)
            {
                Console.WriteLine("Thong tin khach san thu " + (i + 1) + ":");
                hotelList[i].display();
            }
        }

        private static void AddHotels()
        {
            Console.WriteLine("Nhap so luong khach san muon them:");
            int hotelNum = int.Parse(Console.ReadLine());
            for (int i = 1; i <= hotelNum; i++)
            {
                Console.WriteLine("Nhap thong tin cho khach san thu " + i + ":");
                Hotel hotel = new Hotel();
                hotel.input();
                List<Room> roomList = new List<Room>();
                Console.WriteLine("Nhap so luong phong muon them:");
                int roomNum = int.Parse(Console.ReadLine());
                for (int j = 1; j <= roomNum; j++)
                {
                    Console.WriteLine("Nhap thong tin cho phong thu " + j + ":");
                    Room room = new Room();
                    room.input();
                    roomList.Add(room);
                }
                hotel.roomList = roomList;
                hotelList.Add(hotel);
            }
        }

        private static void showMenu()
        {
            Console.WriteLine("Lua chon chuong trinh:");
            Console.WriteLine("1.Nhap them khach san");
            Console.WriteLine("2.In toan bo thong tin lien quan den khach san");
            Console.WriteLine("3.Nhap thong tin dat phong");
            Console.WriteLine("4.Tim phong thoa man ngay");
            Console.WriteLine("5.Tong tien moi khach san thu duoc");
            Console.WriteLine("6.Nhap CMND de tim khach san nguoi no da den");
            Console.WriteLine("7.Thoat");
        }
    }
}


#Book.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLyKhachSan.Modals
{
    class Book
    {
        public DateTime bookDay { get; set; }
        public DateTime renderDay { get; set; }
        public string cmt { get; set; }
        public string hotelCode { get; set; }
        public string roomCode { get; set; }
    }
}


#Customer.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLyKhachSan.Modals
{
    class Customer
    {
        public string cmt { get; set; }
        public string name { get; set; }
        public int age { get; set; }
        public string gender { get; set; }
        public string country { get; set; }
        public Customer()
        {

        }
        public Customer(string cmt,string name, int age, string gender,string country)
        {
            this.cmt = cmt;
            this.name = name;
            this.age = age;
            this.gender = gender;
            this.country = country;
        }
        public void input()
        {
            Console.WriteLine("Ten:");
            name = Console.ReadLine();
            Console.WriteLine("Tuoi:");
            age = int.Parse(Console.ReadLine());
            Console.WriteLine("Gioi tinh:");
            gender = Console.ReadLine();
            Console.WriteLine("Que quan:");
            country = Console.ReadLine();
        }
        public void display()
        {
            Console.WriteLine("CMND: {0}, Ten: {1}, Tuoi: {2}, Gioi tinh: {3}, Que quan: {4}", cmt, name, age, gender, country);
        }
    }
}


#Hotel.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLyKhachSan.Modals
{
    class Hotel
    {
        public string name { get; set; }
        public string address { get; set; }
        public string hotelType { get; set; }
        public List<Room> roomList { get; set; }
        public string hotelCode { get; set; }

        public Hotel()
        {
            roomList = new List<Room>();
        }
        public Hotel(string name, string address, string hotelType, List<Room> roomList, string hotelCode)
        {
            this.name = name;
            this.address = address;
            this.hotelType = hotelType;
            this.roomList = roomList;
            this.hotelCode = hotelCode;
        }
        public void input()
        {
            Console.WriteLine("Ten:");
            name = Console.ReadLine();
            Console.WriteLine("Dia chi:");
            address = Console.ReadLine();
            Console.WriteLine("Loai khach san:");
            hotelType = Console.ReadLine();
            Console.WriteLine("Ma khach san:");
            hotelCode = Console.ReadLine();
        }
        public void display()
        {
            Console.WriteLine("Ten: {0}, Dia chi: {1}, Loai khach san: {2}, Ma khach san: {3}", name, address, hotelType, hotelCode);
            Console.WriteLine("Danh sach phong:");
            foreach (Room room in roomList)
            {
                room.display();
            }
        }
    }
}


#Room.cs


using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLyKhachSan.Modals
{
    class Room
    {
        public string name { get; set; }
        public float price { get; set; }
        public int floor { get; set; }
        public int maximumPeople { get; set; }
        public string roomCode { get; set; }
        public Room()
        {

        }
        public Room(string name, float price, int floor, int maximumPeople, string roomCode)
        {
            this.name = name;
            this.price = price;
            this.floor = floor;
            this.maximumPeople = maximumPeople;
            this.roomCode = roomCode;
        }
        public void input()
        {
            Console.WriteLine("Ten:");
            name = Console.ReadLine();
            Console.WriteLine("Gia:");
            price = float.Parse(Console.ReadLine());
            Console.WriteLine("Tang:");
            floor = int.Parse(Console.ReadLine());
            Console.WriteLine("So nguoi toi da:");
            maximumPeople = int.Parse(Console.ReadLine());
            Console.WriteLine("Ma phong:");
            roomCode = Console.ReadLine();
        }
        public void display()
        {
            Console.WriteLine("Ten: {0}, Gia: {1}, Tang: {2}, So nguoi toi da: {3}, Ma phong: {4}", name, price, floor, maximumPeople, roomCode);
        }
    }
}


avatar
Đỗ Minh Quân [T2008A]
2021-06-02 09:14:07



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotel
{
    class Room
    {
        public string Name { get; set; }
        public int Price { get; set; }
        public int Floor { get; set; }
        public int people { get; set; }
        public string coderoom { get; set; }

        public Room()
        {

        }
        public Room(string Name, int Price, int Floor, int PersonalMax, string coderoom)
        {
            this.Name = Name;
            this.Price = Price;
            this.Floor = Floor;
            this.people =people;
            this.coderoom = coderoom;
        }
        public void Input()
        {
            Console.WriteLine("Nhap Ten Phong:");
            Name = Console.ReadLine();
            Console.WriteLine("Nhap Gia:");
            Price = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Nhap So Tang:");
            Floor = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Nhap So Nguoi Toi Da:");
            people = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Nhap Ma Phong:");
            coderoom = Console.ReadLine();
        }
        public void Display()
        {
            Console.WriteLine("Room (Ten Phong : {0}, Gia Phong : {1}, So Tang : {2}, So Nguoi Toi Da : {3}, Ma Phong : {4} )", Name, Price, Floor, PersonalMax, No);
        }
    }
}

## room