Beispiel #1
0
        /// <summary>
        /// 员工关联用户
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="staffId">员工主键</param>
        /// <param name="userId">用户主键</param>
        /// <returns>影响行数</returns>
        public int SetStaffUser(BaseUserInfo userInfo, string staffId, string userId)
        {
            var result = 0;

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

            ServiceUtil.ProcessUserCenterReadDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BaseStaffManager(dbHelper, userInfo);
                if (ValidateUtil.IsInt(userId))
                {
                    result = manager.SetProperty(staffId, new KeyValuePair <string, object>(BaseStaffEntity.FieldUserId, userId));
                }
                else
                {
                    // 一个用户只能帮定到一个帐户上,检查是否已经绑定过这个用户了。
                    var staffIds = manager.GetIds(new KeyValuePair <string, object>(BaseStaffEntity.FieldUserId, userId), new KeyValuePair <string, object>(BaseStaffEntity.FieldDeleted, 0));
                    if (staffIds == null || staffIds.Length == 0)
                    {
                        result          = manager.SetProperty(staffId, new KeyValuePair <string, object>(BaseStaffEntity.FieldUserId, userId));
                        var userManager = new BaseUserManager(dbHelper, userInfo);
                        var userEntity  = userManager.GetEntity(userId);
                        result          = manager.SetProperty(staffId, new KeyValuePair <string, object>(BaseStaffEntity.FieldUserName, userEntity.UserName));
                    }
                }
            });
            return(result);
        }
 public string[] GetUserIds(string organizeId)
 {
     // 要注意不能重复发信息,只能发一次。
     string[] companyUsers    = null; // 按公司查找用户
     string[] departmentUsers = null; // 按部门查找用户
     string[] workgroupUsers  = null; // 按工作组查找用户
     if (!String.IsNullOrEmpty(organizeId))
     {
         // 这里获得的是用户主键,不是员工主键
         BaseStaffManager staffManager = new BaseStaffManager(DbHelper);
         companyUsers    = staffManager.GetIds(new KeyValuePair <string, object>(BaseStaffEntity.FieldCompanyId, organizeId));
         departmentUsers = staffManager.GetIds(new KeyValuePair <string, object>(BaseStaffEntity.FieldDepartmentId, organizeId));
         workgroupUsers  = staffManager.GetIds(new KeyValuePair <string, object>(BaseStaffEntity.FieldWorkgroupId, organizeId));
     }
     string[] userIds = StringUtil.Concat(companyUsers, departmentUsers, workgroupUsers);
     return(userIds);
 }
Beispiel #3
0
        /// <summary>
        /// 员工关联用户
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="staffId">员工主键</param>
        /// <param name="userId">用户主键</param>
        /// <returns>影响行数</returns>
        public int SetStaffUser(BaseUserInfo userInfo, string staffId, string userId)
        {
            // 写入调试信息
            #if (DEBUG)
            int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

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

            int returnValue = 0;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseStaffManager staffManager = new BaseStaffManager(dbHelper, userInfo);
                    if (string.IsNullOrEmpty(userId))
                    {
                        returnValue = staffManager.SetProperty(staffId, new KeyValuePair <string, object>(BaseStaffEntity.FieldUserId, userId));
                    }
                    else
                    {
                        // 一个用户只能帮定到一个帐户上,检查是否已经绑定过这个用户了。
                        string[] staffIds = staffManager.GetIds(new KeyValuePair <string, object>(BaseStaffEntity.FieldUserId, userId), new KeyValuePair <string, object>(BaseStaffEntity.FieldDeletionStateCode, 0));
                        if (staffIds == null || staffIds.Length == 0)
                        {
                            returnValue = staffManager.SetProperty(staffId, new KeyValuePair <string, object>(BaseStaffEntity.FieldUserId, userId));
                            BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                            BaseUserEntity  userEntity  = userManager.GetEntity(userId);
                            returnValue = staffManager.SetProperty(staffId, new KeyValuePair <string, object>(BaseStaffEntity.FieldUserName, userEntity.UserName));
                        }
                    }
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.StaffService_SetStaffUser, 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);
        }