?? unit7.pas
字號:
unit Unit7;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, Buttons, DB, DBTables;
type
TForm7 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
isxuan: TCheckBox;
Label1: TLabel;
xs: TEdit;
Label2: TLabel;
xzs: TUpDown;
Label3: TLabel;
Label4: TLabel;
xzf: TComboBox;
istian: TCheckBox;
Label5: TLabel;
ts: TEdit;
tians: TUpDown;
Label6: TLabel;
Label7: TLabel;
tzf: TComboBox;
Label8: TLabel;
tj: TBitBtn;
xianshu: TQuery;
Timer1: TTimer;
procedure tjClick(Sender: TObject);
procedure xzfKeyPress(Sender: TObject; var Key: Char);
procedure tzfKeyPress(Sender: TObject; var Key: Char);
procedure xsKeyPress(Sender: TObject; var Key: Char);
procedure tsKeyPress(Sender: TObject; var Key: Char);
procedure Timer1Timer(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure tiansClick(Sender: TObject; Button: TUDBtnType);
procedure xzsClick(Sender: TObject; Button: TUDBtnType);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form7: TForm7;
implementation
uses unit5, Unit4, Unit6, Unit3;
{$R *.dfm}
procedure kongshu1(); //根據填空數目來設定4個填空框的隱現
begin
case strtoint(form6.kongshu.Text) of
1:begin form6.lk2.Visible :=false;form6.k2.Visible :=false;
form6.lk3.Visible :=false;form6.k3.Visible :=false;
form6.lk4.Visible:=false;form6.k4.Visible :=false;end;
2:begin form6.lk3.Visible :=false;form6.k3.Visible :=false;
form6.lk4.Visible:=false;form6.k4.Visible :=false;end;
3:begin form6.lk4.Visible:=false;form6.k4.Visible :=false;end;
end;
end;
function qurand(num,range1:integer):integer;
var
i,j,k:integer;
zancun:array[0..100] of integer;
begin
form5.cunrnd.Clear ;
zancun[0]:=trunc(random(range1)+1);
form5.cunrnd.Items.Add(inttostr(trunc(random(range1)+1))) ;
while form5.jiegou.tag<num-1 do
begin
i:=trunc(random(range1)+1);
for j:=0 to form5.Tag do
begin
if i=zancun[j] then
break;
end;
if j>form5.tag then
begin
form5.jiegou.Tag:=form5.jiegou.Tag+1;
form5.Tag:=form5.Tag+1;
zancun[form5.Tag]:=i;
form5.cunrnd.Items.Add(inttostr(i)) ;
end;
end;
form5.cunrnd.Items.Strings[0]:=inttostr(zancun[0]);
form5.Tag:=0;
form5.jiegou.Tag:=0;
end;
procedure TForm7.tjClick(Sender: TObject);
var //提交用戶需求
k,h,juanno:integer;
begin
if (isxuan.Checked =false) and ((xs.Text <>'0') or (xzf.text<>'0')) then
showmessage('對不起!您沒有選中選擇題型!');
if (istian.Checked =false) and ((ts.Text <>'0') or (tzf.text<>'0')) then
showmessage('對不起!您沒有選中填空題型!');
form5.button3.Tag:=0;
form5.qktk.ExecSQL ;
if (isxuan.Checked =true) and ((xs.Text ='') or (xzf.Text ='')) then
begin
showmessage('請將選擇題信息填寫完整!');
end
else
begin
if (istian.Checked =true) and ((ts.Text ='') or (tzf.Text ='')) then
begin
showmessage('請將填空題信息填寫完整!');
end
else
begin
//根據需要向考試題庫插入試題
if isxuan.Checked =true then
begin//插入選擇題
if xuanke.selke.tag=0 then
begin //將線性代數試題插入試卷庫
form5.chuansong.SQL.Add('select * from 線性代數選擇題庫');
form5.chuansong.Open;
if not form5.chuansong.IsEmpty then
begin
h:=qurand(strtoint(xs.Text ),form5.chuansong.RecordCount); //從題庫中所有的試題中選擇7道題
form5.chuansong.SQL.Clear ;
form5.chuansong.SQL.Add('insert into 考卷試題庫 (題號,題型,題目,選項A,選項B,選項C,選項D,正確答案,所屬課程) select 題號,題型,題目,選項A,選項B,選項C,選項D,正確答案,所屬課程 from 線性代數選擇題庫 where 題號=:no');
for k:=0 to form5.cunrnd.Items.Count-1 do
begin
form5.chuansong.ParamByName('no').AsString :=form5.cunrnd.items.strings[k];
form5.chuansong.ExecSQL ;
end;
form5.chuansong.SQL.Clear ;
end
else
showmessage('對不起!選擇題庫中沒有試題!');
end
else
begin//將外語試題插入試卷題庫
if xuanke.selke.tag=1 then
begin//
form5.chuansong.SQL.Add('select * from 外語選擇題庫');
form5.chuansong.Open;
if not form5.chuansong.IsEmpty then
begin
h:=qurand(strtoint(xs.Text ),form5.chuansong.RecordCount);
form5.chuansong.SQL.Clear ;
form5.chuansong.SQL.Add('insert into 考卷試題庫 (題號,題型,題目,選項A,選項B,選項C,選項D,正確答案,所屬課程) select 題號,題型,題目,選項A,選項B,選項C,選項D,正確答案,所屬課程 from 外語選擇題庫 where 題號=:no');
for k:=0 to form5.cunrnd.Items.Count-1 do
begin
form5.chuansong.ParamByName('no').AsString :=form5.cunrnd.items.strings[k];
form5.chuansong.ExecSQL ;
end;
form5.chuansong.SQL.Clear ;
end
else
showmessage('對不起!選擇題庫中沒有試題!');
end;
end;
end;//插入選擇結束
if istian.Checked =true then
begin//插入填空題
if xuanke.selke.tag=0 then
begin
form5.chuansong.SQL.Clear;
form5.chuansong.SQL.Add('select * from 線性代數填空題庫');
form5.chuansong.Open;
if not form5.chuansong.IsEmpty then
begin
h:=qurand(strtoint(ts.Text ),form5.chuansong.RecordCount);
form5.chuansong.SQL.Clear ;
form5.chuansong.SQL.Add('insert into 考卷試題庫 (題號,題型,題目,選項A,選項B,選項C,選項D,填空數目,所屬課程) select 題號,題型,題目,空1,空2,空3,空4,填空數目,所屬課程 from 線性代數填空題庫 where 題號=:no');
for k:=0 to form5.cunrnd.Items.Count-1 do
begin
form5.chuansong.ParamByName('no').AsString :=form5.cunrnd.Items.Strings[k];
form5.chuansong.ExecSQL ;
end ;
end
else
showmessage('對不起!填空題庫中沒有試題!');
end
else
begin
form5.chuansong.SQL.Add('select * from 外語填空題庫');
form5.chuansong.Open;
if not form5.chuansong.IsEmpty then
begin
h:=qurand(strtoint(ts.Text ),form5.chuansong.RecordCount);
form5.chuansong.SQL.Clear ;
if xuanke.selke.tag=1 then
form5.chuansong.SQL.Add('insert into 考卷試題庫 (題號,題型,題目,選項A,選項B,選項C,選項D,填空數目,所屬課程) select 題號,題型,題目,空1,空2,空3,空4,填空數目,所屬課程 from 外語填空題庫 where 題號=:no')
else
form5.chuansong.SQL.Add('insert into 考卷試題庫 (題號,題型,題目,選項A,選項B,選項C,選項D,填空數目,所屬課程) select 題號,題型,題目,空1,空2,空3,空4,填空數目,所屬課程 from 線性代數填空題庫 where 題號=:no');
for k:=0 to form5.cunrnd.Items.Count-1 do
begin
form5.chuansong.ParamByName('no').AsString :=form5.cunrnd.Items.Strings[k];
form5.chuansong.ExecSQL ;
end;
end
else
showmessage('對不起!填空題庫中沒有試題!');
end;
end;//插入填空結束
//將所選試題已試卷形式展現在教師面前
form5.chuansong.SQL.Clear ;
form5.chuansong.SQL.Add('select * from 考卷試題庫');
form5.chuansong.Open;
if not form5.chuansong.IsEmpty then
begin
form6.show;
if isxuan.Checked =true then
form6.query1.ParamByName('tixing').AsString :='選擇題'
else
form6.query1.ParamByName('tixing').AsString :='填空';
form6.query1.open;
form6.shumu.Caption :=inttostr(form6.Query1.RecordCount );
form6.cunjuan.Visible:=true;
form6.gh.Visible :=true;
if form5.panel1.tag=0 then
begin
while form5.button3.tag=0 do //隨機產生試卷號
begin
form5.seljuanno.Close;
juanno:=trunc(random(200))+1;
form5.seljuanno.ParamByName('no').AsString :=inttostr(juanno);
form5.seljuanno.Open;
if form5.seljuanno.IsEmpty then
begin
form6.juanno.Caption:=form6.juanno.Caption +': '+inttostr(juanno);
form5.button3.Tag:=1;
end;
end;
form5.panel1.Tag:=1;
form6.kecheng.Caption:=form6.kecheng.Caption +': '+teacher.ke.Text;
end;
end;
//展示完成
end;
end;
if isxuan.Checked =false then
begin
form6.xuanze.Visible :=false;
form6.tiankong.Visible :=true;
form6.xz.Visible :=false;
form6.tk.Visible :=false;
form6.shumu1.Caption :=form7.ts.Text ;
kongshu1();
end;
if istian.Checked =false then
begin
form6.xuanze.Visible :=true;
form6.tiankong.Visible :=false;
form6.xz.Visible :=false;
form6.tk.Visible :=false;
end;
form7.Close;
end;
procedure TForm7.xzfKeyPress(Sender: TObject; var Key: Char);
begin
if not ((key>=#48) and (key<=#57) ) then
begin
showmessage('對不起!您輸入了非法的字符!');
key:=#13;
xzf.Text:='';
end;
end;
procedure TForm7.tzfKeyPress(Sender: TObject; var Key: Char);
begin
if not ((key>=#48) and (key<=#57) ) then
begin
showmessage('對不起!您輸入了非法的字符!');
key:=#13;
tzf.Text:='';
end;
end;
procedure TForm7.xsKeyPress(Sender: TObject; var Key: Char);
begin
if not ((key>=#48) and (key<=#57) ) then
begin
showmessage('對不起!您輸入了非法的字符!');
key:=#13;
xs.Text:='';
end;
end;
procedure TForm7.tsKeyPress(Sender: TObject; var Key: Char);
begin
if not ((key>=#48) and (key<=#57) ) then
begin
showmessage('對不起!您輸入了非法的字符!');
key:=#13;
ts.Text:='';
end;
end;
procedure TForm7.Timer1Timer(Sender: TObject);
var
xk,tk:string;
xks,tks:integer;
begin
if timer1.tag=0 then
begin
if xuanke.selke.tag =0 then
begin
xk:='線性代數選擇題庫';
tk:='線性代數填空題庫';
end
else
begin
xk:='外語選擇題庫';
tk:='外語填空題庫';
end;
xianshu.SQL.Clear ;
xianshu.SQL.Add('select * from '+xk);
xianshu.Open;
xzs.Max :=xianshu.RecordCount ;
xianshu.SQL.Clear ;
xianshu.SQL.Add('select * from '+tk);
xianshu.Open;
tians.Max :=xianshu.RecordCount ;
timer1.Tag:=1;
end;
end;
procedure TForm7.FormActivate(Sender: TObject);
begin
form7.Tag:=1;//標志是采用的半自動方式生成試卷
tj.SetFocus ;
end;
procedure TForm7.tiansClick(Sender: TObject; Button: TUDBtnType);
begin
if tians.Position=tians.Max then
showmessage('已達到填空題庫中試題總數!');
end;
procedure TForm7.xzsClick(Sender: TObject; Button: TUDBtnType);
begin
if xzs.Position=xzs.Max then
showmessage('已達到選擇題庫中試題總數!');
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -