using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QMAPP.FJC.Entity.Operation;
using QMAPP.FJC.Web.Models.StatisticalAnalysis;
using QMFrameWork.WebUI.Attribute;
using QMAPP.Common.Web.Controllers;
using QMAPP.KB.Entity;
using QMFrameWork.Data;
using QMAPP.ServicesAgent;
using QMFrameWork.WebUI.DataSource;
using QMFrameWork.Common.Serialization;
using System.Data;
using QMAPP.FJC.Entity.Basic;
namespace QMAPP.FJC.Web.Controllers
{
public class ShiftContrastController : QController
{
///
/// 模块编号:M10-3
/// 作 用:班次对比分析控制层
/// 作 者:王庆男
/// 编写日期:2015年07月06日
///
///
#region 初始化
///
/// 初始化
///
/// 结果
[HandleException]
public ActionResult Init()
{
ShiftContrastModel seachModel = new ShiftContrastModel();
return View("ShiftContrast", seachModel);
}
#endregion
#region 获取列表
///
/// 加载列表
///
/// 结果
[HandleException]
public ActionResult List()
{
ShiftContrastModel seachModel = null;
DataResult> listResult = new DataResult>();
DataPage page = new DataPage();
ServiceAgent wcfAgent = this.GetServiceAgent();
MainOperation condition = null;
try
{
//获取查询对象
seachModel = GetModel();
condition = CopyToModel(seachModel);
#region wcf服务统一接口
listResult = wcfAgent.InvokeServiceFunction>>(QMAPP.ServicesAgent.B9BasicService.MainOperationBLL_GetListGroupBy.ToString(), condition);
#endregion
if (listResult.IsSuccess == false)
{
SetMessage(listResult.Msg);
return View("ShiftContrast", seachModel);
}
var machines = from l in listResult.Result
group l by new { l.PRODUCESHIFTTCODE, l.PRODUCESHIFTNAME } into g
select new
{
CODE = g.Key.PRODUCESHIFTTCODE,
NAME = g.Key.PRODUCESHIFTNAME
};
var query = listResult.Result.GroupBy(m => new { m.MACHINECODDE, m.MACHINENAME });
string arr = "[";
foreach (var petGroup in query)
{
if (arr.Length > 1)
{
arr += ",";
}
arr += "{ \"CODE\":" + "\"" + petGroup.Key.MACHINECODDE + "\"";
arr += ",\"NAME\":" + "\"" + petGroup.Key.MACHINENAME + "\"";
foreach (MainOperation mainOperation in petGroup)
{
arr += ",\"" + mainOperation.PRODUCESHIFTTCODE + "\":\"" + mainOperation.Counts + "\"";
}
arr += "}";
}
arr += "]";
seachModel.results = JsonConvertHelper.GetSerializes(machines);
seachModel.arr = arr;
if (listResult.Result.Count == 0)
{
SetMessage("未查到相关数据!");
}
return View("ShiftContrast", seachModel);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 导出excel
///
/// 导出excel
///
/// 结果
[HttpPost]
public ActionResult ExportExcel()
{
ShiftContrastModel seachModel = null;
MainOperation condition = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult> listResult = new DataResult>();
try
{
//获取查询对象
seachModel = GetModel();
condition = CopyToModel(seachModel);
//获取数据
listResult = wcfAgent.InvokeServiceFunction>>(QMAPP.ServicesAgent.B9BasicService.MainOperationBLL_GetListGroupBy.ToString(), condition);
//导出
QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool();
DataTable dt = JsonConvertHelper.GetDeserialize(JsonConvertHelper.GetSerializes(listResult.Result));
return efTool.GetExcelFileResult("ShiftContrastExp", "班次对比分析.xlsx", dt);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取设备编号下拉列表
///
/// 获取设备编号下拉列表
///
///
public ContentResult GetMachineInfoComboxSource()
{
List listMachineInfo = new List();
ComboboxResult model = new ComboboxResult();
ServiceAgent wcfAgent = this.GetServiceAgent();
MachineInfo entity = new MachineInfo();
try
{
//获取设备信息
listMachineInfo = wcfAgent.InvokeServiceFunction>(QMAPP.ServicesAgent.FeedInManage.InjectionRecorderBLL_GetMachineInfoList.ToString(), entity);
foreach (var item in listMachineInfo)
{
if (model.Items.Count == 0)
{
model.Add(new ComboboxItem { ID = "", Text = "" });
}
else
{
model.Add(new ComboboxItem { ID = item.MACHINECODDE, Text = item.MACHINECODDE });
}
}
return Content(model.ToString());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取班次编号下拉列表
///
/// 获取班次编号下拉列表
///
///
public ContentResult GetProductShiftComboxSource()
{
List listProductShiftInfo = new List();
ComboboxResult model = new ComboboxResult();
ServiceAgent wcfAgent = this.GetServiceAgent();
ProduceShift entity = new ProduceShift();
try
{
//获取班次信息
listProductShiftInfo = wcfAgent.InvokeServiceFunction>(QMAPP.ServicesAgent.FeedInManage.InjectionRecorderBLL_GetProduceShiftList.ToString(), entity);
foreach (var item in listProductShiftInfo)
{
if (model.Items.Count == 0)
{
model.Add(new ComboboxItem { ID = "", Text = "" });
}
else
{
model.Add(new ComboboxItem { ID = item.PRODUCESHIFTTCODE, Text = item.PRODUCESHIFTTCODE });
}
}
return Content(model.ToString());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}