You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
489 lines
18 KiB
489 lines
18 KiB
4 years ago
|
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.FJC.Web.Models.FIS;
|
||
|
using QMFrameWork.Data;
|
||
|
using QMAPP.FJC.Entity.FIS;
|
||
|
using QMAPP.ServicesAgent;
|
||
|
using QMAPP.Entity;
|
||
|
using QMFrameWork.WebUI.DataSource;
|
||
|
using QMFrameWork.Common.Serialization;
|
||
|
using System.Data;
|
||
|
using QMAPP.Common.Web.Models;
|
||
|
using QMAPP.FJC.Entity.Basic;
|
||
|
using QMAPP.MD.Entity;
|
||
|
using QMAPP.FJC.Entity;
|
||
|
using QMAPP.FJC.BLL.FIS;
|
||
|
using QMAPP.FJC.Entity.FileCopy.FIS;
|
||
|
using System.Text.RegularExpressions;
|
||
|
|
||
|
namespace QMAPP.FJC.Web.Controllers
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 注塑计划管理
|
||
|
/// 作 者:郭兆福
|
||
|
/// 时 间:2017年09月15日
|
||
|
/// </summary>
|
||
|
public class OrderPlanController : QController
|
||
|
{
|
||
|
#region 获取信息
|
||
|
/// <summary>
|
||
|
/// 加载列表
|
||
|
/// </summary>
|
||
|
/// <returns>结果</returns>
|
||
|
[HandleException]
|
||
|
public ActionResult List(bool? callback)
|
||
|
{
|
||
|
OrderPlanModel seachModel = new OrderPlanModel();
|
||
|
string order_type = Request["ORDER_TYPE"];
|
||
|
|
||
|
seachModel.PLANTIMESTART = DateTime.Now.Date.AddDays(-10).ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
seachModel.PLANTIMEEND = DateTime.Now.Date.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
seachModel.ImmediateSearch = false;
|
||
|
seachModel.ORDER_TYPE = order_type;
|
||
|
if (callback == true)
|
||
|
TryGetSelectBuffer<OrderPlanModel>(out seachModel);
|
||
|
seachModel.rownumbers = false;
|
||
|
seachModel.url = "/OrderPlan/GetList";
|
||
|
return View("OrderPlanList", seachModel);
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 获取列表
|
||
|
/// <summary>
|
||
|
/// 获取列表
|
||
|
/// </summary>
|
||
|
/// <param name="callBack">是否回调</param>
|
||
|
/// <returns>列表</returns>
|
||
|
[HandleException]
|
||
|
public ActionResult GetList(bool? callBack)
|
||
|
{
|
||
|
OrderPlanModel seachModel = null;
|
||
|
DataPage page = null;
|
||
|
ServiceAgent wcfAgent = this.GetServiceAgent();
|
||
|
OrderPlan condition = null;
|
||
|
DataResult<DataPage> pageResult = new DataResult<DataPage>();
|
||
|
try
|
||
|
{
|
||
|
//获取查询对象
|
||
|
seachModel = GetModel<OrderPlanModel>();
|
||
|
#region 获取缓存值
|
||
|
if (callBack != null)
|
||
|
{
|
||
|
TryGetSelectBuffer<OrderPlanModel>(out seachModel);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//保存搜索条件
|
||
|
SetSelectBuffer<OrderPlanModel>(seachModel);
|
||
|
}
|
||
|
#endregion
|
||
|
//获取前台分页设置信息
|
||
|
page = this.GetDataPage(seachModel);
|
||
|
condition = CopyToModel<OrderPlan, OrderPlanModel>(seachModel);
|
||
|
pageResult = wcfAgent.InvokeServiceFunction<DataResult<DataPage>>("OrderPlanBLL_GetList", condition, page);
|
||
|
|
||
|
if (pageResult.IsSuccess == false)
|
||
|
{
|
||
|
SetMessage(pageResult.Msg);
|
||
|
return List(true);
|
||
|
}
|
||
|
DateGridResult<OrderPlan> result = new DateGridResult<OrderPlan>();
|
||
|
result.Total = pageResult.Result.RecordCount;
|
||
|
result.Rows = JsonConvertHelper.GetDeserialize<List<OrderPlan>>(pageResult.Result.Result.ToString());
|
||
|
|
||
|
return Content(result.GetJsonSource());
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 编辑
|
||
|
/// <summary>
|
||
|
/// 编辑载入
|
||
|
/// </summary>
|
||
|
/// <returns>处理结果</returns>
|
||
|
[HandleException]
|
||
|
public ActionResult Edit()
|
||
|
{
|
||
|
OrderPlanModel model = new OrderPlanModel();
|
||
|
string ID = Request.Params["PID"];
|
||
|
string TYPE = Request.Params["ORDER_TYPE"];
|
||
|
OrderPlan Entity = new OrderPlan();
|
||
|
ServiceAgent wcfAgent = this.GetServiceAgent();
|
||
|
DataResult<OrderPlan> result = new DataResult<OrderPlan>();
|
||
|
try
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(ID) == false)
|
||
|
{
|
||
|
//修改获取原数据
|
||
|
Entity.PID = ID;
|
||
|
Entity.ORDER_TYPE = TYPE;
|
||
|
result = wcfAgent.InvokeServiceFunction<DataResult<OrderPlan>>("OrderPlanBLL_Get", Entity);
|
||
|
|
||
|
Entity = wcfAgent.InvokeServiceFunction<OrderPlan>("OrderPlanBLL_GetOrderPlantState", Entity);
|
||
|
if (Entity.PLAN_STATE == EnumGeter.PLANSTATE.COMPLATED.GetHashCode().ToString())
|
||
|
{
|
||
|
return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();", AppResource.OrderPlanHadCom));
|
||
|
}
|
||
|
if (result.IsSuccess == false)
|
||
|
{
|
||
|
SetMessage(result.Msg);
|
||
|
return View("OrderPlanEdit", model);
|
||
|
}
|
||
|
model = CopyToModel<OrderPlanModel, OrderPlan>(result.Result);
|
||
|
}
|
||
|
model.ORDER_TYPE = TYPE;
|
||
|
return View("OrderPlanEdit", model);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 保存
|
||
|
/// </summary>
|
||
|
/// <param name="model"></param>
|
||
|
/// <returns>处理结果</returns>
|
||
|
[HttpPost]
|
||
|
[HandleException]
|
||
|
[ValidateInput(false)]
|
||
|
public ActionResult Save(OrderPlanModel saveModel)
|
||
|
{
|
||
|
OrderPlan Entity = null;
|
||
|
ServiceAgent wcfAgent = this.GetServiceAgent();
|
||
|
string TYPE = Request.Form["ORDER_TYPE"];
|
||
|
DataResult<int> result = new DataResult<int>();
|
||
|
try
|
||
|
{
|
||
|
Entity = CopyToModel<OrderPlan, OrderPlanModel>(saveModel);
|
||
|
if (string.IsNullOrEmpty(Entity.PID) == true)
|
||
|
{
|
||
|
//新增
|
||
|
Entity.ORDER_TYPE = TYPE;
|
||
|
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("OrderPlanBLL_Insert", Entity);
|
||
|
if (result.IsSuccess == false)
|
||
|
{
|
||
|
SetMessage("计划单号已存在!");
|
||
|
return View("OrderPlanEdit", saveModel);
|
||
|
}
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//修改
|
||
|
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("OrderPlanBLL_Update", Entity);
|
||
|
if (result.IsSuccess == false)
|
||
|
{
|
||
|
SetMessage("计划单号已存在!");
|
||
|
return View("OrderPlanEdit", saveModel);
|
||
|
}
|
||
|
}
|
||
|
return this.GetJsViewResult(string.Format("parent.List(1);parent.showTitle('{0}');parent.closeAppWindow1();", AppResource.SaveMessge));
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 删除
|
||
|
/// <summary>
|
||
|
/// 删除
|
||
|
/// </summary>
|
||
|
/// <returns>结果</returns>
|
||
|
[HttpPost]
|
||
|
[HandleException]
|
||
|
public ActionResult Delete(OrderPlan model)
|
||
|
{
|
||
|
string selectKey = Request.Form["selectKey"];
|
||
|
ServiceAgent wcfAgent = this.GetServiceAgent();
|
||
|
DataResult<int> result = new DataResult<int>();
|
||
|
try
|
||
|
{
|
||
|
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("OrderPlanBLL_Delete", selectKey);
|
||
|
if (result.IsSuccess == false)
|
||
|
{
|
||
|
SetMessage(result.Msg);
|
||
|
return List(true);
|
||
|
}
|
||
|
SetMessage(AppResource.DeleteMessage);
|
||
|
return List(true);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 发布
|
||
|
/// <summary>
|
||
|
/// 发布
|
||
|
/// </summary>
|
||
|
/// <returns></returns>
|
||
|
[HttpPost]
|
||
|
[HandleException]
|
||
|
public ActionResult PutOut(OrderPlan model)
|
||
|
{
|
||
|
string selectKey = Request.Form["selectKey"];
|
||
|
ServiceAgent wcfAgent = this.GetServiceAgent();
|
||
|
DataResult<int> result = new DataResult<int>();
|
||
|
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("OrderPlanBLL_PutOut", selectKey);
|
||
|
if (result.IsSuccess == false)
|
||
|
{
|
||
|
SetMessage(result.Msg);
|
||
|
return List(true);
|
||
|
}
|
||
|
SetMessage(AppResource.PutOutMessage);
|
||
|
return List(true);
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 导出excel
|
||
|
/// <summary>
|
||
|
/// 导出excel
|
||
|
/// </summary>
|
||
|
/// <returns>结果</returns>
|
||
|
[HttpPost]
|
||
|
public ActionResult ExportExcel()
|
||
|
{
|
||
|
OrderPlanModel seachModel = null;
|
||
|
OrderPlan condition = null;
|
||
|
DataTable exportDt = new DataTable();
|
||
|
ServiceAgent wcfAgent = this.GetServiceAgent();
|
||
|
try
|
||
|
{
|
||
|
//获取查询对象
|
||
|
seachModel = GetModel<OrderPlanModel>();
|
||
|
condition = CopyToModel<OrderPlan, OrderPlanModel>(seachModel);
|
||
|
condition.PIDList = Request.Form["selectKey"];
|
||
|
//获取数据
|
||
|
OrderPlanBLL op = new OrderPlanBLL();
|
||
|
|
||
|
exportDt = op.GetExportData(condition);
|
||
|
|
||
|
//exportDt = wcfAgent.InvokeServiceFunction<DataTable>("OrderPlanBLL_GetExportData", condition);
|
||
|
|
||
|
//导出
|
||
|
QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool();
|
||
|
return efTool.GetExcelFileResult("OrderPlanExp", "注塑计划信息.xlsx", exportDt);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 导入excel
|
||
|
/// <summary>
|
||
|
/// 导入excel
|
||
|
/// </summary>
|
||
|
/// <returns>结果</returns>
|
||
|
[HttpPost]
|
||
|
public ActionResult ImportExcel()
|
||
|
{
|
||
|
DataTable dt = null;
|
||
|
List<OrderPlan> list = new List<OrderPlan>();
|
||
|
DataResult<ImportMessage> serviceResult = null;
|
||
|
string fileName = Request.Form["fileName"];
|
||
|
string orderby = Request.Form["ORDER_TYPE"];
|
||
|
ServiceAgent wcfAgent = this.GetServiceAgent();
|
||
|
|
||
|
Materiel materialmodel = new Materiel();
|
||
|
ProduceShift produceshiftmodel = new ProduceShift();
|
||
|
MachineInfo machine = new MachineInfo();
|
||
|
//初始工作中心编号条件
|
||
|
QMAPP.MD.Entity.WorkCell workcell = new QMAPP.MD.Entity.WorkCell();
|
||
|
workcell.WORKCELL_CODE = orderby;
|
||
|
try
|
||
|
{
|
||
|
Regex x = new Regex(@"^[0-9]*$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||
|
dt = this.GetTableByExcel("OrderPlanImp", fileName, dt);
|
||
|
//格式转换
|
||
|
//日期转换,当操作者就是不用导入模板时,防止日期报错
|
||
|
for (int i = 0; i < dt.Rows.Count; i++)
|
||
|
{
|
||
|
//计划日期
|
||
|
string date = dt.Rows[i]["PLAN_DATEIN"].ToString();
|
||
|
if (x.Match(date).Success && !string.IsNullOrEmpty(date) && date.Length<6)
|
||
|
{
|
||
|
dt.Rows[i]["PLAN_DATEIN"] = DateTime.FromOADate(double.Parse(date.ToString())).ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
}
|
||
|
else if (string.IsNullOrEmpty(date))
|
||
|
{
|
||
|
dt.Rows[i]["PLAN_DATEIN"] = null;
|
||
|
}
|
||
|
//计划开始时间
|
||
|
string datestart = dt.Rows[i]["STARTTIMEIN"].ToString();
|
||
|
if (datestart.Split('.')[0].Length < 6 && !string.IsNullOrEmpty(datestart))
|
||
|
{
|
||
|
dt.Rows[i]["STARTTIMEIN"] = DateTime.FromOADate(double.Parse(datestart.ToString()));
|
||
|
}
|
||
|
else if (string.IsNullOrEmpty(date))
|
||
|
{
|
||
|
dt.Rows[i]["STARTTIMEIN"] = null;
|
||
|
}
|
||
|
//计划截止时间
|
||
|
string dateend = dt.Rows[i]["ENDTIMEIN"].ToString();
|
||
|
if (dateend.Split('.')[0].Length < 6 && !string.IsNullOrEmpty(dateend))
|
||
|
{
|
||
|
dt.Rows[i]["ENDTIMEIN"] = DateTime.FromOADate(double.Parse(dateend.ToString()));
|
||
|
}
|
||
|
else if (string.IsNullOrEmpty(date))
|
||
|
{
|
||
|
dt.Rows[i]["ENDTIMEIN"] = null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
list = QMFrameWork.Common.Util.BindHelper.ConvertToList<OrderPlan>(dt).ToList();
|
||
|
serviceResult = wcfAgent.InvokeServiceFunction<DataResult<ImportMessage>>("OrderPlanBLL_GetImportData", list, materialmodel,machine, produceshiftmodel, workcell);
|
||
|
if (serviceResult.Ex != null)
|
||
|
{
|
||
|
throw serviceResult.Ex;
|
||
|
}
|
||
|
if (serviceResult.Result.failureNum != 0)
|
||
|
{
|
||
|
foreach (RowError error in serviceResult.Result.Errors)
|
||
|
{
|
||
|
dt.Rows[error.Key - 1]["InfoError"] = error.Value;
|
||
|
}
|
||
|
ImportMessageModel model = new ImportMessageModel();
|
||
|
model.InfoName = "OrderPlanImp";
|
||
|
model.ReturnUrl = "/OrderPlan/List?callBack=true";
|
||
|
model.Message = serviceResult.Result;
|
||
|
model.ErrorDt = dt;
|
||
|
return new MessageOutputController().OutputImportMessage(model);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
SetMessage(serviceResult.Msg + ",如下:<br/>"
|
||
|
+ "插入" + serviceResult.Result.insertNum + "条,"
|
||
|
+ "更新" + serviceResult.Result.updateNum + "条"
|
||
|
);
|
||
|
return List(true);
|
||
|
}
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
System.IO.File.Delete(MvcApplication.TempPath + fileName);
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 下载模板
|
||
|
/// <summary>
|
||
|
/// 下载导入模板
|
||
|
/// </summary>
|
||
|
/// <returns>结果</returns>
|
||
|
[HttpPost]
|
||
|
public ActionResult GetTemplate()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
string path = AppDomain.CurrentDomain.BaseDirectory + "App_Data/Excel/";
|
||
|
string fileName = "OrderPlanImp.xlsx";
|
||
|
return File(path + fileName, "application/vnd.ms-excel", Url.Encode("注塑信息导入模板.xlsx"));
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
#endregion
|
||
|
|
||
|
#region 订单痕迹记录信息
|
||
|
|
||
|
#region 加载列表
|
||
|
/// <summary>
|
||
|
/// 加载列表
|
||
|
/// </summary>
|
||
|
/// <param name="callBack"></param>
|
||
|
/// <returns></returns>
|
||
|
public ActionResult FisPlanRecord(bool? callBack)
|
||
|
{
|
||
|
FISPlanRecordModel ItemModel = new FISPlanRecordModel();
|
||
|
string MID = Request.Params["MID"];
|
||
|
|
||
|
if (callBack == true)
|
||
|
TryGetSelectBuffer<FISPlanRecordModel>(out ItemModel);
|
||
|
|
||
|
ItemModel.rownumbers = false;
|
||
|
ItemModel.url = "/OrderPlan/FisPlanRecordList?MID=" + MID;
|
||
|
ItemModel.PLAN_NO = Request.Params["MID"];
|
||
|
return View("FisPlanRecordList", ItemModel);
|
||
|
}
|
||
|
/// <summary>
|
||
|
/// 获取列表
|
||
|
/// </summary>
|
||
|
/// <param name="callBack"></param>
|
||
|
/// <returns></returns>
|
||
|
public ActionResult FisPlanRecordList(bool? callBack)
|
||
|
{
|
||
|
FISPlanRecordModel seachModel = null;
|
||
|
DataPage page = null;
|
||
|
ServiceAgent wcfAgent = this.GetServiceAgent();
|
||
|
FISPlanRecord condition = null;
|
||
|
DataResult<DataPage> pageResult = new DataResult<DataPage>();
|
||
|
string MID = Request.Params["MID"];
|
||
|
try
|
||
|
{
|
||
|
//获取查询对象
|
||
|
seachModel = GetModel<FISPlanRecordModel>();
|
||
|
#region 获取缓存值
|
||
|
if (callBack != null)
|
||
|
{
|
||
|
TryGetSelectBuffer<FISPlanRecordModel>(out seachModel);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//保存搜索条件
|
||
|
SetSelectBuffer<FISPlanRecordModel>(seachModel);
|
||
|
}
|
||
|
#endregion
|
||
|
//获取前台分页设置信息
|
||
|
page = this.GetDataPage(seachModel);
|
||
|
if (string.IsNullOrEmpty(seachModel.PLAN_NO))
|
||
|
{
|
||
|
seachModel.PLAN_NO = MID;
|
||
|
}
|
||
|
condition = CopyToModel<FISPlanRecord, FISPlanRecordModel>(seachModel);
|
||
|
#region wcf服务统一接口
|
||
|
pageResult = wcfAgent.InvokeServiceFunction<DataResult<DataPage>>("OrderPlanBLL_FisPlanRecordList", condition, page);
|
||
|
if (pageResult.IsSuccess == false)
|
||
|
{
|
||
|
SetMessage(pageResult.Msg);
|
||
|
return FisPlanRecord(true);
|
||
|
}
|
||
|
DateGridResult<FISPlanRecord> result = new DateGridResult<FISPlanRecord>();
|
||
|
result.Total = pageResult.Result.RecordCount;
|
||
|
result.Rows = JsonConvertHelper.GetDeserialize<List<FISPlanRecord>>(pageResult.Result.Result.ToString());
|
||
|
#endregion
|
||
|
return Content(result.GetJsonSource());
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
throw ex;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
#endregion
|
||
|
|
||
|
}
|
||
|
}
|