/// <summary>
        /// Gets the result of a ContactType on a set of PhysicalAttributes
        /// </summary>
        /// <param name="attacker">The BattleEntity performing the attack</param>
        /// <param name="contactType">The ContactType performed</param>
        /// <param name="physAttributes">The set of PhysicalAttributes to test against</param>
        /// <param name="attributesToIgnore">A set of PhysicalAttributes to ignore</param>
        /// <returns>A ContactResultInfo of the interaction</returns>
        public static ContactResultInfo GetContactResult(BattleEntity attacker, ContactTypes contactType, PhysicalAttributes[] physAttributes, params PhysicalAttributes[] attributesToIgnore)
        {
            //Return the default value
            if (ContactTable.ContainsKey(contactType) == false || physAttributes == null)
            {
                Debug.LogWarning($"{nameof(physAttributes)} array is null or {nameof(ContactTable)} does not contain the ContactType {contactType}!");
                return(ContactResultInfo.Default);
            }

            //Look through the attributes and find the first match
            for (int i = 0; i < physAttributes.Length; i++)
            {
                Dictionary <PhysicalAttributes, ContactResultInfo> tableForContact = ContactTable[contactType];
                PhysicalAttributes attribute = physAttributes[i];

                //If this attribute is ignored, move onto the next
                if (attributesToIgnore?.Contains(attribute) == true)
                {
                    continue;
                }

                if (tableForContact.ContainsKey(attribute) == true)
                {
                    ContactResultInfo contactResult = tableForContact[attribute];
                    //If the ContactResult is a Success if the entity has the same PhysicalAttribute as the one tested, set its result to Success
                    if (contactResult.SuccessIfSameAttr == true && attacker.EntityProperties.HasPhysAttributes(true, attribute) == true)
                    {
                        contactResult.ContactResult = ContactResult.Success;
                    }
                    return(contactResult);
                }
            }

            return(ContactResultInfo.Default);
        }
        /// <summary>
        /// Returns all Elements of an Element Override the BattleEntity has for a particular PhysicalAttribute.
        /// </summary>
        /// <returns>An array of all Elements of the Element Override the BattleEntity has for the PhysicalAttribute, with higher Element values first.</returns>
        protected Elements[] GetElementsForOverride(PhysicalAttributes physAttribute)
        {
            if (HasElementOverride(physAttribute) == false)
            {
                return(new Elements[0]);
            }

            return(ElementOverrides[physAttribute].Keys.ToArray());
        }
        ///<summary>
        ///Adds a Strength to the BattleEntity.
        ///</summary>
        ///<param name="physAttribute">The PhysicalAttribute the BattleEntity is strong against.</param>
        ///<param name="strengthHolder">The data for the Strength.</param>
        public void AddStrength(PhysicalAttributes physAttribute, StrengthHolder strengthHolder)
        {
            if (HasStrength(physAttribute) == false)
            {
                Strengths.Add(physAttribute, new List <StrengthHolder>());
            }

            Strengths[physAttribute].Add(strengthHolder);
            Debug.Log($"Added strength value of {strengthHolder.Value} to {Entity.Name} for the {physAttribute} PhysicalAttribute!");
        }
Esempio n. 4
0
        public void ShouldNotValidatePhysicalAttributeHeight(Race race, double height)
        {
            // Act
            var phWeight = new PhysicalAttributes(race)
            {
                Height = height
            };
            var hero = new Hero(null, race, phWeight, null, null, null);

            // Assert
            unitToTest.ShouldHaveValidationErrorFor(h => h.PhysicalAttributes.Height, hero);
        }
        /// <summary>
        /// Adds a contact exception to the entity
        /// </summary>
        /// <param name="contactType"></param>
        /// <param name="physAttribute"></param>
        public void AddContactException(ContactTypes contactType, PhysicalAttributes physAttribute)
        {
            //Add a new key if one doesn't exist
            if (ContactExceptions.ContainsKey(contactType) == false)
            {
                ContactExceptions.Add(contactType, new List <PhysicalAttributes>());
            }

            //Add to the list
            ContactExceptions[contactType].Add(physAttribute);

            Debug.Log($"Added contact exception on {Entity.Name} for the {physAttribute} PhysicalAttribute during {contactType} contact!");
        }
 /// <summary>
 /// Adds a physical attribute to the entity
 /// </summary>
 /// <param name="physicalAttribute">The physical attribute to add</param>
 public void AddPhysAttribute(PhysicalAttributes physicalAttribute)
 {
     if (PhysAttributes.ContainsKey(physicalAttribute) == true)
     {
         PhysAttributes[physicalAttribute]++;
         Debug.Log($"Incremented the physical attribute {physicalAttribute} for {Entity.Name}!");
         return;
     }
     else
     {
         Debug.Log($"Added the physical attribute {physicalAttribute} to {Entity.Name}'s existing attributes!");
         PhysAttributes.Add(physicalAttribute, 1);
     }
 }
        /// <summary>
        /// Gets this entity's total strength to a particular PhysicalAttribute.
        /// </summary>
        /// <param name="physAttribute">The PhysicalAttribute to test a strength towards.</param>
        /// <returns>A copy of the StrengthHolder associated with the element if found, otherwise default strength data.</returns>
        private StrengthHolder GetStrength(PhysicalAttributes physAttribute)
        {
            if (HasStrength(physAttribute) == false)
            {
                //Debug.Log($"{Entity.Name} does not have a strength for {physAttribute}");
                return(StrengthHolder.Default);
            }

            StrengthHolder strengthHolder = default(StrengthHolder);

            //Get the total strength
            Strengths[physAttribute].ForEach((strength) =>
            {
                strengthHolder.Value += strength.Value;
            });

            return(strengthHolder);
        }
        /// <summary>
        /// Removes a physical attribute from the entity
        /// </summary>
        /// <param name="physicalAttribute">The physical attribute to remove</param>
        public void RemovePhysAttribute(PhysicalAttributes physicalAttribute)
        {
            if (PhysAttributes.ContainsKey(physicalAttribute) == false)
            {
                Debug.LogWarning($"Cannot remove physical attribute {physicalAttribute} because {Entity.Name} does not have it!");
                return;
            }

            PhysAttributes[physicalAttribute]--;
            if (PhysAttributes[physicalAttribute] <= 0)
            {
                PhysAttributes.Remove(physicalAttribute);
                Debug.Log($"Removed the physical attribute {physicalAttribute} from {Entity.Name}'s existing attributes!");
            }
            else
            {
                Debug.Log($"Decremented the physical attribute {physicalAttribute} for {Entity.Name}!");
            }
        }
        /// <summary>
        /// Removes a Strength from the BattleEntity.
        /// </summary>
        /// <param name="physAttribute">The PhysicalAttribute the BattleEntity is strong against.</param>
        public void RemoveStrength(PhysicalAttributes physAttribute, StrengthHolder strengthHolder)
        {
            if (HasStrength(physAttribute) == false)
            {
                Debug.LogWarning($"{Entity.Name} does not have a strength for {physAttribute}");
                return;
            }

            bool removed = Strengths[physAttribute].Remove(strengthHolder);

            if (Strengths[physAttribute].Count == 0)
            {
                Strengths.Remove(physAttribute);
            }

            if (removed == true)
            {
                Debug.Log($"Removed strength value of {strengthHolder.Value} from the {physAttribute} PhysicalAttribute on {Entity.Name}!");
            }
        }
Esempio n. 10
0
        private Hero GenerateHeroS(Race race, Gender gender, GenerateNamePreference generateNamePreference)
        {
            try
            {
                var physicalAttributes = new PhysicalAttributes(race);

                var progression   = new Progression();
                var vitals        = new Vitals();
                var traits        = new Traits();
                var generatedName = nameGenerator.GenerateName(gender, generateNamePreference);

                var hero = new Hero(generatedName, race, physicalAttributes, vitals, progression, traits);

                return(hero);
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// Adds an Element Override of an Element to this BattleEntity for a PhysicalAttribute
        /// </summary>
        /// <param name="attribute">The PhysicalAttribute associated with the Element Override</param>
        /// <param name="element">The Element to add for this PhysicalAttribute</param>
        public void AddElementOverride(PhysicalAttributes attribute, Elements element)
        {
            //Add a new entry if one doesn't exist
            if (HasElementOverride(attribute) == false)
            {
                ElementOverrides.Add(attribute, new SortedDictionary <Elements, int>(new ElementGlobals.ElementComparer()));
            }

            //If we don't have an override for this PhysicalAttribute with this Element, add one
            if (ElementOverrides[attribute].ContainsKey(element) == false)
            {
                ElementOverrides[attribute].Add(element, 1);
            }
            //Increment the count otherwise
            else
            {
                ElementOverrides[attribute][element] += 1;
            }

            Debug.Log($"Added a(n) {element} override to {Entity.Name} for the {attribute} PhysicalAttribute!");
        }
        public void RemoveContactException(ContactTypes contactType, PhysicalAttributes physAttribute)
        {
            if (ContactExceptions.ContainsKey(contactType) == false)
            {
                Debug.LogError($"Cannot remove {physAttribute} from the exception list on {Entity.Name} for {contactType} because no list exists!");
                return;
            }

            bool removed = ContactExceptions[contactType].Remove(physAttribute);

            if (removed == true)
            {
                Debug.Log($"Removed {physAttribute} attribute exception on {Entity.Name} for {contactType} contact!");
            }

            //If there are no PhysicalAttributes in the exceptions list for this ContactType, remove the key
            if (ContactExceptions[contactType].Count == 0)
            {
                ContactExceptions.Remove(contactType);
            }
        }
        /// <summary>
        /// Retrieves the Element Override this BattleEntity has for the first PhysicalAttribute found on a victim
        /// </summary>
        /// <param name="attacker">The BattleEntity this one is attacking</param>
        /// <returns>An ElementOverrideHolder with the type of Element damage this BattleEntity will do and how many overrides of that Element exist.</returns>
        public ElementOverrideHolder GetTotalElementOverride(BattleEntity victim)
        {
            PhysicalAttributes[] victimAttributes = victim.EntityProperties.GetAllPhysAttributes();

            for (int i = 0; i < victimAttributes.Length; i++)
            {
                PhysicalAttributes physAttribute = victimAttributes[i];

                if (HasElementOverride(physAttribute) == true)
                {
                    //NOTE: I'm not happy with the overall performance of this, but it's definitely better than
                    //not allowing more Elements or their counts for each override

                    //Return the first one since they're sorted
                    Elements[] elementsForOverride = GetElementsForOverride(physAttribute);
                    Elements   element             = elementsForOverride[0];

                    return(new ElementOverrideHolder(element, ElementOverrides[physAttribute][element]));
                }
            }

            return(ElementOverrideHolder.Default);
        }
        /// <summary>
        /// Removes an Element Override of an Element this BattleEntity has for a PhysicalAttribute
        /// </summary>
        /// <param name="attribute">The PhysicalAttribute associated with the Element Override</param>
        /// <param name="element">The Element to remove for the Element Override</param>
        public void RemoveElementOverride(PhysicalAttributes attribute, Elements element)
        {
            if (HasElementOverride(attribute) == false || ElementOverrides[attribute].ContainsKey(element) == false)
            {
                Debug.LogWarning($"{Entity.Name} does not contain an element override for the {attribute} PhysicalAttribute and thus cannot remove one!");
                return;
            }

            //Decrement the count for the Element on this PhysicalAttribute
            ElementOverrides[attribute][element]--;
            Debug.Log($"Decremented a(n) {element} override from {Entity.Name} for the {attribute} PhysicalAttribute!");
            if (ElementOverrides[attribute][element] <= 0)
            {
                ElementOverrides[attribute].Remove(element);
                Debug.Log($"Removed the element {element} for the {attribute} PhysicalAttribute from {Entity.Name}'s Element Overrides!");

                //If no Elements are remaining for this PhysicalAttribute, remove the Element Override
                if (ElementOverrides[attribute].Count <= 0)
                {
                    ElementOverrides.Remove(attribute);
                    Debug.Log($"Removed element override for the {attribute} PhysicalAttribute on {Entity.Name}");
                }
            }
        }
        public void Save()
        {
            currCalf = new Calf();

            //string _name = textBoxName.Text;
            //string _fatherName = textBoxFatherName.Text;
            //int _salary = Convert.ToInt32(textBoxSalary.Text);

            #region Validation for valid employee data

            //Check if all text boxes are empty

            IEnumerable <TextBox>  textBoxcollection  = EntryGrid.Children.OfType <TextBox>();
            IEnumerable <ComboBox> comboBoxcollection = EntryGrid.Children.OfType <ComboBox>();

            foreach (TextBox box in textBoxcollection)
            {
                if (string.IsNullOrWhiteSpace(box.Text))
                {
                    if (box.Name == "textBoxDescription" ||
                        box.Name == "textBoxHeight" ||
                        box.Name == "textBoxLength" ||
                        box.Name == "textBoxWidth" ||
                        box.Name == "textBoxPrice" ||
                        box.Name == "textBoxWeight")
                    {
                        //ignore
                    }
                    else
                    {
                        MessageBox.Show("Kindly Fill all the boxes.");
                        return;
                    }
                }
            }


            foreach (ComboBox combobox in comboBoxcollection)
            {
                if (combobox.SelectedIndex == -1)
                {
                    MessageBox.Show("Kindly Select all the Drop-Downs");
                    return;
                }
            }

            //Added Apr-02. Bug Fixed

            if (!datePickerDOB.SelectedDate.HasValue)
            {
                MessageBox.Show("Kindly Enter Date of Birth");
                return;
            }

            //CheckTextBoxes(this);


            #endregion

            try
            {
                currCalf.Price = 0;

                PhysicalAttributes physicalAttrib = new PhysicalAttributes();
                Entities.Size      currSize       = new Entities.Size();

                if (string.IsNullOrWhiteSpace(textBoxHeight.Text))
                {
                    currSize.Height = 0;
                }
                else
                {
                    currSize.Height = Convert.ToDouble(textBoxHeight.Text);
                }

                if (string.IsNullOrWhiteSpace(textBoxLength.Text))
                {
                    currSize.Length = 0;
                }
                else
                {
                    currSize.Length = Convert.ToDouble(textBoxLength.Text);
                }

                if (string.IsNullOrWhiteSpace(textBoxWidth.Text))
                {
                    currSize.Width = 0;
                }
                else
                {
                    currSize.Width = Convert.ToDouble(textBoxWidth.Text);
                }


                if (string.IsNullOrWhiteSpace(textBoxWeight.Text))
                {
                    physicalAttrib.Weight = 0;
                }
                else
                {
                    physicalAttrib.Weight = Convert.ToDouble(textBoxWeight.Text);
                }

                physicalAttrib.CurrentSize = currSize;

                currCalf.CurrPhysicalAttribs = physicalAttrib;

                currCalf.TagNo     = textBoxTagNo.Text;
                currCalf.BirthDate = datePickerDOB.SelectedDate.Value;

                //Only IDs needed for insertion

                currCalf.Breed    = new AnimalBreed();
                currCalf.Breed.ID = ((MasterTables)comboBoxBreed.SelectedItem).ID;


                currCalf.Gender             = new Gender();
                currCalf.Gender.Description = ((MasterTables)comboBoxGender.SelectedItem).Description;  //Modified 31 March

                currCalf.Source    = new AnimalSource();
                currCalf.Source.ID = ((MasterTables)comboBoxSource.SelectedItem).ID;


                currCalf.Type    = new AnimalType();
                currCalf.Type.ID = ((MasterTables)comboBoxAnimalType.SelectedItem).ID;

                //Commented on 01-Apr. No Status required for Calf
                //currCalf.Status = new AnimalStatus();
                //currCalf.Status.ID = ((MasterTables)comboBoxStatus.SelectedItem).ID;


                currCalf.OtherDetails = textBoxDescription.Text;

                Cattle mother = new Cattle();
                Cattle father = new Cattle();

                mother = (Cattle)comboBoxMother.SelectedItem;
                father = (Cattle)comboBoxFather.SelectedItem;

                currCalf.Mother = mother;
                currCalf.Father = father;

                //Added on Paril-02. Static Polymorphism for Calf Procedure
                //Whether it is for just calf
                //calf and mother
                //calf and father
                //or both

                if (mother.TagNo == "Other Farm")
                {
                    if (father.TagNo == "Artificial Insemnation")
                    {
                        animalHandler.Add(currCalf);
                    }
                    else
                    {
                        animalHandler.Add(currCalf, father.ID, 'N');
                    }
                }
                else
                {
                    if (father.TagNo == "Artificial Insemnation")
                    {
                        animalHandler.Add(currCalf, mother.ID, 'Y');
                    }
                    else
                    {
                        animalHandler.Add(currCalf, father.ID, mother.ID);
                    }
                }
            }

            catch (FormatException fexcept)
            {
                MessageBox.Show("Kindly Enter the field in correct (numeric) format. Error on " + fexcept.Source + " .", "Invalid Entry");
                return;
            }

            //Added - 01 Jan
            //For Name/Father name not containing numbers

            catch (ArgumentException aexcept)
            {
                MessageBox.Show(aexcept.Message, "Invalid Entry!");
                return;
            }


            //Clear all the TextBoxes

            foreach (TextBox textbox in textBoxcollection)
            {
                textbox.Text = "";
            }

            foreach (ComboBox combobox in comboBoxcollection)
            {
                combobox.SelectedIndex = -1;
            }

            datePickerDOB.SelectedDate = null;
        }
        private List <Calf> selectCalfs(SqlCommand cmd)
        {
            cmd.CommandType = CommandType.StoredProcedure;
            SqlConnection con       = cmd.Connection;
            List <Calf>   listCalfs = new List <Calf>();

            con.Open();
            using (con)
            {
                SqlDataReader dr = cmd.ExecuteReader();

                //              [TagNo]                     0
                //   ,[RegistrationDate]                    1
                //   ,[AnimalType]                          2
                //,at.Description                           3
                //   ,[Gender]                              4
                //ID                                            5
                //   ,[BirthDate]                       6
                //   ,[Weight]                      7
                //   ,[Height]                      8
                //   ,[Length]                      9
                //   ,[Width]                       10
                //   ,[Price]                           11
                //   ,[Source]                          12
                //,aso.Description                      13
                //   ,[Breed]                                   14
                //,ab.Description                          15
                //   ,[Status]                                16
                //,ast.Description                     17
                //   ,[OtherDetails]                 18
                //   Mother                                19
                // Mother TagNo                     20              Added Apr-02
                //Father                                   21
                // Father TagNo                    22              Added Apr-02

                if (dr.HasRows)
                {
                    listCalfs = new List <Calf>();
                    while (dr.Read())
                    {
                        AnimalBreed currCattleBreed = new AnimalBreed           //14,15
                        {
                            ID          = Convert.ToInt32(dr[14]),
                            Description = Convert.ToString(dr[15])
                        };

                        AnimalSource currCattleSource = new AnimalSource  //12,13
                        {
                            ID          = Convert.ToInt32(dr[12]),
                            Description = Convert.ToString(dr[13])
                        };
                        AnimalStatus currCattleStatus = new AnimalStatus        //16 , 17
                        {
                            ID          = Convert.ToInt32(dr[16]),
                            Description = Convert.ToString(dr[17])
                        };
                        AnimalType currCattleType = new AnimalType()            //2, 3
                        {
                            ID          = Convert.ToInt32(dr[2]),
                            Description = Convert.ToString(dr[3])
                        };
                        Gender currCattleGender = new Gender()                  //4 , 5
                        {
                            Description = Convert.ToString(dr[4])
                        };

                        PhysicalAttributes currPhysicalAttribs = new PhysicalAttributes();

                        currPhysicalAttribs.Weight = Convert.ToDouble(dr[7]);   //7

                        Entities.Size currSize = new Entities.Size();           //TO avoid ambiguity among .Net's Size function

                        currSize.Height = Convert.ToDouble(dr[8]);
                        currSize.Length = Convert.ToDouble(dr[9]);
                        currSize.Width  = Convert.ToDouble(dr[10]);

                        currPhysicalAttribs.CurrentSize = currSize;

                        Cattle currCalfMother = new Cattle();
                        Cattle currCalfFather = new Cattle();

                        //Added April-02

                        currCalfMother.ID = Convert.ToInt32(dr[20]);

                        if (currCalfMother.ID == 0)
                        {
                            currCalfMother.TagNo = "Other Farm";
                        }
                        else
                        {
                            currCalfMother.TagNo = Convert.ToString(dr[19]);
                        }

                        currCalfFather.ID = Convert.ToInt32(dr[22]);

                        if (currCalfFather.ID == 0)
                        {
                            currCalfFather.TagNo = "Artificial Insemnation";
                        }
                        else
                        {
                            currCalfFather.TagNo = Convert.ToString(dr[21]);
                        }

                        //Addition Ends. April-02

                        Calf currCalf = new Calf
                        {
                            ID               = Convert.ToInt32(dr[5]),
                            TagNo            = Convert.ToString(dr[0]),
                            RegistrationDate = Convert.ToDateTime(dr[1]),
                            BirthDate        = Convert.ToDateTime(dr[6]),
                            Price            = Convert.ToInt32(dr[11]),
                            OtherDetails     = Convert.ToString(dr[18])
                        };

                        currCalf.Mother = currCalfMother;
                        currCalf.Father = currCalfFather;

                        currCalf.Breed  = currCattleBreed;
                        currCalf.Gender = currCattleGender;
                        currCalf.CurrPhysicalAttribs = currPhysicalAttribs;
                        currCalf.Source = currCattleSource;
                        currCalf.Status = currCattleStatus;
                        currCalf.Type   = currCattleType;

                        listCalfs.Add(currCalf);
                    }
                }
            }
            return(listCalfs);
        }
        private List <Cattle> selectCattles(SqlCommand cmd)
        {
            cmd.CommandType = CommandType.StoredProcedure;
            SqlConnection con         = cmd.Connection;
            List <Cattle> listCattles = new List <Cattle>();

            con.Open();
            using (con)
            {
                SqlDataReader dr = cmd.ExecuteReader();

                //              [TagNo]                     0
                //   ,[RegistrationDate]                    1
                //   ,[AnimalType]                          2
                //,at.Description                           3
                //   ,[Gender]                              4
                //ID                                            5
                //   ,[BirthDate]                       6
                //   ,[Weight]                      7
                //   ,[Height]                      8
                //   ,[Length]                      9
                //   ,[Width]                       10
                //   ,[Price]                           11
                //   ,[Source]                          12
                //,aso.Description                      13
                //   ,[Breed]                                   14
                //,ab.Description                          15
                //   ,[Status]                                16
                //,ast.Description                     17
                //   ,[OtherDetails]                 18

                //Added 31-March
                //ID as surrogate PK  and removed Gender FK

                if (dr.HasRows)
                {
                    listCattles = new List <Cattle>();
                    while (dr.Read())
                    {
                        AnimalBreed currCattleBreed = new AnimalBreed           //14,15
                        {
                            ID          = Convert.ToInt32(dr[14]),
                            Description = Convert.ToString(dr[15])
                        };

                        AnimalSource currCattleSource = new AnimalSource  //12,13
                        {
                            ID          = Convert.ToInt32(dr[12]),
                            Description = Convert.ToString(dr[13])
                        };
                        AnimalStatus currCattleStatus = new AnimalStatus        //16 , 17
                        {
                            ID          = Convert.ToInt32(dr[16]),
                            Description = Convert.ToString(dr[17])
                        };
                        AnimalType currCattleType = new AnimalType()            //2, 3
                        {
                            ID          = Convert.ToInt32(dr[2]),
                            Description = Convert.ToString(dr[3])
                        };
                        Gender currCattleGender = new Gender()                  //4 , 5
                        {
                            // ID = Convert.ToInt32(dr[4]),
                            Description = Convert.ToString(dr[4])
                        };

                        PhysicalAttributes currPhysicalAttribs = new PhysicalAttributes();

                        currPhysicalAttribs.Weight = Convert.ToDouble(dr[7]);   //7

                        Entities.Size currSize = new Entities.Size();           //TO avoid ambiguity among .Net's Size function

                        currSize.Height = Convert.ToDouble(dr[8]);
                        currSize.Length = Convert.ToDouble(dr[9]);
                        currSize.Width  = Convert.ToDouble(dr[10]);

                        currPhysicalAttribs.CurrentSize = currSize;

                        Cattle currCattle = new Cattle
                        {
                            ID               = Convert.ToInt32(dr[5]),
                            TagNo            = Convert.ToString(dr[0]),
                            RegistrationDate = Convert.ToDateTime(dr[1]),
                            BirthDate        = Convert.ToDateTime(dr[6]),
                            Price            = Convert.ToInt32(dr[11]),
                            OtherDetails     = Convert.ToString(dr[18])
                        };

                        currCattle.Breed  = currCattleBreed;
                        currCattle.Gender = currCattleGender;
                        currCattle.CurrPhysicalAttribs = currPhysicalAttribs;
                        currCattle.Source = currCattleSource;
                        currCattle.Status = currCattleStatus;
                        currCattle.Type   = currCattleType;

                        listCattles.Add(currCattle);
                    }
                }
            }
            return(listCattles);
        }
 /// <summary>
 /// Tells if the BattleEntity has an Element Override for a particular PhysicalAttribute
 /// </summary>
 /// <param name="attribute">The PhysicalAttribute associated with the Element Override</param>
 /// <returns>true if the Element Override exists for the PhysicalAttribute, otherwise false</returns>
 public bool HasElementOverride(PhysicalAttributes attribute)
 {
     return(ElementOverrides.ContainsKey(attribute));
 }
        //Changed
        //Shifted code from Save Button to interface Save() method overriding
        public void Save()
        {
            currCattle = new Cattle();

            //string _name = textBoxName.Text;
            //string _fatherName = textBoxFatherName.Text;
            //int _salary = Convert.ToInt32(textBoxSalary.Text);

            #region Validation for valid employee data

            //Check if all text boxes are empty

            IEnumerable <TextBox>  textBoxcollection  = EntryGrid.Children.OfType <TextBox>();
            IEnumerable <ComboBox> comboBoxcollection = EntryGrid.Children.OfType <ComboBox>();

            foreach (TextBox box in textBoxcollection)
            {
                if (string.IsNullOrWhiteSpace(box.Text))
                {
                    if (box.Name == "textBoxDescription" ||
                        box.Name == "textBoxHeight" ||
                        box.Name == "textBoxLength" ||
                        box.Name == "textBoxWidth" ||
                        box.Name == "textBoxPrice" ||
                        box.Name == "textBoxWeight")
                    {
                        //ignore
                    }
                    else
                    {
                        MessageBox.Show("Kindly Fill all the boxes.");
                        return;
                    }
                }
            }

            foreach (ComboBox combobox in comboBoxcollection)
            {
                if (combobox.SelectedIndex == -1)
                {
                    MessageBox.Show("Kindly Select all the Drop-Downs");
                    return;
                }
            }

            //CheckTextBoxes(this);


            #endregion

            try
            {
                if (string.IsNullOrWhiteSpace(textBoxPrice.Text))
                {
                    currCattle.Price = 0;
                }
                else
                {
                    currCattle.Price = Convert.ToInt32(textBoxPrice.Text);
                }

                PhysicalAttributes physicalAttrib = new PhysicalAttributes();
                Entities.Size      currSize       = new Entities.Size();

                if (string.IsNullOrWhiteSpace(textBoxHeight.Text))
                {
                    currSize.Height = 0;
                }
                else
                {
                    currSize.Height = Convert.ToDouble(textBoxHeight.Text);
                }

                if (string.IsNullOrWhiteSpace(textBoxLength.Text))
                {
                    currSize.Length = 0;
                }
                else
                {
                    currSize.Length = Convert.ToDouble(textBoxLength.Text);
                }

                if (string.IsNullOrWhiteSpace(textBoxWidth.Text))
                {
                    currSize.Width = 0;
                }
                else
                {
                    currSize.Width = Convert.ToDouble(textBoxWidth.Text);
                }


                if (string.IsNullOrWhiteSpace(textBoxWeight.Text))
                {
                    physicalAttrib.Weight = 0;
                }
                else
                {
                    physicalAttrib.Weight = Convert.ToDouble(textBoxWeight.Text);
                }

                physicalAttrib.CurrentSize = currSize;

                currCattle.CurrPhysicalAttribs = physicalAttrib;

                currCattle.TagNo     = textBoxTagNo.Text;
                currCattle.BirthDate = datePickerDOB.SelectedDate.Value;

                //List<MasterTables> masterList = new List<MasterTables>();

                //masterList.Add((MasterTables)comboBoxBreed.SelectedItem);
                //masterList.Add((MasterTables)comboBoxGender.SelectedItem);
                //masterList.Add((MasterTables)comboBoxSource.SelectedItem);

                //AnimalBreed breed = new AnimalBreed();
                //breed = (AnimalBreed)masterList[0];

                //currCattle.Breed = breed;

                //currCattle.Breed = (AnimalBreed)comboBoxBreed.SelectedItem;
                //currCattle.Gender = (Gender)comboBoxGender.SelectedItem;
                //currCattle.Source = (AnimalSource)comboBoxSource.SelectedItem;

                //Only IDs needed for insertion

                currCattle.Breed    = new AnimalBreed();
                currCattle.Breed.ID = ((MasterTables)comboBoxBreed.SelectedItem).ID;


                currCattle.Gender = new Gender();

                string g = ((string)comboBoxGender.SelectedItem);

                currCattle.Gender.Description = g;


                currCattle.Source    = new AnimalSource();
                currCattle.Source.ID = ((MasterTables)comboBoxSource.SelectedItem).ID;


                currCattle.Type    = new AnimalType();
                currCattle.Type.ID = ((MasterTables)comboBoxAnimalType.SelectedItem).ID;


                currCattle.Status    = new AnimalStatus();
                currCattle.Status.ID = ((MasterTables)comboBoxStatus.SelectedItem).ID;


                currCattle.OtherDetails = textBoxDescription.Text;

                animalHandler.Add(currCattle);
            }
            catch (FormatException fexcept)
            {
                MessageBox.Show("Kindly Enter the field in correct (numeric) format. Error on " + fexcept.Source + " .", "Invalid Entry");
                return;
            }

            //Added - 01 Jan
            //For Name/Father name not containing numbers

            catch (ArgumentException aexcept)
            {
                MessageBox.Show(aexcept.Message, "Invalid Entry!");
                return;
            }


            //Clear all the TextBoxes

            foreach (TextBox textbox in textBoxcollection)
            {
                textbox.Text = "";
            }

            foreach (ComboBox combobox in comboBoxcollection)
            {
                combobox.SelectedIndex = -1;
            }
        }
 /// <summary>
 /// Tells if the BattleEntity has a Strength to a particular PhysicalAttribute.
 /// </summary>
 /// <param name="physAttribute">The PhysicalAttribute.</param>
 /// <returns>true if the BattleEntity has a Strength to the PhysicalAttribute, false otherwise.</returns>
 public bool HasStrength(PhysicalAttributes physAttribute)
 {
     return(Strengths.ContainsKey(physAttribute));
 }
 /// <summary>
 /// Tells if the BattleEntity has an Element Override of a particular Element for a particular PhysicalAttribute.
 /// </summary>
 /// <param name="attribute">The PhysicalAttribute associated with the Element Override.</param>
 /// <param name="element">The Element of the Element Override.</param>
 /// <returns>true if an Element Override of the Element exists for the PhysicalAttribute, otherwise false.</returns>
 public bool HasElementOverride(PhysicalAttributes attribute, Elements element)
 {
     return(HasElementOverride(attribute) == true && ElementOverrides[attribute].ContainsKey(element));
 }