コード例 #1
0
 public void GetSchedulesByScheIdTest1()
 {
     Assert.NotNull(sbl.GetScheduleByScheId(1));
 }
コード例 #2
0
        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);
        }