visual basic - 将信息从一种形式调用到另一种形式

时间:2016-01-16 16:11:03

标签: vb.net

form1(登录表单):

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

int bfs(const vector< vector<int> > &g, pair<int, int> p)
{
queue <pair<pair<int, int>, int> > que;
vector< vector<bool> > vis(100000,vector<bool>(100000,false)); //visited
int x, y, k = 0; //k = distance
pair <pair<int, int>, int> next, start;
pair <int, int> pos;
start = make_pair(make_pair(p.first, p.second), 0);
que.push(start);
while(!que.empty())
{
    next = que.front();
    pos = next.first;
    x = pos.first;
    y = pos.second;
    k = next.second;
    que.pop();

    if (y == 0) {
        return k;
    }
    if((g[x+1][y] == 1) && (vis[x+1][y] == false))
    {
        que.push(make_pair(make_pair(x+1, y), k+1));
        vis[x+1][y] = true;
    }
    if((g[x][y+1] == 1) && (vis[x][y+1] == false))
    {
        que.push(make_pair(make_pair(x, y+1), k+1));
        vis[x][y+1] = true;
    }
    if((g[x-1][y] == 1) && (vis[x-1][y] == false))
    {
        que.push(make_pair(make_pair(x-1, y), k+1));
        vis[x-1][y] = true;
    }
    if((g[x][y-1] == 1) && (vis[x][y-1] == false))
    {
        que.push(make_pair(make_pair(x, y-1), k+1));
        vis[x][y-1] = true;
    }
  }
}

int main()
{
int B,L,S,x,y, shortestDist = 1234567;
cin >> B >> L >> S;
vector< pair <int, int> > p; //stones in the first row
vector< vector<int> > g(B, vector<int>(L,0));
for(int i = 0; i < S; i++)
{
        cin >> y >> x;
        g[y][x] = 1; // stone = 1, empty = 0
        if(y == B-1)
            p.push_back(make_pair(x, y));    
}

for(int i=0;i<p.size();++i)
     {
        shortestDist = min(shortestDist,bfs(g,p[i]));
     }
cout << shortestDist + 2 << "\n"; //add 2 because we need to jump from shore  to river at start, and stone to river at end
return 0;
}

窗口2:

Private Sub Login_Btn_Click(sender As Object, e As EventArgs) Handles Login_Btn.Click
    Try
        Dim connStr As String = ""
        Dim connection As New MySqlConnection(connStr)
        Dim READER As MySqlDataReader
        connection.Open()
        Dim Query As String
        Query = "select * from table where username='" & txtusername.Text & "' and password='" & txtpassword.Text & "' "
        COMMAND = New MySqlCommand(Query, connection)
        READER = COMMAND.ExecuteReader
        Dim count As Integer
        count = 0
        While READER.Read
            count = count + 1
        End While
        If count = 1 Then
            Query = "select * from table where username= '" & txtusername.Text & " '"
            Dim username As String
            username = READER("username")
            MessageBox.Show( " " & username )

            MessageBox.Show("Username and password is correct")
            Homepage.Show()
            Me.Hide()
            txtusername.Text = ""
            txtpassword.Text = ""
        EndIf
        connection.Close()

好的,我得到的问题是,当尝试从form1获取用户名信息时,它第一次成功运行。但是,如果我退出并使用其他用户名登录,它仍会显示相同的用户名?请有人帮帮我:)。

1 个答案:

答案 0 :(得分:0)

非常简单的修复-.-

            Dim Homepage = New Homepage
            Homepage.Show()

            Me.Hide()