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

📄 settingview.cpp

📁 保护装置的mbpc软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
						}
					}
				}
			}
		}
	}
}

void CSettingView::OnClickSetlist(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
	if(pNMListView->iItem != -1)
	{	
		CString str;
		if(pNMListView->iSubItem == 2)
		{
			str = m_ListSet.GetItemText(pNMListView->iItem, 2);
			if(!str.IsEmpty())
			{
				if(GetDocument()->m_bSetuped)
				{
					COnOffDlg dlg;
					dlg.m_szTitle.Format("%s", GetDocument()->m_SettingInfo[pNMListView->iItem].setting_name);
					switch(GetDocument()->m_SettingInfo[pNMListView->iItem].data_type)
					{
					case 0:
						{
							dlg.m_szData.Format("%d", GetDocument()->m_SetBuf[pNMListView->iItem].bValue);
							UpdateData(FALSE);
							break;
						}
					case 1:
						{
							dlg.m_szData.Format("%d", GetDocument()->m_SetBuf[pNMListView->iItem].nValue);
							UpdateData(FALSE);
							break;
						}
					case 2:
						{
							dlg.m_szData.Format("%f", GetDocument()->m_SetBuf[pNMListView->iItem].fValue);
							UpdateData(FALSE);
							break;
						}
					}
					//dlg.m_szData.Format("%d", GetDocument()->m_SetBuf[pNMListView->iItem].bValue);
					if(dlg.DoModal() == IDOK)
					{
						UpdateData();
						if(GetDocument()->ChgSetData(m_nSetId, pNMListView->iItem, dlg.m_szData))
						{	
							Sleep(200);
							switch(GetDocument()->m_SettingInfo[pNMListView->iItem].data_type)
							{
							case 0:
								{
									str.Format("%d %s",GetDocument()->m_SetBuf[pNMListView->iItem].bValue, GetDocument()->m_SettingInfo[pNMListView->iItem].setting_unit);
									m_ListSet.SetItemText(pNMListView->iItem, 2, str);
									break;
								}
							case 1:
								{
									str.Format("%d %s",GetDocument()->m_SetBuf[pNMListView->iItem].nValue, GetDocument()->m_SettingInfo[pNMListView->iItem].setting_unit);
									m_ListSet.SetItemText(pNMListView->iItem, 2, str);
									break;
								}
							case 2:
								{
									str.Format("%f %s",GetDocument()->m_SetBuf[pNMListView->iItem].fValue, GetDocument()->m_SettingInfo[pNMListView->iItem].setting_unit);
									m_ListSet.SetItemText(pNMListView->iItem, 2, str);
									break;
								}
							}
							m_bSaved = FALSE;
						}
					}
				}
			}
		}
 //		CString strtemp;
 //		strtemp.Format("单击的是第%d行第%d列",
 //						pNMListView->iItem, pNMListView->iSubItem);
 //		AfxMessageBox(strtemp);
	}
	*pResult = 0;
}

void CSettingView::OnNewsec() 
{
	// TODO: Add your control notification handler code here
	if(GetDocument()->m_bSetuped)
	{
		int nCntr = m_CombSet.GetCount();
		if(nCntr < GetDocument()->m_device_info.setting_sect_count)
		{
			if(nCntr == GetDocument()->m_device_info.used_setting_sec_count)
			{
				CString str;
				str.Format("%d",nCntr + 1);
				m_CombSet.AddString(str);

				m_nSetId = nCntr;
				UpdateData(FALSE);

				memset(GetDocument()->m_SetBuf,0,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;
						}
					}
					m_bNew = 1;
				}
				GetDocument()->m_bSetSaved = FALSE;
			}
		}
		else
			AfxMessageBox("定值区已达上限");
	}
}

void CSettingView::OnPrint() 
{
	// TODO: Add your control notification handler code here
//	GetDocument()->m_device_info.used_setting_sec_count = 1;
	CFileDialog	Filedlg( FALSE,   

	"xls",   

	NULL,   

	OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT   |   

	OFN_ALLOWMULTISELECT|OFN_EXPLORER,     

	"Excel   Files   (*.xls)|*.xls|All   files(*.*)|*.*||",   

	NULL);     
    
//	Filedlg.m_ofn.lpstrFile   =   strBuf;     
    
	Filedlg.m_ofn.lpstrTitle   =   "存储定值";//改变标题   
	CString sExcelFile,sPath;
	GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
	sPath.ReleaseBuffer ();
	int nPos;
	nPos=sPath.ReverseFind ('\\');
	sPath=sPath.Left (nPos);

//	sExcelFile = sPath + "\\List.xls"; 			// 要建立的Excel文件
	Filedlg.m_ofn.lpstrInitialDir   =   sPath;//设定打开初始目录   
    
//	Filedlg.m_ofn.lStructSize   =   structsize;   
    
	Filedlg.m_ofn.nMaxFile   =   MAX_PATH;   


	if(Filedlg.DoModal()   ==   IDOK)   

	{   
		CString   strFilePath   =   Filedlg.GetPathName(); 
		CString	strFileName = Filedlg.GetFileName();
		CString pFileName = strFilePath;
		TRY
		{
			CFile::Remove( pFileName );
		}
		CATCH( CFileException, e )
		{
			#ifdef _DEBUG
				afxDump << "File " << pFileName << " cannot be removed\n";
			#endif
		}
		END_CATCH

		CString strBuf;
		int i;
		
		strBuf.Format("%s%s",GetDocument()->m_device_info.station_name, GetDocument()->m_device_info.device_name);
		CSpreadSheet SS(strFilePath, strBuf,FALSE);
		CStringArray sampleArray, testRow;
			
		SS.BeginTransaction();
//		SS. DeleteSheet();  		
		// 加入标题
		sampleArray.RemoveAll();
		sampleArray.Add("定值号");
		sampleArray.Add("名称");
		sampleArray.Add("单位");
		sampleArray.Add("类型");

		int SettingSec = GetDocument()->m_device_info.used_setting_sec_count;

//		i = GetDocument()->m_device_info.current_sect;
		if(SettingSec != 0)
		{
			strBuf.Format("%d 号定值区", this->m_nSetId + 1);
			sampleArray.Add(strBuf);
		}
		SS.AddHeaders(sampleArray);

		// 加入数据
		//CString strName[] = {"徐景周","徐志慧","郭徽","牛英俊","朱小鹏"};
		//CString strAge[]  = {"27","23","28","27","26"};
		int nCntr = GetDocument()->m_device_info.item_in_sect;
		CString strId[MAX_SETTING_ITEM];
		for(i = 1; i <= nCntr; i++)
		{
			strId[i-1].Format("%d",i);
		}
		
		CString strName[MAX_SETTING_ITEM];
		for(i = 0; i < nCntr; i++)
		{
			strName[i] = (CString)GetDocument()->m_SettingInfo[i].setting_name;
		}
		
		CString strUNIT[MAX_SETTING_ITEM];
		for(i = 0; i < nCntr; i++)
		{
			strUNIT[i] = (CString)GetDocument()->m_SettingInfo[i].setting_unit;
		}
		
		CString strType[MAX_SETTING_ITEM];
		for(i = 0; i < nCntr; i++)
		{
			//strType[i] = (CString)GetDocument()->m_SettingInfo[i].data_type;
			switch(GetDocument()->m_SettingInfo[i].data_type)
			{
			case 0:
				{
					strType[i].Format("布尔型");
					break;
				}
			case 1:
				{
					strType[i].Format("整型");
					break;
				}
			case 2:
				{
					strType[i].Format("浮点型");
					break;
				}
			}
		}
		
		CString strValue[MAX_SETTING_ITEM];

		for(int j = 0; j < nCntr; j++)
		{
			PK_Value* pSetting = &GetDocument()->m_Pk_value[m_nSetId][j];
			switch(GetDocument()->m_SettingInfo[j].data_type)
			{
			case 0:
				{
					strValue[j].Format("%d %s", pSetting->bValue , GetDocument()->m_SettingInfo[j].setting_unit);
					break;
				}
			case 1:
				{
					strValue[j].Format("%d %s", pSetting->nValue , GetDocument()->m_SettingInfo[j].setting_unit);
					break;
				}
			case 2:
				{
					strValue[j].Format("%f %s", pSetting->fValue , GetDocument()->m_SettingInfo[j].setting_unit);
					break;
				}
			}
		}
		

		for(i = 0; i < nCntr; i++)
		{
			sampleArray.RemoveAll();
			sampleArray.Add(strId[i]);
			sampleArray.Add(strName[i]);
			sampleArray.Add(strUNIT[i]);
			sampleArray.Add(strType[i]);
			if(SettingSec != 0)
			{
				sampleArray.Add(strValue[i]);
			}
			SS.AddRow(sampleArray);
		}
			
		SS.Commit();
	}
}

void CSettingView::OnCallall() 
{
	// TODO: Add your control notification handler code here
	for(int i = 0; i < GetDocument()->m_device_info.used_setting_sec_count; i++)
	{
		Sleep(1000);
		if(GetDocument()->BuildSetFrame(i) == 0)
		{
			i = 9;
		}
	}
}

void CSettingView::OnPrint2() 
{
	// TODO: Add your control notification handler code here
	CFileDialog	Filedlg( TRUE,   

	"xls",   

	NULL,   

	OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT   |   

	OFN_ALLOWMULTISELECT|OFN_EXPLORER,     

	"Excel   Files   (*.xls)|*.xls|All   files(*.*)|*.*||",   

	NULL);     
    
//	Filedlg.m_ofn.lpstrFile   =   strBuf;     
    
	Filedlg.m_ofn.lpstrTitle   =   "打开定值表";//改变标题   
	CString sExcelFile,sPath;
	GetModuleFileName(NULL,sPath.GetBufferSetLength (MAX_PATH+1),MAX_PATH);
	sPath.ReleaseBuffer ();
	int nPos;
	nPos=sPath.ReverseFind ('\\');
	sPath=sPath.Left (nPos);

//	sExcelFile = sPath + "\\List.xls"; 			// 要建立的Excel文件
	Filedlg.m_ofn.lpstrInitialDir   =   sPath;//设定打开初始目录   
    
//	Filedlg.m_ofn.lStructSize   =   structsize;   
    
	Filedlg.m_ofn.nMaxFile   =   MAX_PATH;   


	if(Filedlg.DoModal()   ==   IDOK)   

	{  
		CString   strFilePath   =   Filedlg.GetPathName(); 
		CString	strFileName = Filedlg.GetFileName();
		CString pFileName = strFilePath;

		ShellExecute(0, "open", strFilePath, NULL, NULL, SW_SHOWNORMAL);
	}
}

void CSettingView::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	int i = 0;
	CFormView::OnClose();
}

void CSettingView::OnCancelMode() 
{
	CFormView::OnCancelMode();
	
	// TODO: Add your message handler code here
	
}

BOOL CSettingView::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	return CFormView::PreTranslateMessage(pMsg);
}

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

void CSettingView::Chgset()
{
	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;
			}
		}
	}
}

⌨️ 快捷键说明

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