动态生成合计在最近的项目开发过程中,由于客户的需要,要对数据库中相同种类的货物进行汇总统计,经过多方面查阅,发现网上这方面的东西缺乏,于是就写了一个过程来实现这一功能。由不足之处请大家多多指正,多谢
程序中用到了第三方控件vsflexgrid,过程中变量vsgrid可以换成stringgrid但其中的部分代码要做必要的删除。
procedure heji(vsgrid:tvsflexgrid);
var
comn_num,heji,kk,ll:integer; //comn_num: vsgrid的列数 heji:保存合计值 kk:保存程序读取的行数之差
he:boolean;
begin
ceshi:=vsgrid.Rows-1;
he:=false;
try
for record_flag:=conm to ceshi do
begin
if he=true then begin //为真则合计出现过
if record_flag<conm then //跳过合计
begin
he:=false;
continue; //执行下一循环 跳过本循环
end;
end;
if (vsgrid.TextMatrix[record_flag,0]<>vsgrid.TextMatrix[record_flag+1,0]) then //判断相邻纪录是否同类型
begin //不相同则:
he:=true;
vsgrid.AddItem(vsgrid.textmatrix[record_flag,0]+'合计',record_flag+1); //在record_flag处增加合计行
for comn_num:=5 to vsgrid.Cols-1 do //循环计算要合计的字段值
begin heji:=0;
for record_flag2:=conm to record_flag do //从conm处开始计算
begin
if (trim(vsgrid.TextMatrix[0,col])='周计划') or (trim(vsgrid.TextMatrix[0,comn_num])='上周欠产') or (trim(vsgrid.TextMatrix[0,comn_num])='当日')
or (trim(vsgrid.TextMatrix[0,comn_num])='累计') or (trim(vsgrid.TextMatrix[0,comn_num])='欠产') then
begin
// if (vsgrid.TextMatrix[record_flag,6]='直供机') or (vsgrid.TextMatrix[record_flag,6]='内提机') then
heji:=strtoint(vsgrid.TextMatrix[record_flag2,comn_num])+heji; //保存合计值
vsgrid.Select(record_flag+1,comn_num); //
vsgrid.CellForeColor:= clwhite; //给合计换颜色
vsgrid.Text:=inttostr(heji); //给vsgrid的cell负值
vsgrid.Select(record_flag+1,11);
vsgrid.Text:=vsgrid.TextMatrix[record_flag,11];
vsgrid.Select(record_flag+1,12);
vsgrid.Text:=vsgrid.TextMatrix[record_flag,12];
end;
end;
vsgrid.Select(record_flag+1,col);
上一篇:打造Delphi中字符串的replace函数 下一篇:控件treeview的使用 更多相关文章
|
推荐文章
·并发
精彩文章
|