/// <summary>
 /// 添加, 这里可以人工干预,提高程序的性能
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式,表主键是否采用自增的策略</param>
 /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param>
 /// <returns>主键</returns>
 public string Add(BaseSequenceEntity entity, bool identity = true, bool returnId = true)
 {
     Identity  = identity;
     ReturnId  = returnId;
     entity.Id = AddEntity(entity).ToInt();
     return(entity.Id.ToString());
 }
Beispiel #2
0
        //
        // 重置序列(暂不考虑并发问题)
        //


        #region public int Reset(string[] ids) 批量重置
        /// <summary>
        /// 批量重置
        /// </summary>
        /// <param name="ids">主键数组</param>
        /// <returns>影响行数</returns>
        public int Reset(string[] ids)
        {
            int returnValue = 0;
            BaseSequenceEntity sequenceEntity = null;
            SQLBuilder         sqlBuilder     = new SQLBuilder(DbHelper);

            for (int i = 0; i < ids.Length; i++)
            {
                if (ids[i].Length > 0)
                {
                    // 若有相应的表,那就把序列号都计算好
                    sequenceEntity = this.GetEntity(ids[i]);
                    string commandText = string.Format(@" UPDATE BaseSequence
                                               SET Sequence = (SELECT MAX(SortCode) + 1  AS MaxSortCode FROM {0})
	                                               , Reduction = ( SELECT MIN(SortCode) -1 AS MinSortCode FROM {0})
                                             WHERE FullName = '{0}' ", sequenceEntity.FullName);
                    try
                    {
                        this.ExecuteNonQuery(commandText);
                    }
                    catch
                    {
                        sqlBuilder.BeginUpdate(this.CurrentTableName);
                        sqlBuilder.SetValue(BaseSequenceEntity.FieldSequence, this.DefaultSequence);
                        sqlBuilder.SetValue(BaseSequenceEntity.FieldReduction, this.DefaultReduction);
                        sqlBuilder.SetWhere(BaseSequenceEntity.FieldId, ids[i]);
                        returnValue += sqlBuilder.EndUpdate();
                    }
                }
            }
            return(returnValue);
        }
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="status">状态</param>
        public int Update(BaseSequenceEntity entity, out Status status)
        {
            var result = 0;

            // 检查名称是否重复
            if (Exists(new KeyValuePair <string, object>(BaseSequenceEntity.FieldName, entity.Name), entity.Id))
            {
                // 名称已重复
                status = Status.ErrorNameExist;
            }
            else
            {
                // 进行更新操作
                result = UpdateEntity(entity);
                if (result == 1)
                {
                    status = Status.OkUpdate;
                }
                else
                {
                    // 数据可能被删除
                    status = Status.ErrorDeleted;
                }
            }
            return(result);
        }
Beispiel #4
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="businessCardEntity">实体</param>
        public int Update(BaseSequenceEntity sequenceEntity, out string statusCode)
        {
            int returnValue = 0;

            // 检查名称是否重复
            if (this.Exists(new KeyValuePair <string, object>(BaseSequenceEntity.FieldFullName, sequenceEntity.FullName), sequenceEntity.Id))
            {
                // 名称已重复
                statusCode = StatusCode.ErrorNameExist.ToString();
            }
            else
            {
                // 进行更新操作
                returnValue = this.UpdateEntity(sequenceEntity);
                if (returnValue == 1)
                {
                    statusCode = StatusCode.OKUpdate.ToString();
                }
                else
                {
                    // 数据可能被删除
                    statusCode = StatusCode.ErrorDeleted.ToString();
                }
            }
            return(returnValue);
        }
Beispiel #5
0
        /// <summary>
        /// 获得序列
        /// </summary>
        /// <param name="fullName">序列名</param>
        /// <param name="defaultSequence">默认序列</param>
        /// <returns>序列实体</returns>
        protected BaseSequenceEntity GetSequenceByLock(string fullName, int defaultSequence)
        {
            BaseSequenceEntity sequenceEntity = new BaseSequenceEntity();

            // 这里主要是为了判断是否存在
            sequenceEntity = this.GetEntityByName(fullName);
            if (sequenceEntity == null)
            {
                // 这里添加记录时加锁机制。
                // 是否已经被锁住
                this.ReturnStatusCode = StatusCode.CanNotLock.ToString();
                for (int i = 0; i < BaseSystemInfo.LockNoWaitCount; i++)
                {
                    // 被锁定的记录数
                    int lockCount = DbLogic.LockNoWait(DbHelper, BaseSequenceEntity.TableName, new KeyValuePair <string, object>(BaseSequenceEntity.FieldFullName, BaseSequenceEntity.TableName));
                    if (lockCount > 0)
                    {
                        sequenceEntity.FullName  = fullName;
                        sequenceEntity.Reduction = defaultSequence - 1;
                        sequenceEntity.Sequence  = defaultSequence;
                        sequenceEntity.Step      = DefaultStep;
                        this.AddEntity(sequenceEntity);

                        this.ReturnStatusCode = StatusCode.LockOK.ToString();
                        break;
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(BaseRandom.GetRandom(1, BaseSystemInfo.LockNoWaitTickMilliSeconds));
                    }
                }
                if (this.ReturnStatusCode == StatusCode.LockOK.ToString())
                {
                    // JiRiGaLa 这个是否能省略
                    sequenceEntity = this.GetEntityByName(fullName);
                }
            }
            else
            {
                // 若记录已经存在,加锁,然后读取记录。
                // 是否已经被锁住
                this.ReturnStatusCode = StatusCode.CanNotLock.ToString();
                for (int i = 0; i < BaseSystemInfo.LockNoWaitCount; i++)
                {
                    // 被锁定的记录数
                    int lockCount = DbLogic.LockNoWait(DbHelper, BaseSequenceEntity.TableName, new KeyValuePair <string, object>(BaseSequenceEntity.FieldFullName, fullName));
                    if (lockCount > 0)
                    {
                        sequenceEntity        = this.GetEntityByName(fullName);
                        this.ReturnStatusCode = StatusCode.LockOK.ToString();
                        break;
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(BaseRandom.GetRandom(1, BaseSystemInfo.LockNoWaitTickMilliSeconds));
                    }
                }
            }
            return(sequenceEntity);
        }
        /// <summary>
        /// 获取添加
        /// </summary>
        /// <param name="name">序列名</param>
        /// /// <param name="defaultSequence">默认升序序列号</param>
        /// <param name="defaultReduction">默认降序序列号</param>
        /// <param name="defaultStep">递增或者递减数步调</param>
        /// <param name="defaultPrefix">默认的前缀</param>
        /// <param name="defaultDelimiter">默认分隔符</param>
        /// <param name="defaultIsVisable">默认的可见性</param>
        /// <returns>序列实体</returns>
        BaseSequenceEntity GetEntityByAdd(string name, int?defaultSequence = null, int?defaultReduction = null, int?defaultStep = null, string defaultPrefix = "", string defaultDelimiter = "", int?defaultIsVisable = null)
        {
            var sequenceEntity = GetEntityByName(name);

            if (sequenceEntity == null)
            {
                sequenceEntity = new BaseSequenceEntity
                {
                    Name     = name,
                    SortCode = 1
                };
                if (defaultSequence == null)
                {
                    sequenceEntity.Sequence = DefaultSequence;
                }
                else
                {
                    sequenceEntity.Sequence = Convert.ToInt32(defaultSequence);
                }
                if (defaultReduction == null)
                {
                    sequenceEntity.Reduction = DefaultReduction;
                }
                else
                {
                    sequenceEntity.Reduction = Convert.ToInt32(defaultReduction);
                }
                if (defaultStep == null)
                {
                    sequenceEntity.Step = DefaultStep;
                }
                else
                {
                    sequenceEntity.Step = Convert.ToInt32(defaultStep);
                }
                if (!string.IsNullOrEmpty(defaultPrefix))
                {
                    sequenceEntity.Prefix = defaultPrefix;
                }
                else
                {
                    sequenceEntity.Prefix = DefaultPrefix;
                }
                if (!string.IsNullOrEmpty(defaultDelimiter))
                {
                    sequenceEntity.Delimiter = defaultDelimiter;
                }
                else
                {
                    sequenceEntity.Delimiter = DefaultDelimiter;
                }
                sequenceEntity.IsVisible = DefaultIsVisible;
                Add(sequenceEntity);
            }

            return(sequenceEntity);
        }
Beispiel #7
0
        /// <summary>
        /// 更新编码
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="dataTable">数据表</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状态信息</param>
        /// <returns>数据表</returns>
        public int Update(BaseUserInfo userInfo, DataTable dataTable, out string statusCode, out string statusMessage)
        {
            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            BaseSequenceEntity sequenceEntity = new BaseSequenceEntity(dataTable);
            return(this.Update(userInfo, sequenceEntity, out statusCode, out statusMessage));
        }
Beispiel #8
0
 /// <summary>
 /// 批量产生主键
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="sequenceCount">序列个数</param>
 /// <returns>主键数组</returns>
 private string[] Increment(BaseSequenceEntity entity, int sequenceCount)
 {
     string[] result = new string[sequenceCount];
     for (int i = 0; i < sequenceCount; i++)
     {
         result[i]        = Increment(entity);
         entity.Sequence += entity.Step;
     }
     return(result);
 }
Beispiel #9
0
 /// <summary>
 /// 批量产生主键
 /// </summary>
 /// <param name="sequenceEntity">实体</param>
 /// <param name="sequenceCount">序列个数</param>
 /// <returns>主键数组</returns>
 private string[] GetSequence(BaseSequenceEntity sequenceEntity, int sequenceCount)
 {
     string[] returnValue = new string[sequenceCount];
     for (int i = 0; i < sequenceCount; i++)
     {
         returnValue[i]           = GetSequence(sequenceEntity);
         sequenceEntity.Sequence += sequenceEntity.Step;
     }
     return(returnValue);
 }
Beispiel #10
0
        /// <summary>
        /// 按名称获取实体
        /// </summary>
        /// <param name="fullName">序列名称</param>
        /// <returns>实体</returns>
        BaseSequenceEntity GetObjectByName(string fullName)
        {
            BaseSequenceEntity sequenceEntity = null;
            var dt = this.GetDataTable(new KeyValuePair <string, object>(BaseSequenceEntity.FieldFullName, fullName));

            if (dt.Rows.Count > 0)
            {
                sequenceEntity = BaseEntity.Create <BaseSequenceEntity>(dt);
            }
            return(sequenceEntity);
        }
Beispiel #11
0
        /// <summary>
        /// 按名称获取实体
        /// </summary>
        /// <param name="fullName">序列名称</param>
        /// <returns>实体</returns>
        BaseSequenceEntity GetEntityByName(string fullName)
        {
            BaseSequenceEntity sequenceEntity = null;
            DataTable          dataTable      = this.GetDataTable(new KeyValuePair <string, object>(BaseSequenceEntity.FieldFullName, fullName));

            if (dataTable.Rows.Count > 0)
            {
                sequenceEntity = new BaseSequenceEntity(dataTable);
            }
            return(sequenceEntity);
        }
        /// <summary>
        /// 按名称获取实体
        /// </summary>
        /// <param name="name">序列名称</param>
        /// <returns>实体</returns>
        BaseSequenceEntity GetEntityByName(string name)
        {
            BaseSequenceEntity sequenceEntity = null;
            var dt = GetDataTable(new KeyValuePair <string, object>(BaseSequenceEntity.FieldName, name));

            if (dt != null && dt.Rows.Count > 0)
            {
                sequenceEntity = BaseEntity.Create <BaseSequenceEntity>(dt);
            }
            return(sequenceEntity);
        }
Beispiel #13
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="sequenceEntity">实体</param>
 private void SetEntity(SQLBuilder sqlBuilder, BaseSequenceEntity sequenceEntity)
 {
     sqlBuilder.SetValue(BaseSequenceEntity.FieldFullName, sequenceEntity.FullName);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldPrefix, sequenceEntity.Prefix);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldSeparator, sequenceEntity.Separator);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldSequence, sequenceEntity.Sequence);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldReduction, sequenceEntity.Reduction);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldStep, sequenceEntity.Step);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldIsVisible, sequenceEntity.IsVisible);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldDescription, sequenceEntity.Description);
     SetEntityExpand(sqlBuilder, sequenceEntity);
 }
Beispiel #14
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="entity">实体</param>
 private void SetObject(SQLBuilder sqlBuilder, BaseSequenceEntity entity)
 {
     sqlBuilder.SetValue(BaseSequenceEntity.FieldFullName, entity.FullName);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldPrefix, entity.Prefix);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldDelimiter, entity.Delimiter);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldSequence, entity.Sequence);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldReduction, entity.Reduction);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldStep, entity.Step);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldIsVisible, entity.IsVisible);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldDescription, entity.Description);
     SetObjectExpand(sqlBuilder, entity);
 }
Beispiel #15
0
        /// <summary>
        /// 获取降序列
        /// </summary>
        /// <param name="entity">序列实体</param>
        /// <returns>降序列</returns>
        string Decrement(BaseSequenceEntity entity, bool fillZeroPrefix = false, bool usePrefix = false)
        {
            string reduction = entity.Reduction.ToString();

            if (fillZeroPrefix)
            {
                reduction = StringUtil.RepeatString("0", (this.SequenceLength - entity.Reduction.ToString().Length)) + entity.Reduction.ToString();
            }
            if (usePrefix)
            {
                reduction = entity.Prefix + entity.Delimiter + reduction;
            }
            return(reduction);
        }
Beispiel #16
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public BaseSequenceEntity GetObject(BaseUserInfo userInfo, string id)
        {
            BaseSequenceEntity sequenceEntity = null;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var manager    = new BaseSequenceManager(dbHelper, userInfo);
                sequenceEntity = manager.GetObject(id);
            });

            return(sequenceEntity);
        }
 /// <summary>
 /// 添加或更新(主键是否为0)
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式,表主键是否采用自增的策略</param>
 /// <param name="returnId">返回主键,不返回程序允许速度会快,主要是为了主细表批量插入数据优化用的</param>
 /// <returns>主键</returns>
 public string AddOrUpdate(BaseSequenceEntity entity, bool identity = true, bool returnId = true)
 {
     Identity = identity;
     ReturnId = returnId;
     if (entity.Id == 0)
     {
         entity.Id = AddEntity(entity).ToInt();
         return(entity.Id.ToString());
     }
     else
     {
         return(UpdateEntity(entity) > 0 ? entity.Id.ToString() : string.Empty);
     }
 }
Beispiel #18
0
        //
        // 读取序列的
        //


        /// <summary>
        /// 获取序列
        /// </summary>
        /// <param name="sequenceEntity">序列实体</param>
        /// <returns>序列</returns>
        string GetSequence(BaseSequenceEntity sequenceEntity)
        {
            string sequence = sequenceEntity.Sequence.ToString();

            if (this.FillZeroPrefix)
            {
                sequence = StringUtil.RepeatString("0", (this.SequenceLength - sequenceEntity.Sequence.ToString().Length)) + sequenceEntity.Sequence.ToString();
            }
            if (this.UsePrefix)
            {
                sequence = sequenceEntity.Prefix + sequenceEntity.Separator + sequence;
            }
            return(sequence);
        }
Beispiel #19
0
        /// <summary>
        /// 获取降序列
        /// </summary>
        /// <param name="sequenceEntity">序列实体</param>
        /// <returns>降序列</returns>
        string GetReduction(BaseSequenceEntity sequenceEntity)
        {
            string reduction = sequenceEntity.Reduction.ToString();

            if (this.FillZeroPrefix)
            {
                reduction = StringUtil.RepeatString("0", (this.SequenceLength - sequenceEntity.Reduction.ToString().Length)) + sequenceEntity.Reduction.ToString();
            }
            if (this.UsePrefix)
            {
                reduction = sequenceEntity.Prefix + sequenceEntity.Separator + reduction;
            }
            return(reduction);
        }
Beispiel #20
0
        /// <summary>
        /// 获取序列号数组
        /// </summary>
        /// <param name="fullName">序列名称</param>
        /// <param name="sequenceCount">序列个数</param>
        /// <param name="defaultSequence">默认序列</param>
        /// <returns>序列号</returns>
        public string[] GetBatchSequence(string fullName, int sequenceCount, int defaultSequence)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = Environment.TickCount;
            Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
            #endif

            string[] returnValue = new string[sequenceCount];

            // 这里用锁的机制,提高并发控制能力
            lock (SequenceLock)
            {
                this.DefaultSequence = defaultSequence;
                switch (DbHelper.CurrentDbType)
                {
                case CurrentDbType.Access:
                case CurrentDbType.MySql:
                case CurrentDbType.SqlServer:
                    BaseSequenceEntity sequenceEntity = this.GetEntityByAdd(fullName);
                    this.UpdateSequence(fullName, sequenceCount);
                    // 这里循环产生ID数组
                    returnValue = this.GetSequence(sequenceEntity, sequenceCount);
                    break;

                case CurrentDbType.DB2:
                    for (int i = 0; i < sequenceCount; i++)
                    {
                        returnValue[i] = GetDB2Sequence(fullName);
                    }
                    break;

                case CurrentDbType.Oracle:
                    for (int i = 0; i < sequenceCount; i++)
                    {
                        returnValue[i] = GetOracleSequence(fullName);
                    }
                    break;
                }
            }

            // 写入调试信息
            #if (DEBUG)
            int milliEnd = Environment.TickCount;
            Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " :End: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
            #endif

            return(returnValue);
        }
Beispiel #21
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="baseSequenceEntity">实体</param>
        public int UpdateEntity(BaseSequenceEntity baseSequenceEntity)
        {
            SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            this.SetEntity(sqlBuilder, baseSequenceEntity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(BaseSequenceEntity.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(BaseSequenceEntity.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(BaseSequenceEntity.FieldModifiedOn);
            sqlBuilder.SetWhere(BaseSequenceEntity.FieldId, baseSequenceEntity.Id);
            return(sqlBuilder.EndUpdate());
        }
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="sqlBuilder">Sql语句生成器</param>
 /// <param name="entity">实体</param>
 private void SetEntity(SqlBuilder sqlBuilder, BaseSequenceEntity entity)
 {
     SetEntityExtend(sqlBuilder, entity);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldName, entity.Name);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldPrefix, entity.Prefix);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldDelimiter, entity.Delimiter);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldSequence, entity.Sequence);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldReduction, entity.Reduction);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldStep, entity.Step);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldIsVisible, entity.IsVisible);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldDescription, entity.Description);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldSortCode, entity.SortCode);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldDeleted, entity.Deleted);
     sqlBuilder.SetValue(BaseSequenceEntity.FieldEnabled, entity.Enabled);
 }
Beispiel #23
0
        /// <summary>
        /// 获得原序列号
        /// </summary>
        /// <param name="fullName">序列名称</param>
        /// <param name="defaultSequence">默认序列</param>
        /// <param name="sequenceLength">序列长度</param>
        /// <param name="fillZeroPrefix">是否填充补零</param>
        /// <returns>序列号</returns>
        public string GetOldSequence(string fullName, int defaultSequence, int sequenceLength, bool fillZeroPrefix)
        {
            string sequence = string.Empty;

            // 这里用锁的机制,提高并发控制能力
            lock (SequenceLock)
            {
                this.SequenceLength   = sequenceLength;
                this.FillZeroPrefix   = fillZeroPrefix;
                this.DefaultReduction = defaultSequence;
                this.DefaultSequence  = defaultSequence + 1;

                BaseSequenceEntity sequenceEntity = GetEntityByAdd(fullName);
                sequence = GetSequence(sequenceEntity);
            }
            return(sequence);
        }
Beispiel #24
0
        /// <summary>
        /// 获得原序列号
        /// </summary>
        /// <param name="fullName">序列名称</param>
        /// <param name="defaultSequence">默认序列</param>
        /// <param name="sequenceLength">序列长度</param>
        /// <param name="fillZeroPrefix">是否填充补零</param>
        /// <returns>序列号</returns>
        public string StoreCounter(string fullName, int defaultSequence, int sequenceLength, bool fillZeroPrefix)
        {
            string sequence = string.Empty;

            // 这里用锁的机制,提高并发控制能力
            lock (SequenceLock)
            {
                this.SequenceLength   = sequenceLength;
                this.FillZeroPrefix   = fillZeroPrefix;
                this.DefaultReduction = defaultSequence;
                this.DefaultSequence  = defaultSequence + 1;

                BaseSequenceEntity entity = GetObjectByAdd(fullName);
                sequence = Increment(entity);
            }
            return(sequence);
        }
Beispiel #25
0
        /// <summary>
        /// 更新序列
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="sequenceEntity">序列实体</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>影响行数</returns>
        public int Update(BaseUserInfo userInfo, BaseSequenceEntity sequenceEntity, out string statusCode, out string statusMessage)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            statusCode    = string.Empty;
            statusMessage = string.Empty;

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseSequenceManager sequenceManager = new BaseSequenceManager(dbHelper, userInfo);
                    // 编辑数据
                    returnValue = sequenceManager.Update(sequenceEntity, out statusCode);
                    // returnValue = businessCardManager.Update(businessCardEntity, out statusCode);
                    statusMessage = sequenceManager.GetStateMessage(statusCode);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.SequenceService_Update, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif
            return(returnValue);
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity">实体</param>
        /// <param name="status">状态</param>
        public string Add(BaseSequenceEntity entity, out Status status)
        {
            var result = string.Empty;

            // 检查是否重复
            if (Exists(new KeyValuePair <string, object>(BaseSequenceEntity.FieldName, entity.Name)))
            {
                // 名称已重复
                status = Status.ErrorNameExist;
            }
            else
            {
                result = AddEntity(entity);
                // 运行成功
                status = Status.OkAdd;
            }
            return(result);
        }
        //
        // 读取序列的
        //


        /// <summary>
        /// 获取序列
        /// </summary>
        /// <param name="entity">序列实体</param>
        /// <returns>序列</returns>
        string Increment(BaseSequenceEntity entity)
        {
            var sequence = string.Empty;

            if (entity != null)
            {
                sequence = entity.Sequence.ToString();
                if (FillZeroPrefix)
                {
                    sequence = StringUtil.RepeatString("0", (SequenceLength - entity.Sequence.ToString().Length)) + entity.Sequence;
                }
                if (UsePrefix)
                {
                    sequence = entity.Prefix + entity.Delimiter + sequence;
                }
            }
            return(sequence);
        }
Beispiel #28
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="sequenceEntity">实体</param>
        public string Add(BaseSequenceEntity sequenceEntity, out string statusCode)
        {
            string returnValue = string.Empty;

            // 检查是否重复
            if (this.Exists(new KeyValuePair <string, object>(BaseSequenceEntity.FieldFullName, sequenceEntity.FullName)))
            {
                // 名称已重复
                statusCode = StatusCode.ErrorNameExist.ToString();
            }
            else
            {
                returnValue = this.AddEntity(sequenceEntity);
                // 运行成功
                statusCode = StatusCode.OKAdd.ToString();
            }
            return(returnValue);
        }
Beispiel #29
0
        /// <summary>
        /// 添加序列
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="entity">序列实体</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>主键</returns>
        public string Add(BaseUserInfo userInfo, BaseSequenceEntity entity, out string statusCode, out string statusMessage)
        {
            string result = string.Empty;

            string returnCode    = string.Empty;
            string returnMessage = string.Empty;
            var    parameter     = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var sequenceManager = new BaseSequenceManager(dbHelper, userInfo);
                // 调用方法,并且返回运行结果
                result = sequenceManager.Add(entity, out returnCode);
                // result = businessCardManager.Add(businessCardEntity, out statusCode);
                returnMessage = sequenceManager.GetStateMessage(returnCode);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;

            return(result);
        }
Beispiel #30
0
        /// <summary>
        /// 更新序列
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="entity">序列实体</param>
        /// <param name="status">状态</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>影响行数</returns>
        public int Update(BaseUserInfo userInfo, BaseSequenceEntity entity, out Status status, out string statusMessage)
        {
            var result = 0;

            var returnCode    = Status.Ok;
            var returnMessage = string.Empty;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseSequenceManager(dbHelper, userInfo);
                // 编辑数据
                result = manager.Update(entity, out returnCode);
                // result = businessCardManager.Update(businessCardEntity, out status);
                returnMessage = manager.GetStateMessage(returnCode);
            });
            status        = returnCode;
            statusMessage = returnMessage;
            return(result);
        }