⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bushyyearreportunit.pas

📁 公交行业的管理系统
💻 PAS
字号:
unit BusHYYearReportUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, Buttons, StdCtrls, ExtCtrls, DB, ADODB;

type
  TBusHYYearRep = class(TForm)
    ADOQuery1: TADOQuery;
    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;
    Panel14: TPanel;
    Label4: TLabel;
    Label5: TLabel;
    ComboBox2: TComboBox;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn3Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    iAddFlag:Integer;
    iExistFlag:Integer;
    procedure InitListview(ListViewName:TListView;Rows:Integer;Cols:Integer);
    procedure WriteListView(LView:TListView;Row:Integer;Source:TADOQuery);
    function TwoDisim(input:string):string;
    function CalculatePercent(sDiv:string;sDivd:String;sAddPar:Integer):string;
    { Public declarations }
  end;

var
  BusHYYearRep: TBusHYYearRep;

implementation

uses {Code, BusDataModuleUnit,} PrintProc, PrintInfoUnit,
  BusTradeDataModuleUnit;

{$R *.dfm}
function TBusHYYearRep.CalculatePercent(sDiv:string;sDivd:String;sAddPar:Integer):string;
var
        iReturn:String;
        iDiv:single;
        iDivd:single;
        iResult:single;
begin
        if (sDiv='') then
        begin
                iDiv:=0;
        end
        else
        begin
                iDiv:=StrToFloat(sDiv);
        end;

        iDivd:=StrToFloat(sDivd);
        if iDivd=0 then
        begin
                iResult:=0;
        end
        else
        begin
                iResult:=(iDiv-iDivd)/iDivd*sAddPar;
        end;

        iReturn:=FloatToStr(iResult);

        CalculatePercent:=ConverterPercent(iReturn);

end;

procedure TBusHYYearRep.InitListview(ListViewName:TListView;Rows:Integer;Cols:Integer);
var
        iListView:TListView;
        iRecNum:Integer;
        iCol:Integer;
begin
        iListView:=ListViewName;
        for iRecNum:=0 to Rows-1 do
        begin
                for iCol := 0 to Cols-1 do
                begin
                        iListView.Items[iRecNum].SubItems.Add('');
                end;
        end;

end;

procedure TBusHYYearRep.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));
                if  then
                        begin

                        end;

                        //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);
                if (LView.Items[i].SubItems[3]='') or (LView.Items[i].SubItems[3]='0') then
                begin
                        LView.Items[i].SubItems[4]:='0';
                end
                else
                begin
                        LView.Items[i].SubItems[4]:=TwoDisim(CalculatePercent(LView.Items[i].SubItems[2],LView.Items[i].SubItems[3],100));
                end;
                Source.Next;
                //end;
        end;
end;

function TBusHYYearRep.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 TBusHYYearRep.BitBtn1Click(Sender: TObject);
var
        ThisYear,LastYear:String;
        j:integer;
        iCityCode:String;
        iRow:Integer;
        sqlString:String;
        iDataType: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' + '''';
         iDataType:=ComboBox2.Text;

         ADOQuery1.Close;
         ADOQuery1.SQL.Clear;
         sqlString:= 'select 指标代码,' + iDataType + ' as 实际 from 公交行业统计年报_z where '
                   + ' 城市代码=' + iCityCode + ' and 统计年份='+ThisYear;

         ADOQuery1.SQL.Add(sqlString);
         ADOQuery1.Open;

         iExistFlag:=0;
         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('实际').AsFloat<>0 then
                        begin
                                iExistFlag:=1;
                                break;
                        end;
                        ADOQuery1.Next;
                end;
                //iExistFlag:=0;
                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 指标代码,' + iDataType + ' 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('实际').AsFloat<>0 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.' + iDataType + ' AS 全年实际,b.' + iDataType + ' 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 TBusHYYearRep.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;
        BusHYYearRep.Close;
end;

procedure TBusHYYearRep.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 TBusHYYearRep.FormShow(Sender: TObject);
begin
        iAddFlag:=0;
        iExistFlag:=0;

        InitListview(Listview1,23,3);
        InitListview(Listview2,23,3);
        InitListview(Listview3,21,3);
        InitListview(Listview4,19,3);

end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -