📄 bustrayearlrunit.pas
字号:
unit BusTraYearLRUnit;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, ComCtrls, StdCtrls, Buttons, ExtCtrls;
type
TBusTraYearLRFm = class(TForm)
Panel3: TPanel;
Panel1: TPanel;
Panel2: TPanel;
Label6: TLabel;
Edit1: TEdit;
Panel4: TPanel;
Label2: TLabel;
Label3: TLabel;
ComboBox1: TComboBox;
Panel5: TPanel;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
Panel6: TPanel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
ListView1: TListView;
TabSheet2: TTabSheet;
ListView2: TListView;
TabSheet3: TTabSheet;
ListView3: TListView;
TabSheet4: TTabSheet;
ListView4: TListView;
ADOQuery1: TADOQuery;
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
iAddFlag:Integer;
iExistFlag:Integer;
procedure WriteListView(LView:TListView;Row:Integer;Source:TADOQuery);
function TwoDisim(input:string):string;
{ Public declarations }
end;
var
BusTraYearLRFm: TBusTraYearLRFm;
implementation
uses PrintInfoUnit, PrintProc, BusTradeDataModuleUnit;
{$R *.dfm}
procedure TBusTraYearLRFm.WriteListView(LView:TListView;Row:Integer;Source:TADOQuery);
var
i:integer;
begin
for i:=0 to Row-1 do
begin
if LView.Items[i].SubItems.Count<3 then
begin
LView.Items[i].SubItems.Add(TwoDisim(Source.fieldbyname('全年实际').AsString));
LView.Items[i].SubItems.Add(TwoDisim(Source.fieldbyname('去年同期').AsString));
LView.Items[i].SubItems.Add(TwoDisim(Source.fieldbyname('比较百分比').AsString));
Source.Next;
end else
begin
LView.Items[i].SubItems[2]:=TwoDisim(Source.fieldbyname('全年实际').AsString);
LView.Items[i].SubItems[3]:=TwoDisim(Source.fieldbyname('去年同期').AsString);
LView.Items[i].SubItems[4]:=TwoDisim(Source.fieldbyname('比较百分比').AsString);
Source.Next;
end;
end;
end;
function TBusTraYearLRFm.TwoDisim(input:string):string;
var
iPosNum:integer;
sString:string;
begin
iPosNum:=Pos('.',input);
if iPosNum<>0 then
begin
sString:=copy(input,1,iPosNum+2);
TwoDisim:=sString;
end
else if iPosNum=0 then TwoDisim:=input;
end;
procedure TBusTraYearLRFm.BitBtn3Click(Sender: TObject);
var
iRow,iCol:integer;
begin
//Edit4.Text:='';
Edit1.Text:='';
ComboBox1.Text:='';
if ListView1.Items[0].SubItems.Count>2 then
begin
for iRow:=0 to 22 do
for iCol:=2 to 4 do
ListView1.Items[iRow].SubItems[iCol]:='';
end;
if ListView2.Items[0].SubItems.Count>2 then
begin
for iRow:=0 to 22 do
for iCol:=2 to 4 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 4 do
ListView3.Items[iRow].SubItems[iCol]:='';
end;
if ListView4.Items[0].SubItems.Count>2 then
begin
for iRow:=0 to 18 do
for iCol:=2 to 4 do
ListView4.Items[iRow].SubItems[iCol]:='';
end;
BitBtn2.Enabled:=false;
Close;
end;
procedure TBusTraYearLRFm.BitBtn1Click(Sender: TObject);
var
ThisYear,LastYear:String;
j:integer;
iRow:Integer;
sqlString:String;
iCityCode:String;
begin
ThisYear:=ComboBox1.Text;
if ((Length(ThisYear) <> 4) or (ThisYear<'1990') or (ThisYear >'2030')) then
begin
ShowMessage('请输入在时间范围1990-2030内的合法年份!');
exit;
end;
LastYear:=IntToStr(StrToInt(ThisYear)-1);
iCityCode:='''' + '022' + '''';
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
sqlString:= 'select 指标代码,测算值 as 全年实际 from 公交行业统计年报_z where'
+' 城市代码=' + iCityCode + ' and 统计年份='+ThisYear;
ADOQuery1.SQL.Add(sqlString);
ADOQuery1.Open;
if ADOQuery1.RecordCount=0 then
begin
ShowMessage('对不起!数据库中没有'+ThisYear+'年的测算数据,请先录入!');
if iAddFlag=1 then
begin
ClearData(ListView1,23,0,3,2);
ClearData(ListView2,23,0,3,2);
ClearData(ListView3,21,0,3,2);
ClearData(ListView4,19,0,3,2);
end;
BitBtn2.Enabled:=false;
exit;
end
else
begin
ADOQuery1.First;
for iRow:= 0 to ADOQuery1.RecordCount-1 do
begin
if ADOQuery1.FieldByName('全年实际').AsString<>'' then
begin
iExistFlag:=1;
break;
end;
ADOQuery1.Next;
end;
if iExistFlag=0 then
begin
ShowMessage('对不起!数据库中没有'+ThisYear+'年的测算数据,请先录入!');
if iAddFlag=1 then
begin
ClearData(ListView1,23,0,3,2);
ClearData(ListView2,23,0,3,2);
ClearData(ListView3,21,0,3,2);
ClearData(ListView4,19,0,3,2);
end;
exit;
end;
end;
iExistFlag:=0;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
sqlString:= 'select 指标代码,测算值 as 全年实际 from 公交行业统计年报_z where '
+ ' 城市代码=' + iCityCode + ' and 统计年份='+LastYear;
ADOQuery1.SQL.Add(sqlString);
ADOQuery1.Open;
if ADOQuery1.RecordCount=0 then
begin
ShowMessage('对不起!数据库中没有'+LastYear+'年的测算数据,请先录入!');
if iAddFlag=1 then
begin
ClearData(ListView1,23,0,3,2);
ClearData(ListView2,23,0,3,2);
ClearData(ListView3,21,0,3,2);
ClearData(ListView4,19,0,3,2);
end;
BitBtn2.Enabled:=false;
exit;
end
else
begin
ADOQuery1.First;
for iRow:= 0 to ADOQuery1.RecordCount-1 do
begin
if ADOQuery1.FieldByName('全年实际').AsString<>'' then
begin
iExistFlag:=1;
break;
end;
ADOQuery1.Next;
end;
//iExistFlag:=0;
if iExistFlag=0 then
begin
ShowMessage('对不起!数据库中没有'+LastYear+'年的测算数据,请先录入!');
if iAddFlag=1 then
begin
ClearData(ListView1,23,0,3,2);
ClearData(ListView2,23,0,3,2);
ClearData(ListView3,21,0,3,2);
ClearData(ListView4,19,0,3,2);
end;
exit;
end;
end;
iExistFlag:=0;
ADOQuery1.First;
for j:=0 to ADOQuery1.RecordCount-1 do
begin
if StrToFloat(ADOQuery1.FieldByName('全年实际').AsString)=0 then
begin
showmessage(LastYear+'年的测算数据中有些指标的全年实际为零!请重新选择或更改该年数据!');
if iAddFlag=1 then
begin
ClearData(ListView1,23,0,3,2);
ClearData(ListView2,23,0,3,2);
ClearData(ListView3,21,0,3,2);
ClearData(ListView4,19,0,3,2);
end;
BitBtn2.Enabled:=false;
exit;
end;
ADOQuery1.Next;
end;
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
sqlString:='select a.指标代码, a.测算值 AS 全年实际,'
+' b.测算值 AS 去年同期, (全年实际-去年同期)/去年同期*100 AS 比较百分比'
+' from 公交行业统计年报_z AS a, 公交行业统计年报_z AS b'
+' WHERE a.城市代码=' + iCityCode + ' and b.城市代码=a.城市代码'
+' and a.统计年份='+ThisYear+' and b.统计年份='
+LastYear+' and a.指标代码=b.指标代码'
+' ORDER BY a.指标代码';
ADOQuery1.SQL.Add(sqlString);
ADOQuery1.Open;
if ADOQuery1.RecordCount<>0 then
begin
WriteListView(ListView1,23,ADOQuery1);
WriteListView(ListView2,23,ADOQuery1);
WriteListView(ListView3,21,ADOQuery1);
WriteListView(ListView4,19,ADOQuery1);
iAddFlag:=1;
BitBtn2.Enabled:=true;
end;
end;
procedure TBusTraYearLRFm.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),'BusTradeCountYearTab');
for iRow:=0 to 22 do
begin
for iCol:=2 to 4 do
WriteCell(iRow+7,iCol+2,ListView1.Items[iRow].SubItems[iCol]);
WriteCell(3,1,'汇总单位:'+Edit1.Text);
WriteCell(30,1,'统计负责人:'+PrnInfoFrm.StatMainPerson);
WriteCell(30,5,PrnInfoFrm.StatPerson);
WriteCell(30,7,DateToStr(PrnInfoFrm.StatDate));
WriteCell(2,4,ComboBox1.Text+'年');
end;
for iRow:=0 to 22 do
begin
for iCol:=2 to 4 do
WriteCell(iRow+7,iCol+10,ListView2.Items[iRow].SubItems[iCol]);
WriteCell(3,9,'汇总单位:'+Edit1.Text);
WriteCell(30,9,'统计负责人:'+PrnInfoFrm.StatMainPerson);
WriteCell(30,13,PrnInfoFrm.StatPerson);
WriteCell(30,15,DateToStr(PrnInfoFrm.StatDate));
WriteCell(2,12,ComboBox1.Text+'年');
end;
for iRow:=0 to 20 do
begin
for iCol:=2 to 4 do
WriteCell(iRow+38,iCol+2,ListView3.Items[iRow].SubItems[iCol]);
WriteCell(34,1,'汇总单位:'+Edit1.Text);
WriteCell(59,1,'统计负责人:'+PrnInfoFrm.StatMainPerson);
WriteCell(59,5,PrnInfoFrm.StatPerson);
WriteCell(59,7,DateToStr(PrnInfoFrm.StatDate));
WriteCell(33,4,ComboBox1.Text+'年');
end;
for iRow:=0 to 18 do
begin
for iCol:=2 to 4 do
WriteCell(iRow+38,iCol+10,ListView4.Items[iRow].SubItems[iCol]);
WriteCell(34,9,'汇总单位:'+Edit1.Text);
WriteCell(59,9,'统计负责人:'+PrnInfoFrm.StatMainPerson);
WriteCell(59,13,PrnInfoFrm.StatPerson);
WriteCell(59,15,DateToStr(PrnInfoFrm.StatDate));
WriteCell(33,12,ComboBox1.Text+'年');
end;
PrintExcelShow;
PrintPreview;
CloseActiveBook;
end;
procedure TBusTraYearLRFm.FormCreate(Sender: TObject);
begin
iAddFlag:=0;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -