Example #1
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="itemsEntity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <returns>主键</returns>
        public string Add(CiItemsEntity itemsEntity, out string statusCode)
        {
            var returnValue = string.Empty;

            // 检查编号是否重复
            if (this.Exists(CiItemsTable.FieldCode, itemsEntity.Code, CiItemsTable.FieldDeleteMark, 0))
            {
                // 编号已重复
                statusCode = StatusCode.ErrorCodeExist.ToString();
            }
            else
            {
                // 检查名称是否重复
                string[] names  = { CiItemsTable.FieldFullName, CiItemsTable.FieldCategory, CiItemsTable.FieldDeleteMark };
                object[] values = { itemsEntity.FullName, itemsEntity.Category, 0 };
                if (this.Exists(names, values))
                {
                    // 名称与分类已重复
                    statusCode = StatusCode.ErrorNameExist.ToString();
                }
                else
                {
                    returnValue = this.AddEntity(itemsEntity);
                    // 运行成功
                    statusCode = StatusCode.OKAdd.ToString();
                }
            }
            return(returnValue);
        }
Example #2
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="itemsEntity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <returns>影响行数</returns>
        public int Update(CiItemsEntity itemsEntity, out string statusCode)
        {
            var returnValue = 0;

            // 检查是否已被其他人修改
            //if (DbLogic.IsModifed(DBProvider, this.CurrentTableName, itemsEntity.Id, itemsEntity.ModifiedUserId, itemsEntity.ModifiedOn))
            //{
            //    // 数据已经被修改
            //    statusCode = StatusCode.ErrorChanged.ToString();
            //}
            //else
            //{
            // 检查编号是否重复
            if (this.Exists(CiItemsTable.FieldCode, itemsEntity.Code, itemsEntity.Id))
            {
                // 编号已重复
                statusCode = StatusCode.ErrorCodeExist.ToString();
            }
            else
            {
                // 检查名称是否重复
                if (this.Exists(CiItemsTable.FieldFullName, itemsEntity.FullName, CiItemsTable.FieldCategory, itemsEntity.Category, itemsEntity.Id))
                {
                    // 名称已重复
                    statusCode = StatusCode.ErrorNameExist.ToString();
                }
                else
                {
                    returnValue = this.UpdateEntity(itemsEntity);
                    statusCode  = returnValue == 1 ? StatusCode.OKUpdate.ToString() : StatusCode.ErrorDeleted.ToString();
                }
            }
            //}
            return(returnValue);
        }
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public CiItemsEntity GetEntity(UserInfo userInfo, string id)
        {
            CiItemsEntity itemsEntity = null;
            var           parameter   = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.ItemsService_GetEntity);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                var itemsManager = new CiItemsManager(dbProvider, userInfo);
                itemsEntity      = itemsManager.GetEntity(id);
            });
            return(itemsEntity);
        }
Example #4
0
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="itemsEntity">实体</param>
        public int UpdateEntity(CiItemsEntity itemsEntity)
        {
            var sqlBuilder = new SQLBuilder(DBProvider);

            sqlBuilder.BeginUpdate(this.CurrentTableName);
            this.SetEntity(sqlBuilder, itemsEntity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(CiItemsTable.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(CiItemsTable.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(CiItemsTable.FieldModifiedOn);
            sqlBuilder.SetWhere(CiItemsTable.FieldId, itemsEntity.Id);
            return(sqlBuilder.EndUpdate());
        }
Example #5
0
        /// <summary>
        /// 批量进行保存
        /// </summary>
        /// <param name="dataTable">数据表</param>
        /// <returns>影响行数</returns>
        public override int BatchSave(DataTable dataTable)
        {
            var returnValue = 0;
            var itemsEntity = new CiItemsEntity();

            foreach (DataRow dataRow in dataTable.Rows)
            {
                // 删除状态
                if (dataRow.RowState == DataRowState.Deleted)
                {
                    var id = dataRow[CiItemsTable.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0 && itemsEntity.AllowDelete == 1)
                    {
                        returnValue += this.Delete(id);
                    }
                }
                // 被修改过
                if (dataRow.RowState == DataRowState.Modified)
                {
                    var id = dataRow[CiItemsTable.FieldId, DataRowVersion.Original].ToString();
                    if (id.Length > 0)
                    {
                        itemsEntity.GetFrom(dataRow);
                        // 判断是否允许编辑
                        returnValue += itemsEntity.AllowEdit == 1
                                    ? this.UpdateEntity(itemsEntity)
                                    : this.SetProperty(itemsEntity.Id, CiItemsTable.FieldSortCode, itemsEntity.SortCode);// 不允许编辑,但是排序还是允许的
                    }
                }
                // 添加状态
                if (dataRow.RowState == DataRowState.Added)
                {
                    this.GetFrom(dataRow);
                    returnValue += this.AddEntity(itemsEntity).Length > 0 ? 1 : 0;
                }
                if (dataRow.RowState == DataRowState.Unchanged)
                {
                    continue;
                }
                if (dataRow.RowState == DataRowState.Detached)
                {
                    continue;
                }
            }
            return(returnValue);
        }
        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="itemsEntity">实体</param>
        /// <param name="statusCode">返回状态码</param>
        /// <param name="statusMessage">返回状态信息</param>
        /// <returns>数据表</returns>
        public int Update(UserInfo userInfo, CiItemsEntity itemsEntity, out string statusCode, out string statusMessage)
        {
            string returnCode    = string.Empty;
            string returnMessage = string.Empty;
            int    returnValue   = 0;
            var    parameter     = ParameterUtil.CreateWithMessage(userInfo, MethodBase.GetCurrentMethod(), this.serviceName, RDIFrameworkMessage.ItemsService_Update);

            ServiceUtil.ProcessRDIReadDb(userInfo, parameter, dbProvider =>
            {
                var itemsManager = new CiItemsManager(dbProvider, userInfo);
                returnValue      = itemsManager.Update(itemsEntity, out returnCode);
                returnMessage    = itemsManager.GetStateMessage(returnCode);
            });
            statusCode    = returnCode;
            statusMessage = returnMessage;
            return(returnValue);
        }
Example #7
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="sqlBuilder">SQL语句生成器</param>
 /// <param name="itemsEntity">实体</param>
 private void SetEntity(SQLBuilder sqlBuilder, CiItemsEntity itemsEntity)
 {
     sqlBuilder.SetValue(CiItemsTable.FieldParentId, itemsEntity.ParentId);
     sqlBuilder.SetValue(CiItemsTable.FieldCode, itemsEntity.Code);
     sqlBuilder.SetValue(CiItemsTable.FieldFullName, itemsEntity.FullName);
     sqlBuilder.SetValue(CiItemsTable.FieldCategory, itemsEntity.Category);
     sqlBuilder.SetValue(CiItemsTable.FieldTargetTable, itemsEntity.TargetTable);
     sqlBuilder.SetValue(CiItemsTable.FieldIsTree, itemsEntity.IsTree);
     sqlBuilder.SetValue(CiItemsTable.FieldUseItemCode, itemsEntity.UseItemCode);
     sqlBuilder.SetValue(CiItemsTable.FieldUseItemName, itemsEntity.UseItemName);
     sqlBuilder.SetValue(CiItemsTable.FieldUseItemValue, itemsEntity.UseItemValue);
     sqlBuilder.SetValue(CiItemsTable.FieldAllowEdit, itemsEntity.AllowEdit);
     sqlBuilder.SetValue(CiItemsTable.FieldAllowDelete, itemsEntity.AllowDelete);
     sqlBuilder.SetValue(CiItemsTable.FieldDeleteMark, itemsEntity.DeleteMark);
     sqlBuilder.SetValue(CiItemsTable.FieldDescription, itemsEntity.Description);
     sqlBuilder.SetValue(CiItemsTable.FieldEnabled, itemsEntity.Enabled);
     sqlBuilder.SetValue(CiItemsTable.FieldSortCode, itemsEntity.SortCode);
 }
Example #8
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="entity">实体</param>
 /// <returns>主键</returns>
 public string Add(CiItemsEntity entity)
 {
     return(this.AddEntity(entity));
 }
Example #9
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="entity">实体</param>
        public string AddEntity(CiItemsEntity entity)
        {
            var sequence = string.Empty;

            if (string.IsNullOrEmpty(entity.SortCode.ToString()) || entity.SortCode == 0)
            {
                var sequenceManager = new CiSequenceManager(DBProvider, this.Identity);
                sequence        = sequenceManager.GetSequence(this.CurrentTableName);
                entity.SortCode = int.Parse(sequence);
            }
            this.Identity = false;
            var sqlBuilder = new SQLBuilder(DBProvider, this.Identity, this.ReturnId);

            sqlBuilder.BeginInsert(this.CurrentTableName, CiItemsTable.FieldId);
            if (!this.Identity)
            {
                if (string.IsNullOrEmpty(entity.Id))
                {
                    sequence  = BusinessLogic.NewGuid();
                    entity.Id = sequence;
                }
                sqlBuilder.SetValue(CiItemsTable.FieldId, entity.Id);
            }
            else
            {
                if (!this.ReturnId && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2))
                {
                    if (DBProvider.CurrentDbType == CurrentDbType.Oracle)
                    {
                        sqlBuilder.SetFormula(CiItemsTable.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
                    }
                    if (DBProvider.CurrentDbType == CurrentDbType.DB2)
                    {
                        sqlBuilder.SetFormula(CiItemsTable.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper());
                    }
                }
                else
                {
                    if (this.Identity && (DBProvider.CurrentDbType == CurrentDbType.Oracle || DBProvider.CurrentDbType == CurrentDbType.DB2))
                    {
                        if (string.IsNullOrEmpty(sequence))
                        {
                            var sequenceManager = new CiSequenceManager(DBProvider, this.Identity);
                            sequence = sequenceManager.GetSequence(this.CurrentTableName);
                        }
                        entity.Id = sequence;
                        sqlBuilder.SetValue(CiItemsTable.FieldId, entity.Id);
                    }
                }
            }
            this.SetEntity(sqlBuilder, entity);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(CiItemsTable.FieldCreateUserId, UserInfo.Id);
                sqlBuilder.SetValue(CiItemsTable.FieldCreateBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(CiItemsTable.FieldCreateOn);
            if (UserInfo != null)
            {
                sqlBuilder.SetValue(CiItemsTable.FieldModifiedUserId, UserInfo.Id);
                sqlBuilder.SetValue(CiItemsTable.FieldModifiedBy, UserInfo.RealName);
            }
            sqlBuilder.SetDBNow(CiItemsTable.FieldModifiedOn);
            if (DBProvider.CurrentDbType == CurrentDbType.SqlServer && this.Identity)
            {
                sequence = sqlBuilder.EndInsert().ToString();
            }
            else
            {
                sqlBuilder.EndInsert();
            }
            return(sequence);
        }
Example #10
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="entity">实体</param>
 public int Update(CiItemsEntity entity)
 {
     return(this.UpdateEntity(entity));
 }
Example #11
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="entity">实体</param>
 /// <param name="identity">自增量方式</param>
 /// <param name="returnId">返回主鍵</param>
 /// <returns>主键</returns>
 public string Add(CiItemsEntity entity, bool identity, bool returnId)
 {
     this.Identity = identity;
     this.ReturnId = returnId;
     return(this.AddEntity(entity));
 }