2,497
社区成员
发帖
与我相关
我的任务
分享
procedure Tfm_ITime.DBTimeInfSelectionChanged(Sender: TObject);
var
sum,i:integer;
begin
self.GetTotal;
end;
procedure Tfm_ITime.GetTotal;
var
Total: double;
BM: TBookmarkStr;
tmpsum,i:integer;
begin
if not dm.ADO_TimeInf.Active then exit;
if dbtimeinf.DataSource.DataSet.RecordCount<1 then exit;
if dbtimeinf.Selection.SelectionType = gstNon then exit;
if dbtimeinf.Selection.SelectionType = gstRecordBookmarks then
if dbtimeinf.SelectedRows.Count=0 then exit;
tmpsum:=dm.GetDBField(dbtimeinf,'fmoney');
if tmpsum=-1 then exit;
{if tmpsum>=0 then
begin
dbtimeinf.Columns[tmpsum].Footer.Color:=clyellow;
dbtimeinf.Columns[tmpsum].Footer.ValueType:=fvtstatictext;
end;}
total:=0;
{if dbtimeinf.Selection.SelectionType = gstRecordBookmarks then
begin
for i:=0 to DBTimeInf.SelectedRows.Count-1 do
begin
dbtimeinf.DataSource.DataSet.GotoBookmark(pointer(DBTimeInf.SelectedRows.Items[i]));
total:=total+dbtimeinf.Fields[tmpsum].AsFloat;
end;
moneysum.Caption:='选中:'+inttostr(DBTimeInf.SelectedRows.Count)+',求和:'+floatToStr(Total);
end
else if DBTimeInf.Selection.SelectionType = gstAll then
begin
DBTimeInf.DataSource.DataSet.First;
while not DBTimeInf.DataSource.DataSet.Eof do
begin
total:=total+dbtimeinf.Fields[tmpsum].AsFloat;
DBTimeInf.DataSource.DataSet.Next;
end;
moneysum.Caption:='选中:'+inttostr(DBTimeInf.DataSource.DataSet.RecordCount)+',求和:'+floatToStr(Total);
end;}
with DBTimeInf do
begin
with Datasource.Dataset do
try
// BM := Bookmark;
SaveBookmark;
DisableControls;
try
case Selection.SelectionType of
gstRecordBookmarks:
begin
for I := 0 to Selection.Rows.Count-1 do
begin
Bookmark := Selection.Rows[I];
total:=total+dbtimeinf.Fields[tmpsum].AsFloat;
end;
moneysum.Caption:='选中:'+inttostr(DBTimeInf.SelectedRows.Count)+',求和:'+floatToStr(Total);
end;
gstAll:
begin
First;
while EOF = False do
begin
total:=total+dbtimeinf.Fields[tmpsum].AsFloat;
Next;
end;
moneysum.Caption:='选中:'+inttostr(DBTimeInf.SelectedRows.Count)+',求和:'+floatToStr(Total);
end;
end;
finally
//Bookmark := BM;
RestoreBookmark;
EnableControls;
end;
finally
end;
end;
end;