G
goltiger
Unregistered / Unconfirmed
GUEST, unregistred user!
下面是我写的一段程序,
从query1中计算表的一些平均值,
调试通过,但我觉得是否可以精减一下,
能否提高点效率,
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
i,j:integer;
str1,str2,str3,str4,str5,str6,str7,strclass:string;
begin
//平均出钢温度
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt) as ff from conv where date between :date1 and :date2');
dm.Query1.ParamByName('date1').Value:=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
try
dm.Query1.Open;
str2:='出钢温度(平均:'+inttostr(round(strtofloat(dm.Query1.FieldValues['ff'])))+')';
groupbox1.Caption:=str2;
except
showmessage('*********');
end;
//计算3个炉子的平均出钢温度
for i:=4 to 6 do
begin
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt) as ff from conv where date between :date1 and :date2 and conv=:conv1');
dm.Query1.ParamByName('date1').Value :=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
dm.Query1.ParamByName('conv1').Value:=i;
try
dm.Query1.Open;
str1:=inttostr(round(strtofloat(dm.Query1.FieldValues['ff'])));
if i=4 then
label5.Caption:=str1;
if i=5 then
label6.Caption:=str1;
if i=6 then
label7.Caption:=str1;
except
showmessage('记录超出范围,请确定日期!');
end;
end;
//计算4个班组的平均出钢温度
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt) as f1 from conv where date between :date1 and :date2 and class=:classno');
dm.Query1.ParamByName('date1').Value :=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
dm.Query1.ParamByName('classno').Value:='甲';
try
dm.Query1.Open;
str3:=inttostr(round(strtofloat(dm.Query1.FieldValues['f1'])));
label12.Caption:=str3;
except
showmessage('出错,可能是你的日期输入错误!');
end;
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt) as f1 from conv where date between :date1 and :date2 and class=:classno');
dm.Query1.ParamByName('date1').Value :=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
dm.Query1.ParamByName('classno').Value:='乙';
try
dm.Query1.Open;
str3:=inttostr(round(strtofloat(dm.Query1.FieldValues['f1'])));
label13.Caption:=str3;
except
showmessage('一个非正常错误!请重新输入日期再试!');
end;
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt) as f1 from conv where date between :date1 and :date2 and class=:classno');
dm.Query1.ParamByName('date1').Value :=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
dm.Query1.ParamByName('classno').Value:='丙';
try
dm.Query1.Open;
str3:=inttostr(round(strtofloat(dm.Query1.FieldValues['f1'])));
label14.Caption:=str3;
except
showmessage('天哪,重来吧!');
end;
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt) as f1 from conv where date between :date1 and :date2 and class=:classno');
dm.Query1.ParamByName('date1').Value :=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
dm.Query1.ParamByName('classno').Value:='丁';
try
dm.Query1.Open;
str3:=inttostr(round(strtofloat(dm.Query1.FieldValues['f1'])));
label15.Caption:=str3;
except
showmessage('唉,是我太不小心了。你的电脑可能得了非典了! ');
end;
//计算总平均出钢温降、吹氩温降
begin
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt-befort) as ff,avg(befort-aftert) as ee');
dm.Query1.SQL.Add(' from conv where date between :date1 and :date2');
dm.Query1.ParamByName('date1').Value :=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
try
dm.Query1.Open;
str6:=inttostr(round(strtofloat(dm.Query1.FieldValues['ff'])));
str7:=inttostr(round(strtofloat(dm.Query1.FieldValues['ee'])));
groupbox2.Caption:='温降(出钢:'+str6+',吹氩:'+str7+')';
except
showmessage('记录超出范围,请确定日期!');
end;
end;
//计算出钢温降、吹氩温降
for j:=4 to 6 do
begin
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt-befort) as ff,avg(befort-aftert) as ee');
dm.Query1.SQL.Add(' from conv where date between :date1 and :date2 and conv=:conv1');
dm.Query1.ParamByName('date1').Value :=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
dm.Query1.ParamByName('conv1').Value:=j;
try
dm.Query1.Open;
str5:=inttostr(round(strtofloat(dm.Query1.FieldValues['ff'])));
str4:=inttostr(round(strtofloat(dm.Query1.FieldValues['ee'])));
if j=4 then
stringgrid1.Cells[1,1]:=str5;
stringgrid1.Cells[2,1]:=str4;
if j=5 then
stringgrid1.Cells[1,2]:=str5;
stringgrid1.Cells[2,2]:=str4;
if j=6 then
stringgrid1.Cells[1,3]:=str5;
stringgrid1.Cells[2,3]:=str4;
except
showmessage('记录超出范围,请确定日期!');
end;
end;
从query1中计算表的一些平均值,
调试通过,但我觉得是否可以精减一下,
能否提高点效率,
procedure TForm1.SpeedButton1Click(Sender: TObject);
var
i,j:integer;
str1,str2,str3,str4,str5,str6,str7,strclass:string;
begin
//平均出钢温度
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt) as ff from conv where date between :date1 and :date2');
dm.Query1.ParamByName('date1').Value:=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
try
dm.Query1.Open;
str2:='出钢温度(平均:'+inttostr(round(strtofloat(dm.Query1.FieldValues['ff'])))+')';
groupbox1.Caption:=str2;
except
showmessage('*********');
end;
//计算3个炉子的平均出钢温度
for i:=4 to 6 do
begin
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt) as ff from conv where date between :date1 and :date2 and conv=:conv1');
dm.Query1.ParamByName('date1').Value :=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
dm.Query1.ParamByName('conv1').Value:=i;
try
dm.Query1.Open;
str1:=inttostr(round(strtofloat(dm.Query1.FieldValues['ff'])));
if i=4 then
label5.Caption:=str1;
if i=5 then
label6.Caption:=str1;
if i=6 then
label7.Caption:=str1;
except
showmessage('记录超出范围,请确定日期!');
end;
end;
//计算4个班组的平均出钢温度
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt) as f1 from conv where date between :date1 and :date2 and class=:classno');
dm.Query1.ParamByName('date1').Value :=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
dm.Query1.ParamByName('classno').Value:='甲';
try
dm.Query1.Open;
str3:=inttostr(round(strtofloat(dm.Query1.FieldValues['f1'])));
label12.Caption:=str3;
except
showmessage('出错,可能是你的日期输入错误!');
end;
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt) as f1 from conv where date between :date1 and :date2 and class=:classno');
dm.Query1.ParamByName('date1').Value :=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
dm.Query1.ParamByName('classno').Value:='乙';
try
dm.Query1.Open;
str3:=inttostr(round(strtofloat(dm.Query1.FieldValues['f1'])));
label13.Caption:=str3;
except
showmessage('一个非正常错误!请重新输入日期再试!');
end;
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt) as f1 from conv where date between :date1 and :date2 and class=:classno');
dm.Query1.ParamByName('date1').Value :=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
dm.Query1.ParamByName('classno').Value:='丙';
try
dm.Query1.Open;
str3:=inttostr(round(strtofloat(dm.Query1.FieldValues['f1'])));
label14.Caption:=str3;
except
showmessage('天哪,重来吧!');
end;
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt) as f1 from conv where date between :date1 and :date2 and class=:classno');
dm.Query1.ParamByName('date1').Value :=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
dm.Query1.ParamByName('classno').Value:='丁';
try
dm.Query1.Open;
str3:=inttostr(round(strtofloat(dm.Query1.FieldValues['f1'])));
label15.Caption:=str3;
except
showmessage('唉,是我太不小心了。你的电脑可能得了非典了! ');
end;
//计算总平均出钢温降、吹氩温降
begin
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt-befort) as ff,avg(befort-aftert) as ee');
dm.Query1.SQL.Add(' from conv where date between :date1 and :date2');
dm.Query1.ParamByName('date1').Value :=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
try
dm.Query1.Open;
str6:=inttostr(round(strtofloat(dm.Query1.FieldValues['ff'])));
str7:=inttostr(round(strtofloat(dm.Query1.FieldValues['ee'])));
groupbox2.Caption:='温降(出钢:'+str6+',吹氩:'+str7+')';
except
showmessage('记录超出范围,请确定日期!');
end;
end;
//计算出钢温降、吹氩温降
for j:=4 to 6 do
begin
dm.Query1.Close;
dm.Query1.SQL.Clear;
dm.Query1.SQL.Add('select avg(spitt-befort) as ff,avg(befort-aftert) as ee');
dm.Query1.SQL.Add(' from conv where date between :date1 and :date2 and conv=:conv1');
dm.Query1.ParamByName('date1').Value :=strtodate('2003-11-'+combobox2.text);
dm.Query1.ParamByName('date2').Value:=strtodate('2003-11-'+combobox3.text);
dm.Query1.ParamByName('conv1').Value:=j;
try
dm.Query1.Open;
str5:=inttostr(round(strtofloat(dm.Query1.FieldValues['ff'])));
str4:=inttostr(round(strtofloat(dm.Query1.FieldValues['ee'])));
if j=4 then
stringgrid1.Cells[1,1]:=str5;
stringgrid1.Cells[2,1]:=str4;
if j=5 then
stringgrid1.Cells[1,2]:=str5;
stringgrid1.Cells[2,2]:=str4;
if j=6 then
stringgrid1.Cells[1,3]:=str5;
stringgrid1.Cells[2,3]:=str4;
except
showmessage('记录超出范围,请确定日期!');
end;
end;