//對分錄表進行插入和修改時所執行的操作
procedure TDocuInputOpType(opname: string);
var
i:integer;
inputvaloutputvaloldnum:string;
begin
//如果是新增憑證則直接將分錄表中的數據逐條插入
if opname=insert then
begin
for i:= to do
begin
//如果表格中為空則跳出循環
if stringgridCells[i]= then continue;
inputval:=stringgridcells[i];
outputval:=stringgridcells[i];
//插入數據由於借方和貸方數據在sql server中為money故需要進行轉換
adocommandCommandText:=insert into 分錄表([憑證編號][科目代碼]
[借方][貸方][摘要]) values(+dbeditText+
+stringgridCells[i]+cast(+inputval+ as money)
cast(+outputval+ as money)+stringgridCells[i]+);
adocommandExecute;
end;
end;
if opname=edit then
begin
for i:= to do
begin
if stringgridCells[i]= then continue;
inputval:=stringgridcells[i];
outputval:=stringgridcells[i];
//對憑證所屬的分錄表原有數據進行更新
if i<=recordnum then
adocommandCommandText:=update 分錄表 set [科目代碼]
=+stringgridcells[i]+[借方]=cast(+inputval+ as money)
[貸方]=cast(+outputval+ as money)[摘要]=+stringgridCells[i]
+ where 編號=+mytable[i]+
else
//插入憑證所屬的分錄表中的新數據
adocommandCommandText:=insert into 分錄表([憑證編號][科目代碼]
[借方][貸方][摘要]) values(+dbeditText+
+stringgridCells[i]+cast(+inputval+ as money)
cast(+outputval+ as money)+stringgridCells[i]+);
adocommandExecute;
end;
end;
end;
[] [] []
From:http://tw.wingwit.com/Article/program/Delphi/201311/24842.html