Java学生选课系统实验报告 下载本文

edit2.Text:=trim(adoquery1.fieldbyname('xm').AsString); edit3.Text:=trim(adoquery1.fieldbyname('bjmc').AsString); listcourse(id); //列出已选课程 //允许开始选课 bitbtn2.Enabled:=true; bitbtn3.Enabled:=true; //bitbtn4.Enabled:=true; end else begin

//只有在籍学生才能选课

showmessage('该生非在籍学生,不能选课'); bitbtn2.Enabled:=false; bitbtn3.Enabled:=false; id:=''; end; end; end;

//--------显示学生已经选的课程---------- procedure TCourseElect.listcourse(id: string); begin

//将符合选课条件的学生已经选过的课程列在表中 adoquery2.Close; adoquery2.SQL.Clear; adoquery2.SQL.Add('select

XSXX.xh,XKB.kxh,KCXX.kcmc,js,kkxb,KCB.sksjt,sksjj,skdd

from

KCB,XSXX,KCXX,XKB where XKB.kxh=KCB.kxh and XKB.xh=XSXX.xh and KCXX.kcbh=KCB.kcbh'); adoquery2.Open; end;

//---------------课程查询-------------------

29

procedure TCourseElect.BitBtn1Click(Sender: TObject); begin

if(edit4.Text='')and(edit5.Text='')and(edit6.Text='')and(edit7.Text='')then showmessage('请输入查询条件!') else begin

adoquery3.Close; adoquery3.SQL.Clear; adoquery3.SQL.Add('select

KCB.kxh,KCXX.kcbh,kcmc,js,kkxb,pym,KCB.sksjt,sksjj,skdd KCB,XSXX,KCXX,XKB');

adoquery3.SQL.Add('where (XKB.kxh=KCB.kxh and XKB.xh=XSXX.xh and KCXX.kcbh=KCB.kcbh) KCXX.kcmc='''+edit5.Text+'''or XKB.kxh='''+edit7.Text+''')'); Adoquery3.Open;

if(Adoquery3.RecordCount=0)then showmessage('找不到这门课程!') else begin

DBGrid2.DataSource.DataSet:=Adoquery3; DBGrid2.DataSource.DataSet.Active:=false; DBGrid2.DataSource.DataSet.Active:=true; end; end; end;

//-----------将选择的课程添加到学生的选课表中-------------- procedure TCourseElect.BitBtn2Click(Sender: TObject); var num:string; day,section:integer;

and

(KCXX.pym='''+edit4.Text+'''or KCXX.kcbh='''+edit6.Text+'''or

from

30

begin

//未选择课程时,不允许提交 if adoquery3.RecordCount=0 then begin

showmessage('请先选择一门课程'); exit; end;

num:=trim(dbgrid2.Fields[0].Text);//保存课序号

//判断所选的课程是否已选和是否与其他已经选的课程有时间冲突 adoquery1.Close; adoquery1.SQL.Clear;

adoquery1.SQL.Add('select sksjt,sksjj from KCB');

adoquery1.SQL.Add('where kcbh='''+dbgrid2.Fields[1].Text+''''); adoquery1.Open;

while not adoquery1.Eof do begin

day:=adoquery1.fieldbyname('sksjt').AsInteger; section:=adoquery1.fieldbyname('sksjj').AsInteger; adoquery2.First;

while not adoquery2.Eof do begin

//判断课程是否已选

if (trim(adoquery2.fieldbyname('kxh').AsString)=num) then begin

showmessage('所选的课程:'+trim(adoquery2.fieldbyname('kcmc').AsString)+' 已在课表中,请选择其他课程'); exit; end;

//判断课程是否与已选课程有时间冲突 if

(adoquery2.fieldbyname('sksjt').AsInteger=day)and(adoquery2.fieldbyname('sksjj').A

31

sInteger=section) then begin

showmessage('

'+trim(adoquery2.fieldbyname('kcmc').AsString)+' 冲突!'); exit; end;

adoquery2.Next; end;

adoquery1.Next; end; //选课

adocommand1.CommandText:='insert

values('''+id+''','''+trim(dbgrid2.Fields[0].Text)+''')'; adocommand1.Execute; listcourse(id);//刷新数据表 end;

//-------------删除已选课程-------------

procedure TCourseElect.BitBtn3Click(Sender: TObject); begin

if application.MessageBox('确实删除所选课程?','确定删除',MB_OKCANCEL)=IDOK then begin

adocommand1.CommandText:='delete

from

XKB

where

into

XKB([xh],[kxh])

(xh='''+trim(dbgrid3.Fields[0].Text)+''')and(kxh='''+trim(dbgrid3.Fields[1].Text)+''')'; adocommand1.Execute; listcourse(id);//刷现列表 end; end;

procedure TCourseElect.FormClose(Sender: TObject;

32