Mini.Crm/Mini.Web/Areas/Admin/Controllers/BasParameterController.cs

180 lines
7.7 KiB
C#

using Mini.Common;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Mini.Web.Areas.Admin.Controllers
{
public class BasParameterController : BaseController
{
private readonly IBas_ParameterService _basParameterService;
private readonly IBasInnerUserService _basInnerUserService;
private readonly IBas_ParameterGroupService _basParameterGroupService;
private ValidationErrors errors = new ValidationErrors();
public BasParameterController(IBas_ParameterService basParameterService,IBasInnerUserService basInnerUserService,IBas_ParameterGroupService basParameterGroupService)
{
this._basParameterService = basParameterService;
this._basInnerUserService = basInnerUserService;
this._basParameterGroupService = basParameterGroupService;
}
[AuthorizeRedirect(Roles =InitRights.CONST_参数配置)]
public ActionResult Index()
{
ToolBar tool = new ToolBar();
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights., userRightId);
tool.AllowButton(toolbtn);
ViewBag.ToolBar = tool;
Pager gp = new Pager() { page = 1, rows = 10 };
Table tab = new Table("tablist");
tab.AddHiddenHeadCol("PKID", "ID");
tab.AddHeadCol("paraKey", "", "参数键");
tab.AddHeadCol("paraName", "", "参数名");
tab.AddHeadCol("groupName", "", "参数分组");
tab.AddHeadCol("paraValue", "150px", "参数值");
tab.AddHeadCol("paraType", "", "参数类型");
tab.AddHeadCol("DEPTCDOE", "", "营业部");
tab.AddHeadCol("remark", "150px", "备注");
tab.AddHeadCol("url", "120px", "编辑页面");
tab.AddHeadCol("ctime", "75px", "创建时间");
tab.AddHeadCol("creatUser", "", "创建人");
tab.AddHeadCol("utime", "75px", "修改时间");
tab.AddHeadCol("updateUser", "", "修改人");
tab.AddHeadRow();
List<SelectListItem> selectList = new List<SelectListItem>();
selectList.Add(new SelectListItem { Text = "---请选择--", Value = "0" });
List<Bas_ParameterGroup> parameterGroup = _basParameterGroupService.GetListAll();
foreach (Bas_ParameterGroup bpg in parameterGroup)
{
selectList.Add(new SelectListItem { Text = bpg.GroupName, Value = bpg.GroupId });
}
ViewBag.SelectList = selectList;
ViewBag.GroupList = tab.GetTable() + Pagination.GetPage(gp, "tablist", "5,8,10,15");
return View();
}
#region
public JsonResult GetHtmlList(Pager gp, string columns)
{
string groupId = Request.Form["GroupId"];
string parakey = Request.Form["ParaKey"];
string paraName = Request.Form["ParaName"];
string paraValue = Request.Form["ParaValue"];
string paraType = Request.Form["ParaType"];
string stime = Request.Form["STime"];
string etime = Request.Form["ETime"];
List<Bas_Parameter> list = _basParameterService.GetList(ref gp, parakey, paraName, paraValue, paraType, groupId, stime, etime);
Table tb = new Table(columns, true);
tb.gridPager = gp;
foreach (Bas_Parameter model in list)
{
tb.AddHiddenCol(model.PKID);
tb.AddCol(model.ParaKey);
tb.AddCol(model.ParaName);
tb.AddCol(_basParameterGroupService.Get(model.GroupId).GroupName);
tb.AddCol(model.ParaValue);
tb.AddCol(model.ParaType);
tb.AddCol(model.DeptCode);
tb.AddCol(model.Remark);
tb.AddCol(model.EditForm);
tb.AddCol(model.Ctime);
tb.AddCol(_basInnerUserService.GetBasInnerUser(model.CreateUser).uname);
tb.AddCol(model.Utime);
tb.AddCol(_basInnerUserService.GetBasInnerUser(model.UpdateUser).uname);
tb.AddRow();
}
var json = new
{
totalPages = gp.totalPages,
totalRows = gp.totalRows,
rowsList = tb.GetRows()
};
return Json(json, JsonRequestBehavior.AllowGet);
}
#endregion
#region
[AuthorizeToolBar(InitRights.CONST_参数配置, InitToolBar.CONST_Details)]
public ActionResult Details(int pkid)
{
Bas_Parameter bp =_basParameterService.Get(pkid);
Bas_ParameterView model = new Bas_ParameterView()
{
CreateUser = bp.CreateUser,
CreateUserName = _basInnerUserService.GetBasInnerUser(bp.CreateUser).uname,
Ctime = bp.Ctime,
DeptCode = bp.DeptCode,
EditForm = bp.EditForm,
GroupId = bp.GroupId,
GroupName = _basParameterGroupService.Get(bp.GroupId).GroupName,
ParaKey = bp.ParaKey,
ParaName = bp.ParaName,
ParaType = bp.ParaType,
ParaValue = bp.ParaValue,
PKID = bp.PKID,
Remark = bp.Remark,
UpdateUser = bp.UpdateUser,
UpdateUserName = _basInnerUserService.GetBasInnerUser(bp.UpdateUser).uname,
Utime = bp.Utime
};
return View(model);
}
#endregion
#region
#region
[HttpGet]
[AuthorizeToolBar(InitRights.CONST_参数配置, InitToolBar.CONST_Edit)]
public ActionResult Edit(string pkid)
{
Bas_Parameter model = new Bas_Parameter();
if (pkid !=null)
{
model = _basParameterService.Get(Convert.ToInt32(pkid));
}
List<Bas_ParameterGroup> parameterGroup = _basParameterGroupService.GetListAll();
List<SelectListItem> selectlistItem = parameterGroup.Select(m => new SelectListItem() { Text = m.GroupName, Value = m.GroupId.ToString() }).ToList();
ViewBag.ParameterGroupList = selectlistItem;
return View(model);
}
#endregion
#region /
[HttpPost]
[AuthorizeToolBar(InitRights.CONST_参数配置, InitToolBar.CONST_Edit)]
public JsonResult Edit(Bas_Parameter model)
{
if (ModelState.IsValid)
{
string op = Request.Form["hid_option"];
if (op == "add")
{
model.Ctime = DateTime.Now;
model.Utime = DateTime.Now;
model.CreateUser = UserId;
model.UpdateUser = UserId;
model.DeptCode = "技术部";
return JsonHandler.InsertMessage(errors,_basParameterService.Create(model, ref errors));
}
else
{
model.UpdateUser = UserId;
model.Utime = DateTime.Now;
return JsonHandler.UpdateMessage(errors, _basParameterService.Update(model, ref errors));
}
}
else
{
return JsonHandler.ValidateFailMessage();
}
}
#endregion
#endregion
#region
[AuthorizeToolBar(InitRights.CONST_参数配置, InitToolBar.CONST_Delete)]
public JsonResult Delete(string pkid)
{
return JsonHandler.DeleteMessage(errors, _basParameterService.Delete(Convert.ToInt32(pkid),ref errors));
}
#endregion
}
}