procedure TForm1.Button1Click(Sender: TObject);
var
i:string;
j:integer;
m:string;
var
year,month,day:word;
ym,yy,yb,ye:string; //yy前一年开始日期 ym前一年结束日期 yb前一年开始月日 ye前一年结束日
begin
//MessageBox(Handle,PChar(inttostr(dbgrid1.DataSource.DataSet.FieldCount)),PChar('提示'),MB_ICONEXCLAMATION);
//前一年开始日期
database1.Close;
DecodeDate(DateTimePicker1.date,Year, Month, Day);
yy:=inttostr(year-1)+'-'+inttostr(Month)+'-'+inttostr(Day);
yb:=inttostr(Month)+'月'+inttostr(Day);
//前一年结束日期
DecodeDate(DateTimePicker2.date,Year, Month, Day);
ym:=inttostr(year-1)+'-'+inttostr(Month)+'-'+inttostr(Day);
ye:='-'+inttostr(Day);
//MessageBox(Handle,PChar(yy),PChar('提示'),MB_ICONEXCLAMATION);
for j:=1 to 8 do
begin
//tqry.Active:=FALSE;
//yqry.Active:=false;
tqry.ParamByName('RQ1').AsDate:=datetimepicker1.Date;
tqry.ParamByName('RQ2').AsDate:=datetimepicker2.Date;
yqry.ParamByName('RQ3').AsDate:=strtodate(yy);
yqry.ParamByName('RQ4').AsDate:=strtodate(ym);
TQRY.Open;
Yqry.Open;
dbedit1.Text:=tqry.Fields[2].AsString;
dbedit2.Text:=yqry.Fields[2].AsString;
//if tqry.Fields[0].AsInteger=16 or tqry.Fields[0].AsInteger>17 then
//begin
//MessageBox(Handle,PChar('abcd'),PChar('提示'),MB_ICONEXCLAMATION);
//dbedit1.Text:=strtofloat(dbedit.Text)+strtofloat(tqry.Fields[2].AsString);
//i:=format('%.n%s',[(strtofloat(dbedit1.Text)-strtofloat(dbedit2.Text))*100.00/strtofloat(dbedit2.Text),'%']); //取百分比整数
//end
//else
//begin
i:=format('%.n%s',[(strtofloat(dbedit1.Text)-strtofloat(dbedit2.Text))*100.00/strtofloat(dbedit2.Text),'%']); //取百分比整数
//end;
m:=tqry.Fields[1].AsString+i;
label3.Caption:=yb+ye+'日累计同比递增率:';
label4.Caption:=label4.Caption+m;
MaskEdit1.Text:=label3.Caption+label4.Caption;
tqry.Next;
yqry.Next;
end;
//format('%.2n%s', [a*100.00/b, '%']) 小数点两位
end;
procedure TForm1.FormCreate(Sender: TObject);
var idate :TDateTime;
iYear,iMonth,iDay :Word;
i:string;
begin
idate:=now();
DecodeDate(idate,iYear,iMonth,iDay);
if iDay=1 then
begin
i:=DateTimeToStr(EncodeDate(iYear,iMonth-1,1));
end
else
begin
i:=DateTimeToStr(EncodeDate(iYear,iMonth,1));
end;
datetimepicker1.Date:=StrToDate(i);
datetimepicker2.Date:=strtodate(formatdatetime('ddddd',now-1));
end;
procedure TForm1.clibtnClick(Sender: TObject);
begin
MaskEdit1.SetFocus;
MaskEdit1.SelectAll;
MaskEdit1.CopyToClipboard;
end;