public void Ticket(User us)
        {
            Console.Clear();
            string row1 = "=====================================================================";
            string row2 = "---------------------------------------------------------------------";

            Console.WriteLine(row1);
            Console.WriteLine("Đặt vé.");
            Console.WriteLine(row2);
            Console.WriteLine("[Danh sách Phim]\n");
            MovieBL mbl = new MovieBL();

            string[]     properties = { "MovieId", "MovieName", "MovieCategory", "MovieTime", "MovieDateStart", "MovieDateEnd" };
            string[]     cols       = { "Mã phim", "Tên phim", "Thể loại", "Thời lượng(Phút)", "Ngày bắt đầu", "Ngày kết thúc" };
            List <Movie> movies     = mbl.GetMoviesByCineIdAndDateNow(us.Cine.CineId);

            cine = cbl.GetCinemaByCineId(us.Cine.CineId);
            DisplayTableData(movies, properties, cols, "dd/MM/yyyy");
            Console.WriteLine(row1);
            Console.Write("\nChọn phim(theo mã): "); sche.MovieId = input(Console.ReadLine());
            while (mbl.GetMovieByMovieId(sche.MovieId) == null)
            {
                Console.Write("Không có mã này, mời bạn nhập lại: "); sche.MovieId = input(Console.ReadLine());
            }
            movie = mbl.GetMovieByMovieId(sche.MovieId);

            List <Schedule>       ls  = sbl.GetSchedulesByMovieId(sche.MovieId);
            List <ScheduleDetail> lsd = new List <ScheduleDetail>();

            foreach (var itemListSchedule in ls)
            {
                List <ScheduleDetail> newlsdz = sdbl.GetScheduleDetailsByScheIdAndTimeNow(itemListSchedule.ScheId);
                foreach (var itemListScheduleDetail in newlsdz)
                {
                    lsd.Add(itemListScheduleDetail);
                }
            }
            if (lsd.Count == 0)
            {
                while (true)
                {
                    Console.Write("Không còn lịch chiếu cho phim bạn chọn trong ngày hôm nay. Bạn có muốn chọn phim khác?(C/K)");

                    string choice = Console.ReadLine();
                    switch (choice)
                    {
                    case "C":
                        Ticket(us);
                        return;

                    case "c":
                        Ticket(us);
                        return;

                    case "K":
                        mn.menuStaff(us);
                        return;

                    case "k":
                        mn.menuStaff(us);
                        return;

                    default:

                        continue;
                        // break;
                    }
                }
            }
            Console.Clear();
            Console.WriteLine(row1);
            Console.WriteLine("Đặt vé.");
            Console.WriteLine(row2);
            Console.WriteLine("[Danh sách lịch chiếu]");
            int count = 0;
            // lsd.Sort( (l,r) => l.SchedTimeStart.CompareTo(r.SchedTimeStart) );
            // lsd.Sort((x, y) => DateTime.Compare(x.SchedTimeStart, y.SchedTimeStart));
            // foreach (var item in lsd)
            // {

            //  count++;
            //     Schedule schez = new Schedule();
            //     schez = sbl.GetScheduleByScheId(itemlsd.ScheId);
            //     Room rooms = rbl.GetRoomByRoomId(schez.RoomId);
            //     Console.WriteLine(count + ". Bắt đầu từ: " + itemlsd.SchedTimeStart?.ToString("HH:mm") + " -> " + itemlsd.SchedTimeEnd?.ToString("HH:mm") + " Tại phòng: " + rooms.RoomName);
            // }
            ConsoleManager cm = new ConsoleManager();

            // List<ScheduleDetail> newlsd = new List<ScheduleDetail>();
            for (int i = 0; i < lsd.Count - 1; i++)
            {
                for (int j = i + 1; j < lsd.Count; j++)
                {
                    int time1 = cm.TimeToInt(lsd[i].SchedTimeStart?.ToString("HH:mm"));
                    int time2 = cm.TimeToInt(lsd[j].SchedTimeStart?.ToString("HH:mm"));
                    // Console.WriteLine(time1+" "+time2);
                    if (time1 > time2)
                    {
                        ScheduleDetail newsd = new ScheduleDetail();
                        newsd  = lsd[i];
                        lsd[i] = lsd[j];
                        lsd[j] = newsd;
                    }
                }
                // newlsd.Add(lsd[i]);
            }
            foreach (var itemlsd in lsd)
            {
                count++;
                Schedule schez = new Schedule();
                schez = sbl.GetScheduleByScheId(itemlsd.ScheId);
                Room rooms = rbl.GetRoomByRoomId(schez.RoomId);
                Console.WriteLine(count + ". Bắt đầu từ: " + itemlsd.SchedTimeStart?.ToString("HH:mm") + " -> " + itemlsd.SchedTimeEnd?.ToString("HH:mm") + " Tại phòng: " + rooms.RoomName);
            }
            Console.WriteLine(row1);
            Console.Write("Chọn lịch chiếu (theo số thứ tự): ");
            int scheno = input(Console.ReadLine());

            while (scheno > lsd.Count)
            {
                Console.Write("Chọn sai lịch chiếu, mời nhập lại: ");
                scheno = input(Console.ReadLine());
            }
            int?schedId = lsd[scheno - 1].SchedId;

            sched = sdbl.GetScheduleDetailBySchedId(schedId);

            string seatStr = null;

            string[] seat;
            Console.Clear();
            while (true)
            {
                Console.WriteLine(row1);
                Console.WriteLine("Đặt vé");
                Console.WriteLine(row2);
                Console.WriteLine("[Bản đồ phòng chiếu]");
                try
                {
                    // Console.WriteLine(ChoiceSeats(sched));
                    seatStr = ChoiceSeats(sched);
                    seat    = seatStr.Split(",");
                }
                catch (System.Exception)
                {
                    seat = null;
                }

                if (seat == null)
                {
                    Console.Clear();
                    Console.WriteLine("KHÔNG TÌM THẤY GHẾ !!!");
                    continue;
                }
                else if (seat[0] == "same")
                {
                    Console.Clear();
                    Console.WriteLine("BẠN NHẬP SỐ GHẾ TRÙNG NHAU !!!");
                    continue;
                }
                else
                {
                    break;
                }
            }


            // foreach (var item in seat)
            // {
            //     Console.WriteLine(item);
            // }
            // Console.ReadKey();
            foreach (var itemls in ls)
            {
                if (itemls.ScheId == sched.ScheId)
                {
                    sche = itemls;
                }
            }
            // Console.ReadKey();
            Room room = new Room();

            room = rbl.GetRoomByRoomId(sche.RoomId);
            // Console.WriteLine(room.RTName);
            List <PriceSeatOfRoomType> lpsort = psortbl.GetPriceSeatsOfRoomTypeByRTName(room.RTName);
            // PriceSeatOfRoomType psort = null;
            List <PriceSeatOfRoomType> lpsort1 = new List <PriceSeatOfRoomType>();

            // Console.Write(seat[0].ToString());
            foreach (var itemlpsort in lpsort)
            {
                foreach (var item in seat)
                {
                    // Console.WriteLine(itemlpsort.st);
                    // Console.WriteLine(item);
                    if (itemlpsort.STType == item[0].ToString())
                    {
                        // psort = new PriceSeatOfRoomType(itemlpsort.STType,itemlpsort.RTName,itemlpsort.Price);
                        // psort.STType = itemlpsort.STType;
                        // psort.RTName = itemlpsort.RTName;
                        // psort.Price = itemlpsort.Price;
                        lpsort1.Add(new PriceSeatOfRoomType(itemlpsort.RTName, itemlpsort.STType, itemlpsort.Price));
                    }
                }
            }
            Console.Clear();
            Console.WriteLine(row1);
            Console.WriteLine("Đặt vé");
            Console.WriteLine(row2);
            Console.WriteLine("[Thông tin vé đã chọn]");
            double price = 0;

            Console.WriteLine("Phim: {0}", movie.MovieName);
            Console.WriteLine("Thời gian chiếu: {0} - {0} -> {1}", sched.SchedTimeStart?.ToString("dd/MM/yyyy"), sched.SchedTimeStart?.ToString("HH:mm"), sched.SchedTimeEnd?.ToString("HH:mm"));
            Console.WriteLine("Các ghế đã chọn: {0}", seatStr);
            for (int i = 0; i < lpsort1.Count; i++)
            {
                price += lpsort1[i].Price;
            }
            Console.WriteLine(row1);
            Console.WriteLine("Tổng tiền vé: {0}", pricevalid(price));
            while (true)
            {
                Console.Write("Xác nhận mua vé?(C/K)");
                string choice = Console.ReadLine();
                switch (choice)
                {
                case "C":
                    tbl.SellTicket(sched);
                    break;

                case "c":
                    tbl.SellTicket(sched);
                    break;

                case "K":
                    break;

                case "k":
                    break;

                default:
                    continue;
                    // break;
                }
                break;
            }
            Console.Write("Nhập số tiền khách hàng trả(đồng): ");
            double cusmoney;

            while (true)
            {
                try
                {
                    cusmoney = Convert.ToDouble(Console.ReadLine());
                    if (cusmoney <= 0)
                    {
                        Console.Write("Số tiền trả phải lớn hơn 0, mời bạn nhập lại: ");
                        continue;
                    }
                    if (cusmoney < price)
                    {
                        Console.Write("Số tiền nhập không đủ, mời bạn nhập lại: ");
                        continue;
                    }
                    if (cusmoney > 999999999)
                    {
                        Console.Write("Số tiền quá lớn, mời bạn nhập lại: ");
                        continue;
                    }
                }
                catch
                {
                    Console.Write("Bạn phải nhập số tiền bằng số, mời nhập lại số tiền khách hàng trả(đồng): ");
                    continue;
                }

                break;
            }
            if ((cusmoney - price) > 0)
            {
                Console.WriteLine("Tiền trả lại: {0}", pricevalid(cusmoney - price));
            }
            Console.WriteLine(row1);
            Console.WriteLine("Thanh toán thành công!!!\nBấm phím bất kì để in vé");
            Console.ReadKey();
            Console.Clear();
            for (int i = 0; i < lpsort1.Count; i++)
            {
                PrintTicket(sched, sche, room, movie, lpsort1[i], us, cine, seat[i]);
            }
            Console.WriteLine("In vé thành công!!!\nBấm phím bất kì để thoát");
            Console.ReadKey();
            Console.Clear();

            mn.menuStaff(us);
        }
示例#2
0
 public void GetMovieByMovieIdTest1()
 {
     Assert.NotNull(mbl.GetMovieByMovieId(1));
 }
        public void CreateSchedule(User us)
        {
            Console.Clear();
            string row1 = "=====================================================================";
            string row2 = "---------------------------------------------------------------------";

            Console.WriteLine(row1);
            Console.WriteLine("Tạo lịch chiếu phim.");
            Console.WriteLine(row2);
            Console.WriteLine("[Danh sách Phim]\n");
            MovieBL mbl = new MovieBL();

            string[]     properties = { "MovieId", "MovieName", "MovieCategory", "MovieTime", "MovieDateStart", "MovieDateEnd" };
            string[]     cols       = { "Mã phim", "Tên phim", "Thể loại", "Thời lượng(Phút)", "Ngày bắt đầu", "Ngày kết thúc" };
            List <Movie> movies     = mbl.GetMoviesByCineId(us.Cine.CineId);

            // cine = cbl.GetCinemaByCineId(us.Cine.CineId);
            cs.DisplayTableData(movies, properties, cols, "dd/MM/yyyy");
            Console.WriteLine(row1);
            Console.Write("\nChọn phim(theo mã): "); sche.MovieId = cs.input(Console.ReadLine());
            while (mbl.GetMovieByMovieId(sche.MovieId) == null)
            {
                Console.Write("Không có mã này, mời bạn nhập lại: "); sche.MovieId = cs.input(Console.ReadLine());
            }
            cine = us.Cine;
            Console.Clear();
            List <ScheduleDetail> lsd = null;
            int?       scheNewId;
            ScheduleBL sbl     = new ScheduleBL();
            Schedule   scheNew = null;

            while (true)
            {
                // row1 = "========================================";
                // row2 = "----------------------------------------";
                Console.WriteLine(row1);
                Console.WriteLine("Tạo lịch chiếu phim.");
                Console.WriteLine(row2);
                Console.WriteLine("[Danh sách phòng]\n");
                string[] proper = { "RoomId", "RoomName", "RTName" };
                string[] col    = { "Mã phòng", "Tên phòng", "Loại phòng" };
                lr = rbl.GetRoomsByCineId(1);
                cs.DisplayTableData(lr, proper, col, null);
                Console.WriteLine(row1);
                Console.Write("\nChọn phòng(theo mã): "); sche.RoomId = cs.input(Console.ReadLine());
                while (rbl.GetRoomByRoomId(sche.RoomId) == null)
                {
                    Console.Write("Không có mã này, mời bạn nhập lại: "); sche.RoomId = cs.input(Console.ReadLine());
                }
                // while (sbl.GetScheduleByMovieIdAndRoomId(sche.MovieId, sche.RoomId) != null)
                // {
                //     Console.Write("Trùng lịch chiếu, mời bạn nhập lại: ");
                //     sche.RoomId = cs.input(Console.ReadLine());
                //     while (rbl.GetRoomByRoomId(sche.RoomId) == null)
                //     {
                //         Console.Write("Không có mã này, mời bạn nhập lại: "); sche.RoomId = cs.input(Console.ReadLine());
                //     }
                // }
                scheNew = sbl.GetScheduleByMovieIdAndRoomId(sche.MovieId, sche.RoomId);
                if (scheNew == null)
                {
                    scheNewId = null;
                }
                else
                {
                    scheNewId = scheNew.ScheId;
                }
                movie = mbl.GetMovieByMovieId(sche.MovieId);
                room  = rbl.GetRoomByRoomId(sche.RoomId);

                lsd = DisplayTime(movie, room, scheNew);
                // Console.Write("Không tìm thấy khung giờ hoặc trùng, bạn có muốn chọn lại?(C/K)");
                // string choice = Console.ReadLine();
                // switch (choice)
                // {
                //     case "C":
                //         scheNew = sbl.GetScheduleByMovieIdAndRoomId(sche.MovieId, sche.RoomId);
                //         movie = mbl.GetMovieByMovieId(sche.MovieId);
                //         room = rbl.GetRoomByRoomId(sche.RoomId);
                //         lsd = DisplayTime(movie, room, scheNew);
                //         break;
                //     case "c":
                //         scheNew = sbl.GetScheduleByMovieIdAndRoomId(sche.MovieId, sche.RoomId);
                //         movie = mbl.GetMovieByMovieId(sche.MovieId);
                //         room = rbl.GetRoomByRoomId(sche.RoomId);
                //         lsd = DisplayTime(movie, room, scheNew);
                //         break;
                //     case "K":
                //         mn.menuManager(us);
                //         return;
                //     case "k":
                //         mn.menuManager(us);
                //         return;
                //     default:
                //         continue;
                //         // break;
                // }
                if (lsd != null)
                {
                    break;
                }

                Console.Clear();
                Console.WriteLine("Phim: {0} tại phòng: {1} đã đủ suất chiếu !", movie.MovieName, room.RoomName);
            }

            Console.Clear();
            Console.WriteLine(row1);
            Console.WriteLine("Tạo lịch chiếu phim.");
            Console.WriteLine(row2);
            Console.WriteLine("[Chi tiết lịch chiếu]\n");
            Console.WriteLine("Bộ phim: " + movie.MovieName);
            Console.WriteLine("Chiếu tại rạp: " + cine.CineName);
            Console.WriteLine("Chiếu tại phòng: " + room.RoomName);
            Console.WriteLine("Trong các khung giờ lặp mỗi ngày từ ngày {0} - {1} cụ thể như sau: ", movie.MovieDateStart.ToString("dd/MM/yyyy"), movie.MovieDateEnd.ToString("dd/MM/yyyy"));
            int    count    = 1;
            string timeline = "";

            if (scheNew != null)
            {
                timeline = scheNew.ScheTimeline;
            }

            for (int i = 1; i < lsd.Count - 1; i++)
            {
                if (lsd[0].SchedTimeStart?.ToString("HH:mm") == lsd[i].SchedTimeStart?.ToString("HH:mm"))
                {
                    break;
                }
                count++;
            }
            for (int i = 0; i < count; i++)
            {
                try
                {
                    Console.WriteLine("{0}.{1} -> {2}", i + 1, lsd[i].SchedTimeStart?.ToString("HH:mm"), lsd[i].SchedTimeEnd?.ToString("HH:mm"));
                    if (timeline == "")
                    {
                        timeline = timeline + lsd[i].SchedTimeStart?.ToString("HH:mm");
                    }
                    else
                    {
                        timeline = timeline + ", " + lsd[i].SchedTimeStart?.ToString("HH:mm");
                    }
                }
                catch (System.Exception)
                {
                }
            }
            // foreach (var item in lsd)
            // {
            //     if (Schedule)
            //     {

            //     }
            //     {
            //         Console.WriteLine("{0}.{1} {2} -> {3}", count, item.SchedTimeEnd?.ToString("dd/MM/yyyy"), item.SchedTimeStart?.ToString("HH:mm"), item.SchedTimeEnd?.ToString("HH:mm"));
            //     }
            //     if (timeline == "")
            //     {
            //         timeline = timeline + item.SchedTimeStart?.ToString("HH:mm");
            //     }
            //     else
            //     {
            //         timeline = timeline + ", " + item.SchedTimeStart?.ToString("HH:mm");
            //     }
            //     count++;
            // }
            sche = new Schedule(scheNewId, 0, null, timeline, sche.RoomId, sche.MovieId, lsd);
            Console.WriteLine(row1);
            while (true)
            {
                Console.Write("Xác nhận tạo lịch chiếu?(C/K)");
                string choice = Console.ReadLine();
                switch (choice)
                {
                case "C":
                    sbl.CreateSchedule(sche);
                    break;

                case "c":
                    sbl.CreateSchedule(sche);
                    break;

                case "K":
                    break;

                case "k":
                    break;

                default:
                    continue;
                    // break;
                }
                break;
            }
            Console.Clear();

            mn.menuManager(us);
        }