コード例 #1
0
        public string Add(BaseOrganizeEntity organizeEntity, out string statusCode)
        {
            string returnValue = string.Empty;
            // 检查是否重复
            List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
            parameters.Add(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldParentId, organizeEntity.ParentId));
            parameters.Add(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldFullName, organizeEntity.FullName));
            parameters.Add(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldDeletionStateCode, 0));

            //注意Access 的时候,类型不匹配,会出错故此将 ID 传入
            if (BaseSystemInfo.UserCenterDbType == DbTypes.Access)
            {
                if (this.Exists(parameters, organizeEntity.Id))
                {
                    // 名称已重复
                    statusCode = StatusCode.ErrorNameExist.ToString();
                }
                else
                {
                    parameters = new List<KeyValuePair<string, object>>();
                    parameters.Add(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldCode, organizeEntity.Code));
                    parameters.Add(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldDeletionStateCode, 0));
                    if (organizeEntity.Code.Length > 0 && this.Exists(parameters))
                    {
                        // 编号已重复
                        statusCode = StatusCode.ErrorCodeExist.ToString();
                    }
                    else
                    {
                        returnValue = this.AddEntity(organizeEntity);
                        // 运行成功
                        statusCode = StatusCode.OKAdd.ToString();
                    }
                }
            }
            else if (this.Exists(parameters))
            {
                // 名称已重复
                statusCode = StatusCode.ErrorNameExist.ToString();
            }
            else
            {
                parameters = new List<KeyValuePair<string, object>>();
                parameters.Add(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldCode, organizeEntity.Code));
                parameters.Add(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldDeletionStateCode, 0));
                if (organizeEntity.Code.Length > 0 && this.Exists(parameters))
                {
                    // 编号已重复
                    statusCode = StatusCode.ErrorCodeExist.ToString();
                }
                else
                {
                    returnValue = this.AddEntity(organizeEntity);
                    // 运行成功
                    statusCode = StatusCode.OKAdd.ToString();
                }
            }
            return returnValue;
        }
コード例 #2
0
        /// <summary>
        /// 添加实体
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="organizeEntity">实体</param>
        /// <param name="statusCode">状态码</param>
        /// <param name="statusMessage">状态信息</param>
        /// <returns>主键</returns>
        public string Add(BaseUserInfo userInfo, BaseOrganizeEntity organizeEntity, 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;
            string returnValue = string.Empty;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseOrganizeManager organizeManager = new BaseOrganizeManager(dbHelper, userInfo);
                    returnValue = organizeManager.Add(organizeEntity, out statusCode);
                    statusMessage = organizeManager.GetStateMessage(statusCode);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.OrganizeService_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;
        }
コード例 #3
0
        public int Update(BaseOrganizeEntity organizeEntity, out string statusCode)
        {
            int returnValue = 0;
            // 检查是否已被其他人修改
            //if (DbLogic.IsModifed(DbHelper, BaseOrganizeEntity.TableName, organizeEntity.Id, organizeEntity.ModifiedUserId, organizeEntity.ModifiedOn))
            //{
            //    // 数据已经被修改
            //    statusCode = StatusCode.ErrorChanged.ToString();
            //}
            //else
            //{

            List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
            parameters.Add(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldParentId, organizeEntity.ParentId));
            parameters.Add(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldFullName, organizeEntity.FullName));
            parameters.Add(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldDeletionStateCode, 0));

            if (this.Exists(parameters, organizeEntity.Id))
            {
                // 名称已重复
                statusCode = StatusCode.ErrorNameExist.ToString();
            }
            else
            {
                // 检查编号是否重复
                parameters = new List<KeyValuePair<string, object>>();
                parameters.Add(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldCode, organizeEntity.Code));
                parameters.Add(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldDeletionStateCode, 0));

                if (organizeEntity.Code.Length > 0 && this.Exists(parameters, organizeEntity.Id))
                {
                    // 编号已重复
                    statusCode = StatusCode.ErrorCodeExist.ToString();
                }
                else
                {
                    // 1:更新部门的信息
                    returnValue = this.UpdateEntity(organizeEntity);
                    // 2:组织机构修改时,用户表的公司,部门,工作组数据给同步更新。
                    BaseUserManager userManager = new BaseUserManager(this.DbHelper, this.UserInfo);
                    userManager.SetProperty(new KeyValuePair<string, object>(BaseUserEntity.FieldCompanyId, organizeEntity.Id), new KeyValuePair<string, object>(BaseUserEntity.FieldCompanyName, organizeEntity.FullName));
                    userManager.SetProperty(new KeyValuePair<string, object>(BaseUserEntity.FieldDepartmentId, organizeEntity.Id), new KeyValuePair<string, object>(BaseUserEntity.FieldDepartmentName, organizeEntity.FullName));
                    userManager.SetProperty(new KeyValuePair<string, object>(BaseUserEntity.FieldWorkgroupId, organizeEntity.Id), new KeyValuePair<string, object>(BaseUserEntity.FieldWorkgroupName, organizeEntity.FullName));
                    // 03:组织机构修改时,文件夹同步更新
                    BaseFolderManager folderManager = new BaseFolderManager(this.DbHelper, this.UserInfo);
                    folderManager.SetProperty(new KeyValuePair<string, object>(BaseFolderEntity.FieldFolderName, organizeEntity.FullName), new KeyValuePair<string, object>(BaseFolderEntity.FieldId, organizeEntity.Id));
                    if (returnValue == 1)
                    {
                        statusCode = StatusCode.OKUpdate.ToString();
                    }
                    else
                    {
                        statusCode = StatusCode.ErrorDeleted.ToString();
                    }
                }
            }
            //}
            return returnValue;
        }
コード例 #4
0
 public override int BatchSave(DataTable dataTable)
 {
     int returnValue = 0;
     BaseOrganizeEntity organizeEntity = new BaseOrganizeEntity();
     foreach (DataRow dataRow in dataTable.Rows)
     {
         // 删除状态
         if (dataRow.RowState == DataRowState.Deleted)
         {
             string id = dataRow[BaseOrganizeEntity.FieldId, DataRowVersion.Original].ToString();
             if (id.Length > 0)
             {
                 returnValue += this.DeleteEntity(id);
             }
         }
         // 被修改过
         if (dataRow.RowState == DataRowState.Modified)
         {
             string id = dataRow[BaseOrganizeEntity.FieldId, DataRowVersion.Original].ToString();
             if (id.Length > 0)
             {
                 organizeEntity.GetFrom(dataRow);
                 returnValue += this.UpdateEntity(organizeEntity);
             }
         }
         // 添加状态
         if (dataRow.RowState == DataRowState.Added)
         {
             organizeEntity.GetFrom(dataRow);
             returnValue += this.AddEntity(organizeEntity).Length > 0 ? 1 : 0;
         }
         if (dataRow.RowState == DataRowState.Unchanged)
         {
             continue;
         }
         if (dataRow.RowState == DataRowState.Detached)
         {
             continue;
         }
     }
     return returnValue;
 }
コード例 #5
0
 public string AddByDetail(string parentId, string code, string fullName, string category, string outerPhone, string innerPhone, string fax, bool enabled, out string statusCode)
 {
     BaseOrganizeEntity organizeEntity = new BaseOrganizeEntity();
     organizeEntity.ParentId = parentId;
     organizeEntity.Code = code;
     organizeEntity.FullName = fullName;
     organizeEntity.Category = category;
     organizeEntity.OuterPhone = outerPhone;
     organizeEntity.InnerPhone = innerPhone;
     organizeEntity.Fax = fax;
     organizeEntity.Enabled = enabled ? 1 : 0;
     return this.Add(organizeEntity, out statusCode);
 }
コード例 #6
0
ファイル: FrmOrganizeAdd.cs プロジェクト: huoxudong125/DotNet
 public FrmOrganizeAdd(BaseOrganizeEntity entity)
     : this()
 {
     this.organizeEntity = entity;
 }
コード例 #7
0
ファイル: FrmOrganizeAdd.cs プロジェクト: huoxudong125/DotNet
 /// <summary>
 /// 转换数据,将实体类保存到数据表
 /// </summary>
 private BaseOrganizeEntity GetEntity()
 {
     BaseOrganizeEntity entity = new BaseOrganizeEntity();
     if (string.IsNullOrEmpty(this.ucParent.SelectedId))
     {
         entity.ParentId = null;
     }
     else
     {
         entity.ParentId = this.ucParent.SelectedId;
     }
     entity.Code = this.txtCode.Text;
     entity.FullName = this.txtFullName.Text;
     entity.ShortName = this.txtShortName.Text;
     entity.Category = this.cmbCategory.SelectedValue.ToString();
     entity.OuterPhone = this.txtOuterPhone.Text;
     entity.InnerPhone = this.txtInnerPhone.Text;
     entity.Fax = this.txtFax.Text;
     entity.Postalcode = this.txtPostalcode.Text;
     entity.Address = this.txtAddress.Text;
     entity.Web = this.txtWeb.Text;
     entity.Enabled = this.chkEnabled.Checked ? 1 : 0;
     entity.IsInnerOrganize = this.chkIsInnerOrganize.Checked ? 1 : 0;
     entity.Description = this.txtDescription.Text;
     entity.DeletionStateCode = 0;
     return entity;
 }
コード例 #8
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="organizeEntity">实体</param>
 /// <param name="identity">自增量方式</param>
 /// <param name="returnId">返回主鍵</param>
 /// <returns>主键</returns>
 public string Add(BaseOrganizeEntity organizeEntity, bool identity, bool returnId)
 {
     this.Identity = identity;
     this.ReturnId = returnId;
     return this.AddEntity(organizeEntity);
 }
コード例 #9
0
ファイル: FrmMessage.cs プロジェクト: huoxudong125/DotNet
 /// <summary>
 /// 加载树型结构的主键
 /// </summary>
 /// <param name="dataTable">数据表</param>
 /// <param name="fieldId">主键</param>
 /// <param name="fieldParentId">上级字段</param>
 /// <param name="fieldFullName">全称</param>
 /// <param name="treeNode">当前树结点</param>
 private void LoadTreeNodes(DataTable dataTable, string fieldId, string fieldParentId, string fieldFullName, TreeView treeView, TreeNode treeNode, bool loadTree = true)
 {
     BaseOrganizeEntity organizeEntity = new BaseOrganizeEntity();
     // 查找 ParentId 字段的值是否在 Id字段 里
     // 一般情况是简单的数据过滤,就没必要进行严格的检查了,进行了严格的检查,反而降低运行效率
     DataRow[] dataRows = null;
     if (treeNode.Tag == null)
     {
         if (dataTable.Columns[fieldId].DataType == typeof(int)
             || (dataTable.Columns[fieldId].DataType == typeof(Int16))
             || (dataTable.Columns[fieldId].DataType == typeof(Int32))
             || (dataTable.Columns[fieldId].DataType == typeof(Int64))
             || dataTable.Columns[fieldId].DataType == typeof(decimal))
         {
             dataRows = dataTable.Select(fieldParentId + " IS NULL OR " + fieldParentId + " = 0");
         }
         else
         {
             dataRows = dataTable.Select(fieldParentId + " IS NULL OR " + fieldParentId + " = ''");
         }
     }
     else
     {
         dataRows = dataTable.Select(fieldParentId + "=" + ((BaseOrganizeEntity)treeNode.Tag).Id.ToString());
     }
     foreach (DataRow dataRow in dataRows)
     {
         // 节点不为空,并且是当前节点的子节点
         if ((treeNode.Tag != null) && !(((BaseOrganizeEntity)treeNode.Tag).Id.ToString().Equals(dataRow[fieldParentId].ToString())))
         {
             continue;
         }
         // 当前节点的子节点, 加载根节点
         if (dataRow.IsNull(fieldParentId)
             || (dataRow[fieldParentId].ToString() == "0")
             || (dataRow[fieldParentId].ToString().Length == 0)
             || ((treeNode.Tag != null) && (((BaseOrganizeEntity)treeNode.Tag).Id.ToString().Equals(dataRow[fieldParentId].ToString()))))
         {
             TreeNode newTreeNode = new TreeNode();
             newTreeNode.Text = dataRow[fieldFullName].ToString();
             newTreeNode.Tag = new BaseOrganizeEntity(dataRow);
             if ((treeNode.Tag == null))
             {
                 // 树的根节点加载
                 treeView.Nodes.Add(newTreeNode);
             }
             else
             {
                 // 节点的子节点加载,第一层节点需要展开
                 treeNode.Nodes.Add(newTreeNode);
             }
             if (loadTree)
             {
                 // 递归调用本函数
                 LoadTreeNodes(dataTable, fieldId, fieldParentId, fieldFullName, treeView, newTreeNode, loadTree);
             }
         }
     }
 }
コード例 #10
0
partial         void SetEntityExpand(SQLBuilder sqlBuilder, BaseOrganizeEntity organizeEntity);
コード例 #11
0
 /// <summary>
 /// 设置实体
 /// </summary>
 /// <param name="organizeEntity">实体</param>
 private void SetEntity(SQLBuilder sqlBuilder, BaseOrganizeEntity organizeEntity)
 {
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldParentId, organizeEntity.ParentId);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldCode, organizeEntity.Code);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldShortName, organizeEntity.ShortName);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldFullName, organizeEntity.FullName);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldCategory, organizeEntity.Category);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldOuterPhone, organizeEntity.OuterPhone);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldInnerPhone, organizeEntity.InnerPhone);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldFax, organizeEntity.Fax);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldPostalcode, organizeEntity.Postalcode);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldAddress, organizeEntity.Address);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldWeb, organizeEntity.Web);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldIsInnerOrganize, organizeEntity.IsInnerOrganize);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldBank, organizeEntity.Bank);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldBankAccount, organizeEntity.BankAccount);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldDeletionStateCode, organizeEntity.DeletionStateCode);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldEnabled, organizeEntity.Enabled);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldSortCode, organizeEntity.SortCode);
     sqlBuilder.SetValue(BaseOrganizeEntity.FieldDescription, organizeEntity.Description);
     SetEntityExpand(sqlBuilder, organizeEntity);
 }
コード例 #12
0
 /// <summary>
 /// 更新实体
 /// </summary>
 /// <param name="organizeEntity">实体</param>
 public int UpdateEntity(BaseOrganizeEntity organizeEntity)
 {
     SQLBuilder sqlBuilder = new SQLBuilder(DbHelper);
     sqlBuilder.BeginUpdate(this.CurrentTableName);
     this.SetEntity(sqlBuilder, organizeEntity);
     if (UserInfo != null)
     {
         sqlBuilder.SetValue(BaseOrganizeEntity.FieldModifiedUserId, UserInfo.Id);
         sqlBuilder.SetValue(BaseOrganizeEntity.FieldModifiedBy, UserInfo.RealName);
     }
     sqlBuilder.SetDBNow(BaseOrganizeEntity.FieldModifiedOn);
     sqlBuilder.SetWhere(BaseOrganizeEntity.FieldId, organizeEntity.Id);
     return sqlBuilder.EndUpdate();
 }
コード例 #13
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="organizeEntity">实体</param>
 public int Update(BaseOrganizeEntity organizeEntity)
 {
     return this.UpdateEntity(organizeEntity);
 }
コード例 #14
0
 /// <summary>
 /// 获取实体
 /// </summary>
 /// <param name="id">主键</param>
 public BaseOrganizeEntity GetEntity(string id)
 {
     BaseOrganizeEntity organizeEntity = new BaseOrganizeEntity(this.GetDataTable(new KeyValuePair<string, object>(BaseOrganizeEntity.FieldId, id)));
     return organizeEntity;
 }
コード例 #15
0
 /// <summary>
 /// 添加实体
 /// </summary>
 /// <param name="organizeEntity">实体</param>
 public string AddEntity(BaseOrganizeEntity organizeEntity)
 {
     string sequence = string.Empty;
     if (organizeEntity.SortCode == 0)
     {
         BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
         sequence = sequenceManager.GetSequence(this.CurrentTableName);
         organizeEntity.SortCode = int.Parse(sequence);
     }
     SQLBuilder sqlBuilder = new SQLBuilder(DbHelper, this.Identity, this.ReturnId);
     sqlBuilder.BeginInsert(this.CurrentTableName, BaseOrganizeEntity.FieldId);
     if (!this.Identity)
     {
         sqlBuilder.SetValue(BaseOrganizeEntity.FieldId, organizeEntity.Id);
     }
     else
     {
         if (!this.ReturnId && (DbHelper.CurrentDbType == DbTypes.Oracle || DbHelper.CurrentDbType == DbTypes.DB2))
         {
             if (DbHelper.CurrentDbType == DbTypes.Oracle)
             {
                 sqlBuilder.SetFormula(BaseOrganizeEntity.FieldId, "SEQ_" + this.CurrentTableName.ToUpper() + ".NEXTVAL ");
             }
             if (DbHelper.CurrentDbType == DbTypes.DB2)
             {
                 sqlBuilder.SetFormula(BaseOrganizeEntity.FieldId, "NEXT VALUE FOR SEQ_" + this.CurrentTableName.ToUpper());
             }
         }
         else
         {
             if (this.Identity && (DbHelper.CurrentDbType == DbTypes.Oracle || DbHelper.CurrentDbType == DbTypes.DB2))
             {
                 if (organizeEntity.Id == null)
                 {
                     if (string.IsNullOrEmpty(sequence))
                     {
                         BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper, this.Identity);
                         sequence = sequenceManager.GetSequence(this.CurrentTableName);
                     }
                     organizeEntity.Id = int.Parse(sequence);
                 }
                 sqlBuilder.SetValue(BaseOrganizeEntity.FieldId, organizeEntity.Id);
             }
         }
     }
     this.SetEntity(sqlBuilder, organizeEntity);
     if (UserInfo != null)
     {
         sqlBuilder.SetValue(BaseOrganizeEntity.FieldCreateUserId, UserInfo.Id);
         sqlBuilder.SetValue(BaseOrganizeEntity.FieldCreateBy, UserInfo.RealName);
     }
     sqlBuilder.SetDBNow(BaseOrganizeEntity.FieldCreateOn);
     if (UserInfo != null)
     {
         sqlBuilder.SetValue(BaseOrganizeEntity.FieldModifiedUserId, UserInfo.Id);
         sqlBuilder.SetValue(BaseOrganizeEntity.FieldModifiedBy, UserInfo.RealName);
     }
     sqlBuilder.SetDBNow(BaseOrganizeEntity.FieldModifiedOn);
     if (DbHelper.CurrentDbType == DbTypes.SqlServer && this.Identity)
     {
         sequence = sqlBuilder.EndInsert().ToString();
     }
     else
     {
         sqlBuilder.EndInsert();
     }
     return sequence;
 }
コード例 #16
0
 /// <summary>
 /// 加载窗体
 /// </summary>
 public override void FormOnLoad()
 {
     // 组织机构信息
     this.organizeEntity = DotNetService.Instance.OrganizeService.GetEntity(UserInfo, this.EntityId);
     // 绑定下拉筐数据
     this.BindItemDetails();
     // 显示内容
     this.ShowEntity();
     // 获取岗位信息
     this.GetRoleUser();
     // 设置焦点
     this.ActiveControl = this.txtFullName;
     this.txtCode.Focus();
 }
コード例 #17
0
        /// <summary>
        /// 设置实体
        /// </summary>
        /// <param name="organizeEntity">实体</param>
partial         void SetEntityExpand(SQLBuilder sqlBuilder, BaseOrganizeEntity organizeEntity)
        {
            sqlBuilder.SetValue(BaseOrganizeEntity.FieldLayer, organizeEntity.Layer);
        }
コード例 #18
0
 /// <summary>
 /// 添加
 /// </summary>
 /// <param name="organizeEntity">实体</param>
 /// <returns>主键</returns>
 public string Add(BaseOrganizeEntity organizeEntity)
 {
     return this.AddEntity(organizeEntity);
 }