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

📄 bushymonthrepunit.pas

📁 公交行业的管理系统
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit BusHYMonthRepUnit;

interface

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

type
  TBusHYMonthRep = class(TForm)
    ADOQuery1: TADOQuery;
    Panel3: TPanel;
    Panel5: TPanel;
    Panel1: TPanel;
    Label6: TLabel;
    Edit1: TEdit;
    Panel4: TPanel;
    Label2: TLabel;
    Label3: TLabel;
    Label9: TLabel;
    ComboBox1: TComboBox;
    ComboBox2: TComboBox;
    Panel2: 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;
    Panel7: TPanel;
    Label1: TLabel;
    Label5: TLabel;
    ComboBox3: 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 WriteListView(LView:TListView;Row:Integer;ColInit:Integer;Source:TADOQuery);
    function TwoDisim(input:string):string;
    procedure InitListview(ListViewName:TListView;Rows:Integer;Cols:Integer);
    function CalculatePercent(sDiv:string;sDivd:String;sAddPar:Integer):string;

    { Public declarations }
  end;

var
  BusHYMonthRep: TBusHYMonthRep;

implementation

uses  PrintProc, PrintInfoUnit, BusTradeDataModuleUnit;

{$R *.dfm}
function TBusHYMonthRep.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 TBusHYMonthRep.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 TBusHYMonthRep.WriteListView(LView:TListView;Row:Integer;ColInit:Integer;Source:TADOQuery);
var
        i:integer;
        iCol:integer;
begin
        iCol:= ColInit;
        for i:=0 to Row-1 do
        begin
                LView.Items[i].SubItems[ColInit]:=TwoDisim(Source.fieldbyname('本年本月实际').AsString);
                LView.Items[i].SubItems[ColInit+1]:=TwoDisim(Source.fieldbyname('本年累计').AsString);
                Source.Next;
        end;
end;

function TBusHYMonthRep.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 TBusHYMonthRep.BitBtn1Click(Sender: TObject);
var
        iRow:Integer;
        ThisYear,LastYear,StartMon,MonTime:string;
        j:integer;
        iCityCode:String;
        sqlString:String;
        sDataType:String;
        iListView:TListView;
begin
        ThisYear:=ComboBox1.Text;
        StartMon:=ComboBox2.Text;

        if ((Length(ThisYear) <> 4) or (ThisYear<'1990') or (ThisYear >'2030')) then
        begin
                ShowMessage('请输入在时间范围1990-2030内的合法年份!');
                exit;
        end
        else if StartMon='' then
        begin
                ShowMessage('请选择统计月份!');
                exit;
        end;

        LastYear:=IntToStr(StrToInt(ThisYear)-1);

        {if ComboBox3.Text='生成值' then
        begin
                sDataType:='本月实际';
        end
        else
        begin}
                sDataType:= ComboBox3.Text;
        //end;

        ADOQuery1.Close;
        ADOQuery1.SQL.Clear;
        sqlString:='select 指标代码,' + sDataType + ' as 实际 from 公交行业统计月报_z'
                       +' where 城市代码=' + '''' + '022' + '''' + ' and 统计年份='+ThisYear+' and 统计月份='+StartMon;
        ADOQuery1.SQL.Add(sqlString);
        ADOQuery1.Open;
        if ADOQuery1.RecordCount=0 then
        begin
                showmessage('对不起!数据库中没有'+ThisYear+'年'+StartMon+'月的数据!');
                if iAddFlag=1 then
                begin
                        ClearData(ListView1,20,0,6,2);
                        ClearData(ListView2,20,0,6,2);
                        ClearData(ListView3,21,0,6,2);
                        ClearData(ListView4,20,0,6,2);
                end;
                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;
                if iExistFlag=0 then
                begin
                        ShowMessage('对不起!数据库中没有'+ThisYear+'年'+StartMon+'月的数据!');
                        if iAddFlag=1 then
                        begin
                                ClearData(ListView1,20,0,6,2);
                                ClearData(ListView2,20,0,6,2);
                                ClearData(ListView3,21,0,6,2);
                                ClearData(ListView4,20,0,6,2);
                        end;
                        exit;
                end;
        end;

        iExistFlag:=0;
        ADOQuery1.Close;
        ADOQuery1.SQL.Clear;
        sqlString:='select 指标代码,' + sDataType + ' as 实际 from 公交行业统计月报_z'
                       +' where 城市代码=' + '''' + '022' + '''' + ' and 统计年份='+LastYear+' and 统计月份='+StartMon;
        ADOQuery1.SQL.Add(sqlString);
        ADOQuery1.Open;
        if ADOQuery1.RecordCount=0 then
        begin
                showmessage('对不起!数据库中没有'+LastYear+'年'+StartMon+'月的数据!');
                if iAddFlag=1 then
                begin
                        ClearData(ListView1,20,0,6,2);
                        ClearData(ListView2,20,0,6,2);
                        ClearData(ListView3,21,0,6,2);
                        ClearData(ListView4,20,0,6,2);
                end;

                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;
                if iExistFlag=0 then
                begin
                        ShowMessage('对不起!数据库中没有'+LastYear+'年'+StartMon+'月的数据!');
                        if iAddFlag=1 then
                        begin
                                ClearData(ListView1,20,0,6,2);
                                ClearData(ListView2,20,0,6,2);
                                ClearData(ListView3,21,0,6,2);
                                ClearData(ListView4,20,0,6,2);
                        end;
                        exit;
                end;
        end;

        {iExistFlag:=0;
        ADOQuery1.First;
        for j:=0 to ADOQuery1.RecordCount-1 do
        begin
                if (ADOQuery1.FieldByName('实际').AsFloat=0) then
                begin
                        showmessage('对不起!去年本月实际中有零值!请重新选择或修改去年本月实际值!');
                        if iAddFlag=1 then
                        begin
                                ClearData(ListView1,20,0,6,2);
                                ClearData(ListView2,20,0,6,2);
                                ClearData(ListView3,21,0,6,2);
                                ClearData(ListView4,20,0,6,2);

⌨️ 快捷键说明

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