登录界面
在这里插入代码片
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
namespace Test
{
public partial class Form1 : Form
{
private string VerifyCode = “”;
public Form1()
{
InitializeComponent();
VerifyCode = MakeCode(5);
pictureBox1.Image = CreateCodeImg(VerifyCode);
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
FormRegister formRegister = new FormRegister();
formRegister.Show();
}
private void button2_Click(object sender, EventArgs e) //登陆
{
string username = textBoxUserName.Text.Trim(); //取出账号
string password = EncryptWithMD5(textBoxPassWord.Text.Trim()); //取出密码
//string connstr = ConfigurationManager.ConnectionStrings["connectionString"].ToString(); //读取连接字符串
string myConnString = "Data Source=.;Initial Catalog=Text;Persist Security Info=True;User ID=sa;Password=110023"; //连接字符串 Data source为服务器的名字 Text为连接的库
SqlConnection sqlConnection = new SqlConnection(myConnString); //实例化连接对象
sqlConnection.Open();
string sql = "select UserID,UserPassword from UserMessage where UserID = '" + username + "' and UserPassword = '" + password + "'"; //编写SQL命令
SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
if (sqlDataReader.HasRows && radioButton1.Checked) //学生成功登录
{
MessageBox.Show("欢迎使用!"); //登录成功
FormStudent formstudent = new FormStudent();
formstudent.Show();
//this.Hide();
}
if (sqlDataReader.HasRows && radioButton2.Checked) //管理员成功登录
{
MessageBox.Show("欢迎使用!"); //登录成功
FormAdmini formAdmini = new FormAdmini();
formAdmini.Show();
// this.Hide();
}
//验证码
if (string.IsNullOrEmpty(txtVerifyCode.Text))
{
MessageBox.Show("请输入验证码!");
return;
}