Esempio n. 1
0
        public User GetUserByItCodeWithRole(string itcode)
        {
            User user = UserDa.GetUserByItCode(itcode);

            user.Roles.AddRange(UserDa.GetUserRole(user.ItCode, null, null));

            return(user);
        }
Esempio n. 2
0
        public void SetDelgate(string itcode, string delegateItcode)
        {
            User user = UserDa.GetUserByItCode(itcode);

            if (user == null)
            {
                throw new BusinessObjectLogicException("Invalid input!");
            }

            if (String.IsNullOrEmpty(delegateItcode))
            {
                delegateItcode = itcode;                                        // 处理输入
            }
            if (user.DelegateUser == delegateItcode)
            {
                return;                                       // 无实际操作
            }
            if (itcode != delegateItcode)
            {
                User delegateUser = UserDa.GetUserByItCode(delegateItcode);         // 验证输入
                if (delegateUser == null)
                {
                    throw new BusinessObjectLogicException("Invalid delegate user!");
                }
            }


            user.DelegateUser = delegateItcode;

            string title   = null;
            string body    = null;
            string toUser  = null;
            string ccUsers = null;
            string domain  = "@" + Utils.SysDomain();

            if (user.ItCode == delegateItcode)
            {
                // 取消授权

                title  = "TQMP Authorization notice";
                body   = "The authorization from " + user.ItCode + " is canceled.";
                toUser = delegateItcode + domain;
            }
            else
            {
                // 设置授权

                title  = "TQMP Authorization notice";
                body   = "The approval operation is authorized to " + delegateItcode + ".";
                toUser = delegateItcode + domain;
            }

            UserDa.UpdateUserDelegate(itcode, delegateItcode);

            new Mail.MailBl().SendMail(toUser, ccUsers, title, body, System.Net.Mail.MailPriority.Normal, null);
        }
Esempio n. 3
0
        public List <User> GetUserByItCodesWithOrganFullTitle(params string[] itcodes)
        {
            // Dictionary<Guid, Organ> organsDic = new OrganBl().GetOrganTreeDic(null);
            List <User> users = UserDa.GetUserByItCode(itcodes);

            //foreach (User user in users)
            //    user.Organ.Title = organsDic[user.Organ.ID].GetFullTitle();

            return(users);
        }
Esempio n. 4
0
        public void SendPassword(string itcode)
        {
            User existUser = UserDa.GetUserByItCode(itcode);

            if (existUser == null)
            {
                throw new BusinessObjectLogicException("Invalid User!");
            }


            new Mail.MailBl().SendMail(Message.ConvertMailAddress(existUser.ItCode), null, "Hi, Your TQMP System Password",
                                       "Your password is : " + existUser.Password + Utils.GetSysStatement(), System.Net.Mail.MailPriority.Normal);
        }
Esempio n. 5
0
        /// <summary>
        /// 更新用户信息,可以更改用户密码
        /// </summary>
        /// <param name="user"></param>
        public void EditUserInfo(string itcode, string password, string firstname, string lastname, string phone)
        {
            User existUser = UserDa.GetUserByItCode(itcode);

            if (existUser == null)
            {
                throw new BusinessObjectLogicException("Invalid User!");
            }
            if (existUser.Disabled)
            {
                throw new BusinessObjectLogicException("User is disabled!");
            }

            if (!String.IsNullOrEmpty(password))
            {
                existUser.Password = password;
            }
            existUser.FirstName = firstname;
            existUser.LastName  = lastname;
            existUser.Phone     = phone;


            UserDa.UpdateUser(existUser);
        }
Esempio n. 6
0
 public List <User> GetUserByItCodes(params string[] itcodes)
 {
     return(UserDa.GetUserByItCode(itcodes));
 }
Esempio n. 7
0
 public User GetUserByItCode(string itcode)
 {
     return(UserDa.GetUserByItCode(itcode));
 }
Esempio n. 8
0
        public void EditUser(User user)
        {
            User existUser = UserDa.GetUserByItCode(user.ItCode);

            existUser.Roles.AddRange(UserDa.GetUserRole(existUser.ItCode, null, null));

            if (user == null)
            {
                throw new BusinessObjectLogicException("Invalid User!");
            }
            if (user.Organ == null)
            {
                throw new BusinessObjectLogicException("Invalid Organ!");
            }
            if (user.Superior == null)
            {
                throw new BusinessObjectLogicException("Invalid Manager!");
            }
            if (user.Disabled && existUser.Disabled)
            {
                throw new BusinessObjectLogicException("User is disabled!");
            }

            bool updateUser = false;

            if (existUser.FirstName != user.FirstName ||
                existUser.LastName != user.LastName ||
                existUser.AbbrName != user.AbbrName ||
                existUser.Organ.ID != user.Organ.ID ||
                existUser.Superior.ItCode != user.Superior.ItCode ||
                existUser.Phone != user.Phone ||
                existUser.Disabled != user.Disabled ||
                existUser.Department != user.Department)
            {
                existUser.FirstName  = user.FirstName;
                existUser.LastName   = user.LastName;
                existUser.AbbrName   = user.AbbrName;
                existUser.Organ      = user.Organ;
                existUser.Superior   = user.Superior;
                existUser.Phone      = user.Phone;
                existUser.Disabled   = user.Disabled;
                existUser.Department = user.Department;

                updateUser = true;
            }

            List <UserRole> rolesAdd = new List <UserRole>();
            List <UserRole> rolesDel = new List <UserRole>();

            //foreach (UserRole role in existUser.Roles)
            //{
            //    if (!user.Roles.Exists(r => (r.Role == role.Role && r.BU == role.BU)))
            //        rolesDel.Add(role);
            //    //if (!user.Roles.Exists(delegate(UserRole r) { return r.Role == role.Role && r.BU == role.BU; }))
            //    //{ }
            //}
            //foreach (UserRole role in user.Roles)
            //{
            //    if (!existUser.Roles.Exists(r => (r.Role == role.Role && r.BU == role.BU)))
            //        rolesAdd.Add(role);
            //}

            // 如果没有实际更改
            if (!updateUser && rolesAdd.Count == 0 && rolesDel.Count == 0)
            {
                return;
            }

            using (TranscationHelper trans = TranscationHelper.GetInstance())
            {
                trans.BeginTrans();
                try
                {
                    if (updateUser)
                    {
                        UserDa.UpdateUser(existUser, trans);
                    }

                    foreach (UserRole role in rolesDel)
                    {
                        UserDa.DeleteUserRole(role, trans);
                    }
                    foreach (UserRole role in rolesAdd)
                    {
                        UserDa.InsertUserRole(role, trans);
                    }

                    trans.CommitTrans();
                }
                catch
                {
                    trans.RollTrans();
                    throw;
                }
            }
        }