private void RemoveForm_Load(object sender, EventArgs e)
        {
            StreamReader inStream = new StreamReader(AnimalDataFileLocation(selectedGroup));

            switch (selectedGroup)
            {
            case GroupSelection.Birds:
                lblTitle.Text = "Birds";
                break;

            case GroupSelection.Reptiles:
                lblTitle.Text = "Reptiles";
                break;

            case GroupSelection.Mammals:
                lblTitle.Text = "Mammals";
                break;

            default:
                lblTitle.Text = "All Other Animals";
                break;
            }

            lblTitle.Location = CenterTheLabel();

            theAnimals = new ArrayList();

            switch (selectedGroup)
            {
            case GroupSelection.Birds:
                while (!inStream.EndOfStream)
                {
                    Bird aBird = new Bird
                    {
                        Name              = inStream.ReadLine(),
                        Age               = int.Parse(inStream.ReadLine()),
                        Gender            = inStream.ReadLine(),
                        ZooLocation       = inStream.ReadLine(),
                        Type              = inStream.ReadLine(),
                        DietType          = inStream.ReadLine(),
                        HowTheAnimalMoves = inStream.ReadLine(),
                        IsTagged          = Reptile.ConvertYesNoIntoBool(inStream.ReadLine())
                    };

                    inStream.ReadLine();
                    theAnimals.Add(aBird);
                }
                break;

            case GroupSelection.Reptiles:
                while (!inStream.EndOfStream)
                {
                    Reptile aReptile = new Reptile
                    {
                        Name              = inStream.ReadLine(),
                        Age               = int.Parse(inStream.ReadLine()),
                        Gender            = inStream.ReadLine(),
                        ZooLocation       = inStream.ReadLine(),
                        Type              = inStream.ReadLine(),
                        DietType          = inStream.ReadLine(),
                        HowTheAnimalMoves = inStream.ReadLine(),
                        HasAShell         = Reptile.ConvertYesNoIntoBool(inStream.ReadLine()),
                        LivesIndoors      = Reptile.ConvertYesNoIntoBool(inStream.ReadLine())
                    };

                    inStream.ReadLine();
                    theAnimals.Add(aReptile);
                }
                break;

            case GroupSelection.Mammals:
                while (!inStream.EndOfStream)
                {
                    Mammal aMammal = new Mammal
                    {
                        Name              = inStream.ReadLine(),
                        Age               = int.Parse(inStream.ReadLine()),
                        Gender            = inStream.ReadLine(),
                        ZooLocation       = inStream.ReadLine(),
                        Type              = inStream.ReadLine(),
                        DietType          = inStream.ReadLine(),
                        HowTheAnimalMoves = inStream.ReadLine(),
                        Weight            = double.Parse(inStream.ReadLine()),
                        DailyMealCount    = int.Parse(inStream.ReadLine())
                    };

                    inStream.ReadLine();
                    theAnimals.Add(aMammal);
                }
                break;

            case GroupSelection.Others:
                while (!inStream.EndOfStream)
                {
                    Animal anAnimal = new Animal
                    {
                        Name              = inStream.ReadLine(),
                        Age               = int.Parse(inStream.ReadLine()),
                        Gender            = inStream.ReadLine(),
                        ZooLocation       = inStream.ReadLine(),
                        Type              = inStream.ReadLine(),
                        DietType          = inStream.ReadLine(),
                        HowTheAnimalMoves = inStream.ReadLine()
                    };

                    inStream.ReadLine();
                    theAnimals.Add(anAnimal);
                }
                break;
            }

            theAnimals.TrimToSize();

            foreach (Animal animal in theAnimals)
            {
                lstBxAnimalNames.Items.Add(animal.Name);
            }

            inStream.Close();
        }
Example #2
0
        private void BtnSaveEdits_Click(object sender, EventArgs e)
        {
            if (ValidatedUserEnteredData())
            {
                string confirmationPrompt = "Are you sure you want to save the changes you made to the selected animal from the system?\n\n";

                DialogResult confirmation = MessageBox.Show(confirmationPrompt, "Important!!!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (confirmation == DialogResult.Yes)
                {
                    StreamWriter outStream = new StreamWriter(AnimalDataFileLocation(selectedGroup), false);

                    switch (selectedGroup)
                    {
                    case GroupSelection.Birds:
                        Bird editedBird = new Bird
                        {
                            Name              = txtBxName.Text,
                            Age               = int.Parse(txtBxAge.Text),
                            Gender            = cmbBxGender.SelectedItem.ToString(),
                            ZooLocation       = txtBxLocation.Text,
                            Type              = txtBxType.Text,
                            DietType          = cmbBxDietType.SelectedItem.ToString(),
                            HowTheAnimalMoves = txtBxMovement.Text,
                            IsTagged          = Reptile.ConvertYesNoIntoBool(cmbBxIsTagged.SelectedItem.ToString())
                        };

                        theAnimals[lstBxAnimalNames.SelectedIndex] = editedBird;

                        foreach (Bird aBird in theAnimals)
                        {
                            outStream.WriteLine(aBird.Name);
                            outStream.WriteLine(aBird.Age);
                            outStream.WriteLine(aBird.Gender);
                            outStream.WriteLine(aBird.HowTheAnimalMoves);
                            outStream.WriteLine(aBird.ZooLocation);
                            outStream.WriteLine(aBird.Type);
                            outStream.WriteLine(aBird.DietType);
                            outStream.WriteLine(Reptile.ConvertBoolIntoYesNo(aBird.IsTagged));
                            outStream.WriteLine();
                        }
                        break;

                    case GroupSelection.Reptiles:
                        Reptile editedReptile = new Reptile
                        {
                            Name              = txtBxName.Text,
                            Age               = int.Parse(txtBxAge.Text),
                            Gender            = cmbBxGender.SelectedItem.ToString(),
                            ZooLocation       = txtBxLocation.Text,
                            Type              = txtBxType.Text,
                            DietType          = cmbBxDietType.SelectedItem.ToString(),
                            HowTheAnimalMoves = txtBxMovement.Text,
                            HasAShell         = Reptile.ConvertYesNoIntoBool(cmbBxHasAShell.SelectedItem.ToString()),
                            LivesIndoors      = Reptile.ConvertYesNoIntoBool(cmbBxLivesIndoors.SelectedItem.ToString())
                        };

                        theAnimals[lstBxAnimalNames.SelectedIndex] = editedReptile;

                        foreach (Reptile aReptile in theAnimals)
                        {
                            outStream.WriteLine(aReptile.Name);
                            outStream.WriteLine(aReptile.Age);
                            outStream.WriteLine(aReptile.Gender);
                            outStream.WriteLine(aReptile.HowTheAnimalMoves);
                            outStream.WriteLine(aReptile.ZooLocation);
                            outStream.WriteLine(aReptile.Type);
                            outStream.WriteLine(aReptile.DietType);
                            outStream.WriteLine(Reptile.ConvertBoolIntoYesNo(aReptile.HasAShell));
                            outStream.WriteLine(Reptile.ConvertBoolIntoYesNo(aReptile.LivesIndoors));
                            outStream.WriteLine();
                        }
                        break;

                    case GroupSelection.Mammals:
                        Mammal editedMammal = new Mammal
                        {
                            Name              = txtBxName.Text,
                            Age               = int.Parse(txtBxAge.Text),
                            Gender            = cmbBxGender.SelectedItem.ToString(),
                            ZooLocation       = txtBxLocation.Text,
                            Type              = txtBxType.Text,
                            DietType          = cmbBxDietType.SelectedItem.ToString(),
                            HowTheAnimalMoves = txtBxMovement.Text,
                            Weight            = double.Parse(txtBxWeight.Text),
                            DailyMealCount    = int.Parse(cmbBxDailyMeal.Text)
                        };

                        theAnimals[lstBxAnimalNames.SelectedIndex] = editedMammal;

                        foreach (Mammal aMammal in theAnimals)
                        {
                            outStream.WriteLine(aMammal.Name);
                            outStream.WriteLine(aMammal.Age);
                            outStream.WriteLine(aMammal.Gender);
                            outStream.WriteLine(aMammal.HowTheAnimalMoves);
                            outStream.WriteLine(aMammal.ZooLocation);
                            outStream.WriteLine(aMammal.Type);
                            outStream.WriteLine(aMammal.DietType);
                            outStream.WriteLine(aMammal.Weight);
                            outStream.WriteLine(aMammal.DailyMealCount);
                            outStream.WriteLine();
                        }
                        break;

                    default:
                        Animal editedAnimal = new Animal
                        {
                            Name              = txtBxName.Text,
                            Age               = int.Parse(txtBxAge.Text),
                            Gender            = cmbBxGender.SelectedItem.ToString(),
                            ZooLocation       = txtBxLocation.Text,
                            Type              = txtBxType.Text,
                            DietType          = cmbBxDietType.SelectedItem.ToString(),
                            HowTheAnimalMoves = txtBxMovement.Text
                        };

                        theAnimals[lstBxAnimalNames.SelectedIndex] = editedAnimal;

                        foreach (Animal anAnimal in theAnimals)
                        {
                            outStream.WriteLine(anAnimal.Name);
                            outStream.WriteLine(anAnimal.Age);
                            outStream.WriteLine(anAnimal.Gender);
                            outStream.WriteLine(anAnimal.HowTheAnimalMoves);
                            outStream.WriteLine(anAnimal.ZooLocation);
                            outStream.WriteLine(anAnimal.Type);
                            outStream.WriteLine(anAnimal.DietType);
                            outStream.WriteLine();
                        }
                        break;
                    }

                    outStream.Close();
                }
            }
        }