Example #1
0
        private static void RemoveCard()
        {
            string indexstr;
            int    index;

            while (true)
            {
                Console.Clear();
                Console.WriteLine(" - Enter B To Back Out - ");
                Console.WriteLine("Enter ID: ");
                indexstr = Console.ReadLine();
                if (indexstr.ToLower().Equals("b"))
                {
                    return;
                }
                else if (Regex.IsMatch(indexstr, @"^[0-9]+$") && Convert.ToInt32(indexstr) >= 0 && Convert.ToInt32(indexstr) < Allcards.Count)
                {
                    index = Convert.ToInt32(indexstr);
                    break;
                }
            }

            Console.Clear();
            bool            inlist        = false;
            string          selection     = "";
            List <CardList> AffectedLists = new List <CardList>();

            if (CardListFunctions.AllCardLists.Count > 0)
            {
                foreach (CardList cl in CardListFunctions.AllCardLists)
                {
                    if (cl.TheList.Contains(Allcards[index]) && cl.NumOfCard[cl.TheList.IndexOf(Allcards[index])] == Allcards[index].Amount)
                    {
                        AffectedLists.Add(cl);
                        Console.WriteLine("- " + cl.Name);
                        inlist = true;
                    }
                }
            }
            if (inlist)
            {
                while (true)
                {
                    Console.WriteLine("Card Is In The Above List(s) And Will Be Affected. Do You Still Wish To Remove? (Y/N): ");
                    selection = Console.ReadLine();
                    if (selection.ToLower().Equals("y"))
                    {
                        Console.Clear();
                        break;
                    }
                    else if (selection.ToLower().Equals("n"))
                    {
                        return;
                    }
                    Console.Clear();
                }

                foreach (CardList cl in AffectedLists)
                {
                    cl.RemoveByCard(Allcards[index]);
                }

                Console.WriteLine(" ");
                Console.WriteLine("Enter Any Key To Proceed:");
                Console.ReadLine();
            }

            Console.Clear();
            if (Allcards[index].Amount > 1)
            {
                Allcards[index].Amount = Allcards[index].Amount - 1;
                Console.WriteLine(Allcards[index].Special_name + " Amount Is Now " + Allcards[index].Amount);
            }
            else
            {
                Console.WriteLine(Allcards[index].Special_name + " Removed From Database");
                Console.WriteLine("IDs Above " + index + " Are Now One Less Then Before");
                Allcards.RemoveAt(index);
                //do this in a better way?
                SeprateFunctions.Reset();
                PriceFunctions.Reset();
            }
            Console.WriteLine(" ");
            Console.WriteLine("Enter Any Key To Exit:");
            Console.ReadLine();
        }