public void SelectScheduleTimeByTestFail(int movie_id, string datetime, string time)
    {
        string regexDate = @"(?<year>\d{2,4})-(?<month>\d{1,2})-(?<day>\d{1,2})";
        string regexTime = @"^(\d{1,2}|\d\.\d{2}):([0-5]\d):([0-5]\d)(\.\d+)?$";

        Assert.DoesNotMatch(regexDate, datetime);
        Assert.DoesNotMatch(regexTime, time);
        ScheduleBL sch = new ScheduleBL();

        Assert.Null(sch.SelectTimeBy(movie_id, datetime, time));
    }
    public void SelectScheduleTimeByTestTrue(int movie_id, string datetime, string time)
    {
        // 2018-08-01
        string regexDate = @"(?<year>\d{2,4})-(?<month>\d{1,2})-(?<day>\d{1,2})";
        string regexTime = @"^(\d{1,2}|\d\.\d{2}):([0-5]\d):([0-5]\d)(\.\d+)?$";

        Assert.Matches(regexDate, datetime);
        Assert.Matches(regexTime, time);
        // DateTime datetime = DateTime.Now;
        // ScheduleBL sch = new ScheduleBL ();
        Assert.NotNull(sch.SelectTimeBy(movie_id, datetime, time));
    }
Example #3
0
        public static void ShowScheduleByMovieIdAndDatetime(int movie_id, ScheduleBL schechule, string datetime, string datetimeforDatabase)
        {
            Console.Clear();
            MoviesBL movie            = new MoviesBL();
            Movies   informatin       = movie.getMovieById(movie_id);
            RoomBL   room             = new RoomBL();
            TimeSpan datefortimespan  = DateTime.Now.TimeOfDay;
            DateTime comparedatetime  = DateTime.Now;
            string   comparedatetime1 = comparedatetime.ToString($"{comparedatetime:dd/MM/yyyy}");

            // Lấy ra lịch chiếu nhờ STT của Ngày chiếu.
            Console.WriteLine("=====================================================================");
            Console.WriteLine($"-Chọn Lịch Chiếu Của Phim  :  {informatin.Name} Ngày {datetime} -");
            Console.WriteLine("---------------------------------------------------------------------");
            Console.WriteLine("STT  |  Lịch Chiếu          |  Phòng          |  Số ghế còn lại    ");
            Console.WriteLine("---------------------------------------------------------------------");
            List <Schedules> demons = schechule.SelectTime(movie_id, datetimeforDatabase);
            // Lưu tất cả các TimeSpan để so sánh với DateTime.Now.TimeOfDay
            List <string> list1 = new List <string> ();
            // List2 để lấy ra các thời gian show ra màn hình.
            List <string> list2 = new List <string> ();

            string tym_one = string.Format("{0:D2}:{1:D2}:{2:D2}", datefortimespan.Hours, datefortimespan.Minutes, datefortimespan.Seconds);
            int    count1  = 0;

            foreach (var item in demons)
            {
                string timeText = string.Format("{0:D2}:{1:D2}:{2:D2}", item.Start_time.Hours, item.Start_time.Minutes, item.Start_time.Seconds);
                list1.Add(timeText);
            }
            for (int j = 0; j < demons.Count; j++)
            {
                Rooms  ro     = room.GetRoomById(demons[j].Room_id);
                string date1  = demons[j].Show_date.ToString($"{demons[j].Show_date:yyyy-MM-dd}");
                string timeTe = string.Format("{0:D2}:{1:D2}:{2:D2}", demons[j].Start_time.Hours, demons[j].Start_time.Minutes, demons[j].Start_time.Seconds);
                // Schedules sche = schechule.SelectTimeBy (demons[j].Movie_id,date1,timeTe);
                if (comparedatetime1.CompareTo(datetime) == 0)
                {
                    if (tym_one.CompareTo(list1[j]) < 0)
                    {
                        string start = string.Format("{0:D2}:{1:D2}", demons[j].Start_time.Hours, demons[j].Start_time.Minutes);
                        string end   = string.Format("{0:D2}:{1:D2}", demons[j].End_time.Hours, demons[j].End_time.Minutes);
                        count1++;
                        string addtimetolist2 = string.Format("{0:D2}:{1:D2}:{2:D2}", demons[j].Start_time.Hours, demons[j].Start_time.Minutes, demons[j].Start_time.Seconds);
                        list2.Add(addtimetolist2);
                        Schedules sche   = schechule.SelectTimeBy(demons[j].Movie_id, date1, timeTe);
                        string[]  count  = sche.Schedule_room_seat.Trim().Split(";");
                        string[]  seated = count[2].Split(",");
                        string[]  chaier = ro.Chaire_not_placed.Split(",");
                        int       a      = 0;
                        if (seated[0] != "")
                        {
                            a = ro.Number_Of_seats - seated.Length;
                        }
                        else
                        {
                            a = ro.Number_Of_seats;
                        }
                        if (chaier[0] != "")
                        {
                            a = a - chaier.Length;
                        }
                        string format = string.Format($"{count1}.   | {start,-5} -  {end,-5}       |  {ro.Name,-10}     | {a}");
                        Console.WriteLine(format);
                    }
                }
                else
                {
                    string start = string.Format("{0:D2}:{1:D2}", demons[j].Start_time.Hours, demons[j].Start_time.Minutes);
                    string end   = string.Format("{0:D2}:{1:D2}", demons[j].End_time.Hours, demons[j].End_time.Minutes);
                    count1++;
                    Schedules sche   = schechule.SelectTimeBy(demons[j].Movie_id, date1, timeTe);
                    string[]  count  = sche.Schedule_room_seat.Trim().Split(";");
                    string[]  seated = count[2].Split(",");
                    int       a      = 0;
                    if (seated[0] != "")
                    {
                        a = ro.Number_Of_seats - seated.Length;
                    }
                    else
                    {
                        a = ro.Number_Of_seats;
                    }
                    string[] chaier = ro.Chaire_not_placed.Split(",");
                    if (chaier[0] != "")
                    {
                        a = a - chaier.Length;
                    }
                    string addtimetolist2 = string.Format("{0:D2}:{1:D2}:{2:D2}", demons[j].Start_time.Hours, demons[j].Start_time.Minutes, demons[j].Start_time.Seconds);
                    list2.Add(addtimetolist2);
                    string format = string.Format($"{count1}.   | {start,-5} -  {end,-5}       |  {ro.Name,-10}     |  {a }");
                    Console.WriteLine(format);
                }
            }
            Console.WriteLine("---------------------------------------------------------------------");
            int number1;

            Console.WriteLine("0. Quay lại menu chính.");
            Console.WriteLine("*: Nhập số thứ tự để suất chiếu.");
            Console.WriteLine("---------------------------------------------------------------------");
            Console.Write("#Chọn :  ");
            while (true)
            {
                bool isINT = Int32.TryParse(Console.ReadLine(), out number1);
                if (!isINT)
                {
                    Console.WriteLine("Bạn vừa nhập sai giá trị, vui lòng nhập lại.");
                    Console.Write("#Chọn: ");
                }
                else if (number1 < 0 || number1 > list2.Count)
                {
                    Console.WriteLine($"Giá trị trong khoảng từ 0 - > { list2.Count }");
                    Console.Write("#Chọn: ");
                }
                else
                {
                    break;
                }
            }
            if (number1 == 0)
            {
                CinemaInterface.Cinema();
            }
            Console.Clear();
            Schedules sch = schechule.SelectTimeBy(movie_id, datetimeforDatabase, list2[number1 - 1]);

            ChoiceMapSeats.MenuChoiceSeats(sch);
        }
Example #4
0
        public static void MenuChoiceSeats(Schedules scheduleUp)
        {
            List <string> choicedSeat = new List <string> ();

            while (true)
            {
                // ------------------------ Map Seats in Database with Schedule.
                ScheduleBL schechuleBl = new ScheduleBL();
                string     showdate    = scheduleUp.Show_date.ToString($"{scheduleUp.Show_date:yyyy-MM-dd}");
                string     starttime   = string.Format("{0:D2}:{1:D2}:{2:D2}", scheduleUp.Start_time.Hours, scheduleUp.Start_time.Minutes, scheduleUp.Start_time.Seconds);
                Schedules  schedule    = schechuleBl.SelectTimeBy(scheduleUp.Movie_id, showdate, starttime);
                string     map         = schedule.Schedule_room_seat;
                Console.Clear();
                string[]      mapArr  = map.Split(";");
                string[]      rowsArr = mapArr[0].Split(" ");
                int           cols    = Int32.Parse(mapArr[1]);
                List <string> succer  = new List <string> ();
                string[]      seated  = mapArr[2].Split(",");
                succer = AddlistByMapSeat(succer, seated);
                // -------------- Map not
                RoomBL   room = new RoomBL();
                Rooms    ro   = room.GetRoomById(schedule.Room_id);
                string   map_ = ro.Chaire_not_placed;
                string[] map_chaire_not_placed = map_.Split(",");

                // -----------------------------------
                ShowSeatChoice(rowsArr, cols, seated, choicedSeat, schedule, map_chaire_not_placed);
                Console.WriteLine("\n        0. Quay lại.");
                Console.WriteLine("\n        *: Nhập số số ghế theo định dạng A1, A2, A3 để chọn ghế.");
                Console.WriteLine("\n     _______________________________________________________________________________________________");
                string   choice;
                string[] choiced;
                // Cho khánh hàng nhập các ghế mà khách hàng muốn chọn, Phải nhập đúng định dạng thì mới được break ra khỏi While(true).
                while (true)
                {
                    Console.Write("\n        •√ Bạn chọn ghế :");
                    choice = Console.ReadLine().Trim().ToUpper();
                    if (choice == "0")
                    {
                        BookingTicker tick = new BookingTicker();
                        tick.MenuBookingTicker();
                        return;
                    }
                    try {
                        if (choice[choice.Length - 1] == ',')
                        {
                            choice = choice.Remove(choice.Length - 1, 1);
                        }
                    } catch (System.Exception) { }
                    choiced = choice.Split(",");
                    if (CheckInsertIntoChoice(choiced) == true)
                    {
                        break;
                    }
                    else
                    {
                        Console.Clear();
                        ShowSeatChoice(rowsArr, cols, seated, choicedSeat, schedule, map_chaire_not_placed);
                        Console.WriteLine("\n        #: Bạn đã nhập sai định dạng ghế VD : A1, A2, A3. Vui lòng nhập lại!! Hoặc chọn 0 để thoát");
                    }
                }
                string test = "";
                test = CheckSeatInSchedule(choiced, succer, test, rowsArr, cols, map_chaire_not_placed);
                if (test != "")
                {
                    Console.Clear();
                    Console.WriteLine("\n                    -------------------------------------------------------------------------------");
                    Console.WriteLine("                          #: Ghế " + test + " mà bạn chọn không có trong danh sách hoặc đã được đặt rồi. ");
                    Console.WriteLine("                             Vui lòng chọn lại ghế hoặc thoát");
                    Console.WriteLine("\n                    -------------------------------------------------------------------------------");
                    ComeBackMenu(scheduleUp, 0);
                    return;
                }

                string checkedSeat = "";
                // List<string> choicedSeat = new List<string> ();
                for (int i = 0; i < choiced.Length; i++)
                {
                    if (succer.FindIndex(x => x == choiced[i]) == -1)
                    {
                        if (choicedSeat.FindIndex(x => x == choiced[i]) == -1)
                        {
                            succer.Add(choiced[i]);
                            choicedSeat.Add(choiced[i]);
                        }
                        else
                        {
                            checkedSeat = checkedSeat + " " + choiced[i];
                        }
                    }
                }

                ShowSeatChoice(rowsArr, cols, seated, choicedSeat, schedule, map_chaire_not_placed);
                ChoiceBookingAndContinue();
                if (checkedSeat != "")
                {
                    Console.WriteLine("             Bạn vừa chọn ghế " + checkedSeat + " này rồi ! ");
                }
                Console.Write("\n             #Chọn : ");
                int number;
                while (true)
                {
                    bool isINT = Int32.TryParse(Console.ReadLine(), out number);
                    if (!isINT)
                    {
                        Console.Clear();
                        ShowSeatChoice(rowsArr, cols, seated, choicedSeat, schedule, map_chaire_not_placed);
                        ChoiceBookingAndContinue();
                        Console.WriteLine("\n             • Giá trị sai vui lòng nhập lại.");
                        Console.Write("\n             #Chọn : ");
                    }
                    else if (number < 0 || number > 2)
                    {
                        Console.Clear();
                        ShowSeatChoice(rowsArr, cols, seated, choicedSeat, schedule, map_chaire_not_placed);
                        ChoiceBookingAndContinue();
                        Console.WriteLine("\n             • Giá trị sai vui lòng nhập lại 1 hoặc 2. ");
                        Console.Write("\n             #Chọn : ");
                    }
                    else
                    {
                        break;
                    }
                }
                Console.WriteLine();
                switch (number)
                {
                case 1:
                    map = AddSeatsForSchedule(choicedSeat, seated, map);
                    InformationMovieBookingTickets(schedule, choicedSeat, map);
                    choicedSeat = null;
                    choicedSeat = new List <string> ();
                    break;

                case 2:
                    Console.Clear();
                    break;
                }
            }
        }
        public void ChooseMovieScheduleForYou(int movie_id)
        {
            Console.Clear();
            MoviesBL   movie     = new MoviesBL();
            ScheduleBL schechule = new ScheduleBL();
            RoomBL     room      = new RoomBL();
            // information . Lấy ra phim nhờ id movie
            Movies informatin = movie.getMovieById(movie_id);
            // list lấy ra tất cả lịch chiếu của phim.
            List <DateTime> list             = schechule.SelectDatetime(movie_id);
            TimeSpan        datefortimespan  = DateTime.Now.TimeOfDay;
            DateTime        comparedatetime  = DateTime.Now;
            string          comparedatetime1 = comparedatetime.ToString($"{comparedatetime:dd/MM/yyyy}");
            // Array này lấy ra ngày để connect tới database format by yyyy-MM-dd.
            List <string> array = new List <string> ();
            // Array1 này. Lưu lại thời gian để so sách với thời gian hiện tại.
            List <string> array1 = new List <string> ();

            int dem = 0;

            string[] arr1 = new string[] { "Thứ hai", "Thứ ba", "Thứ tư", "Thứ năm", "Thứ sáu", "Thứ bảy", "Chủ nhật" };
            string[] arr2 = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
            Console.WriteLine("============================================================================================");
            Console.WriteLine($"----------------- Chọn Ngày Chiếu Của Phim  :  {informatin.Name} ");
            Console.WriteLine("============================================================================================");
            for (int i = 0; i < list.Count; i++)
            {
                string date = list[i].Date.ToString($"{list[i].Date:dd/MM/yyyy}");
                if (list[i].Date > DateTime.Now && comparedatetime1.CompareTo(date) < 0 || comparedatetime1.CompareTo(date) == 0)
                {
                    string date1 = list[i].Date.ToString($"{list[i].Date:yyyy-MM-dd}");
                    array.Add(date1);
                    array1.Add(date);
                    int    count = -1;
                    string week  = $"{list[i].Date.DayOfWeek}";
                    for (int j = 0; j < arr2.Length; j++)
                    {
                        if (arr2[j] == week)
                        {
                            count = j;
                            break;
                        }
                    }
                    string format = string.Format($"{dem+1,2}.  {date}   {arr1[count],-8}  ");
                    dem++;
                    Console.WriteLine($"{format}");
                    Console.WriteLine();
                }
            }
            int number;

            Console.Write(" * ^: Nhập số STT để chọn ngày chiếu : ");
            while (true)
            {
                bool isINT = Int32.TryParse(Console.ReadLine(), out number);
                if (!isINT)
                {
                    Console.WriteLine("Bạn vừa nhập sai giá trị, vui lòng nhập lại.");
                    Console.Write("#Chọn: ");
                }
                else if (number <= 0 || number > array.Count)
                {
                    Console.WriteLine($"Giá trị trong khoảng từ 1 - > { array.Count }");
                    Console.Write("#Chọn: ");
                }
                else
                {
                    break;
                }
            }
            Console.Clear();
            // Lấy ra lịch chiếu nhờ STT của Ngày chiếu.
            Console.WriteLine("=====================================================================");
            Console.WriteLine($"-Chọn Lịch Chiếu Của Phim  :  {informatin.Name} Ngày {array1[number - 1]} -");
            Console.WriteLine("---------------------------------------------------------------------");
            Console.WriteLine("STT  |  Lịch Chiếu          |  Phòng          |   Số Ghế    ");
            Console.WriteLine("---------------------------------------------------------------------");
            List <Schedules> demons = schechule.SelectTime(movie_id, array[number - 1]);
            // Lưu tất cả các TimeSpan để so sánh với DateTime.Now.TimeOfDay
            List <string> list1 = new List <string> ();
            // List2 để lấy ra các thời gian show ra màn hình.
            List <string> list2 = new List <string> ();

            string tym_one = string.Format("{0:D2}:{1:D2}:{2:D2}", datefortimespan.Hours, datefortimespan.Minutes, datefortimespan.Seconds);
            int    count1  = 0;

            foreach (var item in demons)
            {
                string timeText = string.Format("{0:D2}:{1:D2}:{2:D2}", item.Start_time.Hours, item.Start_time.Minutes, item.Start_time.Seconds);
                list1.Add(timeText);
            }
            for (int j = 0; j < demons.Count; j++)
            {
                Rooms ro = room.GetRoomById(demons[j].Room_id);
                if (comparedatetime1.CompareTo(array1[number - 1]) == 0)
                {
                    if (tym_one.CompareTo(list1[j]) < 0)
                    {
                        string start = string.Format("{0:D2}:{1:D2}", demons[j].Start_time.Hours, demons[j].Start_time.Minutes);
                        string end   = string.Format("{0:D2}:{1:D2}", demons[j].End_time.Hours, demons[j].End_time.Minutes);
                        count1++;
                        string addtimetolist2 = string.Format("{0:D2}:{1:D2}:{2:D2}", demons[j].Start_time.Hours, demons[j].Start_time.Minutes, demons[j].Start_time.Seconds);
                        list2.Add(addtimetolist2);
                        string format = string.Format($"{count1}.   | {start,-5} -  {end,-5}       |  {ro.Name,-10}     | {ro.Number_Of_seats}");
                        Console.WriteLine(format);
                    }
                }
                else
                {
                    string start = string.Format("{0:D2}:{1:D2}", demons[j].Start_time.Hours, demons[j].Start_time.Minutes);
                    string end   = string.Format("{0:D2}:{1:D2}", demons[j].End_time.Hours, demons[j].End_time.Minutes);
                    count1++;
                    string addtimetolist2 = string.Format("{0:D2}:{1:D2}:{2:D2}", demons[j].Start_time.Hours, demons[j].Start_time.Minutes, demons[j].Start_time.Seconds);
                    list2.Add(addtimetolist2);
                    string format = string.Format($"{count1}.   | {start,-5} -  {end,-5}       |  {ro.Name,-10}     |  {ro.Number_Of_seats}");
                    Console.WriteLine(format);
                }
            }
            Console.WriteLine("======================================================================");
            int number1;

            Console.Write(" * ^: Nhập số STT để chọn ngày chiếu : ");
            while (true)
            {
                bool isINT = Int32.TryParse(Console.ReadLine(), out number1);
                if (!isINT)
                {
                    Console.WriteLine("Bạn vừa nhập sai giá trị, vui lòng nhập lại.");
                    Console.Write("#Chọn: ");
                }
                else if (number1 <= 0 || number1 > list2.Count)
                {
                    Console.WriteLine($"Giá trị trong khoảng từ 1 - > { list2.Count }");
                    Console.Write("#Chọn: ");
                }
                else
                {
                    break;
                }
            }
            Console.Clear();
            Schedules sch    = schechule.SelectTimeBy(movie_id, array[number - 1], list2[number1 - 1]);
            string    start1 = string.Format("{0:D2}:{1:D2}", sch.Start_time.Hours, sch.Start_time.Minutes);
            string    end1   = string.Format("{0:D2}:{1:D2}", sch.End_time.Hours, sch.End_time.Minutes);

            Console.WriteLine("=====================================================================");
            Console.WriteLine($"Rạp chiếu phim thế giới.");
            Console.WriteLine($"Phim : {informatin.Name}.  Ngày chiếu : {array1[number - 1]}. Lịch chiếu : {start1} - {end1}");
            Console.WriteLine("---------------------------------------------------------------------");
            Console.WriteLine("---------------------------------------------------------------------");
            Console.WriteLine("CHỌN GHẾ ");
            Console.WriteLine("---------------------------------------------------------------------");
        }