/// <summary>
        /// 添加序列
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="sequenceEntity">序列实体</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>主键</returns>
        public string Add(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

            string returnValue = string.Empty;
            statusCode = string.Empty;
            statusMessage = string.Empty;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseSequenceManager sequenceManager = new BaseSequenceManager(dbHelper, userInfo);
                    // 调用方法,并且返回运行结果
                    returnValue = sequenceManager.Add(sequenceEntity, out statusCode);
                    // returnValue = businessCardManager.Add(businessCardEntity, out statusCode);
                    statusMessage = sequenceManager.GetStateMessage(statusCode);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.SequenceService_Add, 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="baseSequenceEntity">实体</param>
 public int Update(BaseSequenceEntity baseSequenceEntity)
 {
     return this.UpdateEntity(baseSequenceEntity);
 }
 /// <summary>
 /// 获取实体
 /// </summary>
 /// <param name="id">主键</param>
 public BaseSequenceEntity GetEntity(string id)
 {
     BaseSequenceEntity baseSequenceEntity = new BaseSequenceEntity(this.GetDataTable(new KeyValuePair<string, object>(BaseSequenceEntity.FieldId, id)));
     return baseSequenceEntity;
 }
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="baseSequenceEntity">实体</param>
 public string AddEntity(BaseSequenceEntity baseSequenceEntity)
 {
     string sequence = string.Empty;
     this.Identity = false;
     if (baseSequenceEntity.Id != null)
     {
         sequence = baseSequenceEntity.Id.ToString();
     }
     SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);
     sqlBuilder.BeginInsert(this.CurrentTableName, BaseSequenceEntity.FieldId);
     if (!this.Identity)
     {
         if (string.IsNullOrEmpty(baseSequenceEntity.Id))
         {
             sequence = BaseBusinessLogic.NewGuid();
             baseSequenceEntity.Id = sequence ;
         }
         sqlBuilder.SetValue(BaseSequenceEntity.FieldId, baseSequenceEntity.Id);
     }
     else
     {
         if (!this.ReturnId && (DbHelper.CurrentDbType == DbTypes.Oracle || DbHelper.CurrentDbType == DbTypes.DB2))
         {
             if (DbHelper.CurrentDbType == DbTypes.Oracle)
             {
                 sqlBuilder.SetFormula(BaseSequenceEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
             }
             if (DbHelper.CurrentDbType == DbTypes.DB2)
             {
                 sqlBuilder.SetFormula(BaseSequenceEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper());
             }
         }
         else
         {
             if (this.Identity && (DbHelper.CurrentDbType == DbTypes.Oracle || DbHelper.CurrentDbType == DbTypes.DB2))
             {
                 if (string.IsNullOrEmpty(baseSequenceEntity.Id))
                 {
                     if (string.IsNullOrEmpty(sequence))
                     {
                         BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                         sequence = sequenceManager.GetSequence(this.CurrentTableName);
                     }
                     baseSequenceEntity.Id = sequence;
                 }
                 sqlBuilder.SetValue(BaseSequenceEntity.FieldId, baseSequenceEntity.Id);
             }
         }
     }
     this.SetEntity(sqlBuilder, baseSequenceEntity);
     if (UserInfo != null)
     {
         sqlBuilder.SetValue(BaseSequenceEntity.FieldCreateUserId, UserInfo.Id);
         sqlBuilder.SetValue(BaseSequenceEntity.FieldCreateBy, UserInfo.RealName);
     }
     sqlBuilder.SetDBNow(BaseSequenceEntity.FieldCreateOn);
     if (UserInfo != null)
     {
         sqlBuilder.SetValue(BaseSequenceEntity.FieldModifiedUserId, UserInfo.Id);
         sqlBuilder.SetValue(BaseSequenceEntity.FieldModifiedBy, UserInfo.RealName);
     }
     sqlBuilder.SetDBNow(BaseSequenceEntity.FieldModifiedOn);
     if (this.Identity && (DbHelper.CurrentDbType == DbTypes.SqlServer || DbHelper.CurrentDbType == DbTypes.Access))
     {
         sequence = sqlBuilder.EndInsert().ToString();
     }
     else
     {
         sqlBuilder.EndInsert();
     }
     return sequence;
 }
        /// <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>
 /// <returns>名片类</returns>
 private BaseSequenceEntity GetEntity(BaseSequenceEntity sequenceEntity)
 {
     sequenceEntity.FullName = this.txtFullName.Text;
     sequenceEntity.Prefix = this.txtPrefix.Text;
     sequenceEntity.Separator = this.txtSeparator.Text;
     sequenceEntity.Sequence = int.Parse(this.txtSequence.Text);
     sequenceEntity.Reduction = int.Parse(this.txtReduction.Text);
     sequenceEntity.Step = int.Parse(this.txtStep.Text);
     sequenceEntity.Description = this.txtDescription.Text;
     sequenceEntity.IsVisible = this.chkEnabled.Checked ? 1 : 0;
     return sequenceEntity;
 }
        /// <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);
        }
partial         void SetEntityExpand(SQLBuilder sqlBuilder, BaseSequenceEntity sequenceEntity);
 /// <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;
 }
 /// <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;
 }
 //
 // 读取序列的
 //
 /// <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;
 }
 /// <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;
 }
 /// <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="fullName">序列名</param>
        /// <param name="defaultSequence">序列</param>
        /// <param name="defaultReduction">降序序列</param>
        /// <returns>序列实体</returns>
        BaseSequenceEntity GetEntityByAdd(string fullName)
        {
            BaseSequenceEntity sequenceEntity = null;
            sequenceEntity = this.GetEntityByName(fullName);
            if (sequenceEntity == null)
            {
                sequenceEntity = new BaseSequenceEntity();
                // 这里是为了多种数据库的兼容
                sequenceEntity.Id = BaseBusinessLogic.NewGuid();
                sequenceEntity.FullName = fullName;
                sequenceEntity.Sequence = this.DefaultSequence;
                sequenceEntity.Reduction = this.DefaultReduction;
                sequenceEntity.Step = DefaultStep;
                sequenceEntity.Prefix = DefaultPrefix;
                sequenceEntity.Separator = DefaultSeparator;
                sequenceEntity.IsVisible = DefaultIsVisable;
                this.Add(sequenceEntity);
            }

            return sequenceEntity;
        }
 /// <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="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);
 }
        /// <summary>
        /// 检查批量删除的输入的有效性
        /// </summary>
        /// <returns>允许批量删除</returns>
        private bool CheckInputBatchDelete()
        {
            bool returnValue = false;
            // 检查至少要选择一个?
            if (!BaseInterfaceLogic.CheckInputSelectAnyOne(this.grdSequence, "colSelected"))
            {
                return returnValue;
            }
            int selectedCount = 0;
            BaseSequenceEntity sequenceEntity = new BaseSequenceEntity();

            foreach (DataGridViewRow dgvRow in grdSequence.Rows)
            {
                DataRow dataRow = (dgvRow.DataBoundItem as DataRowView).Row;
                if (dataRow.RowState != DataRowState.Deleted)
                {
                    if ((System.Boolean)(dgvRow.Cells["colSelected"].Value??false))
                    {
                        sequenceEntity = new BaseSequenceEntity(dataRow);
                        // 有权限删除
                        if (!sequenceEntity.FullName.Equals("BaseSequence"))
                        {
                            selectedCount++;
                        }
                        else
                        {
                            MessageBox.Show(AppMessage.Format(AppMessage.MSG0018, "BaseSequence"), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return returnValue;
                        }
                    }
                }
            }

            //foreach (DataRowView dataRowView in this.DTSequence.DefaultView)
            //{
            //    DataRow dataRow = dataRowView.Row;
            //    if (dataRow.RowState != DataRowState.Deleted)
            //    {
            //        if (dataRow["colSelected"].ToString() == true.ToString())
            //        {
            //            sequenceEntity = new BaseSequenceEntity(dataRow);
            //            // 有权限删除
            //            if (!sequenceEntity.FullName.Equals("BaseSequence"))
            //            {
            //                selectedCount++;
            //            }
            //            else
            //            {
            //                MessageBox.Show(AppMessage.Format(AppMessage.MSG0018, "BaseSequence"), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
            //                return returnValue;
            //            }
            //        }
            //    }
            //}
            // 有记录被选中了
            returnValue = selectedCount > 0;
            if (!returnValue)
            {
                MessageBox.Show(AppMessage.MSG0024, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            return returnValue;
        }
        /// <summary>
        /// 设置当前所有选中的记录为隐藏状态
        /// </summary>
        /// <returns>设置更新成功</returns>
        private bool SetInvisible()
        {
            bool returnValue = false;
            string statusCode = string.Empty;
            string statusMessage = string.Empty;
            // 检查至少要选择一个
            if (!BaseInterfaceLogic.CheckInputSelectAnyOne(this.grdSequence, "colSelected"))
            {
                return returnValue;
            }
            int selectedCount = 0;
            BaseSequenceEntity sequenceEntity = new BaseSequenceEntity();
            BaseSequenceManager sequenceManager = new BaseSequenceManager(this.UserInfo);

            foreach (DataGridViewRow dgvRow in grdSequence.Rows)
            {
                DataRow dataRow = (dgvRow.DataBoundItem as DataRowView).Row;
                if (dataRow.RowState != DataRowState.Deleted)
                {
                    if ((System.Boolean)(dgvRow.Cells["colSelected"].Value ?? false))
                    {
                        sequenceEntity = new BaseSequenceEntity(dataRow);
                        // 记录BaseSequence不能被隐藏
                        if (!sequenceEntity.FullName.Equals("BaseSequence"))
                        {
                            selectedCount++;
                            sequenceEntity.IsVisible = 0;
                            //sequenceManager.Update(sequenceEntity);该方法调用不成,所以使用了下面调用服务方法更新,待优化
                            int rowCount = DotNetService.Instance.SequenceService.Update(UserInfo, sequenceEntity, out statusCode, out statusMessage);
                        }
                        else
                        {
                            MessageBox.Show(AppMessage.Format(AppMessage.MSG0018, "BaseSequence"), AppMessage.MSG0020, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            return returnValue;
                        }
                    }
                }
            }

            // 被选中记录中被设置隐藏的次数
            returnValue = selectedCount > 0;
            if (!returnValue)
            {
                MessageBox.Show(AppMessage.MSG0024, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            return returnValue;
        }
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="baseSequenceEntity">实体</param>
 /// <returns>主键</returns>
 public string Add(BaseSequenceEntity baseSequenceEntity)
 {
     return this.AddEntity(baseSequenceEntity);
 }
 /// <summary>
 /// 加载窗体
 /// </summary>
 public override void FormOnLoad()
 {
     this.SequenceEntity = DotNetService.Instance.SequenceService.GetEntity(UserInfo, this.EntityId);
     // 显示内容
     this.ShowEntity(this.SequenceEntity);
     // 设置焦点
     this.ActiveControl = this.txtFullName;
     this.txtFullName.Focus();
 }
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="baseSequenceEntity">实体</param>
 /// <param name="identity">自增量方式</param>
 /// <param name="returnId">返回主键</param>
 /// <returns>主键</returns>
 public string Add(BaseSequenceEntity baseSequenceEntity, bool identity, bool returnId)
 {
     this.Identity = identity;
     this.ReturnId = returnId;
     return this.AddEntity(baseSequenceEntity);
 }
 /// <summary>
 /// 显示内容
 /// </summary>
 private void ShowEntity(BaseSequenceEntity sequenceEntity)
 {
     this.txtFullName.Text = sequenceEntity.FullName;
     this.txtPrefix.Text = sequenceEntity.Prefix;
     this.txtSeparator.Text = sequenceEntity.Separator;
     this.txtSequence.Text = sequenceEntity.Sequence.ToString();
     this.txtReduction.Text = sequenceEntity.Reduction.ToString();
     this.txtStep.Text = sequenceEntity.Step.ToString();
     this.txtDescription.Text = sequenceEntity.Description;
     this.chkEnabled.Checked = sequenceEntity.IsVisible == 1 ? true : false;
 }
 /// <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;
 }