一.登录界面
登录界面分为管理员登录和用户登录
1.选择管理员登录时
2.选择用户登录时
3.选择管理员注册时会跳到这个界面
4.选择用户注册时会跳到
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;
using System.Data.SqlClient;
namespace _112管理系统2._0
{
public partial class Form1 : System.Windows.Forms.Form
{
public Form1()
{
InitializeComponent();
}
public int t = 0,k=0;
public void Panduan()//判断填写的用户信息是否存在
{
if (textBox1.Text.Trim() == "" || textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "")
{
MessageBox.Show("填写的信息不能为空");
}
else
{
//指定Sql Sereve提供者的链接字符串
string ConStr = "server=SC-201910241106;database=我的数据库;Trusted_Connection=SSPI";
//建立链接对象
SqlConnection con = new SqlConnection(ConStr);
//打开连接
con.Open();
string str1 = textBox1.Text;
string str2 = textBox2.Text;
string sql = string.Format("select count(*) from 学号 where 学号='{0}' and 姓名='{1}'", str1, str2);
SqlCommand command = new SqlCommand(sql, con);
int i = Convert.ToInt32(command.ExecuteScalar());
if (i > 0)
{
t = 1;
}
else
{
t = 0;
}
con.Close();
}
}
public void Panduan1()//判断填写的管理员信息是否存在
{
if (textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "")
{
MessageBox.Show("填写的信息不能为空");
}
else
{
//指定Sql Sereve提供者的链接字符串
string ConStr = "server=SC-201910241106;database=我的数据库;Trusted_Connection=SSPI";
//建立链接对象
SqlConnection con = new SqlConnection(ConStr);
//打开连接
con.Open();
string str1 = textBox2.Text;
string str2 = textBox3.Text;
string sql = string.Format("select count(*) from 管理员 where 姓名='{0}' and 密码='{1}'", str1, str2);
SqlCommand command = new SqlCommand(sql, con);
int i = Convert.ToInt32(command.ExecuteScalar());
if (i > 0)
{
k = 1;
}
else
{
k = 0;
}
con.Close();
}
}
private void button2_Click(object sender, EventArgs e)//注册按钮事件
{
if(checkBox2.Checked==true&&checkBox1.Checked==false)//跳转管理员注册界面
{
Form2 form2 = new Form2();
form2.Show();
this.Hide();
}
if(checkBox2.Checked == false && checkBox1.Checked == true)//跳转到用户注册界面
{
Form_adimn fa = new Form_adimn();
fa.Show();
this.Hide();
}
}
private void button1_Click(object sender, EventArgs e)//登录按钮事件
{
if (checkBox2.Checked == true && checkBox1.Checked == false)//登录用户界面
{
Panduan();
Class1.str1 = textBox1.Text.ToString();
Class1.str2 = textBox2.Text.ToString();
if (t == 1)
{
Form3 form3 = new Form3();
this.Hide();
form3.Show();
}
else
{
MessageBox.Show("信息填写错误");
}
}
if(checkBox2.Checked == false && checkBox1.Checked == true)//登录管理员界面
{
Panduan1();
if(k==1)
{
MessageBox.Show("登录成功");
adimn_load ad = new adimn_load();
ad.Show();
this.Hide();
}
else
{
MessageBox.Show("管理员信息不存在,请前往注册界面");
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
label1.Visible = false;
textBox1.Visible = false;
checkBox2.Checked = false;
}
}
private void checkBox2_CheckedChanged(object sender, EventArgs e)
{
if (checkBox2.Checked == true)
{
label1.Visible = true ;
textBox1.Visible = true;
checkBox1.Checked = false;
}
}
}
}
**有时间继续更新下面的功能,有疑问可以评论留言**