private void button1_Click(object sender, EventArgs e)
{
string UserCode = textBox1.Text.Trim();
string UserPswd = textBox2.Text.Trim();
if (UserCode=="")
{
MessageBox.Show("请输入帐号");
}
else {
SqlDataReader usdr = FPara.SqlReader("select top 1 * from lampUserName where UserName='" + UserCode + "'", FPara.connStr);
if (usdr != null)
{
if (usdr.Read())
{
if (usdr["Pswd"].ToString() != UserPswd)
{
MessageBox.Show("密码错误");
}
else
{
FPara.ShopCode = usdr["UserName"].ToString();
MessageBox.Show("登录成功");
this.Hide();
Form4 f = new Form4();
f.Show();
}
}
else
{
MessageBox.Show("帐号密码错误");
}
usdr.Close();
namespace UserData
{
public class FPara
{
public static string ShopCode="";
public static bool CheckLogin()
{
if(ShopCode=="")
{
return false;
}
else
{
return true;
}
}
public static SqlConnection connStr=new SqlConnection("Server=XTZJ-674B0F596D\\SQLEXPRESS;uid=sa;pwd=123456;database=master");
public static SqlDataReader SqlReader(string sql,SqlConnection connstr)
{
SqlDataReader sqldr=null;
SqlCommand cmd=new SqlCommand(sql,connstr);
if (cmd.Connection.State.ToString()=="Closed") cmd.Connection.Open();
try
{
sqldr=cmd.ExecuteReader();
}
catch(Exception e)
{
if (e!=null) sqldr=null;
}
return sqldr;
}
//数据库操作连接
public static string SqlCmd(string sql,SqlConnection connstr)
{
string errorstr=null;
SqlCommand sqlcmd= new SqlCommand(sql,connstr);
if (sqlcmd.Connection.State.ToString()=="Open") sqlcmd.Connection.Close();
sqlcmd.Connection.Open();
try
{
sqlcmd.ExecuteNonQuery();
}
catch(Exception e)
{
if (e!=null) errorstr=e.ToString();
}
sqlcmd.Connection.Close();
return errorstr;
}
}
}