数据库专题训练数据库应用系统开发

数据库专题训练实验-------数据库应用系统开发

【实验目的】

  1. 掌握数据库连接技术

【实验环境】

Sql server 2018

Visual Studio 2022

【实验内容】

  1. 需求分析

数据库是一种存储数据并对数据进行操作的工具。数据库的作用在于组织和表达信息,简而言之,数据库就是信息的集合。计算机的数据库可以分为两类:非关系数据库和关系数据库。关系数据库中包含了多个数据表的信息,数据库含有各个不同部分的术语,如记录、域等。

SQLserver 2018就是关系数据库开发工具,数据库能汇集各种信息以供查询、存储和检索。SQL 的优点在于它集数据查询、数据操纵、数据定义和数据控制功能于一体。

教务处的管理人员录入全校的课程基本信息和本学期的课程授课教师、地点、时间;

在学生入学的时候,学院的管理人员录入学生基本信息;

学生每学期自己上网登录系统选课,选课成功后信息存入数据库中,学生自己可以查询选课的情况;

学生选课不成功的情况有:

所选课程的先修课还没有记录,系统提示“缺先修课,选课失败”;

本学期所选课程的上课时间有冲突,系统提示“上课时间有冲突,选课失败”;

学生一学期所选课程的学分最多不能超18学分

学生可以注销所选课程。

学院管理员可以查询学生前几学期的选课信息、可以查询课程基本信息、学生基本信息;

当学生退学时,由教务处的管理人注销学生基本信息

如果开课之后,学生要求退课,则由教务处的工作人员为学生注销所选课程;

允许学生休学,教务处为休学的退学做学籍冻结处理;复学后为其办理解冻处理;

每学期教务处为学生办理学期注册手续;没有办理学期注册的学生不能选课;

学期末,学院工作人员负责录入学生的成绩。

2、用户设计

登录界面设计

教务处界面设计

学院界面设计

学生界面设计

 

 

 

         

学院登录后:

     

学生登录后界面:    

【整体代码】

登录界面代码:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Data.SqlClient;

namespace WindowsFormsApplication1

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void butEnter_Click(object sender, EventArgs e)

        {

            string userkind = this.userkindcmb.Text;

            string userid = this.textBox1.Text;

            string userpwd = this.textBox2.Text;

            string userpwddb;

            string queryString = "select * from ADMINISTRATOR where ID = " + userid + " and DEPARTMENT = '" + userkind + "' and PASSWORD = '" + userpwd + "'";

            //MessageBox.Show(queryString);

           // SqlConnection connection = new SqlConnection("server=.;integrated security=true;database=XKXT");

            SqlConnection connection = new SqlConnection("server=.;integrated security=true;database=XKXT");

            //sqlexpress;

            // queryString = "select PASSWORD from ADMINISTRATOR where NAME=" + userid;

            DataSet ds = new DataSet();

            SqlDataAdapter adapter = new SqlDataAdapter();

           

            adapter.SelectCommand = new SqlCommand(queryString, connection);

          

            adapter.Fill(ds);

            userpwddb = ds.Tables[0].Rows[0][0].ToString();

            if (userkind.Length == 0 || userid.Length == 0 || userpwd.Length == 0)

                MessageBox.Show("输入下信息不完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

            else

            {

                if (userpwddb == userpwd)

                {

                    MessageBox.Show("成功登录", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    if (userkind == "教务处")

                    {

                         frm_admin frmadmin = new frm_admin();

                         frmadmin.strUserid = userid;

                         frmadmin.Show();

                    }

                    if (userkind == "学院")

                    {

                        frm_school frmschool = new frm_school();

                        frmschool.strUserid = userid;

                        frmschool.Show();

                    } if (userkind == "学生")

                    {

                        frm_student frmstudent = new frm_student();

                        frmstudent.strUserid = userid;

                        frmstudent.Show();

                    }

                    //关闭登录界面

                    this.Visible = false;

                    textBox1.Text = "";

                    textBox2.Text = "";

                    userkindcmb.Text = "";

                }

                else

                {

                    MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

            }

        }

        private void butExit_Click(object sender, EventArgs e)

        {

            //退出

            Application.Exit();              

        }

        private void textBox2_TextChanged(object sender, EventArgs e)

        {

        }

        private void textBox1_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.Windows.Forms;

using System.Data.SqlClient;

namespace WindowsFormsApplication1

{

    public partial class frm_admin : Form

    {

        public string strUserid;

        public frm_admin()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            this.Close();

        }

        //private void button2_Click(object sender, EventArgs e)

        private void textBox1_TextChanged(object sender, EventArgs e)

        {

        }

    

        private void button2_Click_1(object sender, EventArgs e)

        {

            //密码修改

            string userpwd = textBox1.Text;

            string queryString = "select * from ADMINISTRATOR where ID = " + strUserid + " and DEPARTMENT = '教务处'";

            SqlConnection connection = new SqlConnection("server=.;integrated security=true;database=XKXT");

            DataSet ds = new DataSet();

            SqlDataAdapter adapter = new SqlDataAdapter();

            SqlCommandBuilder scb = new SqlCommandBuilder(adapter);   //数据更新时用

            adapter.SelectCommand = new SqlCommand(queryString, connection);

            adapter.Fill(ds);

            ds.Tables[0].Rows[0][1] = userpwd;

            adapter.Update(ds);

            MessageBox.Show("密码已经成功修改", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }

        private void button3_Click(object sender, EventArgs e)

        {

            //增加一门课程记录的例子

            SqlConnection connection = new SqlConnection("server=.;integrated security=true;database=XKXT");

            DataSet ds = new DataSet();

            SqlDataAdapter adapter = new SqlDataAdapter();

            SqlCommandBuilder scb = new SqlCommandBuilder(adapter);      //数据更新时用

            int id = int.Parse(textBox2.Text);

            string name = textBox3.Text;

            string classroom = textBox4.Text;

            string teacher = textBox5.Text;

            string time = textBox6.Text;

            int credit = int.Parse(textBox7.Text);

            string note = textBox9.Text;

            int precourse = 0;

            if (textBox8.Text != "")

                     precourse = int.Parse(textBox8.Text);

            string queryString = "select * from C where 1=0";

            //MessageBox.Show(queryString);

            adapter.SelectCommand = new SqlCommand(queryString, connection);

            adapter.Fill(ds);

            DataRow dr = ds.Tables[0].NewRow();

            dr["ID"] = id;

            dr["NAME"] = name;

            dr["CLASSROOM"] = classroom;

            dr["TEACHER"] = teacher;

            dr["TIME"] = time;

            dr["CREDIT"] = credit;

            dr["NOTE"] = note;

            if (precourse != 0)

                dr["PRECOURSE"] = precourse;

            ds.Tables[0].Rows.Add(dr);

            adapter.Update(ds);

       

        MessageBox.Show("成功添加", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }

        private void button4_Click(object sender, EventArgs e)

        {

          

        }

        private void button5_Click(object sender, EventArgs e)

        {

            //删除某学生的选课记录的例子

            SqlConnection connection = new SqlConnection("server=.;integrated security=true;database=XKXT");

            DataSet ds = new DataSet();

            SqlDataAdapter adapter = new SqlDataAdapter();

            SqlCommandBuilder scb = new SqlCommandBuilder(adapter);       //数据更新时用

            string id = textBox11.Text;

            string queryString = "select * from SC where SID = " + id;

            adapter.SelectCommand = new SqlCommand(queryString, connection);

            adapter.Fill(ds);

            //MessageBox.Show(ds.Tables[0].Rows[0][0].ToString());

            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)

                ds.Tables[0].Rows[i].Delete();

            adapter.Update(ds);

            MessageBox.Show("该学生选课记录已经删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

        }

        private void button7_Click(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.Windows.Forms;

using System.Data.SqlClient;

namespace WindowsFormsApplication1

{

    public partial class frm_school : Form

    {

        public string strUserid;

        public frm_school()

        {

            InitializeComponent();

        }

        private void button1_Click(object sender, EventArgs e)

        {

            this.Close();

        }

        private void frm_school_Load(object sender, EventArgs e)

        {

            // TODO: 这行代码将数据加载到表“xKXTDataSet2.C”中。您可以根据需要移动或删除它。

            this.cTableAdapter.Fill(this.xKXTDataSet2.C);

            // TODO: 这行代码将数据加载到表“xKXTDataSet1.SC”中。您可以根据需要移动或删除它。

            this.sCTableAdapter.Fill(this.xKXTDataSet1.SC);

            // TODO: 这行代码将数据加载到表“xKXTDataSet.S”中。您可以根据需要移动或删除它。

            this.sTableAdapter.Fill(this.xKXTDataSet.S);

        }

        private void button2_Click(object sender, EventArgs e)

        {

            //密码修改

            string userpwd = textBox1.Text;

            string queryString = "select * from ADMINISTRATOR where ID = " + strUserid + " and DEPARTMENT = '教务处'";

            SqlConnection connection = new SqlConnection("server=(local)\\sqlexpress;integrated security=true;database=XKXT");

            DataSet ds = new DataSet();

            SqlDataAdapter adapter = new SqlDataAdapter();

            SqlCommandBuilder scb = new SqlCommandBuilder(adapter);   //数据更新时用

            adapter.SelectCommand = new SqlCommand(queryString, connection);

            adapter.Fill(ds);

            ds.Tables[0].Rows[0][1] = userpwd;

            adapter.Update(ds);

        }

        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)

        {

        }

        private void button3_Click(object sender, EventArgs e)

        {

        }

    }

}

表值对应:

【功能举例演示】

1、打开登录界面,合理填充个人信息

如果有没填的报错,提示  

if (userkind.Length == 0 || userid.Length == 0 || userpwd.Length == 0)

             MessageBox.Show("输入下信息不完整", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

按照数据库信息正确登录:

成功登录:

在课程录入中正确填写信息:

 

返回数据库查看新添加的信息,刷新:

可以看到能够正常运行。

其他功能不在一一演示,代码部分列举。

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
一、单项选择题 (只有一个正确答案) 【1】 执行语句"SELECT '2008-01-20'+ INTERVAL 2 DAY; "结果为 A: 2008-01-22 B: 2010-01-20 C: 2008-02-11 D: 2008-03-20 答案: A 【2】 下列哪个是不正确的MySQL的变量命名方式 A: _name B: n$ame C: name D: name! 答案: D 【3】 字符串'hel'lo'输出结果为 A: hel'lo B: 'hello' C: hel\'lo D: 'hel lo' 答案: A 【4】 关系数据库模型是以下哪种方式组织数据结构 A: 树状 B: 文本 C: 二维表 D: 网状 答案: C 【5】 使用下列哪个语句可以删除表中所有数据,但保留表结构 A: truncate table B: rename table C: delete D: drop talbe 答案: A 【6】 E-R图设计属于( )。 A: 概念结构设计 B: 物理结构设计 C: 逻辑结构设计 D: 需求分析设计 答案: B 【7】 执行语句"GREATEST(10,9,128,1)"结果为( )。 A: 9 B: 10 C: 128 D: 1 答案: C 【8】 在一个关系中,若有这样一个属性存在,它的值能唯一地标识关系中的每一个元组,则 称这个属性为 A: 数据项 B: 候选码 C: 主键 D: 主键值 答案: C 【9】 数据库管理系统能实现对数据库中数据的查询、插入、修改和删除等操作。这种功能称 为( )。 A: 数据控制功能 B: 数据操纵功能 C: 数据管理功能 D: 数据定义功能 答案: B 【10】 1999年10月1日在mysql中表示方法错误的是: A: "1999-10-01" B: "1999%10%01" C: "1999\10\01" D: "1999/10/01" 答案: D 【11】 两个表中的行按照给定的条件进行拼接而形成新表的运算为 A: 连接 B: 投影 C: 集合 D: 选择 答案: A 【12】 向表中插入一个行新的纪录的命令为 A: replace into B: insert into C: replace from D: insert from 答案: B 【13】 \n在MySQL中表示 A: " B: 退格符 C: 回车符 D: 换行符 答案: D 【14】 执行语句"SELECT '5' = '5ab';"结果为 A: 0 B: NULL C: False D: 1 答案: A 【15】 显示所有错误的命令 A: show variables B: show warrings C: show errors D: show databases 答案: C 【16】 下列哪项不属于数据库模型的: A: 逻辑 B: 网状 C: 关系 D: 层次 答案: A 【17】 修改数据库的命令为: A: alter database B: Create database C: use database D: drop database 答案: A 【18】 创建表的命令为: A: Create table B: alter table C: drop table D: rename table 答案: A 【19】 删除表的命令为( )。 A: alter table B: drop table C: rename table D: Create table 答案: B 【20】 求查询结果的和的函数为 A: COUNT() B: MIN C: SUM D: MAX 答案: C 【21】 在关系数据库中一个关系是指 A: 一个二维表 B: 表中的一列 C: 表中的一行 D: 表中列的取值围 答案: A 【22】 数据库管理系统的简称为( )。 A: DBMS B: MDBS C: DB D: DBA 答案: A 【23】 数据库表中的基本运算不包括( )。 A: 选择 B: 集合 C: 连接 D: 投影 答案: B 【24】 下列哪个语句指定查询目的 A: from B: select C: grup by D: where 答案: B 【25】 换行是下列哪个转义字符 A: \" B: \n C: \\ D: \' 答案: B 【26】 消除查询结果中重复纪录的关键字为 A: distinct B: having C: ALL D: limit 答案: A 【27】 创建数据库的命令为( )。 A: use database B: Create database C: alter database D: drop database 答案: B 【28】 以下不是
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

编程图一乐

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

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

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

打赏作者

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

抵扣说明:

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

余额充值