123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463 |
- #include "stdafx.h"
- #include "DlgDevice.h"
- #include "StringOperation.h"
- #include ".\dlgdevice.h"
- #include "MainFrm.h"
- #include "resource.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDlgDevice property page
- IMPLEMENT_DYNCREATE(CDlgDevice, CPropertyPage)
- CDlgDevice::CDlgDevice() : CPropertyPage(CDlgDevice::IDD)
- , m_nCommuniteType(0)
- , m_nProtocolType(0)
- , m_strProtocolName(_T(""))
- , m_nDevEnable(0)
- , m_nCollectDev(0)
- , m_strIniName(_T(""))
- , m_strReserved1(_T(""))
- , m_strReserved2(_T(""))
- , m_strReserved3(_T(""))
- , m_strReserved4(_T(""))
- , m_strReserved5(_T(""))
- , m_nReserved1(0)
- , m_nReserved2(0)
- , m_nReserved3(0)
- , m_nReserved4(0)
- , m_nReserved5(0)
- , m_bReserved1(FALSE)
- , m_bReserved2(FALSE)
- , m_bReserved3(FALSE)
- , m_bReserved4(FALSE)
- , m_bReserved5(FALSE)
- {
- //{{AFX_DATA_INIT(CDlgDevice)
- m_nDevDriverID = -1;
- m_nDevFactoryID = -1;
- m_nDevTypeID = -1;
- //}}AFX_DATA_INIT
- m_bIsStu2000 = false;
- }
- CDlgDevice::~CDlgDevice()
- {
- }
- void CDlgDevice::DoDataExchange(CDataExchange* pDX)
- {
- CPropertyPage::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDlgDevice)
- //}}AFX_DATA_MAP
- DDX_Control(pDX, IDC_TREE_DEVICE_FOLDER, m_ctrlDevFolder);
- //DDX_Control(pDX, IDC_LIST_DEVICE, m_ctrlDevice);
- DDX_Radio(pDX, IDC_RADIO_COMM, m_nCommuniteType);
- DDX_CBIndex(pDX, IDC_COMBO_PROCOTOL_TYPE, m_nProtocolType);
- DDX_Text(pDX, IDC_EDT_DLL_NAME, m_strProtocolName);
- DDX_Check(pDX, IDC_CHK_ENABLE, m_nDevEnable);
- DDX_Check(pDX, IDC_CHK_COLLECT_DEV, m_nCollectDev);
- DDX_Text(pDX, IDC_EDT_INI_NAME, m_strIniName);
- }
- BEGIN_MESSAGE_MAP(CDlgDevice, CPropertyPage)
- //{{AFX_MSG_MAP(CDlgDevice)
- //}}AFX_MSG_MAP
- ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_DEVICE_FOLDER, OnTvnSelchangedTreeDeviceFolder)
- ON_BN_CLICKED(IDC_BTN_SEL_DLL, OnBnClickedBtnSelDll)
- ON_BN_CLICKED(IDC_BTN_SEL_INI, OnBnClickedBtnSelIni)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDlgDevice message handlers
- BOOL CDlgDevice::OnInitDialog()
- {
- CPropertyPage::OnInitDialog();
- // TODO: 在此添加额外的初始化
- if( !m_imagelistTree )
- {
- m_imagelistTree.Create(IDB_ADD_DEVICE, 16, 16, RGB(255,255,255));
- }
- m_ctrlDevFolder.SetImageList(&m_imagelistTree, TVSIL_NORMAL);
- // 串口通信设备
- if( ((CButton *)GetDlgItem(IDC_RADIO_COMM))->GetCheck() )
- {
- m_nCommuniteTypeOld = 0;
- }
- // 网络通信设备
- else if( ((CButton *)GetDlgItem(IDC_RADIO_NET))->GetCheck() )
- {
- m_nCommuniteTypeOld = 1;
- }
- //
- UpdateData(TRUE);
- if( m_operation == NEW )
- {
- m_nCommuniteType = 0;
- m_nProtocolType = 0;
- m_nDevEnable = 1;
- }
- UpdateData(FALSE);
- ListDeviceTypes();
- return TRUE; // return TRUE unless you set the focus to a control
- // 异常: OCX 属性页应返回 FALSE
- }
- void CDlgDevice::ListDeviceTypes(HTREEITEM hItemParent)
- {
- HTREEITEM hItemDrive, hItemFactory, hItemType;
- int nDevDriveCount, nDevFactoryCount, nDevTypeCount;
- list<string> listDriveID, listDriveName;
- list<string> listFactoryID, listFactoryName;
- list<string> listDevTypeID, listDevTypeName;
- list<string>::iterator itDriverID, itDriverName;
- list<string>::iterator itFactoryID, itFactoryName;
- list<string>::iterator itDevTypeID, itDevTypeName;
- //获取设备驱动列表
- nDevDriveCount = CDBInterface::GetInstancePtr()->GetDevDriveList(listDriveID, listDriveName);
- if( nDevDriveCount <= 0 ) return;
- for( itDriverID = listDriveID.begin(), itDriverName = listDriveName.begin();
- itDriverID != listDriveID.end() && itDriverName != listDriveName.end();
- itDriverID++, itDriverName++)
- {
- hItemDrive = m_ctrlDevFolder.InsertItem((*itDriverName).c_str(), 0, 1, hItemParent);
- //获取设备驱动对应的厂家列表
- nDevFactoryCount = CDBInterface::GetInstancePtr()->GetDevFactoryList( atoi((*itDriverID).c_str()), listFactoryID, listFactoryName);
- if( nDevFactoryCount <= 0 )
- {
- continue;
- }
- for( itFactoryID = listFactoryID.begin(), itFactoryName = listFactoryName.begin();
- itFactoryID != listFactoryID.end() && itFactoryName != listFactoryName.end();
- itFactoryID++, itFactoryName++)
- {
- hItemFactory = m_ctrlDevFolder.InsertItem((*itFactoryName).c_str(), 0, 1, hItemDrive);
-
- //获取指定厂家设备型号列表
- nDevTypeCount = CDBInterface::GetInstancePtr()->GetDevTypeList(
- atoi((*itDriverID).c_str()),
- atoi((*itFactoryID).c_str()),
- listDevTypeID, listDevTypeName );
- if( nDevTypeCount <= 0 )
- {
- continue;
- }
- for( itDevTypeID = listDevTypeID.begin(), itDevTypeName = listDevTypeName.begin();
- itDevTypeID != listDevTypeID.end() && itDevTypeName != listDevTypeName.end();
- itDevTypeID++, itDevTypeName++)
- {
- hItemType = m_ctrlDevFolder.InsertItem((*itDevTypeName).c_str(), 2, 2, hItemFactory);
- if( strcmp(m_strDevDriveName, (*itDriverName).c_str()) == 0 &&
- strcmp(m_strDevFactoryName, (*itFactoryName).c_str()) == 0 &&
- strcmp(m_strDevTypeName, (*itDevTypeName).c_str()) == 0 )
- {
- m_ctrlDevFolder.SelectItem( hItemType );
- }
- }
- for( itDevTypeID = listDevTypeID.begin(), itDevTypeName = listDevTypeName.begin();
- itDevTypeID != listDevTypeID.end() && itDevTypeName != listDevTypeName.end(); )
- {
- listDevTypeID.erase( itDevTypeID++ );
- listDevTypeName.erase( itDevTypeName++ );
- }
- }
-
- for( itFactoryID = listFactoryID.begin(), itFactoryName = listFactoryName.begin();
- itFactoryID != listFactoryID.end() && itFactoryName != listFactoryName.end(); )
- {
- listFactoryID.erase( itFactoryID++ );
- listFactoryName.erase( itFactoryName++ );
- }
- }
- for( itDriverID = listFactoryID.begin(), itDriverName = listFactoryName.begin();
- itDriverID != listFactoryID.end() && itDriverName != listFactoryName.end(); )
- {
- listDriveID.erase( itDriverID++ );
- listDriveName.erase( itDriverName++ );
- }
- }
- BOOL CDlgDevice::OnSetActive()
- {
- // TODO: 在此添加专用代码和/或调用基类
- //CPropertySheet* pParent=(CPropertySheet*)GetParent();
- //pParent->GetDlgItem(ID_WIZNEXT)->EnableWindow(FALSE);
- //pParent->GetDlgItem(ID_WIZBACK)->ShowWindow(FALSE);
- CPropertySheet* pParent=(CPropertySheet*)GetParent();
- pParent->SetWizardButtons(PSWIZB_NEXT);
- return CPropertyPage::OnSetActive();
- }
- void CDlgDevice::SelChangedTreeDeviceFolder(HTREEITEM hItemSelect)
- {
- CPropertySheet* pParent=(CPropertySheet*)GetParent();
- CString strSelect = m_ctrlDevFolder.GetItemText( hItemSelect );
- CString strDevDriveName = "", strDevFactoryName = "", strDevTypeName = "";
-
- HTREEITEM hItemParent = m_ctrlDevFolder.GetParentItem( hItemSelect );
- if( hItemParent != NULL )
- {
- strDevFactoryName = m_ctrlDevFolder.GetItemText( hItemParent );
- m_strDevFactoryName = strDevFactoryName;
- hItemParent = m_ctrlDevFolder.GetParentItem( hItemParent );
- if( hItemParent != NULL )
- {
- strDevTypeName = strSelect;
- m_strDevTypeName = strDevTypeName;
- strDevDriveName = m_ctrlDevFolder.GetItemText( hItemParent );
- m_strDevDriveName = strDevDriveName;
- pParent->GetDlgItem(ID_WIZNEXT)->EnableWindow(TRUE);
- }
- else
- {
- pParent->GetDlgItem(ID_WIZNEXT)->EnableWindow(FALSE);
- return;
- }
- }
- else
- {
- pParent->GetDlgItem(ID_WIZNEXT)->EnableWindow(FALSE);
- return;
- }
- CHAR szDevDriveID[MAX_ID + 1] = {0};
- CHAR szDevFactoryID[MAX_ID + 1] = {0};
- CHAR szDevTypeID[MAX_ID + 1] = {0};
- //获取设备驱动ID
- CDBInterface::GetInstancePtr()->GetDevDriveID((char *)(LPCTSTR)strDevDriveName, szDevDriveID);
- m_nDevDriverID = atoi(szDevDriveID);
- //获取设备厂家ID
- if( m_nDevDriverID > 0 )
- {
- CDBInterface::GetInstancePtr()->GetDevFactoryID(m_nDevDriverID, (char *)(LPCTSTR)strDevFactoryName, szDevFactoryID);
- m_nDevFactoryID = atoi(szDevFactoryID);
- }
- //获取设备型号ID
- if( m_nDevDriverID > 0 && m_nDevFactoryID > 0 )
- {
- CDBInterface::GetInstancePtr()->GetDevTypeID(m_nDevDriverID, m_nDevFactoryID, (char *)(LPCTSTR)strDevTypeName, szDevTypeID);
- m_nDevTypeID = atoi(szDevTypeID);
- }
- }
- void CDlgDevice::OnTvnSelchangedTreeDeviceFolder(NMHDR *pNMHDR, LRESULT *pResult)
- {
- LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
- // TODO: 在此添加控件通知处理程序代码
- HTREEITEM hItemSelect = pNMTreeView->itemNew.hItem;
- SelChangedTreeDeviceFolder( hItemSelect );
- *pResult = 0;
- }
- HTREEITEM CDlgDevice::FindTreeNode( CTreeCtrl *pTree, HTREEITEM HItem, HTREEITEM HItemSelect )
- {
- HTREEITEM HCurrent;
- HCurrent = pTree->GetChildItem( HItem );
- CString strTemp;
- while( HCurrent != NULL )
- {
- if( HCurrent == HItemSelect )
- {
- break;
- }
- HCurrent = pTree->GetNextSiblingItem(HCurrent);
- }
-
- return HCurrent;
- }
- LRESULT CDlgDevice::OnWizardNext()
- {
- // TODO: 在此添加专用代码和/或调用基类
- CMainFrame *pMainFrm=(CMainFrame*)AfxGetApp()->m_pMainWnd;
- CString strUID;
- CHAR szDevNum[MAX_ID + 1] = {0};
- strUID.Format("%d.%d.%d", m_nDevDriverID, m_nDevFactoryID, m_nDevTypeID);
- CDBInterface::GetInstancePtr()->FindDevInfoByUID((char *)(LPCTSTR)strUID, szDevNum);
- CString strDllName;
- GetDlgItem(IDC_EDT_DLL_NAME)->GetWindowText(strDllName);
- strDllName.MakeLower();
- if( strDllName=="stu2000.dll" )
- m_bIsStu2000 = true;
- else
- m_bIsStu2000 = false;
- if( m_operation == CDlgDevice::NEW )
- {
- pMainFrm->m_wndComport.m_strUID.Format("%d.%d.%d.%d", m_nDevDriverID, m_nDevFactoryID, m_nDevTypeID, atoi(szDevNum) + 1);
- pMainFrm->m_wndComport.m_nTimeout = 10000;
- pMainFrm->m_wndComport.m_nDevAddr = 1;
- pMainFrm->m_wndComport.m_nCommPort = 1;
- pMainFrm->m_wndComport.m_nRate = 3;
- pMainFrm->m_wndComport.m_nCheckCode = 0;
- pMainFrm->m_wndComport.m_nDataBit = 1;
- pMainFrm->m_wndComport.m_nStopBit = 0;
- pMainFrm->m_wndComport.m_nNetIP = htonl(inet_addr("192.168.1.111"));
- pMainFrm->m_wndComport.m_nNetPort = 5555;
- // 串口通信设备
- if( ((CButton *)GetDlgItem(IDC_RADIO_COMM))->GetCheck() )
- {
- pMainFrm->m_wndComport.m_nCommunicateMode = 0;
- }
- // 网络通信设备
- else if( ((CButton *)GetDlgItem(IDC_RADIO_NET))->GetCheck() )
- {
- pMainFrm->m_wndComport.m_nCommunicateMode = 1;
- }
- if( pMainFrm->m_wndComport )
- pMainFrm->m_wndComport.ChangeCtrlState( );
- }
- else if( m_operation == CDlgDevice::EDIT )
- {
- CString str1,str2;
- int nPos=0;
- for( int i=pMainFrm->m_wndComport.m_strUID.GetLength()-1;i>0;i-- )
- {
- if( pMainFrm->m_wndComport.m_strUID[i]=='.' )
- {
- str1 = pMainFrm->m_wndComport.m_strUID.Left( i );
- break;
- }
- }
- str2.Format("%d.%d.%d", m_nDevDriverID, m_nDevFactoryID, m_nDevTypeID );
- CString sTemp;
- sTemp.Format("%d.%d.%d.%d", m_nDevDriverID, m_nDevFactoryID, m_nDevTypeID, atoi(szDevNum) + 1);
- //if( pMainFrm->m_wndComport )
- {
- m_sUidOld = pMainFrm->m_wndComport.m_strUID;
- pMainFrm->m_wndComport.m_strUID2 = sTemp;
- if( str1!=str2 )
- pMainFrm->m_wndComport.m_strUID = sTemp;
- }
- //pMainFrm->m_wndComport.m_nCommunicateMode = m_nCommuniteType;
- // 串口通信设备
- if( ((CButton *)GetDlgItem(IDC_RADIO_COMM))->GetCheck() )
- {
- pMainFrm->m_wndComport.m_nCommunicateMode = 0;
- }
- // 网络通信设备
- else if( ((CButton *)GetDlgItem(IDC_RADIO_NET))->GetCheck() )
- {
- pMainFrm->m_wndComport.m_nCommunicateMode = 1;
- }
- //
- m_nCommuniteType = pMainFrm->m_wndComport.m_nCommunicateMode;
- // 网络设备
- if( m_nCommuniteType == 1 )
- {
- if( m_nCommuniteTypeOld==1 )
- {
- pMainFrm->m_wndComport.m_nTimeout = 10000;
- if( !m_bIsStu2000 )
- pMainFrm->m_wndComport.m_nDevAddr = 1;
- pMainFrm->m_wndComport.m_nCommPort = 1;
- pMainFrm->m_wndComport.m_nRate = 3;
- pMainFrm->m_wndComport.m_nCheckCode = 0;
- pMainFrm->m_wndComport.m_nDataBit = 1;
- pMainFrm->m_wndComport.m_nStopBit = 0;
- }
- if( m_nCommuniteTypeOld==0 )//&& pMainFrm->m_wndComport )
- {
- pMainFrm->m_wndComport.m_nNetIP = htonl(inet_addr("192.168.1.111"));
- pMainFrm->m_wndComport.m_nNetPort = 5555;
- }
- }
- else if( m_nCommuniteType == 0 )// 串口通信设备
- {
- if( m_nCommuniteTypeOld==1 )
- {
- pMainFrm->m_wndComport.m_nTimeout = 10000;
- pMainFrm->m_wndComport.m_nDevAddr = 1;
- pMainFrm->m_wndComport.m_nCommPort = 1;
- pMainFrm->m_wndComport.m_nRate = 3;
- pMainFrm->m_wndComport.m_nCheckCode = 0;
- pMainFrm->m_wndComport.m_nDataBit = 1;
- pMainFrm->m_wndComport.m_nStopBit = 0;
- }
- }
- if( pMainFrm->m_wndComport )
- pMainFrm->m_wndComport.ChangeCtrlState( );
- }
- CString strDriverName;
- GetDlgItem(IDC_EDT_DLL_NAME)->GetWindowText(strDriverName);
- if( !strDriverName.Compare("") || strUID=="-1.-1.-1" )
- {
- MessageBox(g_strSelDevice,g_strTip,MB_ICONWARNING);
- return TRUE;
- }
- return CPropertyPage::OnWizardNext();
- }
- void CDlgDevice::OnBnClickedBtnSelDll()
- {
- // TODO: 在此添加控件通知处理程序代码
- DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
- CString strFindFile = "";
- LPSTR lpszFile = (char*)(const char*)strFindFile;
- LPSTR lpszFilter = "Module File(*.dll)|*.dll||";
- CFileDialog dlg(TRUE,".dll",lpszFile,dwFlags,lpszFilter);
- if(dlg.DoModal() == IDOK)
- {
- strFindFile = dlg.GetFileName();
- GetDlgItem(IDC_EDT_DLL_NAME)->SetWindowText( strFindFile );
- }
- }
- void CDlgDevice::OnBnClickedBtnSelIni()
- {
- // TODO: 在此添加控件通知处理程序代码
- DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
- CString strFindFile = "";
- LPSTR lpszFile = (char*)(const char*)strFindFile;
- LPSTR lpszFilter = "Module File(*.ini)|*.ini||";
- CFileDialog dlg(TRUE,".ini",lpszFile,dwFlags,lpszFilter);
- if(dlg.DoModal() == IDOK)
- {
- strFindFile = dlg.GetFileName();
- GetDlgItem(IDC_EDT_INI_NAME)->SetWindowText( strFindFile );
- }
- }
|