コード例 #1
0
        /// <summary>
        /// 查询分页列表
        /// </summary>
        /// <returns></returns>
        public ActionResult GetList()
        {
            int      pageIndex = WebUtil.GetFormValue <int>("PageIndex", 1);
            int      pageSize  = WebUtil.GetFormValue <int>("PageSize", 15);
            string   TabName   = WebUtil.GetFormValue <string>("TabName", string.Empty);
            string   CompanyID = WebUtil.GetFormValue <string>("CompanyID", string.Empty);
            PageInfo pageInfo  = new PageInfo()
            {
                PageIndex = pageIndex, PageSize = pageSize
            };
            SequenceProvider provider = new SequenceProvider(CompanyID);
            SequenceEntity   entity   = new SequenceEntity();

            entity.TabName   = TabName;
            entity.CompanyID = CompanyID;
            List <SequenceEntity>           listResult = provider.GetList(entity, ref pageInfo);
            DataListResult <SequenceEntity> result     = new DataListResult <SequenceEntity>()
            {
                Code     = (int)EResponseCode.Success,
                PageInfo = pageInfo,
                Result   = listResult,
                Message  = "响应成功"
            };

            return(Content(JsonHelper.SerializeObject(result)));
        }
コード例 #2
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);
        }
コード例 #3
0
        public ActionResult SN()
        {
            string           TabName   = WebUtil.GetFormValue <string>("TabName", string.Empty);
            int              PageIndex = WebUtil.GetFormValue <int>("PageIndex", 1);
            int              PageSize  = WebUtil.GetFormValue <int>("PageSize", 10);
            SequenceProvider provider  = new SequenceProvider();
            SequenceEntity   entity    = new SequenceEntity();

            if (!TabName.IsEmpty())
            {
                entity.Where("TabName", ECondition.Like, "%" + TabName + "%");
            }

            PageInfo pageInfo = new PageInfo()
            {
                PageIndex = PageIndex, PageSize = PageSize
            };
            List <SequenceEntity> listResult = provider.GetList(entity, ref pageInfo);

            listResult = listResult.IsNull() ? new List <SequenceEntity>() : listResult;
            string json = JsonConvert.SerializeObject(listResult);

            this.ReturnJson.AddProperty("Data", json);
            this.ReturnJson.AddProperty("RowCount", pageInfo.RowCount);
            return(Content(this.ReturnJson.ToString()));
        }
コード例 #4
0
        public static string GetNextSequence(string partitionKey, string rowKey, string padding)
        {
            lock (_syncLock)
            {
                int nextSequence = -1;

                SequenceEntity entity = TableStorageHelper.RetrieveAsync <SequenceEntity>(Constants.TABLE_SEQUENCE, partitionKey, rowKey).Result;

                if (entity == null)
                {
                    nextSequence = 1;
                    entity       = new SequenceEntity(partitionKey, rowKey);
                }
                else
                {
                    nextSequence = entity.NextSequence;
                }

                entity.NextSequence = nextSequence + 1;

                TableStorageHelper.InsertOrMergeAsync(Constants.TABLE_SEQUENCE, entity).Wait();

                if (padding != null)
                {
                    return(nextSequence.ToString(padding));
                }
                else
                {
                    return(nextSequence.ToString());
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// 修改序号
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(SequenceEntity entity)
        {
            entity.Include(a => new { a.FirstType, a.FirstRule, a.FirstLength, a.SecondType, a.SecondRule, a.SecondLength, a.ThirdType, a.ThirdRule, a.ThirdLength, a.FourType, a.FourRule, a.FourLength, a.JoinChar, a.Sample, a.CurrentValue, a.Remark });
            entity.Where(a => a.SN == entity.SN).Where(a => a.CompanyID == this.CompanyID);
            int line = this.Sequence.Update(entity);

            return(line);
        }
コード例 #6
0
        /// <summary>
        /// 根据SN号获得序列
        /// </summary>
        /// <param name="SN"></param>
        /// <returns></returns>
        public SequenceEntity Get(string SN)
        {
            SequenceEntity entity = new SequenceEntity();

            entity.IncludeAll();
            entity.Where(a => a.SN == SN).And(a => a.CompanyID == this.CompanyID);
            entity = this.Sequence.GetSingle(entity);
            return(entity);
        }
コード例 #7
0
        /// <summary>
        /// 根据表名序列
        /// </summary>
        /// <param name="TabName"></param>
        /// <returns></returns>
        public SequenceEntity GetSingle(string TabName)
        {
            SequenceEntity entity = new SequenceEntity();

            entity.IncludeAll();
            entity.Where(a => a.TabName == TabName);
            entity = this.Sequence.GetSingle(entity);
            return(entity);
        }
コード例 #8
0
        /// <summary>
        /// 查询序列分页
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="pageInfo"></param>
        /// <returns></returns>
        public List <SequenceEntity> GetList(SequenceEntity entity, ref PageInfo pageInfo)
        {
            entity.IncludeAll();
            entity.OrderBy(a => a.ID, EOrderBy.ASC);
            int rowCount = 0;
            List <SequenceEntity> listResult = this.Sequence.GetList(entity, pageInfo.PageSize, pageInfo.PageIndex, out rowCount);

            pageInfo.RowCount = rowCount;
            return(listResult);
        }
コード例 #9
0
        public ActionResult UpdateSn()
        {
            SequenceEntity entity = WebUtil.GetFormObject <SequenceEntity>("entity");

            if (entity != null)
            {
                SequenceProvider provider = new SequenceProvider();
                int line = provider.Update(entity);
            }
            return(Content(this.ReturnJson.ToString()));
        }
        private void InitCounters(string objectType, out int startCounter, out int endCounter)
        {
            //Update Sequences in database
            using (var repository = _repositoryFactory())
            {
                var sequence             = repository.Sequences.SingleOrDefault(s => s.ObjectType.Equals(objectType, StringComparison.OrdinalIgnoreCase));
                var originalModifiedDate = sequence?.ModifiedDate;

                if (sequence != null)
                {
                    sequence.ModifiedDate = DateTime.UtcNow;
                }
                else
                {
                    sequence = new SequenceEntity {
                        ObjectType = objectType, Value = DefaultSequenceStartValue, ModifiedDate = DateTime.UtcNow
                    };
                    repository.Add(sequence);
                }


                repository.UnitOfWork.Commit();
                //TODO will check it
                //Refresh data to make sure we have latest value in case another transaction was locked
                //repository.Refresh(repository.Sequences);
                sequence     = repository.Sequences.Single(s => s.ObjectType.Equals(objectType, StringComparison.OrdinalIgnoreCase));
                startCounter = sequence.Value;

                //Sequence in database has expired?
                if (originalModifiedDate.HasValue && originalModifiedDate.Value.Date < DateTime.UtcNow.Date)
                {
                    startCounter = DefaultSequenceStartValue;
                }

                try
                {
                    endCounter = checked (startCounter + SequenceReservationRange);
                }
                catch (OverflowException)
                {
                    //need to reset
                    startCounter = DefaultSequenceStartValue;
                    endCounter   = SequenceReservationRange;
                }

                sequence.Value = endCounter;
                //sequence.LastModified = DateTime.UtcNow;
                repository.UnitOfWork.Commit();
            }
        }
コード例 #11
0
        public ActionResult Edit()
        {
            ITopClient client = new TopClientDefault();
            Dictionary <string, string> dic = new Dictionary <string, string>();
            string         CompanyID        = this.CompanyID;
            SequenceEntity entity           = WebUtil.GetFormObject <SequenceEntity>("entity");

            dic.Add("CompanyID", CompanyID);
            dic.Add("Entity", JsonConvert.SerializeObject(entity));

            string result = client.Execute(SequenceApiName.SequenceApiName_Edit, dic);

            return(Content(result));
        }
コード例 #12
0
        private static string ReadAndIncrementSequenceNumber(string key)
        {
            CloudStorageAccount storageAccount =
                CloudStorageAccount.Parse(System.Configuration.ConfigurationManager.AppSettings.Get("AzureStorageAddress"));


            var tableClient = storageAccount.CreateCloudTableClient();
            var tableRef    = tableClient.GetTableReference(System.Configuration.ConfigurationManager.AppSettings.Get("AzureTableName"));

            tableRef.CreateIfNotExists();

            var query      = tableRef.CreateQuery <SequenceEntity>();
            var lastEntity = query.Where(o => o.PartitionKey == key).FirstOrDefault();

            var concurrencyTag = lastEntity?.ETag;

            var lastNumber = "00000";

            if (lastEntity != null)
            {
                lastNumber = lastEntity.Number;
            }
            else
            {
                lastEntity = new SequenceEntity()
                {
                    PartitionKey = key, RowKey = "1"
                };
            }

            int number;

            if (!int.TryParse(lastNumber, out number))
            {
                return("failed to parse: " + lastNumber);
            }

            number++;
            string nextNumber = number.ToString("00000");

            // save back to table
            lastEntity.Number = nextNumber;
            lastEntity.ETag   = concurrencyTag;
            tableRef.Execute(TableOperation.InsertOrReplace(lastEntity));

            return(nextNumber);
        }
コード例 #13
0
        /// <summary>
        /// 查询序列分页
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="pageInfo"></param>
        /// <returns></returns>
        public List <SequenceEntity> GetList(SequenceEntity entity, ref PageInfo pageInfo)
        {
            entity.IncludeAll();
            entity.Where(a => a.CompanyID == this.CompanyID);
            entity.OrderBy(a => a.ID, EOrderBy.ASC);
            if (!entity.TabName.IsEmpty())
            {
                entity.And("TabName", ECondition.Like, "%" + entity.TabName + "%");
            }
            int rowCount = 0;
            List <SequenceEntity> listResult = this.Sequence.GetList(entity, pageInfo.PageSize, pageInfo.PageIndex, out rowCount);

            if (listResult.IsNullOrEmpty())
            {
                this.Init();
                listResult = this.Sequence.GetList(entity, pageInfo.PageSize, pageInfo.PageIndex, out rowCount);
            }
            pageInfo.RowCount = rowCount;
            return(listResult);
        }
コード例 #14
0
        /// <summary>
        /// 编辑标识符规则
        /// </summary>
        /// <returns></returns>
        public ActionResult Edit()
        {
            string           CompanyID = WebUtil.GetFormValue <string>("CompanyID", string.Empty);
            SequenceEntity   entity    = WebUtil.GetFormObject <SequenceEntity>("Entity");
            SequenceProvider provider  = new SequenceProvider(CompanyID);
            int line = provider.Update(entity);

            DataResult dataResult = new DataResult();

            if (line > 0)
            {
                dataResult.Code    = (int)EResponseCode.Success;
                dataResult.Message = "保存成功";
            }
            else
            {
                dataResult.Code    = (int)EResponseCode.Exception;
                dataResult.Message = "保存失败";
            }
            return(Content(JsonHelper.SerializeObject(dataResult)));
        }
コード例 #15
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);
        }