/// <summary> /// /// </summary> /// <param name="type"></param> /// <param name="noName"></param> /// <param name="maxNo"></param> /// <param name="customer"></param> /// <returns></returns> protected NumControl GetANumControl(string type, string noName, string maxNo, string customer) { NumControl nc = new NumControl(0, type, noName, maxNo, customer); return nc; }
private string getBoxId(string boxReg) { string boxID = ""; //New Format of Box Id //RRRR-SSSSS //Remark: //RRRR – @boxReg //- – 固定字符’-‘ //SSSSS – 流水号,31进制,基字符'0123456789BCDFGHJKLMNPQRSTVWXYZ';起始值为R0000;最大值为VZZZZ string maxnum = ""; string prestr = ""; boxID = boxReg + "-"; prestr = boxID; // 自己管理事务开始 try { SqlTransactionManager.Begin(); // IUnitOfWork uof = new UnitOfWork();//使用自己的UnitOfWork //ITC-1414-0065 //从NumControl中获取流水号 //GetMaxNumber INumControlRepository numControl = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); bool addflag = false; maxnum = numControl.GetMaxNumber("BOXID", prestr + "{0}"); if (string.IsNullOrEmpty(maxnum)) { maxnum = "R0000"; addflag = true; } else { MathSequenceWithCarryNumberRule marc = new MathSequenceWithCarryNumberRule(5, "0123456789BCDFGHJKLMNPQRSTVWXYZ"); //maxnum="CNU248000Y"; string numstr = maxnum.Substring(maxnum.Length - 5); if (numstr.ToUpper() == "VZZZZ") { FisException fe = new FisException("CHK867", new string[] { }); //流水号已满! throw fe; } numstr = marc.IncreaseToNumber(numstr, 1); maxnum = numstr; } boxID = boxID + maxnum.ToUpper(); //setSPValue = boxID; NumControl item = new NumControl(); item.NOType = "BOXID"; item.Value = boxID; item.NOName = ""; item.Customer = "HP"; numControl.SaveMaxNumber(item, addflag, prestr + "{0}"); //uof.Commit(); //立即提交UnitOfWork更新NumControl里面的最大值 SqlTransactionManager.Commit();//提交事物,释放行级更新锁 return boxID; } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } }
private string getIMEISeq(string model,string preFixCode,string custom) { string numType ="IMEI"; try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); MACRange currentRange = numCtrlRepository.GetMACRange(preFixCode, new string[] { "R", "A" }); if (currentRange == null) { throw new FisException("ICT014", new string[] {}); } else { if (!validateIMEISettingRange(currentRange.BegNo, currentRange.EndNo)) { throw new FisException("CHK1086", new string[] { currentRange.BegNo + "~" + currentRange.EndNo }); } NumControl currentMaxNum = numCtrlRepository.GetMaxValue(numType, preFixCode); if (currentMaxNum == null) { currentMaxNum = new NumControl(); currentMaxNum.NOName = preFixCode; currentMaxNum.NOType = numType; currentMaxNum.Value = currentRange.BegNo; currentMaxNum.Customer = custom; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.InsertNumControlDefered(uof, currentMaxNum); if (currentMaxNum.Value == currentRange.EndNo) { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Closed); } else { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Active); } uof.Commit(); SqlTransactionManager.Commit(); return currentMaxNum.Value; } else { if (currentMaxNum.Value == currentRange.EndNo) { numCtrlRepository.SetMACRangeStatus(currentRange.ID, MACRange.MACRangeStatus.Closed); currentRange = numCtrlRepository.GetMACRange(preFixCode, new string[] { "R" }); if (!validateIMEISettingRange(currentRange.BegNo, currentRange.EndNo)) { throw new FisException("CHK1086", new string[] { currentRange.BegNo + "~" + currentRange.EndNo }); } if (currentMaxNum.Value == currentRange.BegNo || currentMaxNum.Value == currentRange.EndNo) { throw new FisException("ICT018", new string[] { currentMaxNum.Value }); } } int curNextNum = int.Parse(currentMaxNum.Value)+1; currentMaxNum.Value = curNextNum.ToString("D12"); IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); if (currentMaxNum.Value == currentRange.EndNo) { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Closed); } else { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Active); } uof.Commit(); SqlTransactionManager.Commit(); return currentMaxNum.Value; } } } } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } }
private string GetVendorCT(string vendorCode, string vendor, string mfgCode, string weekCode) { try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); NumControl currentMaxNum = new NumControl(); string preSeqStr = vendorCode + mfgCode + "__" + weekCode; string likecont = preSeqStr + "{0}"; string type = "KP"; string vendorCT = ""; string maxNumber = numCtrlRepository.GetMaxNumber(type, likecont, this.Customer); if (maxNumber != null && maxNumber != "") { currentMaxNum = numCtrlRepository.GetNumControlByNoTypeAndValue(type, maxNumber)[0]; } if (maxNumber == null || maxNumber == "") { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor(vendor); if (first == null) { throw new FisException("ICT013", new string[] { }); } vendorCT = vendorCode + mfgCode + first.code + weekCode + "000"; currentMaxNum.NOName = ""; currentMaxNum.NOType = type; currentMaxNum.Value = vendorCT; currentMaxNum.Customer = this.Customer; numCtrlRepository.InsertNumControl(currentMaxNum); SqlTransactionManager.Commit(); return vendorCT; } else if (maxNumber.Substring(9, 2) != weekCode) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor(vendor); if (first == null) { throw new FisException("ICT013", new string[] { }); } vendorCT = vendorCode + mfgCode + first.code + weekCode + "000"; currentMaxNum.Value = vendorCT; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); return vendorCT; } else { if (maxNumber.EndsWith("ZZZ")) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IList<SupplierCodeInfo> codeList = currentProductRepository.GetSupplierCodeListByCode(maxNumber.Substring(7, 2)); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor(vendor, codeList[0].idex); if (first == null) { throw new FisException("IEC003", new string[] { }); } vendorCT = vendorCode + mfgCode + first.code + weekCode + "000"; currentMaxNum.Value = vendorCT; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); return vendorCT; } else { ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 3, "ZZZ", "000", '0'); string sequenceNumber = maxNumber.Substring(11, 3); sequenceNumber = seqCvt.NumberRule.IncreaseToNumber(sequenceNumber, 1); currentMaxNum.Value = maxNumber.Substring(0, 11) + sequenceNumber; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); return vendorCode + mfgCode + maxNumber.Substring(7, 2) + weekCode + sequenceNumber; } } } } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } }
/// <summary> /// /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { MB currenMB = CurrentSession.GetValue(Session.SessionKeys.MB) as MB; IMBRepository itemRepository = RepositoryFactory.GetInstance().GetRepository<IMBRepository>(); INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); //Modify UC Update 前提条件:Station=15 ITC-1414-0024 if (this.Station != "15") { return base.DoExecute(executionContext); } //------------------------------------------------------------- //2.28. MBCode:若第6码为’M’,则取MBSN前3码为MBCode,若第5码为’M’,则取前2码 //CheckCode:若MBSN的第5码为’M’,则取MBSN的第6码,否则取第7码 string strMBCode =""; string strCheckCode = ""; if (currenMB.Sn.Substring(5,1)=="M") { strMBCode = currenMB.Sn.Substring(0, 3); strCheckCode = currenMB.Sn.Substring(6, 1); } else if (currenMB.Sn.Substring(4,1)=="M") { strMBCode = currenMB.Sn.Substring(0, 2); strCheckCode = currenMB.Sn.Substring(5, 1); } else { strCheckCode = currenMB.Sn.Substring(6, 1); } //------------------------------------------------------------- //2.29. MBSN子板/RCTO的判定:CheckCode为数字,则为子板,为’R’,则为RCTO if (strCheckCode == "R") { //为’R’,则为RCTO } else if (Char.IsNumber(strCheckCode, 0) == true) { //CheckCode为数字,则为子板 } //Session.AddValue("IsDocking", true); // Docking @Type=’PC’ var isDocking = false; try { isDocking = (bool)CurrentSession.GetValue("IsDocking"); } catch (Exception ex) { var strerr = ex.Message; isDocking = false; } //------------------------------------------------------------- //Type: //1、 若@MBSN的CheckCode为‘R’,则@Type=’RCTO’ //2、 若IsFru Checked,则@Type=’Fru’ //3、 其他,@Type=’PC’ string strType = ""; if (isDocking == false) { if (strCheckCode == "R") { strType = "RCTO"; } else if ((bool)CurrentSession.GetValue("bFruChecked")==true) { strType = "Fru"; } else { strType = "PC"; } } else { strType = "PC"; } //------------------------------------------------------------- //[LotList]中是否存在@MBCode和@Type记录 +和@Line) //UC UPDATE 2012/06/20 LotList]中不存在(@MBCode、@Type、和@Line 和 Lot.Status=0)记录 IMES.DataModel.LotInfo Conlot = new IMES.DataModel.LotInfo(); Conlot.mbcode = strMBCode; Conlot.type = strType; Conlot.line = this.Line; Conlot.status = "0";//Add by kaisheng 2012/06/20 IList<LotInfo> retlot = itemRepository.GetlotInfoList(Conlot); if ((retlot == null) || (retlot.Count == 0)) { //不存在@MBCode和@Type记录, 则执行‘15.1 LotNo生成规则’,产生该MBCode和Type的LotNo,并Insert Lot/PCBLot //LotNo规则:YYYYMMDDXXXX,XXXX代表流水码,10进制,自增,幅度为1 // -------------------------------------------------------- //1. LotNo生成 string sublotNo = ""; //string Watercode = ""; sublotNo = DateTime.Today.Year.ToString("0000") + DateTime.Today.Month.ToString("00") + DateTime.Today.Day.ToString("00"); try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { NumControl currentMaxNum = numCtrlRepository.GetMaxValue("LotNo", "LotNo"); if (currentMaxNum == null) { currentMaxNum = new NumControl(); currentMaxNum.NOType = "LotNo"; currentMaxNum.NOName = "LotNo"; currentMaxNum.Value = sublotNo + beginNO; currentMaxNum.Customer = ""; numCtrlRepository.InsertNumControl(currentMaxNum); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.LotNo, sublotNo + beginNO); } else if (currentMaxNum.Value.Substring(0, 8) != sublotNo) { currentMaxNum.Value = sublotNo + beginNO; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.LotNo, sublotNo + beginNO); } else { if (currentMaxNum.Value.EndsWith("9999")) { //SqlTransactionManager.Commit(); throw new FisException("CHK867", new string[] { }); //CHK, The Quantity of LotNo is full today, please contact IE! } else { ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789", 4, "9999", beginNO, '0'); string sequenceNumber = currentMaxNum.Value.Substring(8, 4); sequenceNumber = seqCvt.NumberRule.IncreaseToNumber(sequenceNumber, 1); currentMaxNum.Value = sublotNo + sequenceNumber;//currentMaxNum.Value.Substring(0, 8) + sequenceNumber; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.LotNo, sublotNo + sequenceNumber); } } } } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } //Insert Lot/PCBLot //Insert Lot:LotNo=新产生No, Line=当前Line,Type=@Type, Qty=1, Status=0 //Insert PCBLot:LotNo=@LotNo, PCBNo=@MBSN, Status=1 LotInfo conLotInfo = new LotInfo(); conLotInfo.lotNo = (string)CurrentSession.GetValue(Session.SessionKeys.LotNo); conLotInfo.line = this.Line; conLotInfo.mbcode = strMBCode; conLotInfo.type = strType; conLotInfo.qty = 1; conLotInfo.status = "0"; conLotInfo.editor = this.Editor; itemRepository.InsertLotInfoDefered(CurrentSession.UnitOfWork, conLotInfo); PcblotInfo conPcblotInfo = new PcblotInfo(); conPcblotInfo.lotNo = (string)CurrentSession.GetValue(Session.SessionKeys.LotNo); conPcblotInfo.pcbno = currenMB.Sn; conPcblotInfo.status = "1"; conPcblotInfo.editor = this.Editor; itemRepository.InsertPCBLotInfoDefered(CurrentSession.UnitOfWork, conPcblotInfo); CurrentSession.AddValue("LotNoQty", 1); } else { LotInfo conLotInfo = new LotInfo(); //Get Qty //conLotInfo.lotNo = retlot[0].lotNo; ////conLotInfo.type = strType; //IList<LotInfo> getLotInfo = itemRepository.GetlotInfoList(conLotInfo); //CurrentSession.AddValue("LotNoQty", getLotInfo[0].qty + 1); CurrentSession.AddValue("LotNoQty",retlot[0].qty + 1); //存在@MBCode和@Type记录,则Update Lot,Insert PCBLot //Update Lot:Qty=Qty+1, Editor, Udt where LotNo=@LotNo //Insert PCBLot:LotNo=@LotNo, PCBNo=@MBSN, Status=1 LotInfo setLotInfo = new LotInfo(); conLotInfo = new LotInfo(); conLotInfo.lotNo = retlot[0].lotNo; //conLotInfo.type = strType; //setLotInfo.qty = retlot[0].qty + 1;//1;//setValue.Qty赋1,其他按需要赋值即可 setLotInfo.qty = 1; setLotInfo.editor = this.Editor; setLotInfo.udt = DateTime.Now; //itemRepository.UpdateLotInfoDefered(CurrentSession.UnitOfWork, setLotInfo, conLotInfo); itemRepository.UpdateLotInfoForIncQtyDefered(CurrentSession.UnitOfWork, setLotInfo, conLotInfo); PcblotInfo conPcblotInfo = new PcblotInfo(); conPcblotInfo.lotNo = retlot[0].lotNo; conPcblotInfo.pcbno = currenMB.Sn; conPcblotInfo.status = "1"; conPcblotInfo.editor = this.Editor; itemRepository.InsertPCBLotInfoDefered(CurrentSession.UnitOfWork, conPcblotInfo); } //GetPassQtyfromlotSetting -Activity // Defered方法, +1 可能没立即保存--如何确保Qty值 ?? -- int passQtyforLine = (int)CurrentSession.GetValue("PassQtyinlotSetting"); //2、 Check @MBCode和@Type对应的Qty,若Qty>=PassQty,则Update Lot //Update Lot:Status=1 where LotNo=@LotNo int currentQty = (int)CurrentSession.GetValue("LotNoQty"); if (currentQty >= passQtyforLine) { LotInfo setLotInfo = new LotInfo(); LotInfo conLotInfo = new LotInfo(); //DEBUG Mantis 1005 if ((retlot == null) || (retlot.Count == 0)) conLotInfo.lotNo = (string)CurrentSession.GetValue(Session.SessionKeys.LotNo); else conLotInfo.lotNo = retlot[0].lotNo; setLotInfo.status = "1"; setLotInfo.udt = DateTime.Now; itemRepository.UpdateLotInfoDefered(CurrentSession.UnitOfWork, setLotInfo, conLotInfo); } return base.DoExecute(executionContext); }
private string GetMBCT(string cfg, string thisYear, string weekCode,string mbcfg) { try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); NumControl currentMaxNum = numCtrlRepository.GetMaxValue("MBCT", mbcfg); if (currentMaxNum == null) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB"); if (first == null) { throw new FisException("ICT013", new string[] { }); } currentMaxNum = new NumControl(); currentMaxNum.NOName = mbcfg; currentMaxNum.NOType = "MBCT"; currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; currentMaxNum.Customer = ""; numCtrlRepository.InsertNumControl(currentMaxNum); SqlTransactionManager.Commit(); return cfg + "00" + first.code + weekCode + beginNO; } else if (currentMaxNum.Value.Substring(0, 6) != (thisYear + weekCode)) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB"); if (first == null) { throw new FisException("ICT013", new string[] { }); } currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); return cfg + "00" + first.code + weekCode + beginNO; } else { if (currentMaxNum.Value.EndsWith("ZZZ")) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IList<SupplierCodeInfo> codeList = currentProductRepository.GetSupplierCodeListByCode(currentMaxNum.Value.Substring(6, 2)); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB", codeList[0].idex); if (first == null) { throw new FisException("ICT005", new string[] { }); } currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); return cfg + "00" + first.code + weekCode + beginNO; } else { ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 3, "ZZZ", beginNO, '0'); string sequenceNumber = currentMaxNum.Value.Substring(8, 3); sequenceNumber = seqCvt.NumberRule.IncreaseToNumber(sequenceNumber, 1); currentMaxNum.Value = currentMaxNum.Value.Substring(0, 8) + sequenceNumber; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); return cfg + "00" + currentMaxNum.Value.Substring(6, 2) + weekCode + sequenceNumber; } } } } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } }
/// <summary> /// /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { MB currenMB = CurrentSession.GetValue(Session.SessionKeys.MB) as MB; IPartRepository CurrentPartRepository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); string cust = CurrentPartRepository.GetPartInfoValue(currenMB.PCBModelID, "Cust"); string[] CustCondition = { "ZELDA", "HALFPIPE", "MOSELEY" }; if (CustCondition.Contains(cust)) { IMBRepository currentMBRepository = RepositoryFactory.GetInstance().GetRepository<IMBRepository, IMB>(); string eepValue = currentMBRepository.GetPCBInfoValue(currenMB.Sn, "EEPROM"); if (string.IsNullOrEmpty(eepValue)) { try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); string mbFamily = CurrentSession.GetValue(Session.SessionKeys.FamilyName) as string; MACRange currentRange = numCtrlRepository.GetMACRange(mbFamily, new string[] { "R", "A" }); if (currentRange == null) { throw new FisException("ICT015", new string[] { }); } else { NumControl currentMaxNum = numCtrlRepository.GetMaxValue("EEPROM", mbFamily); if (currentMaxNum == null) { currentMaxNum = new NumControl(); currentMaxNum.NOName = mbFamily; currentMaxNum.NOType = "EEPROM"; currentMaxNum.Value = currentRange.BegNo.Substring(0, 11) + "1"; currentMaxNum.Customer = ""; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.InsertNumControlDefered(uof, currentMaxNum); if (currentMaxNum.Value.Substring(0, 11) == currentRange.EndNo.Substring(0, 11)) { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Closed); } else { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Active); } uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.EEP, currentMaxNum.Value); } else { if (currentMaxNum.Value.Substring(0, 11) == currentRange.EndNo.Substring(0, 11)) { numCtrlRepository.SetMACRangeStatus(currentRange.ID, MACRange.MACRangeStatus.Closed); currentRange = numCtrlRepository.GetMACRange(mbFamily, new string[] { "R" }); if (currentMaxNum.Value.Substring(0, 11) == currentRange.BegNo.Substring(0, 11) || currentMaxNum.Value.Substring(0, 11) == currentRange.EndNo.Substring(0, 11)) { throw new FisException("ICT017", new string[] { currentMaxNum.Value.Substring(0, 11) }); } } if (string.Compare(currentMaxNum.Value.Substring(0, 11), currentRange.BegNo.Substring(0, 11)) < 0 || string.Compare(currentMaxNum.Value.Substring(0, 11), currentRange.EndNo.Substring(0, 11)) > 0) { currentMaxNum.Value = currentRange.BegNo.Substring(0, 11) + "1"; } else { ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789", 7, "9999999", "0000000", '0'); string sequenceNumber = currentMaxNum.Value.Substring(4, 7); sequenceNumber = seqCvt.NumberRule.IncreaseToNumber(sequenceNumber, 1); currentMaxNum.Value = currentMaxNum.Value.Substring(0, 4) + sequenceNumber + "1"; } IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); if (currentMaxNum.Value.Substring(0, 11) == currentRange.EndNo.Substring(0, 11)) { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Closed); } else { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Active); } uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.EEP, currentMaxNum.Value); } } } } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } } } return base.DoExecute(executionContext); }
/// <summary> /// 產生CustomerSN號相关逻辑 /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override System.Workflow.ComponentModel.ActivityExecutionStatus DoExecute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext) { Session session = CurrentSession; IProduct product = (IProduct)session.GetValue(Session.SessionKeys.Product); IMB mb = (IMB)session.GetValue(Session.SessionKeys.MB); IProductRepository productRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IMBRepository mbRep = RepositoryFactory.GetInstance().GetRepository<IMBRepository>(); IPartRepository partRepository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); IModelRepository modelRepository = RepositoryFactory.GetInstance().GetRepository<IModelRepository, Model>(); ActivityCommonImpl utl = ActivityCommonImpl.Instance; string customSN = null; string customer = null; string family =null; if (product==null) { if (mb == null) { family = utl.IsNull<string>(session, Session.SessionKeys.FamilyName); } else { family = mb.MBCode; customer = mb.Customer; } } else { family = product.Family; customer = product.Customer; } if (string.IsNullOrEmpty(customer)) { customer = this.Customer; } ConstValueInfo info = new ConstValueInfo(); info.type = "CustSNExceptRule"; info.name = family; IList<ConstValueInfo> retList = partRepository.GetConstValueInfoList(info); if (retList == null || retList.Count == 0) { // 請维护 ConstValue的 CustSNExceptRule //throw new FisException("CHK1076", new string[] { "ConstValue", "CustSNExceptRule" }); string seqFormat = null; IList<ConstValueInfo> valueList = utl.ConstValue("CustSNRule", family, out seqFormat); string nextNum = utl.GenSN.GetNextSequence(product, customer, "CUSTSN", seqFormat); customSN = nextNum; if (product!=null) { productRep.ExistsCustomSnThrowErrorDefered(session.UnitOfWork, product.ProId, customSN); product.CUSTSN = nextNum; productRep.Update(product, session.UnitOfWork); } else if (mb != null) { mbRep.ExistsCustomSnThrowErrorDefered(session.UnitOfWork,mb.Sn,customSN); mb.CustSn = nextNum; mbRep.Update(mb, session.UnitOfWork); } } else { #region for Skoda model if (product == null) { throw new FisException("CHK975", new List<string> { Session.SessionKeys.Product }); } string skodaFamily4 = retList[0].value; if (string.IsNullOrEmpty(skodaFamily4) || skodaFamily4.Length != 4) { throw new FisException("CHK1076", new string[] { "ConstValue", "CustSNExceptRule" }); } IList<IMES.FisObject.Common.Model.ModelInfo> infoModel = modelRepository.GetModelInfoByModelAndName(product.Model, "Country"); if (infoModel == null || infoModel.Count == 0) { throw new FisException("CHK1076", new string[] { "ModelInfo", "Country" }); } info = new ConstValueInfo(); info.type = "SKODAConutryCode"; info.name = infoModel[0].Value; retList = partRepository.GetConstValueInfoList(info); if (retList == null || retList.Count == 0) { // 請维护 ConstValue的 SKODAConutryCode throw new FisException("CHK1076", new string[] { "ConstValue", "SKODAConutryCode" }); } string skodaCountry = retList[0].value; if (string.IsNullOrEmpty(skodaCountry) || skodaCountry.Length != 5) { throw new FisException("CHK1076", new string[] { "ConstValue", "SKODAConutryCode" }); } DateTime curDate = DateTime.Now; string year = curDate.Year.ToString(); string prestr = ""; ; // 1~4位:是Family4内容 prestr = skodaFamily4; // 5~9位:根据国别判断,如果不足5位末尾补0 prestr += skodaCountry; // 第10位:年份最后一码 prestr += year.Substring(year.Length - 1, 1); // 第11位:1-9月是数字,10月为A,11月B,12月C if (curDate.Month <= 9) prestr += curDate.Month.ToString(); else if (curDate.Month == 10) prestr += "0"; else if (curDate.Month == 11) prestr += "A"; else if (curDate.Month == 12) prestr += "B"; bool addflag = false; string custSn = ""; try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { //从NumControl中获取流水号 //GetMaxNumber INumControlRepository numControl = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); //maxnum = numControl.GetMaxNumber("CPQSNO", prestr + "{0}"); //var maxObj = numControl.GetMaxNumberObj("CPQSNO", prestr + "{0}"); string maxnum = ""; var maxObj = numControl.GetMaxValue("SkodaSN", prestr); //檢查有沒有lock index, 沒有lock index, 改變查詢條件 if (maxObj == null) { //lock NoType='CPQSNO' and NoName='Lock' var data = numControl.GetMaxValue("SkodaSN", "Lock"); maxObj = numControl.GetMaxValue("SkodaSN", prestr); } if (maxObj != null) maxnum = maxObj.Value; if (string.IsNullOrEmpty(maxnum)) { maxnum = "000000"; //起始值:000000 addflag = true; } else { //maxnum="CNU248000Y"; string temstr = "000000"; //起始值:000000 string numstr = maxnum.Substring(maxnum.Length - 6); temstr = numstr; if (numstr.ToUpper() == "999999") { FisException fe = new FisException("CHK867", new string[] { }); //流水号已满! throw fe; } maxnum = GetSN(temstr); } custSn = prestr + maxnum.ToUpper(); // 自己管理事务开始 IUnitOfWork uof = new UnitOfWork();//使用自己的UnitOfWork NumControl item = null;// new NumControl(); if (addflag) { item = new NumControl(); item.NOType = "SkodaSN"; item.Value = custSn; item.NOName = prestr; item.Customer = this.Customer; } else { item = maxObj; item.Value = custSn; } //numControl.SaveMaxNumber(item, addflag, prestr + "{0}"); numControl.SaveMaxNumber(item, addflag); customSN = custSn; if (product != null) { product.CUSTSN = custSn; productRep.Update(product, uof); } else if (mb != null) { mb.CustSn = custSn; mbRep.Update(mb, uof); } uof.Commit(); //立即提交UnitOfWork更新NumControl里面的最大值 // [Customer SN Print]保存结果:增加更新[CustomerSN_Qty]. CustomerSN_Qty栏位 //UPDATE [HPIMES].[dbo].[MO] //SET [CustomerSN_Qty] =[ CustomerSN_Qty]+1 //From Product a,MO b WHERE a.MO=b.MO and a.ProductID=ProductID# if (product != null) { IMORepository moRepository = RepositoryFactory.GetInstance().GetRepository<IMORepository, MO>(); moRepository.UpdateMoForIncreaseCustomerSnQty(product.ProId, 1); } } SqlTransactionManager.Commit();//提交事物,释放行级更新锁 } catch (Exception) { SqlTransactionManager.Rollback(); throw; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } #endregion } session.AddValue(Session.SessionKeys.CustSN, customSN); if (product != null) { session.AddValue(Session.SessionKeys.PrintLogName, product.Customer + "SNO"); session.AddValue(Session.SessionKeys.PrintLogBegNo, product.CUSTSN); session.AddValue(Session.SessionKeys.PrintLogEndNo, product.CUSTSN); session.AddValue(Session.SessionKeys.PrintLogDescr, product.ProId); } else { session.AddValue(Session.SessionKeys.PrintLogName, this.Customer + "SNO"); session.AddValue(Session.SessionKeys.PrintLogBegNo, customSN); session.AddValue(Session.SessionKeys.PrintLogEndNo, customSN); session.AddValue(Session.SessionKeys.PrintLogDescr, family); } return base.DoExecute(executionContext); }
/// <summary> /// 產生CustomerSN號相关逻辑 /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override System.Workflow.ComponentModel.ActivityExecutionStatus DoExecute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext) { IProduct product = (IProduct)CurrentSession.GetValue(Session.SessionKeys.Product); IProductRepository productRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IPartRepository PartRepository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); //lock (_syncRoot_GetSeq)//用于防止同一段代码被同时执行,以前只有一个Service时有效,现在多个Service没有去掉,聊胜于无 //var logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //logger.InfoFormat("GenerateCustomerSnActivity: CurrentSession Hash: {0}; CurrentSession Key: {1}; CurrentSession Type: {2}", CurrentSession.GetHashCode().ToString(), CurrentSession.Key, CurrentSession.Type.ToString()); //logger.InfoFormat("GenerateCustomerSnActivity: IProduct Hash: {0}; IProduct Key: {1}", product.GetHashCode().ToString(), product.Key); //need modify try { //CN(中try国代码)+U(Site Code)+年尾码+周别码+流水码 string custSn = ""; DateTime curDate = DateTime.Now; // string year = curDate.Year.ToString(); string maxnum = ""; string prestr = ""; //求当前日期是一年的中第几周 //int weeks = 0; DateTime dateTime = DateTime.Now;//new DateTime(2016,1,1); var ret = IMES.Infrastructure.Utility.Generates.WeekRuleEngine.Calculate("103", dateTime); string weekCode = ret.Week.ToString().PadLeft(2, '0'); string year = ret.Year.ToString();//dateTime.Year.ToString(); IList<string> valueList = PartRepository.GetValueFromSysSettingByName("Site"); if (valueList.Count == 0) { throw new Exception("Error:尚未設定Site..."); } else { if (valueList[0] == "ICC")//重慶 { custSn = "5CG";// +custSn + year.Substring(year.Length - 1, 1) + weekCode; } else //IPC 上海 { custSn = "CNU";// +custSn + year.Substring(year.Length - 1, 1) + weekCode;//weeks.ToString("d2"); } } //custSn = "CN" + "U" + custSn + year.Substring(year.Length - 1, 1) + weekCode;//weeks.ToString("d2"); ActivityCommonImpl commonImpl = ActivityCommonImpl.Instance; custSn = commonImpl.GetCustSNPreFix3(custSn,product.Family) + year.Substring(year.Length - 1, 1) + weekCode;//weeks.ToString("d2"); prestr = custSn; // 自己管理事务开始 SqlTransactionManager.Begin(); // IUnitOfWork uof = new UnitOfWork();//使用自己的UnitOfWork //从NumControl中获取流水号 //GetMaxNumber INumControlRepository numControl = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); bool addflag = false; //maxnum = numControl.GetMaxNumber("CPQSNO", prestr + "{0}"); var maxObj = numControl.GetMaxNumberObj("CPQSNO", prestr + "{0}"); if (maxObj != null) maxnum = maxObj.Value; //Vincent 2012-12-04 change min sequence number if (string.IsNullOrEmpty(maxnum)) { maxnum = "0000"; addflag = true; } else { // mantis 1515 Regex regex = new Regex("[MW]{3}", RegexOptions.Compiled | RegexOptions.Singleline); string tmpnum = GetSN(maxnum); int cntGetSN = 0; while (regex.Match(tmpnum.ToUpper().Substring(tmpnum.Length - 3)).Success) { cntGetSN++; if (cntGetSN > 3) { throw new NullReferenceException("Error, GetSn with type 'WM*'"); } tmpnum = GetSN(tmpnum); } maxnum = tmpnum; } custSn = custSn + maxnum.ToUpper(); if (productRep.CheckExistCustomSn(custSn)) { List<string> errpara = new List<string>(); errpara.Add(custSn); throw new FisException("CHK1021", errpara); } product.CUSTSN = custSn; //productRep.Update(product, uof); productRep.Update(product, CurrentSession.UnitOfWork); NumControl item = null;// new NumControl(); if (addflag) { item = new NumControl(); item.NOType = "CPQSNO"; item.Value = custSn; item.NOName = ""; item.Customer = "HP"; } else { item = maxObj; item.Value = custSn; } //numControl.SaveMaxNumber(item, addflag, prestr + "{0}"); numControl.SaveMaxNumber(item, addflag); // uof.Commit(); //立即提交UnitOfWork更新NumControl里面的最大值 SqlTransactionManager.Commit();//提交事物,释放行级更新锁 // [Customer SN Print]保存结果:增加更新[CustomerSN_Qty]. CustomerSN_Qty栏位 //UPDATE [HPIMES].[dbo].[MO] //SET [CustomerSN_Qty] =[ CustomerSN_Qty]+1 //From Product a,MO b WHERE a.MO=b.MO and a.ProductID=ProductID# IMORepository moRepository = RepositoryFactory.GetInstance().GetRepository<IMORepository, MO>(); moRepository.UpdateMoForIncreaseCustomerSnQty(product.ProId, 1); } catch (Exception) { SqlTransactionManager.Rollback(); throw; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } if (IsNeedPrintlogParam) { CurrentSession.AddValue(Session.SessionKeys.PrintLogName, product.Customer + "SNO"); CurrentSession.AddValue(Session.SessionKeys.PrintLogBegNo, product.CUSTSN); CurrentSession.AddValue(Session.SessionKeys.PrintLogEndNo, product.CUSTSN); CurrentSession.AddValue(Session.SessionKeys.PrintLogDescr, product.ProId); } return base.DoExecute(executionContext); }
/// <summary> /// 產生CustomerSN號相关逻辑 /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override System.Workflow.ComponentModel.ActivityExecutionStatus DoExecute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext) { IProduct product = (IProduct)CurrentSession.GetValue(Session.SessionKeys.Product); IProductRepository productRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IPartRepository ipartRepository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); //need modify try { //CN(中try国代码)+U(Site Code)+年尾码+周别码+流水码 string custSn = ""; DateTime curDate = DateTime.Now; // string year = curDate.Year.ToString(); string maxnum = ""; string prestr = ""; //求当前日期是一年的中第几周 //int weeks = 0; DateTime dateTime = DateTime.Now;//new DateTime(2016,1,1); var ret = IMES.Infrastructure.Utility.Generates.WeekRuleEngine.Calculate("103", dateTime); string weekCode = ret.Week.ToString().PadLeft(2, '0'); string year = ret.Year.ToString();//dateTime.Year.ToString(); custSn = "CN" + "U" + custSn + year.Substring(year.Length - 1, 1) + weekCode;//weeks.ToString("d2"); prestr = custSn; // 自己管理事务开始 SqlTransactionManager.Begin(); IUnitOfWork uof = new UnitOfWork();//使用自己的UnitOfWork //从NumControl中获取流水号 //GetMaxNumber INumControlRepository numControl = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); bool addflag = false; maxnum = numControl.GetMaxNumber("CPQSNO", prestr + "{0}"); if (string.IsNullOrEmpty(maxnum)) { /* 2012-6-27,为产线测试用,正式使用时要修改回来 maxnum = "Z000"; //起始值:Z000 */ maxnum = "Z000"; //非正式起始值:V000 addflag = true; } else { //maxnum="CNU248000Y"; /* 2012-6-27,为产线测试用,正式使用时要修改回来 string temstr = "Z000"; //起始值:Z000 */ string temstr = "Z000"; string numstr = maxnum.Substring(maxnum.Length - 4); temstr = numstr; //2012-6-27,为产线测试用,正式使用时要删除 /* if (numstr.ToUpper() == "VZZZ") { FisException fe = new FisException("CHK867", new string[] { }); //流水号已满! throw fe; } */ if (numstr.ToUpper() == "YZZZ") { FisException fe = new FisException("CHK867", new string[] { }); //流水号已满! throw fe; } string[] seqLst = new string[4]; seqLst[0] = temstr.Substring(0, 1); seqLst[1] = temstr.Substring(1, 1); seqLst[2] = temstr.Substring(2, 1); seqLst[3] = temstr.Substring(3, 1); int[] idexLst = getSeqNum(seqLst); if (idexLst[3] == 30) { if (idexLst[2] == 30) { if (idexLst[1] == 30) { if (idexLst[0] == 29) { List<string> errpara = new List<string>(); throw new FisException("CHK867", errpara); //流水号已满! } else { if (idexLst[0] == 30) { idexLst[0] = 28; } else if (idexLst[0] == 28) { idexLst[0] = 27; } else if (idexLst[0] == 27) { idexLst[0] = 29; } else { List<string> errpara = new List<string>(); throw new FisException("CHK867", errpara); //非合法的Z、X、W、Y,视为满 } idexLst[1] = 0; idexLst[2] = 0; idexLst[3] = 0; } } else { idexLst[1] += 1; idexLst[2] = 0; idexLst[3] = 0; } } else { idexLst[2] += 1; idexLst[3] = 0; } } else { idexLst[3] += 1; } temstr = numLst[idexLst[0]] + numLst[idexLst[1]] + numLst[idexLst[2]] + numLst[idexLst[3]]; maxnum = temstr; } custSn = custSn + maxnum.ToUpper(); product.CUSTSN = custSn; productRep.Update(product, uof); NumControl item = new NumControl(); item.NOType = "CPQSNO"; item.Value = custSn; item.NOName = ""; item.Customer = "HP"; numControl.SaveMaxNumber(item, addflag, prestr + "{0}"); uof.Commit(); //立即提交UnitOfWork更新NumControl里面的最大值 SqlTransactionManager.Commit();//提交事物,释放行级更新锁 //IMORepository moRepository = RepositoryFactory.GetInstance().GetRepository<IMORepository, MO>(); // moRepository.UpdateMoForIncreaseCustomerSnQty(product.ProId, 1); } catch (Exception) { SqlTransactionManager.Rollback(); throw; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } IList<string> values = ipartRepository.GetValueFromSysSettingByName("Customer"); string value=""; if (values.Count > 0) value = values[0]; CurrentSession.AddValue(Session.SessionKeys.PrintLogName, value + " SNO"); CurrentSession.AddValue(Session.SessionKeys.PrintLogBegNo, product.ProId); CurrentSession.AddValue(Session.SessionKeys.PrintLogEndNo, product.ProId); CurrentSession.AddValue(Session.SessionKeys.PrintLogDescr, product.CUSTSN); return base.DoExecute(executionContext); }
/// <summary> /// 產生CustomerSN號相关逻辑 /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override System.Workflow.ComponentModel.ActivityExecutionStatus DoExecute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext) { IProduct product = (IProduct)CurrentSession.GetValue(Session.SessionKeys.Product); IProductRepository productRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); string stag =(string) CurrentSession.GetValue(Session.SessionKeys.CN); //need modify if (stag == "T") { return base.DoExecute(executionContext); } try { //CN(中国代码)+U(Site Code)+年尾码+周别码+流水码 string custSn = ""; //string weekCode=""; DateTime curDate = DateTime.Now; //string year = curDate.Year.ToString(); string maxnum = ""; string prestr = ""; bool addflag = false; DateTime dateTime = new DateTime(2016, 1, 1); var dd = DateTime.Now; var ret = IMES.Infrastructure.Utility.Generates.WeekRuleEngine.Calculate("103", DateTime.Now); string weekCode = ret.Week.ToString().PadLeft(2, '0'); string year = ret.Year.ToString(); prestr = custSn; SqlTransactionManager.Begin(); IUnitOfWork uof = new UnitOfWork();//使用自己的UnitOfWork custSn = "CN" + "U" + custSn + year.Substring(year.Length - 1, 1) + weekCode; //从NumControl中获取流水号 //GetMaxNumber INumControlRepository numControl = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); //maxnum = numControl.GetMaxNumber("CPQSNO", prestr + "{0}"); var maxObj = numControl.GetMaxNumberObj("CPQSNO", prestr + "{0}"); if (maxObj != null) maxnum = maxObj.Value; if (string.IsNullOrEmpty(maxnum)) { maxnum = "9000"; addflag = true; } else { //maxnum="CNU248000Y"; MathSequenceWithCarryNumberRule marc = new MathSequenceWithCarryNumberRule(4, "0123456789BCDFGHJKLMNPQRSTVWXYZ"); string numstr = maxnum.Substring(maxnum.Length - 4); //string temstr = "0000"; if (numstr.ToUpper() == "YZZZ") { FisException fe = new FisException("CHK867", new string[] { }); //流水号已满! throw fe; } numstr = marc.IncreaseToNumber(numstr, 1); maxnum = numstr; } custSn = custSn + maxnum.ToUpper(); product.CUSTSN = custSn; //productRep.Update(product, CurrentSession.UnitOfWork); NumControl item = null;// new NumControl(); if (addflag) { item = new NumControl(); item.NOType = "CPQSNO"; item.Value = custSn; item.NOName = ""; item.Customer = "HP"; } else { item = maxObj; item.Value = custSn; } //numControl.SaveMaxNumber(item, addflag, prestr + "{0}"); numControl.SaveMaxNumber(item, addflag); uof.Commit(); //立即提交UnitOfWork更新NumControl里面的最大值 SqlTransactionManager.Commit();//提交事物,释放行级更新锁 // [Customer SN Print]保存结果:增加更新[CustomerSN_Qty]. CustomerSN_Qty栏位 //UPDATE [HPIMES].[dbo].[MO] //SET [CustomerSN_Qty] =[ CustomerSN_Qty]+1 //From Product a,MO b WHERE a.MO=b.MO and a.ProductID=ProductID# IMORepository moRepository = RepositoryFactory.GetInstance().GetRepository<IMORepository, MO>(); moRepository.UpdateMoForIncreaseCustomerSnQty(product.ProId, 1); } catch (Exception) { SqlTransactionManager.Rollback(); throw; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } /*CurrentSession.AddValue(Session.SessionKeys.PrintLogName, product.Customer + " SNO"); CurrentSession.AddValue(Session.SessionKeys.PrintLogBegNo, product.CUSTSN); CurrentSession.AddValue(Session.SessionKeys.PrintLogEndNo, product.CUSTSN); CurrentSession.AddValue(Session.SessionKeys.PrintLogDescr, product.ProId); */ return base.DoExecute(executionContext); }
private static string GetFlowNumber() { long flow_number = 0; lock (SS_LOCK) { SqlTransactionManager.Begin(); INumControlRepository rep = RepositoryFactory.GetInstance() .GetRepository<INumControlRepository, NumControl>(); NumControl next_avail = rep.GetMaxValue(SS_TYPE, SS_NAME); if (next_avail == null) { next_avail = new NumControl(); next_avail.Customer = SS_CUST; next_avail.NOType = SS_TYPE; next_avail.NOName = SS_NAME; flow_number = SS_INIT; next_avail.Value = (flow_number + 1).ToString(); rep.InsertNumControl(next_avail); SqlTransactionManager.Commit(); } else { flow_number = long.Parse(next_avail.Value); next_avail.Value = (flow_number + 1).ToString(); IUnitOfWork uof = new UnitOfWork(); rep.Update(next_avail, uof); uof.Commit(); SqlTransactionManager.Commit(); } } return (flow_number % 100000).ToString("D5"); }
/// <summary> /// 產生Carton NO號相关逻辑 /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override System.Workflow.ComponentModel.ActivityExecutionStatus DoExecute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext) { string ctno = (string)CurrentSession.GetValue("CTNO"); int qty = (int)CurrentSession.GetValue("QTY"); IProductRepository productRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); //获取Part.PartNo 和 Part.Descr //条件:Part.PartNo = PartInfo.PartNo and PartInfo.InfoValue=Left([CT No],5) //限制:Top 1 //若Part.PartNo不存在,则报错:“错误的CT No” IPartRepository partRep = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); PartInfo cond = new PartInfo(); cond.PN = ctno.Substring(0, 5); IList<PartInfo> partList = partRep .GetPartInfoList(cond); PartInfo partinfo = partList[0]; IPart part = partRep.Find(partinfo.PN); //Generate New CT No //方法:原[CT No] + 流水码 //数量:Qty //流水码规则: //3位 //31进制:0123456789BCDFGHJKLMNPQRSTVWXYZ //从000开始 // 若为’ZZZ’,则报错:“流水号已用完” //[CT No]为前缀,若[CT No]改变,则流水码从000开始 try { string newCtno = ""; string maxnum = ""; string prestr = ""; bool addflag = false; prestr = ctno; // 自己管理事务开始 //SqlTransactionManager.Begin(); //IUnitOfWork uof = new UnitOfWork();//使用自己的UnitOfWork //从NumControl中获取流水号 //GetMaxNumber INumControlRepository numControl = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); MathSequenceWithCarryNumberRule marc = new MathSequenceWithCarryNumberRule(3, "0123456789BCDFGHJKLMNPQRSTVWXYZ"); NumControl maxObj = numControl.GetMaxNumberObj("CTNO", prestr + "{0}"); if (maxObj != null) maxnum = maxObj.Value; if (string.IsNullOrEmpty(maxnum)) { maxnum = "000"; addflag = true; } else { string numstr = maxnum.Substring(maxnum.Length - 3); long diff = marc.CalculateDifference(numstr,"ZZZ"); if (numstr.ToUpper() == "ZZZ" || diff < qty) { FisException fe = new FisException("CHK867", new string[] { }); //流水号已满! throw fe; } numstr = marc.IncreaseToNumber(numstr, 1); maxnum = numstr; } newCtno = ctno + maxnum.ToUpper(); NumControl item = null;// new NumControl(); if (addflag) { item = new NumControl(); item.NOType = "CTNO"; item.Value = newCtno; item.NOName = ""; item.Customer = "HP"; } else { item = maxObj; item.Value = newCtno; } int count = 1; IPrintLogRepository printRep = RepositoryFactory.GetInstance().GetRepository<IPrintLogRepository, PrintLog>(); IList<string> ctnoList = new List<string>(); while(count <= qty) { ctnoList.Add(item.Value); numControl.SaveMaxNumber(item, addflag); //Insert PartSN //IECSN:产生的18位CT No //IECPn:Step2中获取的Part.PartNo //PartType:Step2中获取的Part.Descr //VendorSN:输入的15码的[CT No] IPartSnRepository partsnRep = RepositoryFactory.GetInstance().GetRepository<IPartSnRepository, PartSn>(); //PartSn(string iecSn, string iecPn, string type, string vendorSn, string vendorDCode, string vCode, string pn151, string editor, string dateCode); PartSn partSn = new PartSn(newCtno, part.PN, part.Descr,ctno,"","","",this.Editor,""); partsnRep.Add(partSn,CurrentSession.UnitOfWork); //Insert PrintLog //Name=’RCTO CT Label’ //BegNo=Begin [CT No] //EndNo=End [CT No] //Descr=[Qty] var log = new PrintLog { Name = "RCTO CT Label", BeginNo = newCtno, EndNo = newCtno, Descr = Convert.ToString(qty), Editor = this.Editor }; printRep.Add(log, CurrentSession.UnitOfWork); //get next count++; addflag = false; maxnum = marc.IncreaseToNumber(maxnum, 1); newCtno = ctno + maxnum.ToUpper(); item = maxObj; item.Value = newCtno; } //uof.Commit(); //立即提交UnitOfWork更新NumControl里面的最大值 //SqlTransactionManager.Commit();//提交事物,释放行级更新锁 CurrentSession.AddValue("CTNOList", ctnoList); } catch (Exception) { //SqlTransactionManager.Rollback(); throw; } finally { //SqlTransactionManager.Dispose(); //SqlTransactionManager.End(); } return base.DoExecute(executionContext); }
/// <summary> /// Generate DummyPalletNo, and Save the Relation with Product in the IMES_PAK..Dummy_ShipDet Table /// </summary> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { FisException ex; List<string> erpara = new List<string>(); // Product currentProduct = (Product)CurrentSession.GetValue(Session.SessionKeys.Product); // string productId = currentProduct.ProId; // 绑定的是每一个刷入的CustSN的ProductID与DummyPalletNo的关系 IProductRepository productRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IList<string> ScanedProductIDList = (IList<string>)CurrentSession.GetValue(Session.SessionKeys.NewScanedProductIDList); IDeliveryRepository iDeliveryRepository = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>(); IPalletRepository iPalletRepository = RepositoryFactory.GetInstance().GetRepository<IPalletRepository, Pallet>(); string DPC = (string)CurrentSession.GetValue(Session.SessionKeys.DummyPalletCase); string dummyPalletNo = (string)CurrentSession.GetValue(Session.SessionKeys.DummyPalletNo); string generateDummyPalletNo = string.Empty; if (DPC == "NA" || DPC == "BA") { //DummyShipDetInfo currentDummyshipdet = (DummyShipDetInfo)CurrentSession.GetValue(Session.SessionKeys.DummyShipDet); //currentDummyshipdet.bol = dummyPalletNo; //currentDummyshipdet.editor = this.Editor; //currentDummyshipdet.cdt = DateTime.Now; ////update: //DummyShipDetInfo condDummyshipdet = new DummyShipDetInfo(); //condDummyshipdet.snoId = currentDummyshipdet.snoId; //iDeliveryRepository.UpdateDummyShipDetInfo(currentDummyshipdet, condDummyshipdet); } else if (DPC == "NAN" || DPC == "BAN") { DummyShipDetInfo dummyshipdet = new DummyShipDetInfo(); IList<DummyShipDetInfo> dummyshipdetList = null; //---- NumberControl ---- INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); NumControl currentMaxNum = numCtrlRepository.GetMaxValue("Dummy", "DummyPalletNo"); if (currentMaxNum == null) { // 从数据库DummyShip_Det表获取当前最大值 dummyshipdetList = iDeliveryRepository.GetDummyShipDetInfoList(dummyshipdet); //拿全集 if (dummyshipdetList == null || dummyshipdetList.Count <= 0) { //generateDummyPalletNo = "9000000001"; //产线确认修改生产号规则:流水号初始值十进制 60000000 generateDummyPalletNo = "90" + "60000000"; } else { int max = 0; foreach (DummyShipDetInfo iDSD in dummyshipdetList) { if (iDSD.plt != null && iDSD.plt != "") { if (iDSD.plt.Length != 10) { erpara.Add(iDSD.plt); ex = new FisException("PAK071", erpara); throw ex; } if (iDSD.plt.Substring(0, 2) != "90") { erpara.Add(iDSD.plt); ex = new FisException("PAK048", erpara); throw ex; } Boolean exitLetter = Regex.Matches(iDSD.plt.Substring(2, 8), "[a-zA-Z]").Count > 0; if (exitLetter) { erpara.Add(iDSD.plt); ex = new FisException("PAK109", erpara); throw ex; } int temp = Convert.ToInt32(iDSD.plt.Substring(2, 8)); if (temp > max) { max = temp; } } } if (max == 0) { generateDummyPalletNo = "90" + "60000000"; } else { max = max + 1; string maxString = max.ToString(); int maxlength = maxString.Length; if (maxlength < 8) { int len = 8 - maxlength; for (int i = 0; i < len; i++) { maxString = "0" + maxString; } } generateDummyPalletNo = "90" + maxString; } } currentMaxNum = new NumControl(); currentMaxNum.NOName = "DummyPalletNo"; currentMaxNum.NOType = "Dummy"; currentMaxNum.Value = generateDummyPalletNo; currentMaxNum.Customer = this.Customer; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.InsertNumControlDefered(uof, currentMaxNum); uof.Commit(); SqlTransactionManager.Commit(); } else { if (currentMaxNum.Value.Length != 10) { erpara.Add(currentMaxNum.Value); ex = new FisException("PAK071", erpara); throw ex; } if (currentMaxNum.Value.Substring(0, 2) != "90") { erpara.Add(currentMaxNum.Value); ex = new FisException("PAK048", erpara); throw ex; } int temp = Convert.ToInt32(currentMaxNum.Value.Substring(2, 8)); temp = temp + 1; string maxtemp = temp.ToString(); int maxlength = maxtemp.Length; if (maxlength < 8) { int len = 8 - maxlength; for (int i = 0; i < len; i++) { maxtemp = "0" + maxtemp; } } generateDummyPalletNo = "90" + maxtemp; //currentMaxNum = new NumControl(); //currentMaxNum.NOName = "DummyPalletNo"; //currentMaxNum.NOType = "Dummy"; currentMaxNum.Value = generateDummyPalletNo; //currentMaxNum.Customer = this.Customer; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); } //---- NumberControl ---- // 每一个刷入的CustSN的ProductID与都要与该生成的DummyPalletNo绑定,并且bol应记录BOL (For NAN: dummyPalletNo = ideliveryRepository.GetDeliveryInfoValue(deliveryNo, "BOL");) foreach (string iprodId in ScanedProductIDList) { dummyshipdet = new DummyShipDetInfo(); dummyshipdet.plt = generateDummyPalletNo; dummyshipdet.snoId = iprodId; dummyshipdet.bol = dummyPalletNo; dummyshipdet.editor = this.Editor; dummyshipdet.cdt = DateTime.Now; dummyshipdet.udt = DateTime.Now; // insert: iDeliveryRepository.InsertDummyShipDetInfoDefered(CurrentSession.UnitOfWork, dummyshipdet); } } CurrentSession.AddValue(Session.SessionKeys.GenerateDummyPalletNo, generateDummyPalletNo); return base.DoExecute(executionContext); }
/// <summary> /// /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { MB currenMB = CurrentSession.GetValue(Session.SessionKeys.MB) as MB; IPartRepository CurrentPartRepository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); string mbctValue = CurrentPartRepository.GetPartInfoValue(currenMB.PCBModelID, "MBCT"); //if (mbctValue == "T") //{ IMBRepository CurrentMBRepository = RepositoryFactory.GetInstance().GetRepository<IMBRepository, IMB>(); MBCFGDef currentMBCFG = CurrentMBRepository.GetMBCFG(currenMB.MBCode, "PC"); if (currentMBCFG == null || string.IsNullOrEmpty(currentMBCFG.CFG)) { throw new FisException("ICT006", new string[] { }); } // string thisYear = DateTime.Today.Year.ToString("0000"); string thisYear = ""; string weekCode = ""; IModelRepository CurrentModelRepository = RepositoryFactory.GetInstance().GetRepository<IModelRepository, Model>(); //Vincent 2014-01-01 fixed bug : used wrong this year cross year issue //IList<string> weekCodeList = CurrentModelRepository.GetCodeFromHPWeekCodeInRangeOfDescr(); IList<HpweekcodeInfo> weekCodeList = CurrentModelRepository.GetHPWeekCodeInRangeOfDescr(); if (weekCodeList != null && weekCodeList.Count > 0) { weekCode = weekCodeList[0].code; thisYear = weekCodeList[0].descr.Trim().Substring(0, 4); } else { throw new FisException("ICT009", new string[] { }); } try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); NumControl currentMaxNum = numCtrlRepository.GetMaxValue("MBCT", currentMBCFG.CFG); if (currentMaxNum == null) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB"); if (first == null) { throw new FisException("ICT013", new string[] { }); } currentMaxNum = new NumControl(); currentMaxNum.NOName = currentMBCFG.CFG; currentMaxNum.NOType = "MBCT"; currentMaxNum.Value = thisYear + weekCode + first.code + "000"; currentMaxNum.Customer = ""; numCtrlRepository.InsertNumControl(currentMaxNum); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.MBCT, currentMBCFG.CFG + "00" + first.code + weekCode + "000"); } else if (currentMaxNum.Value.Substring(0, 6) != (thisYear + weekCode)) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB"); if (first == null) { throw new FisException("ICT013", new string[] { }); } currentMaxNum.Value = thisYear + weekCode + first.code + "000"; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.MBCT, currentMBCFG.CFG + "00" + first.code + weekCode + "000"); } else { if (currentMaxNum.Value.EndsWith("ZZZ")) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IList<SupplierCodeInfo> codeList = currentProductRepository.GetSupplierCodeListByCode(currentMaxNum.Value.Substring(6, 2)); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB", codeList[0].idex); if (first == null) { throw new FisException("ICT005", new string[] { }); } currentMaxNum.Value = thisYear + weekCode + first.code + "000"; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.MBCT, currentMBCFG.CFG + "00" + first.code + weekCode + "000"); } else { ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 3, "ZZZ", "000", '0'); string sequenceNumber = currentMaxNum.Value.Substring(8, 3); sequenceNumber = seqCvt.NumberRule.IncreaseToNumber(sequenceNumber, 1); currentMaxNum.Value = currentMaxNum.Value.Substring(0, 8) + sequenceNumber; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.MBCT, currentMBCFG.CFG + "00" + currentMaxNum.Value.Substring(6, 2) + weekCode + sequenceNumber); } } } } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } //} return base.DoExecute(executionContext); }
public ArrayList Save(List<string> SNList, List<string> PNList, List<string> errList, string Editor, string Station, string customer) { logger.Debug("(ReturnUsedKeysImpl)Save start" + " [editor]:" + Editor + " [station]:" + Station + " [customer]:" + customer); FisException ex; List<string> erpara = new List<string>(); ArrayList retvaluelist = new ArrayList(); string ECOAReturnStatus = "0"; var productRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); var currentRepository = RepositoryFactory.GetInstance().GetRepository<ICOAStatusRepository, COAStatus>(); try { ///生成group id SqlTransactionManager.Begin(); IUnitOfWork Number_uof = new UnitOfWork();//使用自己的UnitOfWork string prestr = ""; string maxnum = ""; bool addflag = false; INumControlRepository numControl = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); maxnum = numControl.GetMaxNumber("GroupID", prestr + "{0}"); if (string.IsNullOrEmpty(maxnum)) { maxnum = "001"; addflag = true; } else { if (maxnum.Substring(6, 3).ToUpper() == "999") { maxnum = "001"; } else { int count = Int32.Parse(maxnum.Substring(6, 3)); count = count + 1; maxnum = (count).ToString().PadLeft(3, '0'); } } DateTime dd = DateTime.Now; string Groupid = dd.Year.ToString().Substring(2,2) + dd.Month.ToString().PadLeft(2, '0') + dd.Day.ToString().PadLeft(2, '0') + maxnum; NumControl item = new NumControl(); item.NOType = "GroupID"; item.Value = Groupid; item.NOName = ""; item.Customer = "HP"; numControl.SaveMaxNumber(item, addflag, prestr + "{0}"); Number_uof.Commit(); //立即提交UnitOfWork更新NumControl里面的最大值 SqlTransactionManager.Commit();//提交事物,释放行级更新锁 ///////////////////////////////////////////////// for (int i = 0; i < SNList.Count; i++) { IProduct CurrentProduct = null; if (errList[i] == "Pass") { string custSn = SNList[i]; IUnitOfWork work = new UnitOfWork(); CurrentProduct = productRepository.GetProductByCustomSn(custSn); if (CurrentProduct == null) { continue; } string line = CurrentProduct.Status.Line; StationStatus Status = StationStatus.Pass; var productLog = new ProductLog { Model = CurrentProduct.Model, Status = Status, Editor = Editor, Line = line, Station = Station, Cdt = DateTime.Now }; CurrentProduct.AddLog(productLog); /////////update product status var newStatus = new ProductStatus(); newStatus.Status = Status; newStatus.StationId = Station; newStatus.Editor = Editor; newStatus.Line = line; newStatus.TestFailCount = 0; if (!string.IsNullOrEmpty(CurrentProduct.Status.ReworkCode) && productRepository.IsLastReworkStation(CurrentProduct.Status.ReworkCode, Station, (int)Status)) { newStatus.ReworkCode = ""; IMES.DataModel.Rework r = new IMES.DataModel.Rework(); r.ReworkCode = CurrentProduct.Status.ReworkCode; r.Editor = Editor; r.Status = "3"; r.Udt = DateTime.Now; productRepository.UpdateReworkConsideredProductStatusDefered(work, r, CurrentProduct.ProId); } else { newStatus.ReworkCode = CurrentProduct.Status.ReworkCode; } newStatus.ProId = CurrentProduct.ProId; CurrentProduct.UpdateStatus(newStatus); productRepository.Update(CurrentProduct, work); ECOAReturnStatus = "1"; } dm.EcoareturnInfo item1 = new dm.EcoareturnInfo(); item1.custsn = SNList[i]; item1.partNo = PNList[i]; item1.message = errList[i]; item1.status = ECOAReturnStatus; item1.line = CurrentProduct.Status.Line; item1.groupNo = Groupid; currentRepository.InsertEcoareturn(item1); } retvaluelist.Add(Groupid); return retvaluelist; } catch (FisException e) { logger.Error(e.mErrmsg); throw e; } catch (Exception e) { logger.Error(e.Message); throw e; } finally { logger.Debug("(ReturnUsedKeysImpl)Save end" + " [editor]:" + Editor + " [station]:" + Station + " [customer]:" + customer); } }
/// <summary> /// /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { string check = (string)CurrentSession.GetValue(Session.SessionKeys.CN); string model = (string)CurrentSession.GetValue(Session.SessionKeys.ModelName); if ((check != null && check == "RCTO") || ((model != null) && (model.IndexOf("173") == 0 || model.IndexOf("146") == 0))) { IMBRepository CurrentMBRepository = RepositoryFactory.GetInstance().GetRepository<IMBRepository, IMB>(); IModelRepository CurrentModelRepository = RepositoryFactory.GetInstance().GetRepository<IModelRepository, Model>(); var CurrentMB = (MB)CurrentSession.GetValue(Session.SessionKeys.MB); IList<IMES.FisObject.Common.Model.ModelInfo> infos = new List<IMES.FisObject.Common.Model.ModelInfo>(); infos = CurrentModelRepository.GetModelInfoByModelAndName(model, "MN"); string series = ""; if (infos == null || infos.Count <= 0) { throw new FisException("ICT006", new string[] { }); } else { series = infos[0].Value; } IList<MBCFGDef> currentMBCFGList = new List<MBCFGDef>(); MBCFGDef currentMBCFG = new MBCFGDef(); currentMBCFGList = CurrentMBRepository.GetMBCFGByCodeSeriesAndType(CurrentMB.MBCode, series, "RCTO"); if (currentMBCFGList == null || currentMBCFGList.Count <= 0) { throw new FisException("ICT006", new string[] { }); } else { currentMBCFG = currentMBCFGList[0]; } //string thisYear = DateTime.Today.Year.ToString("0000"); string thisYear = ""; string weekCode = ""; //Vincent 2014-01-01 fixed bug : used wrong this year cross year issue //IList<string> weekCodeList = CurrentModelRepository.GetCodeFromHPWeekCodeInRangeOfDescr(); IList<HpweekcodeInfo> weekCodeList = CurrentModelRepository.GetHPWeekCodeInRangeOfDescr(); if (weekCodeList != null && weekCodeList.Count > 0) { weekCode = weekCodeList[0].code; thisYear = weekCodeList[0].descr.Trim().Substring(0, 4); } else { throw new FisException("ICT009", new string[] { }); } try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); NumControl currentMaxNum = numCtrlRepository.GetMaxValue("MBCT", currentMBCFG.CFG); if (currentMaxNum == null) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB"); if (first == null) { throw new FisException("ICT013", new string[] { }); } currentMaxNum = new NumControl(); currentMaxNum.NOName = currentMBCFG.CFG; currentMaxNum.NOType = "MBCT"; currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; currentMaxNum.Customer = ""; numCtrlRepository.InsertNumControl(currentMaxNum); SqlTransactionManager.Commit(); CurrentSession.AddValue("MBCT", currentMBCFG.CFG + "00" + first.code + weekCode + beginNO); } else if (currentMaxNum.Value.Substring(0, 6) != (thisYear + weekCode)) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB"); if (first == null) { throw new FisException("ICT013", new string[] { }); } currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue("MBCT", currentMBCFG.CFG + "00" + first.code + weekCode + beginNO); } else { if (currentMaxNum.Value.EndsWith("ZZZ")) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IList<SupplierCodeInfo> codeList = currentProductRepository.GetSupplierCodeListByCode(currentMaxNum.Value.Substring(6, 2)); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB", codeList[0].idex); if (first == null) { throw new FisException("ICT005", new string[] { }); } currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue("MBCT", currentMBCFG.CFG + "00" + first.code + weekCode + beginNO); } else { ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 3, "ZZZ", beginNO, '0'); string sequenceNumber = currentMaxNum.Value.Substring(8, 3); sequenceNumber = seqCvt.NumberRule.IncreaseToNumber(sequenceNumber, 1); currentMaxNum.Value = currentMaxNum.Value.Substring(0, 8) + sequenceNumber; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue("MBCT", currentMBCFG.CFG + "00" + currentMaxNum.Value.Substring(6, 2) + weekCode + sequenceNumber); } } } /*string mbct = CurrentSession.GetValue("MBCT") as string; if (!string.IsNullOrEmpty(mbct)) { IMES.FisObject.PCA.MB.MBInfo mbctInfo = new IMES.FisObject.PCA.MB.MBInfo(0, CurrentMB.Sn, "MBCT", mbct, Editor, DateTime.Now, DateTime.Now); CurrentMB.AddMBInfo(mbctInfo); }*/ } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } } else { MB currenMB = CurrentSession.GetValue(Session.SessionKeys.MB) as MB; string mbctValue = "T"; if (!MustGenerate) { IPartRepository CurrentPartRepository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); mbctValue = CurrentPartRepository.GetPartInfoValue(currenMB.PCBModelID, "MBCT"); } if (mbctValue == "T") { IMBRepository CurrentMBRepository = RepositoryFactory.GetInstance().GetRepository<IMBRepository, IMB>(); MBCFGDef currentMBCFG = CurrentMBRepository.GetMBCFG(currenMB.MBCode, "PC"); if (currentMBCFG == null || string.IsNullOrEmpty(currentMBCFG.CFG)) { throw new FisException("ICT006", new string[] { }); } //string thisYear = DateTime.Today.Year.ToString("0000"); string thisYear = ""; string weekCode = ""; IModelRepository CurrentModelRepository = RepositoryFactory.GetInstance().GetRepository<IModelRepository, Model>(); //Vincent 2014-01-01 fixed bug : used wrong this year cross year issue //IList<string> weekCodeList = CurrentModelRepository.GetCodeFromHPWeekCodeInRangeOfDescr(); IList<HpweekcodeInfo> weekCodeList = CurrentModelRepository.GetHPWeekCodeInRangeOfDescr(); if (weekCodeList != null && weekCodeList.Count > 0) { weekCode = weekCodeList[0].code; thisYear = weekCodeList[0].descr.Trim().Substring(0, 4); } else { throw new FisException("ICT009", new string[] { }); } try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); NumControl currentMaxNum = numCtrlRepository.GetMaxValue("MBCT", currentMBCFG.CFG); if (currentMaxNum == null) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB"); if (first == null) { throw new FisException("ICT013", new string[] { }); } currentMaxNum = new NumControl(); currentMaxNum.NOName = currentMBCFG.CFG; currentMaxNum.NOType = "MBCT"; currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; currentMaxNum.Customer = ""; numCtrlRepository.InsertNumControl(currentMaxNum); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.MBCT, currentMBCFG.CFG + "00" + first.code + weekCode + beginNO); } else if (currentMaxNum.Value.Substring(0, 6) != (thisYear + weekCode)) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB"); if (first == null) { throw new FisException("ICT013", new string[] { }); } currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.MBCT, currentMBCFG.CFG + "00" + first.code + weekCode + beginNO); } else { if (currentMaxNum.Value.EndsWith("ZZZ")) { IProductRepository currentProductRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IList<SupplierCodeInfo> codeList = currentProductRepository.GetSupplierCodeListByCode(currentMaxNum.Value.Substring(6, 2)); SupplierCodeInfo first = currentProductRepository.GetSupplierCodeByVendor("MB", codeList[0].idex); if (first == null) { throw new FisException("ICT005", new string[] { }); } currentMaxNum.Value = thisYear + weekCode + first.code + beginNO; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.MBCT, currentMBCFG.CFG + "00" + first.code + weekCode + beginNO); } else { ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 3, "ZZZ", beginNO, '0'); string sequenceNumber = currentMaxNum.Value.Substring(8, 3); sequenceNumber = seqCvt.NumberRule.IncreaseToNumber(sequenceNumber, 1); currentMaxNum.Value = currentMaxNum.Value.Substring(0, 8) + sequenceNumber; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); uof.Commit(); SqlTransactionManager.Commit(); CurrentSession.AddValue(Session.SessionKeys.MBCT, currentMBCFG.CFG + "00" + currentMaxNum.Value.Substring(6, 2) + weekCode + sequenceNumber); } } } } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } } } return base.DoExecute(executionContext); }
protected string getSequence(Session sess) { #region . Remarks . ///1. 取得已经使用的最大的MAC ///GetData..[NumControl] – NoType = ‘MAC’and NoName = [MACRange].Code = 111 Level Part 的Code 属性 (PartInfo.InfoType = ‘Code’ 记录的InfoValue) ///2. 在该MAC 的基础上加1得到新的MAC ///3. 检查新的MAC 是否已经被其他MB 绑定,如果绑定则报告错误:”MAC Address<%MAC%> is used on another MB<%MB Sno%>, Please call PE!!” ///[PCB] ///4. 检查新的MAC 是否在合法MAC Range ///[MACRange] – Code = 111 Level Part 的Code 属性,Status IN (‘R’, ‘A’) ///5. 如果新的MAC 不在合法的MAC Range 中存在,则在[MACRange] 中选取一个新的Range 来使用 ///SELECT TOP 1 BegNo as [New MAC] FROM MACRange WHERE Status = 'R' AND Code = @Code /// ORDER BY Cdt ///6. 更新MACRange 状态 ///[MACRange] ///新的MAC 所在的记录,如果新的MAC = [MACRange].EndNo,则更新该记录的Status = ‘C’;否则更新该记录的Status = ‘A’ ///7. 更新GetData..[NumControl] #endregion int quantity = 1; //目前只支持一次取一個 string model = ((MB)sess.GetValue(Session.SessionKeys.MB)).Model; // 2010-03-19 Liu Dong(eB1-4) Modify 客户确认: IMES_PCA..MACRange.Code 栏位的数据不是111 Part 的Code 属性,而是111 Part 的Cust 属性 //string _111PartCode = this.Get111PartCode(model); string _111PartCust = this.Get111PartCust(model); sess.AddValue(Session.SessionKeys.PN111Code, _111PartCust); INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); string newNum = string.Empty; string maxNum = string.Empty; MACRange macr = null; lock (_syncRoot_GetSeq) { try { SqlConnectionManager.Begin(); macr = numCtrlRepository.GetMaxMACRange(_111PartCust, MACRange.MACRangeStatus.Active, out maxNum);//Attempt #1 if (macr != null) { newNum = _mr.IncreaseToNumber(maxNum, quantity); } else { macr = numCtrlRepository.GetAvailableRange(_111PartCust, MACRange.MACRangeStatus.Virgin);//Attempt #2 if (macr != null) { newNum = macr.BegNo; } else { macr = numCtrlRepository.GetAvailableRange(_111PartCust, MACRange.MACRangeStatus.Active);//Attempt #3: 此Attempt爲了避免數據的不完整性: 如果NumControl裏的記錄丟失,則可以通過此來補上; 如果MACRange裏的記錄丟失,則必然會報下面的異常. if (macr != null) { newNum = macr.BegNo; } else { throw new FisException("MDL002", new string[] { _111PartCust }); } } } this.CheckBoundWithMB(newNum); //TransactionOptions tsos = new TransactionOptions(); //tsos.IsolationLevel = IsolationLevel.ReadCommitted; //using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew, tsos)) //{ UnitOfWork uow = new UnitOfWork(); if (macr.IsEnd(newNum)) { numCtrlRepository.SetMACRangeStatusDefered(uow, macr.ID, MACRange.MACRangeStatus.Closed); } else { numCtrlRepository.SetMACRangeStatusDefered(uow, macr.ID, MACRange.MACRangeStatus.Active); } NumControl newMax = new NumControl(0, GeneratesConstants.MappingToStandard(GeneratesConstants.Mac), _111PartCust, newNum, this.Customer); // 2010-04-28 Liu Dong(eB1-4) Modify 与需求不一致: MAC地址生成后,不是无条件地向NumControl里插入,而在已存在的情况下,更新当前值(不一定是最大值,因为不一定总是一个Range)就可以了. //numCtrlRepository.SaveMaxNumberDefered(uow, newMax); numCtrlRepository.SaveMaxMACDefered(uow, newMax); // 2010-04-28 Liu Dong(eB1-4) Modify 与需求不一致: MAC地址生成后,不是无条件地向NumControl里插入,而在已存在的情况下,更新当前值(不一定是最大值,因为不一定总是一个Range)就可以了. uow.Commit(); SqlConnectionManager.Commit(); // scope.Complete(); //} } catch (Exception) { SqlConnectionManager.Rollback(); throw; } finally { SqlConnectionManager.Dispose(); SqlConnectionManager.End(); } } return newNum; }
/// <summary> /// 產生BOX ID號號相关逻辑 /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override System.Workflow.ComponentModel.ActivityExecutionStatus DoExecute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext) { IProduct product = (IProduct)CurrentSession.GetValue(Session.SessionKeys.Product); Delivery delivery = (Delivery)CurrentSession.GetValue(Session.SessionKeys.Delivery); IProductRepository productRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IPalletRepository palletRep = RepositoryFactory.GetInstance().GetRepository<IPalletRepository, Pallet>(); IDeliveryRepository deliveryRep = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>(); IModelRepository modelRep = RepositoryFactory.GetInstance().GetRepository<IModelRepository, Model>(); carton.ICartonSSCCRepository cartRep = RepositoryFactory.GetInstance().GetRepository<carton.ICartonSSCCRepository, IMES.FisObject.PAK.CartonSSCC.CartonSSCC>(); try { //New Format of Box Id //Format of RU No //WWSSSSSS //Remark: //WW – HP Week Code //SSSSSS – 流水号,36进制,基字符 string maxnum = ""; string prestr = ""; DateTime dateTime = DateTime.Now; // var ret = IMES.Infrastructure.Utility.Generates.WeekRuleEngine.Calculate("103", dateTime); IList<string> codeList = modelRep.GetCodeFromHPWeekCodeInRangeOfDescr(); string weekCode = ""; if (codeList.Count > 0) { weekCode = codeList[0]; } string runo = ""; runo = weekCode ; prestr = runo; // 自己管理事务开始 SqlTransactionManager.Begin(); IUnitOfWork uof = new UnitOfWork();//使用自己的UnitOfWork //从NumControl中获取流水号 //GetMaxNumber INumControlRepository numControl = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); bool addflag = false; maxnum = numControl.GetMaxNumber("RUNO", prestr + "{0}"); if (string.IsNullOrEmpty(maxnum)) { maxnum = "000001"; addflag = true; } else { MathSequenceWithCarryNumberRule marc = new MathSequenceWithCarryNumberRule(6, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"); string numstr = maxnum.Substring(maxnum.Length - 6); if (numstr.ToUpper() == "ZZZZZZ") { FisException fe = new FisException("CHK867", new string[] { }); //流水号已满! throw fe; } numstr = marc.IncreaseToNumber(numstr, 1); maxnum = numstr; } runo = runo + maxnum.ToUpper(); NumControl item = new NumControl(); item.NOType = "RUNO"; item.Value = runo; item.NOName = ""; item.Customer = "HP"; numControl.SaveMaxNumber(item, addflag, prestr + "{0}"); uof.Commit(); //立即提交UnitOfWork更新NumControl里面的最大值 SqlTransactionManager.Commit();//提交事物,释放行级更新锁 //INSERT INTO [CartonInfo]([CartonNo],[InfoType],[InfoValue],[Editor],[Cdt],[Udt]) //VALUES (@CartonNo, 'RUNo', @RUNo, @Editor, GETDATE(), GETDATE()) CartonInfoInfo sinfo = new CartonInfoInfo(); sinfo.cartonNo = product.CartonSN; sinfo.infoType = "RUNo"; sinfo.infoValue = runo; sinfo.editor = Editor; sinfo.cdt = DateTime.Now; sinfo.udt = DateTime.Now; cartRep.InsertCartonInfoDefered(CurrentSession.UnitOfWork, sinfo); //Product结合Delivery and Carton //将页面上[Products in Carton] 中的每一个Product和页面选定的Delivery 已经上文生成的Carton No 进行结合 – Update Product //Product.DeliveryNo – Delivery No //Product.CartonSN – Carton No IList<IProduct> productList = (List<IProduct>)CurrentSession.GetValue(Session.SessionKeys.ProdList); foreach (var prod in productList) { prod.DeliveryNo = delivery.DeliveryNo; prod.CartonSN = product.CartonSN; productRep.Update(prod, CurrentSession.UnitOfWork); } //6. Update ProductStatus / Insert ProductLog } catch (Exception) { SqlTransactionManager.Rollback(); throw; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } return base.DoExecute(executionContext); }
/// <summary> /// 產生BOX ID號號相关逻辑 /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override System.Workflow.ComponentModel.ActivityExecutionStatus DoExecute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext) { IProduct product = (IProduct)CurrentSession.GetValue(Session.SessionKeys.Product); IProductRepository productRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); IPalletRepository palletRep = RepositoryFactory.GetInstance().GetRepository<IPalletRepository, Pallet>(); IDeliveryRepository deliveryRep = RepositoryFactory.GetInstance().GetRepository<IDeliveryRepository, Delivery>(); IModelRepository modelRep = RepositoryFactory.GetInstance().GetRepository<IModelRepository, Model>(); carton.ICartonSSCCRepository cartRep = RepositoryFactory.GetInstance().GetRepository<carton.ICartonSSCCRepository, IMES.FisObject.PAK.CartonSSCC.CartonSSCC>(); try { //仅当Delivery 的Flag 属性为N 的时候,需要Generate Ship to Carton Label Pdf Document: //1. Generate Box Id //2. Generate and Record Data for Ship to Carton Label //3. Generate Ship to Carton Label Pdf Document string boxID = ""; Delivery curDev = deliveryRep.Find(product.DeliveryNo); //curDev.Editor = this.Editor; CurrentSession.AddValue(Session.SessionKeys.Delivery, curDev); string flagstr = (string)curDev.GetExtendedProperty("Flag"); if (flagstr == "N") { // 1. 解除Carton 结合的旧的Box Id //参考方法: //IF EXISTS (SELECT * FROM CartonInfo (NOLOCK ) WHERE CartonNo=@cn AND InfoType='BoxId') //BEGIN //DELETE CartonInfo WHERE artonNo=@cn AND InfoType='BoxId' //END CartonInfoInfo infoCond = new CartonInfoInfo(); infoCond.cartonNo = product.CartonSN; infoCond.infoType = "BoxId"; IList<CartonInfoInfo> infoList = cartRep.GetCartonInfoInfo(infoCond); if (infoList.Count > 0) { cartRep.DeleteCartonInfoDefered(CurrentSession.UnitOfWork, infoCond); } //2. 取当前日期/ Pallet UCC //参考方法: //SELECT @dt=GETDATE(),@ucc='' //SELECT @ucc = UCC FROM Pallet (NOLOCK) WHERE PalletNo = @plt string ucc = ""; Pallet curPallet = palletRep.Find(product.PalletNo); ucc = curPallet.UCC; int ucclength = ucc.TrimEnd().Length; int index = ucc.TrimEnd().IndexOf(","); //3. 取Delivery 相关属性 //参考方法: //SELECT @po = RTRIM(PoNo), @model = Model FROM Delivery NOLOCK WHERE DeliveryNo = @dn //SELECT @Flag = InfoValue FROM DeliveryInfo NOLOCK WHERE DeliveryNo = @dn AND InfoType = 'Flag' //SELECT @BoxId_Tag = InfoValue FROM DeliveryInfo NOLOCK WHERE DeliveryNo = @dn AND InfoType = 'BoxId' //SET @BoxId_Tag = LEFT(@BoxId_Tag, 10) //SELECT @Region = InfoValue FROM DeliveryInfo NOLOCK WHERE DeliveryNo = @dn AND InfoType = 'RegId' //SELECT @Deport = InfoValue FROM DeliveryInfo NOLOCK WHERE DeliveryNo = @dn AND InfoType = 'Deport' //SELECT @boxReg = InfoValue FROM DeliveryInfo NOLOCK WHERE DeliveryNo = @dn AND InfoType = 'BoxReg' string po = ""; string model = ""; //string descr = ""; string flag = ""; string boxId_Tag = ""; string region = ""; string deport = ""; string boxReg = ""; po = curDev.PoNo.TrimEnd(); model = curDev.ModelName; flag = (string)curDev.GetExtendedProperty("Flag"); boxId_Tag = (string)curDev.GetExtendedProperty("BoxId"); if (!string.IsNullOrEmpty(boxId_Tag) && boxId_Tag.Length >= 10) { boxId_Tag = boxId_Tag.Substring(0, 10); } else { boxId_Tag = ""; } region = (string)curDev.GetExtendedProperty("RegId"); deport = (string)curDev.GetExtendedProperty("Deport"); boxReg = (string)curDev.GetExtendedProperty("BoxReg"); //4. 如果@boxReg<>'',则按照如下规则产生Box Id,并将产生的Box Id 存到变量@BoxId 中 if (!string.IsNullOrEmpty(boxReg)) { //New Format of Box Id //RRRR-SSSSS //Remark: //RRRR – @boxReg //- – 固定字符’-‘ //SSSSS – 流水号,31进制,基字符'0123456789BCDFGHJKLMNPQRSTVWXYZ';起始值为R0000;最大值为VZZZZ string maxnum = ""; string prestr = ""; boxID = boxReg + "-"; prestr = boxID; // 自己管理事务开始 SqlTransactionManager.Begin(); IUnitOfWork uof = new UnitOfWork();//使用自己的UnitOfWork //ITC-1414-0065 //从NumControl中获取流水号 //GetMaxNumber INumControlRepository numControl = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); bool addflag = false; maxnum = numControl.GetMaxNumber("BOXID", prestr + "{0}"); if (string.IsNullOrEmpty(maxnum)) { maxnum = "R0000"; addflag = true; } else { MathSequenceWithCarryNumberRule marc = new MathSequenceWithCarryNumberRule(5, "0123456789BCDFGHJKLMNPQRSTVWXYZ"); //maxnum="CNU248000Y"; string numstr = maxnum.Substring(maxnum.Length - 5); if (numstr.ToUpper() == "VZZZZ") { FisException fe = new FisException("CHK867", new string[] { }); //流水号已满! throw fe; } numstr = marc.IncreaseToNumber(numstr, 1); maxnum = numstr; } boxID = boxID + maxnum.ToUpper(); NumControl item = new NumControl(); item.NOType = "BOXID"; item.Value = boxID; item.NOName = ""; item.Customer = "HP"; numControl.SaveMaxNumber(item, addflag, prestr + "{0}"); uof.Commit(); //立即提交UnitOfWork更新NumControl里面的最大值 SqlTransactionManager.Commit();//提交事物,释放行级更新锁 } else { //5. 如果@boxReg='',则按照如下规则产生Box Id,并将产生的Box Id 存到变量@BoxId 中 //a) 当满足(LEN(RTRIM(@ucc))<>20 or (LEN(RTRIM(@ucc))=20 AND CHARINDEX(',',RTRIM(@ucc))>0)) AND RTRIM(@BoxId_Tag) ='' AND @Flag='N'条件时,按照如下规则产生Box Id if ((ucclength != 20) || (ucclength == 20 && index >= 0 && string.IsNullOrEmpty(boxId_Tag.TrimEnd()) && flag == "N")) { string alarm = ""; switch (region) { case "SNA": alarm = "H410-Y"; break; case "SNL": alarm = "LA" + deport + "Y"; break; case "SNU": alarm = "D7" + deport + "Y"; break; case "SNE": alarm = "63D7-QY"; break; case "SAF": alarm = "H4FN-0C"; break; } //SET ROWCOUNT 1 //SELECT @BoxId=RTRIM(BoxId) FROM SnoCtrl_BoxId WHERE Cust=@alarm AND valid=@editor //IF @BoxId is not null //DELETE FROM SnoCtrl_BoxId WHERE BoxId=@BoxId //SET ROWCOUNT 0 //如果@BoxId IS NULL or @BoxId='',则报告错误:'BoxId已用完.'+@alarm SnoCtrlBoxIdInfo snoConf = new SnoCtrlBoxIdInfo(); SnoCtrlBoxIdInfo snoSet = new SnoCtrlBoxIdInfo(); snoConf.cust = alarm; snoConf.valid = "1"; IList<string> boxList = deliveryRep.GetBoxIdListFromSnoCtrlBoxId(snoConf); snoSet.valid = Editor; //deliveryRep.UpdateSnoCtrlBoxIdInfoDefered(CurrentSession.UnitOfWork, snoSet, snoConf); if (boxList != null && boxList.Count > 0 && !string.IsNullOrEmpty(boxList[0])) { SnoCtrlBoxIdInfo dsnoConf = new SnoCtrlBoxIdInfo(); boxID = boxList[0].TrimEnd(); dsnoConf.boxId = boxID; deliveryRep.DeleteSnoCtrlBoxIdInfoDefered(CurrentSession.UnitOfWork, dsnoConf); } else { List<string> erpara = new List<string>(); erpara.Add(alarm); FisException fe = new FisException("PAK135", erpara); //BoxId已用完.'+@alarm throw fe; } } } //6. 如果LEN(RTRIM(@ucc))=20 AND CHARINDEX(',',@ucc)=0,则UCC 保存到CartonInfo 中; //否则,将Box Id 保存到CartonInfo //Record UCC //IF EXISTS(SELECT * FROM CartonInfo NOLOCK WHERE CartonNo = @cn AND InfoType = 'UCC') //UPDATE CartonInfo SET InfoValue = @ucc, Editor = @editor, Udt = GETDATE() //WHERE CartonNo = @cn AND InfoType = 'UCC' //ELSE //INSERT INTO CartonInfo([CartonNo],[InfoType],[InfoValue],[Editor],[Cdt],[Udt]) //VALUES(@cn, 'UCC', @ucc, @editor, GETDATE(), GETDATE()) //Record Box Id //IF EXISTS(SELECT * FROM CartonInfo NOLOCK WHERE CartonNo = @cn AND InfoType = 'BoxId') //UPDATE CartonInfo SET InfoValue = @BoxId, Editor = @editor, Udt = GETDATE() //WHERE CartonNo = @cn AND InfoType = 'BoxId' //ELSE //INSERT INTO CartonInfo([CartonNo],[InfoType],[InfoValue],[Editor],[Cdt],[Udt]) //VALUES(@cn, 'BoxId', @BoxId, @editor, GETDATE(), GETDATE()) string namestr = ""; string valuestr = ""; if ((ucclength == 20) && (index < 0)) { namestr = "UCC"; valuestr = ucc; } else { namestr = "BoxId"; valuestr = boxID; } infoCond.infoType = namestr; infoList = cartRep.GetCartonInfoInfo(infoCond); CartonInfoInfo setCarton = new CartonInfoInfo(); setCarton.infoValue = valuestr; setCarton.editor = Editor; setCarton.udt = DateTime.Now; if (infoList.Count > 0) { cartRep.UpdateCartonInfoDefered(CurrentSession.UnitOfWork, setCarton, infoCond); } else { setCarton.cartonNo = product.CartonSN; setCarton.infoType = namestr; setCarton.infoValue = valuestr; cartRep.InsertCartonInfoDefered(CurrentSession.UnitOfWork, setCarton); } } //Generate and Record Data for Ship to Carton Label //调用HP_EDI.dbo.op_PackingData_20111031 @BoxId,@dn,@plt,@cn,@cdtEDI实现 //Parameters:@BoxId – Box Id @dn – Delivery No @plt – Pallet No @cn – Carton No @cdtEDI - GETDATE() if (flagstr == "N") { palletRep.CallOp_PackingDataDefered(CurrentSession.UnitOfWork, boxID, product.DeliveryNo, product.PalletNo, product.CartonSN, DateTime.Now); } } catch (Exception) { SqlTransactionManager.Rollback(); throw; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } return base.DoExecute(executionContext); }
private string GetMAC(string cust) { try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); MACRange currentRange = numCtrlRepository.GetMACRange(cust, new string[] { "R", "A" }); if (currentRange == null) { throw new FisException("ICT014", new string[] { }); } else { NumControl currentMaxNum = numCtrlRepository.GetMaxValue("MAC", cust); if (currentMaxNum == null) { currentMaxNum = new NumControl(); currentMaxNum.NOName = cust; currentMaxNum.NOType = "MAC"; currentMaxNum.Value = currentRange.BegNo; currentMaxNum.Customer = ""; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.InsertNumControlDefered(uof, currentMaxNum); if (currentMaxNum.Value == currentRange.EndNo) { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Closed); } else { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Active); } uof.Commit(); SqlTransactionManager.Commit(); return currentMaxNum.Value; } else { if (currentMaxNum.Value == currentRange.EndNo) { numCtrlRepository.SetMACRangeStatus(currentRange.ID, MACRange.MACRangeStatus.Closed); currentRange = numCtrlRepository.GetMACRange(cust, new string[] { "R" }); if (currentMaxNum.Value == currentRange.BegNo || currentMaxNum.Value == currentRange.EndNo) { throw new FisException("ICT018", new string[] { currentMaxNum.Value }); } } string change34MaxNum = Change34(currentMaxNum.Value); string change34BeginNo = Change34(currentRange.BegNo); string change34EndNo = Change34(currentRange.EndNo); if (string.Compare(change34MaxNum, change34BeginNo) < 0 || string.Compare(change34MaxNum, change34EndNo) > 0) { currentMaxNum.Value = currentRange.BegNo; } else { ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789ABCDEF", 4, "FFFF", "0000", '0'); string sequenceNumber = currentMaxNum.Value.Substring(currentMaxNum.Value.Length - 4, 4); string change34Sequence = sequenceNumber.Substring(1, 3).Insert(1, sequenceNumber.Substring(0, 1)); change34Sequence = seqCvt.NumberRule.IncreaseToNumber(change34Sequence, 1); sequenceNumber = change34Sequence.Substring(1, 3).Insert(1, change34Sequence.Substring(0, 1)); currentMaxNum.Value = currentMaxNum.Value.Substring(0, currentMaxNum.Value.Length - 4) + sequenceNumber; } IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); if (currentMaxNum.Value == currentRange.EndNo) { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Closed); } else { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Active); } uof.Commit(); SqlTransactionManager.Commit(); return currentMaxNum.Value; } } } } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } }
/// <summary> /// 产生Asset SN /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { var currenProduct = (IProduct)CurrentSession.GetValue(Session.SessionKeys.Product); string customerSN = (string)CurrentSession.GetValue(Session.SessionKeys.CustSN); string custNum = ""; string cust = currenProduct.ModelObj.GetAttribute("Cust"); //if(string.IsNullOrEmpty(cust)){ // return base.DoExecute(executionContext); //} IPartRepository ipartRepository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); IList<AssetRangeInfo> assetSNRange = ipartRepository.GetAssetRangesByCode(cust); if (assetSNRange.Count == 0) { List<string> errpara = new List<string>(); errpara.Add(customerSN); throw new FisException("CHK200", errpara); } AssetRangeInfo assetRange = null; foreach (AssetRangeInfo tempAssetRange in assetSNRange) { assetRange = tempAssetRange; } try //2012-7-19 { SqlTransactionManager.Begin(); //2012-7-19 lock (_syncRoot_GetSeq) //2012-7-19 { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); //ITC-1360-0495, Jessica Liu, 2012-2-22 //string largestCustNum = numCtrlRepository.GetMaxNumber("AST", cust + "{0}"); string largestCustNum = numCtrlRepository.GetMaxAssetNumber("AST", cust, "HP"); if (string.IsNullOrEmpty(largestCustNum)) { custNum = assetRange.begin; NumControl item = new NumControl(0, "AST", assetRange.code, custNum, "HP"); //numCtrlRepository.SaveMaxNumber(item, true, string.Empty); numCtrlRepository.SaveMaxAssetNumber(item, true); //2012-7-19 SqlTransactionManager.Commit(); } else { string numInLargestCustNum = ""; string numInEnd = ""; string preString = ""; string preEndString = ""; bool bHasNumber = false; string s = largestCustNum; int s_idx = 0; bool bFoundDigit = false; for (int i = 0; i < s.Length; i++) { if (s[i] < '0' || s[i] > '9') { bFoundDigit = false; } else if (bFoundDigit == false) { bFoundDigit = true; s_idx = i; } } if (bFoundDigit == true) { numInLargestCustNum = s.Substring(s_idx); preString = s.Substring(0, s_idx); bHasNumber = true; } string t = assetRange.end; int t_idx = 0; bool bFoundDigit2 = false; for (int i = 0; i < t.Length; i++) { if (t[i] < '0' || t[i] > '9') { bFoundDigit2 = false; } else if (bFoundDigit2 == false) { bFoundDigit2 = true; t_idx = i; } } if ((bFoundDigit2 == true) && (bHasNumber == true)) { numInEnd = t.Substring(t_idx); preEndString = t.Substring(0, t_idx); } else { bHasNumber = false; } if (bHasNumber == true) { if (preString == preEndString) { long largestNum = long.Parse(numInLargestCustNum); long end = long.Parse(numInEnd); if (largestNum >= end) { List<string> errpara = new List<string>(); errpara.Add(customerSN); throw new FisException("CHK201", errpara); } else { largestNum++; //custNum = preString + largestNum.ToString(); int largestNumCount = numInLargestCustNum.Length; string strNewLargestCustNum = largestNum.ToString(); int newlargestNumCount = strNewLargestCustNum.Length; string strPreZero = ""; if (numInLargestCustNum.Substring(0, 1) == "0") { for (int i = 0; i < (largestNumCount - newlargestNumCount); i++) { strPreZero += "0"; } strNewLargestCustNum = strPreZero + strNewLargestCustNum; } custNum = preString + strNewLargestCustNum; NumControl item = new NumControl(0, "AST", assetRange.code, custNum, "HP"); //numCtrlRepository.SaveMaxNumber(item, false, string.Empty); numCtrlRepository.SaveMaxAssetNumber(item, false); //2012-7-19 SqlTransactionManager.Commit(); } } else { List<string> errpara = new List<string>(); errpara.Add(customerSN); throw new FisException("CHK201", errpara); } } else { List<string> errpara = new List<string>(); errpara.Add(customerSN); throw new FisException("CHK201", errpara); } } } } catch (Exception e) //2012-7-19 { SqlTransactionManager.Rollback(); throw e; } finally //2012-7-19 { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } /* else { long largestNum = long.Parse(largestCustNum); long end = long.Parse(assetRange.end); if (largestNum == end) { List<string> errpara = new List<string>(); errpara.Add(customerSN); throw new FisException("CHK201", errpara); } largestNum++; custNum = largestNum.ToString(); NumControl item = new NumControl(0, "AST", assetRange.code, custNum, "HP"); //numCtrlRepository.SaveMaxNumber(item, false, string.Empty); numCtrlRepository.SaveMaxAssetNumber(item, false); } */ /* 2012-7-14, Jessica Liu, for mantis if (cust == "SCUSTA-1") { custNum = "000" + custNum.Trim() + "00"; } else if (cust == "CUSTW-1") { custNum = custNum.Trim() + " HQ P47"; } else if (cust == "CUSTW-2") { custNum = custNum.Trim() + " HQ P49"; } */ if (cust == "SCUSTA-1") { custNum = "000" + custNum.Trim() + "00"; } ConstValueInfo info = new ConstValueInfo(); info.type = "AST"; info.name = cust; IPartRepository partRepository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); IList<ConstValueInfo> retList = partRepository.GetConstValueInfoList(info); if (retList != null && retList.Count != 0) { if (string.IsNullOrEmpty(retList[0].value) == false) { custNum += retList[0].value; } } CurrentSession.AddValue("AssetSN", custNum); return base.DoExecute(executionContext); }
/// <summary> /// 產生Carton NO號相关逻辑 /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override System.Workflow.ComponentModel.ActivityExecutionStatus DoExecute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext) { IProduct product = (IProduct)CurrentSession.GetValue(Session.SessionKeys.Product); IProductRepository productRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); //Format of Carton No //CYMDDSSSS //Remark: //T – 前缀,固定字符’C’ //Y – Year Code,西元年的最后一位 //M – Month Code,1~9 表示1~9 月,A~C 表示10~12 月 //DD – Day Code,两位,00~31 //SSSS – 流水号,10进制,起始值为0001 try { string CartonNO = ""; string maxnum = ""; string prestr = ""; //求当前日期是一年的中第几周 //int weeks = 0; DateTime curDate = DateTime.Now; /*var ret = IMES.Infrastructure.Utility.Generates.WeekRuleEngine.Calculate("103", dateTime); string weekCode = ret.Week.ToString().PadLeft(2, '0'); string year = ret.Year.ToString(); string month = ret.*/ string year = curDate.Year.ToString(); //string month = Convert.ToString(curDate.Month,16); string month = curDate.Month.ToString("X");//2012/10/05 string dd = curDate.Day.ToString("d2"); CartonNO = "C" + year.Substring(year.Length - 1, 1) + month + dd; prestr = CartonNO; // 自己管理事务开始 SqlTransactionManager.Begin(); IUnitOfWork uof = new UnitOfWork();//使用自己的UnitOfWork //从NumControl中获取流水号 //GetMaxNumber INumControlRepository numControl = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); bool addflag = false; //maxnum = numControl.GetMaxNumber("CARTONNO", prestr + "{0}"); var maxObj = numControl.GetMaxValue("CARTONNO", prestr); //檢查有沒有lock index, 沒有lock index, 改變查詢條件 if (maxObj == null) { //lock NoType='CARTONNO' //string maxData = numControl.GetMaxNumber("CARTONNO", "{0}"); //maxObj = numControl.GetMaxNumberObj("CARTONNO", prestr + "{0}"); var data = numControl.GetMaxValue("CARTONNO", "Lock"); maxObj = numControl.GetMaxValue("CARTONNO", prestr); } if (maxObj != null) { maxnum = maxObj.Value; } if (string.IsNullOrEmpty(maxnum)) { maxnum = "0001";//"8000"; addflag = true; } else { //maxnum="CNU248000Y"; string numstr = maxnum.Substring(maxnum.Length - 4); if (numstr.ToUpper() == "9999") { FisException fe = new FisException("CHK867", new string[] { }); //流水号已满! throw fe; } //ITC-1414-0069 int result = Convert.ToInt32(numstr)+1; maxnum = result.ToString("d4"); } CartonNO = CartonNO + maxnum.ToUpper(); NumControl item = null;// new NumControl(); if (addflag) { item = new NumControl(); item.NOType = "CARTONNO"; item.Value = CartonNO; item.NOName = prestr; item.Customer = this.Customer; } else { item = maxObj; item.Value = CartonNO; } //numControl.SaveMaxNumber(item, addflag, prestr + "{0}"); numControl.SaveMaxNumber(item, addflag); uof.Commit(); //立即提交UnitOfWork更新NumControl里面的最大值 SqlTransactionManager.Commit();//提交事物,释放行级更新锁 product.CartonSN = CartonNO; //a. Insert CartonStatus //INSERT INTO [CartonStatus]([CartonNo],[Station],[Status],[Line],[Editor],[Cdt],[Udt]) //VALUES(@CartonNo, @Station, 1, @PdLine, @Editor, GETDATE(), GETDATE()) carton.ICartonSSCCRepository cartRep = RepositoryFactory.GetInstance().GetRepository<carton.ICartonSSCCRepository, IMES.FisObject.PAK.CartonSSCC.CartonSSCC>(); CartonStatusInfo sinfo = new CartonStatusInfo(); sinfo.cartonNo = product.CartonSN; sinfo.station = Station; sinfo.status = 1;//pass sinfo.line = Line; sinfo.editor = Editor; sinfo.cdt = DateTime.Now; sinfo.udt = DateTime.Now; cartRep.AddCartonStatusInfoDefered(CurrentSession.UnitOfWork,sinfo); //b. Insert CartonLog //INSERT INTO [CartonLog]([CartonNo],[Station],[Status],[Line],[Editor],[Cdt]) //VALUES(@CartonNo, @Station, 1, @PdLine, @Editor, GETDATE()) CartonLogInfo linfo = new CartonLogInfo(); linfo.cartonNo = product.CartonSN; linfo.station = Station; linfo.status = 1;//pass linfo.line = Line; linfo.editor = Editor; linfo.cdt = DateTime.Now; cartRep.AddCartonLogInfoDefered(CurrentSession.UnitOfWork,linfo); } catch (Exception) { SqlTransactionManager.Rollback(); throw; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } return base.DoExecute(executionContext); }
/// <summary> /// Generate ATSN7 label /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { var productRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); var partRepository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>(); Product curProduct = (Product)CurrentSession.GetValue(Session.SessionKeys.Product); IList<string> pnList = CurrentSession.GetValue("PnListOfATSN7") as IList<string>; bool bCDSI = (bool)CurrentSession.GetValue("bCDSI"); if (bCDSI == true) { string AST1 = ""; CdsiastInfo cdi = new CdsiastInfo(); cdi.tp = "ASSET_TAG"; cdi.snoId = curProduct.ProId; IList<CdsiastInfo> cdsiastInfoList = productRepository.GetCdsiastInfoList(cdi); if (cdsiastInfoList != null && cdsiastInfoList.Count > 0) { AST1 = cdsiastInfoList[0].sno; } string AST2 = ""; CdsiastInfo cdi2 = new CdsiastInfo(); cdi2.tp = "ASSET_TAG2"; cdi2.snoId = curProduct.ProId; IList<CdsiastInfo> cdsiastInfoList2 = productRepository.GetCdsiastInfoList(cdi2); if (cdsiastInfoList2 != null && cdsiastInfoList2.Count > 0) { AST2 = cdsiastInfoList2[0].sno; } if ((AST1 == "") && (AST2 == "")) { List<string> errpara = new List<string>(); throw new FisException("CHK203", errpara); } else { //不为空则存入 //保存product和Asset SN的绑定关系 foreach (string tmp in pnList) { if (AST1 != "") { IProductPart assetTag1 = new ProductPart(); assetTag1.ProductID = curProduct.ProId; assetTag1.PartID = tmp; assetTag1.PartType = "ATSN7"; assetTag1.Iecpn = ""; assetTag1.CustomerPn = ""; assetTag1.PartSn = AST1; assetTag1.Station = Station; assetTag1.Editor = Editor; assetTag1.Cdt = DateTime.Now; assetTag1.Udt = DateTime.Now; assetTag1.BomNodeType = "AT"; curProduct.AddPart(assetTag1); productRepository.Update(curProduct, CurrentSession.UnitOfWork); } if (AST2 != "") { IProductPart assetTag2 = new ProductPart(); assetTag2.ProductID = curProduct.ProId; assetTag2.PartID = tmp; assetTag2.PartType = "ATSN7"; assetTag2.Iecpn = ""; assetTag2.CustomerPn = ""; assetTag2.PartSn = AST2; assetTag2.Station = Station; assetTag2.Editor = Editor; assetTag2.Cdt = DateTime.Now; assetTag2.Udt = DateTime.Now; assetTag2.BomNodeType = "AT"; curProduct.AddPart(assetTag2); productRepository.Update(curProduct, CurrentSession.UnitOfWork); } } } } else //Not CDSI { string custNum = ""; string cust = curProduct.ModelObj.GetAttribute("Cust"); IList<AssetRangeInfo> assetRangeList = partRepository.GetAssetRangesByCode(cust); if (assetRangeList.Count == 0) //No AssetRange found { List<string> errpara = new List<string>(); throw new FisException("CHK200", errpara); } AssetRangeInfo assetRange = assetRangeList[0]; if (assetRange.begin.Length != assetRange.end.Length) //Length of Begin and End mismatch { List<string> errpara = new List<string>(); throw new FisException("CHK201", errpara); } try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); string largestCustNum = numCtrlRepository.GetMaxAssetNumber("AST", cust, "HP"); if (string.IsNullOrEmpty(largestCustNum)) { custNum = assetRange.begin; //Save current custNum to numControl NumControl item = new NumControl(0, "AST", assetRange.code, custNum, "HP"); numCtrlRepository.SaveMaxAssetNumber(item, true); SqlTransactionManager.Commit(); } else { if (largestCustNum.Length != assetRange.begin.Length) //Length of largestCustNum and assetRange.begin mismatch { List<string> errpara = new List<string>(); throw new FisException("CHK201", errpara); } string prePartCur = ""; string numPartCur = ""; ParseAst(largestCustNum, out prePartCur, out numPartCur); if (numPartCur == "") { List<string> errpara = new List<string>(); throw new FisException("CHK201", errpara); } string prePartMax = ""; string numPartMax = ""; ParseAst(assetRange.end, out prePartMax, out numPartMax); if (numPartMax == "") { List<string> errpara = new List<string>(); throw new FisException("CHK201", errpara); } if (prePartCur != prePartMax) //Prefix of largestCustNum and assetRange.end mismatch { List<string> errpara = new List<string>(); throw new FisException("CHK201", errpara); } long numCur = long.Parse(numPartCur); long numMax = long.Parse(numPartMax); if (numCur >= numMax) { List<string> errpara = new List<string>(); throw new FisException("CHK201", errpara); } numCur++; custNum = prePartCur; int fillZeroCount = numPartCur.Length - numCur.ToString().Length; for (int i = 0; i < fillZeroCount; i++) { custNum += "0"; } custNum += numCur.ToString(); //Save current custNum to numControl NumControl item = new NumControl(0, "AST", assetRange.code, custNum, "HP"); numCtrlRepository.SaveMaxAssetNumber(item, false); SqlTransactionManager.Commit(); } } } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } //Update custNum if (cust == "SCUSTA-1") { custNum = "000" + custNum.Trim() + "00"; } /* else if (cust == "CUSTW-1") { custNum = custNum.Trim() + " HQ P47"; } else if (cust == "CUSTW-2") { custNum = custNum.Trim() + " HQ P49"; } */ ConstValueInfo cond = new ConstValueInfo(); cond.type = "AST"; cond.name = cust; IList<ConstValueInfo> valList = partRepository.GetConstValueInfoList(cond); if (valList.Count > 0 && !String.IsNullOrEmpty(valList[0].value)) { custNum += valList[0].value.Trim(); } //保存product和Asset SN的绑定关系 foreach (string tmp in pnList) { IProductPart assetTag = new ProductPart(); assetTag.ProductID = curProduct.ProId; assetTag.PartID = tmp; assetTag.PartType = "ATSN7"; assetTag.Iecpn = ""; assetTag.CustomerPn = ""; assetTag.PartSn = custNum; assetTag.Station = Station; assetTag.Editor = Editor; assetTag.Cdt = DateTime.Now; assetTag.Udt = DateTime.Now; assetTag.BomNodeType = "AT"; curProduct.AddPart(assetTag); productRepository.Update(curProduct, CurrentSession.UnitOfWork); } } return base.DoExecute(executionContext); }
private string getUCCIDList() { try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { IList<string> ret = new List<string>(); INumControlRepository numControlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); long curMax = 0; bool bInsert = false; string curMaxStr = numControlRepository.GetMaxUCCIDNumber("UCCID"); if (curMaxStr == null || curMaxStr == "") { bInsert = true; curMax = 2000000; } else { curMax = long.Parse(curMaxStr); } string s = "000008869889" + curMax.ToString("0000000"); int dig20 = 0; int sum = 0; for (int j = 0; j < 19; j++) { /* * Answer to: ITC-1360-1155 * Description: Wrong processing while getting dig20. */ if (j % 2 == 0) sum += (s[j] - '0') * 3; else sum += s[j] - '0'; } /* * Answer to: ITC-1360-1153 * Description: Wrong processing while getting dig20. */ dig20 = (10 - (sum % 10)) % 10; s += dig20.ToString(); curMax++; if (curMax == 6000000) { curMax = 2000000; } NumControl nc = new NumControl(-1, "UCCID", "", curMax.ToString(), "HP"); numControlRepository.SaveMaxNumber(nc, bInsert, "{0}"); SqlTransactionManager.Commit(); return s; } } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } }
/// <summary> /// /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override ActivityExecutionStatus DoExecute(ActivityExecutionContext executionContext) { IProduct product = (IProduct)CurrentSession.GetValue(Session.SessionKeys.Product); IProductRepository productRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); //Format of Carton No //TYMDDSSSS //Remark: //T – 前缀,線別第一碼 //Y – Year Code,西元年的最后一位 //M – Month Code,1~9 表示1~9 月,A~C 表示10~12 月 //DD – Day Code,两位,00~31 //SSSS – 流水号,10进制,起始值为0001 try { string CartonNO = ""; string maxnum = ""; string prestr = ""; //求当前日期是一年的中第几周 //int weeks = 0; DateTime curDate = DateTime.Now; /*var ret = IMES.Infrastructure.Utility.Generates.WeekRuleEngine.Calculate("103", dateTime); string weekCode = ret.Week.ToString().PadLeft(2, '0'); string year = ret.Year.ToString(); string month = ret.*/ string year = curDate.Year.ToString(); //string month = Convert.ToString(curDate.Month,16); string month = curDate.Month.ToString("X");//2012/10/05 string dd = curDate.Day.ToString("d2"); CartonNO = this.Line.Substring(0,1)+ year.Substring(year.Length - 1, 1) + month + dd; prestr = CartonNO; // 自己管理事务开始 SqlTransactionManager.Begin(); IUnitOfWork uof = new UnitOfWork();//使用自己的UnitOfWork //从NumControl中获取流水号 //GetMaxNumber INumControlRepository numControl = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); bool addflag = false; //var maxObj = numControl.GetMaxNumberObj("CARTONNO", prestr + "{0}"); var maxObj = numControl.GetMaxValue("CARTONNO", prestr); //檢查有沒有lock index, 沒有lock index, 改變查詢條件 if (maxObj == null) { //lock NoType='CARTONNO' //string maxData = numControl.GetMaxNumber("CARTONNO", "{0}"); //maxObj = numControl.GetMaxNumberObj("CARTONNO", prestr + "{0}"); var data = numControl.GetMaxValue("CARTONNO", "Lock"); maxObj = numControl.GetMaxValue("CARTONNO", prestr); } if (maxObj != null) { maxnum = maxObj.Value; } //maxnum = numControl.GetMaxNumber("CARTONNO", prestr + "{0}"); if (string.IsNullOrEmpty(maxnum)) { maxnum = "0001";//"8000"; addflag = true; } else { //maxnum="CNU248000Y"; string numstr = maxnum.Substring(maxnum.Length - 4); if (numstr.ToUpper() == "9999") { FisException fe = new FisException("CHK867", new string[] { }); //流水号已满! throw fe; } //ITC-1414-0069 int result = Convert.ToInt32(numstr) + 1; maxnum = result.ToString("d4"); } CartonNO = CartonNO + maxnum.ToUpper(); NumControl item = null;// new NumControl(); if (addflag) { item = new NumControl(); item.NOType = "CARTONNO"; item.Value = CartonNO; item.NOName = prestr; //""; item.Customer = "HP"; } else { item = maxObj; item.Value = CartonNO; } //NumControl item = new NumControl(); //item.NOType = "CARTONNO"; //item.Value = CartonNO; //item.NOName = ""; //item.Customer = "HP"; //numControl.SaveMaxNumber(item, addflag, prestr + "{0}"); numControl.SaveMaxNumber(item, addflag); //Create Carton object Carton carton = new Carton(CartonNO, CurrentSession.Station, 1, CurrentSession.Line, CurrentSession.Editor); ICartonRepository cartonRep = RepositoryFactory.GetInstance().GetRepository<ICartonRepository, Carton>(); cartonRep.Add(carton, uof); uof.Commit(); //立即提交UnitOfWork更新NumControl里面的最大值 SqlTransactionManager.Commit();//提交事物,释放行级更新锁 CurrentSession.AddValue(ExtendSession.SessionKeys.CartonSN, CartonNO); CurrentSession.AddValue(Session.SessionKeys.Carton, carton); } catch (Exception) { SqlTransactionManager.Rollback(); throw; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } return base.DoExecute(executionContext); }
/// <summary> /// 產生CustomerSN號相关逻辑 /// </summary> /// <param name="executionContext"></param> /// <returns></returns> protected internal override System.Workflow.ComponentModel.ActivityExecutionStatus DoExecute(System.Workflow.ComponentModel.ActivityExecutionContext executionContext) { IProduct product = (IProduct)CurrentSession.GetValue(Session.SessionKeys.Product); IProductRepository productRep = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>(); //lock (_syncRoot_GetSeq)//用于防止同一段代码被同时执行,以前只有一个Service时有效,现在多个Service没有去掉,聊胜于无 //var logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //logger.InfoFormat("GenerateCustomerSnActivity: CurrentSession Hash: {0}; CurrentSession Key: {1}; CurrentSession Type: {2}", CurrentSession.GetHashCode().ToString(), CurrentSession.Key, CurrentSession.Type.ToString()); //logger.InfoFormat("GenerateCustomerSnActivity: IProduct Hash: {0}; IProduct Key: {1}", product.GetHashCode().ToString(), product.Key); //need modify try { //CN(中try国代码)+U(Site Code)+年尾码+周别码+流水码 string custSn = ""; DateTime curDate = DateTime.Now; // string year = curDate.Year.ToString(); string maxnum = ""; string prestr = ""; //求当前日期是一年的中第几周 //int weeks = 0; DateTime dateTime = DateTime.Now;//new DateTime(2016,1,1); var ret = IMES.Infrastructure.Utility.Generates.WeekRuleEngine.Calculate("103", dateTime); string weekCode = ret.Week.ToString().PadLeft(2, '0'); string year = ret.Year.ToString();//dateTime.Year.ToString(); custSn = "CN" + "U" + custSn + year.Substring(year.Length - 1, 1) + weekCode;//weeks.ToString("d2"); prestr = custSn; // 自己管理事务开始 SqlTransactionManager.Begin(); IUnitOfWork uof = new UnitOfWork();//使用自己的UnitOfWork //从NumControl中获取流水号 //GetMaxNumber INumControlRepository numControl = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); bool addflag = false; maxnum = numControl.GetMaxNumber("CPQSNO", prestr + "{0}"); if (string.IsNullOrEmpty(maxnum)) { maxnum = "Z000"; //起始值:Z000 addflag = true; } else { //maxnum="CNU248000Y"; string temstr = "Z000"; //起始值:Z000 string numstr = maxnum.Substring(maxnum.Length - 4); temstr = numstr; if (numstr.ToUpper() == "YZZZ") { FisException fe = new FisException("CHK867", new string[] { }); //流水号已满! throw fe; } string[] seqLst = new string[4]; seqLst[0] = temstr.Substring(0, 1); seqLst[1] = temstr.Substring(1, 1); seqLst[2] = temstr.Substring(2, 1); seqLst[3] = temstr.Substring(3, 1); int[] idexLst = getSeqNum(seqLst); if (idexLst[3] == 30) { if (idexLst[2] == 30) { if (idexLst[1] == 30) { if (idexLst[0] == 29) { List<string> errpara = new List<string>(); throw new FisException("CHK867", errpara); //流水号已满! } else { if (idexLst[0] == 30) { idexLst[0] = 28; } else if (idexLst[0] == 28) { idexLst[0] = 27; } else if (idexLst[0] == 27) { idexLst[0] = 29; } else { List<string> errpara = new List<string>(); throw new FisException("CHK867", errpara); //非合法的Z、X、W、Y,视为满 } idexLst[1] = 0; idexLst[2] = 0; idexLst[3] = 0; } } else { idexLst[1] += 1; idexLst[2] = 0; idexLst[3] = 0; } } else { idexLst[2] += 1; idexLst[3] = 0; } } else { idexLst[3] += 1; } temstr = numLst[idexLst[0]] + numLst[idexLst[1]] + numLst[idexLst[2]] + numLst[idexLst[3]]; maxnum = temstr; } custSn = custSn + maxnum.ToUpper(); product.CUSTSN = custSn; productRep.Update(product, uof); NumControl item = new NumControl(); item.NOType = "CPQSNO"; item.Value = custSn; item.NOName = ""; item.Customer = "HP"; numControl.SaveMaxNumber(item, addflag, prestr + "{0}"); uof.Commit(); //立即提交UnitOfWork更新NumControl里面的最大值 SqlTransactionManager.Commit();//提交事物,释放行级更新锁 // [Customer SN Print]保存结果:增加更新[CustomerSN_Qty]. CustomerSN_Qty栏位 //UPDATE [HPIMES].[dbo].[MO] //SET [CustomerSN_Qty] =[ CustomerSN_Qty]+1 //From Product a,MO b WHERE a.MO=b.MO and a.ProductID=ProductID# IMORepository moRepository = RepositoryFactory.GetInstance().GetRepository<IMORepository, MO>(); moRepository.UpdateMoForIncreaseCustomerSnQty(product.ProId, 1); } catch (Exception) { SqlTransactionManager.Rollback(); throw; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } CurrentSession.AddValue(Session.SessionKeys.PrintLogName, product.Customer + "SNO"); CurrentSession.AddValue(Session.SessionKeys.PrintLogBegNo, product.ProId); CurrentSession.AddValue(Session.SessionKeys.PrintLogEndNo, product.ProId); CurrentSession.AddValue(Session.SessionKeys.PrintLogDescr, product.CUSTSN); return base.DoExecute(executionContext); }
private List<string> GetMaxMBSn(string prefix,int qty) { List<string> result = new List<string>(); try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); string currentMaxNum = numCtrlRepository.GetMaxNumber("MBSno", prefix + "{0}"); if (string.IsNullOrEmpty(currentMaxNum)) { ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789ABCDEFGHJKLMNPRSTVWXYZ", 4, "ZZZZ", beginNO, '0'); for (int i = 0; i < qty;i++ ) { result.Add(prefix + "R" + seqCvt.NumberRule.IncreaseToNumber(beginNO, i)); } NumControl currentNumControl = new NumControl(); currentNumControl.NOName = ""; currentNumControl.NOType = "MBSno"; currentNumControl.Customer = Customer; currentNumControl.Value = result[qty-1]; numCtrlRepository.InsertNumControl(currentNumControl); SqlTransactionManager.Commit(); return result; } else { if (currentMaxNum.EndsWith("ZZZZ")) { throw new FisException("CHK162", new string[] { }); } else { ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789ABCDEFGHJKLMNPRSTVWXYZ", 4, "ZZZZ", beginNO, '0'); string sequenceNumber = currentMaxNum.Substring(currentMaxNum.Length - 4, 4); for (int i = 1; i <= qty; i++) { result.Add(prefix + "R" + seqCvt.NumberRule.IncreaseToNumber(sequenceNumber, i)); if (result[i-1].EndsWith("ZZZZ")) { throw new FisException("CHK162", new string[] { }); } } IList<NumControl> numCtrlLst = numCtrlRepository.GetNumControlByNoTypeAndValue("MBSno", currentMaxNum); NumControl currentNumControl = numCtrlLst[0]; currentNumControl.Value = result[qty - 1]; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentNumControl, uof); uof.Commit(); SqlTransactionManager.Commit(); return result; } } } } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } }
private IList<string> getIMEISeq(string model, string preFixCode, string custom, int qty) { string numType = "IMEI"; try { IList<string> ret = new List<string>(); if (qty == 1) { ret.Add(getIMEISeq(model, preFixCode, custom)); return ret; } SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); MACRange currentRange = numCtrlRepository.GetMACRange(preFixCode, new string[] { "R", "A" }); if (currentRange == null) { throw new FisException("ICT014", new string[] { }); } else { if (!validateIMEISettingRange(currentRange.BegNo, currentRange.EndNo)) { throw new FisException("CHK1086", new string[] { currentRange.BegNo + "~" + currentRange.EndNo }); } NumControl currentMaxNum = numCtrlRepository.GetMaxValue(numType, preFixCode); if (currentMaxNum == null) { currentMaxNum = new NumControl(); currentMaxNum.NOName = preFixCode; currentMaxNum.NOType = numType; currentMaxNum.Value = currentRange.BegNo; currentMaxNum.Customer = custom; ret.Add(currentMaxNum.Value); qty--; IUnitOfWork uof = new UnitOfWork(); if (qty >0 && currentMaxNum.Value == currentRange.EndNo) //check Last Range { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Closed); currentRange = numCtrlRepository.GetMACRange(preFixCode, new string[] { "R", "A" }); if (currentRange == null) { throw new FisException("ICT014", new string[] { }); } } int remainingCount = qty; for (int j = 0; j < qty; j++) { remainingCount--; int curNum = int.Parse(currentMaxNum.Value) + 1; currentMaxNum.Value = curNum.ToString("D12"); if (remainingCount >0 && currentMaxNum.Value == currentRange.EndNo) //check Last Range { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Closed); currentRange = numCtrlRepository.GetMACRange(preFixCode, new string[] { "R", "A" }); if (currentRange == null) { throw new FisException("ICT014", new string[] { }); } if (!validateIMEISettingRange(currentRange.BegNo, currentRange.EndNo)) { throw new FisException("CHK1086", new string[] { currentRange.BegNo + "~" + currentRange.EndNo }); } if (currentMaxNum.Value == currentRange.BegNo || currentMaxNum.Value == currentRange.EndNo) { throw new FisException("ICT018", new string[] { currentMaxNum.Value }); } } ret.Add(currentMaxNum.Value); } if (int.Parse(currentMaxNum.Value) > int.Parse(currentRange.EndNo)) { throw new FisException("GEN022", new string[] { currentMaxNum.Value + ">" + currentRange.EndNo }); } if (currentMaxNum.Value == currentRange.EndNo) { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Closed); } else { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Active); } numCtrlRepository.InsertNumControlDefered(uof, currentMaxNum); uof.Commit(); SqlTransactionManager.Commit(); return ret; } else { if (currentMaxNum.Value == currentRange.EndNo) { numCtrlRepository.SetMACRangeStatus(currentRange.ID, MACRange.MACRangeStatus.Closed); currentRange = numCtrlRepository.GetMACRange(preFixCode, new string[] { "R","A" }); if (currentRange == null) { throw new FisException("ICT014", new string[] { }); } if (!validateIMEISettingRange(currentRange.BegNo, currentRange.EndNo)) { throw new FisException("CHK1086", new string[] { currentRange.BegNo + "~" + currentRange.EndNo }); } if (currentMaxNum.Value == currentRange.BegNo || currentMaxNum.Value == currentRange.EndNo) { throw new FisException("ICT018", new string[] { currentMaxNum.Value }); } } IUnitOfWork uof = new UnitOfWork(); int remainingCount = qty; for (int j = 0; j < qty; j++) { remainingCount--; int curNextNum = int.Parse(currentMaxNum.Value) + 1; currentMaxNum.Value = curNextNum.ToString("D12"); ret.Add(currentMaxNum.Value); if (remainingCount > 0 && currentMaxNum.Value == currentRange.EndNo) //check Last Range { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Closed); currentRange = numCtrlRepository.GetMACRange(preFixCode, new string[] { "R", "A" }); if (currentRange == null) { throw new FisException("ICT014", new string[] { }); } if (!validateIMEISettingRange(currentRange.BegNo, currentRange.EndNo)) { throw new FisException("CHK1086", new string[] { currentRange.BegNo + "~" + currentRange.EndNo }); } if (currentMaxNum.Value == currentRange.BegNo || currentMaxNum.Value == currentRange.EndNo) { throw new FisException("ICT018", new string[] { currentMaxNum.Value }); } } } if (int.Parse(currentMaxNum.Value) > int.Parse(currentRange.EndNo)) { throw new FisException("GEN022", new string[] { currentMaxNum.Value + ">" + currentRange.EndNo }); } numCtrlRepository.Update(currentMaxNum, uof); if (currentMaxNum.Value == currentRange.EndNo) { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Closed); } else { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Active); } uof.Commit(); SqlTransactionManager.Commit(); return ret; } } } } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } }
private string GetEEP() { try { SqlTransactionManager.Begin(); lock (_syncRoot_GetSeq) { INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>(); string mbFamily = CurrentSession.GetValue(Session.SessionKeys.FamilyName) as string; MACRange currentRange = numCtrlRepository.GetMACRange(mbFamily, new string[] { "R", "A" }); if (currentRange == null) { throw new FisException("ICT015", new string[] { }); } else { NumControl currentMaxNum = numCtrlRepository.GetMaxValue("EEPROM", mbFamily); if (currentMaxNum == null) { currentMaxNum = new NumControl(); currentMaxNum.NOName = mbFamily; currentMaxNum.NOType = "EEPROM"; currentMaxNum.Value = currentRange.BegNo.Substring(0, 11) + "1"; currentMaxNum.Customer = ""; IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.InsertNumControlDefered(uof, currentMaxNum); if (currentMaxNum.Value.Substring(0, 11) == currentRange.EndNo.Substring(0, 11)) { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Closed); } else { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Active); } uof.Commit(); SqlTransactionManager.Commit(); return currentMaxNum.Value; } else { if (currentMaxNum.Value.Substring(0, 11) == currentRange.EndNo.Substring(0, 11)) { numCtrlRepository.SetMACRangeStatus(currentRange.ID, MACRange.MACRangeStatus.Closed); currentRange = numCtrlRepository.GetMACRange(mbFamily, new string[] { "R" }); if (currentMaxNum.Value.Substring(0, 11) == currentRange.BegNo.Substring(0, 11) || currentMaxNum.Value.Substring(0, 11) == currentRange.EndNo.Substring(0, 11)) { throw new FisException("ICT017", new string[] { currentMaxNum.Value.Substring(0, 11) }); } } if (string.Compare(currentMaxNum.Value.Substring(0, 11), currentRange.BegNo.Substring(0, 11)) < 0 || string.Compare(currentMaxNum.Value.Substring(0, 11), currentRange.EndNo.Substring(0, 11)) > 0) { currentMaxNum.Value = currentRange.BegNo.Substring(0, 11) + "1"; } else { ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789", 7, "9999999", "0000000", '0'); string sequenceNumber = currentMaxNum.Value.Substring(4, 7); sequenceNumber = seqCvt.NumberRule.IncreaseToNumber(sequenceNumber, 1); currentMaxNum.Value = currentMaxNum.Value.Substring(0, 4) + sequenceNumber + "1"; } IUnitOfWork uof = new UnitOfWork(); numCtrlRepository.Update(currentMaxNum, uof); if (currentMaxNum.Value.Substring(0, 11) == currentRange.EndNo.Substring(0, 11)) { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Closed); } else { numCtrlRepository.SetMACRangeStatusDefered(uof, currentRange.ID, MACRange.MACRangeStatus.Active); } uof.Commit(); SqlTransactionManager.Commit(); return currentMaxNum.Value; } } } } catch (Exception e) { SqlTransactionManager.Rollback(); throw e; } finally { SqlTransactionManager.Dispose(); SqlTransactionManager.End(); } }