在再给您一点
--------------如果不行,权当灌水------------------
procedure Ttdeform.DoYss;
var debhtemp,gcmc:ansistring;
desl:real;//定额数量
gcbh:integer;//工程编号
i,j:integer;
xj:real;//小结合计
hj:real;//合计
rghj,//人工合计
clhj,//材料合计
jxhj:real;//机械合计
rowcnt:integer;//计数器
GcNum:integer;//工程计数器
begin
with projectdatamodule.yssquery do //打开预算表
begin
Close;
SQl.Clear;
sql.Add('Select * from t_yss');
prepared;
open;
first;
end;
with projectdatamodule.yssquery2 do//打开……
begin
Close;
SQl.Clear;
sql.Add('Select * from yss');
prepared;
open;
if recordcount<>0 then //清除……
begin
for i:=1 to recordcount do delete;
UpdateBatch;
end;
end;
//复制数据从……
with projectdatamodule do
begin
for j:=1 to yssquery.recordcount do
begin
yssquery2.Append;
yssquery2.FieldByName('debh').AsString:=yssquery.FieldByName('debh').AsString;
yssquery2.FieldByName('demc').AsString:=yssquery.FieldByName('demc').AsString;
yssquery2.FieldByName('dw').AsString:=yssquery.FieldByName('dw').AsString;
yssquery2.FieldByName('sl').Asfloat:=yssquery.FieldByName('sl').Asfloat;
yssquery2.FieldByName('jj').Asfloat:=yssquery.FieldByName('jj').Asfloat;
yssquery2.FieldByName('jjhj').Asfloat:=yssquery.FieldByName('jjhj').Asfloat;
yssquery2.FieldByName('gcm').AsString:=yssquery.FieldByName('gcm').Asstring;
yssquery2.Updatebatch;
yssquery.Next;
end;
yssquery.first;
yssquery2.first;
end;
//清除stringgrid数据
for i:=0 to stringgrid1.RowCount do
for j:=0 to stringgrid1.ColCount do stringgrid1.Cells[j,i]:='';//第二步、分小结……
with rationdatamodule.gcquery do
begin
close;
sql.Clear;
sql.Add('Select * from t_gcsm');
prepared;
open;
first;
rowcnt:=0;
rghj:=0;
clhj:=0;
jxhj:=0;
hj:=0;
GcNum:=0;
for i:=1 to recordcount do
begin
gcmc:=trim(fieldbyname('gcm').AsString);
projectdatamodule.yssquery2.Close;
projectdatamodule.yssquery2.SQl.Clear;
projectdatamodule.yssquery2.sql.Add('Select * from yss');
projectdatamodule.yssquery2.sql.Add('where gcm =:gcm');
projectdatamodule.yssquery2.Parameters.ParamByName('gcm').value:=gcmc;
projectdatamodule.yssquery2.prepared;
projectdatamodule.yssquery2.open;
projectdatamodule.yssquery2.first;
if projectdatamodule.yssquery2.recordcount<>0 then//写数据到StringGrid
begin
GcNum:=GcNum+1;
StringGrid1.Cells[0,rowcnt]:=NumExchange(GcNum);
StringGrid1.Cells[1,rowcnt]:=gcmc;
stringgrid1.RowCount:=stringgrid1.RowCount+1;
rowcnt:=rowcnt+1;
xj:=0;
for j:=1 to projectdatamodule.yssquery2.recordcount do
begin
stringgrid1.Cells[0,rowcnt]:=inttostr(j);
stringgrid1.Cells[1,rowcnt]:=projectdatamodule.yssquery2.fieldbyname('demc').AsString;
stringgrid1.Cells[2,rowcnt]:=currtostr(projectdatamodule.yssquery2.fieldbyname('sl').Asfloat);
stringgrid1.Cells[3,rowcnt]:=projectdatamodule.yssquery2.fieldbyname('dw').AsString;
stringgrid1.Cells[4,rowcnt]:=format('%8.2f',[projectdatamodule.yssquery2.fieldbyname('jj').Asfloat]);
stringgrid1.Cells[5,rowcnt]:=format('%8.2f',[projectdatamodule.yssquery2.fieldbyname('jjhj').Asfloat]);
rghj:=rghj+projectdatamodule.yssquery2.fieldbyname('rghj').Asfloat;
clhj:=clhj+projectdatamodule.yssquery2.fieldbyname('clhj').Asfloat;
jxhj:=jxhj+projectdatamodule.yssquery2.fieldbyname('jxhj').Asfloat;
xj:=xj+projectdatamodule.yssquery2.fieldbyname('jjhj').Asfloat;
stringgrid1.RowCount:=stringgrid1.RowCount+1;
rowcnt:=rowcnt+1;
projectdatamodule.yssquery2.next;
end;
//小计
stringgrid1.cells[1,rowcnt]:='小计';
stringgrid1.cells[5,rowcnt]:=format('%8.2f',[xj]);
hj:=hj+xj;
stringgrid1.RowCount:=stringgrid1.RowCount+1;
rowcnt:=rowcnt+1;
end;
next;
end;
stringgrid1.RowCount:=stringgrid1.RowCount+1;
stringgrid1.cells[1,rowcnt]:='合计';
stringgrid1.cells[5,rowcnt]:=format('%8.2f',[hj]);
end;
--------------如果不行,权当灌水------------------
procedure Ttdeform.DoYss;
var debhtemp,gcmc:ansistring;
desl:real;//定额数量
gcbh:integer;//工程编号
i,j:integer;
xj:real;//小结合计
hj:real;//合计
rghj,//人工合计
clhj,//材料合计
jxhj:real;//机械合计
rowcnt:integer;//计数器
GcNum:integer;//工程计数器
begin
with projectdatamodule.yssquery do //打开预算表
begin
Close;
SQl.Clear;
sql.Add('Select * from t_yss');
prepared;
open;
first;
end;
with projectdatamodule.yssquery2 do//打开……
begin
Close;
SQl.Clear;
sql.Add('Select * from yss');
prepared;
open;
if recordcount<>0 then //清除……
begin
for i:=1 to recordcount do delete;
UpdateBatch;
end;
end;
//复制数据从……
with projectdatamodule do
begin
for j:=1 to yssquery.recordcount do
begin
yssquery2.Append;
yssquery2.FieldByName('debh').AsString:=yssquery.FieldByName('debh').AsString;
yssquery2.FieldByName('demc').AsString:=yssquery.FieldByName('demc').AsString;
yssquery2.FieldByName('dw').AsString:=yssquery.FieldByName('dw').AsString;
yssquery2.FieldByName('sl').Asfloat:=yssquery.FieldByName('sl').Asfloat;
yssquery2.FieldByName('jj').Asfloat:=yssquery.FieldByName('jj').Asfloat;
yssquery2.FieldByName('jjhj').Asfloat:=yssquery.FieldByName('jjhj').Asfloat;
yssquery2.FieldByName('gcm').AsString:=yssquery.FieldByName('gcm').Asstring;
yssquery2.Updatebatch;
yssquery.Next;
end;
yssquery.first;
yssquery2.first;
end;
//清除stringgrid数据
for i:=0 to stringgrid1.RowCount do
for j:=0 to stringgrid1.ColCount do stringgrid1.Cells[j,i]:='';//第二步、分小结……
with rationdatamodule.gcquery do
begin
close;
sql.Clear;
sql.Add('Select * from t_gcsm');
prepared;
open;
first;
rowcnt:=0;
rghj:=0;
clhj:=0;
jxhj:=0;
hj:=0;
GcNum:=0;
for i:=1 to recordcount do
begin
gcmc:=trim(fieldbyname('gcm').AsString);
projectdatamodule.yssquery2.Close;
projectdatamodule.yssquery2.SQl.Clear;
projectdatamodule.yssquery2.sql.Add('Select * from yss');
projectdatamodule.yssquery2.sql.Add('where gcm =:gcm');
projectdatamodule.yssquery2.Parameters.ParamByName('gcm').value:=gcmc;
projectdatamodule.yssquery2.prepared;
projectdatamodule.yssquery2.open;
projectdatamodule.yssquery2.first;
if projectdatamodule.yssquery2.recordcount<>0 then//写数据到StringGrid
begin
GcNum:=GcNum+1;
StringGrid1.Cells[0,rowcnt]:=NumExchange(GcNum);
StringGrid1.Cells[1,rowcnt]:=gcmc;
stringgrid1.RowCount:=stringgrid1.RowCount+1;
rowcnt:=rowcnt+1;
xj:=0;
for j:=1 to projectdatamodule.yssquery2.recordcount do
begin
stringgrid1.Cells[0,rowcnt]:=inttostr(j);
stringgrid1.Cells[1,rowcnt]:=projectdatamodule.yssquery2.fieldbyname('demc').AsString;
stringgrid1.Cells[2,rowcnt]:=currtostr(projectdatamodule.yssquery2.fieldbyname('sl').Asfloat);
stringgrid1.Cells[3,rowcnt]:=projectdatamodule.yssquery2.fieldbyname('dw').AsString;
stringgrid1.Cells[4,rowcnt]:=format('%8.2f',[projectdatamodule.yssquery2.fieldbyname('jj').Asfloat]);
stringgrid1.Cells[5,rowcnt]:=format('%8.2f',[projectdatamodule.yssquery2.fieldbyname('jjhj').Asfloat]);
rghj:=rghj+projectdatamodule.yssquery2.fieldbyname('rghj').Asfloat;
clhj:=clhj+projectdatamodule.yssquery2.fieldbyname('clhj').Asfloat;
jxhj:=jxhj+projectdatamodule.yssquery2.fieldbyname('jxhj').Asfloat;
xj:=xj+projectdatamodule.yssquery2.fieldbyname('jjhj').Asfloat;
stringgrid1.RowCount:=stringgrid1.RowCount+1;
rowcnt:=rowcnt+1;
projectdatamodule.yssquery2.next;
end;
//小计
stringgrid1.cells[1,rowcnt]:='小计';
stringgrid1.cells[5,rowcnt]:=format('%8.2f',[xj]);
hj:=hj+xj;
stringgrid1.RowCount:=stringgrid1.RowCount+1;
rowcnt:=rowcnt+1;
end;
next;
end;
stringgrid1.RowCount:=stringgrid1.RowCount+1;
stringgrid1.cells[1,rowcnt]:='合计';
stringgrid1.cells[5,rowcnt]:=format('%8.2f',[hj]);
end;
解决方案 »
- devexpressvcl 安装,一闪就过,安装界面都看不到
- RichEdit 分页生成图片 求高手指点!
- DbGrid如何实现翻页?
- 我要判断2个条件中有中是否有成立的,怎么写这个判断啊?????
- 用delphi写过插件的同志们看过来.100分.
- 要设计一个程序,要求当在一个窗体上输入以分号分割的一串数字时在其他的窗体上会立即将这串数字以坐标轴上的离散点、柱状图、饼图三种形
- 一个很奇怪的问题!
- 为什么在Delphi6.0中一些字符函数用不成?
- 我问一个Form的问题
- Quickreport的打印预览问题
- 五星级问题!100分!做一个文档管理器,如何在数据库中存取带图片的word文档
- ERP高手请指点一下,业务分析问题
生成query,将数据读入动态数组或tring;procedure Ttest.getinfo(astringgrid:Tstringgrid);
var i:integer;
begin
cleargrid(astringgrid); //清空stringgrid;不可少
with Tquery.create(nil) do
try
databasename:='';
close;
sql.add('');
prepare;
open;last;first; //
if recordcount>0 then
astringgrid.rowcount:=recordcount+1;//多个标题栏
for i:=1 to recordcount do
begin
astringgrid.cells[0,i]:=fieldbyname('').asstring;
。
next;
end;
end;
end;
如果你用stringgrid,也可以用动态数组将query中的数据读入,进行操作,最后结果再写入stringgrid中,不过注意别越界噢 :)