📄 bushymonthrepunit.~pas
字号:
end;
//BitBtn3Click(Sender);
exit;
end;
ADOQuery1.Next;
end;
}
{
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
sqlString:='select distinct 统计月份 from 公交行业统计月报_z'
+' where 统计年份='+LastYear+' and 统计月份>=1 and 统计月份<='+StartMon;
ADOQuery1.SQL.Add(sqlString);
ADOQuery1.Open;
MonTime:=IntToStr(ADOQuery1.RecordCount);
}
//------处理本年本月-------
iCityCode:='''' + '022'+'''';
sqlString:='select a.指标代码, max(a.' + sDataType + ') AS 本年本月实际,'
+' sum(b.' + sDataType + ') AS 本年累计'
+' from 公交行业统计月报_z AS a, 公交行业统计月报_z AS b'
+' where a.城市代码=' + iCityCode + ' and b.城市代码=a.城市代码'
+' and a.统计年份='+ThisYear+' and a.统计月份='+StartMon
+' and b.统计年份=a.统计年份 and b.统计月份>=1 and b.统计月份<='+StartMon
+' and a.指标代码=b.指标代码'
+' GROUP BY a.指标代码'
+' ORDER BY a.指标代码';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
{sqlString:='select a.指标代码, max(a.' + sDataType + ') AS 本年本月实际,'
+' sum(b.' + sDataType + ')/'+MonTime+' AS 本年累计, max(c.' + sDataType + ') AS 去年本月实际,'
+' sum(d.' + sDataType + ')/'+MonTime+' AS 去年累计,'
+' (本年本月实际-去年本月实际)/去年本月实际*100 AS 本月比较百分比,'
+' (本年累计-去年累计)/去年累计*100 AS 累计比较百分比'
+' from 公交行业统计月报_z AS a, 公交行业统计月报_z AS b, 公交行业统计月报_z AS c, 公交行业统计月报_z AS d'
+' where a.城市代码=' + iCityCode + ' and b.城市代码=a.城市代码 and c.城市代码=a.城市代码 and d.城市代码=a.城市代码'
+' and a.统计年份='+ThisYear+' and a.统计月份='+StartMon
+' and b.统计年份=a.统计年份 and b.统计月份>=1 and b.统计月份<='+StartMon
+' and c.统计年份='+LastYear+' and c.统计月份='+StartMon
+' and d.统计年份=c.统计年份 and d.统计月份>=1 and d.统计月份<='+StartMon
+' and a.指标代码=b.指标代码 and b.指标代码=c.指标代码 and c.指标代码=d.指标代码'
+' GROUP BY a.指标代码'
+' ORDER BY a.指标代码';
}
ADOQuery1.SQL.Add(sqlString);
ADOQuery1.Open;
ADOQuery1.First;
WriteListView(ListView1,20,2,ADOQuery1);
WriteListView(ListView2,20,2,ADOQuery1);
WriteListView(ListView3,21,2,ADOQuery1);
WriteListView(ListView4,20,2,ADOQuery1);
//------处理去年本月-------
sqlString:='select a.指标代码, max(a.' + sDataType + ') AS 本年本月实际,'
+' sum(b.' + sDataType + ') AS 本年累计'
+' from 公交行业统计月报_z AS a, 公交行业统计月报_z AS b'
+' where a.城市代码=' + iCityCode + ' and b.城市代码=a.城市代码'
+' and a.统计年份='+LastYear+' and a.统计月份='+StartMon
+' and b.统计年份=a.统计年份 and b.统计月份>=1 and b.统计月份<='+StartMon
+' and a.指标代码=b.指标代码'
+' GROUP BY a.指标代码'
+' ORDER BY a.指标代码';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add(sqlString);
ADOQuery1.Open;
ADOQuery1.First;
WriteListView(ListView1,20,4,ADOQuery1);
WriteListView(ListView2,20,4,ADOQuery1);
WriteListView(ListView3,21,4,ADOQuery1);
WriteListView(ListView4,20,4,ADOQuery1);
//------添加百分比-------
iListView:=ListView1;
for iRow := 0 to 19 do
begin
iListView.Items[iRow].SubItems[3]:=iListView.Items[iROw].SubItems[2];
iListView.Items[iRow].SubItems[5]:=iListView.Items[iROw].SubItems[4];
iListView.Items[iRow].SubItems[6]:=CalculatePercent(iListView.Items[iRow].SubItems[2],iListView.Items[iRow].SubItems[4],100);
iListView.Items[iRow].SubItems[7]:=CalculatePercent(iListView.Items[iRow].SubItems[3],iListView.Items[iRow].SubItems[5],100);
end;
iListView:=ListView2;
for iRow := 0 to 4 do
begin
iListView.Items[iRow].SubItems[3]:=iListView.Items[iROw].SubItems[2];
iListView.Items[iRow].SubItems[5]:=iListView.Items[iROw].SubItems[4];
iListView.Items[iRow].SubItems[6]:=CalculatePercent(iListView.Items[iRow].SubItems[2],iListView.Items[iRow].SubItems[4],100);
iListView.Items[iRow].SubItems[7]:=CalculatePercent(iListView.Items[iRow].SubItems[3],iListView.Items[iRow].SubItems[5],100);
end;
for iRow := 5 to 19 do
begin
iListView.Items[iRow].SubItems[6]:=CalculatePercent(iListView.Items[iRow].SubItems[2],iListView.Items[iRow].SubItems[4],100);
iListView.Items[iRow].SubItems[7]:=CalculatePercent(iListView.Items[iRow].SubItems[3],iListView.Items[iRow].SubItems[5],100);
end;
iListView:=ListView3;
for iRow := 0 to 20 do
begin
iListView.Items[iRow].SubItems[6]:=CalculatePercent(iListView.Items[iRow].SubItems[2],iListView.Items[iRow].SubItems[4],100);
iListView.Items[iRow].SubItems[7]:=CalculatePercent(iListView.Items[iRow].SubItems[3],iListView.Items[iRow].SubItems[5],100);
end;
//----第四页特殊处理------
iListView:=ListView4;
iListView.Items[1].SubItems[3]:=SpecDataDiv(iListView.Items[2].SubItems[3],iListView.Items[3].SubItems[3],10000);
iListView.Items[1].SubItems[5]:=SpecDataDiv(iListView.Items[2].SubItems[5],iListView.Items[3].SubItems[5],10000);
iListView.Items[4].SubItems[3]:=SpecDataDiv(iListView.Items[5].SubItems[3],iListView.Items[6].SubItems[3],100);
iListView.Items[4].SubItems[5]:=SpecDataDiv(iListView.Items[5].SubItems[5],iListView.Items[6].SubItems[5],100);
iListView.Items[7].SubItems[3]:=SpecDataDiv(iListView.Items[8].SubItems[3],iListView.Items[9].SubItems[3],100);
iListView.Items[7].SubItems[5]:=SpecDataDiv(iListView.Items[8].SubItems[5],iListView.Items[9].SubItems[5],100);
iListView.Items[10].SubItems[3]:=SpecDataDiv(iListView.Items[11].SubItems[3],iListView.Items[12].SubItems[3],100);
iListView.Items[10].SubItems[5]:=SpecDataDiv(iListView.Items[11].SubItems[5],iListView.Items[12].SubItems[5],100);
iListView.Items[13].SubItems[3]:=SpecDataDiv(ListView3.Items[13].SubItems[3],iListView.Items[13].SubItems[3],1);
iListView.Items[13].SubItems[5]:=SpecDataDiv(ListView3.Items[13].SubItems[5],iListView.Items[13].SubItems[5],1);
for iRow := 0 to 19 do
begin
iListView.Items[iRow].SubItems[6]:=CalculatePercent(iListView.Items[iRow].SubItems[2],iListView.Items[iRow].SubItems[4],100);
iListView.Items[iRow].SubItems[7]:=CalculatePercent(iListView.Items[iRow].SubItems[3],iListView.Items[iRow].SubItems[5],100);
end;
{if ADOQuery1.RecordCount<>0 then
begin
WriteListView(ListView1,20,2,ADOQuery1);
WriteListView(ListView2,20,2,ADOQuery1);
WriteListView(ListView3,21,2,ADOQuery1);
WriteListView(ListView4,20,2,ADOQuery1);
ADOQuery1.First;
for j:=0 to 19 do
begin
ListView1.Items[j].SubItems[2]:=TwoDisim(ADOQuery1.fieldbyname('本年本月实际').AsString);
ListView1.Items[j].SubItems[3]:=TwoDisim(ADOQuery1.fieldbyname('本年本月实际').AsString);
ListView1.Items[j].SubItems[4]:=TwoDisim(ADOQuery1.fieldbyname('去年本月实际').AsString);
ListView1.Items[j].SubItems[5]:=TwoDisim(ADOQuery1.fieldbyname('去年本月实际').AsString);
ListView1.Items[j].SubItems[6]:=TwoDisim(ADOQuery1.fieldbyname('本月比较百分比').AsString);
ListView1.Items[j].SubItems[7]:=TwoDisim(ADOQuery1.fieldbyname('本月比较百分比').AsString);
ADOQuery1.Next;
end;
for j:=0 to 4 do
begin
ListView2.Items[j].SubItems[2]:=TwoDisim(ADOQuery1.fieldbyname('本年本月实际').AsString);
ListView2.Items[j].SubItems[3]:=TwoDisim(ADOQuery1.fieldbyname('本年本月实际').AsString);
ListView2.Items[j].SubItems[4]:=TwoDisim(ADOQuery1.fieldbyname('去年本月实际').AsString);
ListView2.Items[j].SubItems[5]:=TwoDisim(ADOQuery1.fieldbyname('去年本月实际').AsString);
ListView2.Items[j].SubItems[6]:=TwoDisim(ADOQuery1.fieldbyname('本月比较百分比').AsString);
ListView2.Items[j].SubItems[7]:=TwoDisim(ADOQuery1.fieldbyname('本月比较百分比').AsString);
ADOQuery1.Next;
end;
iAddFlag:=1;
end;}
BitBtn2.Enabled:=true;
end;
procedure TBusHYMonthRep.BitBtn3Click(Sender: TObject);
var
iRow,iCol:integer;
begin
//Edit4.Text:='';
Edit1.Text:='';
ComboBox1.Text:='';
ComboBox2.Text:='';
if ListView1.Items[0].SubItems.Count>2 then
begin
for iRow:=0 to 19 do
for iCol:=2 to 7 do
ListView1.Items[iRow].SubItems[iCol]:='';
end;
if ListView2.Items[0].SubItems.Count>2 then
begin
for iRow:=0 to 19 do
for iCol:=2 to 7 do
ListView2.Items[iRow].SubItems[iCol]:='';
end;
if ListView3.Items[0].SubItems.Count>2 then
begin
for iRow:=0 to 20 do
for iCol:=2 to 7 do
ListView3.Items[iRow].SubItems[iCol]:='';
end;
if ListView4.Items[0].SubItems.Count>2 then
begin
for iRow:=0 to 19 do
for iCol:=2 to 7 do
ListView4.Items[iRow].SubItems[iCol]:='';
end;
BitBtn2.Enabled:=false;
BusHYMonthRep.Close;
end;
procedure TBusHYMonthRep.BitBtn2Click(Sender: TObject);
var
iRow:Integer;
iCol:Integer;
begin
if (DeviceDetect=0) then
begin
exit;
end;
if(PrnInfoFrm.ShowModal<>mrOK)then
begin
exit;
end;
PrintInit(ExtractFilePath(application.exeName),'BusTradeCountMonTab');
for iRow:=0 to 19 do
begin
for iCol:=2 to 7 do
WriteCell(iRow+8,iCol+2,ListView1.Items[iRow].SubItems[iCol]);
WriteCell(4,1,'汇总单位:'+Edit1.Text);
WriteCell(28,1,'统计负责人:'+PrnInfoFrm.StatMainPerson);
WriteCell(28,6,PrnInfoFrm.StatPerson);
WriteCell(28,10,DateToStr(PrnInfoFrm.StatDate));
WriteCell(3,5,ComboBox1.Text+'年 '+ComboBox2.Text+'月');
end;
for iRow:=0 to 19 do
begin
for iCol:=2 to 7 do
WriteCell(iRow+8,iCol+12,ListView2.Items[iRow].SubItems[iCol]);
WriteCell(4,11,'汇总单位:'+Edit1.Text);
WriteCell(28,11,'统计负责人:'+PrnInfoFrm.StatMainPerson);
WriteCell(28,16,PrnInfoFrm.StatPerson);
WriteCell(28,20,DateToStr(PrnInfoFrm.StatDate));
WriteCell(3,15,ComboBox1.Text+'年 '+ComboBox2.Text+'月');
end;
for iRow:=0 to 20 do
begin
for iCol:=2 to 7 do
WriteCell(iRow+38,iCol+2,ListView3.Items[iRow].SubItems[iCol]);
WriteCell(34,1,'汇总单位:'+Edit1.Text);
WriteCell(59,1,'统计负责人:'+PrnInfoFrm.StatMainPerson);
WriteCell(59,6,PrnInfoFrm.StatPerson);
WriteCell(59,10,DateToStr(PrnInfoFrm.StatDate));
WriteCell(33,5,ComboBox1.Text+'年 '+ComboBox2.Text+'月');
end;
for iRow:=0 to 19 do
begin
for iCol:=2 to 7 do
WriteCell(iRow+38,iCol+12,ListView4.Items[iRow].SubItems[iCol]);
WriteCell(34,11,'汇总单位:'+Edit1.Text);
WriteCell(59,11,'统计负责人:'+PrnInfoFrm.StatMainPerson);
WriteCell(59,16,PrnInfoFrm.StatPerson);
WriteCell(59,20,DateToStr(PrnInfoFrm.StatDate));
WriteCell(33,15,ComboBox1.Text+'年 '+ComboBox2.Text+'月');
end;
PrintExcelShow;
PrintPreview;
CloseActiveBook;
end;
procedure TBusHYMonthRep.FormShow(Sender: TObject);
begin
iAddFlag:=0;
iExistFlag:=0;
InitListview(ListView1,20,6);
InitListview(ListView2,20,6);
InitListview(ListView3,21,6);
InitListview(LIstView4,20,6);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -