/// <summary> /// 获得数据列表 /// </summary> public List<Maticsoft.Model.Tao.Comment> CommentDataTableToList(DataTable dt) { List<Maticsoft.Model.Tao.Comment> modelList = new List<Maticsoft.Model.Tao.Comment>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Maticsoft.Model.Tao.Comment model; for (int n = 0; n < rowsCount; n++) { model = new Maticsoft.Model.Tao.Comment(); if (dt.Rows[n]["CommentID"] != null && dt.Rows[n]["CommentID"].ToString() != "") { model.CommentID = int.Parse(dt.Rows[n]["CommentID"].ToString()); } if (dt.Rows[n]["OrderID"] != null && dt.Rows[n]["OrderID"].ToString() != "") { model.OrderID = int.Parse(dt.Rows[n]["OrderID"].ToString()); } if (dt.Rows[n]["CourseID"] != null && dt.Rows[n]["CourseID"].ToString() != "") { model.CourseID = int.Parse(dt.Rows[n]["CourseID"].ToString()); } if (dt.Rows[n]["ModuleID"] != null && dt.Rows[n]["ModuleID"].ToString() != "") { model.ModuleID = int.Parse(dt.Rows[n]["ModuleID"].ToString()); } if (dt.Rows[n]["UserID"] != null && dt.Rows[n]["UserID"].ToString() != "") { model.UserID = int.Parse(dt.Rows[n]["UserID"].ToString()); } if (dt.Rows[n]["Comment"] != null && dt.Rows[n]["Comment"].ToString() != "") { model.Comments = dt.Rows[n]["Comment"].ToString(); } if (dt.Rows[n]["CommentDate"] != null && dt.Rows[n]["CommentDate"].ToString() != "") { model.CommentDate = DateTime.Parse(dt.Rows[n]["CommentDate"].ToString()); } if (dt.Rows[n]["ParentID"] != null && dt.Rows[n]["ParentID"].ToString() != "") { model.ParentID = int.Parse(dt.Rows[n]["ParentID"].ToString()); } if (dt.Rows[n]["Score"] != null && dt.Rows[n]["Score"].ToString() != "") { model.Score = int.Parse(dt.Rows[n]["Score"].ToString()); } modelList.Add(model); } } return modelList; }
/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Tao.Comment GetModel(int CommentID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CommentID,OrderID,CourseID,ModuleID,UserID,Comment,CommentDate,ParentID,Score,Status from Tao_Comment "); strSql.Append(" where CommentID=@CommentID"); SqlParameter[] parameters = { new SqlParameter("@CommentID", SqlDbType.Int,4) }; parameters[0].Value = CommentID; Maticsoft.Model.Tao.Comment model = new Maticsoft.Model.Tao.Comment(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["CommentID"] != null && ds.Tables[0].Rows[0]["CommentID"].ToString() != "") { model.CommentID = int.Parse(ds.Tables[0].Rows[0]["CommentID"].ToString()); } if (ds.Tables[0].Rows[0]["OrderID"] != null && ds.Tables[0].Rows[0]["OrderID"].ToString() != "") { model.OrderID = int.Parse(ds.Tables[0].Rows[0]["OrderID"].ToString()); } if (ds.Tables[0].Rows[0]["CourseID"] != null && ds.Tables[0].Rows[0]["CourseID"].ToString() != "") { model.CourseID = int.Parse(ds.Tables[0].Rows[0]["CourseID"].ToString()); } if (ds.Tables[0].Rows[0]["ModuleID"] != null && ds.Tables[0].Rows[0]["ModuleID"].ToString() != "") { model.ModuleID = int.Parse(ds.Tables[0].Rows[0]["ModuleID"].ToString()); } if (ds.Tables[0].Rows[0]["UserID"] != null && ds.Tables[0].Rows[0]["UserID"].ToString() != "") { model.UserID = int.Parse(ds.Tables[0].Rows[0]["UserID"].ToString()); } if (ds.Tables[0].Rows[0]["Comment"] != null && ds.Tables[0].Rows[0]["Comment"].ToString() != "") { model.Comments = ds.Tables[0].Rows[0]["Comment"].ToString(); } if (ds.Tables[0].Rows[0]["CommentDate"] != null && ds.Tables[0].Rows[0]["CommentDate"].ToString() != "") { model.CommentDate = DateTime.Parse(ds.Tables[0].Rows[0]["CommentDate"].ToString()); } if (ds.Tables[0].Rows[0]["ParentID"] != null && ds.Tables[0].Rows[0]["ParentID"].ToString() != "") { model.ParentID = int.Parse(ds.Tables[0].Rows[0]["ParentID"].ToString()); } if (ds.Tables[0].Rows[0]["Score"] != null && ds.Tables[0].Rows[0]["Score"].ToString() != "") { model.Score = int.Parse(ds.Tables[0].Rows[0]["Score"].ToString()); } if (ds.Tables[0].Rows[0]["Status"] != null && ds.Tables[0].Rows[0]["Status"].ToString() != "") { model.Status = Int16.Parse(ds.Tables[0].Rows[0]["Status"].ToString()); } return model; } else { return null; } }