Exemplo n.º 1
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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
 /// <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();
 }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
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);
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
 /// <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="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);
 }
Exemplo n.º 10
0
 /// <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);
 }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
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 DbTypes.Access:
                case DbTypes.MySql:
                case DbTypes.SqlServer:
                    BaseSequenceEntity sequenceEntity = this.GetEntityByAdd(fullName);
                    this.UpdateSequence(fullName, sequenceCount);
                    // 这里循环产生ID数组
                    returnValue = this.GetSequence(sequenceEntity, sequenceCount);
                    break;

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

                case DbTypes.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);
        }
Exemplo n.º 14
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());
        }
Exemplo n.º 15
0
        /// <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);
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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);
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
        /// <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);
        }
Exemplo n.º 20
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public BaseSequenceEntity GetEntity(BaseUserInfo userInfo, string id)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            BaseSequenceEntity sequenceEntity = null;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseSequenceManager sequenceManager = new BaseSequenceManager(dbHelper, userInfo);
                    sequenceEntity = sequenceManager.GetEntity(id);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.SequenceService_GetEntity, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
            BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif
            return(sequenceEntity);
        }
Exemplo n.º 21
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="baseSequenceEntity">实体</param>
 /// <returns>主键</returns>
 public string Add(BaseSequenceEntity baseSequenceEntity)
 {
     return(this.AddEntity(baseSequenceEntity));
 }
Exemplo n.º 22
0
 partial void SetEntityExpand(SQLBuilder sqlBuilder, BaseSequenceEntity sequenceEntity);
Exemplo n.º 23
0
        /// <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);
        }
Exemplo n.º 24
0
        /// <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);
        }
Exemplo n.º 25
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="baseSequenceEntity">实体</param>
 public int Update(BaseSequenceEntity baseSequenceEntity)
 {
     return(this.UpdateEntity(baseSequenceEntity));
 }
Exemplo n.º 26
0
        /// <summary>
        /// 获取倒序序列号
        /// </summary>
        /// <param name="fullName">序列名称</param>
        /// <param name="defaultSequence">默认序列值</param>
        /// <returns>序列号</returns>
        public string GetReduction(string fullName, int defaultSequence)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = Environment.TickCount;
            Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " :Begin: " + MethodBase.GetCurrentMethod().ReflectedType.Name + "." + MethodBase.GetCurrentMethod().Name);
            #endif

            BaseSequenceEntity sequenceEntity = null;

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

                switch (DbHelper.CurrentDbType)
                {
                case DbTypes.Access:
                case DbTypes.MySql:
                case DbTypes.SqlServer:
                    sequenceEntity = GetEntityByAdd(fullName);
                    this.UpdateReduction(fullName);
                    break;

                case DbTypes.Oracle:
                    if (DbHelper.InTransaction)
                    {
                        // 不可以影响别人的事务
                        sequenceEntity = this.GetSequenceByLock(fullName, defaultSequence);
                        if (this.ReturnStatusCode == StatusCode.LockOK.ToString())
                        {
                            if (this.UpdateReduction(fullName) > 0)
                            {
                                this.ReturnStatusCode = StatusCode.LockOK.ToString();
                            }
                            else
                            {
                                this.ReturnStatusCode = StatusCode.CanNotLock.ToString();
                            }
                        }
                    }
                    else
                    {
                        // 这里加锁机制。
                        try
                        {
                            // 开始事务
                            DbHelper.BeginTransaction();
                            this.ReturnStatusCode = StatusCode.CanNotLock.ToString();
                            sequenceEntity        = this.GetSequenceByLock(fullName, defaultSequence);
                            if (this.ReturnStatusCode == StatusCode.LockOK.ToString())
                            {
                                this.ReturnStatusCode = StatusCode.CanNotLock.ToString();
                                if (this.UpdateReduction(fullName) > 0)
                                {
                                    // 提交事务
                                    DbHelper.CommitTransaction();
                                    this.ReturnStatusCode = StatusCode.LockOK.ToString();
                                }
                                else
                                {
                                    // 回滚事务
                                    DbHelper.RollbackTransaction();
                                }
                            }
                            else
                            {
                                // 回滚事务
                                DbHelper.RollbackTransaction();
                            }
                        }
                        catch
                        {
                            // 回滚事务
                            DbHelper.RollbackTransaction();
                            this.ReturnStatusCode = StatusCode.CanNotLock.ToString();
                        }
                    }
                    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(GetReduction(sequenceEntity));
        }
Exemplo n.º 27
0
        /// <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);
        }
Exemplo n.º 28
0
 /// <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));
 }