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 [Video] Chương trình quản lý khách sạn - Develop Hotel Project - Lập Trình C# - Lập Trình C Sharp - C2009G

[Video] Chương trình quản lý khách sạn - Develop Hotel Project - Lập Trình C# - Lập Trình C Sharp - C2009G

by GokiSoft.com - 10:21 16/10/2021 1,189 Lượt Xem


Link Video Bài Giảng

Chương trình quản lý khách sạn - Develop Hotel Project - Lập Trình C# - Lập Trình C Sharp


#Program.cs


using System;
using Bt1460.Utils;
using Bt1460.Models;

namespace Bt1460
{
    class Program
    {
        static void Main(string[] args)
        {
            int choose;

            do
            {
                ShowMenu();
                choose = Utility.ReadInt();

                switch(choose)
                {
                    case 1:
                        DataMgr.GetInstance().InputHotel();
                        break;
                    case 2:
                        DataMgr.GetInstance().DisplayHotel();
                        break;
                    case 3:
                        DataMgr.GetInstance().InputBooking();
                        break;
                    case 4:
                        DataMgr.GetInstance().SearchRoomAvaiable();
                        break;
                    case 5:
                        DataMgr.GetInstance().StatisticProfit();
                        break;
                    case 6:
                        DataMgr.GetInstance().SearchCustomer();
                        break;
                    case 7:
                        Console.WriteLine("Thoat!!!");
                        break;
                    default:
                        Console.WriteLine("Nhap sai!!!");
                        break;
                }
            } while (choose != 7);
        }

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


#Utils/Utility.cs


using System;
namespace Bt1460.Utils
{
    public class Utility
    {
        public static int ReadInt()
        {
            int value;

            while(true)
            {
                try
                {
                    value = int.Parse(Console.ReadLine());
                    return value;
                } catch(Exception e)
                {
                    Console.WriteLine("Nhap lai!!!");
                }
            }
        }

        /**
         * Format: yyyy-MM-dd HH:mm:ss
         */
        public static DateTime ConvertStringToDateTime(string datetimeStr)
        {
            DateTime myDate = DateTime.ParseExact(datetimeStr, "yyyy-MM-dd HH:mm:ss",
                                       System.Globalization.CultureInfo.InvariantCulture);
            return myDate;
        }

        public static string ConvertDateTimeToString(DateTime dateTime)
        {
            return dateTime.ToString("yyyy-MM-dd HH:mm:ss");
        }
    }
}


#Models/Room.cs


using System;
using Bt1460.Utils;

namespace Bt1460.Models
{
    public class Room
    {
        public string Name { get; set; }
        public string RoomNo { get; set; }
        public int Price { get; set; }
        public int Floor { get; set; }
        public int MaxNum { get; set; }

        public Room()
        {
        }

        public Room(string name, string roomNo, int price, int floor, int maxNum)
        {
            Name = name;
            RoomNo = roomNo;
            Price = price;
            Floor = floor;
            MaxNum = maxNum;
        }

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

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

            Console.WriteLine("Nhap gia: ");
            Price = Utility.ReadInt();

            Console.WriteLine("Nhap tang: ");
            Floor = Utility.ReadInt();

            Console.WriteLine("Nhap so nguoi toi da: ");
            MaxNum = Utility.ReadInt();
        }

        public void Display()
        {
            Console.WriteLine("Ten phong: {0}, ma phong: {1}, gia: {2}, tang: {3}, " +
                "so nguoi toi da: {4}", Name, RoomNo, Price, Floor, MaxNum);
        }
    }
}


#Models/Hotel.cs


using System;
using System.Collections.Generic;
using Bt1460.Utils;

namespace Bt1460.Models
{
    public class Hotel
    {
        public string Name { get; set; }
        public string HotelNo { get; set; }
        public string Address { get; set; }
        public string Type { get; set; }
        public List<Room> RoomList { get; set; }

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

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

            Console.WriteLine("Nhap ma KS: ");
            HotelNo = Console.ReadLine();

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

            Console.WriteLine("Nhap loai: ");
            Type = Console.ReadLine();

            Console.WriteLine("Nhap so phong can them: ");
            int N = Utility.ReadInt();

            for(int i=0;i<N;i++)
            {
                Room room = new Room();
                room.Input();

                RoomList.Add(room);
            }
        }

        public void Display()
        {
            Console.WriteLine("Ten KS: {0}, Ma KS: {1}, Dia chi: {2}, Loai KS: {3}",
                Name, HotelNo, Address, Type);

            foreach(Room room in RoomList)
            {
                room.Display();
            }
        }

        public void SearchRoomAvaiable(DateTime checkIn, DateTime checkOut)
        {
            List<string> unavailableRoomList = GetRoomUnavaialbe(checkIn, checkOut);

            Console.WriteLine("=== Danh sach phong con trong cua KS: {0}, Ma KS: {1}", Name, HotelNo);
            foreach(Room room in RoomList)
            {
                if(!unavailableRoomList.Contains(room.RoomNo))
                {
                    room.Display();
                }
            }
        }

        public void StatisticProfit()
        {
            List<Booking> bookingList = DataMgr.GetInstance().BookingList;
            int total = 0;
            foreach (Booking booking in bookingList)
            {
                if (booking.HotelNo == HotelNo)
                {
                    foreach (Room room in RoomList)
                    {
                        if (room.RoomNo == booking.RoomNo)
                        {
                            total += room.Price;
                            break;
                        }
                    }
                }
            }

            Console.WriteLine("Loi nhuon cua KS: {0} la {1}", Name, total);
        }

        List<string> GetRoomUnavaialbe(DateTime checkIn, DateTime checkOut)
        {
            List<string> roomList = new List<string>();
            List<Booking> bookingList = DataMgr.GetInstance().BookingList;

            foreach(Booking booking in bookingList)
            {
                if(booking.HotelNo == HotelNo)
                {
                    if((booking.CheckIn <= checkIn && booking.CheckOut >= checkIn) ||
                        (booking.CheckIn <= checkOut && booking.CheckOut >= checkOut) ||
                        (booking.CheckIn > checkIn && booking.CheckOut < checkOut))
                    {
                        if(!roomList.Contains(booking.RoomNo))
                        {
                            roomList.Add(booking.RoomNo);
                        }
                    }
                }
            }

            return roomList;
        }
    }
}


#Models/DataMgr.cs


using System;
using System.Collections.Generic;
using Bt1460.Utils;

namespace Bt1460.Models
{
    public class DataMgr
    {
        public List<Customer> CustomerList { get; set; }
        public List<Hotel> HotelList { get; set; }
        public List<Booking> BookingList { get; set; }

        private static DataMgr _instance = null;

        private DataMgr()
        {
            CustomerList = new List<Customer>();
            HotelList = new List<Hotel>();
            BookingList = new List<Booking>();
        }

        public static DataMgr GetInstance()
        {
            if(_instance == null)
            {
                _instance = new DataMgr();
            }
            return _instance;
        }

        public void InputHotel()
        {
            Console.WriteLine("Nhap so ks can them: ");
            int N = Utility.ReadInt();

            for(int i=0;i<N;i++)
            {
                Hotel hotel = new Hotel();
                hotel.Input();

                HotelList.Add(hotel);
            }
        }

        public void DisplayHotel()
        {
            foreach(Hotel hotel in HotelList)
            {
                hotel.Display();
            }
        }

        public void InputBooking()
        {
            if (HotelList.Count == 0) return;

            Booking booking = new Booking();
            booking.Input();

            BookingList.Add(booking);
        }

        public void SearchCustomer()
        {
            Console.WriteLine("Nhap CMTND KH can tim: ");
            string cmtnd = Console.ReadLine();

            foreach (Booking booking in BookingList)
            {
                if(booking.Cmtnd == cmtnd)
                {
                    Console.WriteLine("KS khach hang da toi: {0} - Phong: {1}", booking.HotelNo, booking.RoomNo);
                }
            }
        }

        public void StatisticProfit()
        {
            foreach (Hotel hotel in HotelList)
            {
                hotel.StatisticProfit();
            }
        }

        public void SearchRoomAvaiable()
        {
            Console.WriteLine("Nhap Ngay Dat Phong (yyyy-MM-dd HH:mm:ss): ");
            DateTime checkIn = Utility.ConvertStringToDateTime(Console.ReadLine());

            Console.WriteLine("Nhap Ngay Tra Phong (yyyy-MM-dd HH:mm:ss): ");
            DateTime checkOut = Utility.ConvertStringToDateTime(Console.ReadLine());

            foreach(Hotel hotel in HotelList)
            {
                hotel.SearchRoomAvaiable(checkIn, checkOut);
            }
        }
    }
}


#Models/Customer.cs


using System;
using Bt1460.Utils;

namespace Bt1460.Models
{
    public class Customer
    {
        public string Fullname { get; set; }
        public string Cmtnd { get; set; }
        public int Age { get; set; }
        public string Gender { get; set; }
        public string Address { get; set; }

        public Customer()
        {
        }

        public Customer(string cmtnd)
        {
            Cmtnd = cmtnd;
        }

        public Customer(string fullname, string cmtnd, int age, string gender, string address)
        {
            Fullname = fullname;
            Cmtnd = cmtnd;
            Age = age;
            Gender = gender;
            Address = address;
        }

        public void Input()
        {
            Console.WriteLine("==================================");
            InputWithoutCmntd();

            Console.WriteLine("Nhap Cmtnd: ");
            Cmtnd = Console.ReadLine();
        }

        public void InputWithoutCmntd()
        {
            Console.WriteLine("==================================");
            Console.WriteLine("Nhap ten: ");
            Fullname = Console.ReadLine();

            Console.WriteLine("Nhap tuoi: ");
            Age = Utility.ReadInt();

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

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

        public void Display()
        {
            Console.WriteLine("Ten: {0}, cmtnd: {1}, tuoi: {2}, gioi tinh: {3}, " +
                "dia chi: {4}", Fullname, Cmtnd, Age, Gender, Address);
        }
    }
}


#Models/Booking.cs


using System;
using Bt1460.Utils;

namespace Bt1460.Models
{
    public class Booking
    {
        public string HotelNo { get; set; }
        public string RoomNo { get; set; }
        public string Cmtnd { get; set; }
        public DateTime CheckIn { get; set; }
        public DateTime CheckOut { get; set; }

        public Booking()
        {
        }

        public void Input()
        {
            DataMgr dataMgr = DataMgr.GetInstance();
            bool isFind = false;
            Hotel currentHotel = null;

            Console.WriteLine("Nhap Ma KS: ");
            while(true)
            {
                HotelNo = Console.ReadLine();
                isFind = false;
                foreach(Hotel hotel in dataMgr.HotelList)
                {
                    if(hotel.HotelNo == HotelNo)
                    {
                        currentHotel = hotel;
                        isFind = true;
                        break;
                    }
                }
                if(isFind)
                {
                    break;
                } else
                {
                    Console.WriteLine("Nhap lai!!!");
                }
            }
            if (currentHotel.RoomList.Count == 0) return;

            Console.WriteLine("Nhap Ma Phong: ");
            while (true)
            {
                RoomNo = Console.ReadLine();
                isFind = false;
                foreach (Room room in currentHotel.RoomList)
                {
                    if (room.RoomNo == RoomNo)
                    {
                        isFind = true;
                        break;
                    }
                }
                if (isFind)
                {
                    break;
                }
                else
                {
                    Console.WriteLine("Nhap lai!!!");
                }
            }

            Console.WriteLine("NHap Cmtnd: ");
            Cmtnd = Console.ReadLine();
            isFind = true;
            foreach(Customer customer in dataMgr.CustomerList)
            {
                if(customer.Cmtnd == Cmtnd)
                {
                    isFind = true;
                    break;
                }
            }
            if(!isFind)
            {
                Customer customer = new Customer(Cmtnd);
                customer.InputWithoutCmntd();

                dataMgr.CustomerList.Add(customer);
            }

            Console.WriteLine("Nhap Ngay Dat Phong (yyyy-MM-dd HH:mm:ss): ");
            CheckIn = Utility.ConvertStringToDateTime(Console.ReadLine());

            Console.WriteLine("Nhap Ngay Tra Phong (yyyy-MM-dd HH:mm:ss): ");
            CheckOut = Utility.ConvertStringToDateTime(Console.ReadLine());
        }

        public void Display()
        {
            Console.WriteLine("Ma KS: {0}, Ma Phong: {1}, Cmtnd: {2}, " +
                "Ngay Dat Phong: {3}, Ngay Tra Phong: {4}", HotelNo, RoomNo,
                Cmtnd, Utility.ConvertDateTimeToString(CheckIn),
                Utility.ConvertDateTimeToString(CheckOut));
        }
    }
}


Tags:

Bình luận



Chia sẻ từ lớp học

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

Tài Liệu Tham Khảo

Đã sao chép!!!