using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMAPP.Entity; using QMFrameWork.Data; using QMFrameWork.Log; using QMAPP.MD.DAL; using QMAPP.MD.Entity; using QMAPP.BLL; using QMAPP.MD.BLL.Dict; namespace QMAPP.MD.BLL { /// /// 模块名称:Bom信息 /// 作 者:郭兆福 /// 编写日期:2017年05月10日 /// public class PbomBLL : BaseBLL { #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataResult GetList(Pbom condition, DataPage page) { DataResult result = new DataResult(); try { //获取Bom信息列表 DataPage dataPage = new PbomDAL().GetList(condition, page); #region 转换有效性、类型显示 DictManageBLL dictBomStatusBLL = new DictManageBLL(DictKind.BomStatus); List pbomInfoList = dataPage.Result as List; foreach (Pbom b in pbomInfoList) { b.STATUS_NAME = dictBomStatusBLL.GetDictValue(b.STATUS); } #endregion result.Result = dataPage; } catch (Exception ex) { result.IsSuccess = false; result.Msg = Resource.SystemException; return result; } result.IsSuccess = true; return result; } #endregion #region 信息是否重复 /// /// 判断编号是否存在 /// /// /// true:已存在;fasel:不存在。 public bool ExistsBomHdr(Pbom model) { try { return new PbomDAL().ExistsBomHdr(model); } catch (Exception ex) { throw ex; } } #endregion #region 插入信息 /// /// 插入信息 /// /// 信息 /// 插入行数 public DataResult Insert(Pbom model) { DataResult result = new DataResult(); //PBOM信息 model.PID = Guid.NewGuid().ToString(); model.FLGDEL = "0"; model.CREATEUSER = this.LoginUser.UserID; model.UPDATEUSER = model.CREATEUSER; //物料加工工艺 MaterialRoute materialRoute = new MaterialRoute(); materialRoute.PID = Guid.NewGuid().ToString(); // 工艺路线编码 materialRoute.ROUTE_CODE = model.ROUTE_CODE; // PBOM物料编码 materialRoute.MATERIAL_CODE = model.MATERIAL_CODE; materialRoute.FLGDEL = "0"; materialRoute.CREATEUSER = this.LoginUser.UserID; materialRoute.UPDATEUSER = model.CREATEUSER; try { if (ExistsBomHdr(model) == true) { result.IsSuccess = false; result.Msg = "PBOM编号或者物料号信息已经存在!"; return result; } // 取得工艺路线 ProcessRoute route = new ProcessRoute(); route.ROUTE_CODE = model.ROUTE_CODE; route = new ProcessRouteDAL().Get(route); // 工艺路线版本 materialRoute.ROUTE_VER_NUM = route.ROUTE_VER; using (IDataSession session = AppDataFactory.CreateMainSession()) { try { PbomDAL pbomDAL = new PbomDAL(); MaterialRouteDAL materialRouteDAL = new MaterialRouteDAL(); // 开始事务 session.OpenTs(); pbomDAL.BaseSession = session; // 增加PBOM result.Result = pbomDAL.Insert(model); materialRouteDAL.BaseSession = session; // 物料加工工艺 materialRouteDAL.Insert(materialRoute); // 事务提交 session.CommitTs(); } catch (Exception e) { session.RollbackTs(); throw e; } } } catch (Exception ex) { result.IsSuccess = false; result.Msg = Resource.SystemException; return result; } result.IsSuccess = true; return result; } #endregion #region 删除 /// /// 删除信息 /// /// /// 删除个数 public DataResult Delete(string strs) { DataResult result = new DataResult(); PbomDAL pbomDal = new PbomDAL(); MaterialRouteDAL materialRouteDal = new MaterialRouteDAL(); string[] list = strs.Split(":".ToCharArray()); try { using (IDataSession session = AppDataFactory.CreateMainSession()) { session.OpenTs(); pbomDal.BaseSession = session; materialRouteDal.BaseSession = session; foreach (string str in list) { //删除物料工艺信息 result.Result += materialRouteDal.DeleteMaterialRouteByPbomId(str); //删除Bom明细 result.Result += pbomDal.DeleteBomDetailByPbomId(str); //删除Bom result.Result += pbomDal.DeleteBomHdr(new Pbom { PID = str }); } session.CommitTs(); } } catch (Exception ex) { result.IsSuccess = false; result.Msg = Resource.SystemException; return result; } result.IsSuccess = true; return result; } /// /// 删除信息 /// /// 信息 /// 删除个数 public int DeleteBomHdr(Pbom model) { int count = 0; try { PbomDAL pbomDAL = new PbomDAL(); using (IDataSession session = AppDataFactory.CreateMainSession()) { pbomDAL.BaseSession = session; try { session.OpenTs(); count = pbomDAL.DeleteBomHdr(model); PbomItem modelItem = new PbomItem(); modelItem.PBOM_CODE = model.PBOM_CODE; pbomDAL.DeleteBomDetail(modelItem); session.CommitTs(); } catch (Exception ex) { session.RollbackTs(); } } return count; } catch (Exception ex) { throw ex; } } #endregion #region 获取BOM下拉列表 /// /// 获取BOM下拉列表 /// /// 条件 /// 数据页 public DataResult> GetBomHdrList(Pbom condition) { DataResult> result = new DataResult>(); try { result.Result = new PbomDAL().GetBomHdrList(condition); result.IsSuccess = true; return result; } catch (Exception ex) { result.IsSuccess = false; result.Msg = Resource.SystemException; return result; } } #endregion #region 获取BOM明细(分页) /// /// 获取BOM明细(分页) /// /// 条件 /// 数据页 /// 数据页 public DataResult GetPbomItemList(PbomItem condition, DataPage page) { DataResult result = new DataResult(); try { //获取Bom信息列表 DataPage dataPage = new PbomDAL().BomHdrConfigList(condition, page); List pbomItemList = dataPage.Result as List; // 客供标识符 DictManageBLL dictCspFlag = new DictManageBLL(DictKind.CspFlag); foreach (PbomItem m in pbomItemList) { //客供标识符 m.FLAG_CSP_NAME = dictCspFlag.GetDictValue(m.FLAG_CSP); } result.Result = dataPage; } catch (Exception ex) { result.IsSuccess = false; result.Msg = Resource.SystemException; return result; } result.IsSuccess = true; return result; } #endregion #region 获取BOM明细列表 /// /// 获取BOM明细列表 /// /// 条件 /// 数据页 public DataResult> PbomItemList(PbomItem condition) { DataResult> result = new DataResult>(); List list = new List(); try { //获取Bom明细列表 list = new PbomDAL().BomDetailList(condition); result.Result = list; } catch (Exception ex) { result.IsSuccess = false; result.Msg = Resource.SystemException; return result; } result.IsSuccess = true; return result; } #endregion #region 配置Bom明细 /// /// Bom明细保存 /// /// Bom明细信息 /// public DataResult PbomItemSave(PbomItem model) { DataResult result = new DataResult(); if (model.SEQ_NUM<=0) { result.IsSuccess = false; result.Msg = "序号输入1以上的数值!"; return result; } if (model.SEQ_NUM <= model.UP_SQ_NUM) { result.IsSuccess = false; result.Msg = "序号应大于前置序号!"; return result; } if (model.UNIT_SUM <= 0) { result.IsSuccess = false; result.Msg = "数量输入1以上的数值!"; return result; } if (IsPbomHdrMaterial(model) == true) { result.IsSuccess = false; result.Msg = "BOM项目物料不能结合BOM物料相同!"; return result; } if (IsPbomDetailMaterial(model.PBOM_CODE,model.MATERIAL_CODE) == true) { result.IsSuccess = false; result.Msg = "相同的BOM项目物料已经存在!"; return result; } PbomDAL pbomDal = new PbomDAL(); //Bom明细信息 model.PID = Guid.NewGuid().ToString(); model.CREATEUSER = this.LoginUser.UserID; model.UPDATEUSER = model.CREATEUSER; model.FLGDEL = "0"; try { result.Result = new PbomDAL().InsertBomDetail(model); } catch (Exception ex) { result.IsSuccess = false; result.Msg = Resource.SystemException; return result; } result.IsSuccess = true; return result; } /// /// 判断bom头物料和bom物料是否相同 /// /// /// private Boolean IsPbomHdrMaterial(PbomItem model) { PbomDAL pbomDal = new PbomDAL(); Pbom pbom = new Pbom(); pbom.PBOM_CODE = model.PBOM_CODE; pbom = pbomDal.Get(pbom); if (pbom.MATERIAL_CODE == model.MATERIAL_CODE) { return true; } else { return false; } } /// /// 判断bom头物料和bom物料是否相同 /// /// /// private Boolean IsPbomDetailMaterial(string pbomCode,string materialCode) { PbomDAL pbomDal = new PbomDAL(); PbomItem pbomItem = new PbomItem(); pbomItem.PBOM_CODE = pbomCode; pbomItem.MATERIAL_CODE = materialCode; pbomItem = pbomDal.GetBomDetail(pbomItem); if (null != pbomItem) { return true; } else { return false; } } #endregion #region 删除Bom明细 /// /// 删除Bom明细 /// /// 信息 /// 删除个数 public DataResult DeletePbomItem(string str) { PbomDAL bomGroupDal = new PbomDAL(); List listBomDetail = new List(); PbomItem entity = new PbomItem(); DataResult result = new DataResult(); try { using (IDataSession session = AppDataFactory.CreateMainSession()) { session.OpenTs(); bomGroupDal.BaseSession = session; //删除Bom明细 result.Result += bomGroupDal.DeleteBomDetail(new PbomItem() { PID = str }); session.CommitTs(); } } catch (Exception ex) { result.IsSuccess = false; result.Msg = Resource.SystemException; return result; } result.IsSuccess = true; return result; } /// /// 删除信息 /// /// 信息 /// 删除个数 public int DeleteBomDetail(PbomItem model) { int count = 0; try { count = new PbomDAL().DeleteBomDetail(model); return count; } catch (Exception ex) { throw ex; } } #endregion #region 获取物料对应工艺路线 /// /// 获取物料对应工艺路线 /// /// /// public DataResult GetRouteByMaterialCode(MaterialRoute model) { DataResult result = new DataResult(); try { // 物料加工工艺 result.Result = new MaterialRouteDAL().Get(model); return result; } catch (Exception e) { throw e; } } #endregion #region 获取BOM明细列表 /// /// 获取BOM明细列表 /// /// 条件 /// 数据页 public List GetPbomItemAllList(PbomItem model) { try { //获取Bom明细列表 return new PbomDAL().GetPbomItemList(model); } catch (Exception ex) { throw ex; } } #endregion #region 获取BOMItem信息 /// /// 获取信息 /// /// 条件 /// 信息 public PbomItem GetPbomItemOne(PbomItem model) { try { return new PbomDAL().GetPbomItemOne(model); } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "PBOM管理--获取信息" }); throw ex; } } #endregion #region 获取SEQ_NUM最大号 /// /// 获取信息 /// /// 条件 /// 信息 public int GetMaxSeqNum(PbomItem model) { try { var pi = new PbomDAL().GetMaxSeqNum(model); return pi.SEQ_NUM; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "PBOM管理--获取SEQ_NUM最大号" }); throw ex; } } #endregion #region 插入信息 /// /// 插入信息 /// /// 信息 /// 插入行数 public int InsertPbomItem(PbomItem model) { //PBOM信息 model.PID = Guid.NewGuid().ToString(); model.FLGDEL = "0"; model.CREATEUSER = this.LoginUser.UserID; model.UPDATEUSER = model.CREATEUSER; model.CREATEDATE = DateTime.Now; model.UPDATEDATE = model.CREATEDATE; try { return new PbomDAL().InsertPbomItem(model); } catch (Exception ex) { throw ex; } } #endregion #region 更新信息 /// /// 更新信息 /// /// 信息 /// 插入行数 public int UpdatePbomItem(PbomItem model) { model.UPDATEUSER = this.LoginUser.UserID; model.UPDATEDATE = DateTime.Now; try { return new PbomDAL().UpdatePbomItem(model); } catch (Exception ex) { throw ex; } } #endregion #region 删除信息 /// /// 删除信息 /// /// 信息 /// 插入行数 public DataResult DelPbomItem(string pid) { //try //{ // return new PbomDAL().DelPbomItem(pid); //} //catch (Exception ex) //{ // throw ex; //} DataResult result = new DataResult(); try { result.Result = new PbomDAL().DelPbomItem(pid); } catch (Exception ex) { result.IsSuccess = false; result.Msg = Resource.SystemException; return result; } result.IsSuccess = true; return result; } #endregion public List GetBomBySubMaterial(string material) { DAL.PbomDAL dal = new PbomDAL(); return dal.GetPbomByMaterialCode(material); } public List GetFinalPbom(string material) { DAL.PbomDAL dal = new PbomDAL(); return dal.GetFinalPbom(material); } public List GetWorkingBom(string WorklocCode, string OrderNo) { return new DAL.PbomDAL().GetWorkingBom(WorklocCode, OrderNo); } public List GetSubItem(string upmaterial) { return new DAL.PbomDAL().GetSubItem(upmaterial); } } }