using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Web; using System.Web.Mvc; using DSWeb.SoftMng.BLL; using DSWeb.SoftMng.DBUtility; using DSWeb.SoftMng.Model; using DSWeb.SoftMng.Filter; using System.Text; // ReSharper disable once CheckNamespace namespace DSWeb.SoftMng.Controllers { public class ProjectManagementController : Controller { private readonly op_softprojectBLL _bll = new op_softprojectBLL(); private readonly op_softproject_remarkBLL _remarkBll = new op_softproject_remarkBLL(); #region View /// /// 首页 /// /// public ActionResult Index() { if (Session["CODENAME"] == null) Response.Redirect("/login.aspx"); ViewData["CODENAME"] = Session["CODENAME"]; ViewData["SHOWNAME"] = Session["SHOWNAME"]; return View(); } #endregion #region Handler /// /// 获取列表 /// /// 开始索引 /// 分页大小 /// 搜索框的值 /// 排序字段 /// 排序方式 /// 处理情况 /// 当前角色 /// [SqlKeyWordsFilter(Type = "Action")]//sql 防注入过滤器 public JsonResult GetList(int startIndex, int limit, string search, string sortName, string sortOrder, string status, string character) { StringBuilder where = new StringBuilder(); where.Append("1=1"); if (!(String.IsNullOrEmpty(search) || String.IsNullOrWhiteSpace(search))) where.Append(string.Format(" And PROJECTNAME like '%{0}%' OR BSNO like '%{0}%'", search)); if (!String.IsNullOrEmpty(character)) where.Append(string.Format(" And INPUTBY = '{0}'", character)); //单独查询 各类别数量 Dictionary dict = new Dictionary(); string[] arr = { "", "0", "1", "2", "3", "4", "5" }; for (int i = 0; i < arr.Length; i++) dict.Add(i.ToString(), _bll.GetRecordCount(where + (arr[i] == "" ? "" : string.Format(" And BSSTATUS = {0}", arr[i])))); if (!String.IsNullOrEmpty(status)) where.Append(string.Format(" And BSSTATUS = {0}", status)); var list = _bll.GetModelList(startIndex, limit, where.ToString(), String.Format("{0} {1}", sortName, sortOrder)); var count = _bll.GetRecordCount(where.ToString());//总数 return Json(new { total = count, groupTotal = dict, rows = list }); } /// /// 保存 /// /// /// public JsonResult Save(Model.op_softproject model) { bool result; var nowDate = DateTime.Now; if (String.IsNullOrEmpty(model.GID)) { int num = _bll.GetRecordCount("") + 1; //编号 model.GID = Guid.NewGuid().ToString(); model.BSNO = "DSXM" + nowDate.ToString("yy") + num.ToString().PadLeft(5, '0'); model.INPUTBY = Session["SHOWNAME"].ToString(); model.INPUTTIME = DateTime.Now; result = _bll.Add(model) > 0; } //新增 else { //获取原数据 var oldModel = _bll.GetModel(model.GID); //类反射 Type type = typeof(Model.op_softproject); PropertyInfo[] piArr = type.GetProperties(); foreach (var pi in piArr) { if (Array.IndexOf(Request.Params.AllKeys, pi.Name) < 0) pi.SetValue(model, pi.GetValue(oldModel, null), null); } model.MODIFYBY = Session["SHOWNAME"].ToString(); model.MODIFYEDTIME = DateTime.Now; result = _bll.Update(model) > 0; } //修改 return Json(new { success = result, message = result ? "操作成功" : "操作失败" }); } /// /// 删除 /// /// /// public JsonResult Delete(string ids) { bool result = _bll.DeleteListWhere(string.Format("GID in({0})", ids)) > 0; return Json(new { success = result, message = result ? "操作成功" : "操作失败" }); } #endregion #region 备忘 [HttpPost] public JsonResult SaveRemark(Model.op_softproject_remark model) { bool result; var nowDate = DateTime.Now; model.GID = Guid.NewGuid().ToString(); model.INPUTBY = Session["SHOWNAME"].ToString(); model.INPUTTIME = DateTime.Now; result = _remarkBll.Add(model) > 0; return Json(new { success = result, message = result ? "操作成功" : "操作失败" }); } public JsonResult GetRemarkList(int startIndex, int limit, string search, string sortName, string sortOrder) { StringBuilder where = new StringBuilder(); where.Append("1=1"); if (!(String.IsNullOrEmpty(search) || String.IsNullOrWhiteSpace(search))) where.Append(string.Format(" And PROJECTID = '{0}'", search)); var list = _remarkBll.GetModelList(startIndex, limit, where.ToString(), sortName + " " + sortOrder); var count = _remarkBll.GetRecordCount(where.ToString());//总数 return Json(new { total = count, rows = list }); } #endregion } }