我正在做一个工程的登陆界面,可是当我输入用户名、密码之后怎么又弹出来登陆的对话框呢?代码如下
private void btnOK_Click(object sender, EventArgs e)
{
if (txtUsername.Text.Trim() == "")
{
MessageBox.Show("请输入用户名");
txtUsername.Focus();
return;
}
if (txtPsw.Text.Trim() == "")
{
MessageBox.Show("请输入密码");
txtPsw.Focus();
return;
}
// 获取用户信息
else
{
string strSql = "select * from Users where UserName='" + txtUsername.Text + "' and UserPwd='" + txtPsw.Text + "'";
DataSet ds = dataoperate.getDs(strSql, "Users");
if (ds.Tables[0].Rows.Count > 0)
{
this.Hide();
MainForm mainform = new MainForm();
mainform.Show();
}
else
{
MessageBox.Show("用户名或密码错误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
其中dataOperate类代码为 class DataOperate
{
DataConn datacon = new DataConn();
OracleConnection oledbcon;
OracleDataAdapter oledbda;
DataSet ds; public DataSet getDs(string strCon, string tbname)
{
oledbcon = datacon.conn;
oledbda = new OracleDataAdapter(strCon, oledbcon);
ds = new DataSet();
oledbda.Fill(ds, tbname);
return ds;
}
}
private void btnOK_Click(object sender, EventArgs e)
{
if (txtUsername.Text.Trim() == "")
{
MessageBox.Show("请输入用户名");
txtUsername.Focus();
return;
}
if (txtPsw.Text.Trim() == "")
{
MessageBox.Show("请输入密码");
txtPsw.Focus();
return;
}
// 获取用户信息
else
{
string strSql = "select * from Users where UserName='" + txtUsername.Text + "' and UserPwd='" + txtPsw.Text + "'";
DataSet ds = dataoperate.getDs(strSql, "Users");
if (ds.Tables[0].Rows.Count > 0)
{
this.Hide();
MainForm mainform = new MainForm();
mainform.Show();
}
else
{
MessageBox.Show("用户名或密码错误!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
}
其中dataOperate类代码为 class DataOperate
{
DataConn datacon = new DataConn();
OracleConnection oledbcon;
OracleDataAdapter oledbda;
DataSet ds; public DataSet getDs(string strCon, string tbname)
{
oledbcon = datacon.conn;
oledbda = new OracleDataAdapter(strCon, oledbcon);
ds = new DataSet();
oledbda.Fill(ds, tbname);
return ds;
}
}
解决方案 »
- .Net问题:为什么datarow调试后显示赋值成功而页面却显示的是失败的?
- 有关正则表达式的问题
- 点击trackBar1之后音量调到最小了 看了好多例子都是这样
- TabControl的Page问题
- 关于调用父类构造函数的疑问?
- 有关无框窗口的问题?-在线等!
- 帮个忙!!!
- 是高手的请看下面这个贴子:
- 当改变combobox,要发生什么事件??
- 不能将项目“CMSForm”中的依赖项“EnterpriseObjects, Version=1.0.1174.26494, Culture=neutral”复制到运行目录,因为它将改写引用“E
- 【讨论】一个用户权限的设计问题
- 在使用 DatabaseFactory.CreateDatabase 数据库的连接是什么时候做的?
改为 public DataSet getDs(string strCon) oledbda.Fill(ds, tbname)
改为 oledbda.Fill(ds)
建议如下实现
在program.cs 这样写
if(FrmLogin.ShowDiagole()==DiagoleResult.OK)
{
FrmMain.show();
}身边没有vs2005只能够手写 不一定正确 但是可以一试
可能是this.Hide 造成的,在MainForm中添加一个登录窗体的变量。
假设登录窗体为LoginForm
private LoginForm loginForm;MainForm增加一个构造方法;
public MainForm(LoginFrom lForm)
{
this.loginForm = lForm;
}将以下代码
this.Hide
MainForm mainform = new MainForm();
mainform.Show();修改为
this.Hide
MainForm mainform = new MainForm(this);
mainform.Show();然后在MainFrom类的FormLoad方法中
添加:
loginForm.Dispose();
将登录窗体释放掉。
我以前也遇见过的