IMG-LOGO
×

Giáo Trình Học

Khoá học lập trình C# (.NET Core)

Kiến Thức Căn Bản - Khai Báo Biến, Toán Tử, Mệnh Đề Điều Kiện, Lặp

[Video] Giới thiệu về ngôn ngữ lập trình C# & .NET Framework + Khai báo biến trong C# [Video] Hướng dẫn tìm hiểu biến + toán tử trong lập trình C# [Video] Hướng dẫn tìm hiểu mệnh đề điều kiện if - else - switch trong C# [Video] Tìm dãy số nguyên tố - Lập trình C# - Loop trong C# [Video] In dãy số chẵn & lẻ từ mảng số nguyên - Lập trình C# - Loop trong C#




Trang Chủ C Sharp [Assignment] Bài tập ôn luyên tổng quát C# - Lập Trình C# - Lập Trình C Sharp

[Assignment] Bài tập ôn luyên tổng quát C# - Lập Trình C# - Lập Trình C Sharp

by GokiSoft.com - 09:41 01/11/2021 15,494 Lượt Xem

Đề 1: Tạo ứng dụng calculator bằng giao diện (Winform Application) gồm các chức năng sau

- Tạo máy tính gồm các chức năng cơ bản

- Lưu lại toàn bộ lịch sử đã thực hiện các phép tính vào file hoặc CSDL

Đề 2 : Tạo ứng dụng quản lý khách sạn (Dùng console hoặc Winform -> tuỳ chọn)

Note : Form sẽ đc nhiều điểm hơn

Gồm các chức năng

- Thêm/Sửa/Xoá KS

- Thêm sửa xoá khách hàng

- Quản lý đặt phòng

- Tìm kiếm.


Bình luận



Chia sẻ từ lớp học

hainguyen [T2008A]

Ngày viết: 17:08 02/06/2021


#Book.cs


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

namespace AS.De1
{
    class Book
    {
        int Checkin { get; set; }
        int Checkout { get; set; }
        public string CMT { get; set; }
        public string HotelNo { get; set; }
        public string RoomNo { get; set; }

        public Book() { }

        public Book(int Checkin, int Checkout, string CMT, string HotelNo, string RoomNo)
        {
            this.Checkin = Checkin;
            this.Checkout = Checkout;
            this.CMT = CMT;
            this.HotelNo = HotelNo;
            this.RoomNo = RoomNo;
        }

        public void input(List<Custumer> custumerlist, List<Hotel> hotellist)
        {
            Console.WriteLine("Nhap CMT khach hang: ");
            CMT = Console.ReadLine();
            bool isFind = false;
            for (int i = 0; i < custumerlist.Count; i++)
            {
                if (custumerlist[i].CMT.Equals(CMT))
                {
                    isFind = true;
                    break;
                }
            }
            if ( !isFind)
            {
                Console.WriteLine("Khach hang ko ton tai!");
                Custumer custumer = new Custumer();
                custumer.CMT = CMT;
                custumer.InputCMT();
            }

            displayHotelMenu(hotellist);
            Hotel hotel = null;
            while (true)
            {
                HotelNo = Console.ReadLine();
                isFind = false;
                for (int i = 0; i < hotellist.Count; i++)
                {
                    if (hotellist[i].No.Equals(HotelNo))
                    {
                        isFind = true;
                        hotel = hotellist[i];
                        break;
                    }
                }
                if ( !isFind)
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Nhap lai ma khach san!");
                }
            }

            displayRoomMenu(hotel);
            while (true)
            {
                RoomNo = Console.ReadLine();
                isFind = false;
                for (int i = 0; i < hotel.roomlist.Count; i++)
                {
                    if (hotel.roomlist[i].No.Equals(RoomNo))
                    {
                        isFind = true;
                        break;
                    }
                }
                if ( !isFind)
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Nhap lai ma phong!");
                }
            }
            Console.WriteLine("Nhap Ngay Dat Phong:");
            Checkin = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Nhap Ngay Tra Phong:");
            Checkout = Convert.ToInt32(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].No);
            }
            Console.WriteLine("Nhap ma khach san can chon: ");
        }

        public void displayRoomMenu(Hotel hotel)
        {
            for (int i = 0; i < hotel.roomlist.Count; i++)
            {
                Console.WriteLine("{0}. - {1} - {2}", i + 1, hotel.roomlist[i].Name, hotel.roomlist[i].No);
            }
            Console.WriteLine("Nhap ma phong can tron");
        }
    }
}


#Custumer.cs


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

namespace AS.De1
{
    class Custumer
    {
        public string CMT { get; set; }
        public string Fullname { get; set; }
        public int Age { get; set; }
        public string Gender { get; set; }
        public string Address { get; set; }

        public Custumer() { }

        public Custumer(string CMT, string Fullname, int Age, string Gender, string Address)
        {
            this.CMT = CMT;
            this.Fullname = Fullname;
            this.Age = Age;
            this.Gender = Gender;
            this.Address = Address;
        }

        public void input()
        {
            Console.WriteLine("Nhap so CMT: ");
            CMT = Console.ReadLine();
            InputCMT();
        }

        public void InputCMT()
        {
            Console.WriteLine("Nhap ho ten: ");
            Fullname = Console.ReadLine();
            Console.WriteLine("Nhap tuoi: ");
            Age = int.Parse(Console.ReadLine());
            Console.WriteLine("Nhap gender: ");
            Gender = Console.ReadLine();
            Console.WriteLine("Nhap Address: ");
            Address = Console.ReadLine();
        }

        public void display()
        {
            Console.WriteLine("Ho ten: = {0}", Fullname);
            Console.WriteLine("So CMT: = {0}", CMT);
            Console.WriteLine("Tuoi: = {0}", Age);
            Console.WriteLine("Gioi tinh: = {0}", Gender);
            Console.WriteLine("Dia Chi: = {0}", Address);
        }
    }
}


#Hotel.cs


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

namespace AS.De1
{
    class Hotel
    {
        public string No { get; set; }
        public string Name { get; set; }
        public string Address { get; set; }
        public string Type { get; set; }
        public List<Room> roomlist = new List<Room>();

        public Hotel() { }

        public Hotel(string No, string Name, string Address, string Type)
        {
            this.No = No;
            this.Name = Name;
            this.Address = Address;
            this.Type = Type;
        }

        public void input()
        {
            Console.WriteLine("Nhap ma KS: ");
            No = Console.ReadLine();
            Console.WriteLine("Nhap ten khach san: ");
            Name = Console.ReadLine();
            Console.WriteLine("Nhap Address: ");
            Address = Console.ReadLine();
            Console.WriteLine("Nhap Type: ");
            Type = Console.ReadLine();
            Console.WriteLine("Nhap so phong can them: ");
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                Room room = new Room();
                room.input();
                roomlist.Add(room);
            }
        }

        public void display()
        {
            Console.WriteLine("Hotel(Ten Khach San : {0}, Dia Chi : {1}, Loai Khach San : {2})", Name, Address, Type);
            for (int i = 0; i < roomlist.Count; i++)
            {
                roomlist[i].display();
            }
        }

        public void DisplayBase()
        {
            Console.WriteLine("Hotel(Ten Khach San : {0}, Dia Chi : {1}, Loai Khach San : {2})", Name, Address, Type);
        }
    }
}


#Program.cs


using System;
using System.Collections.Generic;

namespace AS.De1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Custumer> custumerlist = new List<Custumer>();
            List<Hotel> hotellist = new List<Hotel>();
            List<Book> booklist = new List<Book>();
            int choose;

            do
            {
                showMenu();
                choose = int.Parse(Console.ReadLine());

                switch (choose)
                {
                    case 1:
                        Input(hotellist);
                        break;
                    case 2:
                        Display(hotellist);
                        break;
                    case 3:
                        InputBook(hotellist, custumerlist, booklist);
                        break;
                    case 4:
                        SearchBook(hotellist, booklist);
                        break;
                    case 5:
                        ThongKe(booklist, hotellist);
                        break;
                    case 6:
                        Search(booklist, hotellist);
                        break;
                    case 7:
                        Environment.Exit(0);
                        break;
                    default:
                        Console.WriteLine("Fail!");
                        break;
                }
            } while (choose != 7);
        }

        static void Input(List<Hotel> hotellist)
        {
            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();
                hotellist.Add(hotel);
            }
        }

        static void Display(List<Hotel> hotellist)
        {
            for (int i = 0; i < hotellist.Count; i++)
            {
                hotellist[i].display();
            }
        }

        static void InputBook(List<Hotel> hotellist, List<Custumer> custumerlist, List<Book> booklist)
        {
            Book book = new Book();
            book.input(custumerlist, hotellist);
            booklist.Add(book);
        } 

        static void SearchBook(List<Hotel> hotellist, List<Book> booklist)
        {
            int Checkin, Checkout;
            Console.WriteLine("Nhap ngay dat phong: ");
            Checkin = int.Parse(Console.ReadLine());
            Console.WriteLine("Nhap ngay tra phong: ");
            Checkout = int.Parse(Console.ReadLine());

            for (int i = 0; i < hotellist.Count; i++)
            {
                hotellist[i].DisplayBase();
                Console.WriteLine("Danh sach phong trong: ");
                List<Room> roomlist = new List<Room>();
                for (int j = 0; j < roomlist.Count; j++)
                {
                    if (checkA(booklist, hotellist[i].No, roomlist[j], Checkin, Checkout))
                    {
                        roomlist[j].display();
                    }
                }
            }
        }

        static bool checkA(List<Book> booklist, Room room, int checkin, int checkout, string roomNo, string hotelNo)
        {
            for (int i = 0; i < booklist.Count; i++)
            {
                Book book = booklist[i];
                if (book.HotelNo.Equals(hotelNo) && book.RoomNo.Equals(roomNo) && (book.Checkin >= checkin && book.Checkin <= checkout) || (book.Checkin >= checkin && book.Checkout <= checkout))
                {
                    return false;
                }
            }
            return true;
        }

        static int Calculate(List<Book> booklist, Hotel hotel)
        {
            int total = 0;
            for (int i = 0; i < booklist.Count; i++)
            {
                if (booklist[i].HotelNo.Equals(hotel.No))
                {
                    int price = GetMoney(hotel.roomlist, booklist[i].RoomNo);
                    total += price * (booklist[i].Checkout) - booklist[i].Checkin;
                }
            }
            return total;
        }

        static int GetMoney(List<Room> roomlist, string roomNo)
        {
            for (int i = 0; i < roomlist.Count; i++)
            {
                if (roomlist[i].No.Equals(roomNo))
                {
                    return (int)roomlist[i].Price;
                }
            }
            return 0;
        }

        static void ThongKe(List<Book> booklist, List<Hotel> hotellist)
        {
            Console.WriteLine("Nhap CMTND Can Tim Kiem:");
            string cmt = Console.ReadLine();
            for (int i = 0; i < booklist.Count; i++)
            {
                if (booklist[i].Equals(cmt))
                {
                    Hotel hotel = Search(hotellist, booklist[i].HotelNo);
                    if (hotel != null)
                    {
                        hotel.DisplayBase();
                    }
                }
            }
        }

        static Hotel Search(List<Hotel> hotellist, string hotelNo)
        {
            for (int i = 0; i < hotellist.Count; i++)
            {
                if (hotellist[i].No.Equals(hotelNo))
                {
                    return hotellist[i];
                }
            }
            return null;
        }

        static void showMenu()
        {
            Console.WriteLine("1. Nhap thong tin khach san");
            Console.WriteLine("2. Hien thi thong tin khach san");
            Console.WriteLine("3. Dat phong");
            Console.WriteLine("4. Tim phong con trong");
            Console.WriteLine("5. Thong ke doanh thu");
            Console.WriteLine("6. Tim kiem thong tin khach hang");
            Console.WriteLine("7. Thoat");
            Console.WriteLine("Chon: ");
        }
    }
}


#Room.cs


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

namespace AS.De1
{
    class Room
    {
        public string Name { get; set; }
        public float Price { get; set; }
        public int Floor { get; set; }
        public int PersonalMax { get; set; }
        public string No { get; set; }

        public Room() { }

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

        public void input()
        {
            Console.WriteLine("Nhap ten phong: ");
            Name = Console.ReadLine();
            Console.WriteLine("Nhap price: ");
            Price =float.Parse(Console.ReadLine());
            Console.WriteLine("Nhap so tang: ");
            Floor =int.Parse(Console.ReadLine());
            Console.WriteLine("Nhap so nguoi toi da: ");
            PersonalMax =int.Parse(Console.ReadLine());
            Console.WriteLine("Nhap ma phong: ");
            No = Console.ReadLine();
        }

        public void display()
        {
            Console.WriteLine("Ten phong: = {0}", Name);
            Console.WriteLine("Price: = {0}", Price);
            Console.WriteLine("So tang: = {0}", Floor);
            Console.WriteLine("PersonalMax : = {0}", PersonalMax);
            Console.WriteLine("No : = {0}", No);
        }
    }
}


Nguyên Phấn Đông [T2008A]

Ngày viết: 16:20 02/06/2021


#Book.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLiKhachSan
{
    class Book
    {
        public DateTime CheckIn { get; set; }
        public DateTime CheckOut { get; set; }
        public int Identitycard { get; set; }
        public string Id_hotel { get; set; }
        public string Id_roomHotel { get; set; }

        public Book() { }
        public void display()
        {
            Console.WriteLine("CheckIn={0},CheckOut={1},Identitycard={2},Id_hotel={3},Id_roomHotel{4}", CheckIn,
                CheckOut, Identitycard, Id_hotel, Id_roomHotel);
        }
        public void input(List<Customer> listCustomers, List<Hotel> hotels)
        {
            if (hotels.Count == 0)
            {
                Console.WriteLine("Chua co du lieu");
                return;
            }
            Console.WriteLine("Nhap CMND ");
            Identitycard = Convert.ToInt32(Console.ReadLine());
            bool ischeck = false;
            foreach (var item in listCustomers)
            {
                if (item.Identitycard.Equals(Identitycard))
                {
                    ischeck = true;
                    break;
                }
            }
            if (!ischeck)
            {
                Customer customer = new Customer();
                customer.Identitycard = Identitycard;
                customer.input2();
                listCustomers.Add(customer);
            }

            //kiem tra ma id hotel can tim
            Hotel currentHotel = null;

            for (; ; )
            {
                Console.WriteLine("Danh sach khach san");
                foreach (var item in hotels)
                {
                    Console.WriteLine("Id KS={0}, Ten KS = {1}", item.Id_Hotel, item.NameHotel);
                }
                Console.WriteLine("nhap id hotel");
                Id_hotel = Console.ReadLine();
                foreach (var item in hotels)
                {
                    if (item.Id_Hotel.Equals(Id_hotel))
                    {
                        currentHotel = item;
                        break;
                    }
                }
                //
                if (currentHotel == null)
                {
                    Console.WriteLine("chon sai roi,nhap lai");
                }
                else
                {
                    break;
                }

            }
            if (currentHotel.ListRoom.Count == 0)
            {
                Console.WriteLine("khach san khong cai dat phong");
                return;
            }

            //kiem tra phong
            for (; ; )
            {
                foreach (var item in currentHotel.ListRoom)
                {
                    Console.WriteLine("Id_room={0}, Name_room={1}", item.IdRoom, item.NameRoom);
                }
                var isFind = false;
                Console.WriteLine("nhap ma phong ");
                Id_roomHotel = Console.ReadLine();
                foreach (var item in currentHotel.ListRoom)
                {
                    if (item.IdRoom.Equals(Id_roomHotel))
                    {
                        isFind = true;
                        break;
                    }
                }
                if (isFind)
                {
                    break;
                }
                else
                {
                    Console.WriteLine("not find, nhap lai");
                }

            }

            Console.WriteLine("ngay check in (dd/mm/yyyy)");
            string dateTime = Console.ReadLine();
            CheckIn = ConvertStringToDatetime(dateTime);

            Console.WriteLine("ngay check in (dd/mm/yyyy)");
            dateTime = Console.ReadLine();
            CheckOut = ConvertStringToDatetime(dateTime);

           
           
            
        }
        public DateTime ConvertStringToDatetime(string value)
        {
            
            DateTime oDate = DateTime.ParseExact(value, "dd/MM/yyyy", null);

            return oDate;
        }
    }
}


#Customer.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLiKhachSan
{
    class Customer
    {
        public int Identitycard { get; set; }
        public string FullName { get; set; }
        public int Age { get; set; }
        public string Gender { get; set; }
        public string Address { get; set; }

        public Customer() { }
        public Customer(int identitycard,string fullname,int age,string gender,string address)
        {
            Identitycard = identitycard;
            FullName = fullname;
            Age = age;
            Gender = gender;
            Address = address;
        }
        public void display()
        {
            Console.WriteLine("Identitycard={0},Fullname={1},Age={2},Gender={3},Address={4}",Identitycard,FullName,
                Age,Gender,Address);
        }

        public void input()
        {
            Console.WriteLine("input Identitycard ");
            Identitycard = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("input fulname ");
            FullName = Console.ReadLine();
            Console.WriteLine("input age");
            Age = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("input gender");
            Gender = Console.ReadLine();
            Console.WriteLine("input Address");
            Address = Console.ReadLine();
        }
        public void input2()
        {
            
            Console.WriteLine("input fulname ");
            FullName = Console.ReadLine();
            Console.WriteLine("input age");
            Age = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("input gender");
            Gender = Console.ReadLine();
            Console.WriteLine("input Address");
            Address = Console.ReadLine();
        }
    }
}


#ksan.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLiKhachSan
{
    class Hotel
    {
        public string NameHotel { get; set; }
        public string AddressHotel { get; set; }
        public enum typehotel { Vip, Binhdan };
        public typehotel Typehotel { get; set; }

        
        public List<Room> ListRoom { get; set; }

        
        public string Id_Hotel { get; set; }

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

        public void inputHotel()
        {
            Console.WriteLine("input id hotel");
            Id_Hotel = Console.ReadLine();
            Console.WriteLine("input namehotel");
            NameHotel = Console.ReadLine();
            Console.WriteLine("input addressHotel");
            AddressHotel = Console.ReadLine();
            Console.WriteLine("input type hotel");
            checkTypeHotel();
            inputRoom();
            

        }
        public void display()
        {
            Console.WriteLine("id_hotel ={0},nameHotel={1},addressHotel={2},TypeHote={3}", Id_Hotel, NameHotel, AddressHotel, Typehotel);
            Console.WriteLine("listroom hotel {0} :", NameHotel);
            foreach (var item in ListRoom)
            {

                item.display();
            }
        }

        public void checkTypeHotel()
        {
            int choose;
            do
            {
                Console.WriteLine("0: Vip");
                Console.WriteLine("1: Binhdan");
                Console.WriteLine("Choose:");
                choose = Convert.ToInt32(Console.ReadLine());

                switch (choose)
                {
                    case 0:
                        Typehotel = typehotel.Vip;

                        break;
                    case 1:
                        Typehotel = typehotel.Binhdan;

                        break;

                    default:
                        Console.WriteLine("Chon lai di");
                        break;

                }
            } while (choose > 1 || choose < 0);

        }

        
        public void inputRoom()
        {
            Console.WriteLine("input N room in Hotel");
            int n = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                Room newroom = new Room();
                newroom.input();
                Console.WriteLine("room vua nhap");
                newroom.display();
                ListRoom.Add(newroom);
            }
        }
        //update hotel 
        public void updateHotel()
        {
            int choose;
            do
            {
                Console.WriteLine("1. Edit id hotel");
                Console.WriteLine("2. Eidt namehotel");
                Console.WriteLine("3. Edit address hotel");
                Console.WriteLine("4. Edit type hotel");
                Console.WriteLine("5. Edit room hotel");
                Console.WriteLine("6. Huy");
                choose = Convert.ToInt32(Console.ReadLine());

                switch (choose)
                {
                    case 1:
                        Console.WriteLine("input id hotel");
                        Id_Hotel = Console.ReadLine();
                        break;
                    case 2:
                        Console.WriteLine("input namehotel");
                        NameHotel = Console.ReadLine();
                        break;
                    case 3:
                        Console.WriteLine("input addressHotel");
                        AddressHotel = Console.ReadLine();
                        break;
                    case 4:
                        checkTypeHotel();
                        break;
                    case 5:
                        foreach (var item in ListRoom)
                        {
                            item.updateRoom();
                        }
                        break;
                    case 6:
                        Console.WriteLine("huy thanh cong");
                        break;
                    default:
                        Console.WriteLine("Chon lai di");
                        break;


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

}

#quanly.cs

using System;
using System.Collections.Generic;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.InteropServices;

namespace QuanLiKhachSan
{
    class Manage
    {
        public static void InputInforHotel(List<Hotel> listHotel)
        {
            Console.WriteLine("input N hotel");
            int n = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                Hotel hotel = new Hotel();
                hotel.inputHotel();
                listHotel.Add(hotel);
            }


        }
        //in thong tin hotel 
        public static void showInfoHotel(List<Hotel> listHotel)
        {
            foreach (var item in listHotel)
            {
                item.display();
            }
        }

        public static Hotel searchByID(List<Hotel> listHotel)
        {
            Console.WriteLine("nhap ID khach san");
            string id_hotel = Console.ReadLine();
            Hotel ht = null;

            foreach (var item in listHotel)
            {
                if (item.Id_Hotel.Equals(id_hotel))
                {
                    ht = item;
                    break;
                }
            }
            return ht;
        }
        //deleted khach san theo id
        public static void DeletedHotel(List<Hotel> listHotel)
        {
            Hotel ht = searchByID(listHotel);
            if (ht != null)
            {
                Console.WriteLine("Xoa thanh cong id-hotel = {0}", ht.Id_Hotel);
                listHotel.Remove(ht);
                Console.WriteLine("Danh sach ks sau khi deleted");
                showInfoHotel(listHotel);
                return;
            }
            Console.WriteLine("id hotel khong ton tai ");

        }

        //edit hotel 
        public static void EditHotel(List<Hotel> listHotel)
        {
            Hotel ht = searchByID(listHotel);
            if (ht == null)
            {
                Console.WriteLine("id hotel khong ton tai");
                return;
            }
            Console.WriteLine("Thong tin khach san : {0}", ht.NameHotel);
            ht.display();
            ht.updateHotel();
            Console.WriteLine("sau khi update");
            ht.display();
        }

        //
        public static void showMenuCustomer(List<Customer> list)
        {
            int choose;
            do
            {

                Console.WriteLine("1. Them khach hang");
                Console.WriteLine("2. Sua thong tin khach hang");
                Console.WriteLine("3. Xoa khach hang");
                Console.WriteLine("4. Danh sach khach hang");
                Console.WriteLine("5. Quay lai menu chinh");
                Console.WriteLine("Choose");
                choose = Convert.ToInt32(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        inputCustomer(list);
                        break;
                    case 2:
                        EditCustomer(list);
                        break;
                    case 3:
                        deletedCustomer(list);
                        break;
                    case 4:
                        Console.WriteLine("Danh sach khach hang");
                        foreach (var item in list)
                        {
                            item.display();
                        }
                        break;
                    case 5:
                        break;
                    default:
                        Console.WriteLine("Chon sai roi");
                        break;


                }
            } while (choose != 5);

        }
        public static void inputCustomer(List<Customer> list)
        {

            Console.WriteLine("Nhap N thong tin khang hang");
            int n = int.Parse(Console.ReadLine());
            for (int i = 0; i < n; i++)
            {
                Customer customer = new Customer();
                customer.input();
                customer.display();
                list.Add(customer);
            }
        }

        //edit customer
        public static void EditCustomer(List<Customer> list)
        {
            Customer customer = searchCustomer(list);
            if (customer != null)
            {
                Console.WriteLine("Sua thong tin khach hang ");
                customer.input();
                Console.WriteLine("thong tin sau khi sua");
                foreach (var item in list)
                {
                    item.display();
                }
                return;
            }
            Console.WriteLine("Identitycard khong ton tai");
        }

        public static Customer searchCustomer(List<Customer> list)
        {
            Console.WriteLine("nhap Identitycard customer ");
            Customer ctm = null;
            int identitycard_customer = Convert.ToInt32(Console.ReadLine());
            foreach (var item in list)
            {
                if (item.Identitycard.Equals(identitycard_customer))
                {
                    ctm = item;
                    break;
                }
            }
            return ctm;
        }
        //deleted customer theo Identitycard
        public static void deletedCustomer(List<Customer> list)
        {

            Customer customer = searchCustomer(list);
            if (customer != null)
            {
                Console.WriteLine("Deleted thanh cong  Identitycard customer ={ 0}", customer.Identitycard);
                list.Remove(customer);
                return;
            }
            Console.WriteLine("Identitycard khong ton tai");
        }

        //code quan li dat phong
        //tim phong con trong
         public 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.Id_Hotel, hotel.NameHotel);
                }
                string HotelCode = Console.ReadLine();
                foreach (Hotel hotel in hotels)
                {
                    if (hotel.Id_Hotel.Equals(HotelCode))
                    {
                        currentHotel = hotel;
                        break;
                    }
                }
                if (currentHotel != null)
                {
                    break;
                }
                Console.WriteLine("(Not Found) Nhap lai: ");
            }
            if (currentHotel.ListRoom.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
         
            foreach (Room room in currentHotel.ListRoom)
            {
                //Tim da danh sach booking cho phong room.
                List<Book> currentBooking = new List<Book>();
                foreach (Book book in books)
                {
                    if (book.Id_hotel.Equals(currentHotel.Id_Hotel) && book.Id_roomHotel.Equals(room.IdRoom))
                    {
                        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)
                    {
                        
                    }
                    else
                    {
                        isFind = true;
                        break;
                    }
                }

                if (!isFind)
                {
                    Console.WriteLine("Room No: {0}, Room Name: {1}", room.IdRoom, room.NameRoom);
                }
            }
        }

        //book hotel
        public static void Booking(List<Customer> customers, List<Hotel> hotels, List<Book> listbooks)
        {
            Book book = new Book();
            book.input(customers, hotels);
            listbooks.Add(book);

        }
        //in danh sach order book
        public static void showInfoBook(List<Book> listBook)
        {
            if (listBook.Count == 0)
            {
                Console.WriteLine("Chua co du lieu");
                return;
            }
            foreach (var item in listBook)
            {
                item.display();
            }
        }

        //showmeu tim kiem
        public static void ShowMenuSearch(List<Hotel> listHotel,List<Customer> listCustomer)
        {
            int choose;
            do
            {
                Console.WriteLine("1. Tim kiem khach san");
                Console.WriteLine("2. Tim kiem khach hang");
                Console.WriteLine("3. Huy");
                Console.WriteLine("Choose: ");
                choose = Convert.ToInt32(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        if (listHotel.Count == 0)
                        {
                            Console.WriteLine("Chua co data");
                            return;
                        }
                        Hotel ht = null;
                        ht = searchByID(listHotel);
                        if(ht == null)
                        {
                            Console.WriteLine("id hotel khong chinh xac");
                            return;                          
                        }
                        ht.display();
                        break;
                    case 2:
                        if (listCustomer.Count == 0)
                        {
                            Console.WriteLine("chua co data");
                            return;
                        }
                        Console.WriteLine("nhap Identitycard khach hang can tim");
                        int search = Convert.ToInt32(Console.ReadLine());
                        Customer currentCustomer = null;
                        foreach (var item in listCustomer)
                        {
                            if (item.Identitycard== search){
                                currentCustomer = item;
                                break;
                            }
                        }
                        if(currentCustomer != null)
                        {
                            Console.WriteLine("thong tin khach hang can tim");
                            currentCustomer.display();
                            return;
                        }
                        Console.WriteLine("IdentityCard khong tim thay");
                        break;
                    case 3:
                        break;
                    default:
                        Console.WriteLine("Chon lai di");
                        break;
                }

            } while (choose != 3);
            

        }


    }

}


#program.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLiKhachSan
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            
            int choose;
            List<Hotel> hotelList = new List<Hotel>();
            var listCustomers = new List<Customer>();
            List<Book> listBooks = new List<Book>();

            do
            {
                showAllMenu();
                choose = Convert.ToInt32(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        showmenu(hotelList);
                        
                        break;
                    case 2:
                        Manage.showMenuCustomer(listCustomers);
                        break;
                    case 3:
                        showBooking(hotelList, listBooks,listCustomers);
                        break;
                    case 4:
                        Manage.ShowMenuSearch(hotelList, listCustomers);
                        break;

                }

            } while (choose !=5);
        }

        public static void showmenu(List<Hotel> list)
        {
            int choose;
            
            do
            {
                Console.WriteLine("1. Them Khach San");
                Console.WriteLine("2. Sua Khach San");
                Console.WriteLine("3. Xoa Khach San");
                Console.WriteLine("4. Quay lai menu");
                
                Console.WriteLine("Chon:");
                choose = Convert.ToInt32(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        Manage.InputInforHotel(list);
                        Manage.showInfoHotel(list);
                        break;
                    case 2:
                        Manage.EditHotel(list);
                        break;
                    case 3:
                        Manage.DeletedHotel(list);
                        break;
                    case 4:
                        
                        break;
                    default:
                        Console.WriteLine("Chon sai roi");
                        break;

                }
            } while (choose!=4);
            
            
        }
        public static void showAllMenu()
        {
            Console.WriteLine("1.Quan Li Khach San");
            Console.WriteLine("2.Quan Li Khach Hang");
            Console.WriteLine("3.Quan Li Dat Phong");
            Console.WriteLine("4.Tim Kiem");
            Console.WriteLine("5. Thoat");
            Console.WriteLine("Choose :");
        }

        public static void showBooking(List<Hotel> listHotel, List<Book> listBooks, List<Customer> customers)
        {
            int choose;
            do
            {
                Console.WriteLine("1. Tim phong trong");
                Console.WriteLine("2. Dat phong");
                Console.WriteLine("3. Xem thong tin cac phong dat");
                Console.WriteLine("4. Quay lai menu");
                Console.WriteLine("Choose: ");
                choose = Convert.ToInt32(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        Manage.FindBookingAvaiable(listHotel, listBooks);
                        break;
                    case 2:
                        Manage.Booking(customers,listHotel,listBooks);
                        break;
                    case 3:
                        Manage.showInfoBook(listBooks);
                        break;
                    case 4:
                        break;
                    default:
                        Console.WriteLine("Chon lai");
                        break;
                }
            } while (choose!= 4);

        }
    }
}


#phong.cs
using System;
using System.Collections.Generic;
using System.Text;

namespace QuanLiKhachSan
{
    class Room
    {
        public string NameRoom { get; set; }
        public int PriceRoom { get; set; }
        public string NameFloor { get; set; } // tên tầng
        public int CountMaxRoom { get; set; }
        public string IdRoom { get; set; }

        public Room() { }
        public Room(string nameRoom, int priceroom, string nameFloor, int countmaxRoom, string idRoom)
        {
            NameRoom = nameFloor;
            PriceRoom = priceroom;
            NameFloor = nameFloor;
            CountMaxRoom = countmaxRoom;
            IdRoom = idRoom;
        }
        public void display()
        {
            Console.WriteLine("nameRoom={0},priceRoom = {1},nameFloor={2},countMaxRoom ={3},Idroom={4}", NameRoom,
                PriceRoom, NameFloor, CountMaxRoom, IdRoom);
        }
        public void input()
        {
            Console.WriteLine("input idroom");
            IdRoom = Console.ReadLine();
            Console.WriteLine("input nameRoom");
            NameRoom = Console.ReadLine();
            Console.WriteLine("input priceRoom");
            PriceRoom = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("input nameFloor");
            NameFloor = Console.ReadLine();
            Console.WriteLine("input CountMaxRoom");
            CountMaxRoom = Convert.ToInt32(Console.ReadLine());

        }
        public void updateRoom()
        {
            int choose;

            do
            {
                Console.WriteLine("1. edit id room");
                Console.WriteLine("2. edit NameRoom");
                Console.WriteLine("3. edit PriceRoom");
                Console.WriteLine("4. edit NameFloor");
                Console.WriteLine("5. edit CountMaxRoom");
                Console.WriteLine("Huy");
                Console.WriteLine("Choose");
                choose = Convert.ToInt32(Console.ReadLine());
                switch (choose)
                {
                    case 1:
                        Console.WriteLine("input idroom");
                        IdRoom = Console.ReadLine();
                        break;
                    case 2:
                        Console.WriteLine("input nameRoom");
                        NameRoom = Console.ReadLine();
                        break;
                    case 3:
                        Console.WriteLine("input priceRoom");
                        PriceRoom = Convert.ToInt32(Console.ReadLine());
                        break;
                    case 4:
                        Console.WriteLine("input nameFloor");
                        NameFloor = Console.ReadLine();
                        break;
                    case 5:
                        Console.WriteLine("input CountMaxRoom");
                        CountMaxRoom = Convert.ToInt32(Console.ReadLine());
                        break;
                    case 6:
                        Console.WriteLine("huy thanh cong");
                        break;
                    default:
                        Console.WriteLine("chon sai roi, chon lai tu 1-6");
                        break;

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


Do Trung Duc [T2008A]

Ngày viết: 17:29 01/06/2021



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

namespace Assigment
{
    [Serializable]
    class Customer
    {
       public string Name { get; set; }
        public int BirthdayYear { get; set; }
        public string IdentificationNumber { get; set; }

        public Customer() { }

        public Customer(string Name, int BirthdayYear, string IdentificationNumber) {
            this.Name = Name;
            this.BirthdayYear = BirthdayYear;
            this.IdentificationNumber = IdentificationNumber;
        }

        public void Input()
        {
            Console.WriteLine("Nhap ten khach:");
            Name = Console.ReadLine();

            Console.WriteLine("Nhap nam sinh cua khach:");
            BirthdayYear  = Int32.Parse(Console.ReadLine());

            Console.WriteLine("Nhap so chung minh thu nhan dan cua khach:");
            IdentificationNumber = Console.ReadLine();
        }

        public void Display()
        {
            Console.WriteLine("Ten: {0}, Nam sinh: {1}, So CMT: {2}", Name, BirthdayYear, IdentificationNumber);
        }
    }
}


Do Trung Duc [T2008A]

Ngày viết: 17:29 01/06/2021



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

namespace Assigment
{
    [Serializable]
    class Room
       
    {
        public List<BookRoom> BookRoomList { get; set; }
       
        public string Name { get; set; }
        public string Type { get; set; }
       // public int HotelID { get; set; }

        //public string HotelName { get; set; }

        public Room()
        {
            BookRoomList = new List<BookRoom>();
        }


        public void AddBookRoom()
        {
            BookRoom bookroom = new BookRoom();
            bookroom.Input();
            BookRoomList.Add(bookroom);
        }

        public void DeleteBookRoom()
        {
            Console.WriteLine("Nhap so CMT khach hang da dat phong: ");
            string IdentitficationNumber = Console.ReadLine();
             foreach (BookRoom bookroom in BookRoomList)
            {
                if (bookroom.BookCustomerIdentification == IdentitficationNumber) {
                    BookRoomList.Remove(bookroom);
                    break;
                }
            }
        }

        public void Input()
        {
            Console.WriteLine("Nhap ten phong: ");
            Name = Console.ReadLine();
            Console.WriteLine("Nhap loai phong phong: An phim 1 neu la phong don, an phim 2 neu la phong doi: ");
            int choose = Int32.Parse(Console.ReadLine());
            if (choose == 1)
            {
                Type = "Single";
            }
            else
            {
                Type = "Double";
            }

            /*Console.WriteLine("Nhap ten khach san: ");
            HotelName = Console.ReadLine();

            Console.WriteLine("Nhap ten khach san: ");
            HotelID =  Int32.Parse(Console.ReadLine());*/
        }

        public void Dispay()
        {
            Console.WriteLine("Ten phong: {0}, Loai phong: {1}", Name, Type);
            Console.WriteLine("Chi tiet thong tin cac lich book phong nhu sau");
                foreach(BookRoom bookroom in BookRoomList)
            {
                bookroom.Display();
            }
            

        }




    }
}


Do Trung Duc [T2008A]

Ngày viết: 17:29 01/06/2021



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

namespace Assigment
{
    [Serializable]
    class BookRoom

    {
        public  List<Customer> CustomerList { get; set; }
        public DateTime CheckInTime { get; set; }
        public DateTime CheckOutTime { get; set; }

        public string BookCustomerName { get; set; }

        public string BookCustomerIdentification { get; set; }

        public int BookCustomerBirthDayYear { get; set; }

        public BookRoom()
        {
            CustomerList = new List<Customer>();
        }
        public void Input()
        {
            Console.WriteLine("Nhap ngay gio checkin:");
            CheckInTime = DateTime.Parse(Console.ReadLine());

            Console.WriteLine("Nhap ngay gio checkout:");
            CheckOutTime = DateTime.Parse(Console.ReadLine());

            Console.WriteLine("Nhap ten khach hang dat phong :");
            BookCustomerName = Console.ReadLine();

            Console.WriteLine("Nam sinh khach dat phong :");
            BookCustomerBirthDayYear = Int32.Parse(Console.ReadLine());

            Console.WriteLine("Nhap so chung minh thu khach dat phong :");
            BookCustomerIdentification = Console.ReadLine();

            Customer bookcustomer = new Customer();
            CustomerList.Add(bookcustomer);

            Console.WriteLine("Nhap tong so luong khach trong phong:");
            int CustomerNumber = Int32.Parse(Console.ReadLine());

            if (CustomerNumber > 1)
            {
                Console.WriteLine("Nhap thong tin cac khach con lai trong phong:");
                for (int i = 1; i < CustomerNumber; i++)
                {
                    Console.WriteLine("Nhap thong tin khach thu {0}:", i + 1);
                    Customer customer = new Customer();
                    customer.Input();
                    CustomerList.Add(customer);
                }
                Console.WriteLine("Nhap thong tin hoan thanh");
            }
            else
            {
                Console.WriteLine("Nhap thong tin hoan thanh");

            }
        }

        public void Display()
        {
            Console.WriteLine("Thoi gian CheckIn: {0}, Thoi gian CheckOut:{1}, Ten Khach Dat: {2}, So SMT khach dat {3}", CheckInTime, CheckOutTime, BookCustomerName, BookCustomerIdentification);
            Console.WriteLine("Thong tin toan bo khach trong phong nhu sau :");
             foreach (Customer customer in CustomerList)
            {
                customer.Display();
            }

        }
    }
}


Phân Loại Bài Viết

Tài Liệu Tham Khảo

Ứng Dụng Tiện Ích



Đã sao chép!!!