这是我用D7写的一段代码:<br>unit C_bzDK;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,<br> cxDataStorage, cxEdit, DB, cxDBData, bsSkinData, bsMessages,<br> BusinessSkinForm, DBTables, cxGridLevel, cxGridCustomTableView,<br> cxGridTableView, cxGridDBTableView, cxClasses, cxControls,<br> cxGridCustomView, cxGrid, bsSkinCtrls, bsSkinBoxCtrls, dxdbtrel,<br> bsdbctrls, Menus, bsSkinMenus, ExtCtrls, DBCtrls, ComCtrls, bsSkinTabs;<br><br>type<br> TFrmBZDK = class(TForm)<br> bsSkinPanel1: TbsSkinPanel;<br> bsSkinPanel3: TbsSkinPanel;<br> bsSkinDBLookupComboBox1: TbsSkinDBLookupComboBox;<br> dxDBLookupTreeView1: TdxDBLookupTreeView;<br> bsSkinLabel1: TbsSkinLabel;<br> bsSkinLabel2: TbsSkinLabel;<br> bsSkinLabel3: TbsSkinLabel;<br> bsSkinLabel4: TbsSkinLabel;<br> bsSkinLabel5: TbsSkinLabel;<br> bsSkinLabel6: TbsSkinLabel;<br> btnOK: TbsSkinButton;<br> btnDK: TbsSkinButton;<br> btnClose: TbsSkinButton;<br> btnClear: TbsSkinButton;<br> btnCX: TbsSkinButton;<br> bsSkinSpinEdit1: TbsSkinSpinEdit;<br> bsSkinSpinEdit2: TbsSkinSpinEdit;<br> bsSkinSpinEdit3: TbsSkinSpinEdit;<br> bsSkinSpinEdit4: TbsSkinSpinEdit;<br> bsSkinPanel2: TbsSkinPanel;<br> cxGrid1: TcxGrid;<br> cxGrid1DBTableView1: TcxGridDBTableView;<br> cxGrid1DBTableView1Th: TcxGridDBColumn;<br> cxGrid1DBTableView1Dan: TcxGridDBColumn;<br> cxGrid1DBTableView1Fz: TcxGridDBColumn;<br> cxGrid1DBTableView1bfz: TcxGridDBColumn;<br> cxGrid1DBTableView1dx: TcxGridDBColumn;<br> cxGrid1Level1: TcxGridLevel;<br> bsSkinLabel10: TbsSkinLabel;<br> QDADM: TQuery;<br> QDADMID: TIntegerField;<br> QDADMDan: TStringField;<br> QDADMDm: TStringField;<br> QBZDA: TQuery;<br> QBZDAid: TIntegerField;<br> QBZDAdm: TStringField;<br> QBZDATh: TSmallintField;<br> QBZDADan: TStringField;<br> QBZDAFz: TFloatField;<br> QBZDAbfz: TFloatField;<br> QBZDAdx: TBooleanField;<br> QBZDAJB: TIntegerField;<br> dsQBZDA: TDataSource;<br> dsQJBXX: TDataSource;<br> QJBXX: TQuery;<br> QJBXXID: TIntegerField;<br> QJBXXPID: TIntegerField;<br> QJBXXMC: TStringField;<br> QKmdmk: TQuery;<br> QKmdmkID: TIntegerField;<br> QKmdmkMC: TStringField;<br> QKmdmkDM: TStringField;<br> dsQKmdmk: TDataSource;<br> bsBusinessSkinForm1: TbsBusinessSkinForm;<br> bsSkinMessage1: TbsSkinMessage;<br> bsSkinPanel4: TbsSkinPanel;<br> cxGrid2: TcxGrid;<br> cxGridDBTableView1: TcxGridDBTableView;<br> cxGridLevel1: TcxGridLevel;<br> bsSkinLabel8: TbsSkinLabel;<br> QCJK: TQuery;<br> dsQCJK: TDataSource;<br> cxGridDBTableView1KH: TcxGridDBColumn;<br> cxGridDBTableView1KM: TcxGridDBColumn;<br> QTemp: TQuery;<br> bsSkinStatusBar1: TbsSkinStatusBar;<br> bsSkinStatusPanel2: TbsSkinStatusPanel;<br> btnDC: TbsSkinButton;<br> bsSkinPopupMenu1: TbsSkinPopupMenu;<br> N1: TMenuItem;<br> bsSkinStatusPanel1: TbsSkinStatusPanel;<br> bsSkinStatusPanel3: TbsSkinStatusPanel;<br> bsSkinLabel7: TbsSkinLabel;<br> bsSkinLabel9: TbsSkinLabel;<br> bsSkinDBNavigator1: TbsSkinDBNavigator;<br> cxGridDBTableView1KMDA: TcxGridDBColumn;<br> bsSkinButton1: TbsSkinButton;<br> bsSkinPanel5: TbsSkinPanel;<br> bsSkinPageControl1: TbsSkinPageControl;<br> bsSkinTabSheet1: TbsSkinTabSheet;<br> bsSkinTabSheet2: TbsSkinTabSheet;<br> QCJK2: TQuery;<br> DSQCJK2: TDataSource;<br> cxGrid3: TcxGrid;<br> cxGridDBTableView2: TcxGridDBTableView;<br> cxGridLevel2: TcxGridLevel;<br> QCJK2KH: TStringField;<br> QCJK2Zz: TFloatField;<br> QCJK2Yw: TFloatField;<br> QCJK2Sx: TFloatField;<br> QCJK2Wl: TFloatField;<br> QCJK2Hx: TFloatField;<br> QCJK2Yy: TFloatField;<br> QCJK2Ls: TFloatField;<br> QCJK2Dl: TFloatField;<br> QCJK2Sw: TFloatField;<br> QCJK2XJ: TFloatField;<br> QCJK2Qt: TFloatField;<br> QCJK2JB: TIntegerField;<br> QCJK2XM: TStringField;<br> cxGridDBTableView2KH: TcxGridDBColumn;<br> cxGridDBTableView2Zz: TcxGridDBColumn;<br> cxGridDBTableView2Yw: TcxGridDBColumn;<br> cxGridDBTableView2Sx: TcxGridDBColumn;<br> cxGridDBTableView2Wl: TcxGridDBColumn;<br> cxGridDBTableView2Hx: TcxGridDBColumn;<br> cxGridDBTableView2Yy: TcxGridDBColumn;<br> cxGridDBTableView2Ls: TcxGridDBColumn;<br> cxGridDBTableView2Dl: TcxGridDBColumn;<br> cxGridDBTableView2Sw: TcxGridDBColumn;<br> cxGridDBTableView2XJ: TcxGridDBColumn;<br> cxGridDBTableView2Qt: TcxGridDBColumn;<br> QCJK2ZF: TFloatField;<br> cxGridDBTableView2DBColumn1: TcxGridDBColumn;<br> QJBXXDM: TStringField;<br> QCJK2ID: TIntegerField;<br> QCJK2ZZ_DA: TStringField;<br> QCJK2YW_DA: TStringField;<br> QCJK2SX_DA: TStringField;<br> QCJK2WL_DA: TStringField;<br> QCJK2HX_DA: TStringField;<br> QCJK2YY_DA: TStringField;<br> QCJK2LS_DA: TStringField;<br> QCJK2DL_DA: TStringField;<br> QCJK2SW_DA: TStringField;<br> QCJK2XJ_DA: TStringField;<br> QCJK2QT_DA: TStringField;<br> QCJK2BJ: TIntegerField;<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> procedure FormDestroy(Sender: TObject);<br> procedure btnCloseClick(Sender: TObject);<br> procedure btnOKClick(Sender: TObject);<br> procedure FormCreate(Sender: TObject);<br> procedure btnCXClick(Sender: TObject);<br> procedure btnDKClick(Sender: TObject);<br> procedure btnClearClick(Sender: TObject);<br> procedure btnDCClick(Sender: TObject);<br> procedure bsSkinLabel8DblClick(Sender: TObject);<br> procedure dsQCJKDataChange(Sender: TObject; Field: TField);<br> procedure bsSkinButton1Click(Sender: TObject);<br> procedure QCJK2CalcFields(DataSet: TDataSet);<br> private<br> { Private declarations }<br> public<br> { Public declarations }<br> procedure SaveCJ(D:string);//保存成绩<br> function CheckDX(D1,D2:string):Boolean;//检查多选题答案<br> end;<br>var<br> FrmBZDK: TFrmBZDK;<br> KMDM:string;<br> JBDM:string;//级部代码<br> BJDM:string;//年级代码<br> iDK:integer;<br> tslKH:Tstringlist;<br>implementation<br> uses main, C_BZDA;<br>{$R *.dfm}<br><br>procedure TFrmBZDK.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> QCJK.close;<br> QJBXX.Close;<br> QKMDMK.Close;<br> QCJK2.Close;<br> tslKH.Destroy;<br> Action:=caFree;<br>end;<br><br>procedure TFrmBZDK.FormDestroy(Sender: TObject);<br>begin<br> FrmBZDK:=NIL;<br>end;<br><br>procedure TFrmBZDK.btnCloseClick(Sender: TObject);<br>begin<br> Close;<br>end;<br><br>procedure TFrmBZDK.btnOKClick(Sender: TObject);<br>begin<br> if (dxDBLookupTreeView1.Text='')or(QJBXX.FieldByName('DM').AsString='') then<br> begin<br> bsSkinMessage1.MessageDlg('请选择一个班级!',<br> (mtinformation),[mbOK],0);<br> Abort;<br> end;<br> if bsSkinDBLookupComboBox1.Text='' then<br> begin<br> bsSkinMessage1.MessageDlg('请选择一个科目!',<br> (mtinformation),[mbOK],0);<br> Abort;<br> end;<br><br> KMDM:=QKMDMK.FieldByName('DM').AsString;<br> JBDM:=QJBXX.FieldByName('PID').AsString;<br> BJDM:=QJBXX.FieldByName('DM').AsString;<br><br> QBZDA.Close;<br> QBZDA.SQL.Clear;<br> QBZDA.SQL.Add('SELECT * FROM BZDA WHERE((DM='''+KMDM+''')AND(JB='+JBDM+')AND(ID>0))ORDER BY TH');<br> QBZDA.Open;<br> if QBZDA.RecordCount=0 then<br> begin<br> QBZDA.Close;<br> bsSkinMessage1.MessageDlg(dxDBLookupTreeView1.Text+bsSkinDBLookupComboBox1.Text+'还没有设置标准答案!',<br> (mtinformation),[mbOK],0);<br> Abort;<br><br> end;<br> QCJK.Close;<br> QCJK.SQL.Clear;<br> QCJK.SQL.Add('SELECT KH,JB,BJ, '+KMDM+','+KMDM+'_DA FROM BZCJK WHERE(JB='+JBDM+')AND(BJ='''+BJDM+''')');<br> //ShowMessage(QCJK.SQL.Text);<br> QCJK.Open;<br> if QCJK.RecordCount=0 then<br> begin<br> QCJK.Close;<br> QBZDA.Close;<br> bsSkinMessage1.MessageDlg(dxDBLookupTreeView1.Text+bsSkinDBLookupComboBox1.Text+'没有考生信息,您需要通过[学生信息]-[输入学生信息]来输入学生信息!',<br> (mtinformation),[mbOK],0);<br> Abort;<br> end;<br> bsSkinLabel10.Caption:=dxDBLookupTreeView1.Text+bsSkinDBLookupComboBox1.Text+' 标准答案';<br> bsSkinSpinEdit2.Value:=QBZDA.RecordCount;<br> btnCX.Enabled:=true;<br> btnDK.Enabled:=true;<br> btnClear.Enabled:=true;<br> btnDC.Enabled:=true;<br> btnOK.Enabled:=false;<br> bsSkinButton1.Enabled:=false;<br> cxGridDBTableView1KM.DataBinding.FieldName:=KMDM;<br> cxGridDBTableView1KMDA.DataBinding.FieldName:=KMDM+'_DA';<br> QCJK2.Close;<br> QCJK2.ParamByName('JB').AsString:=JBDM;<br> QCJK2.ParamByName('BJ').AsString:=BJDM;<br> QCJK2.Open;<br> tslKH.Clear;<br>end;<br><br>procedure TFrmBZDK.FormCreate(Sender: TObject);<br>begin<br> QJBXX.Open;<br> QKMDMK.Open;<br> //QKmdmk2.Open;<br> //QCJK.Open;<br> iDK:=0;<br> tslKH:=TStringList.Create;<br><br>end;<br><br>procedure TFrmBZDK.btnCXClick(Sender: TObject);<br>begin<br> btnCX.Enabled:=false;<br> btnDK.Enabled:=false;<br> btnClear.Enabled:=false;<br> btnDC.Enabled:=false;<br> bsSkinButton1.Enabled:=true;<br><br><br> btnOK.Enabled:=true;<br> QBZDA.Close;<br> QCJK.Close;<br><br>end;<br><br>procedure TFrmBZDK.btnDKClick(Sender: TObject);<br> type<br> TORM_Fun=function(Cmd
char):Integer; stdcall;<br><br>var<br> Cmd:array[0..254] of char;<br> Buf:array[0..254] of char;<br> sp:string;<br> i,j:integer;<br><br>begin<br> begin<br> // ShowMessage('DLL OK!');<br> try<br> // @OmrS:=GetProcAddress(TH,'OrmS');<br> // @OmrG:=GetProcAddress(TH,'OrmG');<br><br> FillChar(buf, SizeOf(buf), Ord(' '));<br> StrPCopy(Cmd,'S '+main.ORM_FormFileName+'/');<br> omrS(cmd); //送格式命令<br><br> while 2=2 do<br> begin<br> sp:=' ';<br> for i:=1 to 200 do<br> begin<br> sp:=sp+' ';<br> end;<br><br> Cmd:= '/ ';<br> J:=main.omrS(Cmd);<br> I:=main.omrG(Buf); //取读卡返回字串<br> bsSkinStatusPanel1.Caption:='阅卷状态:'+main.FrmMain.yjerr(i);<br> if Copy(Buf,1,2)='OK' then<br> begin<br> strpcopy(Cmd,'001');<br> main.omrS(Cmd); //送取数据命令<br> main.omrG(Buf);<br> if Pos('.',Copy(buf,2,9))>0 then<br> begin<br> Cmd:='-/';<br> main.omrS(Cmd);<br> bsSkinLabel7.Caption:='考号[ '+Copy(buf,2,9)+' ]涂写错误!';<br> bsSkinMessage1.MessageDlg('考号[ '+Copy(buf,2,9)+' ]涂写错误!',(mtinformation),[mbOK],0);<br> break;<br> end;<br> if (tslKH.IndexOf(Copy(buf,2,9))<0) then //没过读卡<br> begin<br> tslKH.Add(Copy(buf,2,9));<br> SaveCJ(Copy(Buf,1,200)); //取返回字串<br> FrmBZDK.cxGrid2.Refresh;<br> Cmd:='-/';<br> main.omrS(Cmd);<br> iDK:=iDK+1; //送停机命令<br> bsSkinLabel8.Caption:='已阅卷人数(双击此处计数器置0):'+IntToStr(iDK);<br> end<br> else<br> begin //已读过该考号<br> Cmd:='-/';<br> main.omrS(Cmd);<br> bsSkinLabel7.Caption:='考号[ '+Copy(buf,2,9)+' ]重复!';<br> bsSkinMessage1.MessageDlg('考号[ '+Copy(buf,2,9)+' ]重复!',(mtinformation),[mbOK],0);<br> break;<br> end;<br> end<br> else<br> begin<br> Cmd:='-/'; //送停机命令<br> bsSkinStatusPanel2.Caption:='阅卷机状态:'+main.FrmMain.yjerr(j);<br> bsSkinLabel9.Caption:='阅卷机状态:'+main.FrmMain.yjerr(j);<br> main.omrS(Cmd); <br> btnDK.SetFocus;<br> break;<br> end;<br> end;<br> except<br> Cmd:='-/';<br> main.omrS(Cmd);<br> // FreeLibrary(TH);<br> end;<br> end;<br>end;<br>procedure TFrmBZDK.SaveCJ(D:string);//保存成绩<br>var<br> i,j:integer;<br> DTWZ:integer;//答题位置<br> TS:integer;//答题位置<br> KSTH:integer;//开始题号<br> DAN,BZDA:string;<br> KH:string;<br> CJ:Extended;<br>begin<br> DTWZ:=StrToInt(FormatFloat('0',bsSkinSpinEdit1.Value));<br> TS:=StrToInt(FormatFloat('0',bsSkinSpinEdit2.Value));<br><br> KSTH:=StrToInt(FormatFloat('0',bsSkinSpinEdit4.Value));<br> KH:=Copy(D,2,9);<br> QBZDA.DisableControls;<br> for i:=1 to TS do<br> begin<br> DAN:=main.FrmMain.DAZH(Copy(D,DTWZ+i-1+11,1));<br> QBZDA.Locate('TH',IntToStr(KSTH+i-1),[]);<br> BZDA:=QBZDA.FieldByName('DAN').AsString;<br> if dan<>'' then<br> if QBZDA.FieldByName('DX').Value then//多选<br> begin<br> if DAN=BZDA then<br> begin<br> CJ:=CJ+QBZDA.FieldByName('FZ').AsFloat;<br> end<br> else<br> begin<br> if CheckDX(DAN,BZDA) then<br> CJ:=CJ+QBZDA.FieldByName('BFZ').AsFloat;<br> end;<br> end<br> else<br> begin<br> if DAN=BZDA then<br> CJ:=CJ+QBZDA.FieldByName('FZ').AsFloat;<br> end;<br> end;<br> if not (QCJK.Locate('KH',KH,[])) then<br> begin<br> QCJK.Append;<br> QCJK.Edit;<br> QCJK.FieldByName('KH').AsString:=KH;<br> QCJK.FieldByName('JB').AsString:=JBDM;<br> QCJK.FieldByName(KMDM).AsString:=FormatFloat('0.00',CJ);<br> QCJK.FieldByName(KMDM+'_DA').AsString:=Copy(D,12,TS);<br> QCJK.Post;<br> QCJK.Close;<br> QCJK.Open;<br> QCJK.Last;<br> end<br> else<br> begin<br> QCJK.Edit;<br> //QCJK.FieldByName('JB').AsString:=JBDM;<br> QCJK.FieldByName('KH').AsString:=KH;<br> QCJK.FieldByName(KMDM).AsString:=FormatFloat('0.00',CJ);<br> QCJK.FieldByName(KMDM+'_DA').AsString:=Copy(D,12,TS);<br> QCJK.Post;<br> end;<br> QBZDA.EnableControls;<br> bsSkinLabel7.Caption:='最后考号:'+Copy(D,2,9);<br>end;<br>function TFrmBZDK.CheckDX(D1,D2:string):Boolean;//检查多选题答案<br>var<br> i:integer;<br> sDA:string;<br>begin<br> if D2='ABCD' then<br> sDA:='ABCDABDACDACADCD';<br><br> if D2='ABC' then<br> sDA:='ABCAC';<br> if D2='BCD' then<br> sDA:='BCDBD';<br> if D2='ACD' then<br> sDA:='ACDAD';<br> if D2='ABD' then<br> sDA:='ABDAD';<br><br> if D2='AB' then<br> sDA:='AB';<br> if D2='AC' then<br> sDA:='AC';<br> if D2='AD' then<br> sDA:='AD';<br> if D2='BC' then<br> sDA:='BC';<br> if D2='BD' then<br> sDA:='BD';<br> if D2='CD' then<br> sDA:='CD';<br> CheckDX:=(Pos(D1,sDA)>0);<br>end;<br>procedure TFrmBZDK.btnClearClick(Sender: TObject);<br>begin<br> if bsSkinMessage1.MessageDlg('你确定清空自由阅卷成绩库?',(mtConfirmation),[mbYES,mbNO],0)=mrYes then<br> begin<br> QTemp.Close;<br> QTemp.SQL.Clear;<br> QTemp.SQL.Add('DELETE FROM CJK WHERE JB='+JBDM);<br> QTemp.ExecSQL;<br> QCJK.Close;<br> QCJK.Open;<br> end;<br>end;<br><br>procedure TFrmBZDK.btnDCClick(Sender: TObject);<br>begin<br> main.FrmMain.ToXLS(dxDBLookupTreeView1.Text+'成绩.xls',cxGrid2);<br>end;<br><br>procedure TFrmBZDK.bsSkinLabel8DblClick(Sender: TObject);<br>begin<br> iDK:=0;<br> bsSkinLabel8.Caption:='已阅卷人数(双击此处计数器置0):'+IntToStr(iDK);<br><br>end;<br><br>procedure TFrmBZDK.dsQCJKDataChange(Sender: TObject; Field: TField);<br>begin<br> bsSkinStatusPanel3.Caption:='库中有记录:'+IntToStr(QCJK.RecordCount);<br>end;<br><br>procedure TFrmBZDK.bsSkinButton1Click(Sender: TObject);<br>begin<br> if not Assigned(FrmBZDA) then<br> begin<br> FrmBZDA:=TFrmBZDA.Create(self);<br> end;<br> FrmBZDA.ShowModal;<br><br>end;<br><br>procedure TFrmBZDK.QCJK2CalcFields(DataSet: TDataSet);<br>begin<br> QCJK2.FieldByName('ZF').AsFloat:=QCJK2.FieldByName('ZZ').AsFloat+<br> QCJK2.FieldByName('YW').AsFloat+<br> QCJK2.FieldByName('YY').AsFloat+<br> QCJK2.FieldByName('SX').AsFloat+<br> QCJK2.FieldByName('WL').AsFloat+<br> QCJK2.FieldByName('HX').AsFloat+<br> QCJK2.FieldByName('SW').AsFloat+<br> QCJK2.FieldByName('XJ').AsFloat+<br> QCJK2.FieldByName('DL').AsFloat+<br> QCJK2.FieldByName('QT').AsFloat;<br><br>end;<br><br>end.