subrepclass.pas
来自「一个电力企业的后台管理程序」· PAS 代码 · 共 438 行
PAS
438 行
unit SubRepClass;
interface
Uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, dbtables;
//子业务处理信息类
Type TSubOpAmountDealInfo= Class
Private
function FillCurrNum(Dt_CurrDate: TDateTime;Query: TQuery): Boolean;
function FillTotalNum(Dt_CurrDate,TotalDate: TDateTime;Query: TQuery): Boolean;
Public
M_MonORation,M_ToRation,M_MonSRation,M_TSRation: String;
M_SubOpType,M_SubOpID:string; //子业务类型
M_iTotalCMNum,m_iTotalApNum:integer; //本月总计数,累计总计数
M_iACMPCMNum,m_iACMPApNum:integer; //本月完成数,累计完成数
M_iNoAcmpCMNum,m_iNoAcmpApNum:integer; //本月未完成数,累计未完成数
M_iOtAcmpCMNum,m_iOtAcmpApNum:integer; //本月超期完成数,累计超期完成数
M_iCmUserSatisfyNum,m_iApUserSatisfyNum:integer; //本月客户满意数,累计客户满意数
function FillAllNum(Dt_CurrDate,TotalDate: TDateTime): Boolean;
Procedure CalRation;
//构造函数
constructor Create(OpType,OpID: String);
end;
//业务处理信息类
Type TOpAmountDealInfo= Class
Private
FOpType,FOpID:string;
Fb_OverlayCurrData,Fb_OverLayhisData:boolean;
FDt_Curr,Dt_Addup:Tdatetime;
function GetType: String;
//Procedure CalTrouble;
//procedure CalClientAsk;
function FillCurrNum(Query: TQuery): Boolean;
function FillTotalNum(Query: TQuery): Boolean;
function FillSubBunsi(Query: TQuery): Boolean;
Public
M_iTotalCMNum,m_iTotalApNum:integer; //本月总计数,累计总计数
M_iACMPCMNum,m_iACMPApNum:integer; //本月完成数,累计完成数
M_iNoAcmpCMNum,m_iNoAcmpApNum:integer; //本月未完成数,累计未完成数
M_iOtAcmpCMNum,m_iOtAcmpApNum:integer; //本月超期完成数,累计超期完成数
M_iCmUserSatisfyNum,m_iApUserSatisfyNum:integer; //本月客户满意数,累计客户满意数
SubOpamountDealInfo:array of TSubOpAmountDealInfo;
//构造函数 参数:当前时间、累计时间、是否覆盖当前数据、是否覆盖历史数据
property OpBusiType: String read GetType;
constructor Create(Dt_Curr,Dt_AddupDate:Tdatetime;OpType,OpID:string);
procedure CalBusiSum;
end;
//业务比较信息类
Type TOpAmountCompareInfo= Class
Private
FOpType,FOpID:string;
Dt_Curr,Dt_Addup:Tdatetime;
Fb_OverlayCurrData,Fb_OverLayhisData:boolean;
function GetType : String;
function CalMonData(CurrMon: String): Integer;
function CalTotalData(CurrDate,AdDate: String): Integer;
function GetLastMon(Dt_Date: TDateTime): String;
Public
M_iTotalCMNum,m_iTotalApNum:integer; //本月总计数,累计总计数
M_iTotalLMNum,m_iTotalLYCMNum:integer; //上月总计数,去年同期总计数
M_iTotalLYApNum:integer; //去年累计数
//构造函数 参数:当前时间、累计时间、是否覆盖当前数据、是否覆盖历史数据、业务类别
property OpBusiType: String read GetType;
constructor Create(Dt_CurrDate,Dt_AddupDate:Tdatetime;b_Overlayhisdata:Boolean;OpType,OpID:string);
function FillAllData:Boolean;
function OverlayHisData:Boolean;
end;
implementation
uses SystemDM ;
{ TOpAmountCompareInfo }
function TOpAmountCompareInfo.CalMonData(CurrMon: String): Integer;
begin
Result := 0;
with TQuery.Create(nil) do
try
Close;
DataBaseName := SysDM.DBMain.DatabaseName;
Sql.Text := Format('SELECT ALL_NUM FROM STAT_MONTH_SERVICE_NUM WHERE '+
'SERV_CLASS_ID = ''%S'' AND SERV_CLASS_TYPE = ''%S'' AND MONTH_ID = ''%S''',[FOpID,FOpType,CurrMon]);
//Sql.SaveToFile('C:\te.tec') ;
Open;
if RecordCount > 0 then
Result := FieldByName('ALL_NUM').AsInteger
else
Result := 0;
finally
Free;
end;
end;
function TOpAmountCompareInfo.CalTotalData(CurrDate,AdDate: String): Integer;
begin
Result := 0;
with TQuery.Create(nil) do
Try
Close;
DataBaseName := SysDM.DBMain.DatabaseName;
Sql.Text := Format('SELECT SUM(ALL_NUM) TALL_NUM FROM STAT_MONTH_SERVICE_NUM'+
' WHERE MONTH_ID >= ''%S'' AND MONTH_ID <= ''%S'' '+
' AND SERV_CLASS_ID = ''%S'' AND SERV_CLASS_TYPE = ''%S''',[AdDate,CurrDate,FOpID,FOpType]);
Open;
if RecordCount > 0 then
Result := FieldByName('TALL_NUM').AsInteger
else
Result := 0;
finally
Free;
end;
end;
constructor TOpAmountCompareInfo.Create(Dt_CurrDate, Dt_AddupDate: Tdatetime;
b_Overlayhisdata: Boolean; OpType,OpID: string);
begin
//inherited;
FOpType := OpType;
FOpID := OpID;
Dt_Curr := Dt_CurrDate;
Dt_AddUp := Dt_AddUpDate;
end;
function TOpAmountCompareInfo.FillAllData: Boolean;
var
SCurrDate,SAdDate,LastYear,LastAdYear: String;
begin
SCurrDate := FormatDateTime('YYYYMM',Dt_Curr);
SAdDate := FormatDateTime('YYYYMM',Dt_AddUp);
LastYear := IntToStr(StrToInt(Copy(SCurrDate,1,4)) - 1) + Copy(ScurrDate,5,2);
LastAdYear := IntToStr(StrToInt(Copy(SAdDate,1,4)) - 1) + Copy(SAdDate,5,2);
M_iTotalCMNum := CalMonData(SCurrDate);
M_iTotalLMNum := CalMonData(GetLastMon(Dt_Curr));
m_iTotalApNum := CalTotalData(SCurrDate,SAdDate);
m_iTotalLYCMNum := CalMonData(LastYear);
M_iTotalLYApNum := CalTotalData(LastYear,LastAdYear);
end;
function TOpAmountCompareInfo.GetLastMon(Dt_Date: TDateTime): String;
var
LastMon,Mon,SYear : String;
begin
Result := '';
LastMon := FormatDateTime('YYYYMM',Dt_Date);
SYear := FormatDateTime('YYYY',Dt_Date);
Mon := FormatDateTime('MM',Dt_Date);
if StrToInt(Mon) - 1 = 0 then
Result := IntToStr(StrToInt(SYear) - 1) + '12'
else
Result := IntToStr(StrToInt(LastMon) - 1)
end;
function TOpAmountCompareInfo.GetType: String;
begin
Result := FOpType;
end;
function TOpAmountCompareInfo.OverlayHisData: Boolean;
begin
ShowMessage('OverLay');
end;
{ TOpAmountDealInfo }
procedure TOpAmountDealInfo.CalBusiSum;
var
Query: TQuery;
begin
Query := TQuery.Create(nil);
try
FillCurrNum(Query);
FillTotalNum(Query);
FillSubBunsi(Query);
finally
Query.Free;
end;
end;
constructor TOpAmountDealInfo.Create(Dt_Curr, Dt_AddupDate: Tdatetime;
OpType,OpID: string);
begin
//inherited;
FOpType := OpType;
FOpID := OpID;
FDt_Curr := Dt_Curr;
Dt_Addup := Dt_AddUpDate;
end;
function TOpAmountDealInfo.FillCurrNum(Query: TQuery): Boolean;
var
SCurrDate: String;
begin
Result := False;
SCurrDate := FormatDateTime('YYYYMM',FDt_Curr);
with Query do
try
Close;
DataBaseName := SysDM.DBMain.DatabaseName;
Sql.Text := Format('SELECT * FROM STAT_MONTH_SERVICE_NUM WHERE '+
'MONTH_ID = ''%S'' AND SERV_CLASS_ID = ''%S'''+
' AND SERV_CLASS_TYPE = ''%S''' ,[SCurrDate,FOpID,FOpType]);
Open;
if RecordCount = 0 then //如纪录为空当月值置0
begin
M_iTotalCMNum := 0;
M_iACMPCMNum := 0;
M_iNoAcmpCMNum := 0;
M_iOtAcmpCMNum := 0;
M_iCmUserSatisfyNum := 0;
end
else
begin
M_iTotalCMNum := FieldByName('ALL_Num').AsInteger;
M_iACMPCMNum := FieldByName('ACMP_Num').AsInteger;
M_iNoAcmpCMNum := FieldByName('NOACMP_Num').AsInteger;
M_iOtAcmpCMNum := FieldByName('OTACMP_NUM').AsInteger;
M_iCmUserSatisfyNum := FieldByName('USERSATISFY_NUM').AsInteger;
end;
Result := True;
except
Result := False;
end;
end;
function TOpAmountDealInfo.FillSubBunsi(Query: TQuery): Boolean;
var
SCurrDate,STotalDate: String;
I : Integer;
TempObject: TSubOpAmountDealInfo;
begin
Result := False;
SCurrDate := FormatDateTime('YYYYMM',FDt_Curr);
STotalDate := FormatDatetime('YYYYMM',Dt_AddUp);
with Query do
try
Close;
DataBaseName := SysDM.DBMain.DatabaseName;
Sql.Text := Format('SELECT CLASS_ID,CLASS_TYPE FROM CLASS_CODE '+
'WHERE PARENT_CLASS_ID = ''%S''AND '+
'PARENT_CLASS_TYPE = ''%S''',[FOpID,FOpType]);
Open;
if RecordCount > 0 then
begin
SetLength(SubOpamountDealInfo,RecordCount);
for I := 0 to RecordCount - 1 do
begin
TempObject := TSubOpAmountDealInfo.Create(FieldByName('CLASS_TYPE').AsString,FieldByName('CLASS_ID').AsString);
TempObject.FillAllNum(FDt_Curr,Dt_AddUp);
SubOpamountDealInfo[I] := TempObject;
Next;
end;
end;
Result := True;
except
Result := False;
end;
end;
function TOpAmountDealInfo.FillTotalNum(Query: TQuery): Boolean;
var
SCurrDate,STotalDate: String;
begin
Result := False;
SCurrDate := FormatDateTime('YYYYMM',FDt_Curr);
STotalDate := FormatDatetime('YYYYMM',Dt_AddUp);
with Query do
try
Close;
DataBaseName := SysDM.DBMain.DatabaseName;
Sql.Text := Format('SELECT SUM(ALL_NUM) TALL_NUM,SUM(ACMP_NUM) TACMP_NUM,'+
'SUM(NOACMP_NUM) TNOACMP_NUM,SUM(OTACMP_NUM) TOTACMP_NUM'+
',SUM(USERSATISFY_NUM) TUSERSATISFY_NUM FROM STAT_MONTH_SERVICE_NUM WHERE '+
'MONTH_ID >= ''%S'' AND MONTH_ID <= ''%S'' AND SERV_CLASS_ID '+
'= ''%S'' AND SERV_CLASS_TYPE = ''%S''' ,[STotalDate,SCurrdate
,FOpID,FOpType]);
//Sql.SaveToFile('C:\test.tete') ;
Open;
if RecordCount = 0 then
begin
m_iTotalApNum := 0;
m_iACMPApNum := 0;
m_iNoAcmpApNum := 0;
m_iOtAcmpApNum := 0;
m_iApUserSatisfyNum := 0;
end
else
begin
m_iTotalApNum := FieldByName('TALL_NUM').AsInteger;
m_iACMPApNum := FieldByName('TACMP_NUM').AsInteger;
m_iNoAcmpApNum := FieldByName('TNOACMP_NUM').AsInteger;
m_iOtAcmpApNum := FieldByName('TOTACMP_NUM').AsInteger;
m_iApUserSatisfyNum := FieldByName('TUSERSATISFY_NUM').AsInteger;
end;
Result := True;
except
Result := False;
end;
end;
function TOpAmountDealInfo.GetType: String;
begin
Result := FOpType;
end;
{ TSubOpAmountDealInfo }
procedure TSubOpAmountDealInfo.CalRation;
begin
if M_iTotalCMNum <> 0 then
M_MonORation := Format('%F',[M_iOtAcmpCMNum / M_iTotalCMNum * 100])
else
M_MonORation := '0';
if m_iTotalApNum <> 0 then
M_TORation := Format('%F',[m_iOtAcmpApNum / m_iTotalApNum * 100])
else
M_TORation := '0';
if M_iTotalCMNum <> 0 then
M_MonSRation := Format('%F',[M_iCmUserSatisfyNum / M_iTotalCMNum * 100])
else
M_MonSRation := '0';
if m_iTotalApNum <> 0 then
M_TSRation := Format('%F',[m_iApUserSatisfyNum / m_iTotalApNum * 100])
else
M_TSRation := '0';
end;
constructor TSubOpAmountDealInfo.Create(OpType,OpID: String);
begin
// inherited;
M_SubOpType := OpType;
M_SubOpID := OpID;
end;
function TSubOpAmountDealInfo.FillAllNum(Dt_CurrDate, TotalDate: TDateTime
): Boolean;
var
Query : TQuery;
begin
Query := TQuery.Create(nil);
try
FillCurrNum(Dt_CurrDate,Query);
FillTotalNum(Dt_CurrDate,TotalDate,Query);
finally
Query.Free;
end;
end;
function TSubOpAmountDealInfo.FillCurrNum(Dt_CurrDate: TDateTime;Query: TQuery): Boolean;
var
SCurrDate: String;
begin
Result := False;
SCurrDate := FormatDateTime('YYYYMM',Dt_CurrDate);
with Query do
try
Close;
DataBaseName := SysDM.DBMain.DatabaseName;
Sql.Text := Format('SELECT * FROM STAT_MONTH_SERVICE_NUM WHERE '+
'MONTH_ID = ''%S'' AND SERV_CLASS_ID = ''%S'''+
' AND SERV_CLASS_TYPE = ''%S''' ,[SCurrDate,M_SubOpID,M_SubOpType]);
Open;
if RecordCount = 0 then //如纪录为空当月值置0
begin
M_iTotalCMNum := 0;
M_iACMPCMNum := 0;
M_iNoAcmpCMNum := 0;
M_iOtAcmpCMNum := 0;
M_iCmUserSatisfyNum := 0;
end
else
begin
M_iTotalCMNum := FieldByName('ALL_Num').AsInteger;
M_iACMPCMNum := FieldByName('ACMP_Num').AsInteger;
M_iNoAcmpCMNum := FieldByName('NOACMP_Num').AsInteger;
M_iOtAcmpCMNum := FieldByName('OTACMP_NUM').AsInteger;
M_iCmUserSatisfyNum := FieldByName('USERSATISFY_NUM').AsInteger;
end;
Result := True;
except
Result := False;
end;
end;
function TSubOpAmountDealInfo.FillTotalNum(Dt_CurrDate,
TotalDate: TDateTime; Query: TQuery): Boolean;
var
SCurrDate,STotalDate: String;
begin
Result := False;
SCurrDate := FormatDateTime('YYYYMM',Dt_CurrDate);
STotalDate := FormatDatetime('YYYYMM',ToTalDate);
with Query do
try
Close;
DataBaseName := SysDM.DBMain.DatabaseName;
Sql.Text := Format('SELECT SUM(ALL_NUM) TALL_NUM,SUM(ACMP_NUM) TACMP_NUM,'+
'SUM(NOACMP_NUM) TNOACMP_NUM,SUM(OTACMP_NUM) TOTACMP_NUM'+
',SUM(USERSATISFY_NUM) TUSERSATISFY_NUM FROM STAT_MONTH_SERVICE_NUM WHERE '+
'MONTH_ID >= ''%S'' AND MONTH_ID <= ''%S'' AND SERV_CLASS_ID '+
'= ''%S'' AND SERV_CLASS_TYPE = ''%S''' ,[STotalDate,SCurrdate
,M_SubOpID,M_SubOpType]);
Open;
if RecordCount = 0 then
begin
m_iTotalApNum := 0;
m_iACMPApNum := 0;
m_iNoAcmpApNum := 0;
m_iOtAcmpApNum := 0;
m_iApUserSatisfyNum := 0;
end
else
begin
m_iTotalApNum := FieldByName('TALL_NUM').AsInteger;
m_iACMPApNum := FieldByName('TACMP_NUM').AsInteger;
m_iNoAcmpApNum := FieldByName('TNOACMP_NUM').AsInteger;
m_iOtAcmpApNum := FieldByName('TOTACMP_NUM').AsInteger;
m_iApUserSatisfyNum := FieldByName('TUSERSATISFY_NUM').AsInteger;
end;
Result := True;
except
Result := False;
end;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?