Пример #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);
                        if (this.Sequence.GetCount(entity) == 0)
                        {
                            entity             = new SequenceEntity();
                            entity.SN          = TNumProivder.CreateGUID();
                            entity.TabName     = TabName;
                            entity.FirstType   = (int)ESequence.Sequence;
                            entity.FirstRule   = "";
                            entity.FirstLength = 6;
                            entity.JoinChar    = "";
                            entity.IncludeAll();
                            this.Sequence.Add(entity);
                        }
                    }
                }
            }
            return(0);
        }
Пример #2
0
        /// <summary>
        /// 获得表的序列号
        /// </summary>
        /// <returns></returns>
        public static 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 = TNumProivder.CreateGUID();
                    }
                    else if (SequenceType == (int)ESequence.CustomerTime)
                    {
                        value = DateTime.Now.ToString(SequenceRule);
                    }
                    else if (SequenceType == (int)ESequence.Sequence)
                    {
                        if (SequenceLength == 0)
                        {
                            value = new TNumProivder().GetSwiftNum(type);
                        }
                        else
                        {
                            value = new TNumProivder().GetSwiftNum(type, SequenceLength);
                        }
                    }
                    else if (SequenceType == (int)ESequence.SequenceOfDay)
                    {
                        if (SequenceLength == 0)
                        {
                            value = new TNumProivder().GetSwiftNumByDay(type);
                        }
                        else
                        {
                            value = new TNumProivder().GetSwiftNumByDay(type, SequenceLength);
                        }
                    }
                }
                return(value);
            };

            TableInfo        tableInfo = EntityTypeCache.Get(type);
            string           TabName   = tableInfo.Table.Name;
            SequenceProvider provider  = new SequenceProvider();
            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 = TNumProivder.CreateGUID();
            }
            return(result);
        }