?? uselecourse.pas
字號:
unit uSeleCourse;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, Grids, DBGrids, ExtCtrls, DBCtrls, DB;
type
TfrmSeleCourse = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Label1: TLabel;
Button1: TButton;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Panel3: TPanel;
Panel4: TPanel;
DBGrid1: TDBGrid;
Label5: TLabel;
MaskEdit1: TMaskEdit;
Button2: TButton;
Panel5: TPanel;
Panel6: TPanel;
Label6: TLabel;
Label7: TLabel;
DBGrid2: TDBGrid;
Button3: TButton;
Label8: TLabel;
Label9: TLabel;
Button4: TButton;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
DBEdit5: TDBEdit;
ComboBox1: TComboBox;
DBEdit1: TDBEdit;
DataSource1: TDataSource;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmSeleCourse: TfrmSeleCourse;
implementation
uses dm3; //引用數(shù)據(jù)模塊單元
{$R *.dfm}
//根據(jù)學(xué)號查詢學(xué)生信息
procedure TfrmSeleCourse.Button1Click(Sender: TObject);
var
sno:integer;
begin
sno:=strtoint(combobox1.Text);//取得學(xué)號
datamodule3.snotable.Open;
if datamodule3.snotable.Locate('sno',sno,[]) then
//如果student.db存在該學(xué)號
begin
datamodule3.snoquery.Close;
datamodule3.snoquery.ParamByName('sno').Value:=sno;
datamodule3.snoquery.Prepare;
datamodule3.snoquery.Open;
//統(tǒng)計(jì)該學(xué)生所修過的學(xué)分
datamodule3.creditalquery.Close;
datamodule3.creditalquery.ParamByName('sno').Value:=sno;
datamodule3.creditalquery.Prepare;
datamodule3.creditalquery.Open;
//在dbgrid中顯示該學(xué)生當(dāng)前所選的課程
datamodule3.SCquery.Close;
datamodule3.SCquery.ParamByName('sno').Value:=sno;
datamodule3.SCquery.Open;
//顯示選擇課程統(tǒng)計(jì)信息
datamodule3.statisticsQuery.Close;
datamodule3.statisticsQuery.ParamByName('sno').Value:=sno;
datamodule3.statisticsQuery.Open;
button3.Enabled:=true;
button4.Enabled:=true;
end
else
begin
//如果不存在該學(xué)號,則將“選課”、“退選”按鈕設(shè)置為無效
button3.Enabled:=false;
button4.Enabled:=false;
showmessage('學(xué)號輸入錯(cuò)誤,請重新輸入');
exit;
end;
end;
//查詢可供選修的課程
procedure TfrmSeleCourse.Button2Click(Sender: TObject);
var
cno:integer;
begin
if maskedit1.Text='' then
begin
showmessage('請輸入課程號!');
exit;
end;
cno:=strtoint(maskedit1.Text);//查詢課程號
if not datamodule3.coursetable.Locate('cno',cno,[]) then
showmessage('沒有查找到該課程的相關(guān)信息!');
end;
//選課操作
procedure TfrmSeleCourse.Button3Click(Sender: TObject);
var
cno,sno:integer;
begin
cno:=datamodule3.coursetable.fieldbyname('cno').Value;
sno:=strtoint(combobox1.Text);
//在選擇某一門課程前,先檢查是否已經(jīng)選修過該課程
datamodule3.SELECTQUERY.Close;
datamodule3.SELECTQUERY.SQL.Clear;
datamodule3.SELECTQUERY.SQL.Add('select *from sc.db');
datamodule3.SELECTQUERY.SQL.Add('where sno=:sno');
datamodule3.SELECTQUERY.SQL.Add('and cno=:cno');
datamodule3.SELECTQUERY.SQL.Add('and score=-1');
datamodule3.SELECTQUERY.ParamByName('sno').Value:=sno;
datamodule3.SELECTQUERY.ParamByName('cno').Value:=cno;
datamodule3.SELECTQUERY.Open;
if datamodule3.SELECTQUERY.Locate('sno;cno',vararrayof([sno,cno]),[]) then
//如果已經(jīng)選修過該課程,則不允許再選
begin
showmessage('你已經(jīng)選修了該課程,不允許重復(fù)選修!');
exit;
end;
//如果沒有選修該課程,則進(jìn)行選課操作
//這里將沒有通過的選修課程的分?jǐn)?shù)設(shè)置為-1
datamodule3.SELECTQUERY.Close;
datamodule3.SELECTQUERY.SQL.Clear;
datamodule3.SELECTQUERY.SQL.Add('insert into sc(sno,cno,score)');
datamodule3.SELECTQUERY.sql.Add('values(:sno,:cno,-1)');
datamodule3.SELECTQUERY.ParamByName('sno').Value:=sno;
datamodule3.SELECTQUERY.ParamByName('cno').Value:=cno;
datamodule3.SELECTQUERY.ExecSQL;
//更新選課信息
datamodule3.SCquery.Close;
datamodule3.SCquery.ParamByName('sno').Value:=sno;
datamodule3.SCquery.Open;
//更新統(tǒng)計(jì)信息
datamodule3.statisticsQuery.Close;
datamodule3.statisticsQuery.ParamByName('sno').Value:=sno;
datamodule3.statisticsQuery.Open;
end;
//執(zhí)行退選操作
procedure TfrmSeleCourse.Button4Click(Sender: TObject);
var
cno,sno:integer;
begin
cno:=datamodule3.SCquery.fieldbyname('cno').Value;
sno:=strtoint(combobox1.Text);
//從選課數(shù)據(jù)表中刪除選擇課程
datamodule3.DELETEQUERY.Close;
datamodule3.DELETEQUERY.SQL.Clear;
datamodule3.DELETEQUERY.SQL.Add('delete from sc');
datamodule3.DELETEQUERY.sql.Add('where sno=:sno');
datamodule3.DELETEQUERY.SQL.Add('and cno=:cno');
datamodule3.DELETEQUERY.ParamByName('sno').Value:=sno;
datamodule3.DELETEQUERY.ParamByName('cno').Value:=cno;
datamodule3.DELETEQUERY.ExecSQL;
//更新選課信息表
datamodule3.SCquery.Close;
datamodule3.SCquery.ParamByName('sno').Value:=sno;
datamodule3.SCquery.Open;
//更新統(tǒng)計(jì)信息
datamodule3.statisticsQuery.Close;
datamodule3.statisticsQuery.ParamByName('sno').Value:=sno;
datamodule3.statisticsQuery.Open;
end;
//初始化參數(shù)設(shè)置
procedure TfrmSeleCourse.FormActivate(Sender: TObject);
begin
datamodule3.tblstudent.Active:=true;
datamodule3.tblstudent.First;
while not datamodule3.tblstudent.Eof do
begin
//添加學(xué)號
if combobox1.Items.IndexOf(datamodule3.tblstudent.fieldbyname('sno').Value)=-1 then
combobox1.Items.Add(datamodule3.tblstudent.fieldbyname('sno').Value);
datamodule3.tblstudent.Next;
end;
//“選課”、“退選”按鈕設(shè)置為false
button3.Enabled:=false;
button4.Enabled:=false;
end;
end.
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -