/// <summary> /// 新增一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Add(Traning_Detail model) { StringBuilder sql = new StringBuilder(); sql.Append("insert into [dbo].[Traning_Detail] ([Title],[Content],[Pic],[Creater],[OrganId],[TraingField],[TraingCategory],[TraingTopic],[TraningObject],[Subject],[StudyLevel],[TotalTime],[TrainingForm],[TeacherTitle],[TeacherName],[TeacherFrom],[TeacherPic],[Outline],[PartitionId],[OutSideType],[OutSideLink],[Range],[Status],[ApplyRemark],[Display],[Delflag],[CreateDate],[ParentOrganId],[OutSideContent],[CanEdit],[NationalCoursId])"); sql.Append(" values (@Title,@Content,@Pic,@Creater,@OrganId,@TraingField,@TraingCategory,@TraingTopic,@TraningObject,@Subject,@StudyLevel,@TotalTime,@TrainingForm,@TeacherTitle,@TeacherName,@TeacherFrom,@TeacherPic,@Outline,@PartitionId,@OutSideType,@OutSideLink,@Range,@Status,@ApplyRemark,@Display,@Delflag,@CreateDate,@ParentOrganId,@OutSideContent,@CanEdit,@NationalCoursId)"); 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("@Pic", SqlDbType.VarChar, 200) { Value = model.Pic }, new SqlParameter("@Creater", SqlDbType.Int, 4) { Value = model.Creater }, new SqlParameter("@OrganId", SqlDbType.Int, 4) { Value = model.OrganId }, new SqlParameter("@TraingField", SqlDbType.Int, 4) { Value = model.TraingField }, new SqlParameter("@TraingCategory", SqlDbType.Int, 4) { Value = model.TraingCategory }, new SqlParameter("@TraingTopic", SqlDbType.Int, 4) { Value = model.TraingTopic }, new SqlParameter("@TraningObject", SqlDbType.VarChar, 500) { Value = model.TraningObject }, new SqlParameter("@Subject", SqlDbType.VarChar, 500) { Value = model.Subject }, new SqlParameter("@StudyLevel", SqlDbType.VarChar, 500) { Value = model.StudyLevel }, new SqlParameter("@TotalTime", SqlDbType.Float, 8) { Value = model.TotalTime }, new SqlParameter("@TrainingForm", SqlDbType.Int, 4) { Value = model.TrainingForm }, new SqlParameter("@TeacherTitle", SqlDbType.Int, 4) { Value = model.TeacherTitle }, new SqlParameter("@TeacherName", SqlDbType.VarChar, 20) { Value = model.TeacherName }, new SqlParameter("@TeacherFrom", SqlDbType.VarChar, 50) { Value = model.TeacherFrom }, new SqlParameter("@TeacherPic", SqlDbType.VarChar, 500) { Value = model.TeacherPic }, new SqlParameter("@Outline", SqlDbType.VarChar, 8000) { Value = model.Outline }, new SqlParameter("@PartitionId", SqlDbType.Int, 4) { Value = model.PartitionId }, new SqlParameter("@OutSideType", SqlDbType.Int, 4) { Value = model.OutSideType }, new SqlParameter("@OutSideLink", SqlDbType.VarChar, 500) { Value = model.OutSideLink }, new SqlParameter("@Range", SqlDbType.Int, 4) { Value = model.Range }, new SqlParameter("@Status", SqlDbType.Int, 4) { Value = model.Status }, new SqlParameter("@ApplyRemark", SqlDbType.VarChar, 500) { Value = model.ApplyRemark }, new SqlParameter("@Display", SqlDbType.Bit, 1) { Value = model.Display }, new SqlParameter("@Delflag", SqlDbType.Bit, 1) { Value = model.Delflag }, new SqlParameter("@CreateDate", SqlDbType.DateTime, 8) { Value = model.CreateDate }, new SqlParameter("@ParentOrganId", SqlDbType.Int, 4) { Value = model.ParentOrganId }, new SqlParameter("@OutSideContent", SqlDbType.VarChar, -1) { Value = model.OutSideContent }, new SqlParameter("@CanEdit", SqlDbType.Bit, 1) { Value = model.CanEdit }, new SqlParameter("@NationalCoursId", SqlDbType.Int, 4) { Value = model.NationalCoursId } }; int result = Convert.ToInt32(MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams)); model.Id = Convert.ToInt32(cmdParams[0].Value); return result; }
public ActionResult Edit(Traning_Detail model) { PrepareTrainingApplyBLL bll = new PrepareTrainingApplyBLL(); //ViewBag.TrainingObjectData = bll.GetTraningObject(); //ViewBag.SubjectData = bll.GetSubject(); //ViewBag.StudyLevelData = bll.GetStudyLevel(); //ViewBag.TrainingFormData = bll.GetTrainingForm(); //ViewBag.TeacherTitleData = bll.GetTeacherTitle(); //ViewBag.TrainingFeildData = bll.GetTrainingField("Delflag=0 and IsSpec=0", ""); //ViewBag.TrainingCategoryData = bll.GetTrainingCategory("Delflag=0 and Field=" + model.TraingField, ""); //ViewBag.TrainingTopicData = bll.GetTrainingTopic("Delflag=0 and CategoryId=" + model.TraingCategory, ""); //DataTable attachData = bll.GetAttachTable("Delflag=0 and TraningId=" + model.Id, ""); //ViewBag.AttachData = attachData; //ViewBag.OutCourseTypeData = bll.GetOutCourseType("Delflag=0", ""); if (model.TraingCategory == 0) { TempData["Msg"] = "课程小类不能为空!"; return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id)); } if (model.TraingTopic == null || model.TraingTopic == 0) { TempData["Msg"] = "课程主题不能为空!"; return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id)); } if (string.IsNullOrEmpty(model.TeacherName)) { TempData["Msg"] = "请输入讲师名称!"; return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id)); } if (string.IsNullOrEmpty(model.TeacherFrom)) { TempData["Msg"] = "请输入讲师来自什么地方!"; return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id)); } string msg = ""; if (model.Title == null) model.Title = ""; else model.Title = model.Title.Trim(); //if (bll.CheckExists(model.Title.Replace("'", "''"), Convert.ToInt32(model.OrganId), model.Id)) //{ // TempData["Msg"] = "课程名称已存在"; // return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id)); //} int picType = Code.ExtendHelper.ToInt(Request["PicType"]); if (picType == 0) { TempData["Msg"] = "请选择图片!"; return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id)); } else if (picType == 1)//选择提供的图片 { model.Pic = Request["PicValue"]; } else if (picType == 2)//选择上传的图片 { HttpPostedFileBase pic = Request.Files["Pic"]; string picPath = Code.UploadCore.UploadImage(pic, ref msg); if (picPath == "") { TempData["Msg"] = msg; return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id)); } model.Pic = picPath; } if (Request.Files["TeacherPic"] != null) { if (Request.Files["TeacherPic"].ContentLength > 0) { string teacherPicPath = Code.UploadCore.UploadImage(Request.Files["TeacherPic"], ref msg); if (teacherPicPath == "") { TempData["Msg"] = msg; return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id)); } model.TeacherPic = teacherPicPath; } else { model.TeacherPic = Request["TeacherPicValue"]; } } else { model.TeacherPic = Request["TeacherPicValue"]; } if (!model.CanEdit) { if (Request["submit"] == "保存") model.Status = 1; if (Request["submit"] == "保存并提交") model.Status = 2; } if (model.Range == 1)//区级时更新上级机构Id model.ParentOrganId = bll.GetParentOrganId(Convert.ToInt32(model.OrganId)); if (model.Range == 2)//市级 model.ParentOrganId = null; int outCourseType = Code.ExtendHelper.ToInt(Request["OutCourseType"]); if (model.OutSideType == -1)//内部平台 { model.OutSideLink = null; model.OutSideContent = null; } else//外部平台 { model.OutSideType = outCourseType; } using (TransactionScope trans = new TransactionScope()) { try { //更新培训信息 bll.UpdateTrainingDetail(model); //更新附件 DataTable attach = bll.GetAttachTable("Delflag=0 and TraningId=" + model.Id, ""); List<string> attachIdList = new List<string>(); if (!string.IsNullOrEmpty(Request["AttachPathList"])) { foreach (string s in Request["AttachPathList"].Split(':')) { string[] file = s.Split('|'); if (file[0] == "0") { DataRow row = attach.NewRow(); row["Id"] = file[0]; row["TraningId"] = model.Id; row["Title"] = file[1].Replace("'", "''"); row["Link"] = file[2]; row["Sort"] = 50; row["Display"] = 1; row["Delflag"] = 0; row["CreateDate"] = DateTime.Now; attach.Rows.Add(row); } else { attachIdList.Add(file[0]); } } } foreach (DataRow row in attach.Rows) { if (row.RowState == DataRowState.Unchanged && !attachIdList.Contains(row["Id"].ToString())) row.Delete(); } bll.BatchAttach(attach); if (model.Status == 2)//保存并提交时,新增一条申请流程记录 { Traning_ApplyApplication apply = new Traning_ApplyApplication(); apply.TraningId = model.Id; apply.Status = 1; apply.Remark = "提交审核"; apply.Creater = model.Creater; apply.OrganId = model.OrganId; apply.Delflag = false; apply.CreateDate = DateTime.Now; bll.AddTrainingApply(apply); } trans.Complete(); return RedirectToAction("List"); } catch (Exception) { TempData["Msg"] = "保存失败!"; return Redirect("Edit?Id=" + Dianda.Common.QueryString.UrlEncrypt(model.Id)); } } }
public ActionResult Add(Traning_Detail model) { PrepareTrainingApplyBLL bll = new PrepareTrainingApplyBLL(); ViewBag.TrainingObjectData = bll.GetTraningObject(); ViewBag.SubjectData = bll.GetSubject(); ViewBag.StudyLevelData = bll.GetStudyLevel(); ViewBag.TrainingFormData = bll.GetTrainingForm(); ViewBag.TeacherTitleData = bll.GetTeacherTitle(); ViewBag.OutCourseTypeData = bll.GetOutCourseType("Delflag=0", ""); Organ_Detail otypeModel = new Organ_DetailBLL().GetModel(Code.SiteCache.Instance.ManageOrganId); ViewBag.OTypeId = otypeModel == null ? 0 : Convert.ToInt32(otypeModel.OType); if (model.TraingCategory == 0) { TempData["Msg"] = "课程小类不能为空!"; return View(model); } if (model.TraingTopic == null || model.TraingTopic == 0) { TempData["Msg"] = "课程主题不能为空!"; return View(model); } if (string.IsNullOrEmpty(model.TeacherName)) { TempData["Msg"] = "请输入讲师名称!"; return View(model); } if (string.IsNullOrEmpty(model.TeacherFrom)) { TempData["Msg"] = "请输入讲师来自什么地方!"; return View(model); } string msg = ""; if (model.Title == null) model.Title = ""; else model.Title = model.Title.Trim(); model.OrganId = Code.SiteCache.Instance.ManageOrganId; //if (bll.CheckExists(model.Title.Replace("'", "''"), Convert.ToInt32(model.OrganId), model.Id)) //{ // TempData["Msg"] = "课程名称已存在"; // return View(model); //} int picType = Code.ExtendHelper.ToInt(Request["PicType"]); if (picType == 0) { TempData["Msg"] = "请选择图片!"; return View(model); } else if (picType == 1)//选择提供的图片 { model.Pic = Request["PicValue"]; } else if (picType == 2)//选择上传的图片 { HttpPostedFileBase pic = Request.Files["Pic"]; string picPath = Code.UploadCore.UploadImage(pic, ref msg); if (picPath == "") { TempData["Msg"] = msg; return View(model); } model.Pic = picPath; } HttpPostedFileBase teacherPic = Request.Files["TeacherPic"]; string teacherPicPath = Code.UploadCore.UploadImage(teacherPic, ref msg); if (teacherPicPath == "") { TempData["Msg"] = msg; return View(model); } model.TeacherPic = teacherPicPath; model.CreateDate = DateTime.Now; model.Creater = Code.SiteCache.Instance.ManagerId; model.PartitionId = Code.SiteCache.Instance.LoginInfo.PartitionId; if (model.Range == 1)//区级时更新上级机构Id model.ParentOrganId = bll.GetParentOrganId(Convert.ToInt32(model.OrganId)); if (model.Range == 2)//市级 model.ParentOrganId = null; int outCourseType = Code.ExtendHelper.ToInt(Request["OutCourseType"]); if (model.OutSideType == -1)//内部平台 { model.OutSideLink = null; model.OutSideContent = null; } else//外部平台 { model.OutSideType = outCourseType; } if (Request["submit"] == "保存") model.Status = 1; if (Request["submit"] == "保存并提交") model.Status = 2; model.Display = true; using (TransactionScope trans = new TransactionScope()) { try { //新增培训信息 bll.AddTrainingDetail(model); //更新附件 if (!string.IsNullOrEmpty(Request["AttachPathList"])) { DataTable dt = bll.GetAttachTable("1=0", ""); foreach (string s in Request["AttachPathList"].Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries)) { DataRow row = dt.NewRow(); string[] file = s.Split('|'); row["Id"] = file[0]; row["TraningId"] = model.Id; row["Title"] = file[1].Replace("'", "''"); row["Link"] = file[2]; row["Sort"] = 50; row["Display"] = 1; row["Delflag"] = 0; row["CreateDate"] = DateTime.Now; dt.Rows.Add(row); } bll.BatchAttach(dt); } if (model.Status == 2)//保存并提交时,新增一条申请流程记录 { Traning_ApplyApplication apply = new Traning_ApplyApplication(); apply.TraningId = model.Id; apply.Status = 1; apply.Remark = "提交审核"; apply.Creater = model.Creater; apply.OrganId = model.OrganId; apply.Delflag = false; apply.CreateDate = DateTime.Now; bll.AddTrainingApply(apply); } trans.Complete(); return RedirectToAction("List"); } catch (Exception) { TempData["Msg"] = "保存失败!"; return View(model); } } }
/// <summary> /// 获取数据集 /// </summary> /// <param name="where"></param> /// <param name="orderBy"></param> /// <returns></returns> public List<Traning_Detail> GetList(string where, string orderBy) { StringBuilder sql = new StringBuilder(); sql.Append("select * from [dbo].[Traning_Detail]"); if (!string.IsNullOrEmpty(where)) sql.Append(" where " + where); if (!string.IsNullOrEmpty(orderBy)) sql.Append(" order by " + orderBy); List<Traning_Detail> list = new List<Traning_Detail>(); using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString())) { while (reader.Read()) { Traning_Detail model = new Traning_Detail(); ConvertToModel(reader, model); list.Add(model); } } return list; }
private void ConvertToModel(IDataReader reader, Traning_Detail 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["Pic"] != DBNull.Value) model.Pic = reader["Pic"].ToString(); if (reader["Creater"] != DBNull.Value) model.Creater = Convert.ToInt32(reader["Creater"]); if (reader["OrganId"] != DBNull.Value) model.OrganId = Convert.ToInt32(reader["OrganId"]); if (reader["TraingField"] != DBNull.Value) model.TraingField = Convert.ToInt32(reader["TraingField"]); if (reader["TraingCategory"] != DBNull.Value) model.TraingCategory = Convert.ToInt32(reader["TraingCategory"]); if (reader["TraingTopic"] != DBNull.Value) model.TraingTopic = Convert.ToInt32(reader["TraingTopic"]); if (reader["TraningObject"] != DBNull.Value) model.TraningObject = reader["TraningObject"].ToString(); if (reader["Subject"] != DBNull.Value) model.Subject = reader["Subject"].ToString(); if (reader["StudyLevel"] != DBNull.Value) model.StudyLevel = reader["StudyLevel"].ToString(); if (reader["TotalTime"] != DBNull.Value) model.TotalTime = Convert.ToDouble(reader["TotalTime"]); if (reader["TrainingForm"] != DBNull.Value) model.TrainingForm = Convert.ToInt32(reader["TrainingForm"]); if (reader["TeacherTitle"] != DBNull.Value) model.TeacherTitle = Convert.ToInt32(reader["TeacherTitle"]); if (reader["TeacherName"] != DBNull.Value) model.TeacherName = reader["TeacherName"].ToString(); if (reader["TeacherFrom"] != DBNull.Value) model.TeacherFrom = reader["TeacherFrom"].ToString(); if (reader["TeacherPic"] != DBNull.Value) model.TeacherPic = reader["TeacherPic"].ToString(); if (reader["Outline"] != DBNull.Value) model.Outline = reader["Outline"].ToString(); if (reader["PartitionId"] != DBNull.Value) model.PartitionId = Convert.ToInt32(reader["PartitionId"]); if (reader["OutSideType"] != DBNull.Value) model.OutSideType = Convert.ToInt32(reader["OutSideType"]); if (reader["OutSideLink"] != DBNull.Value) model.OutSideLink = reader["OutSideLink"].ToString(); if (reader["Range"] != DBNull.Value) model.Range = Convert.ToInt32(reader["Range"]); if (reader["Status"] != DBNull.Value) model.Status = Convert.ToInt32(reader["Status"]); if (reader["ApplyRemark"] != DBNull.Value) model.ApplyRemark = reader["ApplyRemark"].ToString(); if (reader["Display"] != DBNull.Value) model.Display = Convert.ToBoolean(reader["Display"]); if (reader["Delflag"] != DBNull.Value) model.Delflag = Convert.ToBoolean(reader["Delflag"]); if (reader["CreateDate"] != DBNull.Value) model.CreateDate = Convert.ToDateTime(reader["CreateDate"]); if (reader["ParentOrganId"] != DBNull.Value) model.ParentOrganId = Convert.ToInt32(reader["ParentOrganId"]); if (reader["OutSideContent"] != DBNull.Value) model.OutSideContent = reader["OutSideContent"].ToString(); if (reader["CanEdit"] != DBNull.Value) model.CanEdit = Convert.ToBoolean(reader["CanEdit"]); if (reader["NationalCoursId"] != DBNull.Value) model.NationalCoursId = Convert.ToInt32(reader["NationalCoursId"]); }
/// <summary> /// 更新一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Update(Traning_Detail model) { StringBuilder sql = new StringBuilder(); sql.Append("update [dbo].[Traning_Detail] set "); sql.Append("[Title]=@Title,[Content]=@Content,[Pic]=@Pic,[Creater]=@Creater,[OrganId]=@OrganId,[TraingField]=@TraingField,[TraingCategory]=@TraingCategory,[TraingTopic]=@TraingTopic,[TraningObject]=@TraningObject,[Subject]=@Subject,[StudyLevel]=@StudyLevel,[TotalTime]=@TotalTime,[TrainingForm]=@TrainingForm,[TeacherTitle]=@TeacherTitle,[TeacherName]=@TeacherName,[TeacherFrom]=@TeacherFrom,[TeacherPic]=@TeacherPic,[Outline]=@Outline,[PartitionId]=@PartitionId,[OutSideType]=@OutSideType,[OutSideLink]=@OutSideLink,[Range]=@Range,[Status]=@Status,[ApplyRemark]=@ApplyRemark,[Display]=@Display,[Delflag]=@Delflag,[CreateDate]=@CreateDate,[ParentOrganId]=@ParentOrganId,[OutSideContent]=@OutSideContent,[CanEdit]=@CanEdit,[NationalCoursId]=@NationalCoursId"); 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("@Pic", SqlDbType.VarChar, 200) { Value = model.Pic }, new SqlParameter("@Creater", SqlDbType.Int, 4) { Value = model.Creater }, new SqlParameter("@OrganId", SqlDbType.Int, 4) { Value = model.OrganId }, new SqlParameter("@TraingField", SqlDbType.Int, 4) { Value = model.TraingField }, new SqlParameter("@TraingCategory", SqlDbType.Int, 4) { Value = model.TraingCategory }, new SqlParameter("@TraingTopic", SqlDbType.Int, 4) { Value = model.TraingTopic }, new SqlParameter("@TraningObject", SqlDbType.VarChar, 500) { Value = model.TraningObject }, new SqlParameter("@Subject", SqlDbType.VarChar, 500) { Value = model.Subject }, new SqlParameter("@StudyLevel", SqlDbType.VarChar, 500) { Value = model.StudyLevel }, new SqlParameter("@TotalTime", SqlDbType.Float, 8) { Value = model.TotalTime }, new SqlParameter("@TrainingForm", SqlDbType.Int, 4) { Value = model.TrainingForm }, new SqlParameter("@TeacherTitle", SqlDbType.Int, 4) { Value = model.TeacherTitle }, new SqlParameter("@TeacherName", SqlDbType.VarChar, 20) { Value = model.TeacherName }, new SqlParameter("@TeacherFrom", SqlDbType.VarChar, 50) { Value = model.TeacherFrom }, new SqlParameter("@TeacherPic", SqlDbType.VarChar, 500) { Value = model.TeacherPic }, new SqlParameter("@Outline", SqlDbType.VarChar, 8000) { Value = model.Outline }, new SqlParameter("@PartitionId", SqlDbType.Int, 4) { Value = model.PartitionId }, new SqlParameter("@OutSideType", SqlDbType.Int, 4) { Value = model.OutSideType }, new SqlParameter("@OutSideLink", SqlDbType.VarChar, 500) { Value = model.OutSideLink }, new SqlParameter("@Range", SqlDbType.Int, 4) { Value = model.Range }, new SqlParameter("@Status", SqlDbType.Int, 4) { Value = model.Status }, new SqlParameter("@ApplyRemark", SqlDbType.VarChar, 500) { Value = model.ApplyRemark }, new SqlParameter("@Display", SqlDbType.Bit, 1) { Value = model.Display }, new SqlParameter("@Delflag", SqlDbType.Bit, 1) { Value = model.Delflag }, new SqlParameter("@CreateDate", SqlDbType.DateTime, 8) { Value = model.CreateDate }, new SqlParameter("@ParentOrganId", SqlDbType.Int, 4) { Value = model.ParentOrganId }, new SqlParameter("@OutSideContent", SqlDbType.VarChar, -1) { Value = model.OutSideContent }, new SqlParameter("@CanEdit", SqlDbType.Bit, 1) { Value = model.CanEdit }, new SqlParameter("@NationalCoursId", SqlDbType.Int, 4) { Value = model.NationalCoursId } }; return MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams); }
public Traning_Detail GetModel(string where) { string sql = "select * from [dbo].[Traning_Detail]"; if (!string.IsNullOrEmpty(where)) sql += " where " + where; using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql)) { if (reader.Read()) { Traning_Detail model = new Traning_Detail(); ConvertToModel(reader, model); return model; } else { return null; } } }
/// <summary> /// 取得一条记录 /// </summary> /// <param name="id"></param> /// <param name="where"></param> /// <returns></returns> public Traning_Detail GetModel(int id, string where) { string sql = "select * from [dbo].[Traning_Detail] 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()) { Traning_Detail model = new Traning_Detail(); 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<Traning_Detail> GetList(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 [dbo].[Traning_Detail]"); 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.Append("select * from (select *,ROW_NUMBER() over (order by " + orderBy + ") as [RowNum] from [dbo].[Traning_Detail]"); if (!string.IsNullOrEmpty(where)) sql.Append(" where " + where); sql.Append(") as T where [RowNum] between " + start + " and " + end); List<Traning_Detail> list = new List<Traning_Detail>(); using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString())) { while (reader.Read()) { Traning_Detail model = new Traning_Detail(); ConvertToModel(reader, model); list.Add(model); } } return list; }
public List<Traning_Detail> GetListHasClass(int pageSize, int pageIndex, string where, string orderBy, out int recordCount) { if (string.IsNullOrEmpty(orderBy)) throw new ArgumentNullException(); StringBuilder s = new StringBuilder(); s.Append(" (select distinct td.* from traning_detail td left join class_detail cd on td.Id=cd.TraningId "); s.Append(" left join Class_StudySection css on cd.Id=css.ClassId "); s.Append(" left join Class_TeachSubject cts on cd.Id=cts.ClassId "); s.Append(" left join Class_TeachGrade ctg on cd.Id=ctg.ClassId "); s.Append(" left join Class_TeachRank ctr on cd.Id=ctr.ClassId "); s.Append(" where td.delflag=0 and td.display=1 and td.Status=5 "); if (!string.IsNullOrEmpty(where)) s.Append(where); s.Append(" and cd.delflag=0 and cd.display=1 and cd.Status=3 ) as tc "); StringBuilder sb = new StringBuilder(); sb.Append("select COUNT(1) from "); sb.Append(s.ToString()); recordCount = Convert.ToInt32(MSEntLibSqlHelper.ExecuteScalarBySql(sb.ToString())); int start = (pageIndex - 1) * pageSize + 1; int end = pageIndex * pageSize; StringBuilder sql = new StringBuilder(); sql.Append("select * from (select *,ROW_NUMBER() over (order by " + orderBy + ") as [RowNum] from " + s); if (pageSize == -1) { sql.Append(") as T"); } else { sql.Append(") as T where [RowNum] between " + start + " and " + end); } List<Traning_Detail> list = new List<Traning_Detail>(); using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString())) { while (reader.Read()) { Traning_Detail model = new Traning_Detail(); ConvertToModel(reader, model); list.Add(model); } } return list; }
/// <summary> /// 更新一条课程记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool UpdateTrainingDetail(Traning_Detail model) { return new Traning_DetailDAL().Update(model) > 0; }
public ActionResult CoursemarketSingleEnrollC(int Id) { ViewBag.Title = "课程详细"; int groupId = Code.SiteCache.Instance.GroupId;//4,学校管理7,普通教师 ViewData["groupId"] = groupId; Traning_DetailBLL traning_DetailBLL = new Traning_DetailBLL(); Traning_Detail traning_Detail = new Traning_Detail(); traning_Detail = traning_DetailBLL.GetModel(Id, ""); return View(traning_Detail); }
/// <summary> /// 新增一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Add(Traning_Detail model) { return dal.Add(model) > 0; }
/// <summary> /// 更新一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Update(Traning_Detail model) { return dal.Update(model) > 0; }
/// <summary> /// 新增一条课程记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool AddTrainingDetail(Traning_Detail model) { return new Traning_DetailDAL().Add(model) > 0; }