예제 #1
0
        public static void Option2()
        {
            Vaccine tempVaccine = new Vaccine();
            string  tempSKU;

            bool flag = true;

            //Get user input SKU\
            do
            {
                //if there are any errors
                if (!flag)
                {
                    Console.Clear();
                    Console.WriteLine("Something went wrong, please start again...");
                    flag = true;
                }

                Console.WriteLine("Please Search for a Vaccine using a SKU Number (7 Digit Whole Number):");
                tempSKU = Console.ReadLine();

                if (tempSKU.ToString().Length != 7)
                {
                    flag = false;
                }
            } while (!flag);


            //Search the List for the requested SKU
            foreach (Vaccine vaccine in vaccines)
            {
                if (vaccine.getSKU() == int.Parse(tempSKU))
                {
                    tempVaccine = vaccine;
                }
            }

            if (tempVaccine != new Vaccine())
            {
                Console.WriteLine("Vaccine with SKU# " + tempSKU + " found!\n" + tempVaccine.ToString());
            }
            else
            {
                Console.WriteLine("Vaccine with SKU# " + tempSKU + " not found!\n");
            }
        }
예제 #2
0
        public static void Option5()
        {
            Console.WriteLine("Delete Vaccine Selected");

            Vaccine tempVaccine = new Vaccine();
            string  tempSKU;
            string  input = "";
            bool    flag  = true;

            //Get user input SKU\
            do
            {
                //if there are any errors
                if (!flag)
                {
                    Console.Clear();
                    Console.WriteLine("Something went wrong, please start again...");
                    flag = true;
                }

                Console.WriteLine("Please Search for a Vaccine using a SKU Number (7 Digit Whole Number):");
                tempSKU = Console.ReadLine();

                if (tempSKU.ToString().Length != 7)
                {
                    flag = false;
                }
            } while (!flag);


            //Search the List for the requested SKU
            foreach (Vaccine vaccine in vaccines)
            {
                if (vaccine.getSKU() == int.Parse(tempSKU))
                {
                    tempVaccine = vaccine;
                }
            }

            //Vaccine is found
            if (tempVaccine != new Vaccine())
            {
                Console.Clear();
                Console.WriteLine("Vaccine with SKU# " + tempSKU + " found!\n");
                Console.WriteLine(tempVaccine.ToString());


                while ((input != "y") && (input != "n"))
                {
                    Console.Write("\n\nAre you sure you want to delete this? Press Y/N: ");
                    input = Console.ReadLine();
                }


                switch (input)
                {
                case "y":
                    Console.WriteLine("Vaccine with SKU# " + tempSKU + " has been deleted.");
                    vaccines.Remove(tempVaccine);
                    break;

                case "n":
                    Console.WriteLine("No Vaccine Deleted, returning to main menu");
                    break;
                }
            }
        }