Ejemplo 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())
            {
                //取用户信息
                DataTable _yhdt = new DataTable("YHTABLE");
                try
                {
                    StringBuilder _sb = new StringBuilder();
                    _sb.Append("SELECT a.yhm,a.dwid,a.xm,b.xdjb,b.aqjb,zhtj_zzjg2.GETDWDM_hgjs(a.dwid) dwdm,");
                    _sb.Append("(select jgqc from qx2_zzjg c where c.zzjgid = a.dwid) DWMC FROM qx2_yhxx a ,qx_tjyhb b ");
                    _sb.Append(" where a.yhid = b.yhid and a.yhid=:YHID ");
                    SqlCommand _cmd = new SqlCommand(_sb.ToString(), cn);
                    _cmd.Parameters.Add(":YHID", decimal.Parse(_yhid));

                    SqlDataAdapter _adapter = new SqlDataAdapter(_cmd);
                    _adapter.Fill(_yhdt);
                }
                catch (Exception ex)
                {
                    SystemLogWriter.WriteLog(string.Format("通用YHID取用户信息失败!YHID={0} 错误信息:{1}", _yhid, ex.Message), EventLogEntryType.Error);
                    throw;
                }

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

                try
                {
                    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;
                }
                catch (Exception ex)
                {
                    SystemLogWriter.WriteLog(string.Format("通用YHID取用户的岗位信息失败!YHID={0} 错误信息:{1}", _yhid, ex.Message), EventLogEntryType.Error);
                    throw;
                }
                cn.Close();
            }
            return(_su);
        }
Ejemplo 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())
            {
                //取用户信息
                StringBuilder _sb = new StringBuilder();
                _sb.Append("SELECT a.yhm,a.yhid,a.dwid,a.xm,b.xdjb,b.aqjb,zhtj_zzjg2.GETDWDM_hgjs(a.dwid) dwdm,");
                _sb.Append("(select jgqc from qx2_zzjg c where c.zzjgid = a.dwid) DWMC FROM qx2_yhxx a ,qx_tjyhb b ");
                _sb.Append(" where a.yhid = b.yhid and a.yhm=:YHM ");
                SqlCommand _cmd = new SqlCommand(_sb.ToString(), cn);
                _cmd.Parameters.Add(":YHM", _userName);
                DataTable      _yhdt    = new DataTable("YHTABLE");
                SqlDataAdapter _adapter = new SqlDataAdapter(_cmd);
                _adapter.Fill(_yhdt);

                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);
        }