void ShowMenu(MenuTitle menuTitle, MenuItem[] MenuItems)
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(menuTitle.ToString().PadLeft(offset + menuTitle.Length / 2));
            Console.WriteLine();
            Console.ResetColor();
            for (int i = 0; i < MenuItems.Length; i++)
            {
                if (i == index)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine(MenuItems[i].ToString().PadLeft(offset + MenuItems[i].Length / 2));
                    Console.ResetColor();
                }
                else
                {
                    Console.WriteLine(MenuItems[i].ToString().PadLeft(offset + MenuItems[i].Length / 2));
                }
            }
        }
        public PresentationLayer()
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            Console.OutputEncoding = Encoding.UTF8;
            Console.CursorVisible  = false;
            Console.WindowWidth    = 2 * offset;
            Console.Title          = appName;

            MainMenuMethods[0] = NewCinemaMenu;
            MainMenuMethods[1] = CinemasMenu;
            MainMenuMethods[2] = MostViewedProjectionMenu;
            MostViewedProjectionMenuMethods[0] = delegate() { IO_Handler.SaveToFile(mostViewedProjectionData); }; //Western technique

            DelegateDictionaries["MainMenu"]    = MainMenuMethods;
            DelegateDictionaries["CinemasMenu"] = CinemasMenuMethods;
            DelegateDictionaries["MostViewedProjectionMenu"] = MostViewedProjectionMenuMethods;
            DelegateDictionaries["InCinemaMenu"]             = InCinemaMenuMethods;
            DelegateDictionaries["InAuditoriumMenu"]         = InAuditoriumMenuMethods;
            DelegateDictionaries["InProjectionMenu"]         = InProjectionMenuMethods;
            DelegateDictionaries["ReservationMenu"]          = ReservationMenuMethods;
            InfoMenu();
            MainMenu();
        }
Beispiel #3
0
        private byte CheckAndReturnPosition(TableElement element)
        {
            byte input;

            if (element == TableElement.row)
            {
                do
                {
                    input = IO_Handler.EnterByte("Please, enter the number of rows: ");
                    if (input < 1 || input > OwnerAuditorium.Rows)
                    {
                        IO_Handler.ErrorMessage($"Invalid input. Pick from range [1-{OwnerAuditorium.Rows}]");
                    }
                } while (input < 1 || input > OwnerAuditorium.Rows);
            }
            else if (element == TableElement.column)
            {
                do
                {
                    input = IO_Handler.EnterByte("Please, enter the number of columns: ");
                    if (input < 1 || input > OwnerAuditorium.Columns)
                    {
                        IO_Handler.ErrorMessage($"Invalid input. Pick from range [1-{OwnerAuditorium.Columns}]");
                    }
                } while (input < 1 || input > OwnerAuditorium.Columns);
            }
            else
            {
                throw new InvalidOperationException("There's no such TableElement! Where the hell did you get that from???");
            }
            return((byte)(input - 1));
        }
Beispiel #4
0
        public override string ToString()
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            return(Name);
        }
Beispiel #5
0
        }   //Not implemented in PresentationLayer, so become obsolete:

        #endregion

        #region OVERRIDES
        public override string ToString()
        {
            #region debug message
            #if DEBUG
            IO_Handler.LogItsCaller();
            #endif
            #endregion
            return($"Auditorium No.{Id}.");
        }
Beispiel #6
0
        public override bool Equals(object obj)
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            return(obj is Cinema cinema &&
                   (Name == cinema.Name));
        }
Beispiel #7
0
 public override bool Equals(object obj)
 {
     #region debug message
     #if DEBUG
     IO_Handler.LogItsCaller();
     #endif
     #endregion
     return(obj is Auditorium auditorium &&
            (Id == auditorium.Id));
 }
Beispiel #8
0
        public Cinema(string Name, byte NumberOfAuditoriums) : base(Name)
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            OwnAuditoriums = new Dictionary <byte, Auditorium>();
            InitAuditoriums(NumberOfAuditoriums);
            ObjectContainer.CDB.Add(this);
        }
        void CinemasMenu()
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            MenuTitle  cinemasMenu      = "Cinemas";
            MenuItem[] cinemasMenuItems = ListToMenuItemArray(ObjectContainer.CDB);
            KeepDoingMenu(cinemasMenu, cinemasMenuItems);
        }
Beispiel #10
0
 private void TestAndCreate(Movie movie)
 {
     try
     {
         OwnProjections.Add(movie.Name, new Projection(this, movie));
         IO_Handler.SuccessMessage($"New projection \"{movie.Name}\" has been added");
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Beispiel #11
0
        public Auditorium(byte Id, Cinema Owner, byte Rows, byte Columns)
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            this.Id          = Id;
            this.OwnerCinema = Owner;
            this.Rows        = Rows;
            this.Columns     = Columns;
            OwnProjections   = new Dictionary <string, Projection>();
        }
Beispiel #12
0
        void MainMenu()
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            MenuTitle  mainMenu       = "MAIN MENU";
            MenuItem   newCinema      = "-Create New Cinema-";
            MenuItem   cinemas        = "Cinemas Menu";
            MenuItem   mostProjection = "Most Viewed Projection";
            MenuItem[] MainMenuItems  = { newCinema, cinemas, mostProjection };
            KeepDoingMenu(mainMenu, MainMenuItems);
        }
Beispiel #13
0
        MenuItem[] DictToMenuItemArray <K, V>(Dictionary <K, V> Collection)
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            List <V> Helper = new List <V>();
            foreach (var item in Collection)
            {
                Helper.Add(item.Value);
            }
            return(ListToMenuItemArray(Helper));
        }
Beispiel #14
0
        MenuItem[] ListToMenuItemArray <T>(List <T> Collection)
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            MenuItem[] MenuItems = new MenuItem[Collection.Count];
            for (int i = 0; i < Collection.Count; i++)
            {
                MenuItems[i] = Collection[i].ToString();
            }
            return(MenuItems);
        }
Beispiel #15
0
        void InAuditoriumMenu()
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
            Thread.Sleep(500);
#endif
            #endregion
            MenuTitle  inAuditoriumMenu      = "In ";
            MenuItem[] inAuditoriumMenuItems = { "-Add Nem Projection-", "Projections" };
            InAuditoriumMenuMethods[0] = activeAuditorium.AddNewProjection;
            InAuditoriumMenuMethods[1] = InProjectionMenu;
            string currentAuditorium = inAuditoriumMenu + activeCinema.OwnAuditoriums[(byte)(index + 1)].ToString() + $"@{ activeCinema}";
            KeepDoingMenu(currentAuditorium, inAuditoriumMenuItems);
        }
Beispiel #16
0
        public Projection FindProjectionByName()
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            if (OwnProjections.Count > 0)
            {
                return(ReturnProjectionByName());
            }
            else
            {
                throw new InvalidOperationException("Related to this Auditorium, there hasn't been any Projections created yet.");
            }
        }      //Not implemented in PresentationLayer, so become obsolete:
Beispiel #17
0
        private Auditorium TryToReturn(byte audNo)
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            try
            {
                return(OwnAuditoriums[audNo]);
            }
            catch (Exception e)
            {
                throw new Exception($"There\'s no such Auditorium in this Cinema: {Name}\n\n", e);
            }
        }
Beispiel #18
0
        //In Subs:
        void InCinemaMenu()
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
            Thread.Sleep(500);
#endif
            #endregion
            MenuTitle  inCinemaMenu      = "In Cinema: ";
            MenuItem[] inCinemaMenuItems = DictToMenuItemArray(ObjectContainer.CDB[index].OwnAuditoriums);
            string     currentCinema     = inCinemaMenu + ObjectContainer.CDB[index].Name;
            activeCinema = ObjectContainer.CDB[index];
            for (int i = 0; i < activeCinema.OwnAuditoriums.Count; i++)
            {
                InCinemaMenuMethods[i] = InAuditoriumMenu;
            }
            KeepDoingMenu(currentCinema, inCinemaMenuItems);
        }
Beispiel #19
0
 public void FreeSeat()
 {
     #region debug message
     #if DEBUG
     Program.LogThisCaller();
     #endif
     #endregion
     byte row = CheckAndReturnPosition(TableElement.row);
     byte col = CheckAndReturnPosition(TableElement.column);
     if (GetSeatAvailability(row, col) == Seat.UnAvailable)
     {
         FlipSeatAvailabilty(row, col);
         ReservedSeatsCount--;
     }
     else
     {
         IO_Handler.ErrorMessage("Still free!");
     }
 }
Beispiel #20
0
        //In Main:
        void NewCinemaMenu()
        {
            MenuTitle newCinemaMenu = "New Cinema Menu";

            MenuItem[] newCinemaMenuItems = { };
            ShowMenu(newCinemaMenu, newCinemaMenuItems);
            string cinemaName = IO_Handler.EnterString("Please, enter the name of the new cinema: ");

            if (ObjectContainer.CDB.Contains(ObjectContainer.CDB.Find(i => i.Name == cinemaName.ToUpper())))
            {
                throw new Exception("This Cinema has already exists!");
            }
            byte auditoriumCount = IO_Handler.EnterByte("Please, enter the number of auditoriums: ");

            new Cinema(cinemaName, auditoriumCount);
            CinemasMenuMethods[cinemaCounter++] = InCinemaMenu;
            IO_Handler.SuccessMessage($"New Cinema: \"{cinemaName}\" has been created with {auditoriumCount} Auditorium{(auditoriumCount>1?"s":"")} in it.");
            Thread.Sleep(sleepTime);
        }
Beispiel #21
0
        }      //Not implemented in PresentationLayer, so become obsolete:

        private Projection ReturnProjectionByName()
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            string projectionName = "";
            while (!OwnProjections.ContainsKey(projectionName))
            {
                projectionName = IO_Handler.EnterString("Name of the movie you are looking for: ").ToUpper();
                if (!OwnProjections.ContainsKey(projectionName))
                {
                    IO_Handler.ErrorMessage($"There is no such Projection in this Auditorium No#{Id} with the given name!");
                    Console.WriteLine("Please, pick one from the following:");
                    IO_Handler.PrintCollection(OwnProjections.Keys);
                }
            }
            Projection Result = OwnProjections[projectionName];
            IO_Handler.SuccessMessage("Projection found!");
            return(Result);
        }   //Not implemented in PresentationLayer, so become obsolete:
Beispiel #22
0
        public Auditorium FindAuditorium()
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            byte audNo = IO_Handler.EnterByte("Enter the #No. of the Auditorium you are looking for: ");

            if (OwnAuditoriums.Count < 1)
            {
                throw new ArgumentOutOfRangeException($"There hasn't been any Auditoriums created yet in this Cinema: {Name}");
            }
            else if (audNo <= OwnAuditoriums.Count)
            {
                return(TryToReturn(audNo));
            }
            else
            {
                throw new ArgumentOutOfRangeException($"You have entered a too large value.\n" +
                                                      $"Please, select within the range of [ 1 - {OwnAuditoriums.Count} ]");
            }
        }
Beispiel #23
0
        public void AddNewProjection()
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            if (OwnProjections.Count < 5)
            {
                string movieName = IO_Handler.EnterString($"{OwnerCinema}/{this}:\n" +
                                                          $"Enter the name of the movie beeing projected: ").ToUpper();
                if (OwnProjections.ContainsKey(movieName))
                {
                    throw new OperationCanceledException("Operation canceled: This movie has already beeing projected here!");
                }
                byte  movieLength  = IO_Handler.EnterByte("Enter the length of this movie in minutes: ");
                Movie currentMovie = new Movie(movieName, movieLength);
                TestAndCreate(currentMovie);
            }
            else
            {
                IO_Handler.ErrorMessage("Projection Limit Reached");
            }
        }
Beispiel #24
0
        private void InitAuditoriums(byte NumberOfAuditoriums)
        {
            #region debug message
#if DEBUG
            IO_Handler.LogItsCaller();
#endif
            #endregion
            byte rows;
            byte cols;
            byte id;
            for (int indexer = 0; indexer < NumberOfAuditoriums; indexer++)
            {
                id = (byte)(indexer + 1);
                do
                {
                    rows = IO_Handler.EnterByte($"Number of rows for Auditorium #No.{id}: ");
                } while (rows < 1);
                do
                {
                    cols = IO_Handler.EnterByte($"Number of columns for Auditorium #No.{id}: ");
                } while (cols < 1);
                OwnAuditoriums.Add(id, new Auditorium(id, this, rows, cols));
            }
        }
Beispiel #25
0
        bool ControlMenu(MenuItem[] MenuItems)
        {
            #region debug message
            #if DEBUG
            IO_Handler.LogItsCaller();
            #endif
            #endregion
            bool invalid = true;
            while (invalid)
            {
                ConsoleKey ck = Console.ReadKey(false).Key;
                switch (ck)
                {
                case ConsoleKey.UpArrow:
                    if (--index == -1)
                    {
                        index = MenuItems.Length - 1;
                    }
                    goto case ConsoleKey.Clear;

                case ConsoleKey.DownArrow:
                    if (++index == MenuItems.Length)
                    {
                        index = 0;
                    }
                    goto case ConsoleKey.Clear;

                case ConsoleKey.PageDown:
                    index = MenuItems.Length - 1;
                    goto case ConsoleKey.Clear;

                case ConsoleKey.PageUp:
                    index = 0;
                    goto case ConsoleKey.Clear;

                case ConsoleKey.Enter:
                    Console.Clear();
                    try
                    {
                        StackFrame sf          = new StackFrame(2);
                        string     caller_lvl2 = sf.GetMethod().Name;
                        if (caller_lvl2.Equals("InCinemaMenu"))
                        {
                            try
                            {
                                activeAuditorium = activeCinema.OwnAuditoriums[(byte)(index + 1)];
                                #region DEBUG
#if DEBUG
                                IO_Handler.SuccessMessage("ACTIVE AUDITORIUM GOT SET NOW!");
                                Thread.Sleep(800);
#endif
                                #endregion
                            }
                            catch (Exception e)
                            {
                                IO_Handler.ErrorMessage($"active auditorium not set:\nLOC-{(new StackFrame(1, true)).GetFileLineNumber()}\n" + e.Message);
                                Thread.Sleep(sleepTime);
                            }
                        }
                        if (caller_lvl2.Equals("InProjectionMenu"))
                        {
                            try
                            {
                                activeProjection = activeAuditorium.OwnProjections.Skip(index).First().Value;
                            }
                            catch (Exception e)
                            {
                                IO_Handler.ErrorMessage($"active projection not set:\nLOC-{(new StackFrame(1, true)).GetFileLineNumber()}\n" + e.Message);
                                Thread.Sleep(sleepTime);
                            }
                        }
                        GetThisMenuMethods()[index]();
                    }
                    catch (Exception e)
                    {
                        IO_Handler.ErrorMessage($"Error while opening this menu!\nLOC-{(new StackFrame(1, true)).GetFileLineNumber()}\n" + e.Message);
                        Thread.Sleep(sleepTime);
                    }
                    goto case ConsoleKey.Clear;

                case ConsoleKey.Escape:
                    index = 0;
                    return(false);

                case ConsoleKey.Clear:
                    return(true);

                default:
                    invalid = true;
                    break;
                }
            }
            return(true);
        }