using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using QMFrameWork.Data;
using QMAPP.Entity;
using QMAPP.FJC.Entity.QT;
using QMAPP.FJC.BLL.QT;
using QMAPP.FJC.DAL.QT;
using QMAPP.BLL;
using QMAPP.FJC.BLL.Basic;
using QMAPP.FJC.BLL.Equipment;
using QMAPP.FJC.Entity.Basic;
using QMAPP.FJC.Entity.Equipment;
using QMAPP.MD.BLL;
using QMAPP.MD.Entity;
using Resource = QMAPP.FJC.Entity.Resource;
namespace QMAPP.FJC.BLL.QT
{
///
/// 模块名称:物料信息绑定关系
/// 作 者:张鹏
/// 编写日期:2017年09月01日
///
public class MaterialBindingBLL : BaseBLL
{
#region 获取信息
///
/// 获取信息
///
/// 条件
/// 信息
public MaterialBinding Get(MaterialBinding info)
{
try
{
return new MaterialBindingDAL().Get(info);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataResult GetList(MaterialBinding condition, DataPage page)
{
DataResult result = new DataResult();
try
{
//获取物料信息列表
DataPage dataPage = new MaterialBindingDAL().GetMaterialBindingList(condition, page);
#region 翻译code
List materialBindingList = dataPage.Result as List;
var materialClassList = new MaterialBLL().GetMaterialClassList(new MaterialClass());
var materialList = new MaterialBLL().GetMaterialList(new Material());
var machineInfoList = new MachineInfoBLL().GetAllMachineInfoList();
var mouldList = new MouldBLL().GetMoulds();
var EQUIP = "设备";
var MOULD = "模具";
var CLASS = "物料类型";
var CODE = "物料号";
if (materialBindingList != null && materialBindingList.Count>0)
foreach (MaterialBinding m in materialBindingList)
{
if (m.BINDING_TYPE == "EQUIP")
{
m.BINDING_TYPE_NAME = EQUIP;
MachineInfo target = machineInfoList.FirstOrDefault(x => x.MACHINECODDE == m.TARGET_CODE);
if (target != null)
{
m.TARGET_CODE_NAME = target.MACHINENAME;
}
}
else if (m.BINDING_TYPE == "MOULD")
{
m.BINDING_TYPE_NAME = MOULD;
Mould target = mouldList.FirstOrDefault(x => x.MOULD_CODE == m.TARGET_CODE);
if (target != null)
{
m.TARGET_CODE_NAME = target.MOULD_NAME;
}
}
if (m.IS_MATERIAL_CODE == "0")
{
m.IS_MATERIAL_NAME = CLASS;
MaterialClass target = materialClassList.Result.FirstOrDefault(x => x.MATERIAL_TYPE_CODE == m.MATERIAL_CODE);
if (target != null)
{
m.MATERIAL_CODE_NAME = target.MATERIAL_TYPE_NAME;
}
}
else if (m.IS_MATERIAL_CODE == "1")
{
m.IS_MATERIAL_NAME = CODE;
Material target = materialList.FirstOrDefault(x => x.MATERIAL_CODE == m.MATERIAL_CODE);
if (target != null)
{
m.MATERIAL_CODE_NAME = target.MATERIAL_NAME;
}
}
}
#endregion
result.Result = dataPage;
}
catch (Exception ex)
{
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public DataResult Insert(MaterialBinding info)
{
DataResult result = new DataResult();
try
{
//基本信息
info.PID = Guid.NewGuid().ToString();
MaterialBindingDAL cmdDAL = new MaterialBindingDAL();
result.Result = new MaterialBindingDAL().Insert(info);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
///
/// 更新信息
///
/// 信息
/// 更新行数
public DataResult Update(MaterialBinding info)
{
DataResult result = new DataResult();
try
{
result.Result = new MaterialBindingDAL().Update(info);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除
///
/// 删除信息
///
/// 主键串
/// 删除个数
public DataResult DeleteArray(string strs)
{
int count = 0;
DataResult result = new DataResult();
string[] list = strs.Split(":".ToCharArray());
try
{
foreach (string str in list)
{
count += this.Delete(new MaterialBinding { PID = str });
}
result.Result = count;
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 删除信息
///
/// 信息
/// 删除个数
public int Delete(MaterialBinding info)
{
try
{
return new MaterialBindingDAL().Del(info);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}