📄 proppage3.cpp
字号:
// PropPage3.cpp : implementation file
#include "stdafx.h"
#include "resource.h"
#include "PropPage3.h"
#include "Database.h"
IMPLEMENT_DYNCREATE(CPropPage3, CPropertyPage)
CPropPage3::CPropPage3() : CPropertyPage(CPropPage3::IDD){
COleDateTime timeNow1 = COleDateTime::GetCurrentTime();//获取计算机时钟.
COleDateTimeSpan spanOne;
spanOne.SetDateTimeSpan(1, 0, 0, 0); // 一天的时间.
COleDateTime timeNow2 = timeNow1 - spanOne; //昨天的同一时间.
CString message1;//显示接收到的数据.
message1.Format(_T("%d"), timeNow2.GetYear()); ///显示当前记录条数
m_strYear1_RO = message1;
message1.Format(_T("%d"), timeNow2.GetMonth()); ///显示当前记录条数
m_strMonth1_RO = message1;
message1.Format(_T("%d"), timeNow2.GetDay()); ///显示当前记录条数
m_strDay1_RO = message1;
message1.Format(_T("%d"), timeNow2.GetHour()); ///显示当前记录条数
m_strHour1_RO = _T("8"); //message1;
message1.Format(_T("%d"), timeNow2.GetMinute()); ///显示当前记录条数
m_strMinute1_RO = _T("0"); //message1;
message1.Format(_T("%d"), timeNow1.GetYear()); ///显示当前记录条数
m_strYear2_RO = message1;
message1.Format(_T("%d"), timeNow1.GetMonth()); ///显示当前记录条数
m_strMonth2_RO = message1;
message1.Format(_T("%d"), timeNow1.GetDay()); ///显示当前记录条数
m_strDay2_RO = message1;
message1.Format(_T("%d"), timeNow1.GetHour()); ///显示当前记录条数
m_strHour2_RO = _T("23"); //message1;
message1.Format(_T("%d"), timeNow1.GetMinute()); ///显示当前记录条数
m_strMinute2_RO = _T("59"); //message1;
}
CPropPage3::~CPropPage3(){
}
void CPropPage3::DoDataExchange(CDataExchange* pDX){
CPropertyPage::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST1, m_lcOverview2);
DDX_CBString(pDX, IDC_CHAXUN_COMBO1, m_strYear1_RO);
DDX_CBString(pDX, IDC_CHAXUN_COMBO2, m_strMonth1_RO);
DDX_CBString(pDX, IDC_CHAXUN_COMBO3, m_strDay1_RO);
DDX_CBString(pDX, IDC_CHAXUN_COMBO4, m_strHour1_RO);
DDX_CBString(pDX, IDC_CHAXUN_COMBO5, m_strMinute1_RO);
DDX_CBString(pDX, IDC_CHAXUN_COMBO6, m_strYear2_RO);
DDX_CBString(pDX, IDC_CHAXUN_COMBO7, m_strMonth2_RO);
DDX_CBString(pDX, IDC_CHAXUN_COMBO8, m_strDay2_RO);
DDX_CBString(pDX, IDC_CHAXUN_COMBO9, m_strHour2_RO);
DDX_CBString(pDX, IDC_CHAXUN_COMBO10, m_strMinute2_RO);
}
BEGIN_MESSAGE_MAP(CPropPage3, CPropertyPage)
ON_BN_CLICKED(IDC_BUTTON6, OnOpenData2)
END_MESSAGE_MAP()
BOOL CPropPage3::OnInitDialog() {
CComboBox* pCB1 = (CComboBox*)GetDlgItem(IDC_CHAXUN_COMBO1);//初始化组合框
COleDateTime timeNow = COleDateTime::GetCurrentTime();//获取计算机时钟.
CString message1;//显示接收到的数据.
for(int nCount = 0; nCount <= 10; nCount++){
message1.Format(_T("%d "), timeNow.GetYear()-nCount); ///显示当前记录条数
pCB1->AddString(message1);
}
pCB1 = (CComboBox*)GetDlgItem(IDC_CHAXUN_COMBO2);//初始化组合框
for(nCount = 0; nCount < 12; nCount++){
if ((timeNow.GetMonth() + nCount) <= 12) message1.Format(_T("%d "), timeNow.GetMonth() + nCount); ///显示当前记录条数
else message1.Format(_T("%d "), timeNow.GetMonth() + nCount - 12);
pCB1->AddString(message1);
}
pCB1 = (CComboBox*)GetDlgItem(IDC_CHAXUN_COMBO3);//初始化组合框
for(nCount = 0; nCount < 31; nCount++){
if ((timeNow.GetDay() + nCount) <= 31) message1.Format(_T("%d "), timeNow.GetDay() + nCount); ///显示当前记录条数
else message1.Format(_T("%d "), timeNow.GetDay() + nCount - 31);
pCB1->AddString(message1);
}
pCB1 = (CComboBox*)GetDlgItem(IDC_CHAXUN_COMBO4);//初始化组合框
for(nCount = 0; nCount < 24; nCount++){
if ((timeNow.GetHour() + nCount) < 24) message1.Format(_T("%d "), timeNow.GetHour() + nCount); ///显示当前记录条数
else message1.Format(_T("%d "), timeNow.GetHour() + nCount - 24);
pCB1->AddString(message1);
}
pCB1 = (CComboBox*)GetDlgItem(IDC_CHAXUN_COMBO5);//初始化组合框
for(nCount = 0; nCount < 60; nCount++){
if ((timeNow.GetMinute() + nCount) < 60) message1.Format(_T("%d "), timeNow.GetMinute() + nCount); ///显示当前记录条数
else message1.Format(_T("%d "), timeNow.GetMinute() + nCount - 60);
pCB1->AddString(message1);
}
pCB1 = (CComboBox*)GetDlgItem(IDC_CHAXUN_COMBO6);//初始化组合框
for(nCount = 0; nCount <= 10; nCount++){
message1.Format(_T("%d "), timeNow.GetYear()-nCount); ///显示当前记录条数
pCB1->AddString(message1);
}
pCB1 = (CComboBox*)GetDlgItem(IDC_CHAXUN_COMBO7);//初始化组合框
for(nCount = 0; nCount < 12; nCount++){
if ((timeNow.GetMonth() + nCount) <= 12) message1.Format(_T("%d "), timeNow.GetMonth() + nCount); ///显示当前记录条数
else message1.Format(_T("%d "), timeNow.GetMonth() + nCount - 12);
pCB1->AddString(message1);
}
pCB1 = (CComboBox*)GetDlgItem(IDC_CHAXUN_COMBO8);//初始化组合框
for(nCount = 0; nCount < 31; nCount++){
if ((timeNow.GetDay() + nCount) <= 31) message1.Format(_T("%d "), timeNow.GetDay() + nCount); ///显示当前记录条数
else message1.Format(_T("%d "), timeNow.GetDay() + nCount - 31);
pCB1->AddString(message1);
}
pCB1 = (CComboBox*)GetDlgItem(IDC_CHAXUN_COMBO9);//初始化组合框
for(nCount = 0; nCount < 24; nCount++){
if ((timeNow.GetHour() + nCount) < 24) message1.Format(_T("%d "), timeNow.GetHour() + nCount); ///显示当前记录条数
else message1.Format(_T("%d "), timeNow.GetHour() + nCount - 24);
pCB1->AddString(message1);
}
pCB1 = (CComboBox*)GetDlgItem(IDC_CHAXUN_COMBO10);//初始化组合框
for(nCount = 0; nCount < 60; nCount++){
if ((timeNow.GetMinute() + nCount) < 60) message1.Format(_T("%d "), timeNow.GetMinute() + nCount); ///显示当前记录条数
else message1.Format(_T("%d "), timeNow.GetMinute() + nCount - 60);
pCB1->AddString(message1);
}
CPropertyPage::OnInitDialog();
return TRUE; // return TRUE unless you set the focus to a control
}
void CPropPage3::OnOpenData2(){//打开数据表按钮程序.
UpdateData(); //更新会话框中的数据.
COleDateTime timeNow1,timeNow2,timeNow3;//获取计算机时钟.
int Year1,Month1,Day1,Hour1,Minute1,Year2,Month2,Day2,Hour2,Minute2;
char str[20];
WideCharToMultiByte(CP_ACP,0,m_strYear1_RO,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Year1);//将字符串送给整数变量.
WideCharToMultiByte(CP_ACP,0,m_strMonth1_RO,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Month1);//将字符串送给整数变量.
WideCharToMultiByte(CP_ACP,0,m_strDay1_RO,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Day1);//将字符串送给整数变量.
WideCharToMultiByte(CP_ACP,0,m_strHour1_RO,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Hour1);//将字符串送给整数变量.
WideCharToMultiByte(CP_ACP,0,m_strMinute1_RO,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Minute1);//将字符串送给整数变量.
timeNow1.SetDateTime(Year1,Month1,Day1,Hour1,Minute1,0);//
WideCharToMultiByte(CP_ACP,0,m_strYear2_RO,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Year2);//将字符串送给整数变量.
WideCharToMultiByte(CP_ACP,0,m_strMonth2_RO,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Month2);//将字符串送给整数变量.
WideCharToMultiByte(CP_ACP,0,m_strDay2_RO,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Day2);//将字符串送给整数变量.
WideCharToMultiByte(CP_ACP,0,m_strHour2_RO,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Hour2);//将字符串送给整数变量.
WideCharToMultiByte(CP_ACP,0,m_strMinute2_RO,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Minute2);//将字符串送给整数变量.
timeNow2.SetDateTime(Year2,Month2,Day2,Hour2,Minute2,59);//
//CString message2;
//message2.Format(_T("Year1 = %d "), Year1); AfxMessageBox(message2);//显示接收到的数据.
//message2.Format(_T("Month1 = %d "), Month1); AfxMessageBox(message2);//显示接收到的数据.
//message2.Format(_T("Day1 = %d "), Day1); AfxMessageBox(message2);//显示接收到的数据.
//message2.Format(_T("Hour1 = %d "), Hour1); AfxMessageBox(message2);//显示接收到的数据.
//message2.Format(_T("Minute1 = %d "), Minute1); AfxMessageBox(message2);//显示接收到的数据.
int Station_Num; float Rain_Data1[20],Water_Data1[20],Gate_Data1[20],Dianya_Data1[20],Data1;
for (int i =0; i <= 20; i++) {Rain_Data1[i] = 0; Water_Data1[i] = 0; Gate_Data1[i] = 0.0f; Dianya_Data1[i] = 0;}
CRecordData recordData;
bool bResult = g_DB.SeekDataDB(CEDB_SEEK_BEGINNING, 0);
bResult = g_DB.ReadDataRecord(recordData);
while(bResult){//记录存在。
WideCharToMultiByte(CP_ACP,0,recordData.m_strAddress,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Station_Num);//将字符串送给整数变量.
WideCharToMultiByte(CP_ACP,0,recordData.m_DateTime,-1,str,20,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d-%d-%d %d:%d", &Year1,&Month1,&Day1,&Hour1,&Minute1);//将字符串送给整数变量.
timeNow3.SetDateTime(Year1,Month1,Day1,Hour1,Minute1,0);//
WideCharToMultiByte(CP_ACP,0,recordData.m_strData,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%f", &Data1);//将字符串送给整数变量.
if ((timeNow3 >= timeNow1) && (timeNow3 <= timeNow2)) {
CString message1 = recordData.m_strType;
if (message1 == _T("雨量")) {
Rain_Data1[Station_Num] = Rain_Data1[Station_Num] + Data1; //累计雨量数据.
}
if (message1 == _T("水位")) {
Water_Data1[Station_Num] = Data1; //累计雨量数据.
}
if (message1 == _T("闸位")) {
Gate_Data1[Station_Num] = Data1; //累计雨量数据.
}
if (message1 == _T("电压")) {
Dianya_Data1[Station_Num] = Data1; //累计雨量数据.
}
}
bResult = g_DB.SeekDataDB(CEDB_SEEK_CURRENT, 1);
if(bResult) bResult = g_DB.ReadDataRecord(recordData);
}
DWORD dwStyle = ListView_GetExtendedListViewStyle(m_lcOverview2); //增加栅格线。
dwStyle = LVS_EX_FULLROWSELECT; //增加栅格线。
ListView_SetExtendedListViewStyle (m_lcOverview2,dwStyle); //增加栅格线。
for (int Column=m_lcOverview2.GetHeaderCtrl()->GetItemCount(); Column >= 0; Column--) m_lcOverview2.DeleteColumn(Column);//删除所有的表头。
m_lcOverview2.InsertColumn(0, TEXT("序号"), LVCFMT_LEFT, 40);
m_lcOverview2.InsertColumn(1, TEXT("站号"), LVCFMT_LEFT, 40);
m_lcOverview2.InsertColumn(2, TEXT("测站名称"), LVCFMT_LEFT, 80);
m_lcOverview2.InsertColumn(3, TEXT("雨量"), LVCFMT_LEFT, 60);
m_lcOverview2.InsertColumn(4, TEXT("水位"), LVCFMT_LEFT, 60);
m_lcOverview2.InsertColumn(5, TEXT("闸位"), LVCFMT_LEFT, 60);
m_lcOverview2.InsertColumn(6, TEXT("电压"), LVCFMT_LEFT, 60);
int nCount = 0; CRecordStation recordStation;
m_lcOverview2.DeleteAllItems();//清除所有的项目。
bResult = g_DB.SeekStationDB(CEDB_SEEK_BEGINNING, 0);
bResult = g_DB.ReadStationRecord(recordStation);
while(bResult){//记录存在。
m_lcOverview2.InsertItem(nCount, recordStation.m_strNumber);
m_lcOverview2.SetItemText(nCount,1,recordStation.m_strAddress);
m_lcOverview2.SetItemText(nCount,2,recordStation.m_strName);
WideCharToMultiByte(CP_ACP,0,recordStation.m_strAddress,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Station_Num);//将字符串送给整数变量.
CString message1;int Station_Num1;
WideCharToMultiByte(CP_ACP,0,recordStation.m_strRainStation,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Station_Num1);//将字符串送给整数变量.
if (Station_Num1 == 1) message1.Format(_T("%.1f"), Rain_Data1[Station_Num]);
else message1 = _T(" ");
m_lcOverview2.SetItemText(nCount,3,message1);
WideCharToMultiByte(CP_ACP,0,recordStation.m_strWaterStation,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Station_Num1);//将字符串送给整数变量.
if (Station_Num1 == 1) message1.Format(_T("%.2f"), Water_Data1[Station_Num]);
else message1 = _T(" ");
m_lcOverview2.SetItemText(nCount,4,message1);
WideCharToMultiByte(CP_ACP,0,recordStation.m_strKaiduStation,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
sscanf(str, "%d", &Station_Num1);//将字符串送给整数变量.
if (Station_Num1 == 1) message1.Format(_T("%.2f"), Gate_Data1[Station_Num]);
else message1 = _T(" ");
m_lcOverview2.SetItemText(nCount,5,message1);
if (Dianya_Data1[Station_Num] != 0) message1.Format(_T("%.2f"), Dianya_Data1[Station_Num]);
else message1 = _T(" ");
m_lcOverview2.SetItemText(nCount,6,message1);
nCount++;//报表增加一行。
bResult = g_DB.SeekStationDB(CEDB_SEEK_CURRENT, 1);
if(bResult) bResult = g_DB.ReadStationRecord(recordStation);
}
m_lcOverview2.InsertItem(nCount, _T("8"));
m_lcOverview2.SetItemText(nCount,1,_T("2"));
m_lcOverview2.SetItemText(nCount,2,_T("中继站"));
CString message1;
if (Dianya_Data1[2] != 0) message1.Format(_T("%.2f"), Dianya_Data1[2]); //列中继电站.
else message1 = _T(" ");
m_lcOverview2.SetItemText(nCount,6,message1); //列中继电站.
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -