c# sql 数据库实验大作业 (学生信息管理)

这是一个关于C#和SQL数据库的实验大作业,涵盖了学生登录、管理员登录、注册、学生表、课程表和SC表的查看及增删改查功能。包括学生和管理员的不同操作界面,如学生信息、课程信息的查看以及管理员对学生和课程信息的管理。
摘要由CSDN通过智能技术生成

视频讲解链接:https://www.bilibili.com/video/BV1FA411B74H/
一 层级概括
主要界面包括学生登录界面,管理员登录界面,注册界面,学生表,课程表,SC表的查看,
以及增删改查界面
二主要代码和界面演示
1.注册界面
在这里插入图片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test518
{
    public partial class Register : Form
    {
        public Register()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            if (comboBox1.Text.Trim() == "学生")//如果是学生注册,添加到SysUsers
            {
                try
                {
                    string connString = "Data Source=.;Initial Catalog=School;User ID=sa;Password=lrx359641708";//数据库连接字符串
                    SqlConnection connection = new SqlConnection(connString);//创建connection对象
                    string sql = "insert into SysUser (UserID,   UserPassWord ,   UserSchoolID, UserMobile, UserBirthday , UserIdentity  ) " +
                                                                     "values (@userid, @userpassword,@userschoolid,@usermobile,@userbirthday,@useridentity)";
                    SqlCommand command = new SqlCommand(sql, connection);
                    SqlParameter sqlParameter = new SqlParameter("@userid", textBox1.Text);
                    command.Parameters.Add(sqlParameter);
                    sqlParameter = new SqlParameter("@userpassword", textBox2.Text);
                    command.Parameters.Add(sqlParameter);
                    sqlParameter = new SqlParameter("@userschoolid", textBox3.Text);
                    command.Parameters.Add(sqlParameter);
                    sqlParameter = new SqlParameter("@usermobile", textBox4.Text);
                    command.Parameters.Add(sqlParameter);
                    sqlParameter = new SqlParameter("@userbirthday", dateTimePicker1.Value);
                    command.Parameters.Add(sqlParameter);
                    sqlParameter = new SqlParameter("@useridentity", comboBox1.Text);
                    command.Parameters.Add(sqlParameter);
                    
                    //打开数据库连接
                    connection.Open();
                    command.ExecuteNonQuery();
                    connection.Close();
                    MessageBox.Show("注册成功");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            if (comboBox1.Text.Trim() == "管理员")//如果是管理员注册,添加到SyUsers
            {
                try
                {
                    string connString = "Data Source=.;Initial Catalog=School;User ID=sa;Password=lrx359641708";//数据库连接字符串
                    SqlConnection connection = new SqlConnection(connString);//创建connection对象
                    string sql = "insert into SyUser (UserID,   UserPassWord ,   UserSchoolID, UserMobile, UserBirthday , UserIdentity  ) " +
                                                                        "values (@userid, @userpassword,@userschoolid,@usermobile,@userbirthday,@useridentity)";
                    SqlCommand command = new SqlCommand(sql, connection);
                    SqlParameter sqlParameter = new SqlParameter("@userid", textBox1.Text);
                    command.Parameters.Add(sqlParameter);
                    sqlParameter = new SqlParameter("@userpassword", textBox2.Text);
                    command.Parameters.Add(sqlParameter);
                    sqlParameter = new SqlParameter("@userschoolid", textBox3.Text);
                    command.Parameters.Add(sqlParameter);
                    sqlParameter = new SqlParameter("@usermobile", textBox4.Text);
                    command.Parameters.Add(sqlParameter);
                    sqlParameter = new SqlParameter("@userbirthday", dateTimePicker1.Value);
                    command.Parameters.Add(sqlParameter);
                    sqlParameter = new SqlParameter("@useridentity", comboBox1.Text);
                    command.Parameters.Add(sqlParameter);
                   
                    //打开数据库连接
                    connection.Open();
                    command.ExecuteNonQuery();
                    connection.Close();
                    MessageBox.Show("注册成功");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            this.Close();//界面关闭

        }



        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        public Byte[] mybyte = new byte[0];

      

        private void textBox1_Leave(object sender, EventArgs e)
        {
            if (textBox1.Text.Trim() != "")
            {
                //使用regex(正则表达式)进行格式设置 至少有数字、大写字母、小写字母各一个。最少3个字符、最长20个字符。
                Regex regex = new Regex(@"(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]).{3,20}");

                if (regex.IsMatch(textBox1.Text))//判断格式是否符合要求
                {
                    //MessageBox.Show("输入密码格式正确!");
                }
                else
                {
                    MessageBox.Show("至少有数字、大写字母、小写字母各一个。最少3个字符、最长20个字符!");
                    textBox1.Focus();
                }
            }
            else
            {
                MessageBox.Show("Please fill in the full information!");
            }

        }

        private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {

        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void label9_Click(object sender, EventArgs e)
        {

        }

        private void label8_Click(object sender, EventArgs e)
        {

        }

        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Register_Load(object sender, EventArgs e)
        {

        }
    }
}

2.学生登录界面
在这里插入图片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test518
{
    public partial class StudentLogin : Form
    {
        public StudentLogin()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string username = textBox1.Text.Trim();  //取出账号
            string password = textBox2.Text.Trim();  //取出密码并加密

     

            //string connstr = ConfigurationManager.ConnectionStrings["connectionString"].ToString(); //读取连接字符串
            string myConnString = "Data Source=.;Initial Catalog=School;Persist Security Info=True;User ID=sa;Password=lrx359641708";

            SqlConnection sqlConnection = new SqlConnection(myConnString);  //实例化连接对象
            sqlConnection.Open();

            string sql = "select UserID,UserPassword from SysUser where UserID = '" + username + "' and UserPassword = '" + password + "'";  
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值