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

📄 u_stlr.~pas

📁 试卷管理系统
💻 ~PAS
📖 第 1 页 / 共 3 页
字号:
  progressfrm.ProgressBar1.Max:=k;
  progressfrm.Caption:='正在输出试题,请稍候...';
  progressfrm.Show;

  if not Assigned(WordObject) then
  begin
    WordObject := TWordObject.Create;
    with WordObject do begin
      Visible := false;
      OnQuit := WordQuit;
    end;
  end;

  v1:=WdDoNotSaveChanges;
  v2:=Unassigned;
  v3:=Unassigned;
  if WordObject.Application.Documents.Count>0 then
  begin
    WordObject.Application.Documents.Close(v1,v2,v3);
    WordObject.Visible:=false;
  end;

  strfrom:= Pb_runpath+'\template\试题输出.doc'+#0;
  strto1:=Pb_runpath+'\temp\试题题目.doc'+#0;

  CopyDirectory(Handle,strfrom,strto1);

  strto2:=Pb_runpath+'\temp\试题参考答案.doc'+#0;
  CopyDirectory(Handle,strfrom,strto2);


  try
    wDoc2:=WordObject.OpenDoc(strto2);
  except
    if Assigned(WordObject) then
    begin
      WordObject.Free;
      WordObject := nil;
    end;
    exit;
  end;

  try
    wDoc1:=WordObject.OpenDoc(strto1);
  except
    if Assigned(WordObject) then
    begin
      WordObject.Free;
      WordObject := nil;
    end;
    exit;
  end;

  wDoc1.Activate;
  wDoc1.Application.Selection.GoTo(-1,0,0,'khdxmc');
  wDoc1.Application.Selection.TypeText(combo_zy.Text
                                            +#13
                                            +combo_khdx.Text
                                            +#13
                                            +'试题题目');
  wDoc1.Application.Selection.GoTo(-1,0,0,'ts');
  wDoc1.Application.Selection.TypeText('共'+inttostr(k)+'题');

  wDoc2.Activate;
  wDoc2.Application.Selection.GoTo(-1,0,0,'khdxmc');
  wDoc2.Application.Selection.TypeText(combo_zy.Text
                                            +#13
                                            +combo_khdx.Text
                                            +#13
                                            +'试题参考答案');
  outing:=true;
  tbl_stk.Filtered:=false;
  tbl_sttx.Open;
  tbl_sttx.First;
  while not tbl_sttx.Eof do
  begin
    Query1.Close;
    Query1.SQL.Text:='select zyxh,gwlbxh,gwzlxh,khdxxh,stxh from stkdb where zyxh=:zyxh and gwlbxh=:gwlbxh'
                   + ' and gwzlxh=:gwzlxh and khdxxh=:khdxxh and txxh=:txxh';
    Query1.ParamByName('zyxh').AsInteger:=integer(combo_zy.Items.Objects[combo_zy.ItemIndex]);
    Query1.ParamByName('gwlbxh').AsInteger:=integer(combo_gwlb.Items.Objects[combo_gwlb.ItemIndex]);
    Query1.ParamByName('gwzlxh').AsInteger:=integer(combo_gwzl.Items.Objects[combo_gwzl.ItemIndex]);
    Query1.ParamByName('khdxxh').AsInteger:=integer(combo_khdx.Items.Objects[combo_khdx.ItemIndex]);
    Query1.ParamByName('txxh').AsInteger:=tbl_sttx.fieldbyname('txxh').AsInteger;
    Query1.Open;

    if Query1.RecordCount=0 then
    begin
      tbl_sttx.Next;
      continue;
    end;


    //写题型
    wDoc1.Activate;
    wDoc1.Application.Selection.EndKey(wdStory);
    wDoc1.Application.Selection.Font.Bold := True;
    wDoc1.Application.Selection.Font.Name := '宋体';
    wDoc1.Application.Selection.Font.Size := 14;
    wDoc1.Application.Selection.TypeText(tbl_sttx.fieldbyname('txmc').AsString);
    wDoc1.Application.Selection.TypeParagraph;

    wDoc2.Activate;
    wDoc2.Application.Selection.EndKey(wdStory);
    wDoc2.Application.Selection.Font.Bold := True;
    wDoc2.Application.Selection.Font.Name := '宋体';
    wDoc2.Application.Selection.Font.Size := 14;
    wDoc2.Application.Selection.TypeText(tbl_sttx.fieldbyname('txmc').AsString);
    wDoc2.Application.Selection.TypeParagraph;

    i:=1;
    while not Query1.Eof do
    begin
      tbl_stk.Locate('zyxh;gwlbxh;gwzlxh;khdxxh;txxh;stxh',VarArrayOf([
                      Query1.FieldByName('zyxh').AsInteger,
                      Query1.FieldByName('gwlbxh').AsInteger,
                      Query1.FieldByName('gwzlxh').AsInteger,
                      Query1.FieldByName('khdxxh').AsInteger,
                      tbl_sttx.FieldByName('txxh').AsInteger,
                      Query1.FieldByName('stxh').AsInteger]),
                      []);

      //写题目
      if tbl_stk.FieldByName('tmifwb').AsBoolean then
      begin
        wDoc1.Activate;

        wDoc1.Application.Selection.Font.Bold := false;
        wDoc1.Application.Selection.Font.Name := '宋体';
        wDoc1.Application.Selection.Font.Size := 14;

        //判断题加前导(    )
        if tbl_sttx.fieldbyname('txxh').AsInteger<>5 then
        begin
          wDoc1.Application.Selection.TypeText(inttostr(i)+'、');
        end
        else
        begin
          wDoc1.Application.Selection.TypeText(inttostr(i)+'、 (      )');
        end;


        wDoc1.Application.Selection.TypeText(trim(tbl_stk.FieldByName('wbtm').AsString));

        wDoc1.Application.Selection.TypeParagraph;
      end
      else
      begin
        blobStream := TBlobStream.Create(TBlobField(tbl_stk.FieldByName('twtm')), bmRead);
        if blobstream.Size>0 then
        begin
          blobstream.position:=0;

          olecontainer3.DestroyObject;

          olecontainer3.loadfromstream(blobstream);

          while true do
          begin
            if olecontainer3.State=osLoaded	then break;
          end;

          olecontainer3.SaveAsDocument(Pb_runpath+'\temp\tmp.doc');

          wDoc:=WordObject.OpenDoc(Pb_runpath+'\temp\tmp.doc');

          wDoc.Content.Copy;

          wDoc.Close;

          wDoc1.Activate;

          wDoc1.Application.Selection.Font.Bold := false;
          wDoc1.Application.Selection.Font.Name := '宋体';
          wDoc1.Application.Selection.Font.Size := 14;

          //判断题加前导(    )
          if tbl_sttx.fieldbyname('txxh').AsInteger<>5 then
          begin
            wDoc1.Application.Selection.TypeText(inttostr(i)+'、');
          end
          else
          begin
            wDoc1.Application.Selection.TypeText(inttostr(i)+'、 (      )');
          end;

          wDoc1.Application.Selection.EndKey(wdStory,wdExtend);
          wDoc1.Application.Selection.Paste;
        end
        else
        begin
          wDoc1.Activate;

          wDoc1.Application.Selection.Font.Bold := false;
          wDoc1.Application.Selection.Font.Name := '宋体';
          wDoc1.Application.Selection.Font.Size := 14;

          //判断题加前导(    )
          if tbl_sttx.fieldbyname('txxh').AsInteger<>5 then
          begin
            wDoc1.Application.Selection.TypeText(inttostr(i)+'、');
          end
          else
          begin
            wDoc1.Application.Selection.TypeText(inttostr(i)+'、 (      )');
          end;

          wDoc1.Application.Selection.EndKey(wdStory,wdExtend);
        end;
        BlobStream.Free;
      end;

      if tbl_stk.FieldByName('daifwb').AsBoolean then
      begin
        wDoc2.Activate;

        wDoc2.Application.Selection.Font.Bold := false;
        wDoc2.Application.Selection.Font.Name := '宋体';
        wDoc2.Application.Selection.Font.Size := 14;

        wDoc2.Application.Selection.TypeText(inttostr(i)+'、');

        wDoc2.Application.Selection.TypeText(trim(tbl_stk.FieldByName('wbda').AsString));

        wDoc1.Application.Selection.TypeParagraph;
      end
      else
      begin
        //写试题答案
        blobStream := TBlobStream.Create(TBlobField(tbl_stk.FieldByName('twda')), bmRead);
        if blobstream.Size>0 then
        begin
          blobstream.position:=0;

          olecontainer3.DestroyObject;

          olecontainer3.loadfromstream(blobstream);

          while true do
          begin
            if olecontainer3.State=osLoaded	then break;
          end;

          olecontainer3.SaveAsDocument(Pb_runpath+'\temp\tmp.doc');

          wDoc:=WordObject.OpenDoc(Pb_runpath+'\temp\tmp.doc');

          wDoc.Content.Copy;

          wDoc.Close;

          wDoc2.Activate;

          wDoc2.Application.Selection.Font.Bold := false;
          wDoc2.Application.Selection.Font.Name := '宋体';
          wDoc2.Application.Selection.Font.Size := 14;

          wDoc2.Application.Selection.TypeText(inttostr(i)+'、');

          wDoc2.Application.Selection.EndKey(wdStory,wdExtend);
          wDoc2.Application.Selection.Paste;
        end
        else
        begin
          wDoc2.Activate;

          wDoc2.Application.Selection.Font.Bold := false;
          wDoc2.Application.Selection.Font.Name := '宋体';
          wDoc2.Application.Selection.Font.Size := 14;

          wDoc2.Application.Selection.TypeText(inttostr(i)+'、');

          wDoc2.Application.Selection.EndKey(wdStory,wdExtend);
        end;
        BlobStream.Free;

      end;

      progressfrm.ProgressBar1.StepIt;

      i:=i+1;

      Query1.Next;
    end;
    tbl_sttx.Next;
  end;
  Query1.Close;

  tbl_stk.Filtered:=true;
  outing:=false;
  progressfrm.Close;
  Screen.Cursor := Save_Cursor;
  olecontainer3.DestroyObject;
  if Assigned(WordObject) then
  begin
    if WordObject.Application.Documents.Count>0 then
    begin
      v1:=WordObject.Application.Documents.Count;
      WordObject.Application.Documents.Item(v1).Activate;
      v2:=wdStory;
      v3:= wdMove;
      WordObject.Application.Selection.HomeKey(v2,v3);

      v1:=WordObject.Application.Documents.Count-1;
      WordObject.Application.Documents.Item(v1).Activate;
      WordObject.Application.Selection.HomeKey(v2,v3);
      SetWindowPos(Handle,HWND_BOTTOM,0,0,0,0,SWP_NOMOVE+SWP_NOSIZE);
      WordObject.Visible:=true;
      WordObject.Application.Activate;
    end;
  end;

end;

procedure Tfrm_stlr.WordQuit(Sender: TObject);
begin
  WordObject.Free;
  WordObject := nil;
end;

procedure Tfrm_stlr.CopyDirectory(AHandle: THandle; AFromDir,
  AToDir: String);
var
  FileOp:SHFILEOPSTRUCT;
begin
  with FileOp do
  begin
    Wnd:=AHandle;
    wFunc:=FO_COPY;
    pFrom:=PChar(AFromDir);
    pTo:=PChar(AToDir);
    fFlags:= FOF_NOCONFIRMATION;
    hNameMappings:=nil;
  end;
  SHFileOperation(FileOp);
end;

procedure Tfrm_stlr.tbl_stkAfterCancel(DataSet: TDataSet);
begin
    btn_insert.Enabled:=true;
    btn_edit.Enabled:=true;
    btn_save.Enabled:=false;
    btn_cancel.Enabled:=false;
end;

procedure Tfrm_stlr.CheckBox1Click(Sender: TObject);
begin
  Memo1.Lines.Clear;
  if OleContainer1.State<>OsEmpty then
    OleContainer1.DestroyObject;

  if CheckBox1.Checked then
  begin
    Memo1.Visible:=true;
    OleContainer1.Visible:=false;
  end
  else
  begin
    Memo1.Visible:=false;
    OleContainer1.Visible:=true;
    OleContainerOpen('1');
  end;
end;

procedure Tfrm_stlr.CheckBox2Click(Sender: TObject);
begin
  Memo2.Lines.Clear;
  if OleContainer2.State<>OsEmpty then
    OleContainer2.DestroyObject;

  if CheckBox2.Checked then
  begin
    Memo2.Visible:=true;
    OleContainer2.Visible:=false;
  end
  else
  begin
    Memo2.Visible:=false;
    OleContainer2.Visible:=true;
    OleContainerOpen('2');
  end;
end;

procedure Tfrm_stlr.GroupBox6MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
  if not CheckBox2.Checked then  OleContainerOpen('2');
end;

procedure Tfrm_stlr.GroupBox5MouseMove(Sender: TObject; Shift: TShiftState;
  X, Y: Integer);
begin
  if not CheckBox1.Checked then  OleContainerOpen('1');
end;

end.

⌨️ 快捷键说明

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