using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QMAPP.Common.Web.Controllers;
using QMFrameWork.WebUI.Attribute;
using QMAPP.MD.Web.Models;
using QMAPP.MD.Entity;
using QMAPP.ServicesAgent;
using QMFrameWork.Data;
using QMAPP.Entity;
using QMFrameWork.WebUI.DataSource;
using QMFrameWork.Common.Serialization;
using QMAPP.FJC.Entity.Basic;
using QMAPP.Entity.Sys;
using QMAPP.MD.Web.Models.Sys;
namespace QMAPP.MD.Web.Controllers
{
///
/// 模 块:逻辑矩阵
/// 作 者:郭兆福
/// 时 间:2018年04月20日
///
public class UserWithMachineController : QController
{
#region 获取列表
///
/// 加载列表
///
/// 结果
[HandleException]
public ActionResult List(bool? callBack)
{
UserWithMachineModel seachModel = new UserWithMachineModel();
if (callBack == true)
TryGetSelectBuffer(out seachModel);
seachModel.rownumbers = false;
seachModel.url = "/UserWithMachine/GetList";
return View("UserWithMachineList", seachModel);
}
///
/// 获取列表
///
/// 是否回调
/// 列表
[HandleException]
public ActionResult GetList(bool? callBack)
{
UserWithMachineModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
UserWithMachine condition = null;
DataResult pageResult = new DataResult();
try
{
//获取查询对象
seachModel = GetModel();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel(seachModel);
#region wcf服务统一接口
pageResult = wcfAgent.InvokeServiceFunction>("UserWithMachineBLL_GetList", condition, page);
if (pageResult.IsSuccess == false)
{
SetMessage(pageResult.Msg);
return List(true);
}
DateGridResult result = new DateGridResult();
result.Total = pageResult.Result.RecordCount;
result.Rows = JsonConvertHelper.GetDeserialize>(pageResult.Result.Result.ToString());
#endregion
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 编辑载入
///
/// 编辑载入
///
/// 处理结果
[HandleException]
public ActionResult Edit()
{
UserWithMachineModel model = new UserWithMachineModel();
string ID = Request.Params["USERID"];
UserWithMachine Entity = new UserWithMachine();
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
if (string.IsNullOrEmpty(ID) == false)
{
//修改获取原数据
Entity.USERID = ID;
result = wcfAgent.InvokeServiceFunction>("UserWithMachineBLL_Get", Entity);
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return View("UserWithMachineEdit", model);
}
model = CopyToModel(result.Result);
return View("UserWithMachineEdit", model);
}
else
{
return View("UserWithMachineAdd", model);
}
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 保存添加
///
/// 保存
///
///
/// 处理结果
[HttpPost]
[HandleException]
[ValidateInput(false)]
public ActionResult UserWithMachineSave(UserWithMachineModel saveModel)
{
MachineInfo condition = new MachineInfo();
UserWithMachine Entity = new UserWithMachine();
DataResult result = new DataResult();
ServiceAgent wcfAgent = this.GetServiceAgent();
//if (string.IsNullOrEmpty(saveModel.EDITFLAG) == false)
//{
// UserWithMachineModel newuserInfo = new UserWithMachineModel();
// newuserInfo.USERID = saveModel.USERID;
// newuserInfo.EDITFLAG = saveModel.EDITFLAG;
// this.EditDelete(newuserInfo);
//}
string machineid = "('" + saveModel.MachineIds.Replace(";", "','") + "')";
condition.PIDS = machineid;
//获取设备信息
List machinelist = wcfAgent.InvokeServiceFunction>("UserWithMachineBLL_GetMachineList", condition);
//用户ID
Entity.USERID = saveModel.USERID;
result = wcfAgent.InvokeServiceFunction>("UserWithMachineBLL_InsertUserWithMachine", Entity, machinelist);
return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();", AppResource.SaveMessge));
}
#endregion
#region 主列表界面点击删除
///
/// 主列表界面点击删除
///
/// 结果
[HttpPost]
[HandleException]
public ActionResult Delete(UserWithMachineModel deleteMode)
{
string ids = Request.Form["selectKey"];
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
deleteMode.USERID = ids;
DataResult Searcchresult = new DataResult();
Searcchresult = wcfAgent.InvokeServiceFunction>("UserWithMachineBLL_Get", deleteMode);
if (Searcchresult.Result != null)
{
deleteMode = CopyToModel(Searcchresult.Result);
try
{
result = wcfAgent.InvokeServiceFunction>("UserWithMachineBLL_Delete", deleteMode.USERID);
}
catch (Exception ex)
{
throw ex;
}
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return List(true);
}
}
SetMessage(AppResource.DeleteMessage);
return List(true);
}
#endregion
#region 编辑时删除&编辑后点击保存按钮时删除
///
/// 编辑时删除&编辑后点击保存按钮时删除
///
/// 结果
[HttpPost]
[HandleException]
public ActionResult EditDelete(UserWithMachineModel saveMode)
{
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
result = wcfAgent.InvokeServiceFunction>("UserWithMachineBLL_EditDelete", saveMode);
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return Edit();
}
SetMessage(AppResource.DeleteMessage);
return Edit();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取用户信息列表
///
/// 获取用户信息列表
///
/// 是否回调
/// 用户信息列表
[HandleException]
public ActionResult GetUserList(bool? callBack)
{
UserModel seachModel = new UserModel();
DataPage page = new DataPage();
ServiceAgent wcfAgent = this.GetServiceAgent();
User condition = null;
try
{
//获取查询对象
seachModel.ActivateFlg = "1";
seachModel = GetModel(seachModel);
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer(seachModel);
}
#endregion
//获取前台分页控件的分页大小
page = this.GetDataPage(seachModel);
//获取数据
condition = CopyToModel(seachModel);
QMAPP.ServicesAgent.ServiceAgent agent = this.GetServiceAgent();
page = agent.InvokeServiceFunction("UserManageBLL_GetList", condition, page);
//转换结果格式
DataGridResult result = new DataGridResult();
result.Rows = JsonConvertHelper.GetDeserialize>(page.Result.ToString());
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 点击设备下拉界面保存(提交)
///
/// 编辑界面填充设备信息
///
///
[HandleException]
public ActionResult AddMachineDetail()
{
string machineID = Request["MACHINEID"].ToString();
//物料发货明细实体
MachineInfo detail = new MachineInfo()
{
PID = machineID,
};
try
{
//实例化服务
ServiceAgent wcfAgent = this.GetServiceAgent();
//通过服务调用ProductOffLineBLL中的CheckRfid方法校验填写的RFID是否合法
MachineInfo dataResult = wcfAgent.InvokeServiceFunction("UserWithMachineBLL_GetMachineInfo", detail);
return Json(dataResult, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 编辑界面填充设备信息
///
/// 编辑界面填充设备信息
///
/// 是否回调
/// 列表
[HandleException]
public ActionResult GetMachineInfoList(bool? callBack)
{
MachineInfoModel seachModel = null;
DataResult pageResult = new DataResult();
DataPage page = new DataPage();
ServiceAgent wcfAgent = this.GetServiceAgent();
MachineInfo condition = null;
try
{
//获取查询对象
seachModel = GetModel();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
page.PageSize = 100;
condition = CopyToModel(seachModel);
if (seachModel.MachineIds != null)
{
string machineid = "('" + seachModel.MachineIds.Replace(";", "','") + "')";
condition.PIDS = machineid;
}
#region wcf服务统一接口
pageResult = wcfAgent.InvokeServiceFunction>(QMAPP.ServicesAgent.B9BasicService.MachineInfoBLL_GetList.ToString(), condition, page);
if (pageResult.IsSuccess == false)
{
SetMessage(pageResult.Msg);
return List(true);
}
DateGridResult result = new DateGridResult();
result.Total = pageResult.Result.RecordCount;
result.Rows = JsonConvertHelper.GetDeserialize>(pageResult.Result.Result.ToString());
#endregion
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
///
/// 获取列表
///
/// 是否回调
/// 列表
[HandleException]
public ActionResult GetListForEdit(bool? callBack)
{
UserWithMachineModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
UserWithMachine condition = null;
DataResult pageResult = new DataResult();
try
{
//获取查询对象
seachModel = GetModel();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
page.PageSize = 100;
condition = CopyToModel(seachModel);
#region wcf服务统一接口
pageResult = wcfAgent.InvokeServiceFunction>("UserWithMachineBLL_GetList", condition, page);
if (pageResult.IsSuccess == false)
{
SetMessage(pageResult.Msg);
return List(true);
}
DateGridResult result = new DateGridResult();
result.Total = pageResult.Result.RecordCount;
result.Rows = JsonConvertHelper.GetDeserialize>(pageResult.Result.Result.ToString());
#endregion
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
}
}