importer.pas

来自「C语言试题库及出题系统,可以导入试题,定制试卷,出题及修改试题,同时带上标准答案」· PAS 代码 · 共 93 行

PAS
93
字号
unit importer;

interface
uses SysUtils,classes,StrUtils,ADODB;

type
  TImporter=class
    InFile:string;
    Database:string;
    tb:tadotable;
    function Import:string;overload;
    function Import(InputFile,DatabaseFile:string):string;overload;
    function AddItem(item:TStringlist):string;
    function appDB(chap,sn,typ,pwr:string;body,ans:ansistring):string;
  end;
implementation
  function TImporter.Import:string;
  var fin:TextFile; s:string; item:tstringlist;
  begin
    result:='';
    item:=tstringlist.Create;
    //Open file
    AssignFile(fin,InFile);
    Reset(fin);
    while (not eof(fin))and(result='') do begin
      readln(fin,s);
      s:=trim(s);
      if length(s)>0 then begin
        item.Add(s);
      end else begin
        if item.Count>0 then result:=AddItem(item);
        item.Clear;
      end;
    end;
  end;
  function TImporter.Import(InputFile,DatabaseFile:string):string;
  begin
    InFile:=InputFile;
    Database:=DatabaseFile;
    tb:=tadotable.Create(nil);
    tb.ConnectionString:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+Database+';Password="";Persist Security Info=True;Jet OLEDB:Database Password=690911';
    result:=Import;
  end;
  function TImporter.AddItem(item:TStringlist):string;
  var s,q,chap,sn,typ,pwr:string; body,ans:tstringlist; i:integer; ws:string;
  begin
    body:=tstringlist.Create;
    ans:=tstringlist.Create;
    s:=item.Strings[0];
    chap:=copy(s,1,pos('-',s)-1);
    delete(s,1,pos('-',s));
    sn:=copy(s,1,pos('-',s)-1);
    delete(s,1,pos('-',s));
    typ:=copy(s,1,pos('-',s)-1);
    delete(s,1,pos('-',s));
    pwr:=s;
    i:=1;
    while (i<item.Count)and(item.Strings[i]<>':')do begin
      body.Add(item.Strings[i]);
      inc(i);
    end;
    q:='';
    ws:='①②③④⑤⑥⑦⑧⑨⑩';
    while (i<item.Count)do begin
      s:=item.Strings[i];
      if s=':' then begin s:=copy(ws,1,2);delete(ws,1,2);end;
      ans.Add(s);
      inc(i);
    end;
    result:=appDB(chap,sn,typ,pwr,body.Text,ans.Text);
  end;
  function TImporter.appDB(chap,sn,typ,pwr:string;body,ans:ansistring):string;
  begin;
    result:='';
    tb.TableName:='shiti';
    tb.Filtered:=false;
    tb.Filter:='知识点='+chap+' and 序号='+sn+'';
    tb.Filtered:=true;
    tb.Open;
    try tb.DeleteRecords(arFiltered);except end;
    try
     if body<>'' then tb.InsertRecord([chap,sn,typ,pwr,body,ans]);
    except
     on E: Exception do begin
      result:=E.Message+chr(13)+chr(10)+'   '+sn+typ+pwr+body+ans;
     end;
    end;
//      tb.filtered:=false;
//      tb.Filter:='';
//      tb.close;
  end;
end.

⌨️ 快捷键说明

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