예제 #1
0
        /// <summary>
        /// 加载用户权限
        /// </summary>
        /// <param name="username"></param>
        private void loadUserRole(string username)
        {
            string           sql  = "select c.description from CTP_USER a left join CTP_REL_USER_ROLE b on a.id = b.LEFTID left join ctp_role c on b.rightId = c.id where a.name = '" + username + "'";
            OracleConnection conn = null;
            OracleCommand    cmd  = new OracleCommand();

            try
            {
                conn            = OracleUtil.OpenConn();
                cmd.Connection  = conn;
                cmd.CommandText = sql;
                var reader = cmd.ExecuteReader();
                if (reader.Read())
                {
                    ConstantUtil.UserRole = reader.IsDBNull(0) ? string.Empty : reader.GetString(0);
                }
            }
            catch (Exception ex)
            {
                log.Error("获取当前登录用户角色失败" + ex.Message, ex);
            }
            finally
            {
                cmd.Dispose();
                OracleUtil.CloseConn(conn);
            }
        }
예제 #2
0
        private void loginButton_Click(object sender, EventArgs e)
        {
            string username = this.userNameTextBox.Text;
            string pass     = this.userPasswordTextBox.Text;

            if (username.Equals("") || pass.Equals(""))
            {
                promptPanel.Show();
            }
            else
            {
                //调用Md5 获取加密后的密码
                string password = MD5Util.GetMd5(pass);
                //获取数据库连接
                OracleConnection connection  = OracleUtil.OpenConn();
                string           queryString = "select password from ctp_user where name ='" + username + "'";

                OracleCommand command = new OracleCommand();
                command.Connection  = connection;
                command.CommandText = queryString;
                try
                {
                    var reader = command.ExecuteReader();
                    if (reader.Read())
                    {
                        string confirmPassword = string.Format("{0}", reader["password"]);
                        if (password.Equals(confirmPassword))
                        {
                            //用户名,密码验证成功
                            //加载权限
                            //loadUserRole(username);
                            this.DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            promptPanel.Show();
                            //MessageBox.Show("用户名或者密码输入错误,请重新输入!");
                        }
                    }
                    else
                    {
                        promptPanel.Show();
                        //MessageBox.Show("用户名或者密码输入错误,请重新输入!");
                    }
                }
                catch (Exception ex)
                {
                    log.Error("获取登录信息失败" + ex.Message, ex);
                }
                finally
                {
                    OracleUtil.CloseConn(connection);
                }
            }
        }