主ABQuery和从ABQuery不能设置缓存更新为真(默认设置即可)
if ABStartTransaction(rstUpSalesDetail.ConnName,tempConnObjectIndex) then
begin
try
OpenQuery(masterQuery,'select top 1 * from T_Purchase where 1=0');
OpenQuery(rstUpSalesDetail,'select top 1 * from T_PurchaseDetail where 1=0');
vNewID:=ABGetGuid(gtGuID);
masterQuery.Append;
masterQuery.FieldByName('PurchaseID').AsString:=vNewID;
masterQuery.FieldByName('SupplierID').AsString:=OrderABQuery.FieldByName('SupplierID').AsString;
masterQuery.FieldByName('DepartmentID').AsString:=OrderABQuery.FieldByName('DepartmentID').AsString;
masterQuery.FieldByName('Date').AsString:=FormatDateTime('yyyy-mm-dd',Date);
masterQuery.Post;
rstSourceData.First;
while not rstSourceData.Eof do
begin
rstUpSalesDetail.Append;
rstUpSalesDetail.FieldByName('PurchaseDetailID').AsString:=ABGetGuid(gtGuID);
rstUpSalesDetail.FieldByName('GoodsID').AsString:=rstSourceData.FieldByName('GoodsID').AsString;
rstUpSalesDetail.FieldByName('PurchaseID').AsString:=vNewID;
rstUpSalesDetail.FieldByName('ColorID').AsString:=rstSourceData.FieldByName('ColorID').AsString;
rstUpSalesDetail.FieldByName('UnitPrice').AsCurrency:=rstSourceData.FieldByName('UnitPrice').AsCurrency;
rstUpSalesDetail.FieldByName('DiscountRate').AsCurrency:=rstSourceData.FieldByName('DiscountRate').AsCurrency;
for i:=1 to MaxSizeCol do
rstUpSalesDetail.FieldByName('x_'+IntToStr(i)).AsInteger:=rstSourceData.FieldByName('x_'+IntToStr(i)).AsInteger;
rstUpSalesDetail.FieldByName('SizeIndex').AsInteger:= MaxSizeCol;
rstUpSalesDetail.FieldByName('Quantity').AsInteger:=Basedata.rstFind3.FieldByName('Quantity').AsInteger;
QtyChang(rstUpSalesDetail.FieldByName('x_1'));
rstUpSalesDetail.FieldByName('Discount').AsInteger:=Basedata.rstFind3.FieldByName('Discount').AsInteger;
rstUpSalesDetail.FieldByName('Amount').AsInteger:=Basedata.rstFind3.FieldByName('Amount').AsInteger;
rstUpSalesDetail.Post;
rstSourceData.Next;
end;
OpenQuery(masterQuery,'update a set QuantitySum=b.qty,a.AmountSum=b.Amt from T_Purchase a,(select sum(quantity) qty,sum(Amount) amt,'+
'sum(Discount) disAmt from T_PurchaseDetail where PurchaseID='''+masterQuery.FieldByName('PurchaseID').AsString+''') b where a.PurchaseID='''+
masterQuery.FieldByName('PurchaseID').AsString+'''',True);
ABCommitTransaction(rstUpSalesDetail.ConnName,tempConnObjectIndex);
ABShow('已成功');
except
on E: Exception do
begin
ABRollbackTransaction(rstUpSalesDetail.ConnName,tempConnObjectIndex);
ABShow('错误!',e.Message);
raise;
end;
end;
end;