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; namespace QMAPP.FJC.BLL.ProduceManage { /// /// 模块编号:M4-1 /// 作 用:生产记录逻辑层 /// 作 者:张敬贺 /// 编写日期:2015年06月04日 /// public class ProducePlanBLL : BaseBLL { #region 获取信息 /// /// 获取信息 /// /// 条件 /// 信息 public DataResult Get(ProducePlan model) { DataResult result = new DataResult(); try { result.Result = new ProducePlanDAL().Get(model); result.IsSuccess = true; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "获取生产记录异常!" }); result.IsSuccess = false; result.Ex = ex; result.Msg = "获取生产记录异常"; } return result; } #endregion #region 获取列表 /// /// 获取列表 /// /// 条件 /// 数据页 /// 数据页 public DataResult GetList(ProducePlan condition, DataPage page) { DataResult result = new DataResult(); try { //获取信息列表 DataPage dataPage = new ProducePlanDAL().GetList(condition, page); #region 转换工序类别显示类型 List list = dataPage.Result as List; //处理字典信息 DictManageBLL dictPROCESSTYPE = new DictManageBLL(DictKind.PROCESSTYPE); DictManageBLL dictPRODUCTTYPE = new DictManageBLL(DictKind.PRODUCTTYPE); DictManageBLL dictPLANSTATUS = new DictManageBLL(DictKind.PLANSTATUS); DictManageBLL dictCREATETYPE = new DictManageBLL(DictKind.CREATETYPE); DictManageBLL dictCOLOR = new DictManageBLL(DictKind.COLOR); DictManageBLL dictHB = new DictManageBLL(DictKind.HAndL); foreach (var info in list) { //替换工序类别显示值 info.PROCESSTYPE = dictPROCESSTYPE.GetDictValue(info.PROCESSTYPE); //替换零件类别显示值 info.PRODUCTTYPE = dictPRODUCTTYPE.GetDictValue(info.PRODUCTTYPE); //替换计划状态显示值 info.PLANSTATUS = dictPLANSTATUS.GetDictValue(info.PLANSTATUS); //替换生产状态显示值 info.CREATETYPE = dictCREATETYPE.GetDictValue(info.CREATETYPE); //颜色 info.COLOR = dictCOLOR.GetDictValue(info.COLOR); //高低配 info.HB = dictHB.GetDictValue(info.HB); } #endregion result.IsSuccess = true; result.Result = dataPage; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "生产记录获取列表异常!" }); result.IsSuccess = false; result.Ex = ex; result.Msg = "生产记录获取列表异常!"; } return result; } /// /// 获取列表 /// /// 条件 /// 全部集合 public List GetAllList(ProducePlan condition) { try { //获取信息列表 List list = new ProducePlanDAL().GetList(condition); return list; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "生产记录获取列表异常!" }); throw ex; } } /// /// 获取列表 /// /// 条件 /// 全部集合 public List GetTotal(ProducePlan condition) { try { List list; //获取信息列表 if (EnumGeter.ProductType.benti.GetHashCode().ToString().Equals(condition.PRODUCTTYPE)) { list = new ProducePlanDAL().GetTotalMain(condition); } else { list = new ProducePlanDAL().GetTotalProduct(condition); } return list; } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "生产记录获取列表异常!" }); throw ex; } } #endregion #region 插入信息 /// /// 插入信息(单表) /// /// 信息 /// 插入行数 public DataResult Insert(ProducePlan model) { DataResult result = new DataResult(); ProducePlanDAL ppDAL = new ProducePlanDAL(); try { result.IsSuccess = true; //基本信息 model.PID = Guid.NewGuid().ToString(); model.PLANSTATUS = QMAPP.FJC.Entity.EnumGeter.PLANSTATUS.INITIALIZATION.GetHashCode().ToString(); model.CREATEUSER = this.LoginUser.UserID; model.CREATEDATE = DateTime.Now; model.UPDATEUSER = model.CREATEUSER; model.UPDATEDATE = model.CREATEDATE; model.PASTFLAG = "0"; model.CREATETYPE = "1"; model.PRODUCELINE = EnumGeter.PRODUCELINE.B9.ToString(); #region 生成生产计划号 string planCode = ppDAL.GetPlanCode(); if (planCode == "") { model.PLANCODE = "B9" + DateTime.Now.ToString("yyyyMMdd") + "001"; } else { model.PLANCODE = planCode.Substring(0, 10) + (Convert.ToInt32(planCode.Substring(10)) + 1); int zeroNum = 13 - model.PLANCODE.Length; string zero = ""; for (int i = 0; i < zeroNum; i++) { zero += "0"; } model.PLANCODE = model.PLANCODE.Substring(0, 10) + zero + model.PLANCODE.Substring(10); } #endregion int temp = ppDAL.Insert(model); if (temp == 0) { result.IsSuccess = false; result.Msg = "生产记录插入失败!"; return result; } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "生产记录插入异常!" }); result.IsSuccess = false; result.Ex = ex; result.Msg = "生产记录插入异常"; } return result; } #endregion #region 更新信息 /// /// 更新信息 /// /// /// 更新行数 public DataResult Update(ProducePlan model) { DataResult result = new DataResult(); result.IsSuccess = true; try { ProducePlan info = new ProducePlanDAL().Get(model); //基本信息 info.PROCESSTYPE = model.PROCESSTYPE; info.PRODUCTTYPE = model.PRODUCTTYPE; info.PRODUCECOUNT = model.PRODUCECOUNT; info.MEMO = model.MEMO; info.UPDATEUSER = this.LoginUser.UserID; int temp = new ProducePlanDAL().Update(info); if (temp == 0) { result.IsSuccess = false; result.Msg = "生产记录更新失败!"; return result; } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "生产记录更新异常!" }); result.IsSuccess = false; result.Ex = ex; result.Msg = "生产记录更新异常"; } return result; } #endregion #region 删除 /// /// 删除信息 /// /// /// 删除个数 public DataResult Delete(string strs) { DataResult result = new DataResult(); result.IsSuccess = true; int count = 0; string[] list = strs.Split(":".ToCharArray()); try { foreach (string str in list) { bool isComplent= this.ExisteStatus(new ProducePlan { PID = str }); if (isComplent == true) { result.IsSuccess = false; result.Msg = Resource.PlanIsComplent; return result; } } foreach (string str in list) { count += this.DeleteInfo(new ProducePlan { PID = str }); } if (count != list.Length) { result.IsSuccess = false; result.Msg = "生产信息部分删除!"; return result; } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "生产记录删除异常!" }); result.IsSuccess = false; result.Msg = "生产记录删除异常!"; result.Ex = ex; } return result; } /// /// 删除信息 /// /// 信息 /// 删除个数 public int DeleteInfo(ProducePlan model) { int count = 0; try { count = new ProducePlanDAL().Delete(model); return count; } catch (Exception ex) { throw ex; } } #endregion #region 完成计划 /// /// 完成计划 /// /// /// 完成计划 public DataResult ProductOver(string str) { DataResult result = new DataResult(); result.IsSuccess = true; int count = 0; try { ProducePlan info = new ProducePlanDAL().Get(new ProducePlan { PID = str }); if (info.PLANSTATUS == EnumGeter.PLANSTATUS.COMPLETED.GetHashCode().ToString()) { result.IsSuccess = false; result.Msg = Resource.PlanNoMoreComplent; return result; } //基本信息 info.PLANSTATUS = QMAPP.FJC.Entity.EnumGeter.PLANSTATUS.COMPLETED.GetHashCode().ToString(); info.UPDATEUSER = this.LoginUser.UserID; count += new ProducePlanDAL().Update(info); if (count == 0) { result.IsSuccess = false; result.Msg = "完成生产记录失败!"; return result; } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "完成生产记录异常!" }); result.IsSuccess = false; result.Msg = "完成生产记录异常!"; result.Ex = ex; } return result; } #endregion #region 校验生产计划是否完成 /// /// 校验生产计划是否完成 /// /// public bool ExisteStatus(ProducePlan model) { try { model = new ProducePlanDAL().Get(model); if (model.PLANSTATUS == EnumGeter.PLANSTATUS.COMPLETED.GetHashCode().ToString()) { return true; } } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo() { ErrorInfo = ex, Tag = ex.StackTrace, Info = "生产记录逻辑层-校验生产计划是否完成" }); } return false; } #endregion } }