You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
5.9 KiB
C#

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
/// <summary>
/// 首页
/// </summary>
/// <returns></returns>
public ActionResult Index()
{
if (Session["CODENAME"] == null)
Response.Redirect("/login.aspx");
ViewData["CODENAME"] = Session["CODENAME"];
ViewData["SHOWNAME"] = Session["SHOWNAME"];
return View();
}
#endregion
#region Handler
/// <summary>
/// 获取列表
/// </summary>
/// <param name="startIndex">开始索引</param>
/// <param name="limit">分页大小</param>
/// <param name="search">搜索框的值</param>
/// <param name="sortName">排序字段</param>
/// <param name="sortOrder">排序方式</param>
/// <param name="status">处理情况</param>
/// <param name="character">当前角色</param>
/// <returns></returns>
[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<string, int> dict = new Dictionary<string, int>();
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 });
}
/// <summary>
/// 保存
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
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 ? "操作成功" : "操作失败" });
}
/// <summary>
/// 删除
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
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
}
}