/// <summary>
        /// Step the frame and evaluate input.
        /// </summary>
        /// <param name="keyinfo">The input</param>
        public override void StepFrame(ConsoleKeyInfo keyinfo)
        {
            base.StepFrame();
            switch (keyinfo.Key)
            {
            case ConsoleKey.Escape:
                status = 4;
                break;

            case ConsoleKey.Enter:
                switch (ValidateInput())
                {
                case 0:
                    title.Flash(ConsoleColor.Red);
                    response.SetText("Unable to find film");
                    response.SetColor(ConsoleColor.Red);
                    break;

                case 1:
                    title.Flash(ConsoleColor.Red);
                    break;

                case 2:
                    status = 4;
                    break;

                default:
                    response.SetText("An unknown error occured");
                    response.SetColor(ConsoleColor.Red);
                    break;
                }
                break;

            default:
                title.Draw(g, keyinfo);
                break;
            }
        }
        /// <summary>
        /// Try to varify the login user.
        /// </summary>
        /// <returns></returns>
        public bool Login()
        {
            //see if they exist
            Member m = Program.members.GetMember(username.Text, out string message, out int index);

            if (message == "Success" && m.Login(password.Text))
            {
                Program.CurrentMember.Update(index);
                return(true);
            }
            //if they can't login for some reason, flash red
            username.Flash(ConsoleColor.Red);
            password.Flash(ConsoleColor.Red);
            return(false);
        }
        /// <summary>
        /// Validate the input the user gave, and give the appropriate response.
        /// </summary>
        /// <returns>If the data was validated and film added</returns>
        internal bool ValidateData()
        {
            bool success = true;

            if (!Regex.IsMatch(title.Text, @"[A-Za-z0-9 \.]+"))
            {
                title.Flash(ConsoleColor.Red);
                success = false;
            }
            if (!Regex.IsMatch(starring.Text, @"[A-Z][a-z\. A-Z,]+"))
            {
                starring.Flash(ConsoleColor.Red);
                success = false;
            }
            if (!Regex.IsMatch(director.Text, @"[A-Z][a-z\. A-Z,]+"))
            {
                director.Flash(ConsoleColor.Red);
                success = false;
            }
            if (!Regex.IsMatch(duration.Text, @"[0-9]+:[0-9]+:[0-9]+"))
            {
                duration.Flash(ConsoleColor.Red);
                success = false;
            }
            if (genre.Text.FriendlyGenreName() == MovieGenre.Error)
            {
                genre.Flash(ConsoleColor.Red);
                success = false;
            }
            if (classification.Text.FriendlyClassName() == MovieClass.Error)
            {
                classification.Flash(ConsoleColor.Red);
                success = false;
            }
            if (!int.TryParse(quantity.Text, out int i) || i < 0)
            {
                quantity.Flash(ConsoleColor.Red);
                success = false;
            }
            if (success)
            {
                string[] s   = duration.Text.Split(':');
                int[]    dur = new int[] { int.Parse(s[0]), int.Parse(s[1]), int.Parse(s[2]) };
                Program.movieCollection.AddDVD(new Movie(title.Text, starring.Text.Split(','), director.Text, dur, genre.Text.FriendlyGenreName(), classification.Text.FriendlyClassName(), int.Parse(quantity.Text)));
            }

            return(success);
        }
 /// <summary>
 /// attempts to borrow the dvd given by the user input.
 /// </summary>
 /// <returns>if it worked</returns>
 private int ValidateInput()
 {
     //first check if the user can even borrow.
     if (Program.members.registeredMembers[Program.CurrentMember.Value].borrowed.GetLength() > 9)
     {
         response.SetText("Borrow Limit reached");
         response.SetColor(ConsoleColor.Red);
         return(0);
     }
     //then check if the given text looks like a move title.
     if (Regex.IsMatch(Title.Text, @"[A-Za-z0-9 \.]+"))
     {
         //check to see if we have the movie.
         Movie m = Program.movieCollection.BorrowMovie(Title.Text, out string message);
         //if we failed for some reason say why.
         if (message != "Success")
         {
             response.SetText(message);
             response.SetColor(ConsoleColor.Red);
             return(0);
         }
         //otherwise if the user hasn't already borrowed a copy of that film, borrow it.
         else if (Program.members.registeredMembers[Program.CurrentMember.Value].borrowed.GetifExists(Title.Text) == null)
         {
             Program.members.registeredMembers[Program.CurrentMember.Value].Borrow(m);
             return(1);
         }
         else
         {
             response.SetText("You've already borrowed that film");
             response.SetColor(ConsoleColor.Red);
             return(0);
         }
     }
     else
     {
         Title.Flash(ConsoleColor.Red);
         return(0);
     }
 }
 /// <summary>
 /// Validate The given input.
 /// </summary>
 /// <returns>The status of the validation</returns>
 private int ValidateInput()
 {
     if (Regex.IsMatch(Name.Text, @"[A-Za-z 0-9]+"))
     {
         Member m = Program.members.GetMember(Name.Text, out string message);
         if (message != "Success")
         {
             response.SetText(message);
             response.SetColor(ConsoleColor.Red);
             return(0);
         }
         else
         {
             response.SetText("Ph: " + m.GetPhoneNumber());
             response.SetColor(ConsoleColor.Green);
         }
     }
     else
     {
         Name.Flash(ConsoleColor.Red);
     }
     return(1);
 }
예제 #6
0
 /// <summary>
 /// Validate The given input.
 /// </summary>
 /// <returns>The status of the validation</returns>
 private int ValidateInput()
 {
     if (Regex.IsMatch(Title.Text, @"[A-Za-z0-9 \.]+"))
     {
         Movie m = Program.members.registeredMembers[Program.CurrentMember.Value].borrowed.GetifExists(Title.Text);
         if (m == null)
         {
             response.SetText("Unable to find film");
             response.SetColor(ConsoleColor.Red);
             return(0);
         }
         else
         {
             m.Return();
             Program.members.registeredMembers[Program.CurrentMember.Value].borrowed.RemoveMovie(m);
             return(1);
         }
     }
     else
     {
         Title.Flash(ConsoleColor.Red);
         return(0);
     }
 }