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

📄 settingview.cpp

📁 保护装置的mbpc软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// SettingView.cpp : implementation file
//

#include "stdafx.h"
#include "mbpc.h"
#include "SettingView.h"
#include "OnOffDlg.h"
#include "CSpreadSheet.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSettingView

IMPLEMENT_DYNCREATE(CSettingView, CFormView)

CSettingView::CSettingView()
	: CFormView(CSettingView::IDD)
{
	//{{AFX_DATA_INIT(CSettingView)
	m_nSetId = 0;
	m_nSetSecId = 0;
	m_bNew = 0;
	m_bSaved = TRUE;
	//}}AFX_DATA_INIT
}

CSettingView::~CSettingView()
{
}

void CSettingView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSettingView)
	DDX_Control(pDX, IDC_CURSET, m_ListCurrent);
	DDX_Control(pDX, IDC_EDIT1, m_EditId);
	DDX_Control(pDX, IDC_COMBSET2, m_CombSecId);
	DDX_Control(pDX, IDC_COMBSET, m_CombSet);
	DDX_Control(pDX, IDC_SETLIST, m_ListSet);
	DDX_CBIndex(pDX, IDC_COMBSET, m_nSetId);
	DDX_CBIndex(pDX, IDC_COMBSET2, m_nSetSecId);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSettingView, CFormView)
	//{{AFX_MSG_MAP(CSettingView)
	ON_BN_CLICKED(IDC_CALL, OnCallSetting)
	ON_BN_CLICKED(IDC_CHGSET, OnChgset)
	ON_BN_CLICKED(IDC_ADDSEC, OnAddsec)
	ON_BN_CLICKED(IDC_SWITCHSET, OnSwitchset)
	ON_NOTIFY(NM_CLICK, IDC_SETLIST, OnClickSetlist)
	ON_BN_CLICKED(IDC_NEWSEC, OnNewsec)
	ON_BN_CLICKED(IDC_PRINT, OnPrint)
	ON_BN_CLICKED(IDC_CALLALL, OnCallall)
	ON_BN_CLICKED(IDC_PRINT2, OnPrint2)
	ON_WM_CLOSE()
	ON_WM_CANCELMODE()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSettingView diagnostics

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

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

/////////////////////////////////////////////////////////////////////////////
// CSettingView message handlers

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

void CSettingView::OnInitialUpdate() 
{
	CFormView::OnInitialUpdate();
	
	// TODO: Add your specialized code here and/or call the base class
	int i;
	for(i = 0; i < GetDocument()->m_device_info.setting_sect_count; i++)
	{
		m_CombSet.DeleteString(0);
		m_CombSecId.DeleteString(0);
	}
	if(GetDocument()->m_bSetuped)
	{
		for(i = 0; i < GetDocument()->m_device_info.used_setting_sec_count; i++)
		{
			CString str;
			str.Format("%d",i + 1);
			m_CombSet.AddString(str);
			m_CombSecId.AddString(str);
		}
	}
	m_nSetSecId = GetDocument()->m_device_info.current_sect;
	CString str;
	str.Format("%d",m_nSetSecId + 1);
	this->m_EditId.SetWindowText(str);
	UpdateData(FALSE);

	LONG lStyle;
	m_ListSet.DeleteAllItems();
	m_ListCurrent.DeleteAllItems();
	for(i = 0; i < 4; i++)
	{
		m_ListCurrent.DeleteColumn(0);
		m_ListSet.DeleteColumn(0);
	}

	lStyle = GetWindowLong(m_ListSet.m_hWnd, GWL_STYLE);//获取当前窗口style
	lStyle &= ~LVS_TYPEMASK; //清除显示方式位
	lStyle |= LVS_REPORT; //设置style
	SetWindowLong(m_ListSet.m_hWnd, GWL_STYLE, lStyle);//设置style
	SetWindowLong(m_ListCurrent.m_hWnd, GWL_STYLE, lStyle);

	DWORD dwStyle = m_ListSet.GetExtendedStyle();
	dwStyle |= LVS_EX_FULLROWSELECT;//选中某行使整行高亮(只适用与report风格的listctrl)
	dwStyle |= LVS_EX_GRIDLINES;//网格线(只适用与report风格的listctrl)
	m_ListSet.SetExtendedStyle(dwStyle); //设置扩展风格
	m_ListCurrent.SetExtendedStyle(dwStyle); //设置扩展风格

	m_ListSet.InsertColumn(0, "定值ID", LVCFMT_LEFT, 50);
	m_ListSet.InsertColumn(1, "名称", LVCFMT_LEFT, 100);
	m_ListSet.InsertColumn(2, "值", LVCFMT_LEFT, 85);
	m_ListSet.InsertColumn(3, "类型", LVCFMT_LEFT, 65);

	m_ListCurrent.InsertColumn(0, "定值ID", LVCFMT_LEFT, 50);
	m_ListCurrent.InsertColumn(1, "名称", LVCFMT_LEFT, 100);
	m_ListCurrent.InsertColumn(2, "值", LVCFMT_LEFT, 85);
	m_ListCurrent.InsertColumn(3, "类型", LVCFMT_LEFT, 65);

	if(GetDocument()->m_bSetuped)
	{
		for(int i = 0; i < GetDocument()->m_device_info.item_in_sect; i++)
		{
			CString str;
			
			str.Format("%d",i + 1);
			int nRow = m_ListCurrent.InsertItem(i,str);

			m_ListCurrent.SetItemText(nRow, 1, (CString)GetDocument()->m_SettingInfo[i].setting_name);
			
			m_ListSet.InsertItem(i,str);
			
			switch(GetDocument()->m_SettingInfo[i].data_type)
			{
			case 0:
				{
					str.Format("%d %s", GetDocument()->m_Pk_value[GetDocument()->m_device_info.current_sect][i].bValue, GetDocument()->m_SettingInfo[i].setting_unit);
					m_ListCurrent.SetItemText(nRow, 2, str);

					m_ListCurrent.SetItemText(i, 3, "布尔型");
					break;
				}
			case 1:
				{
					str.Format("%d %s", GetDocument()->m_Pk_value[GetDocument()->m_device_info.current_sect][i].nValue, GetDocument()->m_SettingInfo[i].setting_unit);
					m_ListCurrent.SetItemText(nRow, 2, str);

					m_ListCurrent.SetItemText(i, 3, "整型");
					break;
				}
			case 2:
				{
					str.Format("%f %s", GetDocument()->m_Pk_value[GetDocument()->m_device_info.current_sect][i].fValue, GetDocument()->m_SettingInfo[i].setting_unit);
					m_ListCurrent.SetItemText(nRow, 2, str);

					m_ListCurrent.SetItemText(i, 3, "浮点型");
					break;
				}
			}
			if(GetDocument()->m_bSetSaved == FALSE)
			{
				m_ListSet.SetItemText(i, 1, (CString)GetDocument()->m_SettingInfo[i].setting_name);

				switch(GetDocument()->m_SettingInfo[i].data_type)
				{
				case 0:
					{
						str.Format("%d %s",GetDocument()->m_SetBuf[i].bValue, GetDocument()->m_SettingInfo[i].setting_unit);
						m_ListSet.SetItemText(i, 2, str);

						m_ListSet.SetItemText(i, 3, "布尔型");
						break;
					}
				case 1:
					{
						str.Format("%d %s",GetDocument()->m_SetBuf[i].nValue, GetDocument()->m_SettingInfo[i].setting_unit);
						m_ListSet.SetItemText(i, 2, str);

						m_ListSet.SetItemText(i, 3, "整型");
						break;
					}
				case 2:
					{
						str.Format("%f %s",GetDocument()->m_SetBuf[i].fValue, GetDocument()->m_SettingInfo[i].setting_unit);
						m_ListSet.SetItemText(i, 2, str);

						m_ListSet.SetItemText(i, 3, "浮点型");
						break;
					}
				}
			}
		}
	}
}

void CSettingView::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
	{
		if(m_bSaved == TRUE)
		{
			OnInitialUpdate();
		}
		//SetTimer(1,500,NULL);
	}
	CFormView::Invalidate();
	
	CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}

void CSettingView::OnCallSetting() 
{
	// TODO: Add your control notification handler code here
	CString str;
	if(GetDocument()->m_bSetuped)
	{
		UpdateData();
		if(GetDocument()->BuildSetFrame(this->m_nSetId))
		{
			memcpy(&GetDocument()->m_SetBuf,&GetDocument()->m_Pk_value[m_nSetId],sizeof(GetDocument()->m_SetBuf));

			for(int i = 0; i < GetDocument()->m_device_info.item_in_sect; i++)
			{				
				m_ListSet.SetItemText(i, 1, (CString)GetDocument()->m_SettingInfo[i].setting_name);

				switch(GetDocument()->m_SettingInfo[i].data_type)
				{
				case 0:
					{
						str.Format("%d %s",GetDocument()->m_SetBuf[i].bValue, GetDocument()->m_SettingInfo[i].setting_unit);
						m_ListSet.SetItemText(i, 2, str);

						m_ListSet.SetItemText(i, 3, "布尔型");
						break;
					}
				case 1:
					{
						str.Format("%d %s",GetDocument()->m_SetBuf[i].nValue, GetDocument()->m_SettingInfo[i].setting_unit);
						m_ListSet.SetItemText(i, 2, str);

						m_ListSet.SetItemText(i, 3, "整型");
						break;
					}
				case 2:
					{
						str.Format("%f %s",GetDocument()->m_SetBuf[i].fValue, GetDocument()->m_SettingInfo[i].setting_unit);
						m_ListSet.SetItemText(i, 2, str);

						m_ListSet.SetItemText(i, 3, "浮点型");
						break;
					}
				}
				GetDocument()->m_bSetSaved = FALSE;
			}
			if(m_nSetId == GetDocument()->m_device_info.current_sect)
			{
				for(int i = 0; i < GetDocument()->m_device_info.item_in_sect; i++)
				{
					CString str;

					m_ListSet.SetItemText(i, 1, (CString)GetDocument()->m_SettingInfo[i].setting_name);

					switch(GetDocument()->m_SettingInfo[i].data_type)
					{
					case 0:
						{
							str.Format("%d %s",GetDocument()->m_SetBuf[i].bValue, GetDocument()->m_SettingInfo[i].setting_unit);
							m_ListCurrent.SetItemText(i, 2, str);

							m_ListCurrent.SetItemText(i, 3, "布尔型");
							break;
						}
					case 1:
						{
							str.Format("%d %s",GetDocument()->m_SetBuf[i].nValue, GetDocument()->m_SettingInfo[i].setting_unit);
							m_ListCurrent.SetItemText(i, 2, str);

							m_ListCurrent.SetItemText(i, 3, "整型");
							break;
						}
					case 2:
						{
							str.Format("%f %s",GetDocument()->m_SetBuf[i].fValue, GetDocument()->m_SettingInfo[i].setting_unit);
							m_ListCurrent.SetItemText(i, 2, str);

							m_ListCurrent.SetItemText(i, 3, "浮点型");
							break;
						}
					}
				}
				UpdateData(FALSE);
			}
		}
	}
}

void CSettingView::OnChgset() 
{
	// TODO: Add your control notification handler code here
	if(GetDocument()->m_bSetuped)
	{
		UpdateData();
		if(this->MessageBox("确定要保存吗?",NULL,MB_OKCANCEL) == IDOK)
		{
			if(GetDocument()->ChgSetCmd(this->m_nSetId, 1))
			{
				memcpy(&GetDocument()->m_Pk_value[m_nSetId],&GetDocument()->m_SetBuf,sizeof(GetDocument()->m_SetBuf));
				GetDocument()->m_bSetSaved = TRUE;
				if(m_bNew == 1)
				{
					CString str;
					str.Format("%d", m_nSetId);
					this->m_CombSecId.AddString(str);
					m_bNew = 0;
				}
				if(m_nSetId == GetDocument()->m_device_info.current_sect)
				{
					for(int i = 0; i < GetDocument()->m_device_info.item_in_sect; i++)
					{
						CString str;

						m_ListSet.SetItemText(i, 1, (CString)GetDocument()->m_SettingInfo[i].setting_name);

						switch(GetDocument()->m_SettingInfo[i].data_type)
						{
						case 0:
							{
								str.Format("%d %s",GetDocument()->m_SetBuf[i].bValue, GetDocument()->m_SettingInfo[i].setting_unit);
								m_ListCurrent.SetItemText(i, 2, str);

								m_ListCurrent.SetItemText(i, 3, "布尔型");
								break;
							}
						case 1:
							{
								str.Format("%d %s",GetDocument()->m_SetBuf[i].nValue, GetDocument()->m_SettingInfo[i].setting_unit);
								m_ListCurrent.SetItemText(i, 2, str);

								m_ListCurrent.SetItemText(i, 3, "整型");
								break;
							}
						case 2:
							{
								str.Format("%f %s",GetDocument()->m_SetBuf[i].fValue, GetDocument()->m_SettingInfo[i].setting_unit);
								m_ListCurrent.SetItemText(i, 2, str);

								m_ListCurrent.SetItemText(i, 3, "浮点型");
								break;
							}
						}
					}
					UpdateData(FALSE);
					m_bSaved = TRUE;
				}
			}
		}
		else
		{
			if(GetDocument()->ChgSetCmd(this->m_nSetId, 0))
			{
				memcpy(&GetDocument()->m_Pk_value[m_nSetId],&GetDocument()->m_SetBuf,sizeof(GetDocument()->m_SetBuf));
				GetDocument()->m_bSetSaved = TRUE;
				m_bSaved = TRUE;
			}
		}
	}
}

void CSettingView::OnAddsec() 
{
	// TODO: Add your control notification handler code here
	/*
	if(GetDocument()->m_bSetuped)
	{
		CString str;
		UpdateData();
		if(GetDocument()->AddSec(m_nSetId))
		{
			AfxMessageBox("添加成功");
			str.Format("%d", m_CombSecId.GetCount());
			m_CombSecId.AddString(str);
			GetDocument()->m_bSetSaved = TRUE;
		}
		else
		{
			if(m_CombSet.GetCount() > GetDocument()->m_device_info.used_setting_sec_count)
				m_CombSet.DeleteString(m_CombSet.GetCount() - 1);
		}
	}*/
}

void CSettingView::OnSwitchset() 
{
	// TODO: Add your control notification handler code here
	CString str;
	if(GetDocument()->m_bSetuped)
	{
		UpdateData();
		GetDocument()->SwitchSet(this->m_nSetSecId);

		if(GetDocument()->BuildSetFrame(this->m_nSetSecId))
		{
			str.Format("%d", (int)GetDocument()->m_device_info.current_sect + 1);
			this->m_EditId.SetWindowText(str);
			if(GetDocument()->m_bSetuped)
			{
				for(int i = 0; i < GetDocument()->m_device_info.item_in_sect; i++)
				{					
					switch(GetDocument()->m_SettingInfo[i].data_type)
					{
					case 0:
						{
							str.Format("%d %s", GetDocument()->m_Pk_value[GetDocument()->m_device_info.current_sect][i].bValue, GetDocument()->m_SettingInfo[i].setting_unit);
							m_ListCurrent.SetItemText(i, 2, str);
							m_ListSet.SetItemText(i, 2, str);
			
							m_ListCurrent.SetItemText(i, 3, "布尔型");
							m_ListSet.SetItemText(i,3, "布尔型");
							break;
						}
					case 1:
						{
							str.Format("%d %s", GetDocument()->m_Pk_value[GetDocument()->m_device_info.current_sect][i].nValue, GetDocument()->m_SettingInfo[i].setting_unit);
							m_ListCurrent.SetItemText(i, 2, str);
							m_ListSet.SetItemText(i,2, str);

							m_ListCurrent.SetItemText(i, 3, "整型");
							m_ListSet.SetItemText(i, 3, "整型");
							break;
						}
					case 2:
						{
							str.Format("%f %s", GetDocument()->m_Pk_value[GetDocument()->m_device_info.current_sect][i].fValue, GetDocument()->m_SettingInfo[i].setting_unit);
							m_ListCurrent.SetItemText(i, 2, str);
							m_ListSet.SetItemText(i,2, str);

							m_ListCurrent.SetItemText(i, 3, "浮点型");
							m_ListSet.SetItemText(i, 3, "浮点型");
							break;

⌨️ 快捷键说明

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