By GokiSoft.com|
09:41 01/11/2021|
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
Đề 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.
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Nguyễn Hữu Hiếu [T2008A]](https://www.gravatar.com/avatar/ca2884508b617fee77f000c7d99c219d.jpg?s=80&d=mm&r=g)
Nguyễn Hữu Hiếu
2021-06-04 06:25:35
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]](https://www.gravatar.com/avatar/1348e3562c6492c26f796cb1f45982a1.jpg?s=80&d=mm&r=g)
Triệu Văn Lăng
2021-06-03 01:51:14
#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]](https://www.gravatar.com/avatar/1348e3562c6492c26f796cb1f45982a1.jpg?s=80&d=mm&r=g)
Triệu Văn Lăng
2021-06-03 01:50:59
#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]](https://www.gravatar.com/avatar/307a5cf29780afab49706dc8b15b86c6.jpg?s=80&d=mm&r=g)
vuong huu phu
2021-06-02 11:45:15
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]](https://www.gravatar.com/avatar/8863d24ed74b396082becbc4db8331fd.jpg?s=80&d=mm&r=g)
Nguyễn Anh Vũ
2021-06-02 10:47:24
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();
}
}
}
#Roomusing 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);
}
}
}
#Bookusing 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:...");
}
}
}
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2021-06-02 10:08:21
#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]](https://www.gravatar.com/avatar/c9c4f8f79ce35b9224637b6cc5fbe5c4.jpg?s=80&d=mm&r=g)
Nguyên Phấn Đông
2021-06-02 09:20:07
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]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2021-06-01 10:29:49
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]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2021-06-01 10:29:34
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]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2021-06-01 10:29:18
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();
}
}
}
}