幫我看看下面代碼有什麼問題嗎?我看了一上午沒看出問題來。 ( 积分: 100 )

  • 主题发起人 主题发起人 fxjpost
  • 开始时间 开始时间
F

fxjpost

Unregistered / Unconfirmed
GUEST, unregistred user!
dm.Command.CommandText := " begin tran "
+ " delete from data "
+ " delete from temp_data "
+ " commit tran ";
dm.Command.Execute;
OpenDial := TopenDialog.Create(self);
while bStop < >1 do
begin
OpenDial.Filter := &quot;Text files (*.txt) &amp;brvbar;*.TXT &quot;;
if OpenDial.Execute then
fileName := OpenDial.FileName
else
break;
if fileName < > &quot; &quot; then
InsertData(fileName, &quot;1 &quot;);
if MessageDlg( &quot;還有掃描檔嗎? &quot;,mtConfirmation, [mbYes, mbNo], 0) = mrYes then//這個地方執行後,直接跳出while語句,為什麼?
begin
bStop := 0;
continue;
end else
begin
bStop := 1;
 
procedure TDM.importBarDate(strBM: string);
var Data: TStringList;
OpenDial: TopenDialog;
bStop:integer;
fileName: string;
procedure insertData(sFileName, style: string);
var Data: TStringList;
Qry: TAdoQuery;
BM, RY, SL, TM: string;
i: integer;
begin
Data := TStringList.Create;
Qry := dm.CreateAdoQuery;
try
Qry.LockType := ltBatchOptimistic;
Data.LoadFromFile(sfileName);
Data.Sort;
Qry.SQL.Add('Select * From Temp_Data where 1<>1 ');
Qry.Open;
for i := Data.Count - 1 downto 0 do
begin
if copy(Data, 34, 1) = style then //1 代表進貨
begin
BM := substr(Data, 3, 4);
if BM <> strBM then continue;
RY := substr(Data, 34, 1);
SL := substr(Data, 36, 5);
TM := trim(Copy(Data, 8, 13));
//TM := lpad(tm, 13, '0');
Qry.Append;
Qry.FieldByName('BM_DM').AsString := BM;
Qry.FieldByName('TM').AsString := TM;
Qry.FieldByName('YD_RY').AsString := RY;
Qry.FieldByName('SL').AsInteger := strtoint(trim(SL));
Data.Delete(i);
end;
end;
Qry.UpdateBatch();
finally
Data.free;
Qry.Free;
end;
end;
///
begin
//先把數據用insertdata過程把數據插入temp_data,然後再把temp_data的數據處理後插入data表中。
//刪除先前bardata數據。
dm.Command.CommandText := ' begin tran '
+ ' delete from data '
+ ' delete from temp_data '
+ ' commit tran ';
dm.Command.Execute;
OpenDial := TopenDialog.Create(self);
while bStop<>1 do
begin
OpenDial.Filter := 'Text files (*.txt)|*.TXT';
if OpenDial.Execute then
fileName := OpenDial.FileName
else
break;
if fileName <> '' then
InsertData(fileName, '1');
if MessageDlg('還有掃描檔嗎?',mtConfirmation, [mbYes, mbNo], 0) = mrYes then
begin
bStop := 0;
continue;
end else
begin
bStop := 1;
break;
end;
end;

with dm do //
begin
dm.Command.CommandText := ' INSERT INTO DATA (BM_DM,TM,YD_RY,SL) '
+ ' SELECT BM_DM,TM,YD_RY,SUM(CONVERT(INTEGER,SL)) '
+ ' FROM TEMP_DATA '
+ ' GROUP BY BM_DM,TM,YD_RY ';
dm.Command.Execute;
end;

end;
 
找到原因了,不能在TDM裡創建
OpenDial := TopenDialog.Create(self);
 
后退
顶部