Beispiel #1
0
        static void Main(string[] args)
        {
            // Kiem tra doi so dong lenh
            // de xac dinh dang cu phap dong lenh
            if (args.Length == 0)
            {
                kieuCP = KieuCuPhap.Dang1; // khi khong co doi so nao thi thuc hien theo dang 1
            }
            else if (args.Length == 1 && args[0] == "-h")
            {
                kieuCP = KieuCuPhap.Dang2; // thuoc dang 2
            }
            else
            {
                // In thong bao loi va hien thi huong dan su dung
                Console.WriteLine("Lenh goi chuong trinh cua ban bi sai");
                kieuCP = KieuCuPhap.Dang2;
            }

            // xu ly theo dang cu phap dong lenh
            switch (kieuCP)
            {
            case KieuCuPhap.Dang1:
                // khoi tao doi tuong quan ly phong
                try
                {
                    // Tao doi tuong va load du lieu tu file data.txt
                    quanlyPhong = new QuanLyPhong();
                    XuLyTapTin.DocDuLieu(QuanLyPhong.DuongDanMacDinh, quanlyPhong);
                }
                catch (FileNotFoundException fx)
                {
                    Console.WriteLine("LOI: Khong tim thay tap tin du lieu");
                    Console.ReadLine();
                }
                catch (XuLyTapTinException ex)
                {
                    Console.WriteLine("LOI: {0}", ex.Message);
                    Console.ReadLine();
                }
                finally
                {
                    quanlyPhong.CoThayDoi = false;
                }

                // Hien thi Menu
                XuLyMenu();
                break;

            case KieuCuPhap.Dang2:
                InHuongDanSuDung();    // In ra huong dan su dung
                Console.ReadKey();     // Cho nguoi sd doc huong dan va bam enter
                Environment.Exit(0);   // roi thoat khoi chuong trinh
                break;
            }
        }
Beispiel #2
0
        // ham xu ly menu
        static void XuLyMenu()
        {
            int  menu;
            bool kt = true;

            while (kt)
            {
                InMenu();                   // in menu ra man hinh
                menu = XulyChonMenu(1, 14); // cho nguoi su dung chon menu

                switch (menu)
                {
                case 1:     // Them phong hoc
                    ThemPhongMoi();
                    break;

                case 2:     // Xoa phong
                    XoaPhong();
                    break;

                case 3:     // Sua thong tin phong
                    SuaTTPhong();
                    break;

                case 4:     // Danh sach phong
                    InDSPhong();
                    break;

                case 5:     // Tim phong trong
                    TimPhongTrong();
                    break;

                case 6:     // Them don muon phong
                    ThemDonMuonMoi();
                    break;

                case 7:     // Xoa don muon phong
                    XoaDonDK();
                    break;

                case 8:     // Sua thong tin don muon phong
                    SuaDonDK();
                    break;

                case 9:     // danh sach don muon phong
                    InDSDonMuonPhong();
                    break;

                case 10:     // thong ke su dung phong theo thoi gian
                    InTheoThoiGian();
                    break;

                case 11:     // thong ke su dung phong theo nguoi muon
                    InTheoNgMuonVaThang();
                    break;

                case 12:     // thong ke su dung phong theo thang
                    ThongKeTanSuat();
                    break;

                case 13:     // tinh tien muon phong
                    TinhTienMuonPhong();
                    break;

                case 14:     // thoat khoi chuong trinh
                    if (XuLyCauHoiYesNo("Ban co chac muon thoat chuong trinh ? (Y/N): "))
                    {
                        // neu muon thoat thi luu du lieu xuong file, neu da co thay doi trong du lieu
                        if (quanlyPhong.CoThayDoi)
                        {
                            try
                            {
                                XuLyTapTin.LuuDuLieu(QuanLyPhong.DuongDanMacDinh, quanlyPhong);
                                Console.WriteLine("\nDa luu thay doi trong co so du lieu vao tap tin data.txt");
                            }
                            catch (XuLyTapTinException ex)
                            {
                                Console.WriteLine("LOI: {0}", ex.Message);
                                Console.ReadLine();
                            }
                        }
                        // roi moi thoat
                        Console.WriteLine("Cam on ban da su dung chuong trinh !");
                        Console.ReadKey();
                        kt = false;
                    }
                    break;
                }
            }
        }