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

📄 proppage2.cpp

📁 使用C开发的嵌入式平台软件源程序.有串行通讯、数据库入库等功能。
💻 CPP
字号:

#include "stdafx.h"
#include "resource.h"
#include "PropPage2.h"
#include "Database.h"
#include "前置机.h"

IMPLEMENT_DYNCREATE(CPropPage2, CPropertyPage)

CPropPage2::CPropPage2() : CPropertyPage(CPropPage2::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"), 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;
}

CPropPage2::~CPropPage2(){
}

void CPropPage2::DoDataExchange(CDataExchange* pDX){
	CPropertyPage::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_LIST2, m_lcOverview1);
	DDX_CBString(pDX, IDC_XIUGAI_COMBO1, m_strName_RO);
	DDX_CBString(pDX, IDC_XIUGAI_COMBO2, m_strType_RO);
	DDX_CBString(pDX, IDC_XIUGAI_COMBO3, m_strYear1_RO);
	DDX_CBString(pDX, IDC_XIUGAI_COMBO4, m_strMonth1_RO);
	DDX_CBString(pDX, IDC_XIUGAI_COMBO5, m_strDay1_RO);
	DDX_CBString(pDX, IDC_XIUGAI_COMBO6, m_strYear2_RO);
	DDX_CBString(pDX, IDC_XIUGAI_COMBO7, m_strMonth2_RO);
	DDX_CBString(pDX, IDC_XIUGAI_COMBO8, m_strDay2_RO);
	DDX_Text(pDX, IDE_RO_PASSWORD, m_PassWord_RO);
	DDX_Text(pDX, IDE_RO_ADDRESS, m_strDateTime_RO);
	DDV_MaxChars(pDX, m_strDateTime_RO, 25);//不能小于二十,否则翻页时会出错.
	DDX_Text(pDX, IDE_RO_NAME, m_strData_RO);
	DDV_MaxChars(pDX, m_strData_RO, 20);
}

BEGIN_MESSAGE_MAP(CPropPage2, CPropertyPage)
	ON_BN_CLICKED(IDC_BUTTON7, OnOpenData1)
	ON_BN_CLICKED(IDC_BUTTON8, OnUpdate)
	ON_BN_CLICKED(IDC_BUTTON9, OnDelete)
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST2, ShowNotification)//点击了列表中的任一行.
END_MESSAGE_MAP()

BOOL CPropPage2::OnSetActive() {
	 m_PassWord_RO = _T("");
	 UpdateData(FALSE);//刷新屏幕.
	 return CPropertyPage::OnSetActive();
}

void CPropPage2::OnUpdate() { //更新按钮.
	 UpdateData(); //更新会话框中的数据.
     //AfxMessageBox(m_PassWord_RO);
	 CRecordPassWord recordPassword; //读取密码.
 	 g_DB.SeekPassWordDB(CEDB_SEEK_BEGINNING, 0);
	 g_DB.ReadPassWordRecord(recordPassword);
	 if (m_PassWord_RO != recordPassword.m_strData) return;//读取密码.

	 CRecordData record; CRecordSend recordSend;
	 int nCount = 0; char str[20]; float OldData,NewData; CString message1;
  	 bool bResult = g_DB.SeekDataDB(CEDB_SEEK_BEGINNING, 0);
	 while(bResult) {
	    if(bResult) bResult = g_DB.ReadDataRecord(record);
	    if(bResult){//记录存在。	
		if((record.m_strName == m_strName_RO) && (record.m_DateTime == m_strDateTime_RO) && (record.m_strType == m_strType_RO)){
                CString m_strAddress_1 = record.m_strAddress;
                WideCharToMultiByte(CP_ACP,0,record.m_strData,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
	            sscanf(str, "%f", &OldData);//将字符串送给整数变量.
  	            WideCharToMultiByte(CP_ACP,0,m_strData_RO,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
	            sscanf(str, "%f", &NewData);//将字符串送给整数变量.
                //AfxMessageBox(_T("Update"));
	            CEPROPVAL *prgPropVal = record.NewPropVal();
	            record.m_strData = m_strData_RO;
	            g_DB.UpdateDataRecord(record);//永久存贮数据.
				if (fabs(NewData - OldData) > 0) { //数据有改变了吗??浮点数的绝对值.
                recordSend.m_strAddress =  m_strAddress_1;
                recordSend.m_strName =  m_strName_RO;
                recordSend.m_DateTime =  m_strDateTime_RO;
                recordSend.m_strType =  m_strType_RO + _T("修改");
				message1.Format(_T("%.2f"), NewData);
                if (m_strType_RO == _T("雨量")) message1.Format(_T("%.2f"), NewData - OldData); ///显示当前记录条数
                recordSend.m_strData =  message1;
				g_DB.AddSendRecord(recordSend);}//永久存贮数据.		
		}
		}
		bResult = g_DB.SeekDataDB(CEDB_SEEK_CURRENT, 1);
	 }
}

void CPropPage2::OnDelete() { //删除按钮.
	 UpdateData(); //更新会话框中的数据.
      //AfxMessageBox(m_PassWord_RO);
	 CRecordPassWord recordPassword; //读取密码.
 	 g_DB.SeekPassWordDB(CEDB_SEEK_BEGINNING, 0);
	 g_DB.ReadPassWordRecord(recordPassword);
	 if (m_PassWord_RO != recordPassword.m_strData) return;//读取密码.

	 CRecordData record;  CRecordSend recordSend;
	int nCount = 0;  char str[20]; float NewData; CString message1;
  	bool bResult = g_DB.SeekDataDB(CEDB_SEEK_BEGINNING, 0);
	while(bResult) {
	    if(bResult) bResult = g_DB.ReadDataRecord(record);
	    if(bResult){//记录存在。	
		if((record.m_strName == m_strName_RO) && (record.m_DateTime == m_strDateTime_RO) && (record.m_strType == m_strType_RO) && (record.m_strData == m_strData_RO)){
	            g_DB.DeleteDataRecord(0);			
  	            WideCharToMultiByte(CP_ACP,0,m_strData_RO,-1,str,10,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
	            sscanf(str, "%f", &NewData);//将字符串送给整数变量.
				if (NewData > 0) {
                recordSend.m_strAddress =  record.m_strAddress;
                recordSend.m_strName =  m_strName_RO;
                recordSend.m_DateTime =  m_strDateTime_RO;
                recordSend.m_strType =  m_strType_RO + _T("修改");
 	            message1.Format(_T("%.2f"), -NewData); ///显示当前记录条数
                recordSend.m_strData =  message1;
				g_DB.AddSendRecord(recordSend);}//永久存贮数据.		
		}
		}
		bResult = g_DB.SeekDataDB(CEDB_SEEK_CURRENT, 1);
	}
}

void CPropPage2::OnOpenData1(){//打开数据表按钮程序.
	 UpdateData(); //更新会话框中的数据.
 	 COleDateTime timeNow1,timeNow2,timeNow3;//获取计算机时钟.
	 int Year1,Month1,Day1,Hour1,Minute1,Year2,Month2,Day2;
     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);//将字符串送给整数变量.
	 timeNow1.SetDateTime(Year1,Month1,Day1,0,0,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);//将字符串送给整数变量.
	 timeNow2.SetDateTime(Year2,Month2,Day2,23,59,59);//
     CRecordData record;
	 DWORD dwStyle = ListView_GetExtendedListViewStyle(m_lcOverview1); //增加栅格线。
	 dwStyle = LVS_EX_FULLROWSELECT; //增加栅格线。
	 ListView_SetExtendedListViewStyle (m_lcOverview1,dwStyle); //增加栅格线。
	 for (int Column=m_lcOverview1.GetHeaderCtrl()->GetItemCount(); Column >= 0; Column--) m_lcOverview1.DeleteColumn(Column);//删除所有的表头。
	 m_lcOverview1.InsertColumn(0, TEXT("站号"), LVCFMT_LEFT, 40);
	 m_lcOverview1.InsertColumn(1, TEXT("站名"), LVCFMT_LEFT, 100);
	 m_lcOverview1.InsertColumn(2, TEXT("时间"), LVCFMT_LEFT, 130);
	 m_lcOverview1.InsertColumn(3, TEXT("类型"), LVCFMT_LEFT, 70);
	 m_lcOverview1.InsertColumn(4, TEXT("数据"), LVCFMT_LEFT, 80);
	 m_lcOverview1.DeleteAllItems();//清除所有的项目。
	 int nCount = 0;
  	 bool bResult = g_DB.SeekDataDB(CEDB_SEEK_END, 0);
	//for(int nCount = 0; nCount <= 100; nCount++){
	 while(bResult) {
	    if(bResult) bResult = g_DB.ReadDataRecord(record);
	    if(bResult){//记录存在。	m_strName_RO
 		//WideCharToMultiByte(CP_ACP,0,m_strName_RO,-1,str,20,NULL,NULL);//实现UNICODE字符到ANSI字符的转换.
		if((m_strName_RO == _T("(全部)")) || (record.m_strName == m_strName_RO)){//有条件的列表.
 		if((m_strType_RO == _T("(全部)")) || (record.m_strType == m_strType_RO)){//有条件的列表.
		WideCharToMultiByte(CP_ACP,0,record.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);//
		if ((timeNow3 >= timeNow1) && (timeNow3 <= timeNow2)) { //如果所查数据时间在指定时间范围之内.
		m_lcOverview1.InsertItem(nCount, record.m_strAddress);
		m_lcOverview1.SetItemText(nCount,1,record.m_strName);
		m_lcOverview1.SetItemText(nCount,2,record.m_DateTime);
		m_lcOverview1.SetItemText(nCount,3,record.m_strType);
		m_lcOverview1.SetItemText(nCount,4,record.m_strData);
		nCount++;
		}
		}
		}
		}
		bResult = g_DB.SeekDataDB(CEDB_SEEK_CURRENT, -1);
	}
}

BOOL CPropPage2::OnInitDialog(){
	//CDialog::OnInitDialog();
	m_PassWord_RO = _T("");//读取站名.
	m_strName_RO = _T("(全部)");//读取站名.
	m_strType_RO = _T("(全部)");//读取站名.
	CComboBox* pCB1=(CComboBox*)GetDlgItem(IDC_XIUGAI_COMBO1);//初始化组合框
	pCB1->AddString(_T("(全部)"));
	CRecordStation record;
 	bool bResult = g_DB.SeekStationDB(CEDB_SEEK_BEGINNING, 0);
	bResult = g_DB.ReadStationRecord(record);
	while(bResult){	
 	    pCB1->AddString(record.m_strName);
		bResult = g_DB.SeekStationDB(CEDB_SEEK_CURRENT, 1);
		if(bResult) bResult = g_DB.ReadStationRecord(record);
	}
	pCB1->AddString(_T("中继站"));

	CComboBox* pCB2=(CComboBox*)GetDlgItem(IDC_XIUGAI_COMBO2);//初始化组合框
	pCB2->AddString(_T("(全部)"));
	pCB2->AddString(_T("雨量"));
	pCB2->AddString(_T("水位"));
	pCB2->AddString(_T("闸位"));
	pCB2->AddString(_T("电压"));
	pCB2->AddString(_T("告警"));

	pCB1 = (CComboBox*)GetDlgItem(IDC_XIUGAI_COMBO3);//初始化组合框
	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_XIUGAI_COMBO4);//初始化组合框
	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_XIUGAI_COMBO5);//初始化组合框
	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_XIUGAI_COMBO6);//初始化组合框
	for(nCount = 0; nCount <= 10; nCount++){
 	        message1.Format(_T("%d "), timeNow.GetYear()-nCount); ///显示当前记录条数
		    pCB1->AddString(message1);
	}
	pCB1 = (CComboBox*)GetDlgItem(IDC_XIUGAI_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_XIUGAI_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);
	}
	CDialog::OnInitDialog();
	return TRUE; 
}

void CPropPage2::ShowNotification(){
	 //AfxMessageBox(_T("点击了List控件"));///显示当前记录条数
	 int index = m_lcOverview1.GetNextItem(-1,LVNI_SELECTED);
	 m_strName_RO = m_lcOverview1.GetItemText(index,1);//读取站名.
	 m_strDateTime_RO = m_lcOverview1.GetItemText(index,2);//读取时间.
	 m_strType_RO = m_lcOverview1.GetItemText(index,3);//读取类型.
 	 m_strData_RO = m_lcOverview1.GetItemText(index,4);//读取数据.
	 UpdateData(FALSE);//刷新屏幕.
}

⌨️ 快捷键说明

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