コード例 #1
0
ファイル: MonsterDAO.cs プロジェクト: JustinDavisA/Tamer
 public List<MonsterDM> ReadMonsters(SqlParameter[] parameters, string statement)
 {
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         using (SqlCommand command = new SqlCommand(statement, connection))
         {
             command.CommandType = CommandType.StoredProcedure;
             if (parameters != null)
             {
                 command.Parameters.AddRange(parameters);
             }
             connection.Open();
             SqlDataReader data = command.ExecuteReader();
             List<MonsterDM> monsters = new List<MonsterDM>();
             while (data.Read())
             {
                 MonsterDM monster = new MonsterDM();
                 monster.Id = Convert.ToInt32(data["Id"]);
                 monster.MonsterName = data["MonsterName"].ToString();
                 monster.MonsterHealth = Convert.ToInt32(data["MonsterHealth"]);
                 monster.AttackName = data["AttackName"].ToString();
                 monster.AttackDamage = Convert.ToInt32(data["AttackDamage"]);
                 monsters.Add(monster);
             }
             return monsters;
         }
     }
 }
コード例 #2
0
ファイル: MonsterDAO.cs プロジェクト: JustinDavisA/Tamer
 public void RemoveMonster(MonsterDM monster)
 {
     SqlParameter[] parameters = new SqlParameter[]
     {
         new SqlParameter("@Id",monster.Id)
     };
     try
     {
         dataWriter.Write(parameters, "DeleteMonster");
         logger.LogError("Event", "The user was able to remove a monster", "Class: MonsterDAO & Method Name: RemoveMonster");
     }
     catch (Exception e)
     {
         logger.LogError("Error", "The user was not able to remove a monster", "Class: monsterDAO & Method Name: Removemonster");
     }
 }
コード例 #3
0
ファイル: MonsterDAO.cs プロジェクト: JustinDavisA/Tamer
        public void AddMonster(MonsterDM monster)
        {
            SqlParameter[] parameters = new SqlParameter[]
            {
                new SqlParameter("@MonsterName",monster.MonsterName)
                ,new SqlParameter("@MonsterHealth",monster.MonsterHealth)
                ,new SqlParameter("@AttackName",monster.AttackName)
                ,new SqlParameter("@AttackDamage",monster.AttackDamage)
            };
            try
            {
                dataWriter.Write(parameters, "CreateMonster");
                logger.LogError("Event", "The user was able to add a monster", "Class: MonsterDAO & Method Name: AddMonster");

            }
            catch (Exception e)
            {
                logger.LogError("Error", "The user was not able to add a monster", "Class: MonsterDAO & Method Name: AddMonster");
            }
        }