/// <summary> /// 得到一个对象实体 /// </summary> public Maticsoft.Model.Tao.Courses GetModel(int CourseID) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 CourseID,CourseName,Description,ShortDescription,CategoryId,TimeDuration,CourseSpan,ExpiryDate,ViewCount,Status,Tags,ImageUrl,Type,VideoContent,CreatedDate,CreatedUserID,Recommended,Latest,Hotsale,SpecialOffer,Price,PV,SalesVolume,Sequence,Attachment,ModuleNum,UpdatedDate,CourseTypes from Tao_Courses "); strSql.Append(" where CourseID=@CourseID"); SqlParameter[] parameters = { new SqlParameter("@CourseID", SqlDbType.Int,4)}; parameters[0].Value = CourseID; Maticsoft.Model.Tao.Courses model = new Maticsoft.Model.Tao.Courses(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { 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]["CourseName"] != null && ds.Tables[0].Rows[0]["CourseName"].ToString() != "") { model.CourseName = ds.Tables[0].Rows[0]["CourseName"].ToString(); } if (ds.Tables[0].Rows[0]["Description"] != null && ds.Tables[0].Rows[0]["Description"].ToString() != "") { model.Description = ds.Tables[0].Rows[0]["Description"].ToString(); } if (ds.Tables[0].Rows[0]["ShortDescription"] != null && ds.Tables[0].Rows[0]["ShortDescription"].ToString() != "") { model.ShortDescription = ds.Tables[0].Rows[0]["ShortDescription"].ToString(); } if (ds.Tables[0].Rows[0]["CategoryId"] != null && ds.Tables[0].Rows[0]["CategoryId"].ToString() != "") { model.CategoryId = int.Parse(ds.Tables[0].Rows[0]["CategoryId"].ToString()); } if (ds.Tables[0].Rows[0]["TimeDuration"] != null && ds.Tables[0].Rows[0]["TimeDuration"].ToString() != "") { model.TimeDuration = int.Parse(ds.Tables[0].Rows[0]["TimeDuration"].ToString()); } if (ds.Tables[0].Rows[0]["CourseSpan"] != null && ds.Tables[0].Rows[0]["CourseSpan"].ToString() != "") { model.CourseSpan = int.Parse(ds.Tables[0].Rows[0]["CourseSpan"].ToString()); } if (ds.Tables[0].Rows[0]["ExpiryDate"] != null && ds.Tables[0].Rows[0]["ExpiryDate"].ToString() != "") { model.ExpiryDate = DateTime.Parse(ds.Tables[0].Rows[0]["ExpiryDate"].ToString()); } if (ds.Tables[0].Rows[0]["ViewCount"] != null && ds.Tables[0].Rows[0]["ViewCount"].ToString() != "") { model.ViewCount = int.Parse(ds.Tables[0].Rows[0]["ViewCount"].ToString()); } if (ds.Tables[0].Rows[0]["Status"] != null && ds.Tables[0].Rows[0]["Status"].ToString() != "") { model.Status = int.Parse(ds.Tables[0].Rows[0]["Status"].ToString()); } if (ds.Tables[0].Rows[0]["Tags"] != null && ds.Tables[0].Rows[0]["Tags"].ToString() != "") { model.Tags = ds.Tables[0].Rows[0]["Tags"].ToString(); } if (ds.Tables[0].Rows[0]["ImageUrl"] != null && ds.Tables[0].Rows[0]["ImageUrl"].ToString() != "") { model.ImageUrl = ds.Tables[0].Rows[0]["ImageUrl"].ToString(); } if (ds.Tables[0].Rows[0]["Type"] != null && ds.Tables[0].Rows[0]["Type"].ToString() != "") { model.Type = int.Parse(ds.Tables[0].Rows[0]["Type"].ToString()); } if (ds.Tables[0].Rows[0]["VideoContent"] != null && ds.Tables[0].Rows[0]["VideoContent"].ToString() != "") { model.VideoContent = ds.Tables[0].Rows[0]["VideoContent"].ToString(); } if (ds.Tables[0].Rows[0]["CreatedDate"] != null && ds.Tables[0].Rows[0]["CreatedDate"].ToString() != "") { model.CreatedDate = DateTime.Parse(ds.Tables[0].Rows[0]["CreatedDate"].ToString()); } if (ds.Tables[0].Rows[0]["CreatedUserID"] != null && ds.Tables[0].Rows[0]["CreatedUserID"].ToString() != "") { model.CreatedUserID = int.Parse(ds.Tables[0].Rows[0]["CreatedUserID"].ToString()); } if (ds.Tables[0].Rows[0]["Recommended"] != null && ds.Tables[0].Rows[0]["Recommended"].ToString() != "") { if ((ds.Tables[0].Rows[0]["Recommended"].ToString() == "1") || (ds.Tables[0].Rows[0]["Recommended"].ToString().ToLower() == "true")) { model.Recommended = true; } else { model.Recommended = false; } } if (ds.Tables[0].Rows[0]["Latest"] != null && ds.Tables[0].Rows[0]["Latest"].ToString() != "") { if ((ds.Tables[0].Rows[0]["Latest"].ToString() == "1") || (ds.Tables[0].Rows[0]["Latest"].ToString().ToLower() == "true")) { model.Latest = true; } else { model.Latest = false; } } if (ds.Tables[0].Rows[0]["Hotsale"] != null && ds.Tables[0].Rows[0]["Hotsale"].ToString() != "") { if ((ds.Tables[0].Rows[0]["Hotsale"].ToString() == "1") || (ds.Tables[0].Rows[0]["Hotsale"].ToString().ToLower() == "true")) { model.Hotsale = true; } else { model.Hotsale = false; } } if (ds.Tables[0].Rows[0]["SpecialOffer"] != null && ds.Tables[0].Rows[0]["SpecialOffer"].ToString() != "") { if ((ds.Tables[0].Rows[0]["SpecialOffer"].ToString() == "1") || (ds.Tables[0].Rows[0]["SpecialOffer"].ToString().ToLower() == "true")) { model.SpecialOffer = true; } else { model.SpecialOffer = false; } } if (ds.Tables[0].Rows[0]["Price"] != null && ds.Tables[0].Rows[0]["Price"].ToString() != "") { model.Price = decimal.Parse(ds.Tables[0].Rows[0]["Price"].ToString()); } if (ds.Tables[0].Rows[0]["PV"] != null && ds.Tables[0].Rows[0]["PV"].ToString() != "") { model.PV = int.Parse(ds.Tables[0].Rows[0]["PV"].ToString()); } if (ds.Tables[0].Rows[0]["SalesVolume"] != null && ds.Tables[0].Rows[0]["SalesVolume"].ToString() != "") { model.SalesVolume = int.Parse(ds.Tables[0].Rows[0]["SalesVolume"].ToString()); } if (ds.Tables[0].Rows[0]["Sequence"] != null && ds.Tables[0].Rows[0]["Sequence"].ToString() != "") { model.Sequence = int.Parse(ds.Tables[0].Rows[0]["Sequence"].ToString()); } if (ds.Tables[0].Rows[0]["Attachment"] != null && ds.Tables[0].Rows[0]["Attachment"].ToString() != "") { model.Attachment = ds.Tables[0].Rows[0]["Attachment"].ToString(); } if (ds.Tables[0].Rows[0]["ModuleNum"] != null && ds.Tables[0].Rows[0]["ModuleNum"].ToString() != "") { model.ModuleNum = int.Parse(ds.Tables[0].Rows[0]["ModuleNum"].ToString()); } if (ds.Tables[0].Rows[0]["UpdatedDate"] != null && ds.Tables[0].Rows[0]["UpdatedDate"].ToString() != "") { model.UpdatedDate = DateTime.Parse(ds.Tables[0].Rows[0]["UpdatedDate"].ToString()); } if (ds.Tables[0].Rows[0]["CourseTypes"] != null && ds.Tables[0].Rows[0]["CourseTypes"].ToString() != "") { model.CourseTypes = int.Parse(ds.Tables[0].Rows[0]["CourseTypes"].ToString()); } return model; } else { return null; } }
/// <summary> /// 获得数据列表 /// </summary> public List<Maticsoft.Model.Tao.Courses> DataTableToList(DataTable dt) { List<Maticsoft.Model.Tao.Courses> modelList = new List<Maticsoft.Model.Tao.Courses>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Maticsoft.Model.Tao.Courses model; for (int n = 0; n < rowsCount; n++) { model = new Maticsoft.Model.Tao.Courses(); if (dt.Rows[n]["CourseID"] != null && dt.Rows[n]["CourseID"].ToString() != "") { model.CourseID = int.Parse(dt.Rows[n]["CourseID"].ToString()); } if (dt.Rows[n]["CourseName"] != null && dt.Rows[n]["CourseName"].ToString() != "") { model.CourseName = dt.Rows[n]["CourseName"].ToString(); } if (dt.Rows[n]["Description"] != null && dt.Rows[n]["Description"].ToString() != "") { model.Description = dt.Rows[n]["Description"].ToString(); } if (dt.Rows[n]["ShortDescription"] != null && dt.Rows[n]["ShortDescription"].ToString() != "") { model.ShortDescription = dt.Rows[n]["ShortDescription"].ToString(); } if (dt.Rows[n]["CategoryId"] != null && dt.Rows[n]["CategoryId"].ToString() != "") { model.CategoryId = int.Parse(dt.Rows[n]["CategoryId"].ToString()); } if (dt.Rows[n]["TimeDuration"] != null && dt.Rows[n]["TimeDuration"].ToString() != "") { model.TimeDuration = int.Parse(dt.Rows[n]["TimeDuration"].ToString()); } if (dt.Rows[n]["CourseSpan"] != null && dt.Rows[n]["CourseSpan"].ToString() != "") { model.CourseSpan = int.Parse(dt.Rows[n]["CourseSpan"].ToString()); } if (dt.Rows[n]["ExpiryDate"] != null && dt.Rows[n]["ExpiryDate"].ToString() != "") { model.ExpiryDate = DateTime.Parse(dt.Rows[n]["ExpiryDate"].ToString()); } if (dt.Rows[n]["ViewCount"] != null && dt.Rows[n]["ViewCount"].ToString() != "") { model.ViewCount = int.Parse(dt.Rows[n]["ViewCount"].ToString()); } if (dt.Rows[n]["Status"] != null && dt.Rows[n]["Status"].ToString() != "") { model.Status = int.Parse(dt.Rows[n]["Status"].ToString()); } if (dt.Rows[n]["Tags"] != null && dt.Rows[n]["Tags"].ToString() != "") { model.Tags = dt.Rows[n]["Tags"].ToString(); } if (dt.Rows[n]["ImageUrl"] != null && dt.Rows[n]["ImageUrl"].ToString() != "") { model.ImageUrl = dt.Rows[n]["ImageUrl"].ToString(); } if (dt.Rows[n]["Type"] != null && dt.Rows[n]["Type"].ToString() != "") { model.Type = int.Parse(dt.Rows[n]["Type"].ToString()); } if (dt.Rows[n]["VideoContent"] != null && dt.Rows[n]["VideoContent"].ToString() != "") { model.VideoContent = dt.Rows[n]["VideoContent"].ToString(); } if (dt.Rows[n]["CreatedDate"] != null && dt.Rows[n]["CreatedDate"].ToString() != "") { model.CreatedDate = DateTime.Parse(dt.Rows[n]["CreatedDate"].ToString()); } if (dt.Rows[n]["CreatedUserID"] != null && dt.Rows[n]["CreatedUserID"].ToString() != "") { model.CreatedUserID = int.Parse(dt.Rows[n]["CreatedUserID"].ToString()); } if (dt.Rows[n]["Recommended"] != null && dt.Rows[n]["Recommended"].ToString() != "") { if ((dt.Rows[n]["Recommended"].ToString() == "1") || (dt.Rows[n]["Recommended"].ToString().ToLower() == "true")) { model.Recommended = true; } else { model.Recommended = false; } } if (dt.Rows[n]["Latest"] != null && dt.Rows[n]["Latest"].ToString() != "") { if ((dt.Rows[n]["Latest"].ToString() == "1") || (dt.Rows[n]["Latest"].ToString().ToLower() == "true")) { model.Latest = true; } else { model.Latest = false; } } if (dt.Rows[n]["Hotsale"] != null && dt.Rows[n]["Hotsale"].ToString() != "") { if ((dt.Rows[n]["Hotsale"].ToString() == "1") || (dt.Rows[n]["Hotsale"].ToString().ToLower() == "true")) { model.Hotsale = true; } else { model.Hotsale = false; } } if (dt.Rows[n]["SpecialOffer"] != null && dt.Rows[n]["SpecialOffer"].ToString() != "") { if ((dt.Rows[n]["SpecialOffer"].ToString() == "1") || (dt.Rows[n]["SpecialOffer"].ToString().ToLower() == "true")) { model.SpecialOffer = true; } else { model.SpecialOffer = false; } } if (dt.Rows[n]["Price"] != null && dt.Rows[n]["Price"].ToString() != "") { model.Price = decimal.Parse(dt.Rows[n]["Price"].ToString()); } if (dt.Rows[n]["PV"] != null && dt.Rows[n]["PV"].ToString() != "") { model.PV = int.Parse(dt.Rows[n]["PV"].ToString()); } if (dt.Rows[n]["SalesVolume"] != null && dt.Rows[n]["SalesVolume"].ToString() != "") { model.SalesVolume = int.Parse(dt.Rows[n]["SalesVolume"].ToString()); } if (dt.Rows[n]["Sequence"] != null && dt.Rows[n]["Sequence"].ToString() != "") { model.Sequence = int.Parse(dt.Rows[n]["Sequence"].ToString()); } if (dt.Rows[n]["Attachment"] != null && dt.Rows[n]["Attachment"].ToString() != "") { model.Attachment = dt.Rows[n]["Attachment"].ToString(); } if (dt.Rows[n]["ModuleNum"] != null && dt.Rows[n]["ModuleNum"].ToString() != "") { model.ModuleNum = int.Parse(dt.Rows[n]["ModuleNum"].ToString()); } if (dt.Rows[n]["UpdatedDate"] != null && dt.Rows[n]["UpdatedDate"].ToString() != "") { model.UpdatedDate = DateTime.Parse(dt.Rows[n]["UpdatedDate"].ToString()); } if (dt.Rows[n]["CourseTypes"] != null && dt.Rows[n]["CourseTypes"].ToString() != "") { model.CourseTypes = int.Parse(dt.Rows[n]["CourseTypes"].ToString()); } modelList.Add(model); } } return modelList; }