168 lines
6.7 KiB
C#
168 lines
6.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Web.Mvc;
|
|
using WX.CRM.Common;
|
|
using WX.CRM.IBLL.Soft;
|
|
using WX.CRM.WebHelper;
|
|
|
|
namespace WX.CRM.WEB.Controllers.Soft
|
|
{
|
|
public class SoftProductController : BaseController
|
|
{
|
|
//
|
|
// GET: /Product/
|
|
|
|
private readonly ISOFT_ACTIVE _product;
|
|
private readonly ISOFT_ACTIVE_Q _product_q;
|
|
ValidationErrors errors = new ValidationErrors();
|
|
public SoftProductController(
|
|
ISOFT_ACTIVE product,
|
|
ISOFT_ACTIVE_Q product_q
|
|
)
|
|
{
|
|
this._product = product;
|
|
this._product_q = product_q;
|
|
}
|
|
[AuthorizeRedirect(Roles = InitRights.CONST_产品活动列表)]
|
|
public ActionResult Index()
|
|
{
|
|
//ToolBar
|
|
ToolBar tool = new ToolBar();
|
|
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.产品活动列表, userRightId);
|
|
tool.AllowButton(toolbtn);
|
|
// tool.AllowButton("Create", "Edit");
|
|
ViewBag.ToolBar = tool;
|
|
//table
|
|
//Pager pager = new Pager() { page = 1, rows = 10 };
|
|
string tableId = "tablist";
|
|
Table tab = new Table(tableId);
|
|
tab.AddHiddenHeadCol("pkid", "ID");
|
|
tab.AddHeadCol("Map_PRODUCTNAME", "12%", "产品名称");
|
|
tab.AddHeadCol("Map_PRODUCTCODE", "12%", "产品编码");
|
|
tab.AddHeadCol("Map_ISSHOW", "12%", "是否显示");
|
|
tab.AddHeadCol("Map_MEMO", "13%", "备注");
|
|
tab.AddHeadCol("Map_CTIME", "12%", "创建时间");
|
|
tab.AddHeadCol("Map_CREATEUSER", "12%", "创建人");
|
|
tab.AddHeadCol("Map_UTIME", "12%", "修改时间");
|
|
tab.AddHeadCol("Map_UPDATEUSER", "", "修改人");
|
|
tab.AddHeadRow();
|
|
ViewBag.List = tab.GetTable();
|
|
|
|
return View();
|
|
}
|
|
[HttpPost]
|
|
/// <summary>
|
|
/// 按照条件获取数据
|
|
/// </summary>
|
|
/// <param name="pager"></param>
|
|
/// <param name="queryStr"></param>
|
|
/// <returns></returns>
|
|
[AuthorizeRedirect(Roles = InitRights.CONST_产品活动列表)]
|
|
public JsonResult GetHtmlList(string productName, string productCode, string columns)
|
|
{
|
|
try
|
|
{
|
|
List<WX.CRM.Model.Entity.SOFT_ACTIVE> list = _product_q.GetPRODUCTList(productName, productCode);
|
|
Table table = new Table(columns, true);
|
|
//table.gridPager = pager;
|
|
foreach (WX.CRM.Model.Entity.SOFT_ACTIVE model in list)
|
|
{
|
|
table.AddHiddenCol(model.PRODUCTID);
|
|
table.AddCol(model.PRODUCTNAME);
|
|
table.AddCol(model.PRODUCTCODE);
|
|
table.AddCol(model.Map_ISSHOW.ToString() == "1" ? "是" : "否");
|
|
table.AddCol(model.Map_MEMO);
|
|
table.AddCol(model.Map_CTIME);
|
|
table.AddCol(InnerUserHelper.Instance.EidAndName(model.Map_CREATEUSER));
|
|
table.AddCol(model.Map_UTIME);
|
|
table.AddCol(InnerUserHelper.Instance.EidAndName(model.Map_UPDATEUSER));
|
|
table.AddRow();
|
|
}
|
|
var json = new
|
|
{
|
|
rowsList = table.GetRows()
|
|
};
|
|
return Json(json, JsonRequestBehavior.AllowGet);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error("SoftProductController_GetHtmlList:" + ex.Message + ex.StackTrace);
|
|
return JsonHandler.ManageMessage(ex.Message, false);
|
|
}
|
|
}
|
|
#region 编辑
|
|
[HttpGet]
|
|
[AuthorizeToolBar(InitRights.CONST_产品活动列表, InitToolBar.CONST_Edit)]
|
|
public ActionResult Edit(string id)
|
|
{
|
|
WX.CRM.Model.Entity.SOFT_ACTIVE model = null;
|
|
if (!string.IsNullOrEmpty(id))
|
|
{
|
|
model = _product_q.GetPRODUCTById(Convert.ToDecimal(id));
|
|
}
|
|
return View(model);
|
|
}
|
|
[HttpPost]
|
|
[AuthorizeToolBar(InitRights.CONST_产品活动列表, InitToolBar.CONST_Edit)]
|
|
public JsonResult Edit(WX.CRM.Model.Entity.SOFT_ACTIVE model, string moduleProduct)
|
|
{
|
|
try
|
|
{
|
|
var modulelist = JsonHelper.JsonDivertToObj<List<ModuleCommit>>(moduleProduct);
|
|
var moduleProductList = new List<WX.CRM.Model.Entity.SOFT_ACTIVEMODULE>();
|
|
foreach (var module in modulelist)
|
|
{
|
|
int days;
|
|
if (int.TryParse(module.Map_DAYS, out days))
|
|
{
|
|
WX.CRM.Model.Entity.SOFT_ACTIVEMODULE soft_productmodule = new WX.CRM.Model.Entity.SOFT_ACTIVEMODULE();
|
|
soft_productmodule.Map_CREATEUSER = UserId;
|
|
soft_productmodule.Map_CTIME = DateTime.Now;
|
|
soft_productmodule.Map_UPDATEUSER = UserId;
|
|
soft_productmodule.Map_UTIME = DateTime.Now;
|
|
soft_productmodule.Map_MODULEID = Convert.ToDecimal(module.Map_MODULEID);
|
|
soft_productmodule.Map_DAYS = days;
|
|
moduleProductList.Add(soft_productmodule);
|
|
}
|
|
else
|
|
{
|
|
ModelState.AddModelError("module" + module.Map_MODULEID, "请输入数字");
|
|
}
|
|
}
|
|
if (!ModelState.IsValid)
|
|
{
|
|
|
|
return JsonHandler.JsonResultSerialize(ModelState);
|
|
}
|
|
|
|
if (model.Map_PRODUCTID == 0)
|
|
{
|
|
model.Map_CREATEUSER = UserId;
|
|
model.Map_CTIME = DateTime.Now;
|
|
bool result = _product.CreateTrans(ref errors, model, moduleProductList);
|
|
return JsonHandler.InsertMessage(errors, result);
|
|
}
|
|
else
|
|
{
|
|
model.Map_UTIME = DateTime.Now;
|
|
model.Map_UPDATEUSER = UserId;
|
|
bool result = _product.UpdateTrans(ref errors, model, moduleProductList);
|
|
return JsonHandler.UpdateMessage(errors, result);
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
LogHelper.Error("SoftProductController_Edit:" + ex.Message + ex.StackTrace);
|
|
return JsonHandler.ManageMessage(ex.Message, false);
|
|
}
|
|
}
|
|
#endregion
|
|
public class ModuleCommit
|
|
{
|
|
public string Map_MODULEID { get; set; }
|
|
public string Map_DAYS { get; set; }
|
|
}
|
|
}
|
|
}
|