📄 busindustry_report.pas
字号:
unit BusIndustry_Report;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, ExtCtrls, StdCtrls, Buttons, DB, ADODB;
Type TChangeReturn=record //记录增加减少的返回数据
incrnum : string;
decrnum : string;
end;
//Type TState=Set of (Run,Nul,Ini,Ful);
type
TAnnualReport = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
TabSheet3: TTabSheet;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
ComboBox1: TComboBox;
Label1: TLabel;
Panel3: TPanel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
ListView1: TListView;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Panel4: TPanel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
ListView2: TListView;
Panel5: TPanel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
ListView3: TListView;
ADOQuery1: TADOQuery;
BitBtn3: TBitBtn;
Edit2: TEdit;
Label20: TLabel;
ADOQuery2: TADOQuery;
ADOCommand1: TADOCommand;
ADOQuery3: TADOQuery;
BitBtn4: TBitBtn;
Label21: TLabel;
Edit3: TEdit;
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
sumyear : string; //汇总年份;
amount : array [1..52] of integer;
itemnumber : integer; //指标个数 从1开始
capital : array [1..52] of single;
iname: array [0..51] of string;
istate : String;
procedure InitListViews(); // init listviews and two array
procedure GetName(rowstr : array of string); //get row name in the listviews
function GetIndex(tmpname : string): integer; //get the position in the array ;failed return -1;
function GetIndex2(tmpname : string; statptn: integer): integer; //get the position in the array searching from statptn ;failed return -1;
procedure annextop(); //add to get the first line in the report
procedure annexdeal(); //deal with some special record
procedure annex(stat:integer; et: integer; n : integer; aim : integer); //add record from stat to et in the listview of n;result put to aim location
function GetIncrDecr(sumyear:string;s1:string;typename:string): TChangeReturn;
procedure SetBtn();
end;
var
AnnualReport: TAnnualReport;
implementation
uses BusTradeDataModuleUnit, BusHYMonthRepUnit, PrintInfoUnit, PrintProc2;
{$R *.dfm}
procedure TAnnualReport.SetBtn();
begin
if (iState = 'Run')
then
begin
ComboBox1.Enabled := false;
BitBtn1.Enabled := false;
BitBtn2.Enabled := false;
BitBtn3.Enabled := false;
BitBtn4.Enabled := false;
end;
if (iState = 'Ini')
then
begin
ComboBox1.Enabled := true;
BitBtn1.Enabled := true;
BitBtn2.Enabled := true;
BitBtn3.Enabled := false;
BitBtn4.Enabled := false;
end;
if (iState = 'Ful')
then
begin
BitBtn1.Enabled := true;
BitBtn2.Enabled := false;
BitBtn3.Enabled := true;
BitBtn4.Enabled := true;
ComboBox1.Enabled := true;
end;
if (iState = 'Nul')
then
begin
BitBtn1.Enabled := true;
BitBtn2.Enabled := false;
BitBtn3.Enabled := false;
BitBtn4.Enabled := true;
end;
end;
function TAnnualReport.GetIncrDecr(sumyear:string;s1:string;typename:string):TChangeReturn;
var
sqlstr2: string;
thisnum,prevnum,conum : integer;
begin
sqlstr2 := 'select count(单位代码) as thisnum from 公用事业单位基本情况表 where 统计年份='+sumyear+' and '+typename+'='+''''+s1+'''';
AdoQuery2.Close;
AdoQuery2.SQL.Clear;
AdoQuery2.SQL.Add(sqlstr2);
AdoQuery2.Open;
thisnum := AdoQuery2.fieldbyname('thisnum').AsInteger;
sqlstr2 := 'select count(单位代码) as prevnum from 公用事业单位基本情况表 where 统计年份='+intTostr(strtoint(sumyear)-1)+' and '+typename+'='+''''+s1+'''';
AdoQuery2.Close;
AdoQuery2.SQL.Clear;
AdoQuery2.SQL.Add(sqlstr2);
AdoQuery2.Open;
prevnum := AdoQuery2.fieldbyname('prevnum').AsInteger;
sqlstr2 := 'select count(单位代码) as conum from 公用事业单位基本情况表 where 统计年份='+sumyear+' and '+typename+'='+''''+s1+''''+ ' and 单位代码 in (select 单位代码 from 公用事业单位基本情况表 where 统计年份='+intTostr(strtoint(sumyear)-1)+' and '+typename+'='+''''+s1+''''+')';
AdoQuery2.Close;
AdoQuery2.SQL.Clear;
AdoQuery2.SQL.Add(sqlstr2);
AdoQuery2.Open;
conum := AdoQuery2.fieldbyname('conum').AsInteger;
GetIncrDecr.incrnum := IntToStr(thisnum - conum);
GetIncrDecr.decrnum := IntToStr(prevnum - conum);
end;
procedure TAnnualReport.annextop();
var
sqlstr: string;
conum,prevnum,tmp: integer;
begin
sqlstr:='select count(单位代码) as amount,sum(企业注册资本金) as moneyval from 公用事业单位基本情况表 where 统计年份='+sumyear;
AdoQuery2.Close;
AdoQuery2.SQL.Clear;
AdoQuery2.SQL.Add(sqlstr);
AdoQuery2.Open;
ListView1.Items.Item[0].SubItems[1]:= AdoQuery2.fieldbyname('amount').AsString;
tmp := StrToInt(ListView1.Items.Item[0].SubItems[1]);
listview1.Items.Item[0].SubItems[4]:= ConverterPercent(AdoQuery2.fieldbyname('moneyval').AsString);
sqlstr:='select count(单位代码) as amount from 公用事业单位基本情况表 where 统计年份='+IntToStr(strToInt(sumyear)-1);
AdoQuery2.Close;
AdoQuery2.SQL.Clear;
AdoQuery2.SQL.Add(sqlstr);
AdoQuery2.Open;
prevnum := AdoQuery2.fieldbyname('amount').AsInteger;
sqlstr:='select count(单位代码) as amount from 公用事业单位基本情况表 where 统计年份='+sumyear+' and 单位代码 in (select 单位代码 from 公用事业单位基本情况表 where 统计年份='+IntToStr(strToInt(sumyear)-1)+')';
AdoQuery2.Close;
AdoQuery2.SQL.Clear;
AdoQuery2.SQL.Add(sqlstr);
AdoQuery2.Open;
conum := AdoQuery2.fieldbyname('amount').AsInteger;
ListView1.Items.Item[0].SubItems[2]:= IntToStr(tmp - conum);
ListView1.Items.Item[0].SubItems[3]:= IntToStr(prevnum - conum);
end;
procedure TAnnualReport.annex(stat:integer; et: integer; n : integer; aim : integer);
var
rowindex: integer;
sumval,incrval,decrval:integer;
moneyval:single;
begin
rowindex := stat;
sumval := 0;incrval:=0;decrval:=0;moneyval:=0;
case n of
1: begin
while (rowindex<=et)
do
begin
sumval := sumval+StrToInt(listview1.Items.Item[rowindex].SubItems[1]);
incrval:= incrval+StrToInt(listview1.Items.Item[rowindex].SubItems[2]);
decrval:= decrval+StrToInt(listview1.Items.Item[rowindex].SubItems[3]);
moneyval:=moneyval+StrToFloat(listview1.Items.Item[rowindex].SubItems[4]);
rowindex:=rowindex+1;
end;
listview1.Items.Item[aim].SubItems[1]:=IntToStr(sumval);
listview1.Items.Item[aim].SubItems[2]:=IntToStr(incrval);
listview1.Items.Item[aim].SubItems[3]:=IntToStr(decrval);
listview1.Items.Item[aim].SubItems[4]:=ConverterPercent(FloatToStr(moneyval));
end;
2: begin
while (rowindex<=et)
do
begin
sumval := sumval+StrToInt(listview2.Items.Item[rowindex].SubItems[1]);
incrval:= incrval+StrToInt(listview2.Items.Item[rowindex].SubItems[2]);
decrval:= decrval+StrToInt(listview2.Items.Item[rowindex].SubItems[3]);
moneyval:=moneyval+StrToFloat(listview2.Items.Item[rowindex].SubItems[4]);
rowindex:=rowindex+1;
end;
listview2.Items.Item[aim].SubItems[1]:=IntToStr(sumval);
listview2.Items.Item[aim].SubItems[2]:=IntToStr(incrval);
listview2.Items.Item[aim].SubItems[3]:=IntToStr(decrval);
listview2.Items.Item[aim].SubItems[4]:=ConverterPercent(FloatToStr(moneyval));
end;
3: begin
while (rowindex<=et)
do
begin
sumval := sumval+StrToInt(listview3.Items.Item[rowindex].SubItems[1]);
incrval:= incrval+StrToInt(listview3.Items.Item[rowindex].SubItems[2]);
decrval:= decrval+StrToInt(listview3.Items.Item[rowindex].SubItems[3]);
moneyval:=moneyval+StrToFloat(listview3.Items.Item[rowindex].SubItems[4]);
rowindex:=rowindex+1;
end;
listview3.Items.Item[aim].SubItems[1]:=IntToStr(sumval);
listview3.Items.Item[aim].SubItems[2]:=IntToStr(incrval);
listview3.Items.Item[aim].SubItems[3]:=IntToStr(decrval);
listview3.Items.Item[aim].SubItems[4]:=ConverterPercent(FloatToStr(moneyval));
end;
end;
end;
procedure TAnnualReport.annexdeal();
var
sqlstr2: string;
thisnum,prevnum,conum : integer;
isum,iincr,idecr,icap: string;
begin
annex(7,18,1,6);
isum := listview1.Items.Item[6].SubItems[1];
iincr:= listview1.Items.Item[6].SubItems[2];
idecr:= listview1.Items.Item[6].SubItems[3];
icap := listview1.Items.Item[6].SubItems[4];
listview1.Items.Item[0].SubItems[1] := isum;
listview1.Items.Item[0].SubItems[2] := iincr;
listview1.Items.Item[0].SubItems[3] := idecr;
listview1.Items.Item[0].SubItems[4] := ConverterPercent(icap);
listview2.Items.Item[0].SubItems[1] := isum;
listview2.Items.Item[0].SubItems[2] := iincr;
listview2.Items.Item[0].SubItems[3] := idecr;
listview2.Items.Item[0].SubItems[4] := ConverterPercent(icap);
listview3.Items.Item[0].SubItems[1] := isum;
listview3.Items.Item[0].SubItems[2] := iincr;
listview3.Items.Item[0].SubItems[3] := idecr;
listview3.Items.Item[0].SubItems[4] := ConverterPercent(icap);
listview3.Items.Item[6].SubItems[1] := isum;
listview3.Items.Item[6].SubItems[2] := iincr;
listview3.Items.Item[6].SubItems[3] := idecr;
listview3.Items.Item[6].SubItems[4] := ConverterPercent(icap);
sqlstr2 :='select count(企业代码) as inum from 主要业务活动表 where 统计年份='+sumyear+' and (地铁='+''''+'1'+''''+' or 轻轨='+''''+'1'+''''+' or 轮渡='+''''+'1'+''''+' or 公共汽车、电车='+''''+'1'+''''+' )';
AdoQuery2.Close;
AdoQuery2.SQL.Clear;
AdoQuery2.SQL.Add(sqlstr2);
AdoQuery2.Open;
thisnum := AdoQuery2.fieldbyname('inum').AsInteger;
listview1.Items.Item[1].SubItems[1]:= IntToStr(thisnum);
sqlstr2 :='select count(企业代码) as inum from 主要业务活动表 where 统计年份='+IntToStr(StrToInt(sumyear)-1)+' and (地铁='+''''+'1'+''''+' or 轻轨='+''''+'1'+''''+' or 轮渡='+''''+'1'+''''+' or 公共汽车、电车='+''''+'1'+''''+' )';
AdoQuery2.Close;
AdoQuery2.SQL.Clear;
AdoQuery2.SQL.Add(sqlstr2);
AdoQuery2.Open;
prevnum := AdoQuery2.fieldbyname('inum').AsInteger;
if (thisnum>prevnum) then listview1.Items.Item[1].SubItems[2]:= IntToStr(thisnum-prevnum);
if (thisnum<prevnum) then listview1.Items.Item[1].SubItems[3]:= IntToStr(thisnum-prevnum);
sqlstr2 :='select sum(企业注册资本金) as capi from 公用事业单位基本情况表 where 统计年份='+sumyear+' and 单位代码 in ( select 企业代码 from 主要业务活动表 where 统计年份='+sumyear+' and (地铁='+''''+'1'+''''+' or 轻轨='+''''+'1'+''''+' or 轮渡='+''''+'1'+''''+' or 公共汽车、电车='+''''+'1'+''''+' ))';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -