📄 total.cpp
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#pragma hdrstop
#include "Total.h"
#include "datetool.h"
#include "inqdate.h"
#include "editdlg.h"
#include "option.h"
#include "bdbf.h"
#include "dido.h"
#include "dynamic.h"
#include "servermodule.h"
#include "gridtool.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
//报表
typedef struct tagTOTALREPORT{
int nRow,nCol; //行数,列数
char szRowField[15]; //行比较的字段名
char szColField[15]; //列比较的字段名
char szTotalField[15]; //统计内容的字段名(szTotalField[0]=0 =>统计数量)
char szTitle[81]; //报表标题
char szCondition[81];//报表条件
char szTextTitle[21];//固定行列交叉处标题
void *pRowFix,*pColFix; //报表固定行
void *pTotal; //报表
BYTE nRowType; //行数据类型
BYTE nRowStatus; //行数据比较
BYTE nColType; //列数据类型
BYTE nColStatus; //列数据比较
BYTE nTotalType; //统计表数据类型
}TOTALREPORT;
//报表固定行列(分界值为DWORD型)
typedef struct tagFIX_DWORD{
char szTitle[20]; //行列标题
DWORD nDivision; //分界值
}FIX_DWORD,* PFIX_DWORD;
//报表固定行列(分界值为TDate型)
typedef struct tagFIX_TDATETIME{
char szTitle[20]; //行列标题
TDateTime tDivision; //分界值
}FIX_TDATETIME,* PFIX_TDATETIME;
//报表固定行列(分界值为String型)
typedef struct tagFIX_STRING{
char szTitle[21]; //行列标题
char szDivision[25]; //分界值
}FIX_STRING,* PFIX_STRING;
#define TOTALDATA_EQUAL 0 //统计数据相等
#define TOTALDATA_INC 1 //统计数据递增
#define TOTALDATA_DEC 1 //统计数据递减
//获取设置统计日期
static int GetSetTotalDate(DWORD &pDate1,DWORD &pDate2,int nMode);
static int GetTotalDate(DWORD *pDate1,DWORD *pDate2);
static int SetTotalDate(DWORD nDate1,DWORD nDate2);
//设置统计日期
static int SetDayToTotal(TComponent* Owner);
//设置统计月份
static int SetMonthToTotal(TComponent* Owner);
//设置统计季度
static int SetQuarterToTotal(TComponent* Owner);
//设置统计年度
static int SetYearToTotal(TComponent* Owner);
//编辑统计日期
static int ReworkTotalCondition(TComponent* Owner,int nMode);
//设置入场报表
static int SetInParkFluxReport(TOTALREPORT *pReport);
//设置出场报表
static int SetOutParkFluxReport(TOTALREPORT *pReport);
//设置停车收费报表
static int SetParkPriceReport(TOTALREPORT *pReport);
//设置用户交费报表
static int SetUserPaidReport(TOTALREPORT *pReport);
//设置日期固定行
static int SetDateFix(FIX_TDATETIME *pFix,DWORD nDate1,DWORD nDate2,
int nMode,int nRow);
//设置车道固定行
static int SetRoadwayFix(FIX_DWORD *pFix,void *pHead,int nRow,int nType);
//设置用户类型固定行
static int SetPriceFix(FIX_DWORD *pFix,void *pHead,int nRow);
//获取类型nType车道数量
static int GetRoadNumWithType(void *pHead,int nType);
//统计一个报表
static int TotalOneReport(TDataSet *pQuery,TOTALREPORT *pReport);
//获取统计位置
static int GetTotalXY(void *pFix,int nFix,char *pszField,int nDataType,int nDataStatus);
//统计数据
static int AddTotalData(void *pTotal,char *pszField,int nDataType,
int nCol,int nRow,int x,int y);
//显示一个报表
static void ShowOneReport(TTotalFrame *pFrame,TOTALREPORT *pReport);
//获取固定行标题
static char *GetFixTitle(void *pFix,int nDataType,int nIndex);
//获取统计单元内容
static char *GetTotalText(void *pTotal,int nDataType,int nCol,int nRow,
int x,int y, char *pszText);
//获取行合计内容
static char *GetTotalRowSumText(void *pTotal,int nDataType,
int nCol,int nRow, int y,char *pszText);
//获取列合计内容
static char *GetTotalColSumText(void *pTotal,int nDataType,
int nCol,int nRow, int x,char *pszText);
//获取总计内容
static char *GetTotalSumText(void *pTotal,int nDataType,
int nCol,int nRow,char *pszText);
//设置格栅单元宽度
static void SetGridWidth(TStringGrid *pGrid);
//设置格栅单元内容
static void SetGridCellText(TStringGrid *pGrid,char *pszText,int nCol,int nRow);
//根据统计日期查询一个表
static int QueryTableWithTotalDate(TADOQuery *pQuery,char *pszTable,char *pszField);
//释放为报表分配的内存
static void FreeOneReport(TOTALREPORT *pReport);
//---------------------------------------------------------------------------
__fastcall TTotalFrame::TTotalFrame(TComponent* Owner)
: TFrame(Owner)
{
}
void __fastcall TTotalFrame::m_TextGridDrawCell(TObject *Sender, int ACol,
int ARow, TRect &Rect, TGridDrawState State)
{
if(State.Contains(gdFixed)){//显示格栅标题
if(ACol>0)//列标题
SetGridTextColor(Sender,ACol,ARow,Rect,clRed,DT_CENTER);
else if(ARow>0)//行标题
SetGridTextColor(Sender,ACol,ARow,Rect,clBlue,DT_CENTER);
else //行列标题交叉处
SetGridTextColor(Sender,ACol,ARow,Rect,-1,DT_CENTER);
}
else //设置格栅文字颜色,文字居中
SetGridTextColor(Sender,ACol,ARow,Rect,-1,DT_RIGHT);
}
//获取设置分析统计类型
int GetSetTotalMode(int nKind)
{
static BYTE nMode=0;
int n;
n = nMode;
if(nKind>0)nMode=nKind;
return(n);
}
//获取设置统计日期
int GetSetTotalDate(DWORD &pDate1,DWORD &pDate2,int nMode)
{
static DWORD nInqDate1,nInqDate2;
if(nMode)
{ nInqDate1 = pDate1; nInqDate2=pDate2;}
else {
pDate1 = nInqDate1;
pDate2 = nInqDate2;
}
return(nInqDate1);
}
//获取统计日期
int GetTotalDate(DWORD *pDate1,DWORD *pDate2)
{
DWORD m,n;
GetSetTotalDate(m,n,0);//获取设置统计日期
if(pDate1!=NULL)*pDate1=m;
if(pDate2!=NULL)*pDate2=n;
return(m);
}
//设置统计日期
int SetTotalDate(DWORD nDate1,DWORD nDate2)
{
GetSetTotalDate(nDate1,nDate2,TRUE);//获取设置统计日期
return(nDate1);
}
//获取统计条件
char *GetTotalText(char *pszBuf)
{
static char *pszTitle[]={
"统计日期 %s~%s","%04d年%1d月份(%s~%s)",
"%04d年第%1d季度(%s~%s)","%04d年度(%s~%s)"
};
DWORD nDate1,nDate2;
char szDate1[15],szDate2[15];
int nMode,nYear,nMonth,nDay;
GetTotalDate(&nDate1,&nDate2);
nMode = GetTotalMode();
DWORDToDateStr(szDate1,nDate1);
DWORDToDateStr(szDate2,nDate2);
GetDateOnDWORD(nDate1,&nYear,&nMonth,&nDay);
if(nMode==TOTAL_DAY) //日统计
wsprintf(pszBuf,pszTitle[0],szDate1,szDate2);
else if(nMode==TOTAL_MONTH) //月统计
wsprintf(pszBuf,pszTitle[1],nYear,nMonth,szDate1,szDate2);
else if(nMode==TOTAL_QUARTER){ //季统计
nMonth = (nMonth-1)/3+1;
wsprintf(pszBuf,pszTitle[2],nYear,nMonth,szDate1,szDate2);
}
else if(nMode==TOTAL_YEAR) //年统计
wsprintf(pszBuf,pszTitle[3],nYear,szDate1,szDate2);
else pszBuf[0];
return(pszBuf);
}
//设置统计日期
int SetDayToTotal(TComponent* Owner)
{
int rc;
DWORD nDate1,nDate2;
GetTotalDate(&nDate1,&nDate2);
rc=ReworkDate(Owner,&nDate1,&nDate2);
if(rc) //设置日期范围
SetTotalDate(nDate1,nDate2);
return(rc);
}
//设置统计月份
int SetMonthToTotal(TComponent* Owner)
{
static char pszText[]="请选择统计年月份";
int rc;
EDITPARAM pe;
DWORD nDate1,nDate2;
GetTotalDate(&nDate1,&nDate2);
ZeroMemory(&pe,sizeof(pe));
pe.pszTitle=GetMainTitle();
pe.pszText=pszText;
pe.pszBuf=(char *)&nDate1;
pe.cbSize=sizeof(nDate1);
pe.nFlag=10; //日期
rc=EditTextStr(Owner,&pe);
if(rc){ //设置日期范围
GetMonthDate(nDate1,&nDate1,&nDate2);
SetTotalDate(nDate1,nDate2);
}
return(rc);
}
//设置统计季度
int SetQuarterToTotal(TComponent* Owner)
{
static char pszText[]="请选择统计季度所在的日期";
int rc;
EDITPARAM pe;
DWORD nDate1,nDate2;
GetTotalDate(&nDate1,&nDate2);
ZeroMemory(&pe,sizeof(pe));
pe.pszTitle=GetMainTitle();
pe.pszText=pszText;
pe.pszBuf=(char *)&nDate1;
pe.cbSize=sizeof(nDate1);
pe.nFlag=10; //日期
rc=EditTextStr(Owner,&pe);
if(rc){ //设置日期范围
GetQuarterDate(nDate1,&nDate1,&nDate2);
SetTotalDate(nDate1,nDate2);
}
return(rc);
}
//设置统计年度
int SetYearToTotal(TComponent* Owner)
{
static char pszText[]="请选择统计年份";
int rc;
EDITPARAM pe;
DWORD nDate1,nDate2;
GetTotalDate(&nDate1,&nDate2);
ZeroMemory(&pe,sizeof(pe));
pe.pszTitle=GetMainTitle();
pe.pszText=pszText;
pe.pszBuf=(char *)&nDate1;
pe.cbSize=sizeof(nDate1);
pe.nFlag=10; //日期
rc=EditTextStr(Owner,&pe);
if(rc){ //设置日期范围
GetYearDate(nDate1,&nDate1,&nDate2);
SetTotalDate(nDate1,nDate2);
}
return(rc);
}
//编辑统计日期
int ReworkTotalCondition(TComponent* Owner,int nMode)
{
int rc;
if(nMode==TOTAL_DAY) //日统计
rc= SetDayToTotal(Owner);
else if(nMode==TOTAL_MONTH) //月统计
rc=SetMonthToTotal(Owner);
else if(nMode==TOTAL_QUARTER) //季统计
rc=SetQuarterToTotal(Owner);
else if(nMode==TOTAL_YEAR) //年统计
rc=SetYearToTotal(Owner);
else rc=FALSE;
if(rc) //设置统计条件
SetTotalMode(nMode);
return(rc);
}
//释放为报表分配的内存
void FreeOneReport(TOTALREPORT *pReport)
{
if(pReport->pTotal!=NULL){
GlobalFree(pReport->pTotal);
pReport->pTotal=NULL;
}
}
//设置入场报表
int SetInParkFluxReport(TOTALREPORT *pReport)
{
static char pszColField[]="INROADNO",
pszRowField[]="INTIME",
pszTitle[]="车辆入场流量统计",
pszTextTitle[]="日期";
DWORD nDate1,nDate2;
int nRow,nCol,nMode;
int nTotalSize,nRowFixSize,nColFixSize;
void *pHead,*pTotal,*pColFix,*pRowFix;
ZeroMemory(pReport,sizeof(TOTALREPORT));
GetTotalDate(&nDate1,&nDate2);
nMode = GetTotalMode();
if(nMode == TOTAL_DAY || nMode==TOTAL_MONTH)
nRow = GetDateDiff(nDate2,nDate1)+1;
else if(nMode == TOTAL_QUARTER)nRow=3;
else if(nMode == TOTAL_YEAR)nRow=12;
else nRow=0;
pHead = GetRoadwayList();
nCol = GetRoadNumWithType(pHead,ROADTYPE_IN); //获取进入车道数量
nTotalSize=sizeof(int)*nCol*nRow;
nRowFixSize = nRow*sizeof(FIX_TDATETIME);
nColFixSize = nCol*sizeof(FIX_DWORD);
if(nRow>0 && nCol>0){
pTotal = (void *)GlobalAlloc(GPTR,nTotalSize+nRowFixSize+nColFixSize);
if(pTotal==NULL)//显示内存不够信息
ShowNotMemory(GetMainTitle());
}
else pTotal=NULL;
if(pTotal==NULL)return(FALSE);
pRowFix = ((char *)pTotal+nTotalSize);
pColFix = ((char *)pTotal+nTotalSize+nRowFixSize);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -