开发环境
软件环境:Intel® Core™ i5-7200U CPU @2.50GHz 2.70 GHz
硬件环境:Win10
开发工具:PB,SQL server
语言:PB
基于实验一的三个表采用嵌入式SQL语言实现数据库的录入、修改和删除等管理功能。或者也可以采用PB实用教程中的第4部分,完成综合应用实习的编程实现。
数据库:
数据库表中定义与实验一要求一样
功能分析设计
功能图:
E-R图
源程序清单和结果
open()事件:
// Profile student
SQLCA.DBMS = "ODBC"
SQLCA.DBParm = "ConnectString='DSN=student;UID=sa;PWD=123'"
Connect;
sc_management:
cb_5:
string s_no,s_class,c_no,s_grade
s_no=trim(sle_3.text)
s_class=trim(sle_2.text)
DECLARE sc_cursor CURSOR FOR
SELECT sclass,sno,cno,grade
FROM SC
WHERE sclass=:s_class and sno=:s_no;
lb_1.reset()
Open sc_cursor;
FETCH sc_cursor INTO :s_class,:s_no,:c_no,:s_grade;
DO WHILE sqlca.sqlcode=0
lb_1.additem("班级:"+s_class+"学号:"+s_no+"课号:"+c_no+"成绩:"+s_grade)
FETCH sc_cursor INTO :s_class,:s_no,:c_no,:s_grade;
LOOP
Close sc_cursor;
cb_4:
string s_no,s_class,c_no,s_grade
s_no=trim(sle_3.text)
s_class=trim(sle_2.text)
c_no=trim(sle_4.text)
s_grade=trim(sle_5.text)
update SC set sclass=:s_class,sno=:s_no,cno=:c_no,grade=:s_grade
where sno=:s_no and sclass=:s_class;
DECLARE sc_cursor CURSOR FOR
SELECT sclass,sno,cno,grade
FROM SC
WHERE sclass=:s_class and sno=:s_no;
lb_1.reset()
Open sc_cursor;
FETCH sc_cursor INTO :s_class,:s_no,:c_no,:s_grade;
DO WHILE sqlca.sqlcode=0
lb_1.additem("班级:"+s_class+"学号:"+s_no+"课号:"+c_no+"成绩:"+s_grade)
FETCH sc_cursor INTO :s_class,:s_no,:c_no,:s_grade;
LOOP
Close sc_cursor;
course_management:
string c_no,c_name,c_pno,c_credit
c_no=trim(sle_1.text)
c_name=trim(sle_2.text)
c_pno=trim(sle_3.text)
c_credit=trim(sle_4.text)
insert into Course(cno,cname,cpno,ccredit)
values( :c_no,:c_name,:c_pno,:c_credit);
if SQLCA.sqlcode=0 then
MessageBox("提示信息","录入成功")
else
MessageBox("提示信息","录入失败")
end if
String c_no
c_no=trim(sle_1.text)
delete from Course where cno=:c_no;
if SQLCA.sqlcode=0 then
MessageBox("提示信息","删除成功")
else
MessageBox("提示信息","删除失败")
end if
string c_no,c_name,c_pno,c_credit
c_no=trim(sle_1.text)
c_name=trim(sle_2.text)
c_pno=trim(sle_3.text)
c_credit=trim(sle_4.text)
update Course set cno=:c_no, cname=:c_name,cpno=:c_pno, ccredit=:c_credit
where cno=:c_no ;
string c_no,c_name,c_pno,c_credit
c_no=trim(sle_1.text)
c_name=trim(sle_2.text)
c_pno=trim(sle_3.text)
c_credit=trim(sle_4.text)
DECLARE sc_cursor CURSOR FOR
SELECT cno,cname,cpno,ccredit
FROM Course
WHERE cno=:c_no;
lb_1.reset()
Open sc_cursor;
FETCH sc_cursor INTO :c_no,:c_name,:c_pno,:c_credit;
DO WHILE sqlca.sqlcode=0
lb_1.additem("课程号:"+c_no+" 课程名:"+c_name+" 前驱课:"+c_pno+" 学分:"+c_credit)
FETCH sc_cursor INTO :c_no,:c_name,:c_pno,:c_credit;
LOOP
Close sc_cursor;
open(main)
student_management:
string s_class,s_no,s_name,s_sex,s_age,s_dept
s_class=trim(sle_1.text)
s_no=trim(sle_2.text)
s_name=trim(sle_3.text)
s_sex=trim(sle_4.text)
s_age=trim(sle_5.text)
s_dept=trim(sle_6.text)
insert into Student(sclass,sno,sname,ssex,sage,sdept)
values(:s_class,:s_no,:s_name,:s_sex,:s_age,:s_dept);
if SQLCA.sqlcode=0 then
MessageBox("提示信息","录入成功")
else
MessageBox("提示信息","录入失败")
end if
String s_class,s_no
s_class=trim(sle_1.text)
s_no=trim(sle_2.text)
delete from Student where sclass=:s_class and sno=:s_no;
if SQLCA.sqlcode=0 then
MessageBox("提示信息","删除成功")
else
MessageBox("提示信息","删除失败")
end if
string s_class,s_no,s_name,s_sex,s_age,s_dept
s_class=trim(sle_1.text)
s_no=trim(sle_2.text)
s_name=trim(sle_3.text)
s_sex=trim(sle_4.text)
s_age=trim(sle_5.text)
s_dept=trim(sle_6.text)
update Student set sclass=:s_class,sno=:s_no,sname=:s_name,ssex=:s_sex,sage=: s_age,sdept=:s_dept
where sno=:s_no and sclass=:s_class;
DECLARE sc_cursor CURSOR FOR
SELECT sclass,sno,sname,ssex,sage,sdept
FROM Student
WHERE sclass=:s_class and sno=:s_no;
lb_1.reset()
Open sc_cursor;
FETCH sc_cursor INTO :s_class,:s_no,:s_name,:s_sex,:s_age,:s_dept;
DO WHILE sqlca.sqlcode=0
lb_1.additem("班级:"+s_class+"学号:"+s_no+"姓名:"+s_name+"性别:"+s_sex+"年龄"+s_age+"系"+"s_dept")
FETCH sc_cursor INTO :s_class,:s_no,:s_name,:s_sex,:s_age,:s_dept;
LOOP
Close sc_cursor;
string s_class,s_no,s_name,s_sex,s_age,s_dept
s_class=trim(sle_1.text)
s_no=trim(sle_2.text)
DECLARE sc_cursor CURSOR FOR
SELECT sclass,sno,sname,ssex,sage,sdept
FROM Student
WHERE sclass=:s_class and sno=:s_no;
lb_1.reset()
Open sc_cursor;
FETCH sc_cursor INTO :s_class,:s_no,:s_name,:s_sex,:s_age,:s_dept;
DO WHILE sqlca.sqlcode=0
lb_1.additem("班级:"+s_class+" 学号:"+s_no+" 姓名:"+s_name+" 性别:"+s_sex+" 年龄"+s_age+" 系"+"s_dept")
FETCH sc_cursor INTO :s_class,:s_no,:s_name,:s_sex,:s_age,:s_dept;
LOOP
Close sc_cursor;
open(main)
运行结果
录入:
查询:
修改:
删除: