出来的表格如下,
产品型号 单相 三相 其它 合计
Z401 3 4 1
Z402 7 15 1
通过统计的代码,我想让它成为:
产品型号 单相 三相 其它 合计
Z401 3 4 1 8
Z402 7 15 1 23
合计 10 19 2 31
我的代码:
{$R *.dfm}
{调用过程}
procedure Tchanpinshulianghuizongbiaofm.addItem(xh, gg, sl: string);
var
p: integer; //P的值就是有几种型号
begin
p := idList.IndexOfName(xh); //在列表中查找是否存在这个型号
if p <> -1 then //存在 (如果有这个型号)
begin
p := strtoint(idList.Values[xh]); //把动态表里的有几种型号的值转化成字符赋给P,
if gg = '单相' then
StringGrid1.Cells[1, p] := sl //把凡是单相数量放在第二列 ,至于哪行是由P决定的,
else if gg = '三相' then
StringGrid1.Cells[2, p] := sl
else
StringGrid1.Cells[3, p] :=sl;
end
else
begin
p := StringGrid1.RowCount;
StringGrid1.RowCount := StringGrid1.RowCount + 1; //有一行表头的
StringGrid1.Cells[0, p] := xh;
if gg = '单相' then
StringGrid1.Cells[1, p] := sl
else if gg = '三相' then
StringGrid1.Cells[2, p] := sl
else
StringGrid1.Cells[3, p] := sl;
idList.Add(xh + '=' + inttostr(p)); //把这个型号加到列表中,并且把它在stringgrid中的行号给它
end;
end;procedure Tchanpinshulianghuizongbiaofm.BitBtn1Click(Sender: TObject);
var
intRow: integer; //定义变量行(row)为整型,变量名字为intRow
dxhj,sxhj,qthj,cphj:real; //分别为单相合计 、三相合计、其它合计、产品合计
begin
intRow:=0;
adodataset1.Close;
adodataset1.CommandText :=
'select cpxh_mc,cpgg_mc,sl=count(*) from s_zxx group by cpxh_mc,cpgg_mc ORDER BY count(*)'; //ORDER BY后面表示的字段是表示按这个字段排序
adodataset1.Open;
StringGrid1.RowCount:=1; while not adodataset1.Eof do
begin
addItem(adodataset1.FieldByname('cpxh_mc').AsString,//把上面的过程循环过
adodataset1.FieldByname('cpgg_mc').AsString,
adodataset1.FieldByname('sl').AsString);
adodataset1.Next;
intRow:=intRow+1;
end;
if StringGrid1.RowCount>=1 then
begin
StringGrid1.FixedRows:=1; //如果行树大于等于一行,那么让他显示表头(因为在清除的时候,定义了它只有一行,这样会没有表头掉的),
StringGrid1.RowCount:=StringGrid1.RowCount+1;
StringGrid1.Cells[0,intRow]:='合计' ; //显示合计标签
StringGrid1.Cells[4,intRow]:=FloatToStr(cphj); //显示行合计
end; idList.Clear;
end;
procedure Tchanpinshulianghuizongbiaofm.FormCreate(Sender: TObject);
begin
idList := TstringList.Create;
end;procedure Tchanpinshulianghuizongbiaofm.FormShow(Sender: TObject);
begin
DateTimePicker2.Date:=StrToDate(DateToStr(Now));
StringGrid1.ColCount:=5;
StringGrid1.Cells[0,0]:='产品型号';
StringGrid1.Cells[1,0]:='单相数量';
StringGrid1.Cells[2,0]:='三相数量';
StringGrid1.Cells[3,0]:='其它规格';
StringGrid1.Cells[4,0]:='合计数量';
end;end.
我现在的问题是三个变量(dxhj,sxhj,qthj,cphj:real; //分别为单相合计 、三相合计、其它合计、产品合计)不字段放在那里循环相加,总是搞不定
产品型号 单相 三相 其它 合计
Z401 3 4 1
Z402 7 15 1
通过统计的代码,我想让它成为:
产品型号 单相 三相 其它 合计
Z401 3 4 1 8
Z402 7 15 1 23
合计 10 19 2 31
我的代码:
{$R *.dfm}
{调用过程}
procedure Tchanpinshulianghuizongbiaofm.addItem(xh, gg, sl: string);
var
p: integer; //P的值就是有几种型号
begin
p := idList.IndexOfName(xh); //在列表中查找是否存在这个型号
if p <> -1 then //存在 (如果有这个型号)
begin
p := strtoint(idList.Values[xh]); //把动态表里的有几种型号的值转化成字符赋给P,
if gg = '单相' then
StringGrid1.Cells[1, p] := sl //把凡是单相数量放在第二列 ,至于哪行是由P决定的,
else if gg = '三相' then
StringGrid1.Cells[2, p] := sl
else
StringGrid1.Cells[3, p] :=sl;
end
else
begin
p := StringGrid1.RowCount;
StringGrid1.RowCount := StringGrid1.RowCount + 1; //有一行表头的
StringGrid1.Cells[0, p] := xh;
if gg = '单相' then
StringGrid1.Cells[1, p] := sl
else if gg = '三相' then
StringGrid1.Cells[2, p] := sl
else
StringGrid1.Cells[3, p] := sl;
idList.Add(xh + '=' + inttostr(p)); //把这个型号加到列表中,并且把它在stringgrid中的行号给它
end;
end;procedure Tchanpinshulianghuizongbiaofm.BitBtn1Click(Sender: TObject);
var
intRow: integer; //定义变量行(row)为整型,变量名字为intRow
dxhj,sxhj,qthj,cphj:real; //分别为单相合计 、三相合计、其它合计、产品合计
begin
intRow:=0;
adodataset1.Close;
adodataset1.CommandText :=
'select cpxh_mc,cpgg_mc,sl=count(*) from s_zxx group by cpxh_mc,cpgg_mc ORDER BY count(*)'; //ORDER BY后面表示的字段是表示按这个字段排序
adodataset1.Open;
StringGrid1.RowCount:=1; while not adodataset1.Eof do
begin
addItem(adodataset1.FieldByname('cpxh_mc').AsString,//把上面的过程循环过
adodataset1.FieldByname('cpgg_mc').AsString,
adodataset1.FieldByname('sl').AsString);
adodataset1.Next;
intRow:=intRow+1;
end;
if StringGrid1.RowCount>=1 then
begin
StringGrid1.FixedRows:=1; //如果行树大于等于一行,那么让他显示表头(因为在清除的时候,定义了它只有一行,这样会没有表头掉的),
StringGrid1.RowCount:=StringGrid1.RowCount+1;
StringGrid1.Cells[0,intRow]:='合计' ; //显示合计标签
StringGrid1.Cells[4,intRow]:=FloatToStr(cphj); //显示行合计
end; idList.Clear;
end;
procedure Tchanpinshulianghuizongbiaofm.FormCreate(Sender: TObject);
begin
idList := TstringList.Create;
end;procedure Tchanpinshulianghuizongbiaofm.FormShow(Sender: TObject);
begin
DateTimePicker2.Date:=StrToDate(DateToStr(Now));
StringGrid1.ColCount:=5;
StringGrid1.Cells[0,0]:='产品型号';
StringGrid1.Cells[1,0]:='单相数量';
StringGrid1.Cells[2,0]:='三相数量';
StringGrid1.Cells[3,0]:='其它规格';
StringGrid1.Cells[4,0]:='合计数量';
end;end.
我现在的问题是三个变量(dxhj,sxhj,qthj,cphj:real; //分别为单相合计 、三相合计、其它合计、产品合计)不字段放在那里循环相加,总是搞不定
解决方案 »
- WEBCONNECTION在IE7下传输超时的问题,急
- delphi6开发人员指南里面我不懂的问题!!!!
- 已连续五个通宵,我要再连续六个!请给予鼓励!另求delphi应聘试题
- 内存操作
- 请问如何将outlook的.wab的通讯录导入自己的数据库?
- 怎么结束Delphi的调试状态?
- 局域网中DELPHI通过myoledb如何联接其他机器中的mysql?在线等待!!
- DELPHI6自带控件的一个资源管理器样式的控件无法得到选中项
- 不难的问题:如何获取串口是否处于打开或关闭状态!!!
- 评价该网页?
- Delphi8.0 .net新鲜出炉,要的快下载!!!(没分给的,哈哈)
- 在北京能正常开发的delphi程序员能挣多少钱?
就着张不知道问题出在哪里
怎么弄也搞不出来