GitHub地址https://github.com/Knock-man/studentStatusManagementSyatem

一、模块功能

设计一个用户登录界面,当用户未注册时,点击注册后跳转注册界面,注册后返回登录界面。
登录后菜单功能模块:

在这里插入图片描述

二、数据库设计

数据库名称:StudentStatusManagement
各实体属性
专业(专业编号,专业名称,专业描述)
班级(班级编号,班级名称,班级人数,班级描述,班主任)
学生(学生编号,学生名称,性别,年龄,学生描述)
课程(课程编号,课程学分,课程名称,课程说明)
用户(用户编号,用户名,密码)
E-R图设计
在这里插入图片描述
关系模式设计

专业(专业编号,专业名称,专业描述)
Major(majorId,majorName,majorExplain)

班级(班级编号,班级名称,班级人数,班级描述,班主任,专业编号)
Class(classId,className,classCount,classExplain,teacher,majorId)

学生(学生编号,学生名称,性别,年龄,,学生描述,班级编号)
Student(studentId,studentName,sex,age,studentExplain,classId)

课程(课程编号,课程学分,课程名称,课程说明)
Course(courseId,courseGrade,courseName,courseExplain)

选课(课程号,学生编号,成绩)
Choose(courseId,studentId,grade)

用户(用户编号,用户名,密码)
User(userId,userName,userPassword)

建表

#建库
CREATE DATABASE IF NOT EXISTS StudentStatusManagement;
#建专业表
CREATE TABLE IF NOT EXISTS Major(
	majorId CHAR(10) NOT NULL PRIMARY KEY,
	majorName CHAR(10),
	majorExplain CHAR(30)
)
#建课程表
CREATE TABLE IF NOT EXISTS Course(
	courseId CHAR(10) NOT NULL PRIMARY KEY,
	courseGrade CHAR(10),
	courseName CHAR(10),
	courseExplain CHAR(30)
)
#建用户表
CREATE TABLE IF NOT EXISTS USER(
	userId INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
	userName CHAR(20),
	userPassword CHAR(20)
)
#建班级表
CREATE TABLE IF NOT EXISTS Class(
	classId CHAR(10)  NOT NULL PRIMARY KEY,
	className CHAR(10),
	classCount CHAR(10),
	classExplain CHAR(30),
	teacher CHAR(10),
	majorId char(10),
	FOREIGN KEY(majorId) REFERENCES  Major(majorId)
)
#建学生表
CREATE TABLE IF NOT EXISTS Student(
	studentId char(10) NOT NULL PRIMARY KEY,
	studentName char(10), 
	sex char(10),
	age char(10),
	studentExplain char(30),
	classId char(10),
	FOREIGN KEY(classId) REFERENCES  Class(classId)
)
#建选课表 
CREATE TABLE IF NOT EXISTS Choose(
	courseId char(10) not null,
	studentId char(10) not null,
	grade char(10),
	PRIMARY KEY(courseId,studentId),
	FOREIGN KEY(courseId) REFERENCES  Course(courseId),
	FOREIGN KEY(studentId) REFERENCES  Student(studentId)
)

三、窗体设计

各窗体控件名:

用户登录:
窗体名:register
用户名:userName
密码:passWord
验证码:verification

用户注册:
窗体名:sign
用户名:userName
密码:passWord
确认密码:againPassword

主菜单:
窗体名:Menu


添加专业:
窗体名:AddProfessional
专业编号:zhuanyeId
专业名称:zhuanyeName
专业描述:describe

浏览专业:
窗体名:BrowseMajor

修改专业:
窗体名:UpdateMajor

添加课程:
窗体名:AddCourse
课程编号:courseId
课程学分:courseCredit
课程名称:courseName
课程说明:describe

浏览课程:
窗体名:BrowseCourse

添加班级:
窗体名:AddClass
班级号:classId
班级名称:className
班主任:teacher
班级人数:count
所属专业:major
说明:emplain

班级浏览:
窗体名:BrowseClass
班级号:classid


添加学生:
窗体名:AddStudent
学号:studentId
姓名:studentName
性别:sex
年龄:age
班级编号:classId

学生预览:
窗体名:BrowseStudent
学号:studentId

录入成绩:
窗体名:AddScore
学号:studentId
课程号:courseId
成绩:Score

成绩浏览:
窗体名:BrowseScore

(一)登录界面

在这里插入图片描述

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 MySql.Data.MySqlClient;

namespace studentStatusManagementSyatem
{
    public partial class register : Form
    {
        public register()
        {
            InitializeComponent();
        }
        
         
        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
            sign stu = new sign();
            stu.Show();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            if (userName.Text=="")
            {
                MessageBox.Show("用户名不能为空", "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            }
            else if (passWord.Text == "")
            {
                MessageBox.Show("密码不能为空", "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else if (verification.Text == "")
            {
                MessageBox.Show("验证码不能为空", "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else if (verification.Text != label4.Text)
            {
                MessageBox.Show("验证码错误,请重新输入", "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                //查询数据库账户信息
                string username = userName.Text;
                string password = passWord.Text;
                string sql = "SELECT COUNT(*) FROM USER WHERE userName='" + username + "' AND userPassword = '" + password + "'; ";
                MySqlCommand com = new MySqlCommand(sql, conn);
                if (Convert.ToInt32(com.ExecuteScalar())==0)
                {
                    MessageBox.Show("用户名或者密码错误,请重新输入", "用户登录", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    Menu stu = new Menu();
                    stu.Show();
                    this.Hide();
                }
            }
        }

        private void register_Load(object sender, EventArgs e)
        {
            Random rd = new Random();
            label4.Text = Convert.ToString(rd.Next(1000, 10000));
        }
    }
}

(二)注册界面

在这里插入图片描述

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 MySql.Data.MySqlClient;

namespace studentStatusManagementSyatem
{
    public partial class sign : Form
    {
        public sign()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            if (userName.Text == "")
            {
                MessageBox.Show("用户名不能为空", "用户注册", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            }
            else if (passWord.Text == "")
            {
                MessageBox.Show("密码不能为空", "用户注册", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }else if (againPassword.Text == "")
            {
                MessageBox.Show("请再次输入密码", "用户注册", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            }else if (passWord.Text != againPassword.Text)
            {
                MessageBox.Show("两次密码输入不一致", "用户注册", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                string username = userName.Text;
                string password = passWord.Text;
                //账户存入数据库
                string sql = "insert into User set userName='" + username + "',userPassword='" + password + "'";
                MySqlCommand com = new MySqlCommand(sql, conn);
                com.ExecuteNonQuery();
                MessageBox.Show("注册成功", "用户注册", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.Hide();
                register stu = new register();
                stu.Show();

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
            register stu = new register();
            stu.Show();
        }

        private void sign_Load(object sender, EventArgs e)
        {

        }
    }
}

(三)主菜单

在这里插入图片描述

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;

namespace studentStatusManagementSyatem
{
    public partial class Menu : Form
    {
        public Menu()
        {
            InitializeComponent();
        }

        private void 添加专业ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //打开添加专业窗口
            page.Text = "添加专业";
            AddProfessional stu = new AddProfessional();
            stu.Show();
            

        }

        private void 专业浏览ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            //打开浏览专业窗口
            page.Text = "专业浏览";
            BrowseMajor stu = new BrowseMajor();
            stu.Show();
        }

        private void 添加课程ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            page.Text = "添加课程";
            AddCourse stu = new AddCourse();
            stu.Show();

        }

        private void 课程浏览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            page.Text = "课程浏览";
            BrowseCourse stu = new BrowseCourse();
            stu.Show();
        }

        private void 退出系统ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Hide();
            register stu = new register();
            stu.Show();
        }

        private void 班级浏览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BrowseClass stu = new BrowseClass();
            stu.Show();
            page.Text = "班级浏览";
        }

        private void 添加班级ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddClass stu = new AddClass();
            stu.Show();
            page.Text = "添加班级";
        }

        private void 添加学生ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            page.Text = "添加学生";
            AddStudent stu = new AddStudent();
            stu.Show();

        }

        private void 学生浏览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            page.Text = "学生预览";
            BrowseStudent stu = new BrowseStudent();
            stu.Show();
        }

        private void 录入成绩ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            page.Text = "添加成绩";
            AddScore stu = new AddScore();
            stu.Show();
        }

        private void 成绩浏览ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            page.Text = "成绩浏览";
            BrowseScore stu = new BrowseScore();
            stu.Show();

        }

        private void Menu_Load(object sender, EventArgs e)
        {

        }
    }
}

(四)专业管理模块

添加专业
在这里插入图片描述

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 MySql.Data.MySqlClient;

namespace studentStatusManagementSyatem
{
    public partial class AddProfessional : Form
    {
       
        public AddProfessional()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            
            this.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            if (zhuanyeId.Text == "")
            {
                MessageBox.Show("专业编号不能为空不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }else if (zhuanyeName.Text == "")
            {
                MessageBox.Show("专业名称不能为空不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {

                //数据库取数据判断专业是否存在
                string zhuanyeid = zhuanyeId.Text;
                string zhuanyename = zhuanyeName.Text;
                string miaoshu = textBox1.Text;
                string sql1 = "select count(*) from major where majorId='"+zhuanyeid+"'";
                MySqlCommand com = new MySqlCommand(sql1, conn);
                if (Convert.ToInt32(com.ExecuteScalar())>0)//专业存在
                {
                    MessageBox.Show("此专业已存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else//添加进数据库
                {
                    string sql2 = "insert into major set majorId='" + zhuanyeid + "',majorName='" + zhuanyename + "',majorExplain='" + miaoshu + "'";
                    MySqlCommand com2 = new MySqlCommand(sql2, conn);
                    com2.ExecuteNonQuery();
                    MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.Hide();
                }

            }
        }

        private void AddProfessional_Load(object sender, EventArgs e)
        {

        }
    }
}

2.浏览专业
在这里插入图片描述

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 MySql.Data.MySqlClient;

namespace studentStatusManagementSyatem
{
    public partial class BrowseMajor : Form
    {
        public static string t1;
        public static string t2;
        public static string t3;
        public static string[] array = new string[100];
        public static int index;
        public BrowseMajor()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void BrowseMajor_Load(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            //获取所有专业
            
            string sql = "SELECT * FROM major";
            MySqlCommand com = new MySqlCommand(sql, conn);
            MySqlDataReader reader = com.ExecuteReader();
            listBox1.Items.Clear();
            listBox1.Items.Add(string.Format("专业编号       专业名          专业说明"));
            int i = 0;
            while (reader.Read())
            {
                listBox1.Items.Add(string.Format("{0,5}\t{1,10}\t{2,10}",reader[0],reader[1],reader[2]));
                array[i++] = (string)reader[0];//将编号依次存入数组
            }
            reader.Close();


        }

        private void button2_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            if (listBox1.SelectedIndex > 0)
            {
                //删除这个专业的学生
                string sql3 = "DELETE student FROM Student,Class WHERE  Student.classId=Class.classId AND Class.majorId='"+array[listBox1.SelectedIndex - 1]+"'";
                MySqlCommand comdt = new MySqlCommand(sql3, conn);
                comdt.ExecuteNonQuery();
                //先删除在这个专业的所有班级
                string sql1 = "DELETE FROM Class WHERE class.majorId='"+ array[listBox1.SelectedIndex - 1] + "'";
                MySqlCommand comd = new MySqlCommand(sql1, conn);
                comd.ExecuteNonQuery();

                //删除专业
                #region 删除
                string sql = "DELETE FROM major WHERE majorId='" + array[listBox1.SelectedIndex - 1] + "'";
                MySqlCommand cmd = new MySqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
                #endregion
                MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.Hide();
            }
            

        }
       
        private void button1_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            
            if (listBox1.SelectedIndex > 0)
            {
                //查数据
                string sql2 = "select * from major where majorId='" + array[listBox1.SelectedIndex - 1] + "'";
                MySqlCommand cmdd = new MySqlCommand(sql2, conn);
                MySqlDataReader reader = cmdd.ExecuteReader();
                while (reader.Read())
                {
                    t1 = (string)reader[0];
                    t2 = (string)reader[1];
                    t3 = (string)reader[2];
                }
                reader.Close();
                BrowseMajor.index = listBox1.SelectedIndex - 1;
                UpdateMajor stu = new UpdateMajor();
                stu.Show(this);
                this.Hide();
                
            }    
            
        }
    }
}

在这里插入图片描述

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 MySql.Data.MySqlClient;

namespace studentStatusManagementSyatem
{
    public partial class UpdateMajor : Form
    {
        public UpdateMajor()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void UpdateMajor_Load(object sender, EventArgs e)
        {
            textBox1.Text = BrowseMajor.t1;
            textBox2.Text = BrowseMajor.t2;
            textBox3.Text = BrowseMajor.t3;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
          
            //string newt1 = textBox1.Text;
            string newt2 = textBox2.Text;
            string newt3 = textBox3.Text;
            string sql="UPDATE major SET  majorName = '"+newt2+"', majorExplain = '"+newt3+"' WHERE majorid = '"+ BrowseMajor.array[BrowseMajor.index] + "'";
            MySqlCommand com = new MySqlCommand(sql, conn);
            com.ExecuteNonQuery();
            MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            this.Hide();
        }
    }
}

(五)班级管理

添加班级
在这里插入图片描述

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 MySql.Data.MySqlClient;
namespace studentStatusManagementSyatem
{
    public partial class AddClass : Form
    {
        public AddClass()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            if (classId.Text=="")
            {
                MessageBox.Show("班级编号不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }else if (className.Text == "")
            {
                MessageBox.Show("班级名称不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                string banjiId = classId.Text;
                string banjiName = className.Text;
                string banzhur = teacher.Text;
                string renshu = count.Text;
                //获得专业名称
                string zhuanye = "";
                if (major.SelectedIndex != -1)
                {
                    zhuanye = major.SelectedItem.ToString();
                }
                else
                {
                    major.SelectedIndex = 0;
                }
                //获得专业id
                string zhuanyeId="";
                string sql = "select majorId from major where majorName='" + zhuanye + "'";
                MySqlCommand comt = new MySqlCommand(sql,conn);
                MySqlDataReader reader = comt.ExecuteReader();
                while (reader.Read())
                {
                    zhuanyeId =(string) reader[0];
                }
                reader.Close();
                MySqlCommand comm = new MySqlCommand();
                string shuoming = emplain.Text;
                string sql1 = "select count(*) from Class where ClassId='" + banjiId + "'";
                MySqlCommand com = new MySqlCommand(sql1, conn);
                if (Convert.ToInt32(com.ExecuteScalar()) > 0)//班级存在
                {
                    MessageBox.Show("此班级已存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else//添加进数据库
                {
                    string sql2 = "insert into Class set classId='" + banjiId + "',className='" + banjiName + "',classCount='" + renshu + "',teacher='"+banzhur+"',classExplain='"+shuoming+"',majorId='"+zhuanyeId+"'";
                    MySqlCommand com2 = new MySqlCommand(sql2, conn);
                    com2.ExecuteNonQuery();
                    MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.Hide();                 
                }

               

            }
        }

        private void AddClass_Load(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            //导入专业进集合

            MySqlCommand st = new MySqlCommand("select majorName from major", conn);
            MySqlDataReader reader1 = st.ExecuteReader();
            major.Items.Clear();
            while (reader1.Read())
            {
                major.Items.Add((string)reader1[0]);
            }
            reader1.Close();
        }
    }
}

班级浏览
在这里插入图片描述

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 MySql.Data.MySqlClient;

namespace studentStatusManagementSyatem
{
   
    public partial class BrowseClass : Form
    {
        public static string t1 = "";
        public static string t2 = "";
        public static string t3 = "";
        public static string t4 = "";
        public static string t5 = "";
        public static string t6 = "";
        public static string[] array = new string[100];
        public static int index;
        public BrowseClass()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            string classId = classid.Text;
            string sql = "select * from Class where classId='" + classId + "'";
            MySqlCommand com = new MySqlCommand(sql, conn);
            MySqlDataReader reader = com.ExecuteReader();
            listBox1.Items.Clear();
            listBox1.Items.Add("班级编号\t班级名称\t班级人数\t班主任\t  班级说明\t");
            while(reader.Read()){
                listBox1.Items.Add(string.Format("{0}\t{1}\t{2}\t\t{3}\t  {4}", reader[0], reader[1], reader[2], reader[4], reader[3] ));
                
            }
            if (listBox1.Items.Count == 1)
            {
                MessageBox.Show("不存在此班级", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            if (listBox1.SelectedIndex>0)
            {
                //先删除这个班的学生
                string sql3 = "DELETE student FROM Student WHERE  Student.classId='" + array[listBox1.SelectedIndex - 1] + "'";
                MySqlCommand comdt = new MySqlCommand(sql3, conn);
                comdt.ExecuteNonQuery();
                //删除
                #region 删除
                string sql = "DELETE FROM Class WHERE ClassId='" + array[listBox1.SelectedIndex-1] + "'";
                MySqlCommand cmd = new MySqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
                #endregion
                MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.Hide();
            }
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex>0)
            {
                index = listBox1.SelectedIndex - 1;
                #region 连接数据库
                //定义连接字符串
                string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
                MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
                conn.Open();//打开数据库
                #endregion
                string sql = "select * from Class where classId='" + array[index] + "'";
                MySqlCommand com = new MySqlCommand(sql, conn);
                MySqlDataReader reader = com.ExecuteReader();
                while (reader.Read()){
                    t1 = (string)reader[0];
                    t2 = (string)reader[1];
                    t3 = (string)reader[2];
                    t4 = (string)reader[3];
                    t5 = (string)reader[4];
                    t6 = (string)reader[5];
                }
                
                
                updateClass stu = new updateClass();
                stu.Show();
                this.Hide();
            }
           
        }

        private void BrowseClass_Load(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            //获取所有班级

            string sql = "SELECT * FROM Class";
            MySqlCommand com = new MySqlCommand(sql, conn);
            MySqlDataReader reader = com.ExecuteReader();
            listBox1.Items.Clear();
            listBox1.Items.Add(string.Format("班级编号\t班级名称\t班级人数\t班主任\t  班级说明\t"));
            int i = 0;
            while (reader.Read())
            {
                listBox1.Items.Add(string.Format("{0}\t{1}\t{2}\t\t{3}\t  {4}", reader[0], reader[1], reader[2], reader[4], reader[3]));
                array[i++] = (string)reader[0];//将编号依次存入数组
            }
            reader.Close();
        }
    }
}

修改班级信息
在这里插入图片描述

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 MySql.Data.MySqlClient;

namespace studentStatusManagementSyatem
{
    public partial class updateClass : Form
    {
        public updateClass()
        {
            InitializeComponent();
        }

        private void updateClass_Load(object sender, EventArgs e)
        {
            classId.Text = BrowseClass.t1;
            className.Text = BrowseClass.t2;
            count.Text = BrowseClass.t3;
            emplain.Text = BrowseClass.t4;
            teacher.Text = BrowseClass.t5;
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            //导入专业进集合

            MySqlCommand st = new MySqlCommand("select majorName from major", conn);
            MySqlDataReader reader1 = st.ExecuteReader();
            major.Items.Clear();
            while (reader1.Read())
            {
                major.Items.Add((string)reader1[0]);
            }
            reader1.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            string banjiId = classId.Text;
            string banjiName = className.Text;
            string banzhur = teacher.Text;
            string renshu = count.Text;

            //获得专业名称
            string zhuanye = "";
            if (major.SelectedIndex != -1)
            {
                zhuanye = major.SelectedItem.ToString();
            }
            else
            {
                major.SelectedIndex = 0;
            }
            //获得专业id
            string zhuanyeId = "";
            string sql = "select majorId from major where majorName='" + zhuanye + "'";
            MySqlCommand comt = new MySqlCommand(sql, conn);
            MySqlDataReader reader = comt.ExecuteReader();
            while (reader.Read())
            {
                zhuanyeId = (string)reader[0];
            }
            reader.Close();
            string shuoming = emplain.Text;
            string sql2 = "update Class set className='" + banjiName + "',classCount='" + renshu + "',teacher='" + banzhur + "',classExplain='" + shuoming + "',majorId='" + zhuanyeId + "' where ClassId='"+ banjiId + "'";
            MySqlCommand com2 = new MySqlCommand(sql2, conn);
            com2.ExecuteNonQuery();
             MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            this.Hide();
            
        }
    }
}

(六)学生管理

添加学生
在这里插入图片描述

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 MySql.Data.MySqlClient;

namespace studentStatusManagementSyatem
{
    public partial class AddStudent : Form
    {
        public AddStudent()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            if (studentId.Text == "")
            {
                MessageBox.Show("学号不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else if (studentName.Text == "")
            {
                MessageBox.Show("学生姓名不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                //  判断该学生是否已经存在
                string studentage = age.Text;
              
                //获得班级名称
                string banji = "";
                if (classId.SelectedIndex != -1)
                {
                    banji  = classId.SelectedItem.ToString();
                }
                else
                {
                    classId.SelectedIndex = 0;
                }
                //获得班级id
                string classid = "";
                string sql = "select ClassId from Class where className='" + banji + "'";
                MySqlCommand comt = new MySqlCommand(sql, conn);
                MySqlDataReader reader = comt.ExecuteReader();
                while (reader.Read())
                {
                    classid = (string)reader[0];
                }
                reader.Close();
                string miashu = textBox5.Text;
                string studentid = studentId.Text;
                string studentname = studentName.Text;
                string studentsex = sex.SelectedItem.ToString();
                string sql1 = "select count(*) from Student where studentId='" + studentid + "'";
                MySqlCommand com = new MySqlCommand(sql1, conn);
                if (Convert.ToInt32(com.ExecuteScalar()) > 0)//学生存在
                {
                    MessageBox.Show("此学生已存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else//添加进数据库
                {
                    string sql2 = "insert into student set studentId='" + studentid + "',studentName='" + studentname + "',sex='" + studentsex + "',age='" + studentage + "',studentExplain='"+ miashu + "',classId='"+classid+"'";
                    MySqlCommand com2 = new MySqlCommand(sql2, conn);
                    com2.ExecuteNonQuery();
                    MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.Hide();
                }
            }
        }

        private void AddStudent_Load(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            //导入班级进集合
            MySqlCommand st = new MySqlCommand("select className from Class", conn);
            MySqlDataReader reader1 = st.ExecuteReader();
            classId.Items.Clear();
            while (reader1.Read())
            {
                classId.Items.Add((string)reader1[0]);
            }
            reader1.Close();
        }
    }
}

学生浏览
在这里插入图片描述

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 MySql.Data.MySqlClient;

namespace studentStatusManagementSyatem
{
    public partial class BrowseStudent : Form
    {
        public static string t1 = "";
        public static string t2 = "";
        public static string t3 = "";
        public static string t4 = "";
        public static string t5 = "";
        public static string t6 = "";
        public static string[] array = new string[100];
        public BrowseStudent()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string studentid = studentId.Text;
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            string sql = "select * from Student where studentId='" + studentid + "'";
            MySqlCommand com = new MySqlCommand(sql, conn);
            MySqlDataReader reader = com.ExecuteReader();
            listBox1.Items.Clear();
            listBox1.Items.Add("  学号\t\t姓名\t性别\t年龄\t 班级编号\t 说明\t");
            while (reader.Read())
            {
                listBox1.Items.Add(string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", reader[0], reader[1], reader[2],reader[3],reader[5],reader[4]));
                
            }
            if (listBox1.Items.Count == 1)
            {
                MessageBox.Show("不存在此学生", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            if (listBox1.SelectedIndex>0)
            {
                //删除学生的所有成绩
                string sql1 = "delete from choose where studentId='"+ BrowseStudent.t1 + "'";
                MySqlCommand cmdt = new MySqlCommand(sql1, conn);
                cmdt.ExecuteNonQuery();
                //删除
                #region 删除
                string sql = "DELETE FROM Student WHERE studentId='" + BrowseStudent.t1 + "'";
                MySqlCommand cmd = new MySqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
                #endregion
                MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.Hide();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex> 0)
            {
                #region 连接数据库
                //定义连接字符串
                string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
                MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
                conn.Open();//打开数据库
                #endregion
                string sql = "select * from Student where studentId='" + array[listBox1.SelectedIndex-1] + "'";
                MySqlCommand com = new MySqlCommand(sql, conn);
                MySqlDataReader reader = com.ExecuteReader();
                while (reader.Read())
                {
                    t1 = (string)reader[0];
                    t2 = (string)reader[1];
                    t3 = (string)reader[2];
                    t4 = (string)reader[3];
                    t5 = (string)reader[4];
                    t6 = (string)reader[5];
                }
                
                UpdateStudent stu = new UpdateStudent();
                stu.Show(this);
                this.Hide();
            }
        }

        private void BrowseStudent_Load(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            //获取所有班级

            string sql = "SELECT * FROM student";
            MySqlCommand com = new MySqlCommand(sql, conn);
            MySqlDataReader reader = com.ExecuteReader();
            listBox1.Items.Clear();
            listBox1.Items.Add(string.Format("  学号\t\t姓名\t性别\t年龄\t 班级编号\t 说明\t"));
            int i = 0;
            while (reader.Read())
            {
                listBox1.Items.Add(string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", reader[0], reader[1], reader[2], reader[3], reader[5], reader[4]));
                array[i++] = (string)reader[0];//将编号依次存入数组
            }
            reader.Close();

        }
    }
    
}

修改学生信息
在这里插入图片描述

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 MySql.Data.MySqlClient;

namespace studentStatusManagementSyatem
{
    public partial class UpdateStudent : Form
    {
        public UpdateStudent()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            if (studentId.Text == "")
            {
                MessageBox.Show("学号不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else if (studentName.Text == "")
            {
                MessageBox.Show("学生姓名不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                //  判断该学生是否已经存在
                string studentage = age.Text;

                //获得班级名称
                string banji = "";
                if (classId.SelectedIndex != -1)
                {
                    banji = classId.SelectedItem.ToString();
                }
                else
                {
                    classId.SelectedIndex = 0;
                }
                //获得班级id
                string classid = "";
                string sql = "select ClassId from Class where className='" + banji + "'";
                MySqlCommand comt = new MySqlCommand(sql, conn);
                MySqlDataReader reader = comt.ExecuteReader();
                while (reader.Read())
                {
                    classid = (string)reader[0];
                }
                reader.Close();
                string miashu = textBox5.Text;
                string studentid = studentId.Text;
                string studentname = studentName.Text;
                string studentsex = sex.SelectedItem.ToString();
                string sql1 = "select count(*) from Student where studentId='" + studentid + "'";                        
                string sql2 = "update student set studentName='" + studentname + "',sex='" + studentsex + "',age='" + studentage + "',studentExplain='" + miashu + "',classId='" + classid + "' where studentId='"+ studentid + "'";
                MySqlCommand com2 = new MySqlCommand(sql2, conn);
                com2.ExecuteNonQuery();
                MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.Hide();
            }
        }

        private void UpdateStudent_Load(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            studentId.Text = BrowseStudent.t1;
            studentName.Text = BrowseStudent.t2;
            age.Text = BrowseStudent.t4;
            textBox5.Text = BrowseStudent.t5;
            //导入班级进集合
            MySqlCommand st = new MySqlCommand("select className from Class", conn);
            MySqlDataReader reader1 = st.ExecuteReader();
            classId.Items.Clear();
            while (reader1.Read())
            {
                classId.Items.Add((string)reader1[0]);
            }
            reader1.Close();

        }
    }
}

(七)课程管理

添加课程
在这里插入图片描述

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 MySql.Data.MySqlClient;
namespace studentStatusManagementSyatem
{
    public partial class AddCourse : Form
    {
        public AddCourse()
        {
            InitializeComponent();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            if (courseId.Text == "")
            {
                MessageBox.Show("课程编号不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }else if (courseName.Text == "")
            {
                    MessageBox.Show("课程名不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }else if (courseCredit.Text == "")
            {
                MessageBox.Show("课程学分不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                //判断课程编号是否已存在
                string courseid = courseId.Text;
                string credit = courseCredit.Text;
                string coursename = courseName.Text;
                string shuoming = textBox1.Text;
                //添加入课程表中
                string sql = "select count(*) from Course where courseId='" + courseid + "'";
                MySqlCommand com = new MySqlCommand(sql, conn);
                if (Convert.ToInt32(com.ExecuteScalar()) > 0)//课程存在
                {
                    MessageBox.Show("此课程已存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else//添加进数据库
                {
                    string sql2 = "insert into Course set courseID='" + courseid + "',courseGrade='" + credit + "',courseName='" + coursename + "',courseExplain='" + shuoming + "'";
                    MySqlCommand com2 = new MySqlCommand(sql2, conn);
                    com2.ExecuteNonQuery();
                    MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.Hide();
                }

            }
        }

        private void AddCourse_Load(object sender, EventArgs e)
        {

        }
    }
}

课程浏览
在这里插入图片描述

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 MySql.Data.MySqlClient;

namespace studentStatusManagementSyatem
{
    public partial class BrowseCourse : Form
    {
        public static string t1;
        public static string t2;
        public static string t3;
        public static string t4;
        string[] array = new string[100];
        public BrowseCourse()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void BrowseCourse_Load(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            //获取所有专业

            string sql = "SELECT * FROM course";
            MySqlCommand com = new MySqlCommand(sql, conn);
            MySqlDataReader reader = com.ExecuteReader();
            listBox1.Items.Clear();
            listBox1.Items.Add(string.Format("课程编号       课程学分          课程名称           课程说明"));
            int i = 0;
            while (reader.Read())
            {
                listBox1.Items.Add(string.Format("{0,5}\t{1,10}\t{2,15}\t{3,10}", reader[0], reader[1], reader[2],reader[3]));
                array[i++] = (string)reader[0];//将编号依次存入数组
            }
            reader.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            if (listBox1.SelectedIndex > 0)
            {
                //删除所有选课记录
                string sql1 = "delete from choose where courseId='" + array[listBox1.SelectedIndex - 1] + "'";
                MySqlCommand comt = new MySqlCommand(sql1, conn);
                comt.ExecuteNonQuery();
                //删除
                #region 删除
                string sql = "DELETE FROM Course WHERE courseId='" + array[listBox1.SelectedIndex - 1] + "'";
                MySqlCommand cmd = new MySqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
                #endregion
                MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.Hide();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion

            if (listBox1.SelectedIndex > 0)
            {
                //查数据
                string sql2 = "select * from Course where courseId='" + array[listBox1.SelectedIndex - 1] + "'";
                MySqlCommand cmdd = new MySqlCommand(sql2, conn);
                MySqlDataReader reader = cmdd.ExecuteReader();
                while (reader.Read())
                {
                    t1 = (string)reader[0];
                    t2 = (string)reader[1];
                    t3 = (string)reader[2];
                    t4 = (string)reader[3];
                }
                reader.Close();
                UpdateCourse stu = new UpdateCourse();
                stu.Show(this);
                this.Hide();
            }
        }
    }
}

课程信息修改
在这里插入图片描述

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 MySql.Data.MySqlClient;
namespace studentStatusManagementSyatem
{
    public partial class UpdateCourse : Form
    {
        public UpdateCourse()
        {
            InitializeComponent();
        }

        private void UpdateCourse_Load(object sender, EventArgs e)
        {
            courseId.Text = BrowseCourse.t1;
            courseCredit.Text = BrowseCourse.t2;
            courseName.Text = BrowseCourse.t3;
            textBox1.Text = BrowseCourse.t4;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            string courseid = courseId.Text;
            string credit = courseCredit.Text;
            string coursename = courseName.Text;
            string shuoming = textBox1.Text;
            //添加入课程表中
            string sql2 = "update  Course set courseGrade='" + credit + "',courseName='" + coursename + "',courseExplain='" + shuoming + "' where courseId='"+courseid+"'";
            MySqlCommand com2 = new MySqlCommand(sql2, conn);
            com2.ExecuteNonQuery();
            MessageBox.Show("修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
             this.Hide();
        }
    }
}

(八)成绩管理

录入成绩
在这里插入图片描述

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 MySql.Data.MySqlClient;
namespace studentStatusManagementSyatem
{
    public partial class AddScore : Form
    {
        public AddScore()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            if (studentId.Text == "")
            {
                MessageBox.Show("学号不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }else if (courseId.Text == "")
            {
                MessageBox.Show("课程号不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }else if (Score.Text == "")
            {
                MessageBox.Show("成绩不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

            }
            else
            {
                //判断是否已经录入
                string studentid = studentId.Text;
                string courseid = courseId.Text;
                string score = Score.Text;
                string sql1 = "SELECT COUNT(*) FROM choose WHERE studentId='"+studentid+"' AND courseId='"+courseid+"' ";
                //判断是否存在此学生
                string sql = "SELECT COUNT(*) FROM student WHERE studentId = '"+studentid+"'";
                MySqlCommand com1 = new MySqlCommand(sql,conn);
                // 判断是否存在此课程
                string sql3 = "SELECT COUNT(*) FROM course WHERE courseId = '" +courseid +"'";
                MySqlCommand com2 = new MySqlCommand(sql3, conn);
                MySqlCommand com = new MySqlCommand(sql1, conn);
                if (Convert.ToInt32(com1.ExecuteScalar())==0)
                {
                    MessageBox.Show("不存在此学生,请先添加", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }else if (Convert.ToInt32(com2.ExecuteScalar()) == 0)
                {
                    MessageBox.Show("不存在此课程,请先添加", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }else if (Convert.ToInt32(com.ExecuteScalar()) > 0)//成绩存在
                {
                    MessageBox.Show("此成绩已存在", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }else//添加进数据库
                {
                    string sql2 = "insert into choose set studentId='" + studentid + "',courseId='" + courseid + "',grade='"+score+"'";
                    MySqlCommand com3 = new MySqlCommand(sql2, conn);
                    com3.ExecuteNonQuery();
                    MessageBox.Show("添加成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    this.Hide();
                }
            }
        }

        private void AddScore_Load(object sender, EventArgs e)
        {

        }
    }
}

浏览成绩
在这里插入图片描述

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 MySql.Data.MySqlClient;
namespace studentStatusManagementSyatem
{
    public partial class BrowseScore : Form
    {
       public static string[] id1 = new string[100];
       public static string[] id2 = new string[100];
        public static string[] id3 = new string[100];
        public static int index;
        public BrowseScore()
        {
            InitializeComponent();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Hide();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string studentid = studentId.Text;
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            string sql = "SELECT course.courseId,student.studentId,studentName,courseName,grade FROM choose,student,course WHERE choose.courseId=course.courseId AND choose.studentId=student.studentId AND student.studentId='"+studentid+"'";
            MySqlCommand com = new MySqlCommand(sql, conn);
            MySqlDataReader reader = com.ExecuteReader();
            listBox1.Items.Clear();
            listBox1.Items.Add("课程号\t学号\t\t    姓名\t  课程名\t\t成绩");
            int i = 0;
            while (reader.Read())
            {
                listBox1.Items.Add(string.Format("{0,5}\t{1,5}\t{2,10}\t{3,10}\t{4,10}", reader[0], reader[1], reader[2], reader[3],reader[4]));
                id1[i] = (string)reader[0];
                id2[i] = (string)reader[1];
                id3[i++] = (string)reader[4];
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            #region 连接数据库
            //定义连接字符串
            string connStr = "Database=StudentStatusManagement;Data Source=127.0.0.1;port=3306;User Id=root;";
            MySqlConnection conn = new MySqlConnection(connStr);//创建Connection对象
            conn.Open();//打开数据库
            #endregion
            if (listBox1.SelectedIndex > 0)
            {
                //删除
                #region 删除
                string sql = "delete FROM choose WHERE choose.courseId='"+ id1[listBox1.SelectedIndex - 1] + "' AND choose.studentId='"+ id2[listBox1.SelectedIndex - 1] + "'";
                MySqlCommand cmd = new MySqlCommand(sql, conn);
                cmd.ExecuteNonQuery();
                #endregion
                MessageBox.Show("删除成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.Hide();
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex > 1)
            {
                index = listBox1.SelectedIndex - 1;
                UpdateSocore stu = new UpdateSocore();
                stu.Show(this);
                this.Hide();
            }
            
        }

        private void BrowseScore_Load(object sender, EventArgs e)
        {

        }
    }
}

Logo

更多推荐