?? bushymonthrepunit.pas
字號:
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內(nèi)的合法年份!');
exit;
end
else if StartMon='' then
begin
ShowMessage('請選擇統(tǒng)計月份!');
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 公交行業(yè)統(tǒng)計月報_z'
+' where 城市代碼=' + '''' + '022' + '''' + ' and 統(tǒng)計年份='+ThisYear+' and 統(tǒng)計月份='+StartMon;
ADOQuery1.SQL.Add(sqlString);
ADOQuery1.Open;
if ADOQuery1.RecordCount=0 then
begin
showmessage('對不起!數(shù)據(jù)庫中沒有'+ThisYear+'年'+StartMon+'月的數(shù)據(jù)!');
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('對不起!數(shù)據(jù)庫中沒有'+ThisYear+'年'+StartMon+'月的數(shù)據(jù)!');
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 公交行業(yè)統(tǒng)計月報_z'
+' where 城市代碼=' + '''' + '022' + '''' + ' and 統(tǒng)計年份='+LastYear+' and 統(tǒng)計月份='+StartMon;
ADOQuery1.SQL.Add(sqlString);
ADOQuery1.Open;
if ADOQuery1.RecordCount=0 then
begin
showmessage('對不起!數(shù)據(jù)庫中沒有'+LastYear+'年'+StartMon+'月的數(shù)據(jù)!');
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('對不起!數(shù)據(jù)庫中沒有'+LastYear+'年'+StartMon+'月的數(shù)據(jù)!');
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 + -