Ejemplo n.º 1
0
 private void ConvertToModel(IDataReader reader, MyTestScore model)
 {
     if (reader["Id"] != DBNull.Value)
         model.Id = Convert.ToInt32(reader["Id"]);
     if (reader["UserId"] != DBNull.Value)
         model.UserId = Convert.ToInt32(reader["UserId"]);
     if (reader["DimensionId"] != DBNull.Value)
         model.DimensionId = Convert.ToInt32(reader["DimensionId"]);
     if (reader["Score"] != DBNull.Value)
         model.Score = reader["Score"].ToString();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 取得一条测试分数
 /// </summary>
 /// <param name="id"></param>
 /// <param name="where"></param>
 /// <returns></returns>
 public MyTestScore GetScore(int id, string where)
 {
     string sql = "select * from [2015NlCP].[dbo].[score] where [Id]=@Id";
     if (!string.IsNullOrEmpty(where))
         sql += " and " + where;
     SqlParameter[] cmdParams = new SqlParameter[]{
         new SqlParameter("@Id", SqlDbType.Int, 4) { Value = id }
     };
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql, cmdParams))
     {
         if (reader.Read())
         {
             MyTestScore model = new MyTestScore();
             ConvertToModel(reader, model);
             return model;
         }
         else
         {
             return null;
         }
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 取得测试分数列表
 /// </summary>
 /// <param name="where"></param>
 /// <param name="orderBy"></param>
 /// <returns></returns>
 public List<MyTestScore> GetScoreList(string where, string orderBy)
 {
     StringBuilder sql = new StringBuilder();
     sql.Append("select * from [2015NlCP].[dbo].[score]");
     if (!string.IsNullOrEmpty(where))
         sql.Append(" where " + where);
     if (!string.IsNullOrEmpty(orderBy))
         sql.Append(" order by " + orderBy);
     List<MyTestScore> list = new List<MyTestScore>();
     using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString()))
     {
         while (reader.Read())
         {
             MyTestScore model = new MyTestScore();
             ConvertToModel(reader, model);
             list.Add(model);
         }
     }
     return list;
 }