Esempio n. 1
0
        /// <summary>
        /// 通过用户ID取用户信息
        /// </summary>
        /// <param name="_yhid"></param>
        /// <returns></returns>
        public static SinoUser GetUserInfoByYHID(string _yhid)
        {
            if (_yhid == "0")
            {
                return(C_GetUserInfo.GetAdminInfo());
            }
            SinoUser _su = new SinoUser();

            using (SqlConnection cn = SqlHelper.OpenConnection())
            {
                //取用户信息

                SqlCommand _cmd = new SqlCommand(SQL_GetUserInfoByYHID, cn);
                _cmd.Parameters.Add(":YHID", decimal.Parse(_yhid));
                DataTable      _yhdt    = new DataTable("YHTABLE");
                SqlDataAdapter _adapter = new SqlDataAdapter(_cmd);
                _adapter.Fill(_yhdt);

                if (_yhdt.Rows.Count < 1)
                {
                    //为未注册用户
                    //throw new Exception(string.Format("用户尚未在系统中注册!"));
                    return(C_GetUserInfo.GetNoRegisterUserByUserID(decimal.Parse(_yhid)));
                }

                DataRow _dr = _yhdt.Rows[0];
                _su.LoginName   = _dr["YHM"].ToString();
                _su.Dwdm        = _dr["DWDM"].ToString();
                _su.DwID        = _dr["DWID"].ToString();
                _su.DwName      = _dr["DWMC"].ToString();
                _su.UserID      = _yhid;
                _su.UserName    = _dr["XM"].ToString();
                _su.SecretLevel = _dr.IsNull("AQJB") ? 0 : int.Parse(_dr["AQJB"].ToString());
                _su.QxszJB      = ""; //级别限定已经无用,现在处理时是按照岗位所在的级别。

                //取岗位信息
                _su.Posts = C_GetGWInfo.Get_PostsByYHID(_su.UserID);
                foreach (SinoPost _sp in _su.Posts)
                {
                    _sp.Rights = C_GetGWInfo.GetRightsOfPost(_sp.PostID, "");
                    if (_sp.IsDefaultPost)
                    {
                        _su.DefaultPost = _sp;
                    }
                }
                if (_su.DefaultPost == null)
                {
                    if (_su.Posts.Count > 0)
                    {
                        _su.DefaultPost = (SinoPost)_su.Posts[0];
                    }
                    else
                    {
                        _su.DefaultPost = new SinoPost();
                    }
                }
                _su.CurrentPost = _su.DefaultPost;
                cn.Close();
            }
            return(_su);
        }
Esempio n. 2
0
        /// <summary>
        /// 通过用户登录名取用户信息
        /// </summary>
        /// <param name="_userName">用户登录名称</param>
        /// <returns></returns>
        public static SinoUser GetUserInfoByLoginName(string _userName)
        {
            if (_userName == "Administrator")
            {
                return(C_GetUserInfo.GetAdminInfo());
            }
            SinoUser _su = new SinoUser();

            using (SqlConnection cn = SqlHelper.OpenConnection())
            {
                //取用户信息

                SqlParameter[] _param =
                {
                    new SqlParameter(":YHM", SqlDbType.VarChar)
                };
                _param[0].Value = _userName;

                DataTable _yhdt = SqlHelper.FillDataTable(cn, CommandType.Text, SQL_GetUserInfoByLoginName, _param);

                if (_yhdt.Rows.Count < 1)
                {
                    //为未注册用户
                    throw new Exception(string.Format("用户尚未在系统中注册!"));
                }

                DataRow _dr = _yhdt.Rows[0];
                _su.LoginName   = _dr["YHM"].ToString();
                _su.Dwdm        = _dr["DWDM"].ToString();
                _su.DwID        = _dr["DWID"].ToString();
                _su.DwName      = _dr["DWMC"].ToString();
                _su.UserID      = _dr["YHID"].ToString();
                _su.UserName    = _dr["XM"].ToString();
                _su.SecretLevel = _dr.IsNull("AQJB") ? 0 : int.Parse(_dr["AQJB"].ToString());
                _su.QxszJB      = ""; //级别限定已经无用,现在处理时是按照岗位所在的级别。

                //取岗位信息
                _su.Posts = C_GetGWInfo.Get_PostsByYHID(_su.UserID);
                foreach (SinoPost _sp in _su.Posts)
                {
                    _sp.Rights = C_GetGWInfo.GetRightsOfPost(_sp.PostID, "");
                    if (_sp.IsDefaultPost)
                    {
                        _su.DefaultPost = _sp;
                    }
                }
                if (_su.DefaultPost == null)
                {
                    if (_su.Posts.Count > 0)
                    {
                        _su.DefaultPost = (SinoPost)_su.Posts[0];
                    }
                    else
                    {
                        _su.DefaultPost = new SinoPost();
                    }
                }
                _su.CurrentPost = _su.DefaultPost;
                cn.Close();
            }
            return(_su);
        }