using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsFormsApplication1
{
public partial class login : Form
{
public login()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.SelectedIndex = 0;
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
//创建数据库连接字符串 SqlConnection connection = new SqlConnection(connString); //通过connection对象创建数据库连接
con.ConnectionString = "server=DESKTOP-3U564EO;database=library;uid=xxpxxplove;pwd=feinibuaiv5";
string sql = string.Format("select count(*) from {2} where num='{0}'and password='{1}'", textBox1.Text,textBox2.Text , comboBox1.Text); //创建sql语句
con.Open(); //打开数据库连接
//创建command对象
SqlCommand command = new SqlCommand(sql,con);
int num = (int)command.ExecuteScalar(); //执行sql查询语句,ExecuteScalar()返回查询结果集中的第一行的第一列
if (num > 0)
{
MessageBox.Show("欢迎进入成绩管理系统!", "登录成功", MessageBoxButtons.OK, MessageBoxIcon.Information); //弹出登录成功消息框
this.Hide(); //当前窗口(登录窗口)不显示
if (comboBox1.Text=="Administrator")
{
Form AMain = new Form();
AMain.ShowDialog();
this.Close();
this.Dispose();
}
else
{
Form RMain = new Form();
RMain.ShowDialog();
this.Close();
this.Dispose();
}
}
else
{
MessageBox.Show("您输入的用户名或密码错误!", "登录失败", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
con.Close();//关闭数据库连接
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}