示例#1
0
        /// <summary>
        /// 登陆验证,返回验证结果
        /// 登陆成功:返回LoginResult.Succeed的枚举,同时返回对应的User
        /// 登陆失败:返回 LoginResult.UserIDError或LoginResult.PwdError的枚举,并且返回User为null
        /// </summary>
        /// <param name="strID">帐号</param>
        /// <param name="strPWD">密码</param>
        /// <param name="user">用户对象(帐号或密码错误,返回null)</param>
        /// <returns></returns>
        public static LoginResult Login(string strID, string strPWD, out User user)
        {
            ViewUser vwUser = new ViewUser(true);
            LoginResult emStatus = LoginResult.UserIDError;
            user = null;
            vwUser.BaseCondition = "a.UserID='" + strID + "'";
            switch (vwUser.Count)
            {
                case 0:
                    break;

                case 1:
                    user = vwUser.GetItem(0) as User;
                    if (user.PWD.Equals(strPWD, StringComparison.CurrentCultureIgnoreCase))//密码正确
                    {
                        emStatus = LoginResult.Succeed;
                    }
                    else
                    {
                        user = null;
                        emStatus = LoginResult.PwdError;
                    }
                    break;

                default:
                    throw (new Exception("存在多个帐号相同的用户"));
            }
            return emStatus;
        }
        /// <summary>
        /// 设置领导和负责人
        /// </summary>
        /// <param name="mType">领导或负责人枚举</param>
        /// <param name="strIDs">用户IDs</param>
        /// <param name="bSetOrReset">取消或者设置</param>
        /// <param name="strMessage">错误消息</param>
        /// <returns></returns>
        public static bool SetUserLeaderType(Common.LeaderType mType, List<string> strIDs, bool bSetOrReset,out string strMessage)
        {
            bool bRet = false;
            strMessage = string.Empty;
            DeptPost dp = new DeptPost();
            User user = new User();
            ViewDeptPost v_dp = new ViewDeptPost();
            dp.EnTrans.Begin();
            dp.EnTrans.IsBatch = true;
            foreach (string strID in strIDs)
            {
                if (strID.Length == 0) continue;
                bRet = dp.Load(Convert.ToInt32(strID));

                if (mType == Common.LeaderType.Manager && bSetOrReset)
                {
                    v_dp.EnTrans = dp.EnTrans;
                    v_dp.Field = "a.ID";
                    v_dp.Condition = " FK_DeptID = " + dp.FK_DeptID + " and LeaderType in (" + (int)Common.LeaderType.Manager + "," + (int)Common.LeaderType.LeaderAndManager + ")";

                    if (v_dp.DtTable != null)
                    {
                        if (v_dp.DtTable.Rows.Count > 0)
                        {
                            user.EnTrans = dp.EnTrans;
                            user.Load(dp.FK_UserID);
                            bRet = false;
                            strMessage = string.Format("({0})所在的部门以存在负责人",user.Name);
                            return bRet;
                        }
                    }
                }
                if (dp.LeaderType == int.MinValue)
                {
                    dp.LeaderType = 0;
                }
                if (bSetOrReset)
                {
                    dp.LeaderType |= (int)mType;
                }
                else
                {
                    if (dp.LeaderType == (int)mType || (dp.LeaderType == ((int)(Common.LeaderType.Leader | Common.LeaderType.Manager))))
                    {
                        dp.LeaderType ^= (int)mType;
                    }
                }
                bRet = dp.Save();
            }
            dp.EnTrans.Commit();
            return bRet;
        }