Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ////////////////////////////////wyszukaj selected = Menu(editMenuArray, selected); i 2 wynik, case w ktorym to bedzie zastap tym co na dole
- case 1:
- Console.Clear();
- Console.WriteLine();
- string[] listArray = showList(authorList);
- selected = Program.Menu(listArray, 0);
- // string[] animalArray = showAnimalToChoose(authorList, selected);
- author.editAnimal(authorList, selected);
- break;
- //////////////////////////// po prostu metody
- static string[] showList(List<Animal> list)
- {
- string[] all = new String[list.Count];
- for (int i = 0; i < list.Count; i++)
- {
- string help;
- if (list[i].gender) help = "male";
- else help = "female";
- all[i] = "Name: " + list[i].name +" Type: " + list[i].type + " Age: " + list[i].age + " Origin: " + list[i].origin + " Gender: " + help;
- }
- var types = all;
- return all;
- }
- static public string[] showAnimalToChoose(List<Animal> list, int numer)
- {
- string[] tab = new String[5];
- tab[0] = "Edit name:" + list[numer].name;
- tab[1] = "Edit type:" + list[numer].type;
- tab[2] = "Edit age:" + list[numer].age;
- tab[3] = "Edit origin:" + list[numer].origin;
- tab[4] = "Edit gender:" + list[numer].gender;
- return tab;
- }
- ////////////////// podmienic metode
- public List<Animal> editAnimal(List<Animal> list, int choose)
- {
- Console.Clear();
- Console.CursorVisible = false;
- Console.SetCursorPosition(0, 0);
- Console.WriteLine("______________________", Color.Yellow);
- Console.SetCursorPosition(0, 2);
- Console.WriteLine(choose);
- Console.Clear();
- Console.WriteLine();
- string[] animalArray = Program.showAnimalToChoose(list, choose);
- int selected = Program.Menu(animalArray, 0);
- if (selected == 0) Console.WriteLine("Name");
- // string[] animalArray = Program.showAnimalToChoose(list, choose);
- /* if (choose == 1)
- Console.WriteLine("Edit name", Color.Yellow);
- if (choose == 2)
- Console.WriteLine("Edit type", Color.Yellow);
- if (choose == 3)
- Console.WriteLine("Edit age", Color.Yellow);
- if (choose == 4)
- Console.WriteLine("Edit origin", Color.Yellow);
- if (choose == 5)
- Console.WriteLine("Edit gender", Color.Yellow);
- Console.SetCursorPosition(0, 3);
- Console.WriteLine("______________________", Color.Yellow);
- Console.SetCursorPosition(0, 6);
- switch (choose)
- {
- case 1:
- try
- {
- Console.Write("Imie do zmiany: ");
- dataToEdit = Console.ReadLine();
- if (dataToEdit.Length <= 0)
- {
- do
- {
- Console.WriteLine("Pole wymagane", Color.Red);
- Console.Write("Imie do zmiany: ");
- dataToEdit = Console.ReadLine();
- } while (dataToEdit.Length <= 0);
- }
- Console.Write("Nowe imie: ");
- newData = Console.ReadLine();
- if (newData.Length <= 0)
- {
- do
- {
- Console.WriteLine("Pole wymagane", Color.Red);
- Console.Write("Nowe imie: ");
- newData = Console.ReadLine();
- } while (newData.Length <= 0);
- }
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i].name == dataToEdit)
- {
- list[i].name = newData;
- editSucess = true;
- }
- }
- }
- catch (FormatException)
- {
- Console.WriteLine("Blad!");
- }
- break;
- case 2:
- try
- {
- Console.Write("Nazwisko do zmiany: ");
- dataToEdit = Console.ReadLine();
- if (dataToEdit.Length <= 0)
- {
- do
- {
- Console.WriteLine("Pole wymagane", Color.Red);
- Console.Write("Nazwisko do zmiany: ");
- dataToEdit = Console.ReadLine();
- } while (dataToEdit.Length <= 0);
- }
- Console.Write("Nowe nazwisko: ");
- newData = Console.ReadLine();
- if (newData.Length <= 0)
- {
- do
- {
- Console.WriteLine("Pole wymagane", Color.Red);
- Console.Write("Nowe nazwisko: ");
- newData = Console.ReadLine();
- } while (newData.Length <= 0);
- }
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i].type == dataToEdit)
- {
- list[i].type = newData;
- editSucess = true;
- }
- }
- }
- catch (FormatException)
- {
- Console.WriteLine("Blad!");
- }
- break;
- case 3:
- try
- {
- Console.Write("Age ");
- ageToEdit = Convert.ToInt32(Console.ReadLine());
- if (ageToEdit == 0)
- {
- do
- {
- Console.WriteLine("Pole wymagane", Color.Red);
- Console.Write("Nazwisko do zmiany: ");
- ageToEdit = Convert.ToInt32(Console.ReadLine());
- } while (ageToEdit == 0);
- }
- Console.Write("Nowe nazwisko: ");
- newData = Console.ReadLine();
- if (newData.Length <= 0)
- {
- do
- {
- Console.WriteLine("Pole wymagane", Color.Red);
- Console.Write("Nowe nazwisko: ");
- newData = Console.ReadLine();
- } while (newData.Length <= 0);
- }
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i].age == ageToEdit)
- {
- list[i].age = Convert.ToInt32(newData);
- editSucess = true;
- }
- }
- }
- catch (FormatException)
- {
- Console.WriteLine("Blad!");
- }
- break;
- case 4:
- try
- {
- Console.Write("Origin");
- dataToEdit = Console.ReadLine();
- if (dataToEdit.Length <= 0)
- {
- do
- {
- Console.WriteLine("Pole wymagane", Color.Red);
- Console.Write("Nazwisko do zmiany: ");
- dataToEdit = Console.ReadLine();
- } while (dataToEdit.Length <= 0);
- }
- Console.Write("Nowe nazwisko: ");
- newData = Console.ReadLine();
- if (newData.Length <= 0)
- {
- do
- {
- Console.WriteLine("Pole wymagane", Color.Red);
- Console.Write("Nowe nazwisko: ");
- newData = Console.ReadLine();
- } while (newData.Length <= 0);
- }
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i].origin == dataToEdit)
- {
- list[i].origin = newData;
- editSucess = true;
- }
- }
- }
- catch (FormatException)
- {
- Console.WriteLine("Blad!");
- }
- break;
- case 5:
- try
- {
- Console.Write("Gender");
- genderToEdit = Convert.ToBoolean(Console.ReadLine());
- if (ageToEdit == 0)
- {
- do
- {
- Console.WriteLine("Pole wymagane", Color.Red);
- Console.Write("Nazwisko do zmiany: ");
- genderToEdit = Convert.ToBoolean(Console.ReadLine());
- } while (ageToEdit == 0);
- }
- Console.Write("Nowe nazwisko: ");
- newData = Console.ReadLine();
- if (newData.Length <= 0)
- {
- do
- {
- Console.WriteLine("Pole wymagane", Color.Red);
- Console.Write("Nowe nazwisko: ");
- newData = Console.ReadLine();
- } while (newData.Length <= 0);
- }
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i].gender == genderToEdit)
- {
- list[i].gender = Convert.ToBoolean(newData);
- editSucess = true;
- }
- }
- }
- catch (FormatException)
- {
- Console.WriteLine("Blad!");
- }
- break;
- }
- */
- /* if (editSucess == false)
- Console.WriteLine("\nNie ma takiego autora!");
- else
- Console.WriteLine("\nPomyslnie edytowano autora");
- */
- Console.WriteLine("\nNacisnij enter aby powrocic do menu");
- Console.ReadLine();
- return list;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement