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

1352 lines
51 KiB

using System;
using System.Collections.Generic;
using QMAPP.BLL;
using QMAPP.Entity;
using QMAPP.FJC.BLL.Dict;
using QMAPP.FJC.DAL.ProduceManage;
using QMAPP.FJC.Entity.ProduceManage;
using QMFrameWork.Data;
using QMFrameWork.Log;
using QMAPP.FJC.Entity;
using System.Data;
using System.Linq;
using QMAPP.FJC.DAL.Basic;
using QMAPP.FJC.Entity.Operation;
using QMAPP.FJC.DAL.Operation;
using QMAPP.FJC.Entity.Equipment;
using QMAPP.MD.BLL;
using QMAPP.MD.DAL;
using QMAPP.MD.Entity;
using Resource = QMAPP.FJC.Entity.Resource;
namespace QMAPP.FJC.BLL.ProduceManage
{
/// <summary>
/// 模块编号:
/// 作 用:返修记录
/// 作 者:王庆男
/// 编写日期:2015年06月24日
///</summary>
public class MendRecorderBLL : BaseBLL
{
#region 获取信息
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public MendRecorder Get(MendRecorder model)
{
try
{
return new MendRecorderDAL().Get(model);
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 获取信息
/// </summary>
/// <param name="">条件</param>
/// <returns>信息</returns>
public MendRecorder GetMendRecorderInfo(MendRecorder model)
{
try
{
MendRecorder entity = new MendRecorder();
entity = new MendRecorderDAL().GetMendRecorderInfo(model);
entity.reasonList = new MenderReasonDAL().GetList(new MenderReason() { PPID = entity.PID });
return entity;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 获取列表
/// <summary>
/// 获取列表winfrom
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataPage GetList(MendRecorder condition, DataPage page)
{
try
{
DataPage dataPage=new MendRecorderDAL().GetList(condition, page);
#region 转换零件类别、工序类别、返修结果、返修方式、返修原因显示类型
List<MendRecorder> mendRecorderList = dataPage.Result as List<MendRecorder>;
DictManageBLL dictHANDLEMETHOD = new DictManageBLL(DictKind.HANDLEMETHOD);
DictManageBLL dictProductTypeBll = new DictManageBLL(DictKind.PRODUCTTYPE);
DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE);
DictManageBLL dictMendResultBll = new DictManageBLL(DictKind.MENDRESULT);
DictManageBLL dictMendTypeBll = new DictManageBLL(DictKind.MENDTYPE);
DictManageBLL dictMendReasonBll = new DictManageBLL(DictKind.MENDREASON);
DictManageBLL dictRegisterStatusBll = new DictManageBLL(DictKind.REGISTERSTATUS);
//转换零件号和类型
var MaterialList = new MaterialBLL().GetAllList(new Material());
var MaterialClassList = new MaterialBLL().GetAllMaterialClassList(new MaterialClass());
//转换ERP
var erpCodes = GetMFGCODES("");
foreach (MendRecorder m in mendRecorderList)
{
//处理方法
m.HANDLEMETHODTXT = dictHANDLEMETHOD.GetDictValue(m.HANDLEMETHOD);
//零件类别
m.PRODUCTTYPETXT = dictProductTypeBll.GetDictValue(m.PRODUCTTYPE);
//工序类别
m.CURRENTPROCESSTXT = dictProcessTypeBll.GetDictValue(m.CURRENTPROCESS);
//返修结果
m.MENDRESULTTXT = dictMendResultBll.GetDictValue(m.MENDRESULT);
//返修方式
m.MENDTYPETXT = dictMendTypeBll.GetDictValue(m.MENDTYPE);
//登记状态
m.REGISTERSTATUSTXT = dictRegisterStatusBll.GetDictValue(m.REGISTERSTATUS);
//零件
var material = MaterialList.FirstOrDefault(x => x.MATERIAL_CODE == m.MATERIAL_CODE);
if (material != null)
m.MATERIAL_NAME = material.MATERIAL_NAME;
//零件类型
var materialClass = MaterialClassList.FirstOrDefault(x => x.MATERIAL_TYPE_CODE == m.MATERIAL_TYPE_CODE);
if (materialClass != null)
m.MATERIAL_TYPE_NAME = materialClass.MATERIAL_TYPE_NAME;
//erp
var erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_MFGCODETYPE);
if (erpcode != null)
m.ERP_MFGCODETYPE = erpcode.ERP_NAME ;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_CAR);
if (erpcode != null)
m.ERP_CAR = erpcode.ERP_NAME ;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_WORKLINE);
if (erpcode != null)
m.ERP_WORKLINE = erpcode.ERP_NAME ;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_SHIFT);
if (erpcode != null)
m.ERP_SHIFT = erpcode.ERP_NAME ;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_WORKCELL);
if (erpcode != null)
m.ERP_WORKCELL = erpcode.ERP_NAME ;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_DEFECTTO);
if (erpcode != null)
m.ERP_DEFECTTO = erpcode.ERP_NAME ;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_PRODUCTTYPE);
if (erpcode != null)
m.ERP_PRODUCTTYPE = erpcode.ERP_NAME ;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_DEFECTCODE);
if (erpcode != null)
m.ERP_DEFECTCODE = erpcode.ERP_NAME ;
}
#endregion
return dataPage;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录-获取列表!"
});
throw ex;
}
}
/// <summary>
/// 获取列表web
/// </summary>
/// <param name="condition">条件</param>
/// <param name="page">数据页</param>
/// <returns>数据页</returns>
public DataResult<DataPage> GetLists(MendRecorder condition, DataPage page)
{
DataResult<DataPage> result = new DataResult<DataPage>();
try
{
DataPage dataPage = new MendRecorderDAL().GetList(condition, page);
#region 转换零件类别、工序类别、返修结果、返修方式、返修原因显示类型
List<MendRecorder> mendRecorderList = dataPage.Result as List<MendRecorder>;
DictManageBLL dictHANDLEMETHOD = new DictManageBLL(DictKind.HANDLEMETHOD);
DictManageBLL dictProductTypeBll = new DictManageBLL(DictKind.PRODUCTTYPE);
DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE);
DictManageBLL dictMendResultBll = new DictManageBLL(DictKind.MENDRESULT);
DictManageBLL dictMendTypeBll = new DictManageBLL(DictKind.MENDTYPE);
//DictManageBLL dictMendReasonBll = new DictManageBLL(DictKind.MENDREASON);
DictManageBLL dictMendStatusSBll = new DictManageBLL(DictKind.REGISTERSTATUS);
//转换零件号和类型
//var MaterialList = new MaterialBLL().GetAllList(new Material());
//var MaterialClassList = new MaterialBLL().GetAllMaterialClassList(new MaterialClass());
//var MachineInfos = new MachineInfoDAL().GetMachineInfos();
//转换ERP
var erpCodes = GetMFGCODES("");
foreach (MendRecorder m in mendRecorderList)
{
//处理方法
m.HANDLEMETHODTXT = dictHANDLEMETHOD.GetDictValue(m.HANDLEMETHOD);
//零件类别
m.PRODUCTTYPE = dictProductTypeBll.GetDictValue(m.PRODUCTTYPE);
//工序类别
m.CURRENTPROCESS = dictProcessTypeBll.GetDictValue(m.CURRENTPROCESS);
//返修结果
m.MENDRESULT = dictMendResultBll.GetDictValue(m.MENDRESULT);
//返修方式
m.MENDTYPE = dictMendTypeBll.GetDictValue(m.MENDTYPE);
//返修状态
m.REGISTERSTATUS = dictMendStatusSBll.GetDictValue(m.REGISTERSTATUS);
//零件
m.OUTSOURCE = m.OUTSOURCE == "1" ? "采购件" : "生产件";
//var material = MaterialList.FirstOrDefault(x => x.MATERIAL_CODE == m.MATERIAL_CODE);
//if (material != null)
//{
// m.MATERIAL_NAME = material.MATERIAL_NAME;
// m.OUTSOURCE = material.OUTSOURCE == "1" ? "采购件" : "生产件";
//}
////零件类型
//var materialClass = MaterialClassList.FirstOrDefault(x => x.MATERIAL_TYPE_CODE == m.MATERIAL_TYPE_CODE);
//if (materialClass != null)
// m.MATERIAL_TYPE_NAME = materialClass.MATERIAL_TYPE_NAME;
//设备名称转换
//var MachineInfo = MachineInfos.FirstOrDefault(x => x.MACHINECODDE == m.MACHINECODDE);
//if (MachineInfo != null)
// m.MACHINENAME = MachineInfo.MACHINENAME;
//erp
var erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_MFGCODETYPE&&x.ERP_MFGCODETYPE=="MENDTYPE");
if (erpcode != null)
m.ERP_MFGCODETYPE = erpcode.ERP_NAME ;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_CAR&&x.ERP_MFGCODETYPE=="CAR");
if (erpcode != null)
m.ERP_CAR = erpcode.ERP_NAME ;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_WORKLINE && x.ERP_MFGCODETYPE == "WORKLINE");
if (erpcode != null)
m.ERP_WORKLINE = erpcode.ERP_NAME ;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_SHIFT && x.ERP_MFGCODETYPE == "SHIFT");
if (erpcode != null)
m.ERP_SHIFT = erpcode.ERP_NAME ;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_WORKCELL && x.ERP_MFGCODETYPE == "WORKCELL");
if (erpcode != null)
m.ERP_WORKCELL = erpcode.ERP_NAME ;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_DEFECTTO && x.ERP_MFGCODETYPE == "DEFECTTO");
if (erpcode != null)
m.ERP_DEFECTTO = erpcode.ERP_NAME ;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_PRODUCTTYPE && x.ERP_MFGCODETYPE == "PRODUCTTYPE");
if (erpcode != null)
m.ERP_PRODUCTTYPE = erpcode.ERP_NAME ;
erpcode = erpCodes.FirstOrDefault(x => x.ERP_CODE == m.ERP_DEFECTCODE && x.ERP_MFGCODETYPE == "DEFECTCODE");
if (erpcode != null)
m.ERP_DEFECTCODE = erpcode.ERP_NAME ;
}
#endregion
result.Result = dataPage;
result.IsSuccess = true;
return result;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录-获取列表!"
});
throw ex;
}
}
#endregion
#region 信息是否重复
/// <summary>
/// 判断名称是否存在
/// </summary>
/// <param name="info"></param>
/// <returns>true:已存在;fasel:不存在。</returns>
public bool ExistsMendRecorder(MendRecorder model)
{
try
{
return new MendRecorderDAL().ExistsMendRecorder(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public int Insert(MendRecorder model)
{
try
{
//基本信息
model.PID = Guid.NewGuid().ToString();
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSER = model.CREATEUSER;
model.UPDATEDATE = model.CREATEDATE;
MendRecorderDAL cmdDAL = new MendRecorderDAL();
if (ExistsMendRecorder(model) == true)
return -1;
return new MendRecorderDAL().Insert(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public int Update(MendRecorder model)
{
try
{
//if (ExistsMendRecorder(Model) == true)
//return -1;
//基本信息
model.UPDATEUSER = this.LoginUser.UserID;
return new MendRecorderDAL().Update(model);
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 删除
/// <summary>
/// 删除信息
/// </summary>
/// <param name=""></param>
/// <returns>删除个数</returns>
public int Delete(string strs)
{
int count = 0;
string[] list = strs.Split(":".ToCharArray());
try
{
foreach (string str in list)
{
count += this.DeleteMendRecorder(new MendRecorder { PID = str });
}
return count;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 删除信息
/// </summary>
/// <param name="">信息</param>
/// <returns>删除个数</returns>
public int DeleteMendRecorder(MendRecorder model)
{
int count = 0;
try
{
count = new MendRecorderDAL().Delete(model);
return count;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
#region 导出数据
/// <summary>
/// 获取导出的数据
/// </summary>
/// <param name="user">查询条件</param>
/// <returns>数据</returns>
public DataResult<DataTable> GetExportData(MendRecorder model)
{
DataResult<DataTable> result = new DataResult<DataTable>();
try
{
DataTable dt = new MendRecorderDAL().GetExportData(model);
#region 转换零件类别、工序类别、返修结果、返修方式、返修原因显示类型
DictManageBLL dictProductTypeBll = new DictManageBLL(DictKind.PRODUCTTYPE);
DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE);
DictManageBLL dictMendResultBll = new DictManageBLL(DictKind.MENDRESULT);
DictManageBLL dictMendTypeBll = new DictManageBLL(DictKind.MENDTYPE);
DictManageBLL dictHANDLEMETHOD = new DictManageBLL(DictKind.HANDLEMETHOD);
DictManageBLL dictMendStatusSBll = new DictManageBLL(DictKind.REGISTERSTATUS);
//var MachineInfos = new MachineInfoDAL().GetMachineInfos();
foreach (DataRow item in dt.Rows)
{
//零件类别
item["PRODUCTTYPE"] = dictProductTypeBll.GetDictValue(item["PRODUCTTYPE"].ToString());
//工序类别
item["CURRENTPROCESS"] = dictProcessTypeBll.GetDictValue(item["CURRENTPROCESS"].ToString());
//返修结果
item["MENDRESULT"] = dictMendResultBll.GetDictValue(item["MENDRESULT"].ToString());
//返修方式
item["MENDTYPE"] = dictMendTypeBll.GetDictValue(item["MENDTYPE"].ToString());
//返修状态
item["REGISTERSTATUS"] = dictMendStatusSBll.GetDictValue(item["REGISTERSTATUS"].ToString());
//处理方法
item["HANDLEMETHOD"] = dictHANDLEMETHOD.GetDictValue(item["HANDLEMETHOD"].ToString());
//零件
item["OUTSOURCE"] = item["OUTSOURCE"] == "1" ? "采购件" : "生产件";
//设备名称转换
//var MachineInfo = MachineInfos.FirstOrDefault(x => x.MACHINECODDE == item["MACHINECODDE"]);
//if (MachineInfo != null)
// item["MACHINENAME"] = MachineInfo.MACHINENAME;
}
#endregion
result.Result = dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录-导出数据!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
public DataResult<DataTable> GetExportDataScrap(MendRecorder model)
{
DataResult<DataTable> result = new DataResult<DataTable>();
try
{
DataTable dt = new MendRecorderDAL().GetExportDataScrap(model);
result.Result = dt;
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录-导出数据!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#region 返修(工控机)
#region 插入信息
/// <summary>
/// 插入信息(单表)
/// </summary>
/// <param name="">信息</param>
/// <returns>插入行数</returns>
public DataResult<int> InsertMendRecorder(MendRecorder model)
{
DataResult<int> result = new DataResult<int>();
try
{
//基本信息
model.PID = Guid.NewGuid().ToString();
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSER = model.CREATEUSER;
model.UPDATEDATE = model.CREATEDATE;
if (ExistsMendRecorder(model) == true)
{
result.IsSuccess = false;
result.Msg = Resource.IsHaving;
}
else
{
result.Result = new MendRecorderDAL().Insert(model);
if (result.Result > 0)
{
result.IsSuccess = true;
result.Msg = Resource.SaveMessge;
}
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录逻辑层-插入信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
public DataResult<int> InsertMendRecordItem(Product product, List<DefectType> defectTypeList)
{
DataResult<int> result = new DataResult<int>();
List<MenderReason> reasonList = new List<MenderReason>();
try
{
MendRecorder model = new MendRecorder();
//基本信息
model.PID = Guid.NewGuid().ToString();
model.PPID = product.PID;
model.PRODUCTCODE = product.PRODUCTCODE;
model.PRODUCTTYPE = product.PRODUCTTYPE;
model.CURRENTPROCESS = product.CURRENTPROCESS;
model.PRODUCELINE = product.PRODUCELINE;
model.MENDRESULT = product.STATUS;
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSER = model.CREATEUSER;
model.UPDATEDATE = model.CREATEDATE;
model.PRODUCESHIFTTCODE = product.PRODUCESHIFTTCODE;
foreach (var defect in defectTypeList)
{
reasonList.Add(new MenderReason()
{
PID = Guid.NewGuid().ToString(),
PPID = model.PID,
DEFECTKEY = defect.DEFECTKEY,
DEFECTVALUE = defect.DEFECTVALUE,
POSITION=defect.POSITION,
CREATEUSER = this.LoginUser.UserID,
CREATEDATE = DateTime.Now,
UPDATEUSER = model.CREATEUSER,
UPDATEDATE = model.CREATEDATE
});
}
MainDAL maindal = new MainDAL();
ProductDAL productDal = new ProductDAL();
Main main = new Main();
Product entity = new Product();
//本体
if (product.PRODUCTTYPE == EnumGeter.ProductType.benti.GetHashCode().ToString())
{
main = maindal.Get(new Main() { PID = product.PID });
main.STATUS = product.STATUS;
MainOperationDAL modal = new MainOperationDAL();
MainOperation moEntity = modal.GetMainOperation(new MainOperation { PDID = main.PID, PROCESSTYPE = EnumGeter.ProcessType.jiaozhu.GetHashCode().ToString() });
if (moEntity != null && string.IsNullOrEmpty(moEntity.PID) == false)
{
model.MOLDNUMBER = moEntity.MOLDNUMBER;
}
}
else
{
//零部件
entity = productDal.Get(new Product() { PID = product.PID });
entity.STATUS = product.STATUS;
model.MOLDNUMBER = "1";
}
MendRecorderDAL menderDal = new MendRecorderDAL();
MenderReasonDAL reasonDal = new MenderReasonDAL();
//MendRecorderDAL
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
menderDal.BaseSession = session;
reasonDal.BaseSession = session;
menderDal.Insert(model);
if (product.PRODUCTTYPE == EnumGeter.ProductType.benti.GetHashCode().ToString())
{
maindal.BaseSession = session;
maindal.Update(main);
}
else
{
productDal.BaseSession = session;
productDal.Update(entity);
}
foreach (var r in reasonList)
{
reasonDal.Insert(r);
}
session.CommitTs();
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录逻辑层-插入信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
//新方法加入main查询 zxd20171221
public DataResult<int> InsertMendRecordItemNew(Product product, List<DefectType> defectTypeList)
{
DataResult<int> result = new DataResult<int>();
List<MenderReason> reasonList = new List<MenderReason>();
try
{
MendRecorder model = new MendRecorder();
//基本信息
model.PID = Guid.NewGuid().ToString();
model.PPID = product.PID;
model.PRODUCTCODE = product.PRODUCTCODE;
model.PRODUCTTYPE = product.PRODUCTTYPE;
model.CURRENTPROCESS = product.CURRENTPROCESS;
model.PRODUCELINE = product.PRODUCELINE;
model.MENDRESULT = product.STATUS;
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSER = model.CREATEUSER;
model.UPDATEDATE = model.CREATEDATE;
model.PRODUCESHIFTTCODE = product.PRODUCESHIFTTCODE;
model.MATERIAL_TYPE_CODE = product.MATERIAL_TYPE;
model.MATERIAL_CODE = product.MATERIAL_CODE;
model.WORKCENTER_CODE = product.WORKCENTER_CODE;
model.MENDTEST = product.MENDTEST;
model.MENDDUTY = product.MENDDUTY;
model.WORKCELL_CODE = product.WORKCELL_CODE;
model.HANDLEMETHOD = product.HANDLEMETHOD;
model.MENDNUMBER = 1;
//前台获取工序下拉框时获取了,下面屏蔽。
model.BATCH_NO = product.BATCH_NO;
model.SHIFT_CODE = product.SHIFT_CODE;
model.MACHINECODDE = product.MACHINECODDE;
//ERP数据
model.ERP_MFGCODETYPE = product.ERP_MFGCODETYPE;
model.ERP_CAR = product.ERP_CAR;
model.ERP_WORKLINE = product.ERP_WORKLINE;
model.ERP_SHIFT = product.ERP_SHIFT;
model.ERP_WORKCELL = product.ERP_WORKCELL;
model.ERP_DEFECTTO = product.ERP_DEFECTTO;
model.ERP_PRODUCTTYPE = product.ERP_PRODUCTTYPE;
model.ERP_DEFECTCODE = product.ERP_DEFECTCODE;
if (string.IsNullOrEmpty(model.ERP_DEFECTCODE) && defectTypeList.Count > 0)
{
model.ERP_DEFECTCODE = defectTypeList[0].DEFECTKEY;
}
//获取MainOperation里的创建时间赋值给BATCH_NO字段,用于统计不合格率。
//var mo = new MainOperationDAL().GetMainOperation(new MainOperation
//{
// PDID = product.PID
//});
//if (mo!=null)
//{
// model.BATCH_NO = mo.UPDATEDATE.ToString("yyyyMMdd");
// //生产班次
// model.SHIFT_CODE = mo.PRODUCESHIFTTCODE;
//}
//根据当前时间获取班次--自动获取班次
var shift= new QMAPP.FJC.BLL.Basic.ProduceShiftBLL().GetWorkingShift(model.WORKCENTER_CODE);
model.PRODUCESHIFTTCODE = shift != null ? shift.PRODUCESHIFTTCODE : "";
foreach (var defect in defectTypeList)
{
reasonList.Add(new MenderReason()
{
PID = Guid.NewGuid().ToString(),
PPID = model.PID,
DEFECTKEY = defect.DEFECTKEY,
DEFECTVALUE = defect.DEFECTVALUE,
POSITION = defect.POSITION,
CREATEUSER = this.LoginUser.UserID,
CREATEDATE = DateTime.Now,
UPDATEUSER = model.CREATEUSER,
UPDATEDATE = model.CREATEDATE
});
//缺陷只取一条,存进主表. 20180607 zxd
model.MENDREASON = defect.DEFECTVALUE;
}
MainDAL maindal = new MainDAL();
ProductDAL productDal = new ProductDAL();
//Main main = new Main();
Product entity = new Product();
//本体
//if (product.PRODUCTTYPE == EnumGeter.ProductType.benti.GetHashCode().ToString())
//{
//main = maindal.Get(new Main() { PID = product.MID });
//main.STATUS = product.STATUS;
//MainOperationDAL modal = new MainOperationDAL();
//MainOperation moEntity = modal.GetMainOperation(new MainOperation { PDID = main.PID, PROCESSTYPE = EnumGeter.ProcessType.jiaozhu.GetHashCode().ToString() });
//if (moEntity != null && string.IsNullOrEmpty(moEntity.PID) == false)
//{
// model.MOLDNUMBER = moEntity.MOLDNUMBER;
//}
//}
//else
//{
//零部件
//entity = productDal.Get(new Product() { PID = product.PID });
//entity.STATUS = product.STATUS;
model.MOLDNUMBER = "1";
//}
//main表
//if (product.isOk==0)
//{
// main = maindal.Get(new Main() { PID = product.MID });
// main.STATUS = product.STATUS;
//}
//product表
entity = productDal.Get(new Product() { PID = product.PID });
entity.STATUS = product.STATUS;
MendRecorderDAL menderDal = new MendRecorderDAL();
MenderReasonDAL reasonDal = new MenderReasonDAL();
//MendRecorderDAL
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
menderDal.BaseSession = session;
reasonDal.BaseSession = session;
menderDal.Insert(model);
//if (product.PRODUCTTYPE == EnumGeter.ProductType.benti.GetHashCode().ToString())
//{
// maindal.BaseSession = session;
// maindal.Update(main);
//}
//else
//{
// productDal.BaseSession = session;
// productDal.Update(entity);
//}
//更新main
//if (product.isOk == 0)
//{
// //maindal.BaseSession = session;
// //maindal.Update(main);
//}
//更新product
productDal.BaseSession = session;
productDal.Update(entity);
//存缺陷信息表,用于明细进入显示。20180607 zxd
foreach (var r in reasonList)
{
reasonDal.Insert(r);
}
session.CommitTs();
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录逻辑层-插入信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
//批量报废 zxd20180205
public DataResult<int> InsertMendRecordItemNewNew(MendRecorder model, List<DefectType> defectTypeList)
{
DataResult<int> result = new DataResult<int>();
List<MenderReason> reasonList = new List<MenderReason>();
try
{
//MendRecorder model = new MendRecorder();
//基本信息
model.PID = Guid.NewGuid().ToString();
//model.PPID = product.PID;
//model.PRODUCTCODE = product.PRODUCTCODE;
//model.PRODUCTTYPE = product.PRODUCTTYPE;
//model.CURRENTPROCESS = product.CURRENTPROCESS;
//model.PRODUCELINE = product.PRODUCELINE;
model.CREATEUSER = this.LoginUser.UserID;
model.CREATEDATE = DateTime.Now;
model.UPDATEUSER = model.CREATEUSER;
model.UPDATEDATE = model.CREATEDATE;
//model.PRODUCESHIFTTCODE = product.PRODUCESHIFTTCODE;
//model.MATERIAL_TYPE_CODE = product.MATERIAL_TYPE_CODE;
//model.MATERIAL_CODE = product.MATERIAL_CODE;
//model.WORKCENTER_CODE = product.WORKCENTER_CODE;
//报废状态
model.MENDRESULT = "2";
//model.MENDNUMBER = product.MENDNUMBER;
//model.BATCH_NO = product.BATCH_NO;
//model.MENDTEST = product.MENDTEST;
//model.MENDDUTY = product.MENDDUTY;
//model.WORKCELL_CODE = product.WORKCELL_CODE;
//model.SHIFT_CODE = product.SHIFT_CODE;
//根据当前时间获取班次--自动获取班次
//通过bom获取工作中心
var workCenterCode = new WorkCellDAL().GetWorkcenterWithMaterial(model.MATERIAL_CODE);
if (!string.IsNullOrEmpty(workCenterCode))
{
model.WORKCENTER_CODE = workCenterCode;
}
var shift = new QMAPP.FJC.BLL.Basic.ProduceShiftBLL().GetWorkingShift(model.WORKCENTER_CODE);
model.PRODUCESHIFTTCODE = shift != null ? shift.PRODUCESHIFTTCODE : "";
foreach (var defect in defectTypeList)
{
reasonList.Add(new MenderReason()
{
PID = Guid.NewGuid().ToString(),
PPID = model.PID,
DEFECTKEY = defect.DEFECTKEY,
DEFECTVALUE = defect.DEFECTVALUE,
POSITION = defect.POSITION,
CREATEUSER = this.LoginUser.UserID,
CREATEDATE = DateTime.Now,
UPDATEUSER = model.CREATEUSER,
UPDATEDATE = model.CREATEDATE
});
model.MENDREASON = defect.DEFECTVALUE;
}
MendRecorderDAL menderDal = new MendRecorderDAL();
MenderReasonDAL reasonDal = new MenderReasonDAL();
//MendRecorderDAL
using (IDataSession session = AppDataFactory.CreateMainSession())
{
session.OpenTs();
menderDal.BaseSession = session;
reasonDal.BaseSession = session;
menderDal.Insert(model);
foreach (var r in reasonList)
{
reasonDal.Insert(r);
}
session.CommitTs();
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录逻辑层-插入信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
//根据当前时间获取班次--自动获取班次
private string getShiftCode_()
{
var shifts = new ShiftDAL().GetAllShift(new Shift__());
string day = DateTime.Now.ToString("HH:mm:ss");
string shift = "";
foreach (var sf in shifts)
{
if (DateTime.Parse(sf.WORK_START_TIME.ToString("HH:mm:ss")) <= DateTime.Parse(day) && DateTime.Parse(sf.WORK_END_TIME.ToString("HH:mm:ss")) >= DateTime.Parse(day))
{
//保修班次
return sf.SHIFT_CODE;
}
}
return null;
}
#endregion
#region 更新信息
/// <summary>
/// 更新信息
/// </summary>
/// <param name=""></param>
/// <returns>更新行数</returns>
public DataResult<int> UpdateMendRecorder(MendRecorder model)
{
DataResult<int> result = new DataResult<int>();
try
{
//基本信息
model.UPDATEUSER = this.LoginUser.UserID;
result.Result = new MendRecorderDAL().Update(model);
if (result.Result > 0)
{
result.IsSuccess = true;
result.Msg = Resource.SaveMessge;
}
}
catch (Exception ex)
{
LogManager.LogHelper.Error(new LogInfo()
{
ErrorInfo = ex,
Tag = ex.StackTrace,
Info = "返修记录逻辑层-更新信息!"
});
result.IsSuccess = false;
result.Msg = Resource.SystemException;
throw ex;
}
result.IsSuccess = true;
return result;
}
#endregion
#endregion
public DataResult<Product> CheckProductCode(string productCode)
{
DataResult<Product> result = new DataResult<Product>();
result.IsSuccess=true;
DictManageBLL dicStatus = new DictManageBLL(DictKind.STATUS);
DictManageBLL dicProcess = new DictManageBLL(DictKind.PROCESSTYPE);
DictManageBLL dicProductType = new DictManageBLL(DictKind.PRODUCTTYPE);
ProductDAL productDal = new ProductDAL();
Product product = productDal.GetProductInfo(new Product() { PRODUCTCODE = productCode });
//条码不存在
//提示
if (product == null)
{
result.IsSuccess = false;
result.Msg = "该条码不存在!";
result.Result = product;
return result;
}
if (product.USINGSTATE == EnumGeter.USINGSTATE.UNUSED.GetHashCode().ToString())
{
product.STATUSNAME = dicStatus.GetDictValue(product.STATUS);
product.CURRENTPROCESSNAME = dicProcess.GetDictValue(product.CURRENTPROCESS);
product.PRODUCTTYPENAME = dicProductType.GetDictValue(product.PRODUCTTYPE);
result.Result = product;
return result;
}
else
{
if (product.PRODUCTTYPE != EnumGeter.ProductType.biaopi.GetHashCode().ToString())
{
result.IsSuccess = false;
result.Msg = "该产品已使用,请对本体件进行返修操作!";
result.Result = product;
}
else
{
//本体件
MainDAL mainDal = new MainDAL();
Main main = mainDal.GetMain(new Main() { EPIDERMISCODE = product.PRODUCTCODE });
product.CURRENTPROCESS = main.CURRENTPROCESS;
product.STATUS = main.STATUS;
product.STATUSNAME = dicStatus.GetDictValue(product.STATUS);
product.CURRENTPROCESSNAME = dicProcess.GetDictValue(product.CURRENTPROCESS);
product.PRODUCTTYPE = EnumGeter.ProductType.benti.GetHashCode().ToString();
product.PRODUCTTYPENAME = dicProductType.GetDictValue(product.PRODUCTTYPE);
product.PID = main.PID;
result.Result = product;
}
}
return result;
}
//新方法,添加main表查询 zxd 20171221
public DataResult<Product> CheckProductCodeNew(string productCode)
{
DataResult<Product> result = new DataResult<Product>();
result.IsSuccess = true;
DictManageBLL dicStatus = new DictManageBLL(DictKind.STATUS);
DictManageBLL dicProcess = new DictManageBLL(DictKind.PROCESSTYPE);
DictManageBLL dicProductType = new DictManageBLL(DictKind.PRODUCTTYPE);
ProductDAL productDal = new ProductDAL();
Product productMain = productDal.GetProductInfoNew(new Product() { PRODUCTCODE = productCode });
//是否成品
if (productMain == null)
{
Product product = productDal.GetProductInfo(new Product() { PRODUCTCODE = productCode });
//条码不存在
//提示
if (product == null)
{
result.IsSuccess = false;
result.Msg = "该条码不存在!";
result.Result = null;
return result;
}
productMain = product;
//在制品
productMain.isOk = 1;
}
//不在库
if (productMain.USINGSTATE != EnumGeter.OUTFLAG.INWAREHOUSE.GetHashCode().ToString())
{
result.IsSuccess = false;
result.Msg = "该条码不在库!";
result.Result = null;
return result;
}
//在制品
if (productMain.isOk == 1)
{
//不是未使用状态
if (productMain.USINGSTATE != EnumGeter.USINGSTATE.UNUSED.GetHashCode().ToString())
{
result.IsSuccess = false;
result.Msg = "该条码不是未使用状态!";
result.Result = null;
return result;
}
}
var teamMember = new TeamMemberBLL().GetAllTeamMember(new TeamMemberEntity { MEMBER_CODE = LoginUser.UserID }).FirstOrDefault();
if (teamMember != null)
{
productMain.TEAM_CODE = teamMember.TEAM_CODE.Trim();
}
productMain.STATUSNAME = dicStatus.GetDictValue(productMain.STATUS);
productMain.CURRENTPROCESSNAME = dicProcess.GetDictValue(productMain.CURRENTPROCESS);
productMain.PRODUCTTYPENAME = dicProductType.GetDictValue(productMain.PRODUCTTYPE);
result.Result = productMain;
return result;
//if (productMain.USINGSTATE == EnumGeter.USINGSTATE.UNUSED.GetHashCode().ToString())
//{
//}
//else
//{
// if (productMain.PRODUCTTYPE != EnumGeter.ProductType.biaopi.GetHashCode().ToString())
// {
// result.IsSuccess = false;
// result.Msg = "该产品已使用,请对本体件进行返修操作!";
// result.Result = productMain;
// }
// else
// {
// //本体件
// MainDAL mainDal = new MainDAL();
// Main main = mainDal.GetMain(new Main() { EPIDERMISCODE = productMain.PRODUCTCODE });
// productMain.CURRENTPROCESS = main.CURRENTPROCESS;
// productMain.STATUS = main.STATUS;
// productMain.STATUSNAME = dicStatus.GetDictValue(productMain.STATUS);
// productMain.CURRENTPROCESSNAME = dicProcess.GetDictValue(productMain.CURRENTPROCESS);
// productMain.PRODUCTTYPE = EnumGeter.ProductType.benti.GetHashCode().ToString();
// productMain.PRODUCTTYPENAME = dicProductType.GetDictValue(productMain.PRODUCTTYPE);
// productMain.PID = main.PID;
// result.Result = productMain;
// }
//}
//return result;
}
public List<MenderReason> GetMenderReasonList(MenderReason condition)
{
List<MenderReason> list = new MenderReasonDAL().GetList(condition);
return list;
}
public MendRecorder GetMaterialTeam(string MaterialCode)
{
//获取车型代码(项目代码)
var mendRecorder = new MenderReasonDAL().GetMaterialTeam(MaterialCode);
//获取班组代码
var teamMember = new TeamMemberBLL().GetAllTeamMember(new TeamMemberEntity { MEMBER_CODE = LoginUser.UserID }).FirstOrDefault();
if (teamMember != null)
{
mendRecorder.TEAM_CODE = teamMember.TEAM_CODE;
}
return mendRecorder;
}
//获取生产线
public MendRecorder GetWorkLine(string workCellCode)
{
//获取车型代码(项目代码)
var mendRecorder = new MenderReasonDAL().GetWorkLine(workCellCode);
return mendRecorder;
}
public DataResult<DataTable> GetListForstatistic(MendRecorder condition)
{
DataResult<DataTable> result = new DataResult<DataTable>();
result.IsSuccess = true;
DataTable dt = new DataTable();
dt = new MendRecorderDAL().GetListForstatistic(condition);
result.Result = dt;
return result;
}
public MainOperation GetMianOperationInfo(string pdid)
{
MendRecorderDAL mendDal = new MendRecorderDAL();
MainOperation result = mendDal.GetMianOperationInfo(new MainOperation() { PDID = pdid });
return result;
}
#region 获取统计信息填充图表
/// <summary>
/// 获取统计信息填充图表
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public DataResult<List<MendRecorder>> GetMendRecorderStatistics(MendRecorder condition)
{
DataResult<List<MendRecorder>> result = new DataResult<List<MendRecorder>>();
MendRecorderDAL dal = new MendRecorderDAL();
List<MendRecorder> list = dal.GetMendRecorderStatistics(condition);
result.Result = list;
result.IsSuccess = true;
return result;
}
#endregion
#region 获取统计信息导出
/// <summary>
/// 获取统计信息填充图表
/// </summary>
/// <param name="condition"></param>
/// <returns></returns>
public DataResult<DataTable> ExportMendRecorderStatistics(MendRecorder condition)
{
DataResult<DataTable> result = new DataResult<DataTable>();
MendRecorderDAL dal = new MendRecorderDAL();
DataTable dt = dal.ExportMendRecorderStatistics(condition);
result.Result = dt;
result.IsSuccess = true;
return result;
}
#endregion
#region 获取返修信息-ERP
/// <summary>
/// 获取某个返修类型的数据-ERP
/// </summary>
/// <returns></returns>
public List<MendRecorder> GetMFGCODES(string MFGCODETYPE)
{
List<MendRecorder> list = new MendRecorderDAL().GetMFGCODES(MFGCODETYPE);
//if (!string.IsNullOrEmpty(MFGCODETYPE))
//{
// foreach (MendRecorder item in list)
// {
// item.ERP_NAME = item.ERP_CODE + "/" + item.ERP_NAME.Replace("\t", "");
// //list.Add(item);
// }
//}
//else
//{
// foreach (MendRecorder item in list)
// {
// item.ERP_NAME = item.ERP_NAME.Replace("\t","");
// //list.Add(item);
// }
//}
foreach (MendRecorder item in list)
{
item.ERP_NAME = item.ERP_CODE + "/" + item.ERP_NAME.Replace("\t", "");
//item.ERP_NAME = item.ERP_CODE + "/" + item.ERP_NAME;
}
list.Insert(0, new MendRecorder() { ERP_CODE = "", ERP_NAME = " " });
return list;
}
#endregion
#region 导出界面上数据
public DataTable GetCheckStatic(MendRecorder model)
{
try
{
DataTable dt = new MendRecorderDAL().ExportExcelData(model);
#region 转换
DictManageBLL dictMENDRESULT = new DictManageBLL(DictKind.MENDRESULT);
DictManageBLL dictHANDLEMETHOD = new DictManageBLL(DictKind.HANDLEMETHOD);
foreach (DataRow dr in dt.Rows)
{
//替换状态类别显示值
dr["MENDRESULT"] = dictMENDRESULT.GetDictValue(dr["MENDRESULT"].ToString());
//处理方法
dr["HANDLEMETHOD"] = dictHANDLEMETHOD.GetDictValue(dr["HANDLEMETHOD"].ToString());
//生产件/采购价
dr["OUTSOURCE"] = dr["OUTSOURCE"] == "1" ? "采购件" : "生产件";
}
#endregion
//根据所选信息进行导出
if (string.IsNullOrEmpty(model.PIDList) == false)
{
model.PIDList = "'" + model.PIDList.Replace(":", "','") + "'";
DataView dv = new DataView(dt);
dv.RowFilter = "PID in (" + model.PIDList + ")";
dt = dv.ToTable();
}
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
}
}