You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

191 lines
7.5 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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;
using System.Security.Cryptography;
namespace Sql
{
public partial class Form1 : Form//进行接口拆分Form1被拆分了还有一部分在放在Form1.Designer.cs里 :Form就是继承自Form
{ //
public Form1()
{
InitializeComponent();//该方法实际上是由系统生成的对于窗体界面的定义方法会跳转到Form1.Designer.cs这个是对界面进行初始化
//在每一个Form文件建立后都会同时产生程序代码文件.CS文件以及与之相匹配的.Designer.CS文件
//业务逻辑以及事件方法等被编写在.CS文件之中而界面设计规则被封装在.Designer.CS文件里
}//做完这个初始化操作以后就弹出登录框了,等待下一步的命令执行
public string MD5Hash(string input)//对数据进行md5加密
{
MD5 md5 = MD5.Create();
byte[] inputBytes = Encoding.ASCII.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString();
}
private void timer1_Tick(object sender, EventArgs e)
{
if(pictureBox1.Location.X<175)//图片校准功能,就是不确定我们的图片大小是怎么样的,但是为了实现滑动功能,将图片从左到右滑动,于是来一个图片校准
{
pictureBox1.Location = new Point(pictureBox1.Location.X + 4, pictureBox1.Location.Y);
}
else
{
if(comboBox1.Text=="学生")
{
string A = MD5Hash(textBox2.Text);
string sql = "select * from Student where Id='" + textBox1.Text + "'and Password='" + A + "'";
Dao dao = new Dao();
IDataReader dr = dao.read(sql);
dr.Read();
string sID = dr["Id"].ToString();
Form3 form3 = new Form3(sID);
form3.Show();
this.Hide();
// this.Close();
}
else
{
if (comboBox1.Text == "老师")
{
Form2 form2 = new Form2();
form2.Show();
this.Hide();
// this.Close();
}
else
{
if (comboBox1.Text == "管理员")//滑动完了以后就进行判断,管理员的话就走这一条
{
Form5 form5 = new Form5();//创建一个form5窗体
form5.Show();//form5窗体展示跳转到form5.Designer.cs文件进行窗体初始化
this.Hide();//form1窗体隐藏
// this.Close();
}
}
}
timer1.Stop();//timer1定时器停止然后打开了form5等待使用者进行操作
}
}
private void button1_Click(object sender, EventArgs e)//点击登录以后触发了这个事件
{
if(login())//这个是一个登录判断然后进入到login()里面去进行判断在下面89行
{
timer1.Start();//启动定时器待会准备运行timer1_Tick()
textBox1.Visible = false;
textBox2.Visible = false;
label1.Visible = false;
label2.Visible = false;
label3.Visible = false;
comboBox1.Visible = false;
button1.Visible = false;
button3.Visible = false;
button4.Visible = false;
button6.Visible = false;
}
else if(textBox1.Text != "" && textBox2.Text != "" && comboBox1.Text != "")
{
MessageBox.Show("账号或密码有误", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
private bool login()
{
if (textBox1.Text == "" || textBox2.Text == ""||comboBox1.Text=="")//逻辑与,两个都为真才行,也就是判断这三个框都不能为空
{
MessageBox.Show("输入不完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);//提示是行头,里面的文字是输入不完整
return false;
}
if (comboBox1.Text == "学生")//如果框框是学生那么走下面的判断,下面的管理员也一样
{
string A = MD5Hash(textBox2.Text);
string sql = "select * from Student where Id='" + textBox1.Text + "'and Password='"+A+"'";
Dao dao = new Dao();
IDataReader dr = dao.read(sql);
if(dr.Read())
{
return true;
}
else
{
return false;
}
}
if (comboBox1.Text == "老师")
{
string A = MD5Hash(textBox2.Text);
string sql = "select * from seat where Name='" + textBox1.Text + "'and Password='" + A + "'";
Dao dao = new Dao();
IDataReader dr = dao.read(sql);
if (dr.Read())
{
return true;
}
else
{
return false;
}
}
if (comboBox1.Text == "管理员")
{
string A = MD5Hash(textBox2.Text);
string sql = "select * from Admin where Id='" + textBox1.Text + "'and Password='" + A + "'";//sql语句进行拼接
Dao dao = new Dao();//创建一个Dao对象准备通过Dao对数据库进行操作
IDataReader dr = dao.read(sql);//dao层的read函数载入sql语句开始查询然后将结果给到dr
if (dr.Read())//如果数据库的读取成功那么返回成功离开到139行
{
return true;
}
else
{
return false;
}
}
return false;
}
private void button3_Click(object sender, EventArgs e)
{
if (textBox1.Text != "" || textBox2.Text != "" || comboBox1.Text != "")
{
DialogResult r = MessageBox.Show("退出后当前输入内容不会保存", "提示", MessageBoxButtons.OKCancel);
if (r == DialogResult.OK)
{
Close();
}
}
else
{
Close();
}
}
private void button4_Click(object sender, EventArgs e)
{
textBox1.Text = null;
}
private void button6_Click(object sender, EventArgs e)
{
textBox2.Text = null;
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}