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

📄 daystaticspage.cpp

📁 IP电话计费管理系统本地版
💻 CPP
字号:
// DayStaticsPage.cpp : implementation file
//分类统计

#include "stdafx.h"
#include "IPCount.h"
#include "DayStaticsPage.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define PERSON_INFO 30
/////////////////////////////////////////////////////////////////////////////
// CDayStaticsPage property page

IMPLEMENT_DYNCREATE(CDayStaticsPage, CPropertyPage)

CDayStaticsPage::CDayStaticsPage() : CPropertyPage(CDayStaticsPage::IDD)
{
	//{{AFX_DATA_INIT(CDayStaticsPage)
	m_strStartTime2 = COleDateTime::GetCurrentTime();
	m_strEndTime2 = COleDateTime::GetCurrentTime();
	//}}AFX_DATA_INIT
	nDiffGridLine=0;
}

CDayStaticsPage::~CDayStaticsPage()
{
}

void CDayStaticsPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDayStaticsPage)
	DDX_Control(pDX, IDC_MSFLEXGRID_DAY_STATICS, m_DayGrid);
	DDX_DateTimeCtrl(pDX, IDC_DATETIME_START, m_strStartTime2);
	DDX_DateTimeCtrl(pDX, IDC_DATETIME_START2, m_strEndTime2);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDayStaticsPage, CPropertyPage)
	//{{AFX_MSG_MAP(CDayStaticsPage)
	ON_BN_CLICKED(IDC_BUTTON_DIFF_COUNT, OnDiffCount)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDayStaticsPage message handlers

BOOL CDayStaticsPage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_DayGrid.SetTextArray(0,"日期");
	m_DayGrid.SetTextArray(1,"本地");
	m_DayGrid.SetTextArray(2,"国内");
	m_DayGrid.SetTextArray(3,"港台");
	m_DayGrid.SetTextArray(4,"美加");
	m_DayGrid.SetTextArray(5,"国际");
	m_DayGrid.SetTextArray(6,"总基本话费");
	m_DayGrid.SetTextArray(7,"总附加费");
	m_DayGrid.SetTextArray(8,"总话费");

	m_DayGrid.SetColWidth(0,1500);
	m_DayGrid.SetColWidth(5,1200);
	m_DayGrid.SetColWidth(6,1300);
	m_DayGrid.SetColWidth(7,1200);
	m_DayGrid.SetColWidth(8,1200);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDayStaticsPage::OnDiffCount() 
{
	// TODO: Add your control notification handler code here
	for (int nGridCol=0;nGridCol<9;nGridCol++)
		m_DayGrid.SetTextMatrix(1,nGridCol,""); 
	ReadFromDb();
}

void CDayStaticsPage::ReadFromDb()
{
	 UpdateData(TRUE);
     SQLHENV henv = NULL;
     SQLHDBC hdbc = NULL;
     BOOL bIsConnected = FALSE;
     SQLHSTMT hstmt = NULL;
     SQLRETURN rc;
     SWORD    sMsgNum = 0;
     SDWORD   pfNative=0;
     strStartTime2 = m_strStartTime2.Format(_T("%Y-%m-%d") );
     strEndTime2 = m_strEndTime2.Format(_T("%Y-%m-%d") );
     
if (SQL_SUCCESS == (rc =::SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv)))
{
  if (SQL_SUCCESS == (rc = ::SQLSetEnvAttr(henv,SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3,SQL_IS_INTEGER)))
  {
	  if (SQL_SUCCESS == (rc =::SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc)))
	  {
		   rc = ::SQLConnect(hdbc,(SQLCHAR*)"IPCount",SQL_NTS,(SQLCHAR*)"", SQL_NTS, (SQLCHAR*)"", SQL_NTS);
	       if ((SQL_SUCCESS == rc)|| (SQL_SUCCESS_WITH_INFO == rc))
		   {
               bIsConnected = TRUE;
               if (SQL_SUCCESS == (rc =::SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt)))
			   {
				    CString strChar='\'';
					CString strSQL="";
					CString strChar2="#";
					strSQL="SELECT * FROM huafei where [日期] between #"+strStartTime2+"# and #"+strEndTime2+strChar2;
                    LPCSTR szSQL = strSQL;

                    if (SQL_SUCCESS == (rc = ::SQLPrepare(hstmt,(unsigned char*)szSQL, SQL_NTS)))
					{
                        if (SQL_SUCCESS == (rc = ::SQLExecute(hstmt)))
						{
		                    SDWORD cb;
							char szStreameNum[PERSON_INFO]="";
							char szOper[PERSON_INFO]="";
							char szTelIndex[PERSON_INFO]="";//线号
	                        char szCalledNum[PERSON_INFO]="";//被叫
	                        char szDay[PERSON_INFO]="";//日期
	                        char szTLen[PERSON_INFO]="";//时长
                            char szFeeRate[PERSON_INFO]="";//费率
							char szCount[PERSON_INFO]="";//话费 
							char szAreaName[PERSON_INFO]="";
							char szExtraTotal[PERSON_INFO]="";
		                    SQLBindCol(hstmt,5,SQL_C_CHAR,szDay,PERSON_INFO,&cb);
		                    SQLBindCol(hstmt,6,SQL_C_CHAR,szTLen,PERSON_INFO,&cb);
		                    SQLBindCol(hstmt,7,SQL_C_CHAR,szFeeRate,PERSON_INFO,&cb);
		                    SQLBindCol(hstmt,8,SQL_C_CHAR,szCount,PERSON_INFO,&cb);
		                    SQLBindCol(hstmt,9,SQL_C_CHAR,szAreaName,PERSON_INFO,&cb);
							SQLBindCol(hstmt,10,SQL_C_CHAR,szExtraTotal,PERSON_INFO,&cb);
                            rc = SQLFetch(hstmt);

	                     	int nCountArea[6];CString strCountArea[6];
							double fExtraTotal=0;
							double nTotalCount=0;CString strTotalCount="";
							CString strYMD="";
							
							for(int nTemp=0;nTemp<6;nTemp++)
							{
							    nCountArea[nTemp]=0;
								strCountArea[nTemp]="";
							}
                            while (SQL_SUCCESS == rc)
							{
								 if(strcmp(szAreaName,"本地")==0)
								 {
									 nCountArea[0]++;
									 strCountArea[0].Format("%d",nCountArea[0]);
									 m_DayGrid.SetTextMatrix(1,1,strCountArea[0]);
								 }
								 else if(strcmp(szAreaName,"国内")==0)
								 {
									 nCountArea[1]++;
									 strCountArea[1].Format("%d",nCountArea[1]);
									 m_DayGrid.SetTextMatrix(1,2,strCountArea[1]);
								 }
								 else if(strcmp(szAreaName,"港台")==0)
								 {
									 nCountArea[2]++;
									 strCountArea[2].Format("%d",nCountArea[2]);
									 m_DayGrid.SetTextMatrix(1,3,strCountArea[2]);
								 }
								 else if(strcmp(szAreaName,"美加")==0)
								 {
									 nCountArea[3]++;
									 strCountArea[3].Format("%d",nCountArea[3]);
									 m_DayGrid.SetTextMatrix(1,4,strCountArea[3]);
								 }	
								 else if(strcmp(szAreaName,"国际")==0)
								 {
									 nCountArea[4]++;
									 strCountArea[4].Format("%d",nCountArea[4]);
									 m_DayGrid.SetTextMatrix(1,5,strCountArea[4]);
								 }	
                                 nTotalCount=nTotalCount+atof(szCount);
                                 fExtraTotal+=atof(szExtraTotal);

								 strcpy((char *)szStreameNum,LPCTSTR(""));
 								 strcpy((char *)szOper,LPCTSTR(""));
								 strcpy((char *)szTelIndex,LPCTSTR(""));
                                 strcpy((char *)szCalledNum,LPCTSTR(""));
								 strcpy((char *)szDay,LPCTSTR(""));
								 strcpy((char *)szTLen,LPCTSTR(""));
                                 strcpy((char *)szFeeRate,LPCTSTR(""));
								 strcpy((char *)szCount,LPCTSTR(""));
								 strcpy((char *)szAreaName,LPCTSTR(""));
								 strcpy((char *)szExtraTotal,LPCTSTR(""));
			                     rc = SQLFetch(hstmt);
							}
 							strTotalCount.Format("%.2f",nTotalCount);//打折不成
                            CString strExtraTotal="";
							strExtraTotal.Format("%.2f",fExtraTotal);
							CString strBTotalCount="";
							strBTotalCount.Format("%.2f",atof(strTotalCount)-atof(strExtraTotal));
							m_DayGrid.SetTextMatrix(1,6,strBTotalCount);
							m_DayGrid.SetTextMatrix(1,7,strExtraTotal);
							m_DayGrid.SetTextMatrix(1,8,strTotalCount);
						}

					}	
			   }
     }
    }
   }
  }

 if (henv)
 {
  if (hdbc)
  {
   if (bIsConnected)
   {
    if (hstmt)
	{
     ::SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
	}
     ::SQLDisconnect(hdbc);
     bIsConnected = FALSE;
   }
   ::SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
   hdbc = NULL;
  }
  ::SQLFreeHandle(SQL_HANDLE_ENV, henv);
  henv = NULL;
 }
}

⌨️ 快捷键说明

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