using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace YFanDriver
{
public partial class LoginForm : Form
{ public LoginForm()
{
InitializeComponent(); } private void button1_Click(object sender, EventArgs e)
{
string Id = textBox1.Text;
string LoginPwd = textBox2.Text;
if (Id == string.Empty)
{
MessageBox.Show("请输入用户名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else if (LoginPwd == string.Empty)
{
MessageBox.Show("请输入密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=YFanDriver;Integrated Security=True");
conn.Open();
string sql = string.Format("select count(*) from users where Id='{0}' and LoginPwd='{1}'", Id, LoginPwd);
SqlCommand comm = new SqlCommand(sql, conn);
int tag = 0;
if ((int)comm.ExecuteScalar() > 0)
tag = 1;
conn.Close(); if (tag == 1)
{
this.DialogResult = DialogResult.OK;
MainForm form = new MainForm();
form.ShowDialog();
LoginForm login = new LoginForm();
login.Close();
}
else
{
MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
} } private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;namespace YFanDriver
{
public partial class LoginForm : Form
{ public LoginForm()
{
InitializeComponent(); } private void button1_Click(object sender, EventArgs e)
{
string Id = textBox1.Text;
string LoginPwd = textBox2.Text;
if (Id == string.Empty)
{
MessageBox.Show("请输入用户名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else if (LoginPwd == string.Empty)
{
MessageBox.Show("请输入密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=YFanDriver;Integrated Security=True");
conn.Open();
string sql = string.Format("select count(*) from users where Id='{0}' and LoginPwd='{1}'", Id, LoginPwd);
SqlCommand comm = new SqlCommand(sql, conn);
int tag = 0;
if ((int)comm.ExecuteScalar() > 0)
tag = 1;
conn.Close(); if (tag == 1)
{
this.DialogResult = DialogResult.OK;
MainForm form = new MainForm();
form.ShowDialog();
LoginForm login = new LoginForm();
login.Close();
}
else
{
MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
} } private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
form.ShowDialog();
LoginForm login = new LoginForm();
login.Close();你new它干嘛用?