/// <summary> /// 新增一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Add(Course_UnitContent model) { StringBuilder sql = new StringBuilder(); sql.Append("insert into [dbo].[Course_UnitContent] ([Title],[Content],[UnitType],[TestCnt],[PrintScore],[TimeLimit],[PassLine],[FinalTestLimit],[UnitId],[TimeLength],[OpenTime],[EndTime],[Display],[Sort],[Delflag],[CreateDate],[ContentType])"); sql.Append(" values (@Title,@Content,@UnitType,@TestCnt,@PrintScore,@TimeLimit,@PassLine,@FinalTestLimit,@UnitId,@TimeLength,@OpenTime,@EndTime,@Display,@Sort,@Delflag,@CreateDate,@ContentType)"); sql.Append(" set @Id=@@IDENTITY"); SqlParameter[] cmdParams = new SqlParameter[]{ new SqlParameter("@Id", SqlDbType.Int, 4) { Value = model.Id, Direction = ParameterDirection.Output }, new SqlParameter("@Title", SqlDbType.VarChar, 200) { Value = model.Title }, new SqlParameter("@Content", SqlDbType.VarChar, 8000) { Value = model.Content }, new SqlParameter("@UnitType", SqlDbType.Int, 4) { Value = model.UnitType }, new SqlParameter("@TestCnt", SqlDbType.Int, 4) { Value = model.TestCnt }, new SqlParameter("@PrintScore", SqlDbType.Bit, 1) { Value = model.PrintScore }, new SqlParameter("@TimeLimit", SqlDbType.Int, 4) { Value = model.TimeLimit }, new SqlParameter("@PassLine", SqlDbType.Int, 4) { Value = model.PassLine }, new SqlParameter("@FinalTestLimit", SqlDbType.Bit, 1) { Value = model.FinalTestLimit }, new SqlParameter("@UnitId", SqlDbType.Int, 4) { Value = model.UnitId }, new SqlParameter("@TimeLength", SqlDbType.Int, 4) { Value = model.TimeLength }, new SqlParameter("@OpenTime", SqlDbType.Int, 4) { Value = model.OpenTime }, new SqlParameter("@EndTime", SqlDbType.Int, 4) { Value = model.EndTime }, new SqlParameter("@Display", SqlDbType.Bit, 1) { Value = model.Display }, new SqlParameter("@Sort", SqlDbType.Int, 4) { Value = model.Sort }, new SqlParameter("@Delflag", SqlDbType.Bit, 1) { Value = model.Delflag }, new SqlParameter("@CreateDate", SqlDbType.DateTime, 8) { Value = model.CreateDate }, new SqlParameter("@ContentType", SqlDbType.Int, 4) { Value = model.ContentType } }; int result = Convert.ToInt32(MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams)); model.Id = Convert.ToInt32(cmdParams[0].Value); return model.Id; }
public ActionResult AddCourseAtivity(Course_UnitContent model) { Course_UnitContentBLL bll = new Course_UnitContentBLL(); int id = bll.Add(model); if (id > 0) { return Json(new { Result = true, UnitContent = id, Msg = "新增成功!" }, JsonRequestBehavior.AllowGet); } else { return Json(new { Result = false, UnitContent = id, Msg = "新增失败!" }, JsonRequestBehavior.AllowGet); } }
/// <summary> /// 新增一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Add(Course_UnitContent model) { //新增默认信息 model.Display = true; model.CreateDate = DateTime.Now; model.Delflag = false; if (model.UnitType == 5 || model.UnitType == 6) { model.TimeLimit = model.TimeLength; } else { model.TimeLimit = 0; } model.PassLine = 0; return dal.Add(model); }
/// <summary> /// DataTable 转换为 List<Course_UnitContent> /// </summary> /// <param name="dtUnitContent"></param> /// <returns></returns> private List<Course_UnitContent> GetCourse_UnitContentList(DataTable dtUnitContent) { var list = new List<Course_UnitContent>(); if (dtUnitContent != null && dtUnitContent.Rows.Count > 0) { foreach (DataRow DrItem in dtUnitContent.Rows) { var model = new Course_UnitContent(); if (DrItem["Id"] != DBNull.Value) model.Id = Convert.ToInt32(DrItem["Id"]); if (DrItem["Title"] != DBNull.Value) model.Title = DrItem["Title"].ToString(); if (DrItem["Content"] != DBNull.Value) model.Content = DrItem["Content"].ToString(); if (DrItem["UnitType"] != DBNull.Value) model.UnitType = Convert.ToInt32(DrItem["UnitType"]); if (DrItem["TestCnt"] != DBNull.Value) model.TestCnt = Convert.ToInt32(DrItem["TestCnt"]); if (DrItem["PrintScore"] != DBNull.Value) model.PrintScore = Convert.ToBoolean(DrItem["PrintScore"]); if (DrItem["TimeLimit"] != DBNull.Value) model.TimeLimit = Convert.ToInt32(DrItem["TimeLimit"]); if (DrItem["PassLine"] != DBNull.Value) model.PassLine = Convert.ToInt32(DrItem["PassLine"]); if (DrItem["FinalTestLimit"] != DBNull.Value) model.FinalTestLimit = Convert.ToBoolean(DrItem["FinalTestLimit"]); if (DrItem["UnitId"] != DBNull.Value) model.UnitId = Convert.ToInt32(DrItem["UnitId"]); if (DrItem["TimeLength"] != DBNull.Value) model.TimeLength = Convert.ToInt32(DrItem["TimeLength"]); if (DrItem["OpenTime"] != DBNull.Value) model.OpenTime = Convert.ToInt32(DrItem["OpenTime"]); if (DrItem["EndTime"] != DBNull.Value) model.EndTime = Convert.ToInt32(DrItem["EndTime"]); if (DrItem["Display"] != DBNull.Value) model.Display = Convert.ToBoolean(DrItem["Display"]); if (DrItem["Sort"] != DBNull.Value) model.Sort = Convert.ToInt32(DrItem["Sort"]); if (DrItem["Delflag"] != DBNull.Value) model.Delflag = Convert.ToBoolean(DrItem["Delflag"]); if (DrItem["CreateDate"] != DBNull.Value) model.CreateDate = Convert.ToDateTime(DrItem["CreateDate"]); if (DrItem["ContentType"] != DBNull.Value) model.ContentType = Convert.ToInt32(DrItem["ContentType"]); list.Add(model); } } return list; }
private void ConvertToModel(IDataReader reader, Course_UnitContent model) { if (reader["Id"] != DBNull.Value) model.Id = Convert.ToInt32(reader["Id"]); if (reader["Title"] != DBNull.Value) model.Title = reader["Title"].ToString(); if (reader["Content"] != DBNull.Value) model.Content = reader["Content"].ToString(); if (reader["UnitType"] != DBNull.Value) model.UnitType = Convert.ToInt32(reader["UnitType"]); if (reader["TestCnt"] != DBNull.Value) model.TestCnt = Convert.ToInt32(reader["TestCnt"]); if (reader["PrintScore"] != DBNull.Value) model.PrintScore = Convert.ToBoolean(reader["PrintScore"]); if (reader["TimeLimit"] != DBNull.Value) model.TimeLimit = Convert.ToInt32(reader["TimeLimit"]); if (reader["PassLine"] != DBNull.Value) model.PassLine = Convert.ToInt32(reader["PassLine"]); if (reader["FinalTestLimit"] != DBNull.Value) model.FinalTestLimit = Convert.ToBoolean(reader["FinalTestLimit"]); if (reader["UnitId"] != DBNull.Value) model.UnitId = Convert.ToInt32(reader["UnitId"]); if (reader["TimeLength"] != DBNull.Value) model.TimeLength = Convert.ToInt32(reader["TimeLength"]); if (reader["OpenTime"] != DBNull.Value) model.OpenTime = Convert.ToInt32(reader["OpenTime"]); if (reader["EndTime"] != DBNull.Value) model.EndTime = Convert.ToInt32(reader["EndTime"]); if (reader["Display"] != DBNull.Value) model.Display = Convert.ToBoolean(reader["Display"]); if (reader["Sort"] != DBNull.Value) model.Sort = Convert.ToInt32(reader["Sort"]); if (reader["Delflag"] != DBNull.Value) model.Delflag = Convert.ToBoolean(reader["Delflag"]); if (reader["CreateDate"] != DBNull.Value) model.CreateDate = Convert.ToDateTime(reader["CreateDate"]); if (reader["ContentType"] != DBNull.Value) model.ContentType = Convert.ToInt32(reader["ContentType"]); }
/// <summary> /// 更新一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Update(Course_UnitContent model) { StringBuilder sql = new StringBuilder(); sql.Append("update [dbo].[Course_UnitContent] set "); sql.Append("[Title]=@Title,[Content]=@Content,[UnitType]=@UnitType,[TestCnt]=@TestCnt,[PrintScore]=@PrintScore,[TimeLimit]=@TimeLimit,[PassLine]=@PassLine,[FinalTestLimit]=@FinalTestLimit,[UnitId]=@UnitId,[TimeLength]=@TimeLength,[OpenTime]=@OpenTime,[EndTime]=@EndTime,[Display]=@Display,[Sort]=@Sort,[Delflag]=@Delflag,[CreateDate]=@CreateDate,[ContentType]=@ContentType"); sql.Append(" where [Id]=@Id"); SqlParameter[] cmdParams = new SqlParameter[] { new SqlParameter("@Id", SqlDbType.Int, 4) { Value = model.Id }, new SqlParameter("@Title", SqlDbType.VarChar, 200) { Value = model.Title }, new SqlParameter("@Content", SqlDbType.VarChar, 8000) { Value = model.Content }, new SqlParameter("@UnitType", SqlDbType.Int, 4) { Value = model.UnitType }, new SqlParameter("@TestCnt", SqlDbType.Int, 4) { Value = model.TestCnt }, new SqlParameter("@PrintScore", SqlDbType.Bit, 1) { Value = model.PrintScore }, new SqlParameter("@TimeLimit", SqlDbType.Int, 4) { Value = model.TimeLimit }, new SqlParameter("@PassLine", SqlDbType.Int, 4) { Value = model.PassLine }, new SqlParameter("@FinalTestLimit", SqlDbType.Bit, 1) { Value = model.FinalTestLimit }, new SqlParameter("@UnitId", SqlDbType.Int, 4) { Value = model.UnitId }, new SqlParameter("@TimeLength", SqlDbType.Int, 4) { Value = model.TimeLength }, new SqlParameter("@OpenTime", SqlDbType.Int, 4) { Value = model.OpenTime }, new SqlParameter("@EndTime", SqlDbType.Int, 4) { Value = model.EndTime }, new SqlParameter("@Display", SqlDbType.Bit, 1) { Value = model.Display }, new SqlParameter("@Sort", SqlDbType.Int, 4) { Value = model.Sort }, new SqlParameter("@Delflag", SqlDbType.Bit, 1) { Value = model.Delflag }, new SqlParameter("@CreateDate", SqlDbType.DateTime, 8) { Value = model.CreateDate }, new SqlParameter("@ContentType", SqlDbType.Int, 4) { Value = model.ContentType } }; return MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams); }
/// <summary> /// 取得一条记录 /// </summary> /// <param name="id"></param> /// <param name="where"></param> /// <returns></returns> public Course_UnitContent GetModel(int id, string where) { string sql = "select * from [dbo].[Course_UnitContent] 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()) { Course_UnitContent model = new Course_UnitContent(); ConvertToModel(reader, model); return model; } else { return null; } } }
/// <summary> /// 获取分页数据集 /// </summary> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <param name="where"></param> /// <param name="orderBy"></param> /// <param name="recordCount"></param> /// <returns></returns> public List<Course_UnitContent> GetListOther(int pageSize, int pageIndex, string where, string orderBy, out int recordCount) { if (string.IsNullOrEmpty(orderBy)) throw new ArgumentNullException(); StringBuilder sb = new StringBuilder(); sb.Append(@"select count(1) from Course_UnitContent inner join Course_UnitDetail on Course_UnitContent.UnitId = Course_UnitDetail.Id and Course_UnitDetail.Display=1 and Course_UnitDetail.Delflag=0 and Course_UnitContent.Display=1 and Course_UnitContent.Delflag=0"); if (!string.IsNullOrEmpty(where)) sb.Append(" where " + where); recordCount = Convert.ToInt32(MSEntLibSqlHelper.ExecuteScalarBySql(sb.ToString())); int start = (pageIndex - 1) * pageSize + 1; int end = pageIndex * pageSize; StringBuilder sql = new StringBuilder(); sql.AppendFormat(@"select * from (select Course_UnitContent.*,ROW_NUMBER() over (order by Course_UnitContent.{0}) as [RowNum] from Course_UnitContent inner join Course_UnitDetail on Course_UnitContent.UnitId = Course_UnitDetail.Id and Course_UnitDetail.Display=1 and Course_UnitDetail.Delflag=0 and Course_UnitContent.Display=1 and Course_UnitContent.Delflag=0", orderBy); if (!string.IsNullOrEmpty(where)) sql.Append(" where " + where); sql.Append(") as T where [RowNum] between " + start + " and " + end); List<Course_UnitContent> list = new List<Course_UnitContent>(); using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString())) { while (reader.Read()) { Course_UnitContent model = new Course_UnitContent(); ConvertToModel(reader, model); list.Add(model); } } return list; }
/// <summary> /// 获取数据集 /// </summary> /// <param name="where"></param> /// <param name="orderBy"></param> /// <returns></returns> public List<Course_UnitContent> GetList(string where, string orderBy) { StringBuilder sql = new StringBuilder(); sql.Append("select * from [dbo].[Course_UnitContent]"); if (!string.IsNullOrEmpty(where)) sql.Append(" where " + where); if (!string.IsNullOrEmpty(orderBy)) sql.Append(" order by " + orderBy); List<Course_UnitContent> list = new List<Course_UnitContent>(); using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString())) { while (reader.Read()) { Course_UnitContent model = new Course_UnitContent(); ConvertToModel(reader, model); list.Add(model); } } return list; }
/// <summary> /// 上下页翻动时,获取 Course_UnitContent 对象 /// </summary> /// <param name="iTrainingId"></param> /// <param name="iUnitContentId"></param> /// <param name="bolNext"></param> /// <returns></returns> private Course_UnitContent GetCourseUnitContentIndex(int iTrainingId, int iClassId, int iUnitContentId, bool bolNext) { var Model_Course_UnitContent = new Course_UnitContent(); var List_Course_UnitContent = this.GetCourseUnitContentActivities(iTrainingId); int iIndex = List_Course_UnitContent.FindIndex(x => x.Id == iUnitContentId); int iCount = List_Course_UnitContent.Count; if (bolNext) { if (iIndex < iCount - 1) Model_Course_UnitContent = List_Course_UnitContent[iIndex + 1]; else if (iIndex == iCount - 1) Model_Course_UnitContent = List_Course_UnitContent[0]; } else { if (iIndex > 0 && iIndex <= iCount - 1) Model_Course_UnitContent = List_Course_UnitContent[iIndex - 1]; else if (iIndex == iCount - 1) Model_Course_UnitContent = List_Course_UnitContent[0]; else if (iIndex == 0) Model_Course_UnitContent = List_Course_UnitContent[iCount - 1]; } ViewBag.ClassId = iClassId; ViewBag.AccountId = Code.SiteCache.Instance.LoginInfo.UserId; ViewBag.Model_Course_UnitContent = Model_Course_UnitContent; return Model_Course_UnitContent; }
/// <summary> /// 获取页面活动的公共方法 /// </summary> /// <param name="bolNeedUpdateProgress">是否需要更新总进度</param> /// <returns></returns> private Course_UnitContent GetCourseUnitContentActivity(int TrainingId, int UnitContent, int ClassId, bool bolNeedUpdateProgress = true) { //获取所有的阅读信息 var courseBll = new Course_UnitContentBLL(); var DetailBll = new Traning_DetailBLL(); var List_Course_UnitContent = new List<Course_UnitContent>(); var Model_Course_UnitContent = new Course_UnitContent(); var stbSqlWhere = new StringBuilder(); var strOrderBy = "Sort"; int iAccountId = 0, iUnitId = 0; iAccountId = Code.SiteCache.Instance.LoginInfo.UserId; stbSqlWhere.Append(" 1 = 1"); if (TrainingId > 0) stbSqlWhere.AppendFormat(" AND Course_UnitDetail.TrainingId = {0}", TrainingId); if (UnitContent > 0) stbSqlWhere.AppendFormat(" AND Course_UnitContent.Id = {0}", UnitContent); List_Course_UnitContent = courseBll.GetListOther(stbSqlWhere.ToString(), strOrderBy); if (List_Course_UnitContent != null && List_Course_UnitContent.Count == 1) Model_Course_UnitContent = List_Course_UnitContent[0]; //根据 TrainingId 获取 Title var Model_Traning_Detail = DetailBll.GetModel(TrainingId, string.Empty); ViewBag.TraningDetailTitle = Model_Traning_Detail.Title; ViewBag.UnitId = iUnitId = Model_Course_UnitContent.UnitId.Value; ViewBag.AccountId = iAccountId; ViewBag.ClassId = ClassId; ViewBag.TrainingId = TrainingId; ViewBag.UnitContent = UnitContent = Model_Course_UnitContent.Id; ViewBag.Model_Course_UnitContent = Model_Course_UnitContent; if (bolNeedUpdateProgress && List_Course_UnitContent != null && List_Course_UnitContent.Count > 0) { //更新总体进度 this.UpdateOverallProgress(iUnitId, ClassId, TrainingId, iAccountId, UnitContent); } return Model_Course_UnitContent; }
public ActionResult EditCourseAtivity(Course_UnitContent model) { Course_UnitContentBLL bll = new Course_UnitContentBLL(); model.Display = true; if (bll.Update(model)) { return Json(new { Result = true, UnitContent = model.Id, Msg = "修改成功!" }, JsonRequestBehavior.AllowGet); } else { return Json(new { Result = false, UnitContent = model.Id, Msg = "修改失败!" }, JsonRequestBehavior.AllowGet); } }
/// <summary> /// 获取页面活动的公共方法 /// </summary> /// <returns></returns> private Course_UnitContent GetCourseUnitContentActivity() { //获取所有的阅读信息 var courseBll = new Course_UnitContentBLL(); var DetailBll = new Traning_DetailBLL(); var List_Course_UnitContent = new List<Course_UnitContent>(); var Model_Course_UnitContent = new Course_UnitContent(); var stbSqlWhere = new StringBuilder(); var strOrderBy = "Sort"; int iClassId = 0, iTrainingId = 0, iAccountId = 0, iUnitContent = 0, iUnitId = 0; int.TryParse(Convert.ToString(Request["TrainingId"]) == "" ? "0" : QueryString.Decrypt(Request["TrainingId"]), out iTrainingId); int.TryParse(Convert.ToString(Request["UnitContent"]) == "" ? "0" : QueryString.Decrypt(Request["UnitContent"]), out iUnitContent); stbSqlWhere.Append(" 1 = 1 "); if (iTrainingId > 0) stbSqlWhere.AppendFormat("AND Course_UnitDetail.TrainingId = {0}", iTrainingId); if (iTrainingId > 0) stbSqlWhere.AppendFormat("AND Course_UnitContent.Id = {0}", iUnitContent); List_Course_UnitContent = courseBll.GetListOther(stbSqlWhere.ToString(), strOrderBy); if (List_Course_UnitContent != null && List_Course_UnitContent.Count == 1) Model_Course_UnitContent = List_Course_UnitContent[0]; //获取当前登录用户的班级和ID iAccountId = Code.SiteCache.Instance.LoginInfo.UserId; //根据 TrainingId 获取 Title var Model_Traning_Detail = DetailBll.GetModel(iTrainingId, string.Empty); ViewBag.TraningDetailTitle = Model_Traning_Detail.Title; ViewBag.AccountId = iAccountId; ViewBag.TrainingId = iTrainingId; ViewBag.UnitContent = iUnitContent = Model_Course_UnitContent.Id; ViewBag.Model_Course_UnitContent = Model_Course_UnitContent; return Model_Course_UnitContent; }
/// <summary> /// 更新一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Update(Course_UnitContent model) { //新增默认信息 if (model.UnitType == 5 || model.UnitType == 6) { model.TimeLimit = model.TimeLength; } else { model.TimeLimit = 0; } model.CreateDate = DateTime.Now; model.Delflag = false; return dal.Update(model) > 0; }