📄 energyvalview.cpp
字号:
// EnergyValView.cpp : implementation file
//
#include "stdafx.h"
#include "mbpc.h"
#include "EnergyValView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEnergyValView
IMPLEMENT_DYNCREATE(CEnergyValView, CFormView)
CEnergyValView::CEnergyValView()
: CFormView(CEnergyValView::IDD)
{
//{{AFX_DATA_INIT(CEnergyValView)
m_szName = _T("");
m_fPratio = 0.0f;
m_fSratio = 0.0f;
m_nTimerFlag = 0;
m_nId = -1;
//}}AFX_DATA_INIT
}
CEnergyValView::~CEnergyValView()
{
}
void CEnergyValView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEnergyValView)
DDX_Control(pDX, IDC_ID, m_CombId);
DDX_Control(pDX, IDC_ENERGYLST, m_ListEnergy);
DDX_Text(pDX, IDC_PARANAME, m_szName);
DDX_Text(pDX, IDC_PARARATIO, m_fPratio);
DDX_Text(pDX, IDC_SECRATIO, m_fSratio);
DDX_CBIndex(pDX, IDC_ID, m_nId);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEnergyValView, CFormView)
//{{AFX_MSG_MAP(CEnergyValView)
ON_WM_CREATE()
ON_WM_TIMER()
ON_BN_CLICKED(IDC_PARASET, OnParaset)
ON_WM_DESTROY()
ON_CBN_SELCHANGE(IDC_ID, OnSelchangeId)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEnergyValView diagnostics
#ifdef _DEBUG
void CEnergyValView::AssertValid() const
{
CFormView::AssertValid();
}
void CEnergyValView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CEnergyValView message handlers
CMbpcDoc* CEnergyValView::GetDocument()
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMbpcDoc)));
return (CMbpcDoc*)m_pDocument;
}
void CEnergyValView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
m_ListEnergy.DeleteAllItems();
int i;
for(i = 0; i < 6; i++)
{
m_ListEnergy.DeleteColumn(0);
}
for(i = 0; i < GetDocument()->m_device_info.energy_count; i++)
{
m_CombId.DeleteString(0);
}
LONG lStyle;
lStyle = GetWindowLong(m_ListEnergy.m_hWnd, GWL_STYLE);//获取当前窗口style
lStyle &= ~LVS_TYPEMASK; //清除显示方式位
lStyle |= LVS_REPORT; //设置style
SetWindowLong(m_ListEnergy.m_hWnd, GWL_STYLE, lStyle);//设置style
DWORD dwStyle = m_ListEnergy.GetExtendedStyle();
dwStyle |= LVS_EX_FULLROWSELECT;//选中某行使整行高亮(只适用与report风格的listctrl)
dwStyle |= LVS_EX_GRIDLINES;//网格线(只适用与report风格的listctrl)
m_ListEnergy.SetExtendedStyle(dwStyle); //设置扩展风格
this->m_ListEnergy.InsertColumn(0,"电度量ID",LVCFMT_LEFT,80);
this->m_ListEnergy.InsertColumn(1,"名称",LVCFMT_LEFT,70);
this->m_ListEnergy.InsertColumn(2,"一次测变比",LVCFMT_LEFT,90);
this->m_ListEnergy.InsertColumn(3,"一次测",LVCFMT_LEFT,90);
this->m_ListEnergy.InsertColumn(4,"二次测变比",LVCFMT_LEFT,90);
this->m_ListEnergy.InsertColumn(5,"二次测",LVCFMT_LEFT,90);
if(GetDocument()->m_bSetuped)
{
CString strText;
this->EnergyCntr = GetDocument()->m_device_info.energy_count;
for(i = 0; i < EnergyCntr; i++)
{
strText.Format("%d",i + 1);
int nRow = m_ListEnergy.InsertItem(i,strText);
m_ListEnergy.SetItemText(nRow, 1, (CString)GetDocument()->m_energy_info[i].energy_name);
strText.Format("%f",GetDocument()->m_energy_info[i].primary_ratio);
m_ListEnergy.SetItemText(nRow, 2, strText);
strText.Format("%f",GetDocument()->m_energy_info[i].secondary_ratio);
m_ListEnergy.SetItemText(nRow, 4, strText);
}
for(int j = 0; j < GetDocument()->m_device_info.energy_count; j++)
{
strText.Format("%d", j+1);
m_CombId.AddString(strText);
}
}
}
int CEnergyValView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFormView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
SetTimer(1,500,NULL);
return 0;
}
void CEnergyValView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
CString str,strText;
char szBuf[1024];
memset(szBuf,0,sizeof(szBuf));
if(1 == nIDEvent)
{
m_nTimerFlag++;
if(m_nTimerFlag > 1)
{
m_nTimerFlag --;
}
else
{
if(GetDocument()->m_bSetuped)
{
for(int i = 0; i < EnergyCntr; i++)
{
sprintf(szBuf,"%f %s",GetDocument()->m_fPrim_Meter[i],GetDocument()->m_energy_info[i].primary_unit);
m_ListEnergy.SetItemText(i, 3, szBuf);
memset(szBuf,0,sizeof(szBuf));
sprintf(szBuf,"%f %s",GetDocument()->m_fSec_Meter[i],GetDocument()->m_energy_info[i].secondary_unit);
m_ListEnergy.SetItemText(i,5,szBuf);
memset(szBuf,0,sizeof(szBuf));
m_ListEnergy.SetItemText(i, 1, (CString)GetDocument()->m_energy_info[i].energy_name);
strText.Format("%f",GetDocument()->m_energy_info[i].primary_ratio);
m_ListEnergy.SetItemText(i, 2, strText);
strText.Format("%f",GetDocument()->m_energy_info[i].secondary_ratio);
m_ListEnergy.SetItemText(i, 4, strText);
}
}
}
m_nTimerFlag--;
}
CFormView::OnTimer(nIDEvent);
}
void CEnergyValView::OnParaset()
{
// TODO: Add your control notification handler code here
if(this->MessageBox("确定要保存吗?",NULL,MB_OKCANCEL) == IDOK)
{
UpdateData(TRUE);
if(GetDocument()->m_bSetuped)
{
GetDocument()->SetMeterPara(this->m_nId,this->m_szName,this->m_fPratio,this->m_fSratio);
Sleep(1000);
GetDocument()->ReqAnaInfo(m_nId);
}
}
}
//DEL void CEnergyValView::OnSecset2()
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL
//DEL }
//DEL void CEnergyValView::OnClickEnergylst(NMHDR* pNMHDR, LRESULT* pResult)
//DEL {
//DEL // TODO: Add your control notification handler code here
//DEL NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
//DEL if(pNMListView->iItem != -1)
//DEL {
//DEL CString strtemp;
//DEL strtemp.Format("单击的是第%d行第%d列",
//DEL pNMListView->iItem, pNMListView->iSubItem);
//DEL AfxMessageBox(strtemp);
//DEL }
//DEL *pResult = 0;
//DEL }
void CEnergyValView::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);
}
void CEnergyValView::OnDestroy()
{
CFormView::OnDestroy();
// TODO: Add your message handler code here
KillTimer(1);
}
void CEnergyValView::OnSelchangeId()
{
// TODO: Add your control notification handler code here
UpdateData();
m_szName.Format("%s", GetDocument()->m_energy_info[m_nId].energy_name);
this->m_fPratio = this->GetDocument()->m_energy_info[m_nId].primary_ratio;
this->m_fSratio = this->GetDocument()->m_energy_info[m_nId].secondary_ratio;
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -