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

📄 unit7.pas

📁 本程序提供了考试学生系统的原代码函数,并实现了很多程序难实现的功能
💻 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 + -