天津投入产出系统后端
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.

365 lines
14 KiB

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 QMFrameWork.Data;
using QMAPP.ServicesAgent;
using QMAPP.MD.Entity;
using QMAPP.Entity;
using QMFrameWork.WebUI.DataSource;
using QMFrameWork.Common.Serialization;
using QMAPP.MD.Web;
namespace QMAPP.MD.Web.Controllers
{
/// <summary>
/// 模块名称:物料
/// 作 者:来洋
/// 编写日期:2018年01月05日
/// </summary>
public class MaterialClassController : QController
{
#region 获取列表
/// <summary>
/// 加载列表
/// </summary>
/// <returns>结果</returns>
[HandleException]
public ActionResult List(bool? callBack)
{
MaterialClassModel seachModel = new MaterialClassModel();
if (callBack == true)
TryGetSelectBuffer<MaterialClassModel>(out seachModel);
seachModel.rownumbers = false;
seachModel.url = "/MaterialClass/GetList";
return View("List", seachModel);
}
/// <summary>
/// 获取列表
/// </summary>
/// <param name="callBack">是否回调</param>
/// <returns>列表</returns>
[HandleException]
public ActionResult GetList(bool? callBack)
{
MaterialClassModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
Material condition = null;
DataResult<DataPage> pageResult = new DataResult<DataPage>();
try
{
//获取查询对象
seachModel = GetModel<MaterialClassModel>();
#region 获取缓存值
if (callBack != null)
{
TryGetSelectBuffer<MaterialClassModel>(out seachModel);
}
else
{
//保存搜索条件
SetSelectBuffer<MaterialClassModel>(seachModel);
}
#endregion
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel<Material, MaterialClassModel>(seachModel);
#region wcf服务统一接口
pageResult = wcfAgent.InvokeServiceFunction<DataResult<DataPage>>("MaterialClassBLL_GetList", condition, page);
if (pageResult.IsSuccess == false)
{
SetMessage(pageResult.Msg);
return List(true);
}
DateGridResult<Material> result = new DateGridResult<Material>();
result.Total = pageResult.Result.RecordCount;
result.Rows = JsonConvertHelper.GetDeserialize<List<Material>>(pageResult.Result.Result.ToString());
#endregion
return Content(result.GetJsonSource());
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取物料信息下拉列表
/// <summary>
/// 获取物料信息下拉列表
/// </summary>
/// <returns>数据源</returns>
[HandleException]
public ActionResult GetMaterialTree()
{
ServiceAgent wcfAgent = this.GetServiceAgent();
var material = new Material();
material.MATERIAL_CODE = Request.Params["MATERIAL_CODE"];
material.MATERIAL_NAME = Request.Params["MATERIAL_NAME"];
material.COLOR = Request.Params["COLOR"];
material.HBTYPE = Request.Params["HBTYPE"];
var isAll = Request.Params["isAll"];
try
{
var materialResult = wcfAgent.InvokeServiceFunction<List<Material>>
("MaterialBLL_GetMaterialList", material);
var classresult = wcfAgent.InvokeServiceFunction<DataResult<List<MaterialClass>>>
("MaterialBLL_GetMaterialClassList", new MaterialClass()).Result;
List<MaterialClassTreeModel> trees = new List<MaterialClassTreeModel>();
//trees.Add(new MaterialClassTreeModel { Id = "", Text = " " });
foreach (MaterialClass item in classresult.Where(p => string.IsNullOrWhiteSpace(p.UP_MATERIAL_TYPE_CODE)).OrderBy(p => p.SEQ_NUM))
{
var subnode = new MaterialClassTreeModel
{
PID = item.PID,
Id = item.MATERIAL_TYPE_CODE,
Text = item.MATERIAL_TYPE_NAME,
children = new List<MaterialClassTreeModel>()
};
AppendTree(subnode, classresult, materialResult, isAll);
if (subnode.children.Count > 0)
{
trees.Add(subnode);
}
}
return Json(trees, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 追加树节点
/// </summary>
/// <param name="node"></param>
/// <param name="mclasslist"></param>
/// <param name="materiallist"></param>
private void AppendTree(MaterialClassTreeModel node, List<MaterialClass> mclasslist, List<Material> materiallist,string isAll)
{
foreach (var mclass in mclasslist.Where(p => string.Equals(node.Id, p.UP_MATERIAL_TYPE_CODE)).OrderBy(p => p.SEQ_NUM))
{
var subnode = new MaterialClassTreeModel
{
PID = mclass.PID,
Id = mclass.MATERIAL_TYPE_CODE,
Text = mclass.MATERIAL_TYPE_NAME,
children = new List<MaterialClassTreeModel>()
};
AppendTree(subnode, mclasslist, materiallist, isAll);
if (isAll == "1")
{
if (subnode.children.Count > 0)
{
node.children.Add(subnode);
}
}
else
{
node.children.Add(subnode);
}
}
foreach (var material in materiallist.Where(p => string.Equals(node.Id, p.MATERIAL_TYPE_CODE)).OrderBy(p => p.MATERIAL_CODE))
{
var subnode = new MaterialClassTreeModel
{
PID = material.PID,
Id = material.MATERIAL_CODE,
Text = material.MATERIAL_NAME,
MATERIAL_SHORT = material.MATERIAL_SHORT,
COLOR = material.COLOR,
HBTYPE = material.HBTYPE,
OUTSOURCE = material.OUTSOURCE,
STD_QTY = material.STD_QTY.ToString(),
PROJECTCODE=material.PROJECTCODE,
REMARK = material.REMARK
};
node.children.Add(subnode);
}
}
#endregion
#region 添加
//添加物料类型
[HandleException]
public ActionResult AddMaterialClass()
{
MaterialClassModel model = new MaterialClassModel();
string materialTypeCode = Request.Params["materialTypeCode"];
MaterialClass Entity = new MaterialClass();
ServiceAgent wcfAgent = this.GetServiceAgent();
//DataResult<MaterialClass> result = new DataResult<MaterialClass>();
try
{
//if (string.IsNullOrEmpty(ID) == false)
//{
// //修改获取原数据
// Entity.PID = ID;
// result = wcfAgent.InvokeServiceFunction<DataResult<MaterialClass>>("MaterialBLL_Get", Entity);
// if (result.IsSuccess == false)
// {
// SetMessage(result.Msg);
// return View("MaterialEdit", model);
// }
// model = CopyToModel<MaterialClassModel, MaterialClass>(result.Result);
//}
Entity.UP_MATERIAL_TYPE_CODE = materialTypeCode;
int maxSeqNum = wcfAgent.InvokeServiceFunction<int>("MaterialClassBLL_GetMaxSeqNum", Entity);
model.SEQ_NUM = maxSeqNum+1;
model.UP_MATERIAL_TYPE_CODE = materialTypeCode;
return View("AddMaterialClass", model);
}
catch (Exception ex)
{
throw ex;
}
}
//添加物料号
[HandleException]
public ActionResult AddMaterialCode()
{
MaterialModel model = new MaterialModel();
string materialTypeCode = Request.Params["materialTypeCode"];
Material Entity = new Material();
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult<MaterialClass> result = new DataResult<MaterialClass>();
try
{
//Entity.MATERIAL_TYPE_CODE = materialTypeCode;
//int maxSeqNum = wcfAgent.InvokeServiceFunction<int>("MaterialClassBLL_GetMaxSeqNum", Entity);
//model.SEQ_NUM = maxSeqNum + 1;
model.MATERIAL_TYPE_CODE = materialTypeCode;
return View("AddMaterialCode", model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 保存
/// <summary>
/// 保存
/// </summary>
/// <param name="model"></param>
/// <returns>处理结果</returns>
[HttpPost]
[HandleException]
[ValidateInput(false)]
public ActionResult SaveMaterialClass(MaterialClassModel saveModel)
{
MaterialClass Entity = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult<int> result = new DataResult<int>();
try
{
Entity = CopyToModel<MaterialClass, MaterialClassModel>(saveModel);
if (string.IsNullOrEmpty(Entity.PID) == true)
{
//新增
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("MaterialClassBLL_Insert", Entity);
}
else
{
//修改
//result = wcfAgent.InvokeServiceFunction<DataResult<int>>("MaterialBLL_Update", Entity);
}
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return View("AddMaterialClass", saveModel);
}
return this.GetJsViewResult(string.Format("parent.List();parent.showTitle('{0}');parent.closeAppWindow1();", AppResource.SaveMessge));
}
catch (Exception ex)
{
throw ex;
}
}
[HttpPost]
[HandleException]
[ValidateInput(false)]
public ActionResult SaveMaterialCode(MaterialModel saveModel)
{
Material Entity = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult<int> result = new DataResult<int>();
try
{
Entity = CopyToModel<Material, MaterialModel>(saveModel);
if (string.IsNullOrEmpty(Entity.PID) == true)
{
//新增
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("MaterialBLL_Insert", Entity);
}
else
{
//修改
//result = wcfAgent.InvokeServiceFunction<DataResult<int>>("MaterialBLL_Update", Entity);
}
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return View("AddMaterialCode", saveModel);
}
return this.GetJsViewResult(string.Format("parent.List();parent.showTitle('{0}');parent.closeAppWindow1();", AppResource.SaveMessge));
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除
/// <summary>
/// 删除
/// </summary>
/// <returns>结果</returns>
[HttpPost]
[HandleException]
public ActionResult Delete(MaterialClassModel saveMode)
{
string PID = Request.Params["PID"];
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult<int> result = new DataResult<int>();
try
{
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("MaterialBLL_Delete", PID);
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return GetMaterialTree();
}
if (result.Result==0)
{
result = wcfAgent.InvokeServiceFunction<DataResult<int>>("MaterialClassBLL_Delete", PID);
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return GetMaterialTree();
}
}
SetMessage(AppResource.DeleteMessage);
return GetMaterialTree();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}