Пример #1
0
        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();
            }
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
        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();
            }


        }
Пример #5
0
        public IList<IMES.DataModel.ProdIdRangeInfo> GetPrintLogProdIdRangeList(string MOId)
        {
            try
            {
                IList<IMES.DataModel.ProdIdRangeInfo> ret = new List<IMES.DataModel.ProdIdRangeInfo>();

                IList<string> lst = GetPrintLogProIdListByList(MOId);

                //规则冗余,应该先执行Rule然后取得.
                ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789", 6, "999999", "000000", '0');

                //if (seqCvt == null || seqCvt.NumberRule == null)
                //    throw new Exception("Cannot find the ISequenceConverter for Product ID!"); 

                if (lst != null && lst.Count > 0)
                {
                    string preStr_last = null;
                    string seq_last = null;
                    foreach (string proId in lst)
                    {
                        bool isContinue = false;

                        string preStr = string.Empty;
                        string seq = CutOutSeq(proId, out preStr, seqCvt.NumberRule.iBits);

                        isContinue = (preStr_last != null && preStr_last == preStr && seq_last != null && seqCvt.NumberRule.IncreaseToNumber(seq_last, 1) == seq);
                        if (isContinue)
                        {
                            IMES.DataModel.ProdIdRangeInfo piri = ret[ret.Count - 1];
                            piri.endId = proId;
                            ret.RemoveAt(ret.Count - 1);
                            ret.Add(piri);
                        }
                        else
                        {
                            IMES.DataModel.ProdIdRangeInfo piri = new IMES.DataModel.ProdIdRangeInfo();
                            piri.endId = piri.startId = proId;
                            ret.Add(piri);
                        }
                        preStr_last = preStr;
                        seq_last = seq;
                    }
                }

                #region . OLD .
                //_Schema.SQLContext sqlCtx = null;
                //lock (MethodBase.GetCurrentMethod())
                //{
                //if (!_Schema.Func.PeerTheSQL(MethodBase.GetCurrentMethod().MetadataToken, out sqlCtx))
                //{
                //    sqlCtx = new _Schema.SQLContext();
                //    sqlCtx.Sentence =   "SELECT MAX({0}) as productID" +
                //                        "  FROM {1} WHERE {2}=%{2} " + 
                //                        "UNION " +
                //                        "SELECT MIN({0}) as productID " +
                //                        "  FROM {1} WHERE {2}=%{2} " + 
                //                        "ORDER BY productID DESC";

                //    sqlCtx.Sentence = string.Format(sqlCtx.Sentence, _Schema.Product.fn_ProductID,
                //                                                    typeof(_Schema.Product).Name,
                //                                                    _Schema.Product.fn_MO
                //                                                    );

                //    sqlCtx.Params.Add(_Schema.Product.fn_MO, new SqlParameter("@" + _Schema.Product.fn_MO, SqlDbType.VarChar));
                //    _Schema.Func.InsertIntoCache(MethodBase.GetCurrentMethod().MetadataToken, sqlCtx);
                //}
                //}
                //sqlCtx.Params[_Schema.Product.fn_MO].Value = MOId;
                //using (SqlDataReader sqlR = _Schema.SqlHelper.ExecuteReader(_Schema.SqlHelper.ConnectionString_FA, CommandType.Text, sqlCtx.Sentence, sqlCtx.Params.Values.ToArray<SqlParameter>()))
                //{
                //    if (sqlR != null)
                //    {
                //        ProdIdRangeInfo pri = null;
                //        while (sqlR.Read())
                //        {
                //            if (null == pri)
                //                pri = new ProdIdRangeInfo();

                //            ret.Add
                //        }
                //    }
                //}
                #endregion

                return ret;
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #6
0
        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();
            }
        }
Пример #7
0
        /// <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);
        }
Пример #8
0
        /// <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);
        }
Пример #9
0
        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();
            }
        }
Пример #10
0
        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();
            }
        }
Пример #11
0
        /// <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))
                {
                    int multiQty = (int)CurrentSession.GetValue(Session.SessionKeys.MultiQty);
                    IList<string> eepList = new List<string>();
                    ISequenceConverter seqCvt = new SequenceConverterNormal("0123456789", 7, "9999999", "0000000", '0');

                    for (int i = 0; i < multiQty; i++)
                    {
                        string maxEEP = GetEEP();

                        eepList.Add(maxEEP);
                    }

                    CurrentSession.AddValue(Session.SessionKeys.EEPList, eepList);

                }
            }

            return base.DoExecute(executionContext);
        }