zoukankan      html  css  js  c++  java
  • 提取无忧测试系统的一个小工具

    很多参加计算机职称考试的一些朋友肯定用过无忧考系统,这套系统把所有题库放在一些Access文件里面,直接用access打开看不到明文,似乎加密了,其实仔细分析下,他存储的格式是RTF,只不过去掉了些RTF文件的关键信息.为了方便浏览(因为他有一些表之间的关联),特写了一个Delphi的小工具..下面给出一些关键的代码.
      1unit MainForm;
      2
      3interface
      4
      5uses
      6  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      7  Dialogs, StdCtrls, Grids, DBGrids,DB,ADODB, ComCtrls;
      8
      9type
     10  TForm1 = class(TForm)
     11    Button1: TButton;
     12    SaveDialog1: TSaveDialog;
     13    OpenDialog1: TOpenDialog;
     14    Button2: TButton;
     15    Button3: TButton;
     16    ProgressBar1: TProgressBar;
     17    procedure Button1Click(Sender: TObject);
     18    procedure Button2Click(Sender: TObject);
     19    procedure Button3Click(Sender: TObject);
     20  private
     21    { Private declarations }
     22  public
     23    { Public declarations }
     24  end;
     25  function  SaveFiledToFile(myfield:TField;FilePath:String;filename:String):Boolean;
     26var
     27  Form1: TForm1;
     28
     29implementation
     30
     31uses DataDM,StrUtils;
     32
     33{$R *.dfm}
     34var
     35   DataBaseName:string;
     36   ResultFileName:string;
     37   iCount : Integer;
     38function  SaveFiledToFile(myfield:TField;FilePath:String;filename:String):Boolean;
     39var
     40   bs:TADOBlobStream;
     41   allPath:String;
     42begin
     43  bs:=TADOBlobStream.Create(TBlobField(myfield),bmRead);
     44  try
     45    if RightStr(trim(FilePath),1)<>'\' then
     46       allPath:=FilePath+'\'+FileName
     47    else
     48       allPath:=filePath+FileName;
     49    if FileExists(allPath) then
     50       DeleteFile(allPath);
     51    bs.SaveToFile(allpath);
     52  finally
     53     bs.Free;
     54  end;
     55  Result:=True;
     56end;
     57
     58procedure TForm1.Button1Click(Sender: TObject);
     59var
     60    titleQR  : TADOQuery;  //题干及答案
     61    choiceQR : TADOQuery;  //题选项
     62    tempFile : TextFile;   //临时文件
     63    tempString,tsFileName: String;
     64    function GetAnswer(encode:Integer):String;
     65    begin
     66        case encode of
     67           1:  Result:='A';
     68           2:  Result:='B';
     69           4:  Result:='C';
     70           8:  Result:='D';
     71        end;
     72    end;
     73begin
     74
     75    tsFileName := ExtractFileDir(Application.ExeName)+ '\TemplateStart.txt';
     76    //ShowMessage(tsfileName);exit;
     77    if not FileExists(DataBaseName) then
     78    begin
     79       ShowMessage('源数据库文件不存在,请重新仔细选择!');
     80       exit;
     81    end;
     82    if FileExists(ResultFileName) then
     83    begin
     84      if MessageDlg('目标文件已存在,继续的话将被覆盖,是否继续?',
     85         mtConfirmation, [mbYes, mbNo],0= mrNo then
     86      begin
     87            exit;
     88      end;
     89    end;
     90
     91    if Length(ResultFileName)=0 then
     92    begin
     93       ShowMessage('请返回选择结果文件存放位置');
     94       exit;
     95    end;
     96//    SetLength();
     97    SetLength(tsFileName,Length(tsFileName));
     98    SetLength(ResultFileName,Length(ResultFileName));
     99    CopyFile(PChar(tsFileName),PChar(ResultFileName),False);
    100    AssignFile(tempfile,ResultFileName);
    101    Append(tempFile);
    102    titleQR := TADOQuery.Create(nil);
    103    GaoZhiDM.DataConn.Connected := True;
    104    titleQR.Connection := GaoZhiDM.DataConn;
    105    titleQr.SQL.Text := 'SELECT * FROM tbl_operation where c_recno=''010400362'' ORDER BY C_RECNO ';
    106    choiceQR := TADOQuery.Create(nil);
    107    choiceQR.Connection := GaoZhiDM.DataConn;
    108    choiceQR.SQL.Text := 'SELECT * FROM tbl_choicevice WHERE C_recno= :recordno';
    109    iCount:=0;
    110    try
    111       titleQR.Open;
    112       ProgressBar1.Max := titleQR.RecordCount;
    113       while not titleQR.Eof  do
    114       begin
    115            { ProgressBar1.Position := iCount;
    116             Application.ProcessMessages;
    117             iCount:=iCount+1;
    118             tempString := IntToStr(iCount) + ':' ;
    119             tempString := tempString + titleQR.FieldValues['M_TITLE'];
    120             tempString := tempString+'\par ';
    121
    122             WriteLn(tempFile,tempString);}

    123             SaveFiledToFile(titleQr.FieldByName('o_rudecont'),'g:\temp','a.dat');
    124             titleQr.Next;
    125       end;
    126       WriteLn(tempFile,'  \par }}');
    127    finally
    128       CloseFile(tempFile);
    129       if  choiceQR.Active then
    130       begin
    131          choiceQR.Close;
    132       end;
    133       if  titleQR.Active then
    134       begin
    135          titleQR.Close;
    136       end;
    137       titleQR.Free;
    138       choiceQR.Free;
    139    end;
    140    ShowMessage('数据已处理完毕!');
    141end;
    142
    143procedure TForm1.Button2Click(Sender: TObject);
    144begin
    145  if  OpenDialog1.Execute then
    146  begin
    147     DataBaseName := OpenDialog1.FileName;
    148     //Showmessage(DataBaseName);
    149     if GaoZhiDM.DataConn.Connected then
    150        GaoZhiDm.DataConn.Close;
    151     GaoZhiDM.DataConn.ConnectionString :=
    152       'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+DataBaseName+';Persist Security Info=False';
    153  end;
    154end;
    155
    156procedure TForm1.Button3Click(Sender: TObject);
    157begin
    158  if SaveDialog1.Execute then
    159  begin
    160     ResultFileName := SaveDialog1.FileName;
    161    // ShowMessage(ResultFileName);
    162  end;
    163end;
    164
    165end.
    166
  • 相关阅读:
    第1次实践作业
    Beta版本演示
    2019 SDN上机第7次作业
    Beta冲刺(4/4)
    Beta冲刺(3/4)
    Beta冲刺(2/4)
    Beta冲刺(1/4)
    2019 SDN上机第6次作业
    2019 SDN上机第5次作业
    SDN课程阅读作业(2)
  • 原文地址:https://www.cnblogs.com/wxx/p/187486.html
Copyright © 2011-2022 走看看