using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using QMFrameWork.Data;
using QMAPP.Entity;
using QMAPP.BLL;
using QMAPP.BLL.Sys;
using QMAPP.DAL;
using QMAPP.MD.BLL.Dict;
using QMAPP.MD.Entity;
using QMAPP.MD.DAL;
using QMAPP.FJC.DAL.QT;
namespace QMAPP.MD.BLL
{
///
/// 模块名称:采集数据借口
/// 作 者:QMMES
/// 编写日期:2017年09月05日
///
public class DaiBLL : BaseBLL
{
#region 获取信息
///
/// 获取信息
///
/// 条件
/// 信息
public Dai Get(Dai info)
{
try
{
return new DaiDAL().Get(info);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表
///
/// 获取列表
///
/// 条件
/// 数据页
/// 数据页
public DataPage GetList(Dai condition, DataPage page)
{
try
{
var p = new DaiDAL().GetList(condition, page);
#region 翻译
List pList = p.Result as List;
var workCellList = new WorkCellBLL().GetAllList(new WorkCell());
var materialClassList = new MaterialBLL().GetMaterialClassList(new MaterialClass()).Result;
var materialList = new MaterialBLL().GetMaterialList(new Material());
var analyzerList = new AnalyzerDAL().GetList();
var stateCodeList = GetWorkCellStateCodeList("");
var UserList = new UserManageBLL().GetUserComboxSource();
DictManageBLL dictDataType = new DictManageBLL(DictKind.DataType);
DictManageBLL dictDaMode = new DictManageBLL(DictKind.DaMode);
DictManageBLL dictIsProcessCode = new DictManageBLL(DictKind.IsProcessCode);
DictManageBLL dictDivbyMould = new DictManageBLL(DictKind.DivbyMould);
foreach (Dai m in pList)
{
//采集类型
m.DATA_TYPE_NAME = dictDataType.GetDictValue(m.DATA_TYPE);
//采集方式
m.DA_MODE_NAME = dictDaMode.GetDictValue(m.DA_MODE);
//过程主码
m.ISPROCESSCODE_NAME = dictIsProcessCode.GetDictValue(m.ISPROCESSCODE);
//区分模具
m.DIVBY_MOULD_NAME = dictDivbyMould.GetDictValue(m.DIVBY_MOULD);
//工序
var workCell = workCellList.FirstOrDefault(x => x.WORKCELL_CODE == m.WORKCELL_CODE);
if (workCell != null)
m.WORKCELL_NAME = workCell.WORKCELL_NAME;
//物料类型
var materialClass = materialClassList.FirstOrDefault(x => x.MATERIAL_TYPE_CODE == m.MATERIAL_TYPE);
if (materialClass != null)
m.MATERIAL_TYPE_NAME = materialClass.MATERIAL_TYPE_NAME;
//物料号 如何MATERIAL_CODE==MATERIAL_TYPE说明页面选的是类型
if (m.MATERIAL_TYPE == m.MATERIAL_CODE)
{
m.MATERIAL_CODE = null;
}
else
{
var material = materialList.FirstOrDefault(x => x.MATERIAL_CODE == m.MATERIAL_CODE);
if (material != null)
m.MATERIAL_CODE_NAME = material.MATERIAL_NAME;
}
//解析类别
var analyzer = analyzerList.FirstOrDefault(x => x.ANALYZER_CODE == m.ANALYZE_CODE);
if (analyzer != null)
m.ANALYZE_CODE_NAME = analyzer.ANALYZER_NAME;
//状态码
var stateCode = stateCodeList.FirstOrDefault(x => x.STATE_CODE == m.STATE_CODE);
if (stateCode != null)
m.STATE_NAME = stateCode.STATE_NAME;
//创建人员
var userCreat = UserList.FirstOrDefault(x => x.UserID == m.CREATEUSER);
if (userCreat != null)
m.CREATEUSER_NAME = userCreat.UserName;
//更新人员
var userUpdate = UserList.FirstOrDefault(x => x.UserID == m.UPDATEUSER);
if (userUpdate != null)
m.UPDATEUSER_NAME = userUpdate.UserName;
}
#endregion
return p;
}
catch (Exception ex)
{
throw ex;
}
}
//获取状态码的下拉框
public List GetWorkCellStateCodeList(string workCellCode)
{
try
{
return new DaiDAL().GetWorkCellStateCodeList(workCellCode);
}
catch (Exception e)
{
throw e;
}
}
#endregion
#region 信息是否重复
///
/// 判断名称是否存在
///
/// 信息
/// true:已存在;fasel:不存在。
public bool Exists(Dai info)
{
try
{
return new DaiDAL().Exists(info);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
///
/// 插入信息(单表)
///
/// 信息
/// 插入行数
public DataResult Insert(Dai info)
{
DataResult result = new DataResult();
try
{
//基本信息
info.PID = Guid.NewGuid().ToString();
info.CREATEUSER = this.LoginUser.UserID;
info.CREATEDATE = DateTime.Now;
info.UPDATEUSER = info.CREATEUSER;
info.UPDATEDATE = info.CREATEDATE;
//if (Exists(info) == true)
//{
// result.IsSuccess = false;
// result.Msg = Resource.MaterielCodeIsHave;
// return result;
//}
DaiDAL cmdDAL = new DaiDAL();
result.Result = new DaiDAL().Insert(info);
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
///
/// 更新信息
///
/// 信息
/// 更新行数
public DataResult Update(Dai info)
{
DataResult result = new DataResult();
try
{
info.UPDATEUSER = this.LoginUser.UserID;
info.UPDATEDATE = DateTime.Now;
//if (Exists(info) == true)
//{
// result.IsSuccess = false;
// result.Msg = Resource.MaterielCodeIsHave;
// return result;
//}
result.Result = new DaiDAL().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 Dai { PID = str });
}
result.Result = count;
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
throw ex;
}
}
///
/// 删除信息
///
/// 信息
/// 删除个数
public int Delete(Dai info)
{
try
{
return new DaiDAL().Del(info);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}