110,539
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace 毕业设计
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)//处理登陆
{
try
{
string StrSQL="SELECT * FROM 密码管理表 WHERE 用户名 LIKE '"+this.textBox1.Text+"' AND 用户类
型 LIKE '"+this.comboBox1.Text+"'";//this.textBox1.Text里面是用户名,this.comboBox1.Text是用户类型,
this.sqlDataAdapter1.SelectCommand.CommandText=StrSQL;
this.sqlDataAdapter1.SelectCommand.Connection=this.sqlConnection1;
//打开数据库连接
this.sqlConnection1.Open();
//执行SQL命令
System.Data.SqlClient.SqlDataReader MyRead=this.sqlDataAdapter1.SelectCommand.ExecuteReader();
while(MyRead.Read())
{
if(MyRead.GetString(2).Trim()==this.textBox2.Text.ToString())//如果密码相同
{
Form4 dlg4=new Form4();
if(this.comboBox1.Text=="系统管理员")
{
dlg4.type=1;
}
if(this.comboBox1.Text=="业务员")
{
dlg4.type=2;
}
if(this.comboBox1.Text=="普通用户")
{
dlg4.type=3;
}
dlg4.ShowDialog();
}
else
{
MessageBox.Show("您所输入的用户或密码有错误","信息提示",
MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
this.sqlConnection1.Close();
}
catch(Exception Err)
{
MessageBox.Show(Err.Message,"信息提示",
MessageBoxButtons.OK,MessageBoxIcon.Information);
//如果打开了连接,则关闭它
if(this.sqlConnection1.State==ConnectionState.Open)
{
this.sqlConnection1.Close();
}
}
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
}
}