飞蓬打得过邪剑仙吗:dbgrideh中多选时selection 这里只处理区域(有问题,已解决)
来源:百度文库 编辑:九乡新闻网 时间:2024/04/29 06:06:14
procedure DbgridEhMouseUpExtend(Sender: TObject);type TCalcFld= record fldId: Integer; fldCol: Integer;//第几列 fldName: string; fldTitle: string; end; TCalcFldList= array of TCalcFld; TCalcResult= record fldId: Integer; //对应CalcFld中的FldId fldSum: Extended; //合计 fldNum: integer; //计数 end; TCalcRstList= array of TCalcResult;var AGridEh: TDBGridEh; TopBookMark: TBookmark; BottomBookMark: TBookmark; CurbookMark: TBookmark; aBeforeScroll,aAfterScroll: TDataSetNotifyEvent; numCount: Integer; numSum: Extended; numAvg: Extended; i,j: Integer; strMsg: string; cLeft,cRight: Integer; CalcFldList: TCalcFldList; //统计列信息 CalcRstList: TCalcRstList; //统计数据信息begin AGridEh:= TDBGridEh(Sender); if not AGridEh.DataSource.DataSet.Active then Exit; CurbookMark:= AGridEh.DataSource.DataSet.GetBookmark; aBeforeScroll:= AGridEh.DataSource.DataSet.BeforeScroll; aAfterScroll:= AGridEh.DataSource.DataSet.AfterScroll; AGridEh.DataSource.DataSet.DisableControls; try numSum:= 0; numCount:= 0; AGridEh.DataSource.DataSet.Bookmark:= AGridEh.Selection.Rect.TopRow; if AGridEh.Selection.Rows.Count>0 then begin //行级选择 改用很耗时的算法 SetLength(CalcFldList,AGridEh.VisibleColCount); j:= 0; for i:= 0 to AGridEh.VisibleColCount-1 do begin if AGridEh.Fields[i].DataType in [ftSmallint, ftInteger, ftWord, ftFloat, ftCurrency, ftBCD,ftLargeint] then begin CalcFldList[j].fldId:= j; CalcFldList[j].fldCol:= i; CalcFldList[j].fldName:= AGridEh.Fields[i].FieldName; CalcFldList[j].fldTitle:= AGridEh.Fields[i].Text; Inc(j); end; end; SetLength(CalcFldList,j); SetLength(CalcRstList,High(Calcfldlist)+1); for i:= 0 to High(CalcRstList) do begin CalcRstList[i].fldId:= i; CalcRstList[i].fldSum:= 0; CalcRstList[i].fldNum:= 0; end; AGridEh.Selection.Rows.DataSet.First; //AGridEh.Selection.Rows. while not AGridEh.Selection.Rows.DataSet.Eof do begin //这里会遍历全部 if AGridEh.Selection.Rows.CurrentRowSelected then begin for i:= 0 to High(CalcFldList) do begin if AGridEh.Fields[CalcFldList[i].fldCol].Value<>null then begin CalcRstList[i].fldSum:= CalcRstList[i].fldSum+ AGridEh.Fields[CalcFldList[i].fldCol].Value; inc(CalcRstList[i].fldNum); end; end; end; AGridEh.Selection.Rows.DataSet.Next; end; end else if AGridEh.Selection.Rect.LeftCol<>-1 then begin //区域选择 SetLength(CalcFldList,AGridEh.Selection.Rect.RightCol-AGridEh.Selection.Rect.LeftCol+1); j:= 0; for i:= AGridEh.Selection.Rect.LeftCol to AGridEh.Selection.Rect.RightCol do begin if AGridEh.Fields[i].DataType in [ftSmallint, ftInteger, ftWord, ftFloat, ftCurrency, ftBCD,ftLargeint] then begin CalcFldList[j].fldId:= j; CalcFldList[j].fldCol:= i; CalcFldList[j].fldName:= AGridEh.Fields[i].FieldName; CalcFldList[j].fldTitle:= AGridEh.FieldColumns[AGridEh.Fields[i].FieldName].Title.Caption; Inc(j); end; end; SetLength(CalcFldList,j); SetLength(CalcRstList,High(Calcfldlist)+1); for i:= 0 to High(CalcRstList) do begin CalcRstList[i].fldId:= i; CalcRstList[i].fldSum:= 0; CalcRstList[i].fldNum:= 0; end; while (not AGridEh.DataSource.DataSet.Eof) do begin for i:= 0 to High(CalcFldList) do begin if AGridEh.Fields[CalcFldList[i].fldCol].Value<>null then begin CalcRstList[i].fldSum:= CalcRstList[i].fldSum+ AGridEh.Fields[CalcFldList[i].fldCol].Value; inc(CalcRstList[i].fldNum); end; end; if AGridEh.DataSource.DataSet.Bookmark=AGridEh.Selection.Rect.BottomRow then Break; AGridEh.DataSource.DataSet.Next; end; end else Exit; finally //AGridEh.DataSource.DataSet.GotoBookmark(bookMark); //AGridEh.DataSource.DataSet.Bookmark:= bookMark; AGridEh.DataSource.DataSet.EnableControls; AGridEh.DataSource.DataSet.GotoBookmark(CurbookMark); AGridEh.DataSource.DataSet.AfterScroll:= aAfterScroll; AGridEh.DataSource.DataSet.BeforeScroll:= aBeforeScroll; //AGridEh.DataSource.DataSet.GotoBookmark(CurbookMark); //AGridEh.DataSource.DataSet.GotoBookmark(bookMark); //AGridEh.DataSource.DataSet.EnableControls;// AGridEh.DataSource.DataSet.BeforeScroll:= aBeforeScroll;// AGridEh.DataSource.DataSet.AfterScroll:= aAfterScroll; end; if High(calcFldList)<>-1 then begin for i:= 0 to High(calcFldList) do begin if CalcRstList[i].fldNum<>0 then strMsg:= Format('列名:%s 求和=%f 平均数=%f 计数=%d',[CalcFldList[i].fldTitle,CalcRstList[i].fldSum,CalcRstList[i].fldSum/CalcRstList[i].fldNum,CalcRstList[i].fldNum]) else strMsg:= ''; form1.mmo1.Lines.Add(strMsg); end; end else begin form1.mmo1.Lines.Add('nothing can be calceturated!'); end;end;procedure TForm1.dbGridEh2MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);var AGridEh: TDBGridEh; TopBookMark: TBookmark; BottomBookMark: TBookmark; CurbookMark: TBookmark; aBeforeScroll,aAfterScroll: TDataSetNotifyEvent; numCount: Integer; numSum: Extended; numAvg: Extended; i: Integer; strMsg: string; cLeft,cRight: Integer;beginDbgridEhMouseUpExtend(Sender);Exit;//这里为知为何不能直接操作AGridEh.DataSource.DataSet.BeforeScroll 这些东西,如果操作的话就会摄错.//晕,原来是没有赋值的原因// StrPCopy(TopBookMark,AGridEh.Selection.Rect.TopRow);// StrPCopy(BottomBookMark,AGridEh.Selection.Rect.BottomRow); //if not AGridEh.DataSource.DataSet.Active then Exit;// aBeforeScroll:= AGridEh.DataSource.DataSet.BeforeScroll;// aAfterScroll:= AGridEh.DataSource.DataSet.AfterScroll; AGridEh:= TDBGridEh(Sender); if not AGridEh.DataSource.DataSet.Active then Exit; CurbookMark:= AGridEh.DataSource.DataSet.GetBookmark; aBeforeScroll:= AGridEh.DataSource.DataSet.BeforeScroll; aAfterScroll:= AGridEh.DataSource.DataSet.AfterScroll; AGridEh.DataSource.DataSet.DisableControls; try numSum:= 0; numCount:= 0; AGridEh.DataSource.DataSet.Bookmark:= AGridEh.Selection.Rect.TopRow; if AGridEh.Selection.Rows.Count>0 then begin //行级选择 改用很费明的算法 AGridEh.Selection.Rows.DataSet.First; //AGridEh.Selection.Rows. while not AGridEh.Selection.Rows.DataSet.Eof do begin //这里会遍历全部 if AGridEh.Selection.Rows.CurrentRowSelected then begin for i:= 0 to AGridEh.VisibleColCount-1 do begin if AGridEh.Fields[i].DataType in [ftSmallint, ftInteger, ftWord, ftFloat, ftCurrency, ftBCD,ftLargeint] then begin if AGridEh.Fields[i].Value<>null then begin numSum:= numSum+ AGridEh.Fields[i].Value; Inc(numCount); end; end; end; end; AGridEh.Selection.Rows.DataSet.Next; end; end else if AGridEh.Selection.Rect.LeftCol<>-1 then begin //区域选择 while (not AGridEh.DataSource.DataSet.Eof) do begin for i:= AGridEh.Selection.Rect.LeftCol to AGridEh.Selection.Rect.RightCol do begin //这样实现的话,在调整了列位置时就出问题啦 // if AGridEh.DataSource.DataSet.Fields[i].DataType in [ftSmallint, ftInteger, ftWord, ftFloat, ftCurrency, ftBCD,ftLargeint] then begin // if AGridEh.DataSource.DataSet.Fields[i].Value<>null then begin // numSum:= numSum+ AGridEh.DataSource.DataSet.Fields[i].Value; // inc(numCount); // end; // end; if AGridEh.Fields[i].DataType in [ftSmallint, ftInteger, ftWord, ftFloat, ftCurrency, ftBCD,ftLargeint] then begin if AGridEh.Fields[i].Value<>null then begin numSum:= numSum+ AGridEh.Fields[i].Value; Inc(numCount); end; end; end; if AGridEh.DataSource.DataSet.Bookmark=AGridEh.Selection.Rect.BottomRow then Break; AGridEh.DataSource.DataSet.Next; end; end else Exit; finally //AGridEh.DataSource.DataSet.GotoBookmark(bookMark); //AGridEh.DataSource.DataSet.Bookmark:= bookMark; AGridEh.DataSource.DataSet.EnableControls; AGridEh.DataSource.DataSet.GotoBookmark(CurbookMark); AGridEh.DataSource.DataSet.AfterScroll:= aAfterScroll; AGridEh.DataSource.DataSet.BeforeScroll:= aBeforeScroll; //AGridEh.DataSource.DataSet.GotoBookmark(CurbookMark); //AGridEh.DataSource.DataSet.GotoBookmark(bookMark); //AGridEh.DataSource.DataSet.EnableControls;// AGridEh.DataSource.DataSet.BeforeScroll:= aBeforeScroll;// AGridEh.DataSource.DataSet.AfterScroll:= aAfterScroll; end; if numCount>1 then begin strMsg:= Format('求和=%f 平均数=%f 计数=%d',[numSum,numSum/numCount,numCount]); mmo1.Lines.Add(strMsg); end else begin mmo1.Lines.Add('nothing can be calceturated!'); end;end;
dbgrideh中多选时selection 这里只处理区域(有问题,已解决)
dbgrideh中多选时selection 这里只处理区域(有问题,已解决)
dbgrideh中多选时selection
解决“已完毕,但网页上有错误”的问题
电脑有问题自己解决
【滤镜教程】如何只对某一区域进行滤镜处理 - iSee分享频道
解决电脑CPU使用率过高怎么处理的问题
解决曝光问题 处理无法完全修复的照片
轻松帮你解决图片批量处理问题
事业单位分类改革只解决分钱 核心问题未定调
解决快捷方式有错误的问题
婚前必须解决的问题有哪些?
婚前必须解决的问题有哪些?
婚前必须解决的问题有哪些?
婚前必须解决的问题有哪些?
有多少“头发问题”需要“老板”解决
婚姻出现问题 该怎么办? - 已解决 - 搜搜问问
电脑问题有图帮看下怎么解决! - 已回答 - 搜搜问问
期货炒单问题 - 已解决 - 搜搜问问
解决SQL数据库日志已满的问题
有问题的自制原始凭证处理方法
处理问题最有水平的方法
关于纳税人丢失已填开发票处理问题的批复
世界上有哪些社会制度 - 已解决 - 搜搜问问