欢迎来到飞鸟慕鱼博客,开始您的技术之旅!
当前位置: 首页知识笔记正文

抽取无忧考试系统的小工具

终极管理员 知识笔记 63阅读

很多参加计算机职称考试的朋友一定用过无忧考试系统。这个系统把所有的题库都放在一些access文件里,直接用Access打开,但是好像加密了。其实仔细分析,他存储的格式是RTF。只是去掉了RTF文件的一些关键信息。为了方便浏览(因为它在表之间有一些关联),突出了一个Delphi小工具.这里是一些关键代码。1unitMainForm23界面45使用6窗口、消息、系统工具、变体、类、图形、控件、表单、7对话框、StdCtrls、网格、DBGrids、DB、ADODB、ComCtrls89 type 10 form 1=class(t form)11 button 1: tbutton;12保存对话框1:保存

Dialog;
 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  Save(myfield:TField;):Boolean;
 26var
 27  Form1: TForm1;
 28
 29implementation
 30
 31uses DataDM,StrUtils;
 32
 33{$R *.dfm}
 34var
 35   DataBaseName:string;
 36   Result:string;
 37   iCount : Integer;
 38function  Save(myfield:TField;):Boolean;
 39var
 40   bs:TADOBlobStream;
 41   allPath:String;
 42begin
 43  bs:=TADOBlobStream.Create(TBlobField(myfield),bmRead);
 44  try
 45    if RightStr(trim(),1)<>'\' then
 46       allPath:=+'\'+
 47    else
 48       allPath:=+;
 49    if (allPath) then
 50       Delete);
 51    bs.SaveTo);
 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    temp;//临时文件
 63    tempString,ts;
 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    ts;:= Extract(Application.ExeName)+ '\TemplateStart.txt';
 76    //ShowMessage(ts);exit;
 77    if not (DataBaseName) then
 78    begin
 79       ShowMessage('源数据库文件不存在,请重新仔细选择!');
 80       exit;
 81    end;
 82    if (Result) 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(Result)=0 then
 92    begin
 93       ShowMessage('请返回选择结果文件存放位置');
 94       exit;
 95    end;
 96//    SetLength();
 97    SetLength(ts(ts));
 98    SetLength(Result(Result));
 99    Copy(ts),PChar(Result),False);
100    Assign);
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(temp);}

123             Save(titleQr.FieldByName('o_rudecont'),'g:\temp','a.dat');
124             titleQr.Next;
125       end;
126       WriteLn(tempFile,'  \par }}');
127    finally
128       Close);
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.;
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     Result;:= SaveDialog1.;
161    // ShowMessage(Result);
162  end;
163end;
164
165end.
166

标签:
声明:无特别说明,转载请标明本文来源!