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
{
///
/// 模块名称:物料
/// 作 者:来洋
/// 编写日期:2018年01月05日
///
public class MaterialClassController : QController
{
#region 获取列表
///
/// 加载列表
///
/// 结果
[HandleException]
public ActionResult List(bool? callBack)
{
MaterialClassModel seachModel = new MaterialClassModel();
if (callBack == true)
TryGetSelectBuffer(out seachModel);
seachModel.rownumbers = false;
seachModel.url = "/MaterialClass/GetList";
return View("List", seachModel);
}
///
/// 获取列表
///
/// 是否回调
/// 列表
[HandleException]
public ActionResult GetList(bool? callBack)
{
MaterialClassModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
Material 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>("MaterialClassBLL_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 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>
("MaterialBLL_GetMaterialList", material);
var classresult = wcfAgent.InvokeServiceFunction>>
("MaterialBLL_GetMaterialClassList", new MaterialClass()).Result;
List trees = new List();
//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()
};
AppendTree(subnode, classresult, materialResult, isAll);
if (subnode.children.Count > 0)
{
trees.Add(subnode);
}
}
return Json(trees, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 追加树节点
///
///
///
///
private void AppendTree(MaterialClassTreeModel node, List mclasslist, List 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()
};
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 result = new DataResult();
try
{
//if (string.IsNullOrEmpty(ID) == false)
//{
// //修改获取原数据
// Entity.PID = ID;
// result = wcfAgent.InvokeServiceFunction>("MaterialBLL_Get", Entity);
// if (result.IsSuccess == false)
// {
// SetMessage(result.Msg);
// return View("MaterialEdit", model);
// }
// model = CopyToModel(result.Result);
//}
Entity.UP_MATERIAL_TYPE_CODE = materialTypeCode;
int maxSeqNum = wcfAgent.InvokeServiceFunction("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 result = new DataResult();
try
{
//Entity.MATERIAL_TYPE_CODE = materialTypeCode;
//int maxSeqNum = wcfAgent.InvokeServiceFunction("MaterialClassBLL_GetMaxSeqNum", Entity);
//model.SEQ_NUM = maxSeqNum + 1;
model.MATERIAL_TYPE_CODE = materialTypeCode;
return View("AddMaterialCode", model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 保存
///
/// 保存
///
///
/// 处理结果
[HttpPost]
[HandleException]
[ValidateInput(false)]
public ActionResult SaveMaterialClass(MaterialClassModel saveModel)
{
MaterialClass Entity = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
Entity = CopyToModel(saveModel);
if (string.IsNullOrEmpty(Entity.PID) == true)
{
//新增
result = wcfAgent.InvokeServiceFunction>("MaterialClassBLL_Insert", Entity);
}
else
{
//修改
//result = wcfAgent.InvokeServiceFunction>("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 result = new DataResult();
try
{
Entity = CopyToModel(saveModel);
if (string.IsNullOrEmpty(Entity.PID) == true)
{
//新增
result = wcfAgent.InvokeServiceFunction>("MaterialBLL_Insert", Entity);
}
else
{
//修改
//result = wcfAgent.InvokeServiceFunction>("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 删除
///
/// 删除
///
/// 结果
[HttpPost]
[HandleException]
public ActionResult Delete(MaterialClassModel saveMode)
{
string PID = Request.Params["PID"];
ServiceAgent wcfAgent = this.GetServiceAgent();
DataResult result = new DataResult();
try
{
result = wcfAgent.InvokeServiceFunction>("MaterialBLL_Delete", PID);
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return GetMaterialTree();
}
if (result.Result==0)
{
result = wcfAgent.InvokeServiceFunction>("MaterialClassBLL_Delete", PID);
if (result.IsSuccess == false)
{
SetMessage(result.Msg);
return GetMaterialTree();
}
}
SetMessage(AppResource.DeleteMessage);
return GetMaterialTree();
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}