/// <summary> /// 获取数据集 /// </summary> /// <param name="where"></param> /// <param name="orderBy"></param> /// <returns></returns> public List<Traning_ApplyApplication> GetList(string where, string orderBy) { StringBuilder sql = new StringBuilder(); sql.Append("select * from [dbo].[Traning_ApplyApplication]"); if (!string.IsNullOrEmpty(where)) sql.Append(" where " + where); if (!string.IsNullOrEmpty(orderBy)) sql.Append(" order by " + orderBy); List<Traning_ApplyApplication> list = new List<Traning_ApplyApplication>(); using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString())) { while (reader.Read()) { Traning_ApplyApplication model = new Traning_ApplyApplication(); ConvertToModel(reader, model); list.Add(model); } } return list; }
/// <summary> /// 新增一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Add(Traning_ApplyApplication model) { StringBuilder sql = new StringBuilder(); sql.Append("insert into [dbo].[Traning_ApplyApplication] ([TraningId],[Status],[Remark],[Creater],[Delflag],[CreateDate],[OrganId])"); sql.Append(" values (@TraningId,@Status,@Remark,@Creater,@Delflag,@CreateDate,@OrganId)"); sql.Append(" set @Id=@@IDENTITY"); SqlParameter[] cmdParams = new SqlParameter[]{ new SqlParameter("@Id", SqlDbType.Int, 4) { Value = model.Id, Direction = ParameterDirection.Output }, new SqlParameter("@TraningId", SqlDbType.Int, 4) { Value = model.TraningId }, new SqlParameter("@Status", SqlDbType.Int, 4) { Value = model.Status }, new SqlParameter("@Remark", SqlDbType.VarChar, 500) { Value = model.Remark }, new SqlParameter("@Creater", SqlDbType.Int, 4) { Value = model.Creater }, new SqlParameter("@Delflag", SqlDbType.Bit, 1) { Value = model.Delflag }, new SqlParameter("@CreateDate", SqlDbType.DateTime, 8) { Value = model.CreateDate }, new SqlParameter("@OrganId", SqlDbType.Int, 4) { Value = model.OrganId } }; 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="model"></param> /// <returns></returns> public bool AddTrainingApply(Traning_ApplyApplication model) { return new Traning_ApplyApplicationDAL().Add(model) > 0; }
//课程审核 public ActionResult AjaxTrainingCheck(int id, string value, string remark) { PrepareTrainingCheckBLL bll = new PrepareTrainingCheckBLL(); Traning_Detail model = bll.GetTrainingDetail(id, "Delflag=0 and Status in (2,4) and PartitionId=" + Code.SiteCache.Instance.LoginInfo.PartitionId); if (model == null) { return Json(new { Result = true, Msg = "记录不存在!" }, JsonRequestBehavior.AllowGet); } if (value == "1")//审核通过 { model.Status = 3; model.ApplyRemark = ""; } else//审核不通过 { model.Status = 4; model.ApplyRemark = remark; } Traning_ApplyApplication apply = new Traning_ApplyApplication(); apply.TraningId = model.Id; apply.Status = Convert.ToInt32(value); apply.Remark = model.ApplyRemark; apply.Creater = Code.SiteCache.Instance.LoginInfo.UserId; apply.OrganId = Code.SiteCache.Instance.ManageOrganId; apply.Delflag = false; apply.CreateDate = DateTime.Now; using (TransactionScope trans = new TransactionScope()) { try { bll.UpdateTrainingDetail(model);//更新课程 bll.AddTrainingApply(apply);//新增一条课程审核记录 trans.Complete(); return Json(new { Result = true, Msg ="操作成功!" }, JsonRequestBehavior.AllowGet); } catch { return Json(new { Result = false, Msg = "操作失败!" }, JsonRequestBehavior.AllowGet); } } }
public ActionResult Check(int id, string checkResult, string unpassRemark) { PrepareTrainingCheckBLL bll = new PrepareTrainingCheckBLL(); Traning_Detail model = bll.GetTrainingDetail(id, "Delflag=0 and Status in (2,4)"); if (model == null) { return Content("<script>setTimeout(function () { window.location.href = '/Prepare/TrainingCheck/List' }, 3000);</script>操作失败,3秒后自动返回到列表!"); } if (checkResult == "1")//审核通过 { model.Status = 3; model.ApplyRemark = null; } else//审核不通过 { if (unpassRemark.Trim() == "") { TempData["Msg"] = "不通过原因不能为空白!"; return Redirect("Check?Id=" + Dianda.Common.QueryString.UrlEncrypt(id)); } model.Status = 4; model.ApplyRemark = unpassRemark.Trim(); } int managerId = Code.SiteCache.Instance.ManagerId; int partitionId = Code.SiteCache.Instance.LoginInfo.PartitionId; Traning_ApplyApplication apply = new Traning_ApplyApplication(); apply.TraningId = model.Id; apply.Status = Convert.ToInt32(checkResult); apply.Remark = model.ApplyRemark; apply.Creater = managerId; apply.OrganId = Code.SiteCache.Instance.ManageOrganId; apply.Delflag = false; apply.CreateDate = DateTime.Now; using (TransactionScope trans = new TransactionScope()) { try { bll.UpdateTrainingDetail(model);//更新课程 bll.AddTrainingApply(apply);//新增一条课程审核记录 string msg = ""; if (model.Status == 3) { msg = string.Format("课程:{0} 审核通过!", model.Title); } else { msg = string.Format("课程:{0} 审核不通过,原因:{1}", model.Title, model.ApplyRemark); } Code.MsgHelper.sendMsg(model.Creater, managerId, partitionId, "审核信息", msg);//新增消息通知 trans.Complete(); return RedirectToAction("List"); } catch { TempData["Msg"] = "操作失败!"; return Redirect("Check?Id=" + Dianda.Common.QueryString.UrlEncrypt(id)); } } }
//批量审核 public ActionResult AjaxTrainingCheckBatch(string ids, string value, string remark) { StringBuilder where = new StringBuilder(); where.Append("Delflag=0 and Status in (2,4) and PartitionId=" + Code.SiteCache.Instance.LoginInfo.PartitionId + " and Id in (" + ids + ")"); int status = value == "1" ? 3 : 4; remark = value == "1" ? "" : remark; int managerId = Code.SiteCache.Instance.ManagerId; List<Traning_ApplyApplication> applies = new List<Traning_ApplyApplication>(); foreach (string id in ids.Split(',')) { Traning_ApplyApplication apply = new Traning_ApplyApplication(); apply.TraningId = Convert.ToInt32(id); apply.Status = Convert.ToInt32(value); apply.Remark = remark; apply.Creater = managerId; apply.OrganId = Code.SiteCache.Instance.ManageOrganId; apply.Delflag = false; apply.CreateDate = DateTime.Now; applies.Add(apply); } List<Traning_Detail> trainings = new Traning_DetailBLL().GetList("Id in (" + ids + ")", ""); using (TransactionScope trans = new TransactionScope()) { try { int partitionId = Code.SiteCache.Instance.LoginInfo.PartitionId; string msg; foreach (Traning_Detail training in trainings) { if (status == 3) { msg = string.Format("课程:{0} 审核通过!", training.Title); } else { msg = string.Format("课程:{0} 审核不通过,原因:{1}", training.Title, remark); } Code.MsgHelper.sendMsg(training.Creater, managerId, partitionId, "审核信息", msg); } new PrepareTrainingCheckBLL().BatchTrainingApply(where.ToString(), status, remark, applies); trans.Complete(); return Json(new { Result = true, Msg = "操作成功!" }, JsonRequestBehavior.AllowGet); } catch { return Json(new { Result = false, Msg = "操作失败!" }, JsonRequestBehavior.AllowGet); } } }
/// <summary> /// 更新一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Update(Traning_ApplyApplication model) { return dal.Update(model) > 0; }
/// <summary> /// 新增一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Add(Traning_ApplyApplication model) { return dal.Add(model) > 0; }
/// <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_ApplyApplication> 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_ApplyApplication]"); 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_ApplyApplication]"); if (!string.IsNullOrEmpty(where)) sql.Append(" where " + where); sql.Append(") as T where [RowNum] between " + start + " and " + end); List<Traning_ApplyApplication> list = new List<Traning_ApplyApplication>(); using (IDataReader reader = MSEntLibSqlHelper.ExecuteDataReaderBySql(sql.ToString())) { while (reader.Read()) { Traning_ApplyApplication model = new Traning_ApplyApplication(); ConvertToModel(reader, model); list.Add(model); } } return list; }
private void ConvertToModel(IDataReader reader, Traning_ApplyApplication model) { if (reader["Id"] != DBNull.Value) model.Id = Convert.ToInt32(reader["Id"]); if (reader["TraningId"] != DBNull.Value) model.TraningId = Convert.ToInt32(reader["TraningId"]); if (reader["Status"] != DBNull.Value) model.Status = Convert.ToInt32(reader["Status"]); if (reader["Remark"] != DBNull.Value) model.Remark = reader["Remark"].ToString(); if (reader["Creater"] != DBNull.Value) model.Creater = Convert.ToInt32(reader["Creater"]); if (reader["Delflag"] != DBNull.Value) model.Delflag = Convert.ToBoolean(reader["Delflag"]); if (reader["CreateDate"] != DBNull.Value) model.CreateDate = Convert.ToDateTime(reader["CreateDate"]); if (reader["OrganId"] != DBNull.Value) model.OrganId = Convert.ToInt32(reader["OrganId"]); }
/// <summary> /// 更新一条记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public int Update(Traning_ApplyApplication model) { StringBuilder sql = new StringBuilder(); sql.Append("update [dbo].[Traning_ApplyApplication] set "); sql.Append("[TraningId]=@TraningId,[Status]=@Status,[Remark]=@Remark,[Creater]=@Creater,[Delflag]=@Delflag,[CreateDate]=@CreateDate,[OrganId]=@OrganId"); sql.Append(" where [Id]=@Id"); SqlParameter[] cmdParams = new SqlParameter[] { new SqlParameter("@Id", SqlDbType.Int, 4) { Value = model.Id }, new SqlParameter("@TraningId", SqlDbType.Int, 4) { Value = model.TraningId }, new SqlParameter("@Status", SqlDbType.Int, 4) { Value = model.Status }, new SqlParameter("@Remark", SqlDbType.VarChar, 500) { Value = model.Remark }, new SqlParameter("@Creater", SqlDbType.Int, 4) { Value = model.Creater }, new SqlParameter("@Delflag", SqlDbType.Bit, 1) { Value = model.Delflag }, new SqlParameter("@CreateDate", SqlDbType.DateTime, 8) { Value = model.CreateDate }, new SqlParameter("@OrganId", SqlDbType.Int, 4) { Value = model.OrganId } }; return MSEntLibSqlHelper.ExecuteNonQueryBySql(sql.ToString(), cmdParams); }
/// <summary> /// 取得一条记录 /// </summary> /// <param name="id"></param> /// <param name="where"></param> /// <returns></returns> public Traning_ApplyApplication GetModel(int id, string where) { string sql = "select * from [dbo].[Traning_ApplyApplication] 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_ApplyApplication model = new Traning_ApplyApplication(); ConvertToModel(reader, model); return model; } else { return null; } } }
/// <summary> /// 更新一条审核记录 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool UpdateTrainingApply(Traning_ApplyApplication model) { return new Traning_ApplyApplicationDAL().Update(model) > 0; }