winform登陆后关闭登录窗口跳转到主窗体
2014-01-14 16:07
330 查看
private void btn_submit_Click(object sender, EventArgs e)
{
try
{
SqlConnection con = new ConnectSQL().getSQLCon();
string sql = "select * from userinfo where username='" + this.txt_NserName.Text + "'";
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
if (dr["password"].ToString() == this.txt_pwd.Text)
{
//MainForm mainform = new MainForm();
//UserInfo user = new UserInfo();
UserInfo.email = dr["email"].ToString();
UserInfo.nickname = dr["nickname"].ToString();
UserInfo.state = dr["state"].ToString();
UserInfo.username = dr["username"].ToString();
UserInfo.userimage = dr["userimage"].ToString();
UserInfo.uid = int.Parse(dr["uid"].ToString());
//mainform.user = user;
this.DialogResult = DialogResult.OK;
//this.Close();
//this.Visible = false;
// mainform.Show();
}
else
{
MessageBox.Show("密码错误!");
}
dr.Dispose();
con.Close();
}
else
{
if (this.txt_NserName.Text == "")
{
MessageBox.Show("请输入信息");
}
else
{
MessageBox.Show("该用户名不存在");
}
dr.Dispose();
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("点击按钮事件异常:/n"+ex.ToString()
以上代码是登录按钮的事件
对于登录后怎么关闭的登录窗口的代码如下,其中要注明的是userinfo是个静态类,用来存储用户的信息,以带到主窗体中去
上述代码可以根据自己情况而定,关键是要传入一个参数:this.DialogResult = DialogResult.OK;
下面代码写在程序Program.cs里
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
LoginForm login = new LoginForm();
login.ShowDialog();
if (login.DialogResult == DialogResult.OK)
{
Application.Run(new MainForm());
}
}
{
try
{
SqlConnection con = new ConnectSQL().getSQLCon();
string sql = "select * from userinfo where username='" + this.txt_NserName.Text + "'";
SqlCommand cmd = new SqlCommand(sql, con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
if (dr["password"].ToString() == this.txt_pwd.Text)
{
//MainForm mainform = new MainForm();
//UserInfo user = new UserInfo();
UserInfo.email = dr["email"].ToString();
UserInfo.nickname = dr["nickname"].ToString();
UserInfo.state = dr["state"].ToString();
UserInfo.username = dr["username"].ToString();
UserInfo.userimage = dr["userimage"].ToString();
UserInfo.uid = int.Parse(dr["uid"].ToString());
//mainform.user = user;
this.DialogResult = DialogResult.OK;
//this.Close();
//this.Visible = false;
// mainform.Show();
}
else
{
MessageBox.Show("密码错误!");
}
dr.Dispose();
con.Close();
}
else
{
if (this.txt_NserName.Text == "")
{
MessageBox.Show("请输入信息");
}
else
{
MessageBox.Show("该用户名不存在");
}
dr.Dispose();
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("点击按钮事件异常:/n"+ex.ToString()
以上代码是登录按钮的事件
对于登录后怎么关闭的登录窗口的代码如下,其中要注明的是userinfo是个静态类,用来存储用户的信息,以带到主窗体中去
上述代码可以根据自己情况而定,关键是要传入一个参数:this.DialogResult = DialogResult.OK;
下面代码写在程序Program.cs里
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
LoginForm login = new LoginForm();
login.ShowDialog();
if (login.DialogResult == DialogResult.OK)
{
Application.Run(new MainForm());
}
}
相关文章推荐
- winform登陆后关闭登录窗口跳转到主窗体
- winform登录后跳转 (主窗体转移到新窗口)
- C# winform登录窗口关闭方法
- C# Winform中实现主窗口打开登录窗口关闭的方法
- Winform 当前窗口跳转目标窗口关闭时资源的释放
- C# winForm 窗口跳转 后关闭上一个窗口的方法
- 【转】winform登录后跳转 新方法 挺好的(移到新窗口)
- c# winform登录(关闭当前form跳转到另一个form)
- C# Winform中实现主窗口打开登录窗口关闭的方法
- C# Winform中实现主窗口打开登录窗口关闭的方法
- winform里c#验证用户正确后 怎么打开新窗口时关闭登陆窗口
- winform登录后跳转 (主窗体转移到新窗口)
- C# Winform中实现主窗口打开登录窗口关闭的方法
- WinForm:一个登陆窗体引发的问题系列(五):窗口跳转
- WinForm------如何跳转另一个窗口,同时关闭当前窗口
- C# winform登录窗口关闭方法
- 3月30日 winform如何正确合理关闭登录窗口
- winform 验证用户正确后打开新窗口时关闭登陆窗口
- C# winform登录窗口关闭方法