Пример #1
0
        /// <summary>
        /// 新增序号管理
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Init()
        {
            DataTable table = this.Sequence.GetTables();

            if (table != null && table.Rows.Count > 0)
            {
                foreach (DataRow row in table.Rows)
                {
                    string TabName = row["name"] != null ? row["name"].ToString() : string.Empty;
                    if (!TabName.IsEmpty())
                    {
                        SequenceEntity entity = new SequenceEntity();
                        entity.Where(a => a.TabName == TabName)
                        .And(a => a.CompanyID == this.CompanyID)
                        ;
                        if (this.Sequence.GetCount(entity) == 0)
                        {
                            entity             = new SequenceEntity();
                            entity.SN          = TNumProvider.CreateGUID();
                            entity.TabName     = TabName;
                            entity.FirstType   = (int)ESequence.Sequence;
                            entity.FirstRule   = "";
                            entity.FirstLength = 7;
                            entity.JoinChar    = "";
                            entity.CompanyID   = this.CompanyID;
                            entity.IncludeAll();
                            this.Sequence.Add(entity);
                        }
                    }
                }
            }
            return(0);
        }
Пример #2
0
        /// <summary>
        /// 获得表的序列号
        /// </summary>
        /// <returns></returns>
        public string GetSequence(Type type)
        {
            Func <int, string, int, string> Func = (int SequenceType, string SequenceRule, int SequenceLength) =>
            {
                string value = string.Empty;
                if (SequenceType > 0)
                {
                    if (SequenceType == (int)ESequence.Constant)
                    {
                        value = SequenceRule;
                    }
                    else if (SequenceType == (int)ESequence.Guid)
                    {
                        value = TNumProvider.CreateGUID();
                    }
                    else if (SequenceType == (int)ESequence.CustomerTime)
                    {
                        value = DateTime.Now.ToString(SequenceRule);
                    }
                    else if (SequenceType == (int)ESequence.Sequence)
                    {
                        if (SequenceLength == 0)
                        {
                            value = new TNumProvider(this.CompanyID).GetSwiftNum(type);
                        }
                        else
                        {
                            value = new TNumProvider(this.CompanyID).GetSwiftNum(type, SequenceLength);
                        }
                    }
                    else if (SequenceType == (int)ESequence.SequenceOfDay)
                    {
                        if (SequenceLength == 0)
                        {
                            value = new TNumProvider(this.CompanyID).GetSwiftNumByDay(type);
                        }
                        else
                        {
                            value = new TNumProvider(this.CompanyID).GetSwiftNumByDay(type, SequenceLength);
                        }
                    }
                }
                return(value);
            };

            TableInfo        tableInfo = EntityTypeCache.Get(type);
            string           TabName   = tableInfo.Table.Name;
            SequenceProvider provider  = new SequenceProvider(CompanyID);
            SequenceEntity   entity    = provider.GetSingle(TabName);

            string result = string.Empty;

            if (entity != null)
            {
                List <string> list = new List <string>();
                if (entity.FirstType > 0)
                {
                    list.Add(Func(entity.FirstType, entity.FirstRule, entity.FirstLength));
                }
                if (entity.SecondType > 0)
                {
                    list.Add(Func(entity.SecondType, entity.SecondRule, entity.SecondLength));
                }
                if (entity.ThirdType > 0)
                {
                    list.Add(Func(entity.ThirdType, entity.ThirdRule, entity.ThirdLength));
                }
                if (entity.FourType > 0)
                {
                    list.Add(Func(entity.FourType, entity.FourRule, entity.FourLength));
                }
                result = string.Join(entity.JoinChar, list.ToArray());
            }
            else
            {
                result = new TNumProvider(this.CompanyID).GetSwiftNum(type, 6);
            }
            return(result);
        }