Ejemplo n.º 1
0
        private string GetMaxMBSn(string prefix)
        {
            try
            {
                SqlTransactionManager.Begin();
                lock (_syncRoot_GetSeq)
                {
                    INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>();

                    string currentMaxNum = numCtrlRepository.GetMaxNumber("MBSno", prefix + "{0}");
                    if (string.IsNullOrEmpty(currentMaxNum))
                    {

                        NumControl currentNumControl = new NumControl();
                        currentNumControl.NOName = "";
                        currentNumControl.NOType = "MBSno";
                        currentNumControl.Value = prefix + "R" + beginNO;
                        currentNumControl.Customer = Customer;
                        numCtrlRepository.InsertNumControl(currentNumControl);
                        SqlTransactionManager.Commit();
                        return currentNumControl.Value;
                    }
                    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);
                            sequenceNumber = seqCvt.NumberRule.IncreaseToNumber(sequenceNumber, 1);

                            IList<NumControl> numCtrlLst = numCtrlRepository.GetNumControlByNoTypeAndValue("MBSno", currentMaxNum);
                            NumControl currentNumControl = numCtrlLst[0];

                            currentNumControl.Value = prefix + "R" + sequenceNumber;
                            IUnitOfWork uof = new UnitOfWork();
                            numCtrlRepository.Update(currentNumControl, uof);
                            uof.Commit();
                            SqlTransactionManager.Commit();
                            return currentNumControl.Value;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                SqlTransactionManager.Rollback();
                throw e;
            }
            finally
            {
                SqlTransactionManager.Dispose();
                SqlTransactionManager.End();
            }
        }
Ejemplo n.º 2
0
        private string GenerateCodeNew(string cust)
        {
            try
            {
                var currenProduct = (IProduct)CurrentSession.GetValue(Session.SessionKeys.Product);
                string customerSN = (string)CurrentSession.GetValue(Session.SessionKeys.CustSN);

                string custNum = "";
                string numType = "AST";

                IPartRepository ipartRepository = RepositoryFactory.GetInstance().GetRepository<IPartRepository, IPart>();

                INumControlRepository numCtrlRepository = RepositoryFactory.GetInstance().GetRepository<INumControlRepository, NumControl>();

                SqlTransactionManager.Begin();
                lock (_syncRoot_GetSeq)
                {
                    AssetRangeCodeInfo currentRange = ipartRepository.GetAssetRangeByStatus(cust, new string[] { "A", "R" });

                    if (currentRange == null)
                    {
                        throw new FisException("CHK200", new string[] { customerSN });
                    }

                    NumControl currentMaxNum = numCtrlRepository.GetMaxValue(numType, cust);

                    if (currentMaxNum == null)
                    {
                        #region 第一次產生Serial Number
                        //Check new Range
                        CheckAssetNum(customerSN,
                                                     currentRange.Begin, currentRange.End);
                        currentMaxNum = new NumControl();
                        currentMaxNum.NOName = cust;
                        currentMaxNum.NOType = numType;
                        currentMaxNum.Value = currentRange.Begin;
                        currentMaxNum.Customer = this.Customer;

                        IUnitOfWork uof = new UnitOfWork();
                        numCtrlRepository.InsertNumControlDefered(uof, currentMaxNum);
                        if (currentMaxNum.Value == currentRange.End)
                        {
                            ipartRepository.SetAssetRangeStatusDefered(uof, currentRange.ID, "C");
                        }
                        else
                        {
                            ipartRepository.SetAssetRangeStatusDefered(uof, currentRange.ID, "A");
                        }
                        uof.Commit();
                        SqlTransactionManager.Commit();
                        custNum = currentMaxNum.Value;
                        #endregion
                    }
                    else
                    {
                        #region no need check endNumber
                        //if (currentMaxNum.Value == currentRange.End)
                        //{
                        //    ipartRepository.SetAssetRangeStatus(currentRange.ID, "C");
                        //    currentRange = ipartRepository.GetAssetRangeByStatus(cust, new string[] { "R" });
                        //    if (currentRange == null ||
                        //        currentMaxNum.Value.Equals(currentRange.Begin) ||
                        //        currentMaxNum.Value.Equals(currentRange.End))
                        //    {
                        //        throw new FisException("CHK200", new string[] { customerSN });
                        //    }
                        //    else
                        //    {
                        //        #region 更換新Range產生Serial Number
                        //        //Check new Range
                        //        CheckAssetNum(customerSN, currentRange.Begin, currentRange.End);
                        //        IUnitOfWork uof = new UnitOfWork();
                        //        currentMaxNum.Value = currentRange.Begin;
                        //        numCtrlRepository.Update(currentMaxNum, uof);
                        //        ipartRepository.SetAssetRangeStatusDefered(uof, currentRange.ID, "A");
                        //        uof.Commit();
                        //        SqlTransactionManager.Commit();
                        //        custNum = currentMaxNum.Value;
                        //        #endregion
                        //    }
                        //}
                        #endregion

                        if (currentRange.Status == "R" &&
                           checkNewRange(currentMaxNum.Value, currentRange.Begin, currentRange.End))
                        {
                            #region 更換新Range產生Serial Number
                            //Check new Range
                            CheckAssetNum(customerSN, currentRange.Begin, currentRange.End);
                            IUnitOfWork uof = new UnitOfWork();
                            currentMaxNum.Value = currentRange.Begin;
                            numCtrlRepository.Update(currentMaxNum, uof);
                            if (currentRange.Begin.CompareTo(currentRange.End) <  0)
                            {
                                ipartRepository.SetAssetRangeStatusDefered(uof, currentRange.ID, "A");
                            }
                            else
                            {
                                ipartRepository.SetAssetRangeStatusDefered(uof, currentRange.ID, "C");
                            }                           
                            uof.Commit();
                            SqlTransactionManager.Commit();
                            custNum = currentMaxNum.Value;
                            #endregion
                        }
                        else
                        {
                            currentMaxNum.Value = GenNextAssetNum(customerSN, currentMaxNum.Value, currentRange.End);
                            IUnitOfWork uof = new UnitOfWork();
                            numCtrlRepository.Update(currentMaxNum, uof);
                            if (currentMaxNum.Value == currentRange.End)
                            {
                                ipartRepository.SetAssetRangeStatusDefered(uof, currentRange.ID, "C");
                            }
                            else
                            {
                                ipartRepository.SetAssetRangeStatusDefered(uof, currentRange.ID, "A");
                            }
                            uof.Commit();
                            SqlTransactionManager.Commit();
                            custNum = currentMaxNum.Value;
                        }
                    }
                }

                if (cust == "SCUSTA-1")
                {
                    custNum = "000" + custNum + "00";
                }

                return custNum;
            }
            catch (Exception e)     //2012-7-19
            {
                SqlTransactionManager.Rollback();
                throw e;
            }
            finally                 //2012-7-19
            {
                SqlTransactionManager.Dispose();
                SqlTransactionManager.End();
            }
        }
Ejemplo n.º 3
0
 private void PatientPhone_PreviewTextInput(object sender, System.Windows.Input.TextCompositionEventArgs e)
 {
     NumControl.NumsOnlyInput(sender, e);
 }