using System; using System.Collections.Generic; using System.Linq; using System.Text; using QMAPP.BLL; using QMAPP.FJC.Entity.Basic; using QMAPP.FJC.DAL.Basic; using QMFrameWork.Data; using QMAPP.FJC.BLL.Dict; using QMAPP.FJC.Entity; using QMAPP.Entity; using QMFrameWork.Log; namespace QMAPP.FJC.BLL.Basic { /// /// 模块编号:M2-7 /// 作 用:工序设置逻辑层 /// 作 者:王丹丹 /// 编写日期:2015年06月01日 /// public class ProcessSetBLL : BaseBLL { #region 获取信息 /// /// 获取信息 /// /// 条件 /// 信息 public DataResult Get(ProcessSet model) { DataResult result = new DataResult(); try { result.Result = new ProcessSetDAL().Get(model); } 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 GetByModel(ProcessSet model) { DataResult result = new DataResult(); try { List list = new ProcessSetDAL().GetList(model); if (list.Count > 0) { result.Result = list[0]; } } 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> GetListByModel(ProcessSet model) { DataResult> result = new DataResult>(); try { List list = new ProcessSetDAL().GetList(model); if (list.Count > 0) { result.Result = list; } } 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 GetList(ProcessSet condition, DataPage page) { DataResult result = new DataResult(); try { //获取信息列表 DataPage dataPage = new ProcessSetDAL().GetList(condition, page); #region 转换工序是否必须、在制品工序设置、工序类别、是否是主零件显示类型 List processSetList = dataPage.Result as List; DictManageBLL dictLpneccessaryBll = new DictManageBLL(DictKind.LPNECCESSARY); DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE); DictManageBLL dictWipSetBll = new DictManageBLL(DictKind.WIPSET); DictManageBLL dictIsMainBll = new DictManageBLL(DictKind.ISMAIN); DictManageBLL dictProductTypeBll = new DictManageBLL(DictKind.PRODUCTTYPE); foreach (ProcessSet m in processSetList) { //工序是否必须 m.LPNECCESSARYTXT = dictLpneccessaryBll.GetDictValue(m.LPNECCESSARY); //工序类别 m.PROCESSTYPETXT = dictProcessTypeBll.GetDictValue(m.PROCESSTYPE); //在制品工序设置 m.WIPSETTXT = dictWipSetBll.GetDictValue(m.WIPSET); //是否是主零件 m.ISMAINTXT = dictIsMainBll.GetDictValue(m.ISMAIN); //零件类别 m.PRODUCTTYPETEXT = dictProductTypeBll.GetDictValue(m.PRODUCTTYPE); } #endregion result.Result = dataPage; } 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 List GetAllList(ProcessSet condition) { try { //获取信息列表 #region 转换工序是否必须、在制品工序设置、工序类别显示类型 List processSetList = new ProcessSetDAL().GetList(condition); DictManageBLL dictLpneccessaryBll = new DictManageBLL(DictKind.LPNECCESSARY); DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE); DictManageBLL dictWipSetBll = new DictManageBLL(DictKind.WIPSET); foreach (ProcessSet m in processSetList) { //工序是否必须 m.LPNECCESSARYTXT = dictLpneccessaryBll.GetDictValue(m.LPNECCESSARY); //工序类别 m.PROCESSTYPETXT = dictProcessTypeBll.GetDictValue(m.PROCESSTYPE); //在制品工序设置 m.WIPSETTXT = dictWipSetBll.GetDictValue(m.WIPSET); } #endregion return processSetList; } catch (Exception ex) { throw ex; } } #endregion #region 信息是否重复 /// /// 判断名称是否存在 /// /// /// true:已存在;fasel:不存在。 public bool ExistsProcessSet(ProcessSet model) { try { return new ProcessSetDAL().ExistsProcessSet(model); } catch (Exception ex) { throw ex; } } #endregion #region 插入信息 /// /// 插入信息(单表) /// /// 信息 /// 插入行数 public DataResult Insert(ProcessSet model) { DataResult result = new DataResult(); ProcessSetDAL cmdDAL = new ProcessSetDAL(); //基本信息 model.PID = Guid.NewGuid().ToString(); model.CREATEUSER = this.LoginUser.UserID; model.CREATEDATE = DateTime.Now; model.UPDATEUSER = model.CREATEUSER; model.UPDATEDATE = model.CREATEDATE; model.PRODUCELINE = EnumGeter.PRODUCELINE.B9.ToString(); try { if (ExistsProcessSet(model) == true) { result.IsSuccess = false; result.Msg = Resource.ProduceTypeOrProcesssTypeIsHave; return result; } result.Result = new ProcessSetDAL().Insert(model); } 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 Update(ProcessSet model) { DataResult result = new DataResult(); //基本信息 model.UPDATEUSER = this.LoginUser.UserID; try { if (ExistsProcessSet(model) == true) { result.IsSuccess = false; result.Msg = Resource.ProduceTypeOrProcesssTypeIsHave; return result; } result.Result = new ProcessSetDAL().Update(model); } 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 Delete(string strs) { DataResult result = new DataResult(); string[] list = strs.Split(":".ToCharArray()); try { foreach (string str in list) { result.Result += this.DeleteProcessSet(new ProcessSet { PID = str }); } } 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 int DeleteProcessSet(ProcessSet model) { int count = 0; DataResult result = new DataResult(); try { //获取当前工序设置信息 model = new ProcessSetDAL().Get(model); //获取该零件下的最大工序顺序的工序信息 result = this.GetProcessIndex(new ProcessSet() { PRODUCTTYPE = model.PRODUCTTYPE, }); //删除工序 count = new ProcessSetDAL().Delete(model); //更新该工序后的所有工序的工序顺序 //如果当前工序不等于应插入的最大工序顺序 if (model.PROCESSINDEX != result.Result.MAXPROCESSINDEX) { result.Result.OLDPROCESSINDEX = model.PROCESSINDEX + 1; //更新原工序顺序 new ProcessSetDAL().UpdateIndexForWord(result.Result); } return count; } catch (Exception ex) { throw ex; } } #endregion #region 根据工序id获取工序信息 /// /// 根据工序id获取工序信息 /// /// 条件 /// *信息 public DataResult GetProcessInfo(ProcessSet model) { ProcessInfo condition = new ProcessInfo(); ProcessInfoDAL psDal = new ProcessInfoDAL(); DataResult result = new DataResult(); try { if (model != null && !string.IsNullOrEmpty(model.PCID)) { condition.PID = model.PCID; //获取工序信息 condition = psDal.Get(condition); #region 转换工序类别显示类型 if (condition != null) { DictManageBLL dictProcessTypeBll = new DictManageBLL(DictKind.PROCESSTYPE); //工序类别 condition.PROCESSTYPETXT = condition.PROCESSNAME; } #endregion } result.Result= condition; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "工序设置逻辑层-根据工序id获取工序信息!" }); result.IsSuccess = false; result.Msg = Resource.SystemException; throw ex; } result.IsSuccess = true; return result; } #endregion #region 根据工序id获取工序信息集合 /// /// 根据工序id获取工序信息 /// /// 条件 /// *信息 public DataResult> GetProcessInfoList(ProcessSet model) { ProcessInfo condition = new ProcessInfo(); ProcessInfoDAL psDal = new ProcessInfoDAL(); DataResult> result = new DataResult>(); try { if (model != null && !string.IsNullOrEmpty(model.PCID)) { condition.PID = model.PCID; } if (model != null&&!string.IsNullOrEmpty(model.OPERATETYPE)) { condition.OPERATETYPE = model.OPERATETYPE; } if (!string.IsNullOrEmpty(model.PROCESSTYPE)) { condition.PROCESSTYPE = model.PROCESSTYPE; } //获取工序信息 result.Result = new ProcessInfoDAL().GetList(condition); } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "工序设置逻辑层-根据工序id获取工序信息集合!" }); result.IsSuccess = false; result.Msg = Resource.SystemException; throw ex; } result.IsSuccess = true; return result; } #endregion #region 获取下一个加工工序 /// /// 获取下一个加工工序 /// /// 当前工序 /// public ProcessSet GetNextProcess(ProcessSet current) { ProcessSet nextProcessSet = new ProcessSet(); ProcessSetDAL psdal = new ProcessSetDAL(); try { //获取该生产线下该产品类别所有加工工序 List psList = psdal.GetList(new ProcessSet() { PRODUCTTYPE = current.PRODUCTTYPE, PRODUCELINE = current.PRODUCELINE, }); //获取当前工序 ProcessSet currentProcess = psList.First(o => o.PROCESSTYPE == current.PROCESSTYPE); //获取加工序列大于当前工序的加工工序 if (psList.Count(o => o.PROCESSINDEX > currentProcess.PROCESSINDEX) > 0) { nextProcessSet = psList.Where(o => o.PROCESSINDEX > currentProcess.PROCESSINDEX) .OrderBy(o=>o.PROCESSINDEX).First(); } } catch (Exception ex) { throw ex; } return nextProcessSet; } #endregion #region 获取该生产线下该产品类别下最新工序 /// /// 获取该生产线下该产品类别下最新工序 /// /// 当前工序 /// public DataResult GetProcessIndex(ProcessSet current) { ProcessSetDAL psdal = new ProcessSetDAL(); ProcessSet processSet = new ProcessSet(); DataResult result = new DataResult(); try { //获取该生产线下该产品类别所有加工工序 List psList = psdal.GetList(new ProcessSet() { PRODUCTTYPE = current.PRODUCTTYPE, }); //获取产品类别下最新工序 result.Result = psList.Where(o => o.PROCESSINDEX == psList.Max(p => p.PROCESSINDEX)).FirstOrDefault(); } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "工序设置逻辑层-获取该生产线下该产品类别下最新工序!" }); throw ex; } result.IsSuccess = true; return result; } #endregion #region 保存工序设置信息 /// /// 保存工序设置信息 /// /// 工序信息 /// 插入/更新数量 public DataResult Save(ProcessSet processSet) { DataResult result = new DataResult(); ProcessSetDAL psDal = new ProcessSetDAL(); try { using (IDataSession session = AppDataFactory.CreateMainSession()) { session.OpenTs(); psDal.BaseSession = session; #region 更新 //更新 if (!string.IsNullOrEmpty(processSet.PID)) { if (psDal.ExistsProcessSet(processSet) == true) { result.IsSuccess = false; result.Msg = Resource.IsHaving; return result; } else { //如果修改了零件类别或修改了工序顺序(原工序类别不等于当前工序类别或原工序顺序不等于当前工序顺序) if (processSet.OLDPRODUCTTYPE != processSet.PROCESSTYPE || processSet.PROCESSINDEX != processSet.OLDPROCESSINDEX) { //如果当前工序不等于应插入的最大工序顺序 if (processSet.PROCESSINDEX != processSet.MAXPROCESSINDEX + 1) { if (processSet.PROCESSINDEX > processSet.OLDPROCESSINDEX) { processSet.OLDPROCESSINDEX = processSet.OLDPROCESSINDEX + 1; //更新原工序顺序 psDal.UpdateIndexForWord(processSet); } if (processSet.PROCESSINDEX < processSet.OLDPROCESSINDEX) { processSet.OLDPROCESSINDEX = processSet.OLDPROCESSINDEX - 1; //更新原工序顺序 psDal.UpdateIndexBackWord(processSet); } } } //更新新工序设置 result.Result = psDal.Update(processSet); } } #endregion #region 新建 //新建 else { //基本信息 processSet.PID = Guid.NewGuid().ToString(); if (psDal.ExistsProcessSet(processSet) == true) { result.IsSuccess = false; result.Msg = Resource.IsHaving; return result; } else { //如果当前工序不等于应插入的最大工序顺序 if (processSet.PROCESSINDEX != processSet.MAXPROCESSINDEX + 1) { processSet.OLDPROCESSINDEX = processSet.MAXPROCESSINDEX; //更新原工序顺序 psDal.UpdateIndexBackWord(processSet); } #region 基本信息 //基本信息 processSet.CREATEUSER = this.LoginUser.UserID; processSet.CREATEDATE = DateTime.Now; processSet.UPDATEUSER = processSet.CREATEUSER; processSet.UPDATEDATE = processSet.CREATEDATE; processSet.PRODUCELINE = EnumGeter.PRODUCELINE.B9.ToString(); processSet.PRODUCTNAME = processSet.PRODUCTTYPE; #endregion //插入新工序设置 result.Result = psDal.Insert(processSet); } } #endregion 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 } }