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

📄 setupview.cpp

📁 保护装置的mbpc软件
💻 CPP
字号:
// SetupView.cpp : implementation file
//

#include "stdafx.h"
#include "mbpc.h"
#include "SetupView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSetupView

IMPLEMENT_DYNCREATE(CSetupView, CFormView)

CSetupView::CSetupView()
	: CFormView(CSetupView::IDD)
{
	//{{AFX_DATA_INIT(CSetupView)
	m_nAddr = 0;
	m_nDay = 0;
	m_nCombEnergy = 0;
	m_nHour = 0;
	m_nMinute = 0;
	m_nMonth = 0;
	m_szOffname = _T("");
	m_szOnname = _T("");
	m_nSec = 0;
	m_nTimeStyle = 0;
	m_nYear = 0;
	m_nDiComb = 0;
	m_nEnergy = 0;
	m_szDeviceName = _T("");
	m_szStationName = _T("");
	m_nTimerFlag = 0;
	m_szDiName = _T("");
	//}}AFX_DATA_INIT
}

CSetupView::~CSetupView()
{
}

void CSetupView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSetupView)
	DDX_Control(pDX, IDC_DINAMEDIS, m_EditDiNameDis);
	DDX_Control(pDX, IDC_STATIONNAMEDISP, m_EditStationNameDisp);
	DDX_Control(pDX, IDC_DEVICENAMEDISP, m_EditDeviceNameDisp);
	DDX_Control(pDX, IDC_ENERGYDIS2, m_EditEnergyDis2);
	DDX_Control(pDX, IDC_DICOMB, m_CombDi);
	DDX_Control(pDX, IDC_YEARDIS, m_EditYearDis);
	DDX_Control(pDX, IDC_TIMESTYLE, m_CombTimeStyle);
	DDX_Control(pDX, IDC_SECDIS, m_EditSecDis);
	DDX_Control(pDX, IDC_ONNAMEDIS, m_EditOnnameDis);
	DDX_Control(pDX, IDC_OFFNAMEDIS, m_EditOffnameDis);
	DDX_Control(pDX, IDC_MONTHDIS, m_EditMonthDis);
	DDX_Control(pDX, IDC_MINUTEDIS, m_EditMinDis);
	DDX_Control(pDX, IDC_HOURDIS, m_EditHourDis);
	DDX_Control(pDX, IDC_ENERGYDIS, m_EditEnergyDis);
	DDX_Control(pDX, IDC_ENERGYCOMB, m_CombEnergy);
	DDX_Control(pDX, IDC_DAYDIS, m_EditDayDisp);
	DDX_Control(pDX, IDC_ADDRDISP, m_EditAddrDisp);
	DDX_Text(pDX, IDC_ADDREDIT, m_nAddr);
	DDX_Text(pDX, IDC_DAY, m_nDay);
	DDX_CBIndex(pDX, IDC_ENERGYCOMB, m_nCombEnergy);
	DDX_Text(pDX, IDC_HOUR, m_nHour);
	DDX_Text(pDX, IDC_MINUTE, m_nMinute);
	DDX_Text(pDX, IDC_MONTH, m_nMonth);
	DDX_Text(pDX, IDC_OFFNAME, m_szOffname);
	DDX_Text(pDX, IDC_ONNAME, m_szOnname);
	DDX_Text(pDX, IDC_SECOND, m_nSec);
	DDX_CBIndex(pDX, IDC_TIMESTYLE, m_nTimeStyle);
	DDX_Text(pDX, IDC_YEAR, m_nYear);
	DDX_CBIndex(pDX, IDC_DICOMB, m_nDiComb);
	DDX_Text(pDX, IDC_ENERGY, m_nEnergy);
	DDX_Text(pDX, IDC_DEVICENAMEEDIT, m_szDeviceName);
	DDX_Text(pDX, IDC_STATIONNAMEEDIT, m_szStationName);
	DDX_Text(pDX, IDC_DINAME, m_szDiName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSetupView, CFormView)
	//{{AFX_MSG_MAP(CSetupView)
	ON_BN_CLICKED(IDC_ADDSET, OnAddset)
	ON_BN_CLICKED(IDC_TIMESET, OnTimeset)
	ON_BN_CLICKED(IDC_ONOFFSET, OnOnoffset)
	ON_BN_CLICKED(IDC_ENERGYOK, OnEnergyok)
	ON_BN_CLICKED(IDC_ENERGYSET, OnEnergyset)
	ON_BN_CLICKED(IDC_TIMESYTLESET, OnTimesytleset)
	ON_WM_CREATE()
	ON_WM_TIMER()
	ON_WM_DESTROY()
	ON_BN_CLICKED(IDC_NAMESET, OnNameset)
	ON_CBN_SELCHANGE(IDC_DICOMB, OnSelchangeDicomb)
	ON_CBN_SELCHANGE(IDC_ENERGYCOMB, OnSelchangeEnergycomb)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSetupView diagnostics

#ifdef _DEBUG
void CSetupView::AssertValid() const
{
	CFormView::AssertValid();
}

void CSetupView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CSetupView message handlers

void CSetupView::OnAddset() 
{
	// TODO: Add your control notification handler code here
	if(GetDocument()->m_bSetuped)
	{
		if(this->MessageBox("确定要保存吗?",NULL,MB_OKCANCEL) == IDOK)
		{
			UpdateData(TRUE);
			GetDocument()->AddrSetting(this->m_nAddr);
		}
	}
}

void CSetupView::OnTimeset() 
{
	// TODO: Add your control notification handler code here
	if(GetDocument()->m_bSetuped)
	{
		if(this->MessageBox("确定要保存吗?",NULL,MB_OKCANCEL) == IDOK)
		{
			UpdateData(TRUE);
			GetDocument()->SetTime(this->m_nYear,this->m_nMonth,this->m_nDay,this->m_nHour,this->m_nMinute,this->m_nSec);
		}
	}
}

void CSetupView::OnOnoffset() 
{
	// TODO: Add your control notification handler code here
	if(GetDocument()->m_bSetuped)
	{
		if(this->MessageBox("确定要保存吗?",NULL,MB_OKCANCEL) == IDOK)
		{
			UpdateData();
			GetDocument()->SetDI(this->m_nDiComb, this->m_szDiName,this->m_szOnname,this->m_szOffname);
		}
	}
}

void CSetupView::OnEnergyok() 
{
	// TODO: Add your control notification handler code here
	if(GetDocument()->m_bSetuped)
	{
		UpdateData(TRUE);
		GetDocument()->m_nMeterBuf[this->m_nCombEnergy] = this->m_nEnergy;
	}
}

void CSetupView::OnEnergyset() 
{
	// TODO: Add your control notification handler code here
	if(GetDocument()->m_bSetuped)
	{
		if(this->MessageBox("确定要保存吗?",NULL,MB_OKCANCEL) == IDOK)
		{
			GetDocument()->InitMeter(GetDocument()->m_device_info.energy_count);
		}
	}
}

void CSetupView::OnTimesytleset() 
{
	// TODO: Add your control notification handler code here
	if(GetDocument()->m_bSetuped)
	{
		if(this->MessageBox("确定要保存吗?",NULL,MB_OKCANCEL) == IDOK)
		{
			GetDocument()->SetTimeStyle(this->m_nTimeStyle);
		}
	}
}

int CSetupView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CFormView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	SetTimer(1,100,NULL);
	return 0;
}

void CSetupView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	UpdateData(TRUE);
	char szBuf[32], szYear[1],szMonth[1],szDay[1],szHour[1],szMin[1],szSec[1];
	memset(szBuf,0,sizeof(szBuf));
	memset(szYear,0,1);
	memset(szMonth,0,1);
	memset(szDay,0,1);
	memset(szHour,0,1);
	memset(szMin,0,1);
	memset(szSec,0,1);
	CString str;
	
	if(1 == nIDEvent)
	{
		m_nTimerFlag++;
		
		if(m_nTimerFlag > 1)
		{
			m_nTimerFlag --;
		}
		else
		{
			if(GetDocument()->m_bSetuped)
			{
				itoa((int)GetDocument()->m_device_info.device_address,szBuf,10);
				this->m_EditAddrDisp.SetWindowText(szBuf);
				memset(szBuf,0,sizeof(szBuf));
				
				itoa((int)GetDocument()->m_Time.TimeBuf.year,szYear,10);
				this->m_EditYearDis.SetWindowText(szYear);
				itoa((int)GetDocument()->m_Time.TimeBuf.month,szMonth,10);
				this->m_EditMonthDis.SetWindowText(szMonth);
				itoa((int)GetDocument()->m_Time.TimeBuf.day,szDay,10);
				this->m_EditDayDisp.SetWindowText(szDay);
				itoa((int)GetDocument()->m_Time.TimeBuf.hour,szHour,10);
				this->m_EditHourDis.SetWindowText(szHour);
				itoa((int)GetDocument()->m_Time.TimeBuf.minute,szMin,10);
				this->m_EditMinDis.SetWindowText(szMin);
				itoa((int)GetDocument()->m_Time.TimeBuf.second,szSec,10);
				this->m_EditSecDis.SetWindowText(szSec);
				memset(szYear,0,1);
				memset(szMonth,0,1);
				memset(szDay,0,1);
				memset(szHour,0,1);
				memset(szMin,0,1);
				memset(szSec,0,1);
				
				//itoa(this->m_nDiComb,szBuf,10);
				//this->m_EditDiDis.SetWindowText(szBuf);
				//memset(szBuf,0,sizeof(szBuf));
				this->m_EditDiNameDis.SetWindowText((CString)GetDocument()->m_DiInfo[m_nDiComb].digital_name);
				this->m_EditOffnameDis.SetWindowText((CString)GetDocument()->m_DiInfo[m_nDiComb].off_name);
				this->m_EditOnnameDis.SetWindowText((CString)GetDocument()->m_DiInfo[m_nDiComb].on_name);
				
				str.Format("%d",GetDocument()->m_nEnergyBuf[this->m_nCombEnergy]);
				this->m_EditEnergyDis.SetWindowText(str);

				str.Format("%d",GetDocument()->m_nMeterBuf[m_nCombEnergy]);
				this->m_EditEnergyDis2.SetWindowText(str);

				str.Format("%s", GetDocument()->m_device_info.device_name);
				this->m_EditDeviceNameDisp.SetWindowText(str);

				str.Format("%s", GetDocument()->m_device_info.station_name);
				this->m_EditStationNameDisp.SetWindowText(str);
			}
		}
		m_nTimerFlag--;
	}
	CFormView::OnTimer(nIDEvent);
}

void CSetupView::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	CString strBuf;
	// TODO: Add your specialized code here and/or call the base class
	int i;
	for(i = 0; i < GetDocument()->m_device_info.energy_count; i++)
	{
		CString str;
		str.Format("%d",i+1);
		this->m_CombEnergy.AddString(str);
	}
	for(i = 0; i < GetDocument()->m_device_info.di_count; i++)
	{
		CString str;
		str.Format("%d",i+1);
		this->m_CombDi.AddString(str);
	}
	this->m_CombTimeStyle.AddString("PPS对时");
	this->m_CombTimeStyle.AddString("网络对时");
	if(GetDocument()->m_bSetuped)
	{
		this->m_nAddr = GetDocument()->m_device_info.device_address;

		this->m_nYear = GetDocument()->m_Time.TimeBuf.year;
		this->m_nMonth = GetDocument()->m_Time.TimeBuf.month;
		this->m_nDay = GetDocument()->m_Time.TimeBuf.day;
		this->m_nHour = GetDocument()->m_Time.TimeBuf.hour;
		this->m_nMinute = GetDocument()->m_Time.TimeBuf.minute;
		this->m_nSec = GetDocument()->m_Time.TimeBuf.second;
		
		this->m_szOffname = (CString)GetDocument()->m_DiInfo[m_nDiComb].off_name;
		this->m_szOnname = (CString)GetDocument()->m_DiInfo[m_nDiComb].on_name;

		memcpy(&GetDocument()->m_nMeterBuf,&GetDocument()->m_nEnergyBuf,sizeof(GetDocument()->m_nMeterBuf));
		
		strBuf.Format("%d",GetDocument()->m_nEnergyBuf[this->m_nCombEnergy]);
		this->m_EditEnergyDis2.SetWindowText(strBuf);
		this->m_nEnergy = GetDocument()->m_nEnergyBuf[this->m_nCombEnergy];

		this->m_szDeviceName.Format("%s",GetDocument()->m_device_info.device_name);

		this->m_szStationName.Format("%s",GetDocument()->m_device_info.station_name);
	}
	UpdateData(FALSE);
}

CMbpcDoc* CSetupView::GetDocument()
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMbpcDoc)));
	return (CMbpcDoc*)m_pDocument;
}

void CSetupView::OnDestroy() 
{
	CFormView::OnDestroy();
	
	// TODO: Add your message handler code here
	KillTimer(1);
}

void CSetupView::OnNameset() 
{
	// TODO: Add your control notification handler code here
	if(GetDocument()->m_bSetuped)
	{
		if(this->MessageBox("确定要保存吗?",NULL,MB_OKCANCEL) == IDOK)
		{
			GetDocument()->SetDeviceName(this->m_szStationName, this->m_szDeviceName);
		}
	}
}

void CSetupView::OnSelchangeDicomb() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	this->m_szOffname = (CString)GetDocument()->m_DiInfo[m_nDiComb].off_name;
	this->m_szOnname = (CString)GetDocument()->m_DiInfo[m_nDiComb].on_name;
	this->m_szDiName = (CString)GetDocument()->m_DiInfo[m_nDiComb].digital_name;
	UpdateData(FALSE);
}

void CSetupView::OnSelchangeEnergycomb() 
{
	// TODO: Add your control notification handler code here
	UpdateData();
	
}

void CSetupView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView) 
{
	// TODO: Add your specialized code here and/or call the base class
	UpdateData();
	if(bActivate == FALSE)
	{
		KillTimer(1);
	}
	else
	{
		OnInitialUpdate();
		SetTimer(1,500,NULL);
	}
//	CFormView::Invalidate();

	CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}

⌨️ 快捷键说明

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