Beispiel #1
0
        }        //End GetPath (int)

        /// <summary>
        /// Displays all Card in list.
        /// </summary>
        /// <param name="cards">The cards.</param>
        public static void DisplayAllCards(CreditCardList cards)
        {
            int index = 0;             //Index of current value

            //Display all Cards
            foreach (CreditCard card in cards)
            {
                Console.WriteLine((index + 1) + ".\n" + card.ToString( ) + "\n\n");
                index++;
            }
        }        //End DisplayAllCards (CreditCardList)
Beispiel #2
0
        }        //End DisplayCard (CreditCard)

        /// <summary>
        /// Requests the save.
        /// </summary>
        /// <param name="cards">The cards.</param>
        public static void RequestSave(CreditCardList cards)
        {
            //User try to exit dialog
            DialogResult result;

            result = MessageBox.Show("Would like to save the list " +
                                     "before continuing",
                                     "Error",
                                     MessageBoxButtons.YesNo,
                                     MessageBoxIcon.Error);
            if (result == DialogResult.Yes)
            {
                cards.SaveDataFile(GetPath(SAVE));
                MessageBox.Show("File was saved");
            }    //End else-if statement
        }        //End RequestSave (CreditCardList)
Beispiel #3
0
        }                             //End Main (string [ ])

        #endregion

        #region Extra methods
        /// <summary>
        /// Gets the card.
        /// </summary>
        /// <param name="cards">The cards.</param>
        /// <returns>Card</returns>
        private static CreditCard GetCard(CreditCardList cards)
        {
            int choice = -1;

            do
            {
                DisplayAllCards(cards);
                Console.WriteLine("\n\nWhich card");
                try
                {
                    choice = Int32.Parse(Console.ReadLine( ));
                }
                catch (Exception e)
                {
                    //Display Error Message
                    MessageBox.Show(e.Message,
                                    "Error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            } while (choice < 1 || cards.Count < choice);
            return(cards[choice - 1]);
        }        //End GetCard (CreditCardList)
Beispiel #4
0
        static void Main(string [] args)
        {
            CreditCardList Cards          = null;
            ConsoleColor   Background     = ConsoleColor.Blue;
            ConsoleColor   Foreground     = ConsoleColor.White;
            string         welcomeMessage = "Welcome to the customer control log. This program will allow you to add new customers" +
                                            ", update existing customers, and store their forms of payment. Where would you like to start?";
            string exitMessage = "Thank you, for using this program if you have any question.\n" +
                                 "\nPlease contact me at:\n\n" +
                                 "Justin Adams\n" +
                                 "[email protected]\n" +
                                 "CSCI 2210\n";

            string [] MenuMain = { "Create Card List",
                                   "Open Card List",
                                   "Add Credit Card",
                                   "Remove Credit Card",
                                   "Display Credit Card",
                                   "Find Credit Card By Number",
                                   "Find Credit Cards By Customer",
                                   "Display All Valid Cards",
                                   "Sort Credit By Number",
                                   "Display All Cards",
                                   "Exit Program" };
            string [] MenuChange = { "Name",
                                     "Email",
                                     "Phone",
                                     "Card Number",
                                     "Card Expiration" };
            //Set Colors for Console
            Console.BackgroundColor = Background;
            Console.ForegroundColor = Foreground;
            Console.Clear( );

            //Display Welcome Message
            Utility.Message(welcomeMessage, "Welcome");
            //Add Menu switch between the choices
            int Selection = -1;             //Selection index for menu

            do
            {
                //Reset Index
                Selection = -1;
                try
                {
                    Selection = Utility.Menu(MenuMain);
                }                //End try statement
                catch (Exception e)
                {
                    //Display Error Message
                    MessageBox.Show(e.Message,
                                    "Error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }                //End catch statement
                switch (Selection)
                {
                case 1:                        //Create new credit card list
                    if (Cards != null && Cards.SaveNeeded)
                    {
                        RequestSave(Cards);
                        Cards = new CreditCardList( );
                    }                            //End if statement
                    Cards = new CreditCardList( );
                    break;

                case 2:                        //Open credit card list from list
                    try
                    {
                        Cards = new CreditCardList(GetPath(OPEN));
                        MessageBox.Show("Credit card list was opened",
                                        "Opened",
                                        MessageBoxButtons.OK);
                    }                            //End try statement
                    catch (Exception e)
                    {
                        //Display Error Message
                        MessageBox.Show(e.Message,
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }                            //End catch statement
                    break;

                case 3:                        //Add credit card to list
                    if (Cards != null)
                    {
                        try
                        {
                            Cards += AddCard(MenuChange);
                        }                                //End try statement
                        catch (Exception e)
                        {
                            //Display Error Message
                            MessageBox.Show(e.Message,
                                            "Error",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        }                        //End catch statement
                    }                            //End if statement
                    else
                    {
                        MessageBox.Show("Please create a card list first",
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }                            //End else statement
                    break;

                case 4:                        //Remove credit card from list
                    if (Cards != null)
                    {
                        try
                        {
                            Cards -= GetCard(Cards);
                        }                                //End try statement
                        catch (Exception e)
                        {
                            //Display Error Message
                            MessageBox.Show(e.Message,
                                            "Error",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        }                        //End catch statement
                    }                            //End if statement
                    else
                    {
                        MessageBox.Show("Please create a card list first",
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }                            //End else statement
                    break;

                case 5:                        //Find card by position
                    if (Cards != null)
                    {
                        try
                        {
                            DisplayCard(GetCard(Cards));
                            Utility.PressAnyKey( );
                        }                                //End try statement
                        catch (Exception e)
                        {
                            //Display Error Message
                            MessageBox.Show(e.Message,
                                            "Error",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        }                        //End catch statement
                    }                            //End if statement
                    else
                    {
                        MessageBox.Show("Please create a card list first",
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }                            //End else statement
                    break;

                case 6:                        //Find card by the card number
                    if (Cards != null)
                    {
                        try
                        {
                            Console.WriteLine("What is the number");
                            DisplayCard(Cards [Console.ReadLine( )]);
                            Utility.PressAnyKey( );
                        }                                //End try statement
                        catch (Exception e)
                        {
                            //Display Error Message
                            MessageBox.Show(e.Message,
                                            "Error",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        }                        //End catch statement
                    }                            //End if statement
                    else
                    {
                        MessageBox.Show("Please create a card list first",
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }                            //End else statement
                    break;

                case 7:                        //Find card or cards by customer name
                    if (Cards != null)
                    {
                        try
                        {
                            Console.WriteLine("What is the name");
                            List <CreditCard> Names = Cards.RetrieveCardByName(Console.ReadLine( ));
                            foreach (CreditCard card in Names)
                            {
                                DisplayCard(card);
                            }                            //End foreach loop
                            Utility.PressAnyKey( );
                        }                                //End try statement
                        catch (Exception e)
                        {
                            //Display Error Message
                            MessageBox.Show(e.Message,
                                            "Error",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        }                        //End catch statement
                    }                            //End if statement
                    else
                    {
                        MessageBox.Show("Please create a card list first",
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }                            //End else statement
                    break;

                case 8:                        //Display all valid cards
                    if (Cards != null)
                    {
                        try
                        {
                            List <CreditCard> Names = Cards.RetrieveCards( );
                            foreach (CreditCard card in Names)
                            {
                                DisplayCard(card);
                            }                            //End foreach loop
                            Utility.PressAnyKey( );
                        }                                //End try statement
                        catch (Exception e)
                        {
                            //Display Error Message
                            MessageBox.Show(e.Message,
                                            "Error",
                                            MessageBoxButtons.OK,
                                            MessageBoxIcon.Error);
                        }                        //End catch statement
                    }                            //End if statement
                    else
                    {
                        MessageBox.Show("Please create a card list first",
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }                            //End else statement
                    break;

                case 9:                        //Sort cards by number
                    if (Cards != null)
                    {
                        Cards.Sort( );
                    }                            //End if statement
                    else
                    {
                        MessageBox.Show("Please create a card list first",
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }                            //End else statement
                    break;

                case 10:                        //Display all cards in list
                    if (Cards != null)
                    {
                        DisplayAllCards(Cards);
                        Utility.PressAnyKey( );
                    }                            //End if statement
                    else
                    {
                        MessageBox.Show("Please create a card list first",
                                        "Error",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error);
                    }                            //End else statement
                    break;

                case 11:                        //Exit program
                    if (Cards != null)
                    {
                        if (Cards.SaveNeeded)
                        {
                            RequestSave(Cards);
                        }                                //End if statement
                        else
                        {
                            Utility.Message(exitMessage, "Exit");
                            System.Environment.Exit(0);
                        }                        //End else statement
                    }                            //End if statement
                    else
                    {
                        Utility.Message(exitMessage, "Exit");
                        System.Environment.Exit(0);
                    }                            //End else statement
                    break;

                default:
                    break;
                }                     //End switch statement
            }while (Selection != 11); //End do-while loop
        }                             //End Main (string [ ])