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,509 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

Nguyễn Hữu Hiếu [T2008A]

Ngày viết: 13:25 04/06/2021



using System;
using System.Collections.Generic;

namespace Assigment
{
    class Program
    {
        static void Main(string[] args)
        {
            List<Hotel> hotelList = new List<Hotel>();
            List<Khachhang> khList = new List<Khachhang>();



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

                switch (choose)
                {
                    case 1:
                        Hotel hotel = new Hotel();
                        hotel.Add();
                        hotelList.Add(hotel);

                        break;
                    case 2:
                        Khachhang kh = new Khachhang();
                        kh.Add();
                        khList.Add(kh);
                        break;
                    case 3:
                        foreach(Hotel ht in hotelList)
                        {
                            ht.Display();
                        }

                        break;
                    case 4:

                        foreach (Khachhang khl in khList)
                        {
                            khl.Display();
                        }
                        break;
                    case 5:
                        break;
                    default:

                        break;

                }


            }
            while (choose != 5);



        }

        static void showMenu()
        {
            Console.WriteLine("1.Them khach san");
            Console.WriteLine("2.Them khach hang");
            Console.WriteLine("3.Hien thi KS");
            Console.WriteLine("4.Hien thi KH");
            Console.WriteLine("5.Thoat");
            Console.WriteLine("Chon choose: ");
        }

    }
}



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

namespace Assigment
{
    class Hotel
    {
        public string IdHotel { get; set; }
        public string NameHotel { get; set; }
        public string AddHotel { get; set; }
        public string Room { get; set; }

        public Hotel() { }

        public void Add()
        {
            Console.WriteLine("Nhap ma KS:");
            string IdHotel = Console.ReadLine();

            Console.WriteLine("Nhap ten KS:");
            string NameHotel = Console.ReadLine();

            Console.WriteLine("Nhap dia chi KS:");
            string AddHotel = Console.ReadLine();

            Console.WriteLine("Nhap phong KS:");
            string Room = Console.ReadLine();




        }

        public void Display()
        {
            Console.WriteLine("Khach san: {0} - {1} - {2}", IdHotel, NameHotel, AddHotel);
        }



    }
}



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

namespace Assigment
{
    class Khachhang
    {
        string Name { get; set; }
        string Cmt { get; set; }
        string Diachi { get; set; }

        public Khachhang() { }

        public void Add()
        {
            

            Console.WriteLine("Nhap ten:");
            string Name = Console.ReadLine();

            Console.WriteLine("Nhap CMT:");
            string Cmt = Console.ReadLine();

            Console.WriteLine("Nhap dia chi:");
            string Diachi = Console.ReadLine();

            
        }

        public void Display()
        {
            Console.WriteLine("Khach hang - {0} - {1} - {2}", Name, Cmt, Diachi);
        }
    }
}


Triệu Văn Lăng [T2008A]

Ngày viết: 08:51 03/06/2021


#Room.cs


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

namespace QLKhackSan
{
    class Room
    {
        public string NameRoom { get; set; }
        public string CodeRoom { get; set; }
        public int PeopleMax { get; set; }
        public float Price { get; set; }
        public int Floor { get; set; }

        public Room()
        {

        }

        public Room(string NameRoom, float Price, string CodeRoom, int PeopleMax, int Floor)
        {
            this.NameRoom = NameRoom;
            this.Price = Price;
            this.CodeRoom = CodeRoom;
            this.PeopleMax = PeopleMax;
            this.Floor = Floor;
        }

        public void inputRoom()
        {
            Console.WriteLine("Nhap Ten phong: ");
            NameRoom = Console.ReadLine();

            Console.WriteLine("Nhap ma phong:");
            CodeRoom = Console.ReadLine();

            Console.WriteLine("Nhap so nguoi o toi da:");
            PeopleMax = Convert.ToInt32(Console.ReadLine());

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

            Console.WriteLine("Phong o tang may: ");
            Floor = Convert.ToInt32(Console.ReadLine());
        }

        public void displayRoom()
        {
            Console.WriteLine("Ten phong: {0}, Ma phong: {1}, So nguoi toi da: {2}, Gia phong: {3}, Phong o tang: {4}",
                            NameRoom, CodeRoom, PeopleMax, Price, Floor);
        }
    }
}


Triệu Văn Lăng [T2008A]

Ngày viết: 08:50 03/06/2021


#Booking.cs


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

namespace QLKhackSan
{
    class Booking
    {
        public List<Customer> customersList { get; set; }
        public string CMTND { get; set; }
        public string CodeHotel { get; set; }
        public string CodeRoom { get; set; }
        public DateTime CheckIn { get; set; }
        public DateTime CheckOut { get; set; }

        public Booking()
        {
            customersList = new List<Customer>();
        }

        public Booking(string CMTND, string CodeHotel, string CodeRoom, DateTime CheckIn, DateTime CheckOut)
        {
            this.CMTND = CMTND;
            this.CodeHotel = CodeHotel;
            this.CodeRoom = CodeRoom;
            this.CheckIn = CheckIn;
            this.CheckOut = CheckOut;
        }

        public void input(List<Customer> customersList, List<Hotel> hotelList)
        {
            if(hotelList.Count == 0)
            {
                Console.WriteLine("Khong co du lieu");
                return;
            }

            Console.WriteLine("Nhap CMTND khack hang:");
            CMTND = Console.ReadLine();
            bool checkCMTND = false;

            foreach(Customer customer in customersList)
            {
                if(customer.CMTND.Equals(CMTND) )
                {
                    checkCMTND = true;
                    break;
                }
            }

            if(!checkCMTND)
            {
                Console.WriteLine("Nhap thong tin khack hang");
                Customer customer = new Customer();
                customer.inputCustomer();

                customersList.Add(customer);
            }

            Console.WriteLine("Nhap ma khack san:");
            Hotel currentHotel = null;
            for(; ; )
            {
                foreach(Hotel hotel in hotelList)
                {
                    Console.WriteLine("Ma khack san: {0}, Ten khack san", hotel.CodeHotel, hotel.NameHotel);
                }

                CodeHotel = Console.ReadLine();
                foreach (Hotel hotel in hotelList)
                {
                    if(hotel.CodeHotel.Equals(CodeHotel))
                    {
                        currentHotel = hotel;
                        break;
                    }
                }

                if(currentHotel != null)
                {
                    break;
                }
                Console.WriteLine("Nhap lai");
            }

            Console.WriteLine("Nhap ma phong:");
            if(currentHotel.roomList.Count == 0)
            {
                Console.WriteLine("Khack san khong co phong nay");
                return;
            }

            for(; ; )
            {
                foreach(Room room in currentHotel.roomList)
                {
                    Console.WriteLine("Ma phong {0}, Ten phong: {1}", room.CodeRoom, room.NameRoom);
                }

                checkCMTND = false;
                CodeRoom = Console.ReadLine();
                foreach (Room room in currentHotel.roomList)
                {
                    if(room.CodeRoom.Equals(CodeRoom))
                    {
                        checkCMTND = true;
                        break;
                    }
                }

                if(checkCMTND)
                {
                    break;
                } else
                {
                    Console.WriteLine("Nhap lai");
                }
            }

            Console.WriteLine("Ngay dat phong(dd/mm/yyy):");
            string dateTime = Console.ReadLine();
            CheckIn = ConvertStringToDatetime(dateTime);

            Console.WriteLine("Ngay tra phong(dd/mm/yyy):");
            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 QLKhackSan
{
    class Customer
    {
        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 Customer()
        {
        }

        public Customer(string CMTND, string FullName, int Age, string Gender, string Address)
        {
            this.CMTND = CMTND;
            this.Fullname = Fullname;
            this.Age = Age;
            this.Gender = Gender;
            this.Address = Address;
        }

        public void inputCustomer()
        {
            Console.WriteLine("Nhap so CMTND:");
            CMTND = Console.ReadLine();

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

            Console.WriteLine("Nhap Tuoi:");
            Age = Convert.ToInt32(Console.ReadLine());

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

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


#Hotel.cs


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

namespace QLKhackSan
{
    class Hotel
    {
        public string NameHotel { get; set; }
        public string AddressHotel { get; set; }
        public string CodeHotel { get; set; }
        public string TypeHotel { get; set; }
        public int numberRoom { get; set; }
        public List<Room> roomList { get; set; }
        public Hotel() 
        {
            List<Room> roomList = new List<Room>();
        } 
        
        public Hotel(string NameHotel, string AddressHotel, string CodeHotel, string TypeHotel, int numberRoom)
        {
            this.NameHotel = NameHotel;
            this.AddressHotel = AddressHotel;
            this.CodeHotel = CodeHotel;
            this.TypeHotel = TypeHotel;
            this.numberRoom = numberRoom;
        }

        public void inputHotel()
        {
            Console.WriteLine("Nhap Ten khack san:");
            NameHotel = Console.ReadLine();

            Console.WriteLine("Nhap Ma khack san:");
            CodeHotel = Console.ReadLine();

            Console.WriteLine("Nhap Dia chi:");
            AddressHotel = Console.ReadLine();

            Console.WriteLine("Nhap Loai khack san(VIP/Binh dan):");
            TypeHotel = Console.ReadLine();

            Console.WriteLine("Nhap so phong: ");
            numberRoom = Convert.ToInt32(Console.ReadLine());
            for(int i = 0; i < numberRoom; i++)
            {
                Console.WriteLine("Nhap thong tin phong thu {0}", i + 1);
                Room room = new Room();
                room.inputRoom();

                roomList.Add(room);
            }
        }

        public void displayHotel()
        {
            Console.WriteLine("Ten khack san: {0}, Ma KS: {1}, Dia chi: {2}, Loai khack san: {3}, So phong: {4}",
                            NameHotel, CodeHotel, AddressHotel, TypeHotel, numberRoom);
            foreach(Room room in roomList)
            {
                room.displayRoom();
            }
        }
    }
}


#Program.cs


using System;
using System.Collections.Generic;
using QLKhackSan;
namespace QLKhackSan
{
    class Program
    {
        static List<Hotel> hotelList = new List<Hotel>();
        static List<Customer> customersList = new List<Customer>();
        static List<Room> roomList = new List<Room>();
        static List<Booking> bookList = new List<Booking>();
        static void Main(string[] args)
        {
            int choose = 0;
            do
            {
                Menu();
                choose = Convert.ToInt32(Console.ReadLine());

                switch(choose)
                {
                    case 1:
                        Console.WriteLine("Nhap so khack san muon them:");
                        int n = Convert.ToInt32(Console.ReadLine());

                        for(int i = 0; i < n; i++)
                        {
                            Console.WriteLine("Nhap thong tin khack san thu {0}", i + 1);
                            Hotel hotel = new Hotel();
                            hotel.inputHotel();
                            hotelList.Add(hotel);
                        }
                        break;
                    case 2:
                        foreach(Hotel hotel in hotelList)
                        {
                            hotel.displayHotel();
                        }
                        break;
                    case 3:
                        Console.WriteLine("Nhap Ma khack san muon xoa:");
                        string CodeHotelDelete = Console.ReadLine();
                        foreach(Hotel hotel in hotelList)
                        {
                            if(hotel.CodeHotel == CodeHotelDelete)
                            {
                                hotelList.Remove(hotel);
                                break;
                            }
                            Console.WriteLine("Da xo khack san");
                        }
                        break;
                    case 4:
                        Booking booking = new Booking();
                        booking.input(customersList, hotelList);
                        break;
                    case 5:
                        if(hotelList.Count == 0)
                        {
                            Console.WriteLine("Khong co du lieu");
                            return;
                        }

                        Hotel currentHotel = null;
                        for (; ; )
                        {
                            foreach (Hotel hotel in hotelList)
                            {
                                Console.WriteLine("Ma khack san: {0}, Ten khack san", hotel.CodeHotel, hotel.NameHotel);
                            }

                            string CodeHotel = Console.ReadLine();
                            foreach (Hotel hotel in hotelList)
                            {
                                if (hotel.CodeHotel.Equals(CodeHotel))
                                {
                                    currentHotel = hotel;
                                    break;
                                }
                            }

                            if (currentHotel != null)
                            {
                                break;
                            }
                            Console.WriteLine("Nhap lai");
                        }
                        Console.WriteLine("Chon ngay dat phong: ");
                        string dateTime = Console.ReadLine();
                        DateTime CheckIn = DateTime.ParseExact(dateTime, "dd/MM/yyyy", null);

                        Console.WriteLine("Chon ngay tra phong:");
                         dateTime = Console.ReadLine();
                        DateTime CheckOut = DateTime.ParseExact(dateTime, "dd/MM/yyyy", null);

                        foreach(Room room in currentHotel.roomList)
                        {
                            List<Booking> currentBooking = new List<Booking>();
                            foreach(Booking book in bookList)
                            {
                                if(book.CodeHotel.Equals(currentHotel.CodeHotel) && book.CodeRoom.Equals(room.CodeRoom))
                                {
                                    currentBooking.Add(book);
                                }
                            }
                            bool isFind = false;
                            foreach (Booking book in currentBooking)
                            {
                                if (DateTime.Compare(book.CheckIn, CheckOut) > 0 || DateTime.Compare(book.CheckOut, CheckIn) < 0)
                                {
                                    //OK
                                }
                                else
                                {
                                    isFind = true;
                                    break;
                                }
                            }

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

                        break;
                    case 6:
                        Console.WriteLine("Nhap ma khack san can tim kiem:");
                        string searchCodeHotel = Console.ReadLine();
                        foreach(Hotel hotel in hotelList)
                        {
                            if(hotel.CodeHotel == searchCodeHotel)
                            {
                                hotel.displayHotel();
                            }
                        }
                        break;
                    case 7:
                        Console.WriteLine("Thoat!!!");
                        break;
                    default:
                        Console.WriteLine("Nhap lai!!!");
                        break;
                }
            } while (choose != 7);
        }

        private static void Menu()
        {
            Console.WriteLine("Lua chon chuong trinh");
            Console.WriteLine("1. Nhap thong tin khack san");
            Console.WriteLine("2. Hien thi thong tin khack san");
            Console.WriteLine("3. Xoa khack san");
            Console.WriteLine("4. Dat phong");
            Console.WriteLine("5. Tim kiem thong tin dat phong");
            Console.WriteLine("6. Tim kiem khack san");
            Console.WriteLine("7. Thoat");
        }
    }
}


vuong huu phu [T2008A]

Ngày viết: 18:45 02/06/2021



using System;
using System.Collections.Generic;
using System.IO;

namespace Quanlykhachsan
{
    class Program
    {
        public static List<Khach_san> khachsan_list = new List<Khach_san>();
        public static  List<Khach_hang> Khach_hang_list = new List<Khach_hang>();
        static void Main(string[] args)
        {
           dulieukh();dulieuks();
            int lc;
            do
            {
                menu();
                Console.WriteLine("Nhap su lua chon : ");
                lc = Int32.Parse(Console.ReadLine());
                
                switch (lc) {
                    
                    case 1:
                        String name = " Khach san ";
                        menu2(name);
                        int lc1;
                        Console.WriteLine("Nhap su lua chon : ");
                        lc1 = Int32.Parse(Console.ReadLine());
                        switch (lc1) {
                            case 1:
                                int n;
                                Console.WriteLine("Nhap so luong khach san : ");
                                n = Int32.Parse(Console.ReadLine());
                                for (int i = 0; i < n; i++) {
                                    Khach_san ks = new Khach_san();
                                    ks.nhap_ks();
                                    khachsan_list.Add(ks);
                                }
                                break;
                            case 2:
                                String ma;
                                Console.WriteLine("Nhap ma khach san muon xoa : ");
                                ma = Console.ReadLine();
                                xoa(ma);
                                break;
                            case 3:
                                String maupdate;
                                Console.WriteLine("Nhap ma khach san muon xoa : ");
                                maupdate = Console.ReadLine();
                                xoa(maupdate);
                                Khach_san ks1 = new Khach_san();
                                ks1.nhap_ks();
                                khachsan_list.Add(ks1);
                                
                                break;
                        }
                        luukhachsan();
                        break;


                    case 2:
                        String name1 = " Khach hang ";
                        menu2(name1);
                        int lc2;
                        Console.WriteLine("Nhap su lua chon : ");
                        lc2 = Int32.Parse(Console.ReadLine());
                        switch (lc2)
                        {
                            case 1:
                                int n;
                                Console.WriteLine("Nhap so luong khach hang : ");
                                n = Int32.Parse(Console.ReadLine());
                                foreach (Khach_san ks in khachsan_list) {
                                    ks.hienthi();
                                }
                                String nameks = "";
                                Console.WriteLine("Nhap ma khach san ");
                                String ma = Console.ReadLine();
                                for (int i = 0; i < khachsan_list.Count; i++) {
                                    if (khachsan_list[i].Maks == ma) {
                                        nameks = khachsan_list[i].Tenks;
                                    }
                                }
                                for (int i = 0; i < n; i++)
                                {
                                    Khach_hang ks = new Khach_hang();
                                    ks.Tenkh = nameks;
                                    ks.nhap();
                                    Khach_hang_list.Add(ks);
                                }
                                break;
                            case 2:
                                String makh;
                                Console.WriteLine("Nhap ma khach san muon xoa : ");
                                makh = Console.ReadLine();
                                xoa1(makh);
                                break;
                            case 3:
                                String maupdate;
                                Console.WriteLine("Nhap ma khach hang muon sua : ");
                                maupdate = Console.ReadLine();
                                xoa1(maupdate);
                                Khach_hang ks1 = new Khach_hang();
                                ks1.nhap();
                                Khach_hang_list.Add(ks1);
                               
                                break;
                        }
                            luukhachhang();
                        break;


                    case 3:
                        foreach (Khach_hang kh in Khach_hang_list) {
                            kh.hienthi();
                        }
                        break;


                    case 4:
                        int lctimkiem;
                        Console.WriteLine(" 1 Tim kiem khach san ");
                        Console.WriteLine(" 2 Tim kiem khach hang ");
                        Console.WriteLine("Nhap su lua chon");
                        lctimkiem = Int32.Parse(Console.ReadLine());
                        switch (lctimkiem) {
                            case 1:
                                Console.WriteLine("Nhap ma khach san can tim");
                                String ma = Console.ReadLine();
                                foreach (Khach_san ks in khachsan_list) {
                                    if (ks.Maks.Equals(ma)) {
                                        ks.hienthi();
                                    }
                                }
                                break;
                            case 2:
                                Console.WriteLine("Nhap ma khach hang can tim");
                                String makh = Console.ReadLine();
                                foreach (Khach_hang kh in Khach_hang_list)
                                {
                                    if (kh.Makh.Equals(makh))
                                    {
                                        kh.hienthi();
                                    }
                                }
                                break;
                        }
                        break;
                }
            } while (lc <= 4 );
            
            
        }
        public static void menu() {
            Console.WriteLine(" 1 Them / sua / xoa khach san :");
            Console.WriteLine(" 2 Them / sua /xoa / khach hang :");
            Console.WriteLine(" 3 Quan ly dat phong :");
            Console.WriteLine(" 4 Tim kiem : ");
            Console.WriteLine(" 5 Thoat !!!! : ");
        }
        public static void menu2(String name) {
            Console.WriteLine(" 1 Them " + name);
            Console.WriteLine(" 2 Xoa " + name);
            Console.WriteLine(" 3 Sua " + name);
        }
        public static void xoa(String ma) {
            int t = 0;
            for (int i = 0; i < khachsan_list.Count; i++) {
                if (khachsan_list[i].Maks == ma) {
                    khachsan_list.RemoveAt(i);
                    t++;
                }
            }
            if (t == 0) {
                Console.WriteLine(" Khong co ma khach san nay");
            }
        }

        public static void xoa1(String ma)
        {
            int t = 0;
            for (int i = 0; i < Khach_hang_list.Count; i++)
            {
                if (Khach_hang_list[i].Makh == ma)
                {
                    Khach_hang_list.RemoveAt(i);
                    t++;
                }
            }
            if (t == 0)
            {
                Console.WriteLine(" Khong co ma khach hang nay");
            }
        }
        public static void luukhachsan() {
            using (Stream tr = File.Open(@"Khachsan.dat", FileMode.Create))
            {
                var format1 = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                format1.Serialize(tr, khachsan_list);
            }
                dulieuks();
        }

        public static void luukhachhang()
        {
            using (Stream tr = File.Open(@"Khachhang.dat", FileMode.Create))
            {
                var format1 = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                format1.Serialize(tr, Khach_hang_list);
            }
                 dulieukh();
        }

        public static void dulieuks() {
            using (Stream tr1 = File.Open(@"Khachsan.dat", FileMode.Open))
            {
                var format = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                khachsan_list = (List<Khach_san>)format.Deserialize(tr1);
            }
        }
        public static void dulieukh()
        {
            using (Stream tr1 = File.Open(@"Khachhang.dat", FileMode.Open))
            {
                var format = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                Khach_hang_list = (List<Khach_hang>)format.Deserialize(tr1);
            }
        }
    }
}



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

namespace Quanlykhachsan
{
    [Serializable]
    class Khach_hang
    {
        public String Makh { set; get; }
        public String Loai_phong { set; get; }
        public String Tenkh { set; get; }
        public String ngay_thue { set; get; }
        public String Ngay_tra { set; get; }
        String[] phong = { " 1 giong ngu ", " 2 giong ngu ", " vip " };

        public Khach_hang() { }
        public Khach_hang(String Makh, String Loai_phong, String Tenkh, String ngay_thue, String Ngay_tra) {
            this.Makh = Makh;
            this.Loai_phong = Loai_phong;
            this.Tenkh = Tenkh;
            this.ngay_thue = ngay_thue;
            this.Ngay_tra = Ngay_tra;
        }

        public void nhap() {
            Console.WriteLine("Nhap ma khach hang :");
            Makh = Console.ReadLine();
            Console.WriteLine("Nhap loai phong :");
            int chon;
            Console.WriteLine(" 1 phong ngu 1 giuong");
            Console.WriteLine(" 2 phong ngu 2 giuong");
            Console.WriteLine(" 3 phong vip");
            Console.WriteLine("Chon loai phong ngu");
            chon = Int32.Parse(Console.ReadLine());
            switch (chon) {
                case 1:
                    Loai_phong = phong[1];
                    break;
                case 2:
                    Loai_phong = phong[2];
                    break;
                case 3:
                    Loai_phong = phong[3];
                    break;
            }
            Console.WriteLine("Nhap ten khach hang:");
            Tenkh = Console.ReadLine();
            Console.WriteLine("Nhap ngay thue :");
            ngay_thue = Console.ReadLine();
            Console.WriteLine("Nhap ngay tra :");
            Ngay_tra = Console.ReadLine();
        }
        public void hienthi() {
            Console.WriteLine(" Ma khach hang : " + Makh + " , Loai phong " + Loai_phong + " , Ten khach hang :" + Tenkh + " , Ngay thue phong : " + ngay_thue + " , Ngay tra phong :" + Ngay_tra);
            Console.WriteLine();
        }

    }
}



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

namespace Quanlykhachsan
{
    [Serializable]
    class Khach_san
    {
        public string Maks { set; get; }
        public string Tenks { set; get; }
        public string Diachi { set; get; }

        public Khach_san() { }
        public Khach_san(String Maks,String Tenks,String Diachi) {
            this.Maks = Maks;
            this.Tenks = Tenks;
            this.Diachi = Diachi;
        }

        public void nhap_ks (){
            Console.WriteLine(" Nhap ma khach san : ");
            Maks = Console.ReadLine();
            Console.WriteLine(" Nhap ten khach san :");
            Tenks = Console.ReadLine();
            Console.WriteLine(" Nhap dia chi khach san : ");
            Diachi = Console.ReadLine();
        }
        public void hienthi() {
            Console.WriteLine( "Ma khach san: " + Maks + " , Ten khach san " + Tenks + " , Dia chi : " + Diachi);
        }

    }
}


Nguyễn Anh Vũ [T2008A]

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


#Hotel
using System;
using System.Collections.Generic;
using System.Text;

namespace Assignment1526
{
    class Hotel
    {
        internal object hotelID;
        internal IEnumerable<Room> rooms;
        internal int name;

        public void addCustomer(List<Customer> customers, List<string> ids)
        {
            Customer customer = new Customer();
            customer.input(ids);
            customer.Add(customer);
        }
        public void editCustomer(List<Customer> customers)
        {
            bool ischeck = true;
            while (ischeck)
            {
                Console.WriteLine("Enter PersonalID to edit : ");
                string str = Console.ReadLine();
                bool isCheck = false;
                foreach (Customer cus in customers)
                {
                    if (str.Equals(cus.cmnd))
                    {
                        cus.input(str);
                        ischeck = false;
                        isCheck = true;
                        break;
                    }
                }
                if (!isCheck)
                {
                    Console.WriteLine("PersonalID is Not exist !!");
                }


            }
        }

        internal void Display()
        {
            throw new NotImplementedException();
        }

        public void deleteCustomer(List<Hotel> hotels, List<Customer> customers)
        {
            bool ischeck = true;
            while (ischeck)
            {
                Console.WriteLine("Enter PersonalID to delete : ");
                string str = Console.ReadLine();
                bool isCheck = false;
                foreach (Customer cus in customers)
                {
                    if (str.Equals(cus.cmnd))
                    {
                        customers.Remove(cus);
                        ischeck = false;
                        isCheck = true;
                        break;
                    }
                }
                if (!isCheck)
                {
                    Console.WriteLine("PersonalID is Not exist !!");
                }


            }
        }

        internal void addHotel(List<Hotel> hotels, List<string> ids)
        {
            throw new NotImplementedException();
        }

        internal void deleteCustomer(List<Hotel> hotels, List<string> ids)
        {
            throw new NotImplementedException();
        }

        internal void editHotel(List<Hotel> hotels, List<string> ids)
        {
            throw new NotImplementedException();
        }
    }
}

#Customer

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

namespace Assignment1526
{
    class Customer
    {
        public string cmnd { get; set; }
        public string name { get; set; }
        public string gender { get; set; }
        public string address { get; set; }
        public int age { get; set; }
        public Customer()
        {
        }
        public Customer(string cmnd, string name, string gender, string address, int age)
        {
            this.cmnd = cmnd;
            this.name = name;
            this.gender = gender;
            this.address = address;
            this.age = age;
        }
        public void input(List<string> vs)
        {
            inputCmnd(vs);
            input(cmnd);
        }
        public void input(string cmnd)
        {
            this.cmnd = cmnd;
            inputName();
            inputAge();
            inputGender();
            inputaddress();
        }
        private void inputAge()
        {
            bool ischeck = true;
            while (ischeck)
            {
                Console.WriteLine("Age :");

                string c2 = Console.ReadLine();
                if (checkInt(c2) && string.IsNullOrEmpty(c2) == false)
                {
                    age = int.Parse(c2);
                    ischeck = false;
                    break;
                }
                else
                {
                    Console.WriteLine("Error !!");
                }
            }
        }
        bool checkInt(string s)
        {
            bool check = true;
            foreach (char item in s)
            {
                if (item < 48 || item > 57)
                {
                    check = false;
                    break;
                }

            }
            return check;
        }

        private void inputCmnd(List<string> vs)
        {
            bool ischeck = false;
            for (; ischeck == false;)
            {
                Console.WriteLine("PersonalID : ");
                cmnd = Console.ReadLine();
                foreach (string str in vs)
                {
                    if (cmnd.Equals(str))
                    {
                        Console.WriteLine("PersonalID is exist !!");
                        ischeck = true;
                        break;
                    }
                }
                if (!ischeck && string.IsNullOrEmpty(cmnd) == false)
                {
                    vs.Add(cmnd);
                    ischeck = true;
                    break;
                }
                else
                {
                    Console.WriteLine("Error !!");
                    ischeck = false;
                }
            }
        }
        private void inputGender()
        {
            bool ischeck = true;
            while (ischeck)
            {
                Console.WriteLine("Gender : ");
                gender = Console.ReadLine();
                if (string.IsNullOrEmpty(gender) == false)
                {
                    ischeck = false;
                }
            }

        }
        private void inputaddress()
        {
            bool ischeck = true;
            while (ischeck)
            {
                Console.WriteLine("Address : ");
                address = Console.ReadLine();
                if (string.IsNullOrEmpty(address) == false)
                {
                    ischeck = false;
                }
            }

        }
        private void inputName()
        {
            bool ischeck = true;
            while (ischeck)
            {
                Console.WriteLine("Name : ");
                name = Console.ReadLine();
                if (string.IsNullOrEmpty(name) == false)
                {
                    ischeck = false;
                }
            }

        }
        public void display()
        {
            Console.WriteLine("CMND : {0} , Fullname : {1} , Age : {2} , Gender : {3} , Address : {4}", cmnd, name, age, gender, address);
        }

        internal void addCustomer(List<Customer> customers, List<string> ids)
        {
            throw new NotImplementedException();
        }

        internal void editCustomer(List<Customer> customers)
        {
            throw new NotImplementedException();
        }

        internal void deleteCustomer(List<Customer> customers)
        {
            throw new NotImplementedException();
        }
    }
}
#Room


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

namespace Assignment1526
{
    class Room
    {
        public string roomName { get; set; }
        public int floorNumber { get; set; }
        public int maxPerson { get; set; }
        public int price { get; set; }
        public string roomCode { get; set; }
        public Room()
        {
        }
        public Room(string roomName, int floorNumber, int maxPerson, int price, string roomCode)
        {
            this.roomName = roomName;
            this.floorNumber = floorNumber;
            this.maxPerson = maxPerson;
            this.price = price;
            this.roomCode = roomCode;
        }
        public void input(List<string> vs)
        {
            inputRoomName();
            inputfloorNumber();
            inputmaxPerson();
            inputprice();
            inputRoomCode(vs);
        }
        private void inputfloorNumber()
        {


            bool ischeck = true;
            while (ischeck)
            {
                Console.WriteLine("tang  : ");

                string c2 = Console.ReadLine();
                if (checkInt(c2) && string.IsNullOrEmpty(c2) == false)
                {
                    floorNumber = int.Parse(c2);
                    ischeck = false;
                    break;
                }
                else
                {
                    Console.WriteLine("Error !!");
                }
            }

        }
        private void inputmaxPerson()
        {


            bool ischeck = true;
            while (ischeck)
            {
                Console.WriteLine("so nguoi toi da : ");

                string c2 = Console.ReadLine();
                if (checkInt(c2) && string.IsNullOrEmpty(c2) == false)
                {
                    maxPerson = int.Parse(c2);
                    ischeck = false;
                    break;
                }
                else
                {
                    Console.WriteLine("Error !!");
                }
            }

        }

        private void inputprice()
        {


            bool ischeck = true;
            while (ischeck)
            {
                Console.WriteLine("gia phong 1 ngay : ");

                string c2 = Console.ReadLine();
                if (checkInt(c2) && string.IsNullOrEmpty(c2) == false)
                {
                    price = int.Parse(c2);
                    ischeck = false;
                    break;
                }
                else
                {
                    Console.WriteLine("Error !!");
                }
            }

        }
        bool checkInt(string s)
        {
            bool check = true;
            foreach (char item in s)
            {
                if (item < 48 || item > 57)
                {
                    check = false;
                    break;
                }

            }
            return check;
        }
        private void inputRoomCode(List<string> vs)
        {
            bool ischeck = false;
            for (; ischeck == false;)
            {
                Console.WriteLine("ma phong : ");
                roomCode = Console.ReadLine();
                foreach (string str in vs)
                {
                    if (roomCode.Equals(str))
                    {
                        Console.WriteLine("PersonalID is exist !!");
                        ischeck = true;
                        break;
                    }
                }
                if (!ischeck && string.IsNullOrEmpty(roomCode) == false)
                {
                    vs.Add(roomCode);
                    ischeck = true;
                    break;
                }
                else
                {
                    Console.WriteLine("Error !!");
                    ischeck = false;
                }
            }
        }
        private void inputRoomName()
        {
            bool ischeck = true;
            while (ischeck)
            {
                Console.WriteLine("ten phong : ");
                roomName = Console.ReadLine();
                if (string.IsNullOrEmpty(roomName) == false)
                {
                    ischeck = false;
                }
            }

        }
        public void display()
        {
            Console.WriteLine("roomName : {0} , numberFloor : {1} , maxPerson : {2} , Price : {3} , roomCode : {4}", roomName, floorNumber, maxPerson, price, roomCode);

        }
    }
}

#Book


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

namespace Assignment1526
{
    class Book
    {
        public DateTime checkin { get; set; }
        public DateTime checkout { get; set; }
        public string cmnd { get; set; }
        public string hotelID { get; set; }
        public string roomCode { get; set; }
        public Book()
        {
        }
        public void display()
        {
            Console.WriteLine("CheckIn : {0} , CheckOut : {1} , Cmnd : {2} , HotelID : {3} , roomID : {4}", checkin, checkout, cmnd, hotelID, roomCode);
        }
        public void input(List<Hotel> hotel)
        public void input(List<Customer> customers)
        public void input(List<string>)
        {
            string strDatetime = null;
            while (string.IsNullOrEmpty(strDatetime))
            {
                Console.WriteLine("Ngay book (dd/mm/YYYY): ");
                strDatetime = Console.ReadLine();
                checkin = DateTime.ParseExact(strDatetime, "dd/MM/yyyy", null);
            }
            strDatetime = null;
            while (string.IsNullOrEmpty(strDatetime))
            {
                Console.WriteLine("Ngay tra phong (dd/mm/YYYY): ");
                strDatetime = Console.ReadLine();
                checkout = DateTime.ParseExact(strDatetime, "dd/MM/yyyy", null);
            }
            inputCMND(customers);
            inputHotelID(hotels, ids);
        }
        private void inputCMND(List<Customer> customers)
        {
            bool dk = false;
            Console.WriteLine("Enter PersonID : ");
            string find = Console.ReadLine();
            foreach (var item in customers)
            {
                if (find.Equals(item.cmnd))
                {
                    cmnd = find;
                    dk = true;
                    break;
                }
            }
            if (!dk)
            {
                Console.WriteLine("nhập thông tin Customer");
                Customer customer = new Customer();
                customer.input(find);
                customers.Add(customer);
                cmnd = customer.cmnd;
            }

        }
        private void inputHotelID(List<Hotel> hotels, List<string> ids)
        {
            bool dk = false;
            Console.WriteLine("Enter hotelID : ");
            string find = Console.ReadLine();
            foreach (var item in hotels)
            {
                if (find.Equals(item.hotelID))
                {
                    hotelID = find;
                    dk = true;
                    break;
                }
            }
            if (!dk)
            {
                Console.WriteLine("nhập thông tin hotel : ");
                Hotel hotel = new Hotel();
                hotel.input(ids);
                hotelID = hotel.hotelID;
                hotels.Add(hotel);
            }
            foreach (var item in hotels)
            {
                if (hotelID.Equals(item.hotelID))
                {
                    findRoom(item);
                }
            }


        }

        private void findRoom(Hotel hotel)
        {
            bool dk = true;
            while (dk)
            {
                foreach (Room item in hotel.rooms)
                {
                    item.display();
                }
                Console.WriteLine("Enter roomCode to book : ");
                string check;
                check = Console.ReadLine();
                foreach (Room item in hotel.rooms)
                {
                    if (check.Equals(item.roomCode))
                    {
                        roomCode = check;
                        dk = false;
                        break;
                    }
                }
                if (dk)
                {
                    Console.WriteLine("ma phong sai !!");
                }
            }
        }

        internal static void inpu(List<Hotel> hotels, List<Customer> customers, List<string> ids)
        {
            throw new NotImplementedException();
        }

        internal static void Add(Action book)
        {
            throw new NotImplementedException();
        }
    }
}



#Program
using System;

namespace Assignment1526
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;
            FunctionMennu functionMennu = new FunctionMennu();
            int c;
            do
            {
                menu();
                c = int.Parse(Console.ReadLine());
                switch (c)
                {
                    case 1:
                        functionMennu.Hotel();
                        break;
                    case 2:
                        functionMennu.Customer();
                        break;
                    case 3:
                        functionMennu.book();
                        break;
                    case 4:
                        functionMennu.Searching();
                        break;
                    case 5:
                        Console.WriteLine("Thoát !!");
                        break;

                    default:
                        Console.WriteLine("Lỗi !!");
                        break;
                }

            } while (c != 5);
        }
        static void menu()
        {
            Console.WriteLine("1: Khách Sạn");
            Console.WriteLine("2: Khách Hàng");
            Console.WriteLine("3: Đặt Phòng");
            Console.WriteLine("4: Tìm Kiếm");
            Console.WriteLine("5: Thoát");
            Console.WriteLine("Chọn:...");
        }
    }
}



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

Tài Liệu Tham Khảo

Đã sao chép!!!