C#之教务系统 已通过答辩 成绩为优秀 需要SQL文件与原码的请自取

C#实现教学管理系统

概述

这是我大二时候写的一个管理系统 仿照学校教学管理系统实现上面内容包含还是较多的比如权限认证,数据可视化 学生功能有 选课 退课 选课当中有时间的判定 不能重复选择 查看自己课表 查看总课表 预约教室 查看成绩 查看公告 健康打卡等
老师 有录入成绩 排课 修改学生信息 查看自己的课表等
教务老师是超级用户 权限很多 有管理空教室 管理教师 给老师排课 删除这门课 新增课程 指定学分 发布系统公告 根据学号查询 姓名查询 查询健康打卡的情况 导出未打卡学生的名单等等

E-R图

在这里插入图片描述
该设计的E-R图全部应用visio画图软件画图,从实际开发中来说,数据库的表名没有部分没有依照该E-R图来完成程序(这是值得改进的一个方面)。

数据库模型

在这里插入图片描述
数据库里面我已经转储成一份SQL 文件 需要者自取
另附 我的SQL server版本是 SQL server 2014

模块功能

登录

(1)登录端口与其功能:该界面为学校的各个用户登录所用(图2.5.1),其中对身份验证不通过有相应的提示(图2.5.2),同时还提供了密码修改和输入密码时的隐藏机制(图2.5.3)。
(1),同时还提供了密码修改和输入密码时的隐藏机制(图2.5.3)。
在这里插入图片描述
图2.5.1
![在这里插入图片描述](https://img-blog.csdnimg.cn/d879c43be8e349a1a61b3033c6b361bb.png
图2.5.2
在这里插入图片描述

图2.5.3

学生界面

学生用户界面:学生端的功能具体有选课、查看课表、修改密码、预约教室、成绩查询、健康打卡等主要功能。
①我们设计了选课时判断课程时间是否冲突,当上课时间发生冲突时会告诉学生无法选择该课程(图2.5.4)。
图2.5.4
②在选课不发生不冲突的时候将会选课成功(图2.5.5)。
在这里插入图图2.5.5片描述
我们为学生设计了密码修改让学生更方便修改登录信息,我们也考虑到了安全问题,在该界面需要输入原密码才能更改,这让密码安全性更高(图2.5.6)。
在这里插入图片描述
④当代大学生需要团日活动或者使用教室进行一些日常活动,该功能提交申请由教务处审核通过(图2.5.7)。
在这里插入图片描述
⑤学生通过预约查询可以看到是否成功借用该教室。如果教务处不同意将会出现审批不通过的字样,待审核为提交的请求还为被教务处审批。(图2.5.8)。
在这里插入图片描述
⑥为了满足当前时事我们加入了健康打卡,教务处(管理员)也能导出表格进行查看完成情况。(图2.5.8)。
在这里插入图片描述
⑦查询选课情况以及课程表(图2.5.9):这里学生可以看到自己选择的课与时间同时也能查看开设的全部课程(小窗口比较多,一次性展示)。
在这里插入图片描述

老师界面

②(图2.5.12)这里我们运用SQL语句实现删除学生的操作,老师从数据库中删除该学生的相关个人信息。同时为了防止误触删除学生,我们为老师设计了确定来防止误删除。
在这里插入图片描述
③(图2.5.13)这里我们运用SQL语句实现修改学生个人信息的操作,老师可以修改学生姓名、班级、出生日期和籍贯的等相关信息。但其中作为主键的学号是没有办法修改的,一个学生只能由一个学号且不能被修改的。
在这里插入图片描述
功能较多不一一展示需要的同学们自行探索

教务老师界面

教务处老师能够管理教师的各种相关信息,能够查询老师的账号与密码以及职称等多条信息(图2.5.20)。
在这里插入图片描述
老师的个人信息会随着时间的推移和新老师的加入而改变,这里教务处可以更改老师的相应信息,来维持数据的不断变化过程。(图2.5.21)。
在这里插入图片描述
总体查询功能:我们为教务处老师查询学校教务相关信息设计了个整体查询,该功能不仅能查看学生的选课、挂科率等和相关信息(图2.5.22),同时还能查看老师的开课和相关信息(图2.5.24),最后还能查看老师和学生的打卡信息(图2.5.23)。
在这里插入图片描述
在这里插入图片描述
还可以将信息导入Excel 表格保存至本地 等等
在这里插入图片描述

部分核心代码

数据库连接部分

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Data;


namespace 图书借阅系统
{
    class Dao
    {
        public SqlConnection connect()
        {
            string str = @"Data Source=贾丙奥的PC机;Initial Catalog=Demo;Integrated Security=True";
            SqlConnection sc = new SqlConnection(str);
            sc.Open();
            return sc;
        }
       


        public SqlCommand command(string sql)
        {
            SqlCommand cmd = new SqlCommand(sql, connect());
            return cmd;
        }
        public int Execute(string sql)
        {
            return command(sql).ExecuteNonQuery();
        }
        public SqlDataReader read(string sql)
        {
            return command(sql).ExecuteReader();
        }



    }
}

学生界面代码

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 图书借阅系统
{
    
    public partial class Form30 : Form
    {
        int locax3;
        int locax4;
        int locax5;
        string CLASS;
        string SID;
        string SNAME;
        string CName;
        string notice;//公告内容
       



        public Form30()
        {
            InitializeComponent();
            locax3 = pictureBox3.Location.X;
            locax4 = pictureBox4.Location.X;
            locax5 = pictureBox5.Location.X;
            timer1.Start();
            Table();




        }



       

        public void Table()//让表显示数据
        {
           
            locax3 = pictureBox3.Location.X;
            locax4 = pictureBox4.Location.X;
            locax5 = pictureBox5.Location.X;
            string sql = "select * from Course";
            Dao dao = new Dao();
            IDataReader dr = dao.read(sql);
            dataGridView1.Rows.Clear();//先清空再重新建立
            while (dr.Read())//dr.read()每次读一行返回的为true or false;
            {
                //插入数据
                string a, b, c, d, e;
                //a 为 id b为 name c为班级 d 为生日
                a = dr["id"].ToString();
                b = dr["Name"].ToString();
                c = dr["Credit"].ToString();
                d = dr["Teacher"].ToString();
                string[] str = { a, b, c, d };//创建一个数组
                dataGridView1.Rows.Add(str);//按照行的方式进行逐行添加

            }
            dr.Close();//关闭方式

        }

        public Form30(string sID, string Sname)
        {

            //大小的代码 740 130
                      
            SID = sID;
            SNAME = Sname;
            InitializeComponent();
            Table();
            timer1.Start();
            label3.Text = Sname;
            label4.Text = sID;
            
            

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            
                if (pictureBox2.Location.X < 1380)
                {
                   if(bunifuCircleProgressbar1.Value<100)               
                  bunifuCircleProgressbar1.Value += 1;
                    pictureBox2.Location = new Point(pictureBox2.Location.X + 9, pictureBox2.Location.Y);
                    pictureBox3.Location = new Point(pictureBox3.Location.X + 9, pictureBox2.Location.Y);
                    pictureBox4.Location = new Point(pictureBox4.Location.X + 9, pictureBox2.Location.Y);
                    pictureBox5.Location = new Point(pictureBox5.Location.X + 9, pictureBox2.Location.Y);
                    
            }
            else
                {

                    pictureBox2.Location = new Point(460, 6);
                    pictureBox3.Location = new Point(locax3,6);
                    pictureBox4.Location = new Point(locax4,6 );
                    pictureBox5.Location = new Point(locax5, 6);
                bunifuCircleProgressbar1.Value = 0;

            }


        }

        private void Form30_Load(object sender, EventArgs e)
        {

        }

        private void panel6_Paint(object sender, PaintEventArgs e)
        {

        }

        private void panel5_Paint(object sender, PaintEventArgs e)
        {

        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void panel7_Paint(object sender, PaintEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {

            //获取选中课程的id
            string cID = dataGridView1.SelectedCells[0].Value.ToString();
            //获取课程名字
            string CNAME = dataGridView1.SelectedCells[1].Value.ToString();

            //获取用户名(选课学生)已经获得
            //获取班级名字
            string SS = "select class from student where id='" + SID + "'";
            Dao dao1234 = new Dao();
            dao1234.read(SS);
            IDataReader ida = dao1234.read(SS);

            while (ida.Read())
            {
                CLASS = ida["class"].ToString();
            }

            //保证一门课程只能选一次
            string sqlf = "select  *  from CourseRecord where sid='" + SID + "' and cid='" + cID + "'";
            Dao dao = new Dao();
            IDataReader dc = dao.read(sqlf);
            if (dc.Read())
            {
                MessageBox.Show("您已经选过这个课,不能重复选着");
            }
            else
            {
                //保证课程时间不能冲突
                string SQL = "select  kb.cname,kb.time,kb.jxl,kb.rid from kb,chengji where kb.cname=chengji.cname and sno='" + SID + "'and time in(select time from kb,course where Course.Name=kb.cname and cname='" + CNAME + "') ";
                Dao dao1233 = new Dao();
                dao1233.read(SQL);
                IDataReader read = dao1233.read(SQL);
                if (read.Read())//已经有这个时间段的课程不可以选课
                {
                    MessageBox.Show("课程时间冲突不可以选择", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    string sql = "insert into CourseRecord values('" + SID + "','" + cID + "')";

                    // MessageBox.Show(sql); 验证代码
                    int i = dao.Execute(sql);
                    if (i > 0)
                    {
                        MessageBox.Show("选课成功");
                    }

                    //更新成绩表
                    string SQL1 = "insert into chengji(sno,sname,class,cname)values('" + SID + "','" + SNAME + "','" + CLASS + "','" + CNAME + "')";
                    Dao dao123 = new Dao();
                    dao123.Execute(SQL1);
                }

            }

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {
            //打开form31
            Form31 form31 = new Form31(SID, CName);
            form31.Show();
            //显示所选择的课程
        }

        private void button11_Click(object sender, EventArgs e)
        {
            Form32 form32 = new Form32(SID);
            form32.ShowDialog();
        }

        private void button10_Click(object sender, EventArgs e)
        {
            Form56 form56 = new Form56();
            form56.Show();
        }

        private void button8_Click(object sender, EventArgs e)
        {

            Form54 form54 = new Form54(SNAME);
            form54.Show();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            Form33 form33 = new Form33(SID);
            form33.Show();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Form76 form76 = new Form76(SID);
            form76.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Form62 form62 = new Form62();
            form62.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Form34 form34 = new Form34(SID);
            form34.Show();
        }

        private void dataGridView1_CellContentClick_1(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void pictureBox6_Click(object sender, EventArgs e)
        {

        }

        private void panel9_Paint(object sender, PaintEventArgs e)
        {

        }

        private void button9_Click(object sender, EventArgs e)
        {
            int a;
            a = 0;
            Form501 form501 = new Form501(a);
            form501.Show();
            
        }

        private void pictureBox7_Click(object sender, EventArgs e)
        {

        }

        private void panel8_Paint(object sender, PaintEventArgs e)
        {

        }

        private void pictureBox8_Click(object sender, EventArgs e)
        {

        }

        private void panel7_Paint_1(object sender, PaintEventArgs e)
        {

        }

        private void pictureBox9_Click(object sender, EventArgs e)
        {

        }

        private void panel6_Paint_1(object sender, PaintEventArgs e)
        {

        }

        private void pictureBox10_Click(object sender, EventArgs e)
        {

        }

        private void panel10_Paint(object sender, PaintEventArgs e)
        {

        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void panel3_Paint(object sender, PaintEventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void panel4_Paint(object sender, PaintEventArgs e)
        {

        }

        private void pictureBox5_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox4_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox2_Click(object sender, EventArgs e)
        {

        }

        private void panel5_Paint_1(object sender, PaintEventArgs e)
        {

        }

        private void pictureBox11_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox12_Click(object sender, EventArgs e)
        {

        }

        private void panel12_Paint(object sender, PaintEventArgs e)
        {

        }

        private void pictureBox13_Click(object sender, EventArgs e)
        {

        }

        private void panel13_Paint(object sender, PaintEventArgs e)
        {

        }

        private void pictureBox14_Click(object sender, EventArgs e)
        {

        }

        private void panel14_Paint(object sender, PaintEventArgs e)
        {

        }

        private void pictureBox15_Click(object sender, EventArgs e)
        {

        }

        private void panel15_Paint(object sender, PaintEventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void button12_Click(object sender, EventArgs e)
        {
            
            Form301 form301 = new Form301(SNAME,SID);
            form301.Show();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(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 图书借阅系统
{
    public partial class Form20 : Form
    {
        string Tname;
        public Form20()
        {
            InitializeComponent();
            Table();//调用方法进行添加
            string sq = "select count(*) as num from student where dgree='大学生'";
            string a = "select count(*) as num2 from student where dgree='中学生'";
            string b = "select count(*) as num3 from student where dgree='小学生'";
            int count = 0;
            int count2 = 0;
            int countx = 0;
            int countm = 0;
            Dao dao = new Dao();
            dao.read(sq);
            string se;
            IDataReader re = dao.read(sq);
            IDataReader re2 = dao.read(a);
            IDataReader re3 = dao.read(b);
            if (re.Read())//大学生
            {
                se = re["num"].ToString();
                count = int.Parse(se);//转换为数字
            }
            if (re2.Read())//中学生
            {
                se = re2["num2"].ToString();
                countm = int.Parse(se);//转换为数字
            }
            if (re3.Read())//小学生
            {
                se = re3["num3"].ToString();
                countx = int.Parse(se);//转换为数字
            }
            string sq2 = "select count(id) as num from student ";
            dao.read(sq2);
            re = dao.read(sq2);
            if (re.Read())
            {
                se = re["num"].ToString();
                count2 = int.Parse(se);//转换为数字
            }
           

            if (countm != 0 && countm != 0)
            {

                bunifuCircleProgressbar2.Value = (int)(countm * 100 / count);
            }

            if (countx != 0 && countx != 0)
            {

                bunifuCircleProgressbar3.Value = (int)(countx * 100 / count);
            }

            if (count != 0 && count2 != 0)
            {

                bunifuCircleProgressbar1.Value = (int)(100 - bunifuCircleProgressbar2.Value - bunifuCircleProgressbar3.Value);
            }
            else
            {
                bunifuCircleProgressbar1.Value = 0;
            }

           
        }

        public Form20(string name)
        {
           
            InitializeComponent();
            Tname = name;
            label1.Text = name.ToString();
            Table();//调用方法进行添加
            string sq = "select count(*) as num from student where class like'机械%'";
            string a = "select count(*) as num2 from student where class like'英才%'";
            string b = "select count(id) as num3  from Student where class  not like  '英才%' and class not like '机械%'  ";
            int count = 0;
            int count2 = 0;
            int countx = 0;
            int countm = 0;
            Dao dao = new Dao();
            dao.read(sq);
            string se;
            IDataReader re = dao.read(sq);
            IDataReader re2 = dao.read(a);
            IDataReader re3 = dao.read(b);
            if (re.Read())//机械
            {
                se = re["num"].ToString();
                count = int.Parse(se);//转换为数字
            }
            if (re2.Read())//英才
            {
                se = re2["num2"].ToString();
                countm = int.Parse(se);//转换为数字
            }
            if (re3.Read())//其他
            {
                se = re3["num3"].ToString();
                countx = int.Parse(se);//转换为数字
            }
            string sq2 = "select count(id) as num from student ";
            dao.read(sq2);
            re = dao.read(sq2);
            if (re.Read())
            {
                se = re["num"].ToString();
                count2 = int.Parse(se);//转换为数字
            }


            if (countm != 0 && countm != 0)
            {

                bunifuCircleProgressbar2.Value = (int)(countm * 100 / count2);
            }

            if (countx != 0 && countx != 0)
            {

                bunifuCircleProgressbar3.Value = (int)(countx * 100 / count2);
            }

            if (count != 0 && count2 != 0)
            {

                bunifuCircleProgressbar1.Value = (int)(100 - bunifuCircleProgressbar2.Value - bunifuCircleProgressbar3.Value);
            }
            else
            {
                bunifuCircleProgressbar1.Value = 0;
            }
            

        }




        public void Table()//让表显示数据
        {
            string sql = "select * from Student";
            Dao dao = new Dao();
            IDataReader dr = dao.read(sql);
            dataGridView1.Rows.Clear();//先清空再重新建立
            while (dr.Read())//dr.read()每次读一行返回的为true or false;
            {
                //插入数据
                string a, b, c, d, e, f;
                //a 为 id b为 name c为班级 d 为生日
                a = dr["id"].ToString();
                b = dr["Name"].ToString();
                c = dr["class"].ToString();
                d = dr["birthday"].ToString();
                e = dr["JG"].ToString();                
                string[] str = { a, b, c, d, e };//创建一个数组
                dataGridView1.Rows.Add(str);//按照行的方式进行逐行添加

            }
            dr.Close();//关闭方式

        }








        private void label1_Click(object sender, EventArgs e)
        {
            string sqe = "select name from teacher where ";
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form21 form21 = new Form21(this);
            form21.ShowDialog();//不能以对话框弹出.//弹出一个子窗体仍可以对父窗体进行操作
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void button7_Click(object sender, EventArgs e)
        {
            Table();
            string sq = "select count(*) as num from student where class like'机械%'";
            string a = "select count(*) as num2 from student where class like'英才%'";
            string b = "select count(id) as num3  from Student where class  not like  '英才%' and class not like '机械%'  ";
            int count = 0;
            int count2 = 0;
            int countx = 0;
            int countm = 0;
            Dao dao = new Dao();
            dao.read(sq);
            string se;
            IDataReader re = dao.read(sq);
            IDataReader re2 = dao.read(a);
            IDataReader re3 = dao.read(b);
            if (re.Read())//机械
            {
                se = re["num"].ToString();
                count = int.Parse(se);//转换为数字
            }
            if (re2.Read())//英才
            {
                se = re2["num2"].ToString();
                countm = int.Parse(se);//转换为数字
            }
            if (re3.Read())//其他
            {
                se = re3["num3"].ToString();
                countx = int.Parse(se);//转换为数字
            }
            string sq2 = "select count(id) as num from student ";
            dao.read(sq2);
            re = dao.read(sq2);
            if (re.Read())
            {
                se = re["num"].ToString();
                count2 = int.Parse(se);//转换为数字
            }


            if (countm != 0 && countm != 0)
            {

                bunifuCircleProgressbar2.Value = (int)(countm * 100 / count2);
            }

            if (countx != 0 && countx != 0)
            {

                bunifuCircleProgressbar3.Value = (int)(countx * 100 / count2);
            }

            if (count != 0 && count2 != 0)
            {

                bunifuCircleProgressbar1.Value = (int)(100 - bunifuCircleProgressbar2.Value - bunifuCircleProgressbar3.Value);
            }
            else
            {
                bunifuCircleProgressbar1.Value = 0;
            }


        }

        private void bunifuCustomLabel1_Click(object sender, EventArgs e)
        {

        }

        private void button8_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Form20_Load(object sender, EventArgs e)
        {

        }

        private void button6_Click(object sender, EventArgs e)
        {
            DialogResult r = MessageBox.Show("确认删除么?", "提示", MessageBoxButtons.OKCancel);
            if (r == DialogResult.OK)
            {
                Dao dao = new Dao();
                string id, name;
                id = dataGridView1.SelectedCells[0].Value.ToString();
                name = dataGridView1.SelectedCells[1].Value.ToString();
                string sql2 = "delete from jiankang where id = '" + id + "' and Name = '" + name + "'";
                dao.Execute(sql2);
                string sql = "delete from student where id = '" + id + "' and Name = '" + name + "'";

                dao.Execute(sql);

                MessageBox.Show("删除成功,点击ok自动刷新", "MessageBoxButtons.OK");
                string sq = "select count(*) as num from student where class like'机械%'";
                string a = "select count(*) as num2 from student where class like'英才%'";
                string b = "select count(id) as num3  from Student where class  not like  '英才%' and class not like '机械%'  ";
                int count = 0;
                int count2 = 0;
                int countx = 0;
                int countm = 0;                
                dao.read(sq);
                string se;
                IDataReader re = dao.read(sq);
                IDataReader re2 = dao.read(a);
                IDataReader re3 = dao.read(b);
                if (re.Read())//机械
                {
                    se = re["num"].ToString();
                    count = int.Parse(se);//转换为数字
                }
                if (re2.Read())//英才
                {
                    se = re2["num2"].ToString();
                    countm = int.Parse(se);//转换为数字
                }
                if (re3.Read())//其他
                {
                    se = re3["num3"].ToString();
                    countx = int.Parse(se);//转换为数字
                }
                string sq2 = "select count(id) as num from student ";
                dao.read(sq2);
                re = dao.read(sq2);
                if (re.Read())
                {
                    se = re["num"].ToString();
                    count2 = int.Parse(se);//转换为数字
                }


                if (countm != 0 && countm != 0)
                {

                    bunifuCircleProgressbar2.Value = (int)(countm * 100 / count2);
                }

                if (countx != 0 && countx != 0)
                {

                    bunifuCircleProgressbar3.Value = (int)(countx * 100 / count2);
                }

                if (count != 0 && count2 != 0)
                {

                    bunifuCircleProgressbar1.Value = (int)(100 - bunifuCircleProgressbar2.Value - bunifuCircleProgressbar3.Value);
                }
                else
                {
                    bunifuCircleProgressbar1.Value = 0;
                }

                Table();

            }
            else
            {
                Table();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string[] str = { dataGridView1.SelectedCells[0].Value.ToString(), dataGridView1.SelectedCells[1].Value.ToString(), dataGridView1.SelectedCells[2].Value.ToString(), dataGridView1.SelectedCells[3].Value.ToString(), dataGridView1.SelectedCells[4].Value.ToString() };//获取用户输入

            Form21 form21 = new Form21(str, this);
            form21.ShowDialog();//以对话框弹出.
        }

        private void button4_Click(object sender, EventArgs e)
        {


            Form9 form9 = new Form9();
            form9.Show();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            Form79 form79 = new Form79(Tname);
            form79.Show();
        }

        private void panel3_Paint(object sender, PaintEventArgs 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 图书借阅系统
{
    public partial class Form50 : Form
    {
        int locax2;
        int locax3;
        int locax4;
        int locax5;
        int count = 0;//记录点击次数
        int count1 = 0;
        string SNAME;
        public Form50()
        {
            InitializeComponent();
            panel11.Visible = false;
            panel18.Visible = false;
            locax3 = pictureBox3.Location.X;
            locax4 = pictureBox4.Location.X;
            locax5 = pictureBox5.Location.X;
            locax2 = pictureBox2.Location.X;
            timer1.Start();
        }

        public Form50(string Sname)
        {
            InitializeComponent();
            panel11.Visible = false;
            panel18.Visible = false;
            locax3 = pictureBox3.Location.X;
            locax4 = pictureBox4.Location.X;
            locax5 = pictureBox5.Location.X;
            locax2 = pictureBox2.Location.X;
            label3.Text = Sname;
           Table();
            timer1.Start();
        }


        public void Table()//让表显示数据
        {
            string sql = "select * from shenqing";
            Dao dao = new Dao();
            IDataReader dr = dao.read(sql);
            dataGridView1.Rows.Clear();//先清空再重新建立
            while (dr.Read())//dr.read()每次读一行返回的为true or false;
            {
                //插入数据
                string a, b, c, d, e, f;
                //a 为 name b为 id c为时间 d 为申请信息 e 为申请原因
                a = dr["name"].ToString();
                b = dr["id"].ToString();
                c = dr["time"].ToString();
                d = dr["jxl"].ToString();
                e = dr["rid"].ToString();
                f = dr["reason"].ToString();
                string[] str = { a, b, c, d, e, f };//创建一个数组
                dataGridView1.Rows.Add(str);//按照行的方式进行逐行添加

            }
            dr.Close();//关闭方式

        }


        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

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

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (pictureBox2.Location.X < 1370)
            {
                if (bunifuCircleProgressbar1.Value < 100)
                    bunifuCircleProgressbar1.Value += 1;
                pictureBox2.Location = new Point(pictureBox2.Location.X + 10, pictureBox2.Location.Y);
                pictureBox3.Location = new Point(pictureBox3.Location.X + 10, pictureBox2.Location.Y);
                pictureBox4.Location = new Point(pictureBox4.Location.X + 10, pictureBox2.Location.Y);
                pictureBox5.Location = new Point(pictureBox5.Location.X + 10, pictureBox2.Location.Y);

            }
            else
            {

                pictureBox2.Location = new Point(locax2, 6);
                pictureBox3.Location = new Point(locax3, 6);
                pictureBox4.Location = new Point(locax4, 6);
                pictureBox5.Location = new Point(locax5, 6);
                bunifuCircleProgressbar1.Value = 0;

            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form55 form55 = new Form55();
            form55.Show();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if(count==0)
            {
                dataGridView1.Visible = false;
                panel11.Visible = true;
                count++;
            }
            else
            {
                dataGridView1.Visible = true;
                panel11.Visible = false;
                count--;
            }
           
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Form51 form51 = new Form51();
            form51.Show();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            Form61 form61 = new Form61();
            form61.Show();
        }

        private void button13_Click(object sender, EventArgs e)
        {
            Form59 form59 = new Form59();
            form59.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {

        }

        private void button4_Click_1(object sender, EventArgs e)
        {
            if (count1 == 0)
            {
                dataGridView1.Visible = false;
                panel18.Visible = true;
                count1++;
            }
            else
            {
                dataGridView1.Visible = true;
                panel18.Visible = false;
                count1--;
            }
        }

        private void pictureBox7_Click(object sender, EventArgs e)
        {

        }

        private void button15_Click(object sender, EventArgs e)
        {
            Form6 form6 = new Form6();
            form6.Show();
        }

        private void button14_Click(object sender, EventArgs e)
        {
            Form4 form4 = new Form4();
            form4.Show();
        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void button16_Click(object sender, EventArgs e)
        {
            Table();
        }

        private void button9_Click(object sender, EventArgs e)
        {
            Form70 form70 = new Form70();
            form70.Show();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Form501 form501 = new Form501();
            form501.Show();
        }

        private void panel3_Paint(object sender, PaintEventArgs e)
        {

        }
    }
}

导出数据保存到本地的代码

  public static bool dataGridViewToCSV(DataGridView dataGridView)
        {
            if (dataGridView.Rows.Count == 0)
            {
                MessageBox.Show("没有数据可导出!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "CSV files (*.csv)|*.csv";
            saveFileDialog.FilterIndex = 0;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.CreatePrompt = true;
            saveFileDialog.FileName = null;
            saveFileDialog.Title = "保存";
            if (saveFileDialog.ShowDialog() == DialogResult.OK)
            {
                Stream stream = saveFileDialog.OpenFile();
                StreamWriter sw = new StreamWriter(stream, System.Text.Encoding.GetEncoding(-0));
                string strLine = "";
                try
                {
                    //表头
                    for (int i = 0; i < dataGridView.ColumnCount; i++)
                    {
                        if (i > 0)
                            strLine += ",";
                        strLine += dataGridView.Columns[i].HeaderText;
                    }
                    strLine.Remove(strLine.Length - 1);
                    sw.WriteLine(strLine);
                    strLine = "";
                    //表的内容
                    for (int j = 0; j < dataGridView.Rows.Count; j++)
                    {
                        strLine = "";
                        int colCount = dataGridView.Columns.Count;
                        for (int k = 0; k < colCount; k++)
                        {
                            if (k > 0 && k < colCount)
                                strLine += ",";
                            if (dataGridView.Rows[j].Cells[k].Value == null)
                                strLine += "";
                            else
                            {
                                string cell = dataGridView.Rows[j].Cells[k].Value.ToString().Trim();
                                //防止里面含有特殊符号
                                cell = cell.Replace("\"", "\"\"");
                                //cell = "\"" + cell + "\""; //每个元素值用引号包括
                                strLine += cell;
                            }
                        }
                        sw.WriteLine(strLine);
                    }
                    sw.Close();
                    stream.Close();
                    MessageBox.Show("数据被导出到:" + saveFileDialog.FileName.ToString(), "导出完毕", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "导出错误", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
            }
            return true;
        }```
        

``

总结

创作不易 请各位关注姥爷给个关注 您的支持就是我前进的动力

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一心向上的小奥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值