using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 电子元器件数据库管理
{
public partial class loin : Form
{
public static bool lfstate = false;
private DataRow userRow;
public static string Group;
/// <summary>
/// 必需的设计器变量。
/// </summary>
//private System.ComponentModel.Container components = null;
public loin()
{
InitializeComponent();
}
public int isUser()
{
SqlConnection SqlCon = new SqlConnection();
SqlCommand LogInCommand = new SqlCommand();
SqlDataAdapter userAdapter = new SqlDataAdapter();
DataSet UserInfoSet = new DataSet();
try
{
SqlCon.ConnectionString = "server=localhost;Trusted_Connection=yes;user=sa;pwd=;database=dzyqj";//连接字段
LogInCommand.Connection = SqlCon;
LogInCommand.CommandText = "SELECT userid,password,groupid From user";
userAdapter.SelectCommand = LogInCommand;
userAdapter.SelectCommand.Connection = SqlCon;
SqlCon.Open();
userAdapter.Fill(UserInfoSet, "user");//填充数据集
for (int i = 0; i < UserInfoSet.Tables["user"].Rows.Count; i++)
{
this.userRow = UserInfoSet.Tables["user"].Rows[i];
//只有当输入的用户名和密码同时对应上数据库中记录时,才能通过校验
if (userRow[0].ToString().Trim() == this.comboBox1.Text.Trim() && userRow[1].ToString().Trim() == this.textBox1.Text.Trim())
{
Group = userRow[2].ToString().Trim();
return 1;