⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sj_third.pas

📁 学员管理的软件
💻 PAS
字号:
unit sj_third;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, ComCtrls;

type
  TForm5 = class(TForm)
    Label1: TLabel;
    RadioGroup1: TRadioGroup;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    ProgressBar1: TProgressBar;
    Label2: TLabel;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
 //   function inarray(i:integer):boolean;
    procedure rand_l(i:integer);  //根据题型,所属试卷选题号
    procedure initarray;
    procedure rand_h(i:integer;j:integer);//随机从th-l中选i个题号 put key_z[]
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form5: TForm5;
  th_z:array[0..1000] of integer;  //最大返回一次1000条记录
  key_z:array[0..100] of integer;  //没一题型的道数最多为100
  cur_num:integer;//当前总题数
  key_num:integer=0;//控制当前已经在key-z数组中的个数
  ts_num:array [0..20] of integer;   //题型号对应的题数
  txh_arr:array [0..20] of integer;  //题型号
  ERR:boolean=false;


implementation

{$R *.dfm}
uses login,main,sj_second,sj_four_rand,sj_four_man,sj_zero,sj_first;
procedure TForm5.BitBtn1Click(Sender: TObject);
begin
sj_second.Form4.Show;
form5.Hide;
end;

procedure Tform5.initarray;
var i:integer;
begin
for i:=0 to 1000 do
begin
th_z[i]:=0;
end;
for i:=0 to 100 do
begin
key_z[i]:=0;
end;
end;

procedure tform5.rand_l(i:integer);  //根据题型,所属试卷选题号
var ii:integer;
begin
initarray;
ii:=0;
with main.DataModule2 do
begin
aq1.Close;
aq1.SQL.Clear;
//去前1000条
aq1.SQL.Add('select top 1000 试题号 from 试题表 where 所属试卷='+inttostr(sj_zero.sj_id)+' and 题型='+inttostr(i));
aq1.Open;
while not aq1.Eof do
begin
th_z[ii]:=aq1.FieldByName('试题号').Value;
ii:=ii+1;
aq1.Next;
end;
cur_num:=ii-1;
end;
end;
(*
function Tform5.inarray(i:integer):boolean;  //题号为i的是否满足需要
var
ii:integer;
begin
for ii:=0 to cur_num do
begin
if ((key_z[ii]-i)=0) then
Result:=true;
end;
result:=false;
end;
*)
procedure tform5.rand_h(i:integer;j:integer);//随机从th-l中选i个题号 put key_z[]
//题型为j
var
iii,ii:integer;
num:integer;
flag:boolean;
begin
flag:=true;
rand_l(j);
Randomize;
//ii:=0;
key_num:=0;
if cur_num<i then
begin
application.MessageBox('在数据库中有一题型的题数不够!','错误',0);
err:=true;
exit;
end;
while true do
begin
num:=random(cur_num+1);
if num=0 then continue;
flag:=true;
for iii:=0 to cur_num do
begin
if (key_z[iii]=num) then
begin
flag:=false;
break;
end;
end;
if (flag) then      //得到了另一个满足需要的题号
begin
   key_z[key_num]:=num;
   inc(key_num);
   //录入数据库
   with main.DataModule2 do
   begin
   aq1.SQL.Clear;
   aq1.SQL.Add('select * from 用户作答表');
   aq1.Close;
   aq1.Open;
   aq1.Insert;
   aq1.FieldByName('题号').AsInteger:=th_z[num];
   aq1.FieldByName('试卷号').AsInteger:=sj_zero.sj_id;
   aq1.Post;
   end;
end;
if key_num>i-1 then exit;//大于要求的题数退出
end;
end;

procedure TForm5.BitBtn2Click(Sender: TObject);
var
inum,iinum:integer;
tlx_num:integer;
i:integer;
begin
with main.DataModule2 do
begin
  aq1.Close;
  aq1.SQL.Clear;
  aq1.SQL.Add('select * from 用户作答表 where 试卷号='+inttostr(sj_zero.sj_id));
  aq1.Open;
  if not aq1.Eof then
  begin
      showmessage('对不起,数据库中已经有这张试卷了,我们将不再处理');
      form5.Close;
  end;
end;
case RadioGroup1.ItemIndex of
0: begin  //随机抽题
//总题型数
tlx_num:=0;
for i:=0 to 20 do
begin
if (sj_second.ts[i]>0 ) then
      tlx_num:=tlx_num+1;
end;
//设置进度条
progressbar1.Max:=tlx_num;
progressbar1.Position:=0;
progressbar1.Visible:=true;
screen.Cursor:=crHourGlass;
for inum:=0 to tlx_num-1 do
begin
//根据这个题型选择ts[inum]个记录
  rand_h(sj_second.ts[inum],txh_arr[inum]);
  progressbar1.Position:=progressbar1.Position+1;
end;
screen.Cursor:=crdefault;
progressbar1.Visible:=false;
if (err=true) then
begin
label2.Visible:=true;
label2.Caption:='正在回退删除已出入记录,请稍侯......';
with main.DataModule2 do //删除以前添加的数据
begin
aq1.Close;
aq1.SQL.Clear;
aq1.SQL.Add('delete  from 用户作答表 where 试卷号='+inttostr(sj_zero.sj_id));
aq1.ExecSQL;
label2.Visible:=false;
end;
end;
end;
1: sj_four_man.Form7.Show;
end;
form5.Hide;
end;
procedure TForm5.FormShow(Sender: TObject);
var i:integer;
ii:integer;
begin
err:=false;
ii:=0;
for i:=0 to 20 do
begin
ts_num[i]:=sj_second.ts[i];
end;
for i:=0 to 20 do
begin
if sj_first.txh[i]>0 then
begin
txh_arr[ii]:=sj_first.txh[i];
inc(ii);
end;
end;
end;
end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -