全体起立!广州大学数据库综合设计实验

全体起立!你一个数据库能秒杀我?你要是能秒杀我,我当场,把Oracle给买下然后解散。

广州大学数据库综合实验

实验内容: 设计的数据库系统可从以下题目中选择,但不限定于以下题目,可自由选择。
需提供系统简要的需求分析,给出大体的功能介绍;完成数据库的概念结构设计,建议用PowerDesigner画出系统的逻辑结构图或物理结构图(也可以使用其他工具);任选自己熟悉的数据库管理系统和编程语言完成系统主要功能模块的开发。
系统题目参考:
1、学生成绩管理系统
2、网上书城系统
3、进销存系统
4、酒店客房管理系统
5、图书馆管理系统

我这里选的是学生成绩管理系统。
本博客部分参考师兄的博客
参考博客

具体内容

1、数据库的建立
2、数据库每个表和视图对应类的建立
3、C#窗口的开发

----------------------------------------------------------------------------------------

一、数据库的建立

E-R图:
全体起立!广州大学数据库综合设计实验_第1张图片

主要步骤:

1 创建用户lsz,密码是lsznb

create user Lsz identified by Lsznb;

grant connect,resource,unlimited tablespace to Lsz;

grant create view to Lsz;

2建表

create table student
(
sno varchar2(10) primary key,
sname varchar2(20) not null unique,
ssex char(3) check(ssex in('男','女')),
sage smallint not null,
pwd varchar(20) not null
);
create table teacher
(
tno varchar(7) primary key,
tname varchar(20) not null unique,
tposition varchar(20) not null,
tsalary smallint not null,
pwd varchar(20) not null
);
create table course
(
cno varchar(4) primary key,
cname varchar(40) not null unique,
ccredit smallint not null,
tno varchar(7) not null,
foreign key (tno) references teacher(tno)
);
create table sc
(
sno varchar(10) not null,
cno varchar(4) not null,
grade smallint not null,
primary key(sno,cno),
foreign key (sno) references student(sno),
foreign key (cno) references course(cno)
);

3插入数据

insert into student(sname,ssex,sno, sage, pwd) values('王志伟','男','180610001',20,'123456');

insert into student(sname,ssex,sno, sage, pwd) values('刘旋启','女','180610002',19,'123456');

insert into student(sname,ssex,sno, sage, pwd) values('薯饼','女','180610011',18,'123456');

insert into student(sname,ssex,sno, sage, pwd) values('白曹彤','男','180610012',19,'123456');

insert into student(sname,ssex,sno, sage, pwd) values('黎样宁','男','180610021',19,'123456');

insert into teacher(tno,tname, tposition, tsalary, pwd) values('t001','张三','教授',20000,'123456');

insert into teacher(tno,tname, tposition, tsalary, pwd) values('t002','李四','副教授',15000,'123456');

insert into teacher(tno,tname, tposition, tsalary, pwd) values('t003','王五','教授',35000,'123456');

insert into teacher(tno,tname, tposition, tsalary, pwd) values('t004','王八蛋','副教授',38000,'123456');

insert into teacher(tno,tname, tposition, tsalary, pwd) values('t005','李冰冰','副教授',42000,'123456');

insert into teacher(tno,tname, tposition, tsalary, pwd) values('t006','张芬芳','教授',60000,'123456');

insert into course values('6','数值分析',2,'t001');

insert into course values('2','高等数学',4,'t002');

insert into course values('7','C++语言',4,'t003');

insert into course values('5','数据结构',4,'t002');

insert into course values('1','数据库',4,'t003');

insert into course values('3','汇编语言',3,'t004');

insert into course values('4','操作系统',3,'t005');

insert into sc values('180610001','1',92);

insert into sc values('180610001','2',85);

insert into sc values('180610001','3',88);

insert into sc values('180610002','2',90);

insert into sc values('180610002','3',80);

留部分数据后面建立视图没问题再插入
4建立视图

create view courseinfo as select course.cno 课程编号,course.cname 课程名称,teacher.tname 任课老师,course.ccredit 课程学分,countnum 选修人数,
avg_grade 平均分,max_grade 最高分,min_grade 最低分 from teacher,
course left outer join (select cname, count(*) countnum,avg(grade) avg_grade,max(grade) max_grade,min(grade) min_grade from sc,course 
where course.cno=sc.cno group by cname)a1 on (course.cname=a1.cname) where teacher.tno=course.tno;

create view studentinfo as select student.sno 学号,student.sname 姓名,(select sum(grade) from sc where sno=student.sno) 总分 ,
(select sum(ccredit) from course where cno in (select cno from sc where sno=student.sno)) 总学分 ,
(select max(grade) from sc where sc.sno in (student.sno)) 最高分,(select min(grade) from sc where sc.sno in (student.sno)) 最低分 from student;

create view teacherinfo1 as select tposition 职位,count(tno) 在任人数,avg(tsalary) 平均工资 from teacher group by tposition;

create view teacherinfo2 as select tno 教师工号,tname 教师名称,(select count(student.sno) from student,sc,course where student.sno=sc.sno and sc.cno=course.cno and course.tno=teacher.tno) 授课学生总人数 from teacher;

5保存

Commit

建成后的大概样式:
全体起立!广州大学数据库综合设计实验_第2张图片

二、数据库每个表和视图对应类的建立

我一共建立了8个类(还有一个是User类,用于用户登录) 不过再建立类之前有个操作是下载oracle的插件

链接oracle的语句是

OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=xxxx))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";

注意在app里面查看自己的主机地址号(xxxx)

Student.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Oracle.ManagedDataAccess.Client;
using System.Configuration;
using System.Windows;
using System.Security.AccessControl;

namespace StudentOracleMangement
{
    class Student
    {
        public string sno { get; set; }
        public string sname { get; set; }
        public string ssex { get; set; }
        public string sage { get; set; }
        public string pwd { get; set; }   
        public static void Copy()//镜像
        {
            UserInformation.cs.Clear();//初始化
            string SelectSQL = "select sno,sname,ssex,sage,pwd from student where " +
                "sname like :sname";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":sname",
                OracleDbType.Char, 20) };
            para[0].Value = "%";
            List<Student> list = new List<Student>();
            //创建连接,创建对象
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(SelectSQL, con);
                cmd.Parameters.AddRange(para);
                OracleDataReader odr = cmd.ExecuteReader();
                while (odr.Read())
                {
                    Student s = new Student();
                    s.sno = odr["sno"].ToString();
                    s.sname = odr.GetString(1);
                    s.ssex = odr.GetString(2);
                    s.sage = Convert.ToString(odr.GetInt32(3));
                    s.pwd = odr.GetString(4);
                    list.Add(s);
                    //拷贝镜像                    
                    CopyStudent ns = new CopyStudent();
                    ns.sno = s.sno;
                    ns.sname = s.sname;
                    ns.ssex = s.ssex;
                    ns.sage = s.sage;
                    ns.pwd = s.pwd;
                    UserInformation.cs.Add(ns);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();//关闭连接
            }
        }
        public static List<Student> SelectStudent(string sname)//查询学生
        {           
            string SelectSQL = "select sno,sname,ssex,sage,pwd from student where " +
                "sname like :sname";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":sname",
                OracleDbType.Char, 20) };
            para[0].Value = sname + "%";
            List<Student> list = new List<Student>();
            //创建连接,创建对象
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();     
                OracleCommand cmd = new OracleCommand(SelectSQL, con);
                cmd.Parameters.AddRange(para);
                OracleDataReader odr = cmd.ExecuteReader();
                while(odr.Read())
                {
                    Student s = new Student();                   
                    s.sno = odr["sno"].ToString();
                    s.sname = odr.GetString(1);
                    s.ssex = odr.GetString(2);
                    s.sage = Convert.ToString(odr.GetInt32(3));
                    s.pwd = odr.GetString(4);                 
                    list.Add(s);                   
                }
            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }finally
            {
                con.Close();//关闭连接
            }
            return list;
        }
        public static List<Student> SelectStudent2(string sno)//根据学号查询学生
        {
            string SelectSQL = "select sno,sname,ssex,sage,pwd from student where " +
                "sno like :sno";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":sno",
                OracleDbType.Char, 20) };
            para[0].Value = sno + "%";
            List<Student> list = new List<Student>();
            //创建连接,创建对象
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(SelectSQL, con);
                cmd.Parameters.AddRange(para);
                OracleDataReader odr = cmd.ExecuteReader();
                while (odr.Read())
                {
                    Student s = new Student();
                    s.sno = odr["sno"].ToString();
                    s.sname = odr.GetString(1);
                    s.ssex = odr.GetString(2);
                    s.sage = Convert.ToString(odr.GetInt32(3));
                    s.pwd = odr.GetString(4);
                    list.Add(s);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();//关闭连接
            }
            return list;
        }
        public static List<Student> SelectStudent3(string sno)//根据学号查询学生(不显示密码)
        {
            string SelectSQL = "select sno,sname,ssex,sage,pwd from student where " +
                "sno like :sno";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":sno",
                OracleDbType.Char, 20) };
            para[0].Value = sno + "%";
            List<Student> list = new List<Student>();
            //创建连接,创建对象
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(SelectSQL, con);
                cmd.Parameters.AddRange(para);
                OracleDataReader odr = cmd.ExecuteReader();
                while (odr.Read())
                {
                    Student s = new Student();
                    s.sno = odr["sno"].ToString();
                    s.sname = odr.GetString(1);
                    s.ssex = odr.GetString(2);
                    s.sage = Convert.ToString(odr.GetInt32(3));
                    s.pwd = "******";
                    list.Add(s);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();//关闭连接
            }
            return list;
        }
        public static int DeleteStudent(string sno)//删除
        {
            int result = 0;
            string sql = "delete from student where sno=:sno";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":sno", OracleDbType.Char, 10) };
            para[0].Value = sno;
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                result = cmd.ExecuteNonQuery();
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }finally
            {
                con.Close();
            }
            return result;
        }
        public static int InsertStudent(Student s)//插入
        {
            int result = 0;
            string sql = "insert into student(sno,sname,ssex,sage,pwd) values(:sno,:sname,:ssex,:sage,:pwd)";
            OracleParameter[] para = new OracleParameter[] {new OracleParameter(":sno",OracleDbType.Char,10),
            new OracleParameter(":sname",OracleDbType.Char,20),
            new OracleParameter(":ssex",OracleDbType.Char,3),
            new OracleParameter(":sage",OracleDbType.Int32),
            new OracleParameter(":pwd",OracleDbType.Char,20)};
            para[0].Value = s.sno;
            para[1].Value = s.sname;
            para[2].Value = s.ssex;
            para[3].Value = s.sage;
            para[4].Value = s.pwd;
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                result = cmd.ExecuteNonQuery();

            } catch (Exception ex){
                MessageBox.Show(ex.Message);
            }finally
            {
                con.Close();
            }
            return result;
        }
        public static int UpdateStudent(Student s)//更新数据
        {
            int result = 0;
            string sql = "update student set sname=:sname,ssex=:ssex,sage=:sage,pwd=:pwd where sno=:sno";
            OracleParameter[] para = new OracleParameter[] {new OracleParameter(":sname",OracleDbType.Char,20),
            new OracleParameter(":ssex",OracleDbType.Char,20),
            new OracleParameter(":sage",OracleDbType.Int32),
            new OracleParameter(":pwd",OracleDbType.Char,20),   
            new OracleParameter(":sno",OracleDbType.Char,10)};//接口
            para[0].Value = s.sname;
            para[1].Value = s.ssex;
            para[2].Value = s.sage;
            para[3].Value = s.pwd;
            para[4].Value = s.sno;
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                result = cmd.ExecuteNonQuery();
            }catch (Exception ex){
                MessageBox.Show(ex.Message);
            }finally
            {
                con.Close();
            }
            return result;
        }
    }
}

StudentInfo.cs

using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace StudentOracleMangement
{
    class StudentInfo
    {
        public string 学号 { get; set; }
        public string 姓名 { get; set; }
        public double 总分 { get; set; }
        public double 总学分 { get; set; }
        public double 最高分 { get; set; }
        public double 最低分 { get; set; }
        public static List<StudentInfo> SelcetStudentInfo(string sno)
        {
            string sql = "select *from studentinfo where 学号 like :学号";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":学号", OracleDbType.Char, 20) };
            para[0].Value =sno+ "%";
            //MessageBox.Show(tname+"%");
            List<StudentInfo> list = new List<StudentInfo>();
            //创建链接,打开连接,创建命令对象,执行命令,关闭连接
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                OracleDataReader odr = cmd.ExecuteReader();
                while (odr.Read())
                {
                    StudentInfo s = new StudentInfo();
                    s.学号 = odr["学号"].ToString();
                    s.姓名 = odr.GetString(1);
                    if (odr.IsDBNull(2))
                    {
                        s.总分 =0;
                    }
                    else
                    {
                        s.总分 = odr.GetDouble(2);
                    }
                    if (odr.IsDBNull(3))
                    {
                        s.总学分 = 0;
                    }
                    else
                    {
                        s.总学分 = odr.GetDouble(3);
                    }
                    if (odr.IsDBNull(4))
                    {
                        s.最高分 = 0;
                    }
                    else
                    {
                        s.最高分 = odr.GetDouble(4);
                    }
                    if (odr.IsDBNull(5))
                    {
                        s.最低分 = 0;
                    }
                    else
                    {
                        s.最低分 = odr.GetDouble(5);
                    }                                                   
                    list.Add(s);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            
            return list;
        }
    }
}

Teachers.cs

using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace StudentOracleMangement
{
    
    class Teachers
    {
        public string tno { get; set; }
        public string tname { get; set; }
        public string 职位 { get; set; }
        public double 工资 { get; set; }
        public string pwd { get; set; }
        public static List<Teachers> SelectTeacher(string tname)//查询老师
        {            
            string SelectSQL = "select tno,tname,tposition,tsalary,pwd from teacher where " +
                "tname like :tname";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":tname",
                OracleDbType.Char, 20) };
            para[0].Value = tname + "%";
            List<Teachers> list = new List<Teachers>();
            //创建连接,创建对象
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(SelectSQL, con);
                cmd.Parameters.AddRange(para);
                OracleDataReader odr = cmd.ExecuteReader();
                while (odr.Read())
                {
                    Teachers s = new Teachers();
                    s.tno = odr["tno"].ToString();
                    s.tname = odr.GetString(1);
                    s.职位 = odr.GetString(2);
                    s.工资 = Convert.ToDouble(odr.GetInt32(3));
                    s.pwd = odr.GetString(4);
                    list.Add(s);                    
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();//关闭连接
            }
            return list;
        }
        public static List<Teachers> SelectTeacher2(string tname)//查询老师(不显示密码)
        {
            string SelectSQL = "select tno,tname,tposition,tsalary,pwd from teacher where " +
                "tname like :tname";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":tname",
                OracleDbType.Char, 20) };
            para[0].Value = tname + "%";
            List<Teachers> list = new List<Teachers>();
            //创建连接,创建对象
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(SelectSQL, con);
                cmd.Parameters.AddRange(para);
                OracleDataReader odr = cmd.ExecuteReader();
                while (odr.Read())
                {
                    Teachers s = new Teachers();
                    s.tno = odr["tno"].ToString();
                    s.tname = odr.GetString(1);
                    s.职位 = odr.GetString(2);
                    s.工资 = Convert.ToDouble(odr.GetInt32(3));
                    s.pwd = "******";
                    list.Add(s);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();//关闭连接
            }
            return list;
        }
        public static int DeleteTeacher(string tno)//删除
        {
            int result = 0;
            string sql = "delete from teacher where tno=:tno";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":tno", OracleDbType.Char, 10) };
            para[0].Value = tno;
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                result = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return result;
        }

        public static void Copy()//镜像教师信息
        {
            UserInformation.ts.Clear();//初始化
            string SelectSQL = "select tno,tname,tposition,tsalary,pwd from teacher where " +
                "tname like :tname";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":tname",
                OracleDbType.Char, 20) };
            para[0].Value = "%";            
            //创建连接,创建对象
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(SelectSQL, con);
                cmd.Parameters.AddRange(para);
                OracleDataReader odr = cmd.ExecuteReader();
                while (odr.Read())
                {
                    Teachers s = new Teachers();
                    s.tno = odr["tno"].ToString();
                    s.tname = odr.GetString(1);
                    s.职位 = odr.GetString(2);
                    s.工资 = Convert.ToDouble(odr.GetInt32(3));
                    s.pwd = odr.GetString(4);                   
                    //拷贝镜像

                    CopyTeacher ns = new CopyTeacher();
                    ns.tno = s.tno;
                    ns.tname = s.tname;
                    ns.职位 = s.职位;
                    ns.工资 = s.工资;
                    ns.pwd = s.pwd;
                    UserInformation.ts.Add(ns);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();//关闭连接
            }
        }

        public static int InsertTeacher(Teachers s)//插入
        {
            int result = 0;
            string sql = "insert into teacher(tno,tname,tposition,tsalary,pwd) values(:tno,:tname,:职位,:工资,:pwd)";
            OracleParameter[] para = new OracleParameter[] {new OracleParameter(":tno",OracleDbType.Char,10),
            new OracleParameter(":tname",OracleDbType.Char,20),
            new OracleParameter(":职位",OracleDbType.Char,3),
            new OracleParameter(":工资",OracleDbType.Double),
            new OracleParameter(":pwd",OracleDbType.Char,20)};
            para[0].Value = s.tno;
            para[1].Value = s.tname;
            para[2].Value = s.职位;
            para[3].Value = s.工资;
            para[4].Value = s.pwd;
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                result = cmd.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return result;
        }
        public static int UpdateTeacher(Teachers s)//更新数据
        {
            int result = 0;
            string sql = "update teacher set tname=:tname,tposition=:职位,tsalary=:工资,pwd=:pwd where tno=:tno";
            OracleParameter[] para = new OracleParameter[] {new OracleParameter(":tname",OracleDbType.Char,20),
            new OracleParameter(":职位",OracleDbType.Char,20),
            new OracleParameter(":工资",OracleDbType.Int32),
            new OracleParameter(":pwd",OracleDbType.Char,20),
            new OracleParameter(":tno",OracleDbType.Char,10)};//接口
            para[0].Value = s.tname;
            para[1].Value = s.职位;
            para[2].Value = s.工资;
            para[3].Value = s.pwd;
            para[4].Value = s.tno;
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                result = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return result;
        }
    }
}

TeacherInfo.cs

using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace StudentOracleMangement
{
    class TeacherInfo
    {
        public string 职位 { get ; set ; }
        public int 在任人数 { get; set; }
        public double 平均工资 { get; set; }
        public string 教师工号{ get; set; }
        public string 教师姓名 { get; set; }
        public int 授课学生总人数 { get; set; }
        public static List<TeacherInfo> SelectTeacher()
        {
            string sql = "select *from teacherinfo1 where 职位 like :职位";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":职位", OracleDbType.Char, 7) };
            para[0].Value = "%";
            //MessageBox.Show(tname+"%");
            List<TeacherInfo> list = new List<TeacherInfo>();
            //创建链接,打开连接,创建命令对象,执行命令,关闭连接
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                OracleDataReader odr = cmd.ExecuteReader();
                while(odr.Read())
                {
                    TeacherInfo s = new TeacherInfo();
                    s.职位 = odr["职位"].ToString();
                    s.在任人数 = odr.GetInt32(1);
                    if(odr.IsDBNull(2))
                    {
                        s.平均工资 = 0;
                    }
                    else
                    {
                        s.平均工资 = odr.GetDouble(2);
                    }
                    list.Add(s);
                }
            }catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }finally
            {
                con.Close();
            }
            return list;
        }
        public static List<TeacherInfo> SelectTeacher2(string tno)
        {
            string sql = "select *from teacherinfo2 where 教师工号 like :教师工号";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":教师工号", OracleDbType.Char, 7) };
            para[0].Value = tno + "%";
            List<TeacherInfo> list = new List<TeacherInfo>();
            //创建链接,打开连接,创建命令对象,执行命令,关闭连接
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                OracleDataReader odr = cmd.ExecuteReader();
                while (odr.Read())
                {
                    TeacherInfo s_infon = new TeacherInfo();
                    //c.Cno = odr.GetString(0); //ord["cno'].
                    s_infon.教师工号 = odr["教师工号"].ToString();
                    //t.tno = odr.GetString(0);
                    s_infon.教师姓名 = odr.GetString(1);
                    if (odr.IsDBNull(2))
                        s_infon.授课学生总人数 = 0;
                    else
                        s_infon.授课学生总人数 = odr.GetInt32(2);

                    list.Add(s_infon);
                }
            }catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return list;
        }
    }
}

Course.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using Oracle.ManagedDataAccess.Client;
namespace StudentOracleMangement
{
    class Course
    {
        //对Course表操作
        public string cno { get; set; }
        public string cname { get; set; }
        public double ccredit { get; set; }
        public string tno { get; set; }
        public static List<Course> SelectCourse(string cname)//查询课程
        {
            string SelectSQL = "select cno,cname,ccredit,tno from course where " +
                "cname like :cname";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":cname",
                OracleDbType.Char, 20) };
            para[0].Value = cname + "%";
            List<Course> list = new List<Course>();
            //创建连接,创建对象
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(SelectSQL, con);
                cmd.Parameters.AddRange(para);
                OracleDataReader odr = cmd.ExecuteReader();
                while (odr.Read())
                {
                    Course s = new Course();
                    s.cno = odr["cno"].ToString();
                    s.cname = odr.GetString(1);                   
                    s.ccredit = odr.GetDouble(2);                   
                    s.tno =odr.GetString(3);               
                    list.Add(s);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();//关闭连接
            }
            return list;
        }
        public static int DeleteCourse(string cno)//删除
        {
            int result = 0;
            string sql = "delete from course where cno=:cno";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":cno", OracleDbType.Char, 10) };
            para[0].Value = cno;
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                result = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return result;
        }
        public static int InsertCourse(Course s)//插入
        {
            int result = 0;
            string sql = "insert into course(cno,cname,ccredit,tno) values(:cno,:cname,:ccredit,:tno)";
            OracleParameter[] para = new OracleParameter[] {new OracleParameter(":cno",OracleDbType.Char,10),
            new OracleParameter(":cname",OracleDbType.Char,20),
            new OracleParameter(":ccredit",OracleDbType.Double),
            new OracleParameter(":tno",OracleDbType.Char,10)};
            para[0].Value = s.cno;
            para[1].Value = s.cname;
            para[2].Value = s.ccredit;
            para[3].Value = s.tno;
            
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                result = cmd.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return result;
        }
        public static int UpdateCourse(Course s)//更新数据
        {
            int result = 0;
            string sql = "update course set cname=:cname,ccredit=:ccredit,tno=:tno where cno=:cno";
            OracleParameter[] para = new OracleParameter[] {new OracleParameter(":cname",OracleDbType.Char,20),
            new OracleParameter(":ccredit",OracleDbType.Double),
            new OracleParameter(":tno",OracleDbType.Char,10),           
            new OracleParameter(":cno",OracleDbType.Char,10)};//接口
            para[0].Value = s.cname;
            para[1].Value = s.ccredit;
            para[2].Value = s.tno;
            para[3].Value = s.cno;

            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                result = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return result;
        }
    }
}

*CourseInfo.cs

using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace StudentOracleMangement
{
    class CourseInfo
    {
        public string 课程编号 { get; set; }
        public string 课程名称 { get; set; }
        public string 任课老师 { get; set; }
        public double 课程学分 { get; set; }
        public int 选修人数 { get; set; }
        public double 平均分 { get; set; }
        public double 最高分 { get; set; }
        public double 最低分 { get; set; }
        public static List<CourseInfo> SelectCourseInfo(string cno)
        {
           
            string sql = "select *from courseinfo where 课程编号 like :课程编号";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":课程编号", OracleDbType.Char, 20) };
            para[0].Value = cno + "%";
            //MessageBox.Show(tname+"%");
            List<CourseInfo> list = new List<CourseInfo>();
            //创建链接,打开连接,创建命令对象,执行命令,关闭连接
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                OracleDataReader odr = cmd.ExecuteReader();
                while (odr.Read())
                {
                    CourseInfo s = new CourseInfo();
                    s.课程编号 = odr["课程编号"].ToString();
                    s.课程名称 = odr.GetString(1);
                    s.任课老师 = odr.GetString(2);
                    if (odr.IsDBNull(3))
                    {
                        s.课程学分 = 0;
                    }
                    else
                    {
                        s.课程学分 = odr.GetDouble(3);
                    }
                    if (odr.IsDBNull(4))
                    {
                        s.选修人数 = 0;
                    }
                    else
                    {
                        s.选修人数 = odr.GetInt32(4);
                    }
                    if (odr.IsDBNull(5))
                    {
                        s.平均分 = 0;
                    }
                    else
                    {
                        s.平均分 = odr.GetDouble(5);
                    }
                    if (odr.IsDBNull(6))
                    {
                        s.最高分 = 0;
                    }
                    else
                    {
                        s.最高分 = odr.GetDouble(6);
                    }
                    if (odr.IsDBNull(7))
                    {
                        s.最低分 = 0;
                    }
                    else
                    {
                        s.最低分 = odr.GetDouble(7);
                    }
                    list.Add(s);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }

            return list;
        }

    }
}

SC.cs

using Oracle.ManagedDataAccess.Client;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting.Metadata.W3cXsd2001;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

namespace StudentOracleMangement
{
    class SC
    {
        //对SC表操作    可以用于学生选课和老师给学生成绩
        public string sno { get; set; }//学号
        public string cno { get; set; }//课程号
        public double grade { get; set; }//成绩
        public static List<SC> SelectSC(string sno)//查询学生选课成绩
        {
            string SelectSQL = "select sno,cno,grade from sc where " +
                "sno like :sno";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":sno",
                OracleDbType.Char, 10) };
            para[0].Value = sno + "%";
            List<SC> list = new List<SC>();
            //创建连接,创建对象
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(SelectSQL, con);
                cmd.Parameters.AddRange(para);
                OracleDataReader odr = cmd.ExecuteReader();
                while (odr.Read())
                {
                    SC s = new SC();
                    s.sno = odr["sno"].ToString();
                    s.cno = odr.GetString(1);
                    if (odr.IsDBNull(2))
                    {
                        s.grade = 0;
                    }
                    else
                    {
                        s.grade = odr.GetDouble(2);
                    }
                    list.Add(s);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();//关闭连接
            }
            return list;
        }
        public static int DeleteSC(string sno)//根据学号删除学生成绩
        {
            int result = 0;
            string sql = "delete from sc where sno=:sno";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":sno", OracleDbType.Char, 10) };
            para[0].Value = sno;
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                result = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return result;
        }
        public static int DeleteSC2(string cno)//根据课程号删除学生成绩
        {
            int result = 0;
            string sql = "delete from sc where cno=:cno";
            OracleParameter[] para = new OracleParameter[] { new OracleParameter(":sno", OracleDbType.Char, 10),
                new OracleParameter(":cno", OracleDbType.Char, 10) };
            para[1].Value = cno;
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                result = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return result;
        }
        public static int InsertSC(SC s)//插入
        {
            int result = 0;
            string sql = "insert into sc(sno,cno,grade) values(:sno,:cno,:grade)";
            OracleParameter[] para = new OracleParameter[] {new OracleParameter(":sno",OracleDbType.Char,10),
            new OracleParameter(":cno",OracleDbType.Char,10),
            new OracleParameter(":grade",OracleDbType.Double)};
            para[0].Value = s.sno;
            para[1].Value = s.cno;
            para[2].Value = s.grade;      
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                result = cmd.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return result;
        }
        public static int InsertSC2(string Ssno,string Scno)//学生选课,添加sno和cno,grade为0
        {
            int result = 0;
            string sql = "insert into sc(sno,cno,grade) values(:sno,:cno,:grade)";
            OracleParameter[] para = new OracleParameter[] {new OracleParameter(":sno",OracleDbType.Char,10),
            new OracleParameter(":cno",OracleDbType.Char,10),
            new OracleParameter(":grade",OracleDbType.Double)};
            para[0].Value = Ssno;
            para[1].Value = Scno;
            para[2].Value = 0;
            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                result = cmd.ExecuteNonQuery();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return result;
        }
        public static int UpdateSC(SC s)//更新数据
        {
            int result = 0;
            string sql = "update sc set grade=:grade where sno=:sno and cno=:cno";
            OracleParameter[] para = new OracleParameter[] {new OracleParameter(":grade",OracleDbType.Double),          
            new OracleParameter(":sno",OracleDbType.Char,10),
             new OracleParameter(":cno",OracleDbType.Char,10)};//接口
            para[0].Value = s.grade;
            para[1].Value = s.sno;
            para[2].Value = s.cno;
           

            OracleConnection con = new OracleConnection(/*ConfigurationManager.ConnectionStrings["strCon"].ConnectionString*/);
            con.ConnectionString = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORACLE)));Persist Security Info=True;User ID=lsz;Password=Lsznb;";
            try
            {
                con.Open();
                OracleCommand cmd = new OracleCommand(sql, con);
                cmd.Parameters.AddRange(para);
                result = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return result;
        }
    }
}

UserInformation.cs(用于用户登录)

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

namespace StudentOracleMangement
{
    //镜像,用于存放学生和老师的基本信息
    //学生类镜像
    public class CopyStudent
    {

        public string sno { get; set; }
        public string sname { get; set; }
        public string ssex { get; set; }
        public string sage { get; set; }
        public string pwd { get; set; }
    }
    public class CopyTeacher
    {

        public string tno { get; set; }
        public string tname { get; set; }
        public string 职位 { get; set; }
        public double 工资 { get; set; }
        public string pwd { get; set; }
    }

    public class UserInformation
    {
        public static List<CopyStudent> cs = new List<CopyStudent>();//存放student表里面的信息
        public static List<CopyTeacher> ts = new List<CopyTeacher>();//存放teacher表里面的信息
        public UserInformation()
        {           
        }
    } 
}


小总结:

  1. 基本思路一致(查找函数、添加函数、删除函数、更新函数)
  2. 注意的地方是有的表比如sc表里面有两个外键,那么在窗口实现的时候注意不要修改。
  3. 在存用户信息的时候用委托的方式可以在管理员操作后及时载入,避免添加了新用户,其却登不了系统。

三、C#窗口的开发

登录界面预览:
全体起立!广州大学数据库综合设计实验_第3张图片
cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Oracle.ManagedDataAccess.Client;
using static StudentOracleMangement.登录界面;
using static StudentOracleMangement.Teacher;
using static StudentOracleMangement.Manger;
namespace StudentOracleMangement
{
    /// 
    /// MainWindow.xaml 的交互逻辑
    /// 
    public partial class MainWindow : Window
    {
        public 登录界面 form1 = new 登录界面();
        public Teacher form2 = new Teacher();
        public Manger form3 = new Manger();
        public MainWindow()
        {
            InitializeComponent();
        }
        private void 登录界面_RMW()
        {
            form1.Hide();
            this.Show();
        }
        private void 教师界面_RMW()
        {
            form2.Hide();
            this.Show();
        }
        private void 管理界面_RMW()
        {
            form3.Hide();
            this.Show();
        }

        private void login_Click(object sender, RoutedEventArgs e)//登录
        {
            if (xStudent.IsChecked == true) //跳转到学生管理界面
            {
                bool flag1 = false;
                foreach (var a in UserInformation.cs)
                {
                    if (a.sname == user.Text && a.pwd == password.Password)//找到了
                    {
                        flag1 = true;form1.s = a;form1.Title ="学生 :"+ user.Text;
                        form1.Show();
                        this.Hide();//当前窗口隐藏
                        form1.RMW += new ReturnMainWindow(登录界面_RMW);
                    }
                }
                if(!flag1)//没找到
                {
                    System.Windows.MessageBox.Show("账号或者密码错误!");
                }
            }
            else if (Teacher.IsChecked == true)//跳转到教师管理界面
            {
                bool flag1 = false;
                foreach (var a in UserInformation.ts)
                {
                    if (a.tname == user.Text && a.pwd == password.Password)
                    {
                        flag1 = true;form2.t = a;form2.Title = "教师 :"+user.Text;
                        form2.Show();
                        this.Hide();//当前窗口隐藏  
                        form2.RMW += new ReturnMainWindow3(教师界面_RMW);
                    }
                }
                if (!flag1)//没找到
                {
                    System.Windows.MessageBox.Show("账号或者密码错误!");
                }
            }
            else if (user.Text == "manger" && password.Password == "333" && Manger.IsChecked == true)//跳转到管理员界面
            {
                form3.Show();
                this.Hide();//当前窗口隐藏              
                form3.RMW += new ReturnMainWindow2(管理界面_RMW);
            }
            else
            {
                System.Windows.MessageBox.Show("账号或者密码错误!");
            }
        }
        private void Out_Click(object sender, RoutedEventArgs e)//退出程序
        {
            Application.Current.Shutdown();
        }

        private void Close_EnD(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void Load_Information(object sender, RoutedEventArgs e)//导入学生数据
        {
            Student.Copy();
            Teachers.Copy();
        }
    }
}

学生界面预览:
全体起立!广州大学数据库综合设计实验_第4张图片
cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using static StudentOracleMangement.Student;
namespace StudentOracleMangement
{
    /// 
    /// 登录界面.xaml 的交互逻辑
    /// 
    public partial class 登录界面 : Window
    {
        //定义委托返回主窗口
        public event ReturnMainWindow RMW;
        public delegate void ReturnMainWindow();
        public CopyStudent s = new CopyStudent();        
        public 登录界面()
        {
            InitializeComponent();
        }

        private void Return_Click(object sender, RoutedEventArgs e)
        {
            RMW();
        }

        private void Select_Click(object sender, RoutedEventArgs e)//查询
        {          
            this.dataGridView1.ItemsSource = Student.SelectStudent3(this.textbox1.Text);
            this.dataGridView2.ItemsSource = StudentInfo.SelcetStudentInfo(this.textbox1.Text);
        }

        private void dataGridView1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {            
        }

        private void Student_Load(object sender, RoutedEventArgs e)//导入学生信息
        {
            this.dataGridView1.ItemsSource = Student.SelectStudent3(s.sno);
            this.dataGridView2.ItemsSource = StudentInfo.SelcetStudentInfo(s.sno);
        }

        private void Button_Click(object sender, RoutedEventArgs e)//选课
        {
            StudentSelectCourse form1 = new StudentSelectCourse();
            form1.SetSno(s.sno);
            form1.Show();
        }

        private void Close_Es(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Application.Current.Shutdown();
        }
    }
}

教师界面预览:
全体起立!广州大学数据库综合设计实验_第5张图片
cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace StudentOracleMangement
{
    /// 
    /// Teacher.xaml 的交互逻辑
    /// 
    public partial class Teacher : Window
    {
        public event ReturnMainWindow3 RMW;
        public delegate void ReturnMainWindow3();
        public CopyTeacher t = new CopyTeacher();
        public Teacher()
        {
            InitializeComponent();
        }

        private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {

        }

        private void Button_Click(object sender, RoutedEventArgs e)//返回
        {
            RMW();
        }

        private void Close_Et(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)//查询
        {
            this.dataGridView1.ItemsSource = Teachers.SelectTeacher2(textbox1.Text);
        }

        private void Load_Teacher(object sender, RoutedEventArgs e)//导入
        {
            TZW.Text = t.职位;
            TGZ.Text = t.工资.ToString();
            TNAME.Text = t.tname;
            this.dataGridView1.ItemsSource = Teachers.SelectTeacher2(t.tname);
        }

        private void MSG_Click(object sender, RoutedEventArgs e)//给学生赋成绩
        {
            MangeSC form1 = new MangeSC();
            form1.Show();
        }
    }
}

管理员界面预览:
全体起立!广州大学数据库综合设计实验_第6张图片
cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using static StudentOracleMangement.MangeStudent;
using static StudentOracleMangement.MangeTeacher;
using static StudentOracleMangement.MangeCourse;
using static StudentOracleMangement.MangeSC;
namespace StudentOracleMangement
{
    /// 
    /// Manger.xaml 的交互逻辑
    /// 
    public partial class Manger : Window
    {
        //定义委托返回主窗口
        public event ReturnMainWindow2 RMW;
        public delegate void ReturnMainWindow2();
        public MangeStudent form1=new MangeStudent();
        public MangeTeacher form2 = new MangeTeacher();
        public MangeCourse form3 = new MangeCourse();
        public MangeSC form4 = new MangeSC();
        public Manger()
        {
            InitializeComponent();
        }

        private void MS_Click(object sender, RoutedEventArgs e)//学生
        {
            if(form1.IsDisposed)
            {
                form1 = new MangeStudent();
            }           
            form1.Show();
        }

        private void MT_Click(object sender, RoutedEventArgs e)//教师
        {
            if (form2.IsDisposed)
            {
                form2 = new MangeTeacher();
            }
            form2.Show();
        }

        private void MC_Click(object sender, RoutedEventArgs e)//课程
        {
            if (form3.IsDisposed)
            {
                form3 = new MangeCourse();
            }
            form3.Show();
        }

        private void Button_Click(object sender, RoutedEventArgs e)//返回
        {
            Student.Copy();
            Teachers.Copy();
            RMW();
        }

        private void MSC_Click(object sender, RoutedEventArgs e)//成绩
        {
            if (form4.IsDisposed)
            {
                form4 = new MangeSC();
            }
            form4.Show();
        }

        private void Close_Em(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Application.Current.Shutdown();
        }
    }
}

下面的窗口几乎换汤不换药,差不都那个思路,有手就行
学生管理窗口:
全体起立!广州大学数据库综合设计实验_第7张图片
这里要注意导入方式和DataGridView里面列的添加按钮,反正我觉得wpf的gridview有时不如dgv方便。
全体起立!广州大学数据库综合设计实验_第8张图片
点击添加项目数据源
在这里插入图片描述
全体起立!广州大学数据库综合设计实验_第9张图片
在这里添加你写的类
然后记得添加按钮(添加类)
全体起立!广州大学数据库综合设计实验_第10张图片
添加完后不要忘记调整属性
全体起立!广州大学数据库综合设计实验_第11张图片
cs

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 static StudentOracleMangement.Student;
using static StudentOracleMangement.InsertStudent;
using static StudentOracleMangement.StudentUpData;
namespace StudentOracleMangement
{
    public partial class MangeStudent : Form
    {
        public MangeStudent()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void MangeStudent_Load(object sender, EventArgs e)
        {
            this.dataGridView1.DataSource = Student.SelectStudent(this.textBox1.Text);
        }

        private void button1_Click(object sender, EventArgs e)//添加学生
        {
            InsertStudent form1 = new InsertStudent();
            form1.Show();
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (this.dataGridView1.Rows.Count == 0)
                return;
            if (e.RowIndex < 0)
                return;
            DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
            if(e.ColumnIndex==5)
            {
                //删除按钮
                string sno = row.Cells[0].Value.ToString();
                if(Student.DeleteStudent(sno)==1)
                {
                    MessageBox.Show("删除学生成功!");
                }
            }
            else
            {
                if (e.ColumnIndex == 6)
                {
                    //修改
                    Student s = (Student)row.DataBoundItem;
                    StudentUpData form1 = new StudentUpData();
                    form1.SetTextBox_Text(s.sno, s.sname, s.ssex, s.sage, s.pwd);
                    form1.Show();
                }
            }
        }

        private void Select_Click(object sender, EventArgs e)//查询
        {
            this.dataGridView1.DataSource = Student.SelectStudent(this.textBox1.Text);
        }

        private void button2_Click(object sender, EventArgs e)//统计
        {
            StudentTable form1 = new StudentTable();
            form1.Show();
        }
    }
}

这里面有些新窗口添加和更新差不多,统计则是导入视图的表
添加窗口:
全体起立!广州大学数据库综合设计实验_第12张图片
cs

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 static StudentOracleMangement.Student;
namespace StudentOracleMangement
{
    public partial class InsertStudent : Form
    {
        public InsertStudent()
        {
            InitializeComponent();
        }

        private void 添加_Click(object sender, EventArgs e)//添加
        {
            Student s = new Student();
            s.sno = SNO.Text;
            s.sname = SNAME.Text;
            s.ssex = SSEX.Text;
            s.sage = SAGE.Text;
            s.pwd = SPWD.Text;
            //存入数据库
            if(Student.InsertStudent(s)==1)
            {
                MessageBox.Show("插入学生数据成功!");
            }
        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void SPWD_TextChanged(object sender, EventArgs e)
        {

        }

        private void SAGE_TextChanged(object sender, EventArgs e)
        {

        }

        private void SSEX_TextChanged(object sender, EventArgs e)
        {

        }

        private void SNO_TextChanged(object sender, EventArgs e)
        {

        }

        private void SNAME_TextChanged(object sender, EventArgs e)
        {

        }
    }
}

统计窗口:
全体起立!广州大学数据库综合设计实验_第13张图片
cs

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 static StudentOracleMangement.StudentInfo;
namespace StudentOracleMangement
{
    public partial class StudentTable : Form
    {
        public StudentTable()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Load_Student(object sender, EventArgs e)//导入学生视图信息
        {
            this.dataGridView1.DataSource = StudentInfo.SelcetStudentInfo(this.textBox1.Text);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void Select_Click(object sender, EventArgs e)//查询
        {
            this.dataGridView1.DataSource = StudentInfo.SelcetStudentInfo(this.textBox1.Text);
        }
    }
}

其余的教师、课程、成绩类似。

有手就行

当然,学生界面还有选课功能,教师界面还有给学生评分功能(得一个教师只能评他自己教的学生的成绩)
下面举例选课功能:
全体起立!广州大学数据库综合设计实验_第14张图片
里面有两个按钮,一个选课,一个退选
cs

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 StudentOracleMangement
{
    public partial class StudentSelectCourse : Form
    {
        public string sno;
        public StudentSelectCourse()
        {
            InitializeComponent();
        }
        public void SetSno(string a)
        {
            sno = a;
        }
        private void Load_course(object sender, EventArgs e)//导入课程信息
        {
            this.dataGridView1.DataSource = Course.SelectCourse(this.textBox1.Text);
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)//表格button
        {
            if (this.dataGridView1.Rows.Count == 0)
                return;
            if (e.RowIndex < 0)
                return;
            DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
            if (e.ColumnIndex == 4)
            {
                //选课
                string cno = row.Cells[0].Value.ToString();
                if (SC.InsertSC2(sno,cno) == 1)
                {
                    MessageBox.Show("选课成功!");
                }
            }
            else
            {
                //退课
                if (e.ColumnIndex == 5)
                {
                    string cno = row.Cells[0].Value.ToString();
                    if (SC.DeleteSC2(cno) == 1)
                    {
                        MessageBox.Show("退课成功!");
                    }
                }
            }
        }

        private void Select_Click(object sender, EventArgs e)//查询
        {
            this.dataGridView1.DataSource = Course.SelectCourse(this.textBox1.Text);
        }
    }
}

部分总结:

  1. 就是一个学生表,里面可以添加、修改、删除学生,还能打包学生的数据,统计成新的表格(前面建立的学生视图)。
  2. 其余的教师、课程、成绩类似。
  3. 管理员返回时因为伴随数据的修改应当通过委托的方式来更新用户信息,通过学生类和教师类的Copy()

总结

0.整个运行结果图:

全体起立!广州大学数据库综合设计实验_第15张图片
全体起立!广州大学数据库综合设计实验_第16张图片
全体起立!广州大学数据库综合设计实验_第17张图片
全体起立!广州大学数据库综合设计实验_第18张图片
全体起立!广州大学数据库综合设计实验_第19张图片
全体起立!广州大学数据库综合设计实验_第20张图片
全体起立!广州大学数据库综合设计实验_第21张图片
全体起立!广州大学数据库综合设计实验_第22张图片

  1. 主要耗时点:(数据库的建立_E-R图,连接数据的接口,用户类的建立_要在需要镜像的类里面copy_可能是我想多了,试了几种办法,发现解决问题还挺简单的)
  2. 数据结构的上下级关系(程序运行的顺序)

全体起立!广州大学数据库综合设计实验_第23张图片

  1. 实验报告一个个截图贴代码比较费时
  2. 比较繁琐,但是基本思路差不多。本次实验也是多亏了师兄的数据库建立思路才能顺利完成。

评价:建库一时爽,编程火葬场

你可能感兴趣的:(实验报告,oracle,c#,wpf,.net,visual,studio,code)