关于SQL2K的问题.(20分)

  • 主题发起人 主题发起人 易名烦
  • 开始时间 开始时间

易名烦

Unregistered / Unconfirmed
GUEST, unregistred user!
小弟有有三个问题请问各位大哥大姐:
1、常出现“超时已过期”的提示。
2、程序运行时窗口动不了,加application.ProcessMessages;也不行,可能是加的地方不对!
3、最后有个提示“PASS”,但是有运行完了还出不来,象被卡住了,要按ALT+TAB才会弹出。
代码如下,如果能改进,请赐教:
procedure TFRLRTHD.BitBtn1Click(Sender: TObject);
VAR
TXTFILE:TSTRINGS;
TXTSTR:ARRAY [1..10] OF STRING;
M_POINT,I:INTEGER;
PASS:BOOLEAN;
begin
TXTFILE:=TSTRINGLIST.Create;
FRMAIN.ADOConnection1.GetTableNames(TXTFILE,FALSE);
IF TXTFILE.IndexOf('disposalTHD')>-1 THEN
BEGIN
IF MESSAGEBOX(HANDLE,'上次的没有返回系统编号,要继续吗?','提示',MB_OKCANCEL+MB_ICONWARNING)=IDOK THEN
FRMAIN.MDeleTable('disposalTHD')
ELSE
EXIT;
END;

IF MESSAGEBOX(HANDLE,pchar('确定已执行系统导出了吗?'+#13+'文件名:'+statusbar1.Panels[1].text),'提示',MB_OKCANCEL+MB_ICONINFORMATION)=IDCANCEL THEN
EXIT;

//判断文件存在否
IF NOT FILEEXISTS(STATUSBAR1.Panels[1].Text) THEN
BEGIN
MESSAGEBOX(HANDLE,pchar('文件不存在!'+#13+statusbar1.Panels[1].text),'提示',MB_OK+MB_ICONERROR);
EXIT;
END;

//判断文件是否正确
TXTFILE.Clear;
TXTFILE.LoadFromFile(STATUSBAR1.Panels[1].TEXT);
TXTSTR[1]:=TXTFILE[0];
//取字符串
M_POINT:=2;
WHILE ANSIPOS(#9,TXTSTR[1])<>0 do
BEGIN
TXTSTR[M_POINT]:=COPY(TXTSTR[1],1,ANSIPOS(#9,TXTSTR[1])-1);
DELETE(TXTSTR[1],1,ANSIPOS(#9,TXTSTR[1]));
M_POINT:=M_POINT+1;
END;

//判断凭证号是否数字,
IF (ORD(TXTSTR[2][1])>47) AND (ORD(TXTSTR[2][1])<58) THEN
//类型是否英文,
IF (ORD(TXTSTR[4][1])>64) AND (ORD(TXTSTR[4][1])<91) THEN
//代码是否数字,
begin
IF NOT((ORD(TXTSTR[6][1])>47) AND (ORD(TXTSTR[6][1])<58)) THEN
BEGIN
MESSAGEBOX(HANDLE,pchar('不是系统导出文件!'+#13+statusbar1.Panels[1].text),'提示',MB_OK+MB_ICONERROR);
EXIT;
END;
end
ELSE
BEGIN
MESSAGEBOX(HANDLE,pchar('不是系统导出文件!'+#13+statusbar1.Panels[1].text),'提示',MB_OK+MB_ICONERROR);
EXIT;
END
ELSE
begin
MESSAGEBOX(HANDLE,pchar('不是系统导出文件!'+#13+statusbar1.Panels[1].text),'提示',MB_OK+MB_ICONERROR);
EXIT;
end;

SCREEN.Cursor:=CRHOURGLASS;
//导入系统导出文件
WITH ADOQUERY1 DO
BEGIN
CLOSE;
SQL.Clear;
SQL.Add('DELETE FROM DDTT');
EXECSQL;
END;
FOR I:=0 TO TXTFILE.Count-1 DO
BEGIN
TXTSTR[1]:=TXTFILE;
M_POINT:=2;
WHILE ANSIPOS(#9,TXTSTR[1])<>0 do
BEGIN
TXTSTR[M_POINT]:=COPY(TXTSTR[1],1,ANSIPOS(#9,TXTSTR[1])-1);
DELETE(TXTSTR[1],1,ANSIPOS(#9,TXTSTR[1]));
M_POINT:=M_POINT+1;
END;
WITH ADOQUERY1 DO
BEGIN
SQL.Clear;
SQL.Add('INSERT INTO DDTT VALUES ('
+MAIN.SEMICOLON+TXTSTR[2]+MAIN.SEMICOLON+','
+MAIN.SEMICOLON+TXTSTR[3]+MAIN.SEMICOLON+','
+MAIN.SEMICOLON+TXTSTR[4]+MAIN.SEMICOLON+','
+MAIN.SEMICOLON+TXTSTR[5]+MAIN.SEMICOLON+','
+MAIN.SEMICOLON+TXTSTR[6]+MAIN.SEMICOLON+')');
EXECSQL;
END;
END;
showmessage('1');
FRMAIN.MDeleTable('LS_PH');
WITH ADOQUERY1 DO
BEGIN
CLOSE;
SQL.Clear;
SQL.Add('CREATE TABLE LS_PH (BH VARCHAR(50))');
EXECSQL;

SQL.Clear;
SQL.Add('INSERT INTO LS_PH SELECT * FROM ZPH');
EXECSQL;

SQL.Clear;
SQL.Add('INSERT INTO LS_PH SELECT DISTINCT POBH FROM DDTT');
EXECSQL;

SQL.Clear;
SQL.Add('INSERT INTO ZPH SELECT DISTINCT BH FROM LS_PH');
EXECSQL;

FRMAIN.MDeleTable('LS_PH');

SQL.Clear;
SQL.Add('SELECT * INTO disposalTHD FROM THD_DK WHERE YQZ=0 OR YQZ IS NULL');
EXECSQL;

SQL.Clear;
SQL.Add('DELETE FROM disposalTHD WHERE THPH IN (SELECT * FROM ZPH)');
EXECSQL;

SQL.Clear;
SQL.Add('ALTER TABLE disposalTHD ADD JCYWLX VARCHAR(10)');
EXECSQL;

SQL.Clear;
SQL.Add('ALTER TABLE disposalTHD ADD JCWLDM VARCHAR(20)');
EXECSQL;

SQL.Clear;
SQL.Add('ALTER TABLE disposalTHD ADD JCBM VARCHAR(10)');
EXECSQL;

SQL.Clear;
SQL.Add('DELETE FROM DDPSR');
EXECSQL;

SQL.Clear;
SQL.Add('SELECT * FROM disposalTHD');
OPEN;

FIRST;
WHILE NOT EOF DO
BEGIN
//替换类型
ADOQUERY2.Close;
ADOQUERY2.SQL.Clear;
ADOQUERY2.SQL.Add('SELECT * FROM YWLX WHERE YWLX=:YWLX');
ADOQUERY2.Parameters.ParamByName('YWLX').Value:=FIELDS.FIELDBYNAME('YWLX').AsString;
ADOQUERY2.Open;
IF ADOQUERY2.RecordCount>0 THEN
BEGIN
EDIT;
FIELDS.FieldByName('JCYWLX').AsString:=ADOQUERY2.Fields.FieldBYNAME('YWLXDM').AsString;
END
ELSE
BEGIN
FRWHYWLX.Edit1.Text:=FIELDS.FIELDBYNAME('YWLX').AsString;
M_CANCEL:=FALSE;
FRWHYWLX.ShowModal;
IF M_CANCEL THEN
BEGIN
SCREEN.Cursor:=CRDEFAULT;
EXIT;
END
ELSE
BEGIN
EDIT;
FIELDS.FieldByName('JCYWLX').AsString:=M_YWLX;
END;
END;
ADOQUERY2.Close;
ADOQUERY2.SQL.Clear;
ADOQUERY2.SQL.Add('SELECT * FROM WLZSJ WHERE JQXH=:JQXH');
ADOQUERY2.Parameters.ParamByName('JQXH').Value:=FIELDS.FIELDBYNAME('JQXH').AsString;
ADOQUERY2.Open;
IF ADOQUERY2.RecordCount>0 THEN
BEGIN
EDIT;
FIELDS.FieldByName('JCWLDM').AsString:=ADOQUERY2.Fields.FieldBYNAME('WLDM').AsString;
FIELDS.FieldByName('JCBM').AsString:=ADOQUERY2.Fields.FIELDBYNAME('BM').AsString;
END
ELSE
BEGIN
FRWHWLDM.Edit1.Text:=FIELDS.FIELDBYNAME('JQXH').AsString;
M_CANCEL:=FALSE;
FRWHWLDM.ShowModal;
IF M_CANCEL THEN
BEGIN
SCREEN.Cursor:=CRDEFAULT;
EXIT;
END
ELSE
BEGIN
EDIT;
FIELDS.FieldByName('JCWLDM').AsString:=M_WLDM;
FIELDS.FieldByName('JCBM').AsString:=M_BM;
END;
END;
//替换单价
IF COPY(INTTOSTR(STRTOINT(FIELDS.FIELDBYNAME('DWBH1').AsString)),1,1)='9' THEN
BEGIN
ADOQUERY2.Close;
ADOQUERY2.SQL.Clear;
ADOQUERY2.SQL.Add('SELECT * FROM PR01 WHERE F3=:F3 AND F51=:F51');
ADOQUERY2.PARAMETERS.ParamByName('F3').Value:=FIELDS.FIELDBYNAME('JCWLDM').AsString;
ADOQUERY2.PARAMETERS.ParamByName('F51').Value:=INTTOSTR(STRTOINT(FIELDS.FIELDBYNAME('BGSDM').AsString));
ADOQUERY2.OPEN;
IF ADOQUERY2.RecordCount>0 THEN
BEGIN
EDIT;
FIELDS.FieldByName('DJ').AsInteger:=ADOQUERY2.Fields.FieldBYNAME('F6').AsInteger;
END
ELSE
BEGIN
ADOQUERY2.Close;
ADOQUERY2.SQL.Clear;
ADOQUERY2.SQL.Add('SELECT * FROM PR01 WHERE F3=:F3');
ADOQUERY2.PARAMETERS.ParamByName('F3').Value:=FIELDS.FIELDBYNAME('JCWLDM').AsString;
ADOQUERY2.OPEN;
IF ADOQUERY2.RecordCount>0 THEN
BEGIN
EDIT;
FIELDS.FieldByName('DJ').AsInteger:=ADOQUERY2.Fields.FIELDBYNAME('F6').AsInteger;
END
ELSE
BEGIN
IF MESSAGEBOX(HANDLE,pchar('有物料单价未维护,是否继续检测?'+#13+FIELDS.FIELDBYNAME('BGSDM').ASSTRING
+' 的 '+FIELDS.FieldBYNAME('JQXH').ASSTRING+#13+'点击“确定”继续,“取消”通出?'),
'提示',MB_OKCANCEL+MB_ICONWARNING)=IDOK THEN
PASS:=FALSE
ELSE
EXIT;
END;
END;
END;
//替换独立核算的单价
IF ANSIPOS(INTTOSTR(STRTOINT(Fields.FieldByName('DWBH1').AsString)),FRMAIN.ADOCONFIG.Fields.FIELDBYNAME('DLHS').AsString)>0 THEN
BEGIN
IF ANSIPOS(FIELDS.FieldByName('JCYWLX').AsString,'ZORD ZTPD')>0 THEN
BEGIN
ADOQUERY2.Close;
ADOQUERY2.SQL.Clear;
ADOQUERY2.SQL.Add('SELECT * FROM PR01 WHERE F3=:F3 AND F51=:F51');
ADOQUERY2.PARAMETERS.ParamByName('F3').Value:=FIELDS.FIELDBYNAME('JCWLDM').AsString;
ADOQUERY2.PARAMETERS.ParamByName('F51').Value:=INTTOSTR(STRTOINT(FIELDS.FIELDBYNAME('BGSDM').AsString));
ADOQUERY2.OPEN;
IF ADOQUERY2.RecordCount>0 THEN
BEGIN
EDIT;
FIELDS.FieldByName('DJ').AsInteger:=ADOQUERY2.Fields.FieldBYNAME('F6').AsInteger;
END
ELSE
BEGIN
ADOQUERY2.Close;
ADOQUERY2.SQL.Clear;
ADOQUERY2.SQL.Add('SELECT * FROM PR01 WHERE F3=:F3');
ADOQUERY2.PARAMETERS.ParamByName('F3').Value:=FIELDS.FIELDBYNAME('JCWLDM').AsString;
ADOQUERY2.OPEN;
IF ADOQUERY2.RecordCount>0 THEN
BEGIN
EDIT;
FIELDS.FieldByName('DJ').AsInteger:=ADOQUERY2.Fields.FIELDBYNAME('F6').AsInteger;
END
ELSE
BEGIN
IF MESSAGEBOX(HANDLE,pchar('有物料单价未维护,是否继续检测?'+#13+FIELDS.FIELDBYNAME('BGSDM').ASSTRING
+' 的 '+FIELDS.FieldBYNAME('JQXH').ASSTRING+#13+'点击“确定”继续,“取消”通出?'),
'提示',MB_OKCANCEL+MB_ICONWARNING)=IDOK THEN
PASS:=FALSE
ELSE
EXIT;
END;
END;
END;
END;

//写记录
ADOQUERY2.Close;
ADOQUERY2.SQL.Clear;
ADOQUERY2.SQL.Add('INSERT INTO DDPSR VALUES (:P1,:P2,:P3,:P4,:P5,:P6,:P7,:P8,:P9,:P10,:P11,:P12,:P13,:P14,:P15,:P16,:P17,:P18,:P19,:P20,:P21,:P22,:P23,:P24)');
ADOQUERY2.Parameters.ParamByName('P1').Value:=FIELDS.FIELDBYNAME('JCYWLX').AsString;
ADOQUERY2.Parameters.ParamByName('P2').Value:='2000';
ADOQUERY2.Parameters.ParamByName('P3').Value:='11';
ADOQUERY2.Parameters.ParamByName('P4').Value:=FIELDS.FIELDBYNAME('JCBM').AsString;
ADOQUERY2.Parameters.ParamByName('P5').Value:=FIELDS.FieldBYNAME('BGSDM').AsString;
ADOQUERY2.Parameters.ParamByName('P6').Value:=FIELDS.FIELDBYNAME('XSZDM').AsString;
ADOQUERY2.Parameters.ParamByName('P7').Value:=FIELDS.FieldBYNAME('THPH').AsString;
ADOQUERY2.Parameters.ParamByName('P8').Value:='';
ADOQUERY2.Parameters.ParamByName('P9').Value:=FIELDS.FIELDBYNAME('NN').AsString+'.'+FIELDS.FIELDBYNAME('YY').AsString+'.'+FIELDS.FIELDBYNAME('RR').AsString;
ADOQUERY2.Parameters.ParamByName('P10').Value:=FIELDS.FIELDBYNAME('DWBH1').AsString;
IF FIELDS.FIELDBYNAME('FXDM').AsString='' THEN
ADOQUERY2.Parameters.ParamByName('P11').Value:=FIELDS.FIELDBYNAME('DWBH1').AsString
ELSE
ADOQUERY2.Parameters.ParamByName('P11').Value:=FIELDS.FIELDBYNAME('FXDM').AsString;
IF STRTODATE(FIELDS.FIELDBYNAME('NN').AsString+'-'+FIELDS.FIELDBYNAME('YY').AsString+'-'+FIELDS.FIELDBYNAME('RR').AsString)>DATE() THEN
ADOQUERY2.Parameters.ParamByName('P12').Value:=FORMATDATETIME('YYYY',DATE())+'.'+FORMATDATETIME('MM',DATE())+'.'+FORMATDATETIME('DD',DATE())
ELSE
ADOQUERY2.Parameters.ParamByName('P12').Value:=FIELDS.FIELDBYNAME('NN').AsString+'.'+FIELDS.FIELDBYNAME('YY').AsString+'.'+FIELDS.FIELDBYNAME('RR').AsString;
ADOQUERY2.Parameters.ParamByName('P13').Value:=FIELDS.FIELDBYNAME('GCDM').AsString;
IF STRTODATE(FIELDS.FIELDBYNAME('NN').AsString+'-'+FIELDS.FIELDBYNAME('YY').AsString+'-'+FIELDS.FIELDBYNAME('RR').AsString)>DATE() THEN
ADOQUERY2.Parameters.ParamByName('P14').Value:=FORMATDATETIME('YYYY',DATE())+'.'+FORMATDATETIME('MM',DATE())+'.'+FORMATDATETIME('DD',DATE())
ELSE
ADOQUERY2.Parameters.ParamByName('P14').Value:=FIELDS.FIELDBYNAME('NN').AsString+'.'+FIELDS.FIELDBYNAME('YY').AsString+'.'+FIELDS.FIELDBYNAME('RR').AsString;
IF ANSIPOS(FIELDS.FieldByName('JCYWLX').AsString,'ZRE ZKAD')>0 THEN
ADOQUERY2.Parameters.ParamByName('P15').Value:='008'
ELSE
ADOQUERY2.Parameters.ParamByName('P15').Value:=' ';
ADOQUERY2.Parameters.ParamByName('P16').Value:=FIELDS.FIELDBYNAME('JCWLDM').AsString;
ADOQUERY2.Parameters.ParamByName('P17').Value:=FIELDS.FIELDBYNAME('SL').AsFloat;
ADOQUERY2.Parameters.ParamByName('P19').Value:=FIELDS.FIELDBYNAME('SFJX').AsString;
ADOQUERY2.Parameters.ParamByName('P20').Value:=0;
ADOQUERY2.Parameters.ParamByName('P21').Value:=0;
ADOQUERY2.Parameters.ParamByName('P22').Value:=DATETOSTR(DATE());
IF ANSIPOS(FIELDS.FIELDBYNAME('JCYWLX').AsString,'ZKBD ZKAD')>0 THEN
BEGIN
ADOQUERY2.Parameters.ParamByName('P18').Value:=0;
ADOQUERY2.Parameters.ParamByName('P23').Value:='08';
END
ELSE
IF FIELDS.FieldByName('JCYWLX').AsString='ZORD' THEN
BEGIN
ADOQUERY2.Parameters.ParamByName('P18').Value:=FIELDS.FIELDBYNAME('DJ').AsFloat;
ADOQUERY2.Parameters.ParamByName('P23').Value:='08';
END
ELSE
BEGIN
ADOQUERY2.Parameters.ParamByName('P18').Value:=FIELDS.FIELDBYNAME('DJ').AsFloat;
ADOQUERY2.Parameters.ParamByName('P23').Value:='03';
END;
ADOQUERY2.Parameters.ParamByName('P24').Value:='';
ADOQUERY2.ExecSQL;
//下一条
NEXT;
END;
UpdateBatch();
CLOSE;
SQL.Clear;
SQL.Add('SELECT * FROM DDPSR ORDER BY POBH');
OPEN;
ADOQUERY2.Close;
ADOQUERY2.SQL.Clear;
ADOQUERY2.SQL.Add('SELECT POBH,COUNT(POBH) AS XMS FROM DDPSR GROUP BY POBH');
ADOQUERY2.Open;

TXTFILE.Clear;

FIRST;
WHILE NOT EOF DO
BEGIN
ADOQUERY2.Locate('POBH',FIELDS.FIELDBYNAME('POBH').AsString,[]);
EDIT;
FIELDS.FieldByName('DDPH').AsInteger:=ADOQUERY2.RecNo;
FIELDS.FieldByName('XMS').AsString:=ADOQUERY2.Fields.FIELDBYNAME('XMS').AsString;
FIELDS.FieldByName('DDS').AsInteger:=ADOQUERY2.RecordCount;
TXTFILE.Add( LEFTSTR(trim(FIELDS.FIELDBYNAME('DDLX').AsString)+' ',4)
+'2000'+'11'+LEFTSTR(trim(FIELDS.FieldBYNAME('BM').AsString),2)
+LEFTSTR(trim(FIELDS.FIELDBYNAME('XSBGS').AsString),4)
+LEFTSTR(trim(FIELDS.FIELDBYNAME('XSZ').AsString),3)
+LEFTSTR(trim(FIELDS.FieldBYNAME('POBH').AsString)+' ',35)
+LEFTSTR(trim(FIELDS.FieldBYNAME('DDPH').AsString)+' ',10)
+LEFTSTR(trim(FIELDS.FieldBYNAME('CGDDRQ').AsString)+' ',10)
+RIGHTSTR('0000000000'+trim(FIELDS.FieldBYNAME('SHDF').AsString),10)
+RIGHTSTR('0000000000'+trim(FIELDS.FieldBYNAME('SODF').AsString),10)
+LEFTSTR(trim(FIELDS.FieldBYNAME('JHRQ').AsString)+' ',10)
+LEFTSTR(trim(FIELDS.FieldBYNAME('GCDM').AsString)+' ',4)
+LEFTSTR(trim(FIELDS.FieldBYNAME('DJRQ').AsString)+' ',10)
+LEFTSTR(trim(FIELDS.FieldBYNAME('DDYY').AsString)+' ',3)
+LEFTSTR(trim(FIELDS.FieldBYNAME('WLDM').AsString)+' ',18)
+RIGHTSTR(' '+FORMAT('%10.2f',[FIELDS.FieldBYNAME('THSL').ASFLOAT]),19)
+RIGHTSTR(' '+FORMAT('%10.2f',[FIELDS.FieldBYNAME('XSDJ').ASFLOAT]),16)
+LEFTSTR(trim(FIELDS.FieldBYNAME('TPBZ').AsString)+' ',28)
+RIGHTSTR(' '+trim(FIELDS.FieldBYNAME('XMS').AsString),3)
+RIGHTSTR(' '+trim(FIELDS.FieldBYNAME('DDS').AsString),10)
+FORMATDATETIME('YYYYMMDD',DATE())
+LEFTSTR(trim(FIELDS.FieldBYNAME('FPDJ').AsString)+' ',2)
);
//下一条
NEXT;
END;
UPDATEBATCH();
TXTFILE.SaveToFile('C:/M_DDPSR.TXT');
END;

SCREEN.Cursor:=CRDEFAULT;
SHOWMESSAGE('PASS');
txtfile.Free;
end;
 
你先在这段代码的第一句处设置断点,然后再单步调试,看看是在哪一句处卡了壳,再
把这一句指出来,要看完这么一大段代码倒真是头晕。
 
呵呵,我写的全是一堆大粪!
 
1) 可能是网络连接或者是ConnectionString/ODBC DSN配置问题
2) 把你的处理过程做进一个TThread代替
3) ...不明白
 
我怀疑是ShowModal的问题, 你把所有的MessageBox都用Memo来处理, 然后看看行不行.
If you create a message box while a dialog box is present, use the handle of
the dialog box as the hWnd parameter. The hWnd parameter should not identify
a child window, such as a control in a dialog box.
 
我用的是MDI,当前是个子窗口!
 
netfool:
连接还出错啊,没问搞错哦。
线程我还不会写!
 
[red]The hWnd parameter should not identify
a child window, such as a control in a dialog box.[/red]
 
你的ADO引擎的驱动是什么版本呢?如果是安装的SQL2K的客户端就不用回答了,我记得
如果ADO引擎不对的话,数据库操作就会特别得慢,会报那个“超时已过期”
 
就是装了客户端!
还有人会吗?
 
多人接受答案了。
 

Similar threads

I
回复
0
查看
629
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部