/// <summary> /// 获取订购周期最大编号 /// </summary> /// <param name="pMaxCycleNo"></param> /// <returns></returns> private CycleNoConfig CreateCycleNo(string pMaxCycleNo) { int iCycleNo = 0; if (string.IsNullOrEmpty(pMaxCycleNo) || !int.TryParse(pMaxCycleNo, out iCycleNo)) { return(null); } //获取周期编号的前4位年份及后n位编号 var pMaxYear = pMaxCycleNo.Length >= 4 ? pMaxCycleNo.Substring(0, 4) : ""; var pMaxNo = pMaxCycleNo.Length >= 4 ? pMaxCycleNo.Substring(4, pMaxCycleNo.Length - 4) : ""; int iMaxYear = 0; int iMaxNo = 0; if (!int.TryParse(pMaxYear, out iMaxYear) || !int.TryParse(pMaxNo, out iMaxNo)) { return(null); } var pCfg = new CycleNoConfig(); pCfg.CurYear = DateTime.Now.Year; pCfg.CurMonth = DateTime.Now.Month; pCfg.CurDay = DateTime.Now.Day; pCfg.CurHour = DateTime.Now.Hour; pCfg.CurMinute = DateTime.Now.Minute; pCfg.MaxYear = iMaxYear; pCfg.MaxNo = iMaxNo; pCfg.CurNo = (pCfg.CurYear > pCfg.MaxYear) ? 1 : (iMaxNo + 1); return(pCfg); }
/// <summary> /// 更新订购周期 /// </summary> /// <typeparam name="TM"></typeparam> /// <returns></returns> public bool UpdateOrderCycle <TM>(TM pCycle) where TM : OrderCycleTM { var pCycles = new List <TM>(); pCycles.Add(pCycle); var dtCycles = CommonFunction.GetDataTableFromEntities <TM>(pCycles); //生成用户创建时输入的最大流水号是否与系统当前最大流水号一致 CycleNoConfig pCurData = CreateCycleNo(pCycle.CycleNo); int pMaxNoInSys = NumberHelper.Singleton.GetNo(_DicKey); if (pMaxNoInSys != -1 && pCurData.MaxNo != pMaxNoInSys) { throw new Exception(""); } //定义数据更新后执行action Action pAfter = () => { NumberHelper.Singleton.SetNo(_DicKey, GetNextCycleNo); }; //添加AOP拦截,当有周期维护更新时,同时更新最大流水号(周期编号CycleNo) var pDataWriting = new DataWritingInterceptor(() => { }, pAfter); var pDA = CastleAOPUtil.NewPxyByClass <OrderCycleDA>(pDataWriting); return(pDA.Update(dtCycles)); }