Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.26 KB | None | 0 0
  1.  
  2. ////////////////////////////////wyszukaj selected = Menu(editMenuArray, selected); i 2 wynik, case w ktorym to bedzie zastap tym co na dole
  3.  
  4. case 1:
  5.                                     Console.Clear();
  6.                                     Console.WriteLine();
  7.                                     string[] listArray = showList(authorList);
  8.                                     selected = Program.Menu(listArray, 0);
  9.  
  10.                                     //  string[] animalArray = showAnimalToChoose(authorList, selected);
  11.  
  12.                                        author.editAnimal(authorList, selected);
  13.                                     break;
  14. //////////////////////////// po prostu metody
  15.  
  16. static string[] showList(List<Animal> list)
  17.         {
  18.             string[] all = new String[list.Count];
  19.  
  20.             for (int i = 0; i < list.Count; i++)
  21.             {
  22.                 string help;
  23.                 if (list[i].gender) help = "male";
  24.                 else help = "female";
  25.                 all[i] = "Name: " + list[i].name +" Type: " + list[i].type + " Age: " + list[i].age + " Origin: " + list[i].origin + " Gender: " + help;
  26.             }
  27.  
  28.             var types = all;
  29.  
  30.             return all;
  31.         }
  32.  
  33.        static public string[] showAnimalToChoose(List<Animal> list, int numer)
  34.         {
  35.             string[] tab = new String[5];
  36.  
  37.             tab[0] = "Edit name:" + list[numer].name;
  38.             tab[1] = "Edit type:" + list[numer].type;
  39.             tab[2] = "Edit age:" + list[numer].age;
  40.             tab[3] = "Edit origin:" + list[numer].origin;
  41.             tab[4] = "Edit gender:" + list[numer].gender;
  42.  
  43.             return tab;
  44.         }
  45.  
  46.  
  47. //////////////////  podmienic metode
  48. public List<Animal> editAnimal(List<Animal> list, int choose)
  49.         {
  50.  
  51.             Console.Clear();
  52.  
  53.             Console.CursorVisible = false;
  54.             Console.SetCursorPosition(0, 0);
  55.             Console.WriteLine("______________________", Color.Yellow);
  56.  
  57.             Console.SetCursorPosition(0, 2);
  58.  
  59.             Console.WriteLine(choose);
  60.             Console.Clear();
  61.             Console.WriteLine();
  62.             string[] animalArray = Program.showAnimalToChoose(list, choose);
  63.             int selected = Program.Menu(animalArray, 0);
  64.             if (selected == 0) Console.WriteLine("Name");
  65.            // string[] animalArray = Program.showAnimalToChoose(list, choose);
  66.             /*           if (choose == 1)
  67.                            Console.WriteLine("Edit name", Color.Yellow);
  68.                        if (choose == 2)
  69.                            Console.WriteLine("Edit type", Color.Yellow);
  70.                        if (choose == 3)
  71.                            Console.WriteLine("Edit age", Color.Yellow);
  72.                        if (choose == 4)
  73.                            Console.WriteLine("Edit origin", Color.Yellow);
  74.                        if (choose == 5)
  75.                            Console.WriteLine("Edit gender", Color.Yellow);
  76.                        Console.SetCursorPosition(0, 3);
  77.                        Console.WriteLine("______________________", Color.Yellow);
  78.  
  79.                        Console.SetCursorPosition(0, 6);
  80.                        switch (choose)
  81.                        {
  82.                            case 1:
  83.                                try
  84.                                {
  85.                                    Console.Write("Imie do zmiany: ");
  86.                                    dataToEdit = Console.ReadLine();
  87.                                    if (dataToEdit.Length <= 0)
  88.                                    {
  89.                                        do
  90.                                        {
  91.                                            Console.WriteLine("Pole wymagane", Color.Red);
  92.                                            Console.Write("Imie do zmiany: ");
  93.                                            dataToEdit = Console.ReadLine();
  94.                                        } while (dataToEdit.Length <= 0);
  95.                                    }
  96.                                    Console.Write("Nowe imie: ");
  97.                                    newData = Console.ReadLine();
  98.                                    if (newData.Length <= 0)
  99.                                    {
  100.                                        do
  101.                                        {
  102.                                            Console.WriteLine("Pole wymagane", Color.Red);
  103.                                            Console.Write("Nowe imie: ");
  104.                                            newData = Console.ReadLine();
  105.                                        } while (newData.Length <= 0);
  106.                                    }
  107.  
  108.                                    for (int i = 0; i < list.Count; i++)
  109.                                    {
  110.                                        if (list[i].name == dataToEdit)
  111.                                        {
  112.                                            list[i].name = newData;
  113.                                            editSucess = true;
  114.                                        }
  115.                                    }
  116.                                }
  117.                                catch (FormatException)
  118.                                {
  119.                                    Console.WriteLine("Blad!");
  120.                                }
  121.                                break;
  122.  
  123.                            case 2:
  124.  
  125.                                try
  126.                                {
  127.                                    Console.Write("Nazwisko do zmiany: ");
  128.                                    dataToEdit = Console.ReadLine();
  129.                                    if (dataToEdit.Length <= 0)
  130.                                    {
  131.                                        do
  132.                                        {
  133.                                            Console.WriteLine("Pole wymagane", Color.Red);
  134.                                            Console.Write("Nazwisko do zmiany: ");
  135.                                            dataToEdit = Console.ReadLine();
  136.                                        } while (dataToEdit.Length <= 0);
  137.                                    }
  138.  
  139.                                    Console.Write("Nowe nazwisko: ");
  140.                                    newData = Console.ReadLine();
  141.                                    if (newData.Length <= 0)
  142.                                    {
  143.                                        do
  144.                                        {
  145.                                            Console.WriteLine("Pole wymagane", Color.Red);
  146.                                            Console.Write("Nowe nazwisko: ");
  147.                                            newData = Console.ReadLine();
  148.                                        } while (newData.Length <= 0);
  149.                                    }
  150.  
  151.                                    for (int i = 0; i < list.Count; i++)
  152.                                    {
  153.                                        if (list[i].type == dataToEdit)
  154.                                        {
  155.                                            list[i].type = newData;
  156.                                            editSucess = true;
  157.                                        }
  158.                                    }
  159.                                }
  160.                                catch (FormatException)
  161.                                {
  162.                                    Console.WriteLine("Blad!");
  163.                                }
  164.                                break;
  165.  
  166.                            case 3:
  167.  
  168.                                try
  169.                                {
  170.                                    Console.Write("Age ");
  171.                                    ageToEdit = Convert.ToInt32(Console.ReadLine());
  172.                                    if (ageToEdit == 0)
  173.                                    {
  174.                                        do
  175.                                        {
  176.                                            Console.WriteLine("Pole wymagane", Color.Red);
  177.                                            Console.Write("Nazwisko do zmiany: ");
  178.                                            ageToEdit = Convert.ToInt32(Console.ReadLine());
  179.                                        } while (ageToEdit == 0);
  180.                                    }
  181.  
  182.                                    Console.Write("Nowe nazwisko: ");
  183.                                    newData = Console.ReadLine();
  184.                                    if (newData.Length <= 0)
  185.                                    {
  186.                                        do
  187.                                        {
  188.                                            Console.WriteLine("Pole wymagane", Color.Red);
  189.                                            Console.Write("Nowe nazwisko: ");
  190.                                            newData = Console.ReadLine();
  191.                                        } while (newData.Length <= 0);
  192.                                    }
  193.  
  194.                                    for (int i = 0; i < list.Count; i++)
  195.                                    {
  196.                                        if (list[i].age == ageToEdit)
  197.                                        {
  198.                                            list[i].age = Convert.ToInt32(newData);
  199.                                            editSucess = true;
  200.                                        }
  201.                                    }
  202.                                }
  203.                                catch (FormatException)
  204.                                {
  205.                                    Console.WriteLine("Blad!");
  206.                                }
  207.                                break;
  208.  
  209.                            case 4:
  210.  
  211.                                try
  212.                                {
  213.                                    Console.Write("Origin");
  214.                                    dataToEdit = Console.ReadLine();
  215.                                    if (dataToEdit.Length <= 0)
  216.                                    {
  217.                                        do
  218.                                        {
  219.                                            Console.WriteLine("Pole wymagane", Color.Red);
  220.                                            Console.Write("Nazwisko do zmiany: ");
  221.                                            dataToEdit = Console.ReadLine();
  222.                                        } while (dataToEdit.Length <= 0);
  223.                                    }
  224.  
  225.                                    Console.Write("Nowe nazwisko: ");
  226.                                    newData = Console.ReadLine();
  227.                                    if (newData.Length <= 0)
  228.                                    {
  229.                                        do
  230.                                        {
  231.                                            Console.WriteLine("Pole wymagane", Color.Red);
  232.                                            Console.Write("Nowe nazwisko: ");
  233.                                            newData = Console.ReadLine();
  234.                                        } while (newData.Length <= 0);
  235.                                    }
  236.  
  237.                                    for (int i = 0; i < list.Count; i++)
  238.                                    {
  239.                                        if (list[i].origin == dataToEdit)
  240.                                        {
  241.                                            list[i].origin = newData;
  242.                                            editSucess = true;
  243.                                        }
  244.                                    }
  245.                                }
  246.                                catch (FormatException)
  247.                                {
  248.                                    Console.WriteLine("Blad!");
  249.                                }
  250.                                break;
  251.  
  252.                            case 5:
  253.  
  254.                                try
  255.                                {
  256.                                    Console.Write("Gender");
  257.                                    genderToEdit = Convert.ToBoolean(Console.ReadLine());
  258.                                    if (ageToEdit == 0)
  259.                                    {
  260.                                        do
  261.                                        {
  262.                                            Console.WriteLine("Pole wymagane", Color.Red);
  263.                                            Console.Write("Nazwisko do zmiany: ");
  264.                                            genderToEdit = Convert.ToBoolean(Console.ReadLine());
  265.                                        } while (ageToEdit == 0);
  266.                                    }
  267.  
  268.                                    Console.Write("Nowe nazwisko: ");
  269.                                    newData = Console.ReadLine();
  270.                                    if (newData.Length <= 0)
  271.                                    {
  272.                                        do
  273.                                        {
  274.                                            Console.WriteLine("Pole wymagane", Color.Red);
  275.                                            Console.Write("Nowe nazwisko: ");
  276.                                            newData = Console.ReadLine();
  277.                                        } while (newData.Length <= 0);
  278.                                    }
  279.  
  280.                                    for (int i = 0; i < list.Count; i++)
  281.                                    {
  282.                                        if (list[i].gender == genderToEdit)
  283.                                        {
  284.                                            list[i].gender = Convert.ToBoolean(newData);
  285.                                            editSucess = true;
  286.                                        }
  287.                                    }
  288.                                }
  289.                                catch (FormatException)
  290.                                {
  291.                                    Console.WriteLine("Blad!");
  292.                                }
  293.                                break;
  294.  
  295.  
  296.  
  297.                        }
  298.  
  299.                */
  300.  
  301.             /*  if (editSucess == false)
  302.                   Console.WriteLine("\nNie ma takiego autora!");
  303.               else
  304.                   Console.WriteLine("\nPomyslnie edytowano autora");
  305.              */
  306.             Console.WriteLine("\nNacisnij enter aby powrocic do menu");
  307.             Console.ReadLine();
  308.  
  309.             return list;
  310.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement