/// <summary> /// 得到一个对象实体 /// </summary> public abc.Model.Model.CourseLesson DataRowToModel(DataRow row) { abc.Model.Model.CourseLesson model = new abc.Model.Model.CourseLesson(); if (row != null) { if (row["LessonId"] != null && row["LessonId"].ToString() != "") { model.LessonId = int.Parse(row["LessonId"].ToString()); } if (row["CourseId"] != null && row["CourseId"].ToString() != "") { model.CourseId = int.Parse(row["CourseId"].ToString()); } if (row["Number"] != null && row["Number"].ToString() != "") { model.Number = int.Parse(row["Number"].ToString()); } if (row["LessonName"] != null) { model.LessonName = row["LessonName"].ToString(); } if (row["Content"] != null) { model.Content = row["Content"].ToString(); } if (row["LessonDesc"] != null) { model.LessonDesc = row["LessonDesc"].ToString(); } if (row["CLength"] != null && row["CLength"].ToString() != "") { model.CLength = int.Parse(row["CLength"].ToString()); } if (row["IsFree"] != null && row["IsFree"].ToString() != "") { model.IsFree = int.Parse(row["IsFree"].ToString()); } if (row["Enabled"] != null && row["Enabled"].ToString() != "") { model.Enabled = int.Parse(row["Enabled"].ToString()); } if (row["Createtime"] != null && row["Createtime"].ToString() != "") { model.Createtime = DateTime.Parse(row["Createtime"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(abc.Model.Model.CourseLesson model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CourseLesson set "); strSql.Append("LessonName=SQL2012LessonName,"); strSql.Append("Content=SQL2012Content,"); strSql.Append("LessonDesc=SQL2012LessonDesc,"); strSql.Append("CLength=SQL2012CLength,"); strSql.Append("IsFree=SQL2012IsFree,"); strSql.Append("Enabled=SQL2012Enabled,"); strSql.Append("Createtime=SQL2012Createtime"); strSql.Append(" where LessonId=SQL2012LessonId"); SqlParameter[] parameters = { new SqlParameter("SQL2012LessonName", SqlDbType.VarChar, 255), new SqlParameter("SQL2012Content", SqlDbType.VarChar, 255), new SqlParameter("SQL2012LessonDesc", SqlDbType.VarChar, 255), new SqlParameter("SQL2012CLength", SqlDbType.Int, 4), new SqlParameter("SQL2012IsFree", SqlDbType.Int, 4), new SqlParameter("SQL2012Enabled", SqlDbType.Int, 4), new SqlParameter("SQL2012Createtime", SqlDbType.DateTime), new SqlParameter("SQL2012LessonId", SqlDbType.Int, 4), new SqlParameter("SQL2012CourseId", SqlDbType.Int, 4), new SqlParameter("SQL2012Number", SqlDbType.Int, 4) }; parameters[0].Value = model.LessonName; parameters[1].Value = model.Content; parameters[2].Value = model.LessonDesc; parameters[3].Value = model.CLength; parameters[4].Value = model.IsFree; parameters[5].Value = model.Enabled; parameters[6].Value = model.Createtime; parameters[7].Value = model.LessonId; parameters[8].Value = model.CourseId; parameters[9].Value = model.Number; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(abc.Model.Model.CourseLesson model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CourseLesson("); strSql.Append("CourseId,Number,LessonName,Content,LessonDesc,CLength,IsFree,Enabled,Createtime)"); strSql.Append(" values ("); strSql.Append("SQL2012CourseId,SQL2012Number,SQL2012LessonName,SQL2012Content,SQL2012LessonDesc,SQL2012CLength,SQL2012IsFree,SQL2012Enabled,SQL2012Createtime)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("SQL2012CourseId", SqlDbType.Int, 4), new SqlParameter("SQL2012Number", SqlDbType.Int, 4), new SqlParameter("SQL2012LessonName", SqlDbType.VarChar, 255), new SqlParameter("SQL2012Content", SqlDbType.VarChar, 255), new SqlParameter("SQL2012LessonDesc", SqlDbType.VarChar, 255), new SqlParameter("SQL2012CLength", SqlDbType.Int, 4), new SqlParameter("SQL2012IsFree", SqlDbType.Int, 4), new SqlParameter("SQL2012Enabled", SqlDbType.Int, 4), new SqlParameter("SQL2012Createtime", SqlDbType.DateTime) }; parameters[0].Value = model.CourseId; parameters[1].Value = model.Number; parameters[2].Value = model.LessonName; parameters[3].Value = model.Content; parameters[4].Value = model.LessonDesc; parameters[5].Value = model.CLength; parameters[6].Value = model.IsFree; parameters[7].Value = model.Enabled; parameters[8].Value = model.Createtime; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public abc.Model.Model.CourseLesson GetModel(int LessonId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 LessonId,CourseId,Number,LessonName,Content,LessonDesc,CLength,IsFree,Enabled,Createtime from CourseLesson "); strSql.Append(" where LessonId=SQL2012LessonId"); SqlParameter[] parameters = { new SqlParameter("SQL2012LessonId", SqlDbType.Int, 4) }; parameters[0].Value = LessonId; abc.Model.Model.CourseLesson model = new abc.Model.Model.CourseLesson(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }