コード例 #1
0
        /// <summary>
        /// </summary>		
        protected override SequencialNumberRanges getSequence(Session sess, string preSeqStr, int quantity, bool seqRestart, ISequenceConverter seqCvt)
        {
            SequencialNumberRanges ret = new SequencialNumberRanges();

            //IProductRepository pdtRepository = RepositoryFactory.GetInstance().GetRepository<IProductRepository, IProduct>();
            INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>();

            string type = GetClass();
            //string subruleName = GetClass();
            
            lock (_syncRoot_GetSeq)
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
                {
                    try
                    {
                        SqlTransactionManager.Begin();

                        bool insOrUpd = true;
                        //string maxMo = pdtRepository.GetMaxProductId(preSeqStr);
                        string maxMo = numCtrlRepository.GetMaxNumber(GeneratesConstants.MappingToStandard(type), preSeqStr, this.Customer);
                        string seq = string.Empty;
                        SequencialNumberSegment cnbs = new SequencialNumberSegment();
                        if (string.IsNullOrEmpty(maxMo))
                        {
                            seq = seqCvt.NumberRule.MinNumber;
                            insOrUpd = true;
                        }
                        else
                        {
                            seq = this.CutOutSeq(preSeqStr, maxMo);
                            insOrUpd = false;
                        }

                        cnbs.NumberBegin = seqCvt.Convert(string.Format(preSeqStr, seqCvt.NumberRule.IncreaseToNumber(seq, 1)));
                        cnbs.NumberEnd = seqCvt.Convert(string.Format(preSeqStr, seqCvt.NumberRule.IncreaseToNumber(seq, quantity)));

                        //pdtRepository.SetMaxProductId((string)sess.GetValue(Session.SessionKeys.SMTMONO), cnbs.NumberEnd);
                        numCtrlRepository.SaveMaxNumber(GetANumControl(GeneratesConstants.MappingToStandard(type), string.Empty/*subruleName*/, cnbs.NumberEnd, this.Customer), insOrUpd, preSeqStr);
                        ret.Ranges = new SequencialNumberSegment[] { (SequencialNumberSegment)cnbs };

                        SqlTransactionManager.Commit();
                    }
                    catch (Exception)
                    {
                        SqlTransactionManager.Rollback();
                        throw;
                    }
                    finally
                    {
                        SqlTransactionManager.Dispose();
                        SqlTransactionManager.End();
                    }
                }
            }
            return ret;
        }
コード例 #2
0
        protected override SequencialNumberRanges getSequence(Session sess, string preSeqStr, int quantity, bool seqRestart, ISequenceConverter seqCvt)
        {
            SequencialNumberRanges ret = new SequencialNumberRanges();

            //IMBMORepository mbmoRepository = RepositoryFactory.GetInstance().GetRepository<IMBMORepository, IMBMO>();
            INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>();
          
            string type = GetClass();
            //string subruleName = GetClass();

            lock (_syncRoot_GetSeq)
            {
              
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Suppress))
                {
                    try
                    {
                        SqlConnectionManager.Begin();

                        bool insOrUpd = true;
                        //string maxMo = mbmoRepository.GetMaxMO(preSeqStr);//((bool)Session.GetValue(Session.SessionKeys.IsExperiment));
                        string maxMo = numCtrlRepository.GetMaxNumber(GeneratesConstants.MappingToStandard(type), preSeqStr);//, this.Customer);//2011-09-27 不考虑Customer
                    
                        string seq = string.Empty;
                        SequencialNumberSegment cnbs = new SequencialNumberSegment();
                        if (string.IsNullOrEmpty(maxMo))
                        {
                            seq = seqCvt.NumberRule.MinNumber;
                            cnbs.NumberBegin = seqCvt.Convert(string.Format(preSeqStr, seqCvt.NumberRule.IncreaseToNumber(seq, 0)));
                            cnbs.NumberEnd = seqCvt.Convert(string.Format(preSeqStr, seqCvt.NumberRule.IncreaseToNumber(seq, quantity - 1)));
                            insOrUpd = true;
                       //     NumControl a = new NumControl(0,,,,,,);
                        //    numCtrlRepository.Add(a,CurrentSession.UnitOfWork); 
                        }
                        else
                        {
                            seq = this.CutOutSeq(preSeqStr, maxMo);
                            cnbs.NumberBegin = seqCvt.Convert(string.Format(preSeqStr, seqCvt.NumberRule.IncreaseToNumber(seq, 1)));
                            cnbs.NumberEnd = seqCvt.Convert(string.Format(preSeqStr, seqCvt.NumberRule.IncreaseToNumber(seq, quantity)));
                            insOrUpd = false;
                            //get data
                            //numCtrlRepository.Find(
                        }

                        //mbmoRepository.SetMaxMO((bool)CurrentSession.GetValue(Session.SessionKeys.IsExperiment), GetAMBMO(sess, cnbs.NumberEnd, this.Editor, quantity));
                        //Model _MInfo = (Model)CurrentSession.GetValue(Session.SessionKeys.ModelObj);
                       // numCtrlRepository.SaveMaxNumber(GetANumControl(GeneratesConstants.MappingToStandard(type), _MInfo.ModelName /*subruleName*/, cnbs.NumberEnd, this.Customer), insOrUpd, preSeqStr);

                        numCtrlRepository.SaveMaxNumberWithOutByCustomer(GetANumControl(GeneratesConstants.MappingToStandard(type), string.Empty/*subruleName*/, cnbs.NumberEnd, this.Customer), insOrUpd, preSeqStr);//2011-09-27 不考虑Customer
                        ret.Ranges = new SequencialNumberSegment[] { (SequencialNumberSegment)cnbs };
                         
                        // Check Customer SN Range By Model

                        //Model modelObj = (Model)CurrentSession.GetValue(Session.SessionKeys.ModelObj);
                        //string strSeqNo = cnbs.NumberEnd.Substring(6, 6);
                        //string strBeginCustSnNo = modelObj.GetAttribute("StartUnitID’ ");
                        //string strEndCustSnNo = modelObj.GetAttribute("EndUnitID");
                        //if (strBeginCustSnNo == null | strEndCustSnNo == null)
                        //{
                         
                        //    throw new Exception(" The Customer SN range by MODEL not define!");
                        //}
                        //if (int.Parse(strSeqNo) < int.Parse(strBeginCustSnNo) | int.Parse(strSeqNo) > int.Parse(strEndCustSnNo))
                        //{
                        //    throw new Exception(" The Customer SN out of range of this MODEL!");
                        
                        //}
                        // Check Customer SN Range By Model

                        SqlConnectionManager.Commit();
                    }
                    catch (Exception)
                    {
                        SqlConnectionManager.Rollback();
                        throw;
                    }
                    finally
                    {
                        SqlConnectionManager.Dispose();
                        SqlConnectionManager.End();
                        scope.Complete();
                    }
             
            }
            }
            return ret;
        }