using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMAPP.BLL; using QMAPP.Entity; using QMAPP.FJC.Entity.ProduceManage; using QMFrameWork.Data; using QMFrameWork.Log; using QMAPP.FJC.Entity; using QMAPP.FJC.Entity.Operation; using QMAPP.FJC.DAL.ProduceManage; using QMAPP.FJC.BLL.Dict; using QMAPP.FJC.DAL.Operation; using System.Data; using QMAPP.MD.BLL; using QMAPP.MD.Entity; using Resource = QMAPP.FJC.Entity.Resource; namespace QMAPP.FJC.BLL.ProduceManage { public class ScrapRecordBLL : BaseBLL { #region 获取信息 /// /// 获取信息 /// /// 条件 /// 信息 public MendRecorder Get(MendRecorder model) { try { return new ScrapRecordDAL().Get(model); } catch (Exception ex) { throw ex; } } /// /// 获取信息 /// /// 条件 /// 信息 public MendRecorder GetMendRecorderInfo(MendRecorder model) { try { MendRecorder entity = new MendRecorder(); entity = new ScrapRecordDAL().GetMendRecorderInfo(model); entity.reasonList = new MenderReasonDAL().GetList(new MenderReason() { PPID = entity.PID }); return entity; } catch (Exception ex) { throw ex; } } #endregion #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataPage GetList(MendRecorder condition, DataPage page) { try { DataPage dataPage = new ScrapRecordDAL().GetList(condition, page); #region 转换零件类别、工序类别、返修结果、返修方式、返修原因显示类型 List mendRecorderList = dataPage.Result as List; 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); foreach (MendRecorder m in mendRecorderList) { //零件类别 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.MENDREASONTXT = dictMendTypeBll.GetDictValue(m.MENDREASON); //登记状态 m.REGISTERSTATUSTXT = dictRegisterStatusBll.GetDictValue(m.REGISTERSTATUS); } #endregion return dataPage; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "返修记录-获取列表!" }); throw ex; } } /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataResult GetLists(MendRecorder condition, DataPage page) { DataResult result = new DataResult(); try { DataPage dataPage = new ScrapRecordDAL().GetList(condition, page); #region 转换零件类别、工序类别、返修结果、返修方式、返修原因显示类型 List mendRecorderList = dataPage.Result as List; 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 erpCodes = new MendRecorderBLL().GetMFGCODES(""); foreach (MendRecorder m in mendRecorderList) { //零件类别 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.MENDREASON = dictMendReasonBll.GetDictValue(m.MENDREASON); //返修状态 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; ////零件类型 //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 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 信息是否重复 /// /// 判断名称是否存在 /// /// /// true:已存在;fasel:不存在。 public bool ExistsMendRecorder(MendRecorder model) { try { return new ScrapRecordDAL().ExistsMendRecorder(model); } catch (Exception ex) { throw ex; } } #endregion #region 插入信息 /// /// 插入信息(单表) /// /// 信息 /// 插入行数 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; ScrapRecordDAL cmdDAL = new ScrapRecordDAL(); if (ExistsMendRecorder(model) == true) return -1; return new ScrapRecordDAL().Insert(model); } catch (Exception ex) { throw ex; } } #endregion #region 更新信息 /// /// 更新信息 /// /// /// 更新行数 public int Update(MendRecorder model) { try { //if (ExistsMendRecorder(Model) == true) //return -1; //基本信息 model.UPDATEUSER = this.LoginUser.UserID; return new ScrapRecordDAL().Update(model); } catch (Exception ex) { throw ex; } } #endregion #region 删除 /// /// 删除信息 /// /// /// 删除个数 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; } } /// /// 删除信息 /// /// 信息 /// 删除个数 public int DeleteMendRecorder(MendRecorder model) { int count = 0; try { count = new ScrapRecordDAL().Delete(model); return count; } catch (Exception ex) { throw ex; } } #endregion #region 导出数据 /// /// 获取导出的数据 /// /// 查询条件 /// 数据 public DataResult GetExportData(MendRecorder model) { DataResult result = new DataResult(); try { DataTable dt = new ScrapRecordDAL().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 dictMendReasonBll = new DictManageBLL(DictKind.MENDREASON); DictManageBLL dictMendStatusSBll = new DictManageBLL(DictKind.REGISTERSTATUS); 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["MENDREASON"] = dictMendReasonBll.GetDictValue(item["MENDREASON"].ToString()); //返修状态 item["REGISTERSTATUS"] = dictMendStatusSBll.GetDictValue(item["REGISTERSTATUS"].ToString()); //ERP汇总 //item["ERPS"] = item["ERP_DEFECTCODE"]; } #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; } #endregion #region 返修(工控机) #region 插入信息 /// /// 插入信息(单表) /// /// 信息 /// 插入行数 public DataResult InsertMendRecorder(MendRecorder model) { DataResult result = new DataResult(); 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 ScrapRecordDAL().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 InsertMendRecordItem(Product product, List defectTypeList) { DataResult result = new DataResult(); List reasonList = new List(); 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"; } ScrapRecordDAL menderDal = new ScrapRecordDAL(); MenderReasonDAL reasonDal = new MenderReasonDAL(); //ScrapRecordDAL 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; } #endregion #region 更新信息 /// /// 更新信息 /// /// /// 更新行数 public DataResult UpdateMendRecorder(MendRecorder model) { DataResult result = new DataResult(); try { //基本信息 model.UPDATEUSER = this.LoginUser.UserID; result.Result = new ScrapRecordDAL().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 #region 校验产品条码号是否存在 /// /// /// /// /// public DataResult CheckProductCode(string productCode) { DataResult result = new DataResult(); 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; } public List GetMenderReasonList(MenderReason condition) { List list = new MenderReasonDAL().GetList(condition); return list; } public DataResult GetListForstatistic(MendRecorder condition) { DataResult result = new DataResult(); result.IsSuccess = true; DataTable dt = new DataTable(); dt = new ScrapRecordDAL().GetListForstatistic(condition); result.Result = dt; return result; } #endregion #region 获取统计信息填充图表 /// /// 获取统计信息填充图表 /// /// /// public DataResult> GetMendRecorderStatistics(MendRecorder condition) { DataResult> result = new DataResult>(); ScrapRecordDAL dal = new ScrapRecordDAL(); List list = dal.GetMendRecorderStatistics(condition); result.Result = list; result.IsSuccess = true; return result; } #endregion #region 获取统计信息导出 /// /// 获取统计信息填充图表 /// /// /// public DataResult ExportMendRecorderStatistics(MendRecorder condition) { DataResult result = new DataResult(); ScrapRecordDAL dal = new ScrapRecordDAL(); DataTable dt = dal.ExportMendRecorderStatistics(condition); result.Result = dt; result.IsSuccess = true; return result; } #endregion } }