private Animal CreateNewAnimalFromDatabas(string id, string categori, string name, string age, string gender, string info)
        {
            Animal newAnimalFromDatabas = new Animal();

            newAnimalFromDatabas.ID           = new Guid(id);
            newAnimalFromDatabas.CategoryType = (CategoryType)System.Enum.Parse(typeof(CategoryType), categori);
            newAnimalFromDatabas.Name         = name;
            newAnimalFromDatabas.Age          = Convert.ToInt32(age);
            newAnimalFromDatabas.GenderType   = (GenderType)System.Enum.Parse(typeof(GenderType), gender);

            if (newAnimalFromDatabas.CategoryType == CategoryType.Mammal)

            {
                var extraInfo = DataAccess.LoadExtraAnimalInfo(id);
                foreach (DataRow row in extraInfo.Rows)
                {
                    Mammal        newMammal     = new Mammal();
                    var           teeth         = row["teeth"];
                    var           quarantine    = row["quarantine"];
                    MammalFactory mammalFactory = new MammalFactory();
                    newAnimalFromDatabas.GetAnimalSpecificData += String.IsNullOrEmpty(info) ? newAnimalFromDatabas.GetAnimalSpecificData = "" : "Important info: " + info;

                    newMammal = mammalFactory.AddNewSpecifications(newMammal, Convert.ToInt32(quarantine), true, Convert.ToInt32(teeth));
                    newAnimalFromDatabas.GetAnimalSpecificData += newMammal.AnimalSpecificData();
                }
            }
            else
            {
                newAnimalFromDatabas.GetAnimalSpecificData += String.IsNullOrEmpty(info) ? newAnimalFromDatabas.GetAnimalSpecificData = "" : "Important info: " + info;
            }

            return(newAnimalFromDatabas);
        }
Example #2
0
        /// <summary>
        /// Setts all the information in an animal object
        /// </summary>
        /// <param name="animal">Animal</param>
        /// <returns>Animal</returns>
        private Animal CreateAnimal(Animal animal)
        {
            if (CheckInput())
            {
                switch (lstCategory.SelectedValue)
                {
                case Category.Mammal:
                    animal = MammalFactory.CreateMammal((MammalSpecies)lstAnimals.SelectedValue);
                    break;

                case Category.Bird:
                    animal = BirdFactory.CreateBird((BirdSpecies)lstAnimals.SelectedValue);
                    break;
                }
                if (!IsNumber(txtAge.Text))
                {
                    MessageBox.Show("Please input only numbers in age");
                    return(null);
                }
                if (!IsNumber(txtCategorySpec.Text))
                {
                    MessageBox.Show("Please input only numbers in category information");
                    return(null);
                }
                if (int.TryParse(txtAge.Text, out int age))
                {
                    if (age >= 0)
                    {
                        animal.Age = age;
                    }
                    else
                    {
                        MessageBox.Show("Age is negative");
                        return(null);
                    }
                }

                if (int.TryParse(txtCategorySpec.Text, out int result))
                {
                    if (result >= 0)
                    {
                        animal.AddCategoryInformation(txtCategorySpec.Text);
                    }
                    else
                    {
                        MessageBox.Show("Category information is negative");
                        return(null);
                    }
                }

                if (IsNumber(txtName.Text))
                {
                    MessageBox.Show("Please only input letters in the name");
                    return(null);
                }
                else
                {
                    animal.Name = txtName.Text;
                }

                if (IsNumber(txtSpeciesSpec.Text))
                {
                    MessageBox.Show("Please only input letters in the species information.");
                    return(null);
                }
                else
                {
                    animal.AddSpeciesInformation(txtSpeciesSpec.Text);
                }
                if (cboxGender.SelectedIndex == -1)
                {
                    MessageBox.Show("Please choose a gender");
                    return(null);
                }

                animal.Gender = (Gender)cboxGender.SelectedValue;
                animal.CreateFoodSchedule();
            }
            return(animal);
        }
        private Animal SetAnimalType()
        {
            Animal newAnimal        = new Animal();
            var    selectedCategori = listBxCategori.SelectedIndex;

            if (string.IsNullOrEmpty(listbxAnimalSpecies.Text))
            {
                showValidationMessage.ShowNewMessageBox("Du måste välja djurarten från listan!");
                return(newAnimal = null);
            }
            else
            {
                switch (selectedCategori)
                {
                case 0:
                    BirdSpecies birdSpecies = (BirdSpecies)Enum.Parse(typeof(BirdSpecies), listbxAnimalSpecies.Text);
                    BirdFactory birdFactory = new BirdFactory();
                    newAnimal = birdFactory.Createbird(birdSpecies);
                    break;

                case 1:
                    InsectSpecies insectSpecies = (InsectSpecies)Enum.Parse(typeof(InsectSpecies), listbxAnimalSpecies.Text);
                    InsectFactory insectFactory = new InsectFactory();
                    newAnimal = insectFactory.CreateInsect(insectSpecies);
                    break;

                case 2:
                    MammalSpecies mammalSpecies = (MammalSpecies)Enum.Parse(typeof(MammalSpecies), listbxAnimalSpecies.Text);
                    MammalFactory mammalFactory = new MammalFactory();
                    int           daysOfQuarantine;
                    int           numberOfteeth;
                    bool          underQuarantine = chBoxUnderQuarantine.Checked;
                    if (!helper.CheckInteger(texBoxDaysInQuarantine.Text, out daysOfQuarantine) && underQuarantine == true)
                    {
                        string messageDayOfQuarantine = "You have entered the error value in days of quarantine";
                        errorDayInQuarantiner.SetError(texBoxDaysInQuarantine, messageDayOfQuarantine);
                        showValidationMessage.ShowNewMessageBox(messageDayOfQuarantine);
                        newAnimal = null;
                        break;
                    }
                    else
                    {
                        errorDayInQuarantiner.Clear();
                    }
                    if (!int.TryParse(tboxNoOfTeeth.Text, out numberOfteeth))
                    {
                        errorNoOfTeeth.SetError(tboxNoOfTeeth, "You have entered the error value");
                        showValidationMessage.TeethException(tboxNoOfTeeth.Text);
                        newAnimal = null;
                        break;
                    }
                    else
                    {
                        errorNoOfTeeth.Clear();
                    }


                    newAnimal = mammalFactory.CreateMammal(mammalSpecies, daysOfQuarantine, underQuarantine, numberOfteeth);

                    break;

                case 3:
                    MarineSpecies marineSpecies = (MarineSpecies)Enum.Parse(typeof(MarineSpecies), listbxAnimalSpecies.Text);
                    MarineFactory marineFactory = new MarineFactory();
                    newAnimal = marineFactory.CreateMarine(marineSpecies);
                    break;

                case 4:
                    ReptileSpecies reptileSpecies = (ReptileSpecies)Enum.Parse(typeof(ReptileSpecies), listbxAnimalSpecies.Text);
                    ReptileFactory reptileFactory = new ReptileFactory();
                    newAnimal = reptileFactory.CreateReptile(reptileSpecies);
                    break;
                }
            }

            return(newAnimal);
        }