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.

196 lines
8.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.Mvc;
using DSWeb.SoftMng.BLL;
using DSWeb.SoftMng.Model;
namespace DSWeb.SoftMng.Controllers
{
public class EmailSchemeController: Controller
{
private readonly t_code_cust_mailprojectBLL _bll = new t_code_cust_mailprojectBLL();
private readonly t_code_cust_mailproject_detailBLL _tbll = new t_code_cust_mailproject_detailBLL();
#region View
/// <summary>
/// 首页
/// </summary>
/// <returns></returns>
//[ModuleAuthFilter(Name = "secRegist")]//过滤器
public ActionResult Index()
{
if (Session["CODENAME"] == null)
Response.Redirect("/login.aspx");
return View();
}
#endregion
#region Handler
/// <summary>
/// 获取列表
/// </summary>
/// <returns></returns>
public JsonResult GetList(int startIndex, int limit, string search)
{
StringBuilder where = new StringBuilder();
where.Append("1=1");
if (!(String.IsNullOrEmpty(search) || String.IsNullOrWhiteSpace(search)))
where.Append(string.Format(" And ([方案名称] like '%{0}%' OR [客户名称] like '%{0}%')", search));
var list = _bll.GetModelList(startIndex, limit, where.ToString(), "[方案代码] ASC");
var result = from p in list
select new
{
f = p.,
k = p.,
k_Text=p.,
t = p.,
d = p.,
r = p.
};
var count = _bll.GetRecordCount(where.ToString());//总数
return Json(new { total = count, rows = result });
}
public JsonResult GetDetailList(int id)
{
StringBuilder where = new StringBuilder();
where.Append("[方案代码] = {0}");
var list = _tbll.GetModelList(string.Format(where.ToString(), id));
var result = from p in list
select new
{
p.DE_ID,
f = p.,
p = p.,
p_Text=p.,
s = p.,
x = p.,
y = p.,
z = p.
};
return Json(result);
}
/// <summary>
/// 保存主实例
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public JsonResult Save(t_code_cust_mailproject model)
{
bool result;
model. = Convert.ToInt32(Request["f"] == "" ? "0" : Request["f"]);
if (model.==0)
{
model. = Request["t"];
model. = Request["k"];
model. = Request["r"];
model. = Convert.ToBoolean(Request["d"]);
model. = Session["SHOWNAME"].ToString();
model. = DateTime.Now;
result = _bll.Add(model) > 0;
} //新增
else
{
//类反射
var oldModel = _bll.GetModel(model.);
Type type = typeof(t_code_cust_mailproject);
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. = Request["t"];
model. = Request["k"];
model. = Request["r"];
model. = Convert.ToBoolean(Request["d"]);
result = _bll.Update(model) > 0;
} //修改
return Json(new { success = result, message = result ? "操作成功" : "操作失败" });
}
/// <summary>
/// 保存主实例
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public JsonResult SaveDetail(t_code_cust_mailproject_detail model)
{
bool result;
if (model.DE_ID == 0)
{
model. = Convert.ToInt32(Request["f"] == "" ? "0" : Request["f"]);
model. = Request["p"];
model. = Request["s"];
model. = Request["x"];
model. = Request["y"];
model. = Request["z"];
result = _tbll.Add(model) > 0;
} //新增
else
{
//类反射
var oldModel = _tbll.GetModel(model.DE_ID);
Type type = typeof(t_code_cust_mailproject_detail);
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. = Request["p"];
model. = Request["s"];
model. = Request["x"];
model. = Request["y"];
model. = Request["z"];
result = _tbll.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("[方案代码] in({0})", ids)) > 0;
return Json(new { success = result, message = result ? "操作成功" : "操作失败" });
}
/// <summary>
/// 删除
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public JsonResult DeleteDetail(string ids)
{
bool result = _tbll.DeleteListWhere(string.Format("[DE_ID] in({0})", ids)) > 0;
return Json(new { success = result, message = result ? "操作成功" : "操作失败" });
}
/// <summary>
/// 获取单据类型
/// </summary>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="query"></param>
/// <returns></returns>
public JsonResult GetDocType(int pageIndex, int pageSize, string query)
{
tSysEnumValueBLL ibll = new tSysEnumValueBLL();
StringBuilder where = new StringBuilder();
where.Append("EnumTypeID='8000'");
if (!String.IsNullOrEmpty(query))
where.Append(string.Format("EnumValueName LIKE '%{0}%' OR EnumValueID LIKE '%{0}%' ", query));
var list = ibll.GetModelList(pageIndex, pageSize, where.ToString(), "EnumValueName collate Chinese_PRC_CS_AS_KS_WS");
var total = ibll.GetRecordCount(where.ToString());
var result = from p in list
select new
{
id = p.EnumValueName,
text = p.EnumValueName
};
return Json(new { data = result, total }, JsonRequestBehavior.AllowGet);
}
#endregion
}
}