大学生数据库课程设计之学生选课系统(一个超级简单的系统)

本文介绍了一个基于Windows窗体、C#语言和SQL数据库的大学生数据库课程设计项目——学生选课系统。系统包含登录界面和不同权限的操作界面,支持数据增删改,但未实现查询功能。提供了部分代码示例和数据库连接方法。
摘要由CSDN通过智能技术生成

大学数据库课程设计–一个简单的学生选课系统

一、系统简介

一个超级简单的学生选课系统,使用Windows窗体设计界面,使用C#语言实现各种功能,数据库使用的是SQL。由于时间原因,做的非常仓促,系统中没有查询功能,能够实现数据的增删改。下面开始系统演示吧。

二、系统演示

1、登录界面

在这里插入图片描述

我使用Windows窗体设计成这个样子 看着还算不错,嘻嘻。

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            if(pictureBox1.Location.X<150)
            {
                pictureBox1.Location = new Point(pictureBox1.Location.X + 1, pictureBox1.Location.Y);
            }//图标移动
            else
            {
                if(comboBox1.Text == "学生")
                {
                    string sql = "select * from Stu where Name = '" + textBox1.Text + "'and Password ='" + textBox2.Text + "'";
                    Dao dao = new Dao();
                    IDataReader dr = dao.read(sql);
                    dr.Read();
                    string Sid = dr["ID"].ToString();
                    Form3 form3 = new Form3(Sid);
                    form3.Show();//显示这个窗体
                    this.Hide();//隐藏这个窗体
                }
                else
                {
                    if(comboBox1.Text == "老师")
                    {
                        string sql = "select * from Teacher where Name = '" + textBox1.Text + "'and Password ='" + textBox2.Text + "'";
                        Dao dao = new Dao();
                        IDataReader dr = dao.read(sql);
                        dr.Read();
                        string Tid = dr["ID"].ToString();
                        Form7 form7 = new Form7(Tid);
                        form7.Show();
                        this.Hide();
                    }
                    else
                    {
                        if(comboBox1.Text == "管理员")
                        {
                            Form5 form5 = new Form5();
                            form5.Show();
                            this.Hide();
                        }
                    }
                }
            
                timer1.Stop();
            }
        }
    
       
        //判断是否登录
        private string login()
        {
            if(textBox1.Text == ""||textBox2.Text == ""||comboBox1.Text == "")
            {
                MessageBox.Show("输入不完整,请检查","提示",MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if(comboBox1.Text == "学生")
            {
                string sql = "select * from Stu where Name = '" +textBox1.Text+ "'and Password ='" +textBox2.Text+ "'";
                Dao dao = new Dao();

                IDataReader dr = dao.read(sql);
                if(dr.Read())
                {
                    return "学生";
                }
                else
                {
                    MessageBox.Show("用户名或密码错误");
                    return "-1";
                }


            }
            if(comboBox1.Text == "老师")
            {
                string sql = "select * from Teacher where Name = '" +textBox1.Text+ "'and Password ='" +textBox2.Text+ "'";
                Dao dao = new Dao();

                IDataReader dr = dao.read(sql);
                if (dr.Read())
                {
                    return "老师";
                }
                else
                {
                    MessageBox.Show("用户名或密码错误");
                    return "-1";
                }
            }
            if(comboBox1.Text == "管理员")
            {
                if(textBox1.Text == "admin"&&textBox2.Text == "admin")
                {
                    return "管理员";
                }
                else
                {
                    MessageBox.Show("用户名或密码错误");
                    return "-1";
                }
            }

            return "-1";
        }
        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = null;
            textBox2.Text = null;
            comboBox1.Text = null;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }
        //登录事件
        private void button1_Click_1(object sender, EventArgs e)
        {
            if (login() != "-1")
            {
                timer1.Start();//启动计时器控件,图片开始移动
                textBox1.Visible = false;
                textBox2.Visible = false;
                comboBox1.Visible = false;
                label1.Visible = false;
                label2.Visible = false;
                label3.Visible = false;
            }
            else
            {
                MessageBox.Show("信息错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void Form1_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();//强行结束整个程序
        }
    }

上述为系统登录的代码,请结合一些注释理解。系统登录界面,有三个权限,分别为学生、老师及管理员,在代码中,都有对应的代码 ,请仔细看。

2、学生操作界面

在这里插入图片描述

 public partial class Form3 : Form
    {
        string SID;
        public Form3(string Sid)
        {
            SID = Sid;
            InitializeComponent();
            toolStripStatusLabel3.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//显示当前时间
            toolStripStatusLabel1.Text = "欢迎学号为" + SID + "的同学登录选课系统";
            timer1.Start();
            Table();
        }
        public void Table()
        {
            dataGridView1.Rows.Clear();
            string sql = "select * from Course";
            Dao dao = new Dao();
            IDataReader dr = dao.read(sql);
            while (dr.Read())
            {
                string a, b, 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();//关闭链接
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            toolStripStatusLabel3.Text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");//显示当前时间
        }

        private void Form3_FormClosed(object sender, FormClosedEventArgs e)
        {
            Application.Exit();//强行结束整个程序
        }

        private void 选课ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string Cid = dataGridView1.SelectedCells[0].Value.ToString();//获取选中得课程号
            string sql1 = "Select * from  CourseChoose where Sid = '"+SID+"' and Cid = '"+Cid+"'";
           
            Dao dao = new Dao();
            IDataReader dc = dao.read(sql1);

            if(!dc.Read())
            {               
                string sql = "Insert into CourseChoose values('" + SID + "','" + Cid + "')";
             
                int i = dao.Execute(sql);
                if(i>0)
                {
     
  • 33
    点赞
  • 439
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值