示例#1
0
 /// <summary>
 /// Calculate the average height of the zoo location
 /// </summary>
 public void AverageWeights()
 {
     foreach (var item in ZooInfo.OrderBy(i => i.Key))
     {
         double avg   = 0;
         int    count = 0;
         AverageWeight = 0;
         for (int i = 0; i < item.Value.Count; i++)
         {
             Animal a = new Animal();
             avg            = a.CalculateAverageWeight(item.Value[i]);
             AverageWeight += avg;
             count++;
         }
         AverageWeight = AverageWeight / count;
         Console.WriteLine($"{item.Key} Zoo has an average weight of {AverageWeight.ToString("N2")} pounds.");
         Console.WriteLine();
     }
 }
示例#2
0
        /// <summary>
        /// Saves the force power descriptor.
        /// </summary>
        /// <returns>Race Object</returns>
        public Race SaveRace()
        {
            SqlDataReader      result;
            DatabaseConnection dbconn     = new DatabaseConnection();
            SqlCommand         command    = new SqlCommand();
            SqlConnection      connection = new SqlConnection(dbconn.SQLSEVERConnString);

            try
            {
                connection.Open();
                command.Connection  = connection;
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "InsertUpdate_Race";

                command.Parameters.Add(dbconn.GenerateParameterObj("@RaceID", SqlDbType.Int, RaceID.ToString(), 0));
                command.Parameters.Add(dbconn.GenerateParameterObj("@RaceName", SqlDbType.VarChar, RaceName.ToString(), 50));
                command.Parameters.Add(dbconn.GenerateParameterObj("@RaceDescription", SqlDbType.VarChar, RaceDescription.ToString(), 1000));
                command.Parameters.Add(dbconn.GenerateParameterObj("@OtherDescription", SqlDbType.VarChar, OtherDescription.ToString(), 1000));
                command.Parameters.Add(dbconn.GenerateParameterObj("@SizeID", SqlDbType.Int, SizeID.ToString(), 0));
                command.Parameters.Add(dbconn.GenerateParameterObj("@Sex", SqlDbType.Char, Sex.ToString(), 1));
                command.Parameters.Add(dbconn.GenerateParameterObj("@RageAbility", SqlDbType.Bit, RageAbility.ToString(), 0));
                command.Parameters.Add(dbconn.GenerateParameterObj("@ShapeShiftAbility", SqlDbType.Bit, ShapeShiftAbility.ToString(), 0));
                command.Parameters.Add(dbconn.GenerateParameterObj("@Primitive", SqlDbType.Bit, Primitive.ToString(), 0));
                command.Parameters.Add(dbconn.GenerateParameterObj("@BonusSkill", SqlDbType.Bit, BonusSkill.ToString(), 0));
                command.Parameters.Add(dbconn.GenerateParameterObj("@BonusFeat", SqlDbType.Bit, BonusFeat.ToString(), 0));
                command.Parameters.Add(dbconn.GenerateParameterObj("@AverageHeight", SqlDbType.Decimal, AverageHeight.ToString(), 0));
                command.Parameters.Add(dbconn.GenerateParameterObj("@AverageWeight", SqlDbType.Decimal, AverageWeight.ToString(), 0));
                command.Parameters.Add(dbconn.GenerateParameterObj("@SpeedID", SqlDbType.Int, SpeedID.ToString(), 0));

                result = command.ExecuteReader();

                result.Read();
                SetReaderToObject(ref result);
            }
            catch
            {
                Exception e = new Exception();
                this._insertUpdateOK = false;
                this._insertUpdateMessage.Append(e.Message + "                     Inner Exception= " + e.InnerException);
                throw e;
            }
            finally
            {
                command.Dispose();
                connection.Close();
            }
            return(this);
        }