跳出另外一个窗口的问题。。。
代码。谢谢。。Login.cs的代码:
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace 设备维护系统
{
public partial class Login : Form
{
public Login()
{
InitializeComponent();
}
public bool blCanLogin;
OleDbConnection connection1 = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;" + "Data Source = d:\\shebei.mdb");
private void button1_Click(object sender, EventArgs e)
{
blCanLogin = false;
string sql = "select username,password from admin";
DataRow myRow;
connection1.Open();
OleDbDataAdapter adp = new OleDbDataAdapter(sql, connection1);
DataSet ds = new DataSet();
adp.Fill(ds, "user");
if (textBox1.Text.Trim() != "")
{
if (textBox2.Text.Trim() != "")
{
for (int i = 0; i < ds.Tables["user"].Rows.Count; i++)
{
myRow = ds.Tables["user"].Rows[i];
if (myRow[0].ToString().Trim() == textBox1.Text.ToString().Trim() && myRow[1].ToString().Trim() == textBox2.Text.ToString().Trim())
{
blCanLogin = true;
MainForm mainForm = new MainForm();
// mainForm.myname = this.textBox1.Text.Trim(); return;
}
connection1.Close();
}
MessageBox.Show("你输入的用户名或密码不正确!");
connection1.Close();
return;
}
else
MessageBox.Show("密码不能为空");
connection1.Close();
return;
}
else
MessageBox.Show("用户名不能为空");
connection1.Close();
}
private void button2_Click(object sender, EventArgs e)
{
blCanLogin = false;
this.Close();
}
}
}
Program.cs的代码:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace 设备维护系统
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// Application.Run(new login());
Login login = new Login();
login.ShowDialog();
MainForm mainForm = new MainForm();
// mainForm.myname = login.textBox1.Text.Trim();
if (login.blCanLogin == true)
mainForm.ShowDialog();
}
}
}
我点登陆,没反应。数据库的账号和密码都输入正确。。