// SCPProperties.cpp : implementation file // #include "stdafx.h" #include "CLDMWLSCP.h" #include "SCPProperties.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // SCPProperties property page IMPLEMENT_DYNCREATE(CSCPProperties, CPropertyPage) CSCPProperties::CSCPProperties() : CPropertyPage(CSCPProperties::IDD) { //{{AFX_DATA_INIT(CSCPProperties) m_sClientName = _T(""); m_sServerName = _T(""); m_uServerPort = 0; m_uMaxClients = 4; //}}AFX_DATA_INIT } CSCPProperties::~CSCPProperties() { } void CSCPProperties::DoDataExchange(CDataExchange* pDX) { CPropertyPage::DoDataExchange(pDX); //{{AFX_DATA_MAP(CSCPProperties) DDX_Control(pDX, IDC_BUTSTOP, m_ButStop); DDX_Control(pDX, IDC_BUTSTART, m_ButStart); DDX_Control(pDX, IDC_EDSERVERPORT, m_cServerPort); DDX_Control(pDX, IDC_EDSERVERNAME, m_cServerName); DDX_Control(pDX, IDC_BUT_DELETE, m_cDeleteClient); DDX_Control(pDX, IDC_BUTADDTOLIST, m_cAddToList); DDX_Control(pDX, IDC_EDCLIENTNAME, m_cClientName); DDX_Control(pDX, IDC_LIST_CLIENTS, m_ClientsList); DDX_Text(pDX, IDC_EDCLIENTNAME, m_sClientName); DDX_Text(pDX, IDC_EDSERVERNAME, m_sServerName); DDX_Text(pDX, IDC_EDSERVERPORT, m_uServerPort); DDV_MinMaxUInt(pDX, m_uServerPort, 1, 100000); DDX_Text(pDX, IDC_EDIT_MAX_CLIENTS, m_uMaxClients); DDV_MinMaxUInt(pDX, m_uMaxClients, 0, 1000); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CSCPProperties, CPropertyPage) //{{AFX_MSG_MAP(CSCPProperties) ON_BN_CLICKED(IDC_BUTADDTOLIST, OnButaddtolist) ON_BN_CLICKED(IDC_BUT_DELETE, OnButDelete) ON_NOTIFY(NM_CLICK, IDC_LIST_CLIENTS, OnClickListClients) ON_BN_CLICKED(IDC_BUTSTOP, OnButstop) ON_BN_CLICKED(IDC_BUTSTART, OnButstart) //}}AFX_MSG_MAP END_MESSAGE_MAP() BOOL CSCPProperties::OnInitDialog() { CPropertyPage::OnInitDialog(); // Build clients list m_ClientsList.InsertColumn(0, "Calling AE Title", LVCFMT_LEFT, 203, 0); m_ClientsList.InsertColumn(1, "IP Address", LVCFMT_LEFT, 203, 1); m_ClientsList.SetExtendedStyle(m_ClientsList.GetExtendedStyle() | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); // Read data from registry ReadDataFromRegistry(); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } ///////////////////////////////////////////////////////////////////////////// // SCPProperties message handlers // Read data from the registry L_VOID CSCPProperties::ReadDataFromRegistry() { long lRet; m_sServerName = "LEAD_SERVER"; m_uServerPort = 104; lRet = m_cMyRegKey.Open(HKEY_CURRENT_USER, REGISTRY_LOCATION); if (lRet == ERROR_SUCCESS) { L_CHAR szBufValue[1000]; DWORD dwCount; // Server Name dwCount = sizeof(szBufValue); lRet = m_cMyRegKey.QueryValue(szBufValue, "sServerName", &dwCount); if (lRet == ERROR_SUCCESS) { m_sServerName = szBufValue; } DWORD dwValue; // Server port number lRet = m_cMyRegKey.QueryValue(dwValue, "uServerPort"); if (lRet == ERROR_SUCCESS) { m_uServerPort = dwValue; } // DB Path Path dwCount = sizeof(szBufValue); lRet = m_cMyRegKey.QueryValue(szBufValue, "sDatabaseName", &dwCount); if (lRet == ERROR_SUCCESS) { m_sDataBasePath = szBufValue; ((CPropertySheetDlg*)GetParent())->m_sDBFileName = szBufValue; } // Maximum Clients lRet = m_cMyRegKey.QueryValue(dwValue, "uMaxClients"); if (lRet == ERROR_SUCCESS) { m_uMaxClients = dwValue; } // Reading clinets for the list DWORD uResult; L_UINT uCurIdx = 0; L_CHAR szValueName[MAX_PATH]; DWORD dwNameCount; HKEY hkListKey; L_UCHAR szValue[130]; DWORD dwType; uResult = RegOpenKeyEx(HKEY_CURRENT_USER, REGISTRY_LOCATION_CLIENTS_LIST, NULL, KEY_READ, &hkListKey); if (uResult == ERROR_SUCCESS) { while (uResult == ERROR_SUCCESS) { dwCount = sizeof(szValue); dwNameCount = sizeof(szValueName); szValueName[0] = '\0'; szValue[0] = '\0'; dwType = REG_SZ; uResult = RegEnumValue(hkListKey, uCurIdx, szValueName, &dwNameCount, NULL, //NULL, NULL, NULL); &dwType, szValue, &dwCount); if (uResult == ERROR_SUCCESS) { // Parse the returned string and fill it in the list ParseThenFill(szValue); } uCurIdx++; } RegCloseKey(hkListKey); } m_cMyRegKey.Close(); } UpdateData(FALSE); } L_VOID CSCPProperties::ParseThenFill(CString sKeyVlaue) { L_INT nPos = sKeyVlaue.Find("##"); if (nPos < 0) return; // Add Client name and IP to the list L_UINT nRowsCount; nRowsCount = m_ClientsList.GetItemCount(); m_ClientsList.InsertItem(nRowsCount, sKeyVlaue.Left(nPos)); m_ClientsList.SetItem( nRowsCount, 1, LVIF_TEXT, sKeyVlaue.Right(sKeyVlaue.GetLength() - (nPos + 2)), 0, 0, LVIS_SELECTED, 0); } // Save the data in the registry L_VOID CSCPProperties::SaveInRegistry() { long lRet; lRet = m_cMyRegKey.Create(HKEY_CURRENT_USER, REGISTRY_LOCATION); if (lRet == ERROR_SUCCESS) { // Server name m_cMyRegKey.SetValue(m_sServerName, "sServerName"); // Server port number m_cMyRegKey.SetValue(m_uServerPort, "uServerPort"); // Maximum clients m_cMyRegKey.SetValue(m_uMaxClients, "uMaxClients"); // Adding sub key for the list L_INT uIndex = -1; L_UINT Count = 0; CString sItemName = ""; CString sItemValue = ""; // Delete the old list items HKEY hkListKey; L_UINT uResult = RegOpenKeyEx(HKEY_CURRENT_USER, REGISTRY_LOCATION_CLIENTS_LIST, NULL, KEY_READ, &hkListKey); if (uResult == ERROR_SUCCESS) { RegDeleteKey(HKEY_CURRENT_USER, REGISTRY_LOCATION_CLIENTS_LIST); } // Cretae a new key and fill the list of data inside it lRet = m_cMyRegKey.Create(HKEY_CURRENT_USER, REGISTRY_LOCATION_CLIENTS_LIST); if (lRet == ERROR_SUCCESS) { uIndex = m_ClientsList.GetNextItem(uIndex, LVNI_ALL); while (uIndex != -1) { Count++; sItemValue.Format("%s##%s", m_ClientsList.GetItemText(uIndex, 0), m_ClientsList.GetItemText(uIndex, 1)); sItemName.Format("Client%d", Count); m_cMyRegKey.SetValue(sItemValue, sItemName); uIndex = m_ClientsList.GetNextItem(uIndex, LVNI_ALL); } } m_cMyRegKey.Close(); } } void CSCPProperties::OnButaddtolist() { UpdateData(TRUE); if (m_sClientName.IsEmpty()) { MessageBox("Please fill the Clinet Name field!", "Modality work-list provider", MB_OK | MB_ICONEXCLAMATION); m_cClientName.SetFocus(); return; } CString sClientIP; GetDlgItemText(IDC_IPADDRESS_CLIENT, sClientIP); L_UINT nRowsCount; nRowsCount = m_ClientsList.GetItemCount(); m_ClientsList.InsertItem(nRowsCount, m_sClientName); m_ClientsList.SetItem( nRowsCount, 1, LVIF_TEXT, sClientIP, 0, 0, LVIS_SELECTED, 0); m_sClientName = ""; UpdateData(FALSE); SetDlgItemText(IDC_IPADDRESS_CLIENT, ""); m_cClientName.SetFocus(); } L_VOID CSCPProperties::OnButDelete() { L_UINT nRowsCount; // Get items count nRowsCount = m_ClientsList.GetItemCount(); if (nRowsCount == 0) { return; } // Get the selected item POSITION pos = m_ClientsList.GetFirstSelectedItemPosition(); if (m_ClientsList.DeleteItem(m_ClientsList.GetNextSelectedItem(pos)) == TRUE) { m_cAddToList.EnableWindow(TRUE); } m_cDeleteClient.EnableWindow(FALSE); m_ClientsList.SetFocus(); } void CSCPProperties::OnClickListClients(NMHDR* pNMHDR, LRESULT* pResult) { L_UINT nRowsCount; // Get items count nRowsCount = m_ClientsList.GetSelectedCount(); if (nRowsCount == 0) { m_cDeleteClient.EnableWindow(FALSE); return; } else { m_cDeleteClient.EnableWindow(TRUE); } *pResult = 0; } void CSCPProperties::OnButstop() { // Stop the connection CWaitCursor CurWait; ((CPropertySheetDlg*)GetParent())->m_MWListSCP.StopListening(); // Status m_ButStart.EnableWindow(TRUE); m_ButStop.EnableWindow(FALSE); CurWait.Restore(); } void CSCPProperties::OnButstart() { if (!UpdateData(TRUE)) return; if (m_sServerName.IsEmpty()) { MessageBox("Please specify an AE Title for the SCP!","Modlaity Worklist - SCP", MB_OK|MB_ICONEXCLAMATION); m_cServerName.SetFocus(); return; } m_ButStart.EnableWindow(FALSE); CWaitCursor CurWait; L_UINT uClientsCount = m_ClientsList.GetItemCount(); pCLIENTINFO AllClientsInfo = new CLIENTINFO[uClientsCount]; L_INT uIndex = -1; uIndex = m_ClientsList.GetNextItem(uIndex, LVNI_ALL); while (uIndex != -1) { // Get the information of current client lstrcpyn(AllClientsInfo[uIndex].szClientName, (L_CHAR*)(LPCTSTR)m_ClientsList.GetItemText(uIndex, 0), sizeof(AllClientsInfo[uIndex].szClientName)); lstrcpyn(AllClientsInfo[uIndex].szClientIP, (L_CHAR*)(LPCTSTR)m_ClientsList.GetItemText(uIndex, 1), sizeof(AllClientsInfo[uIndex].szClientIP)); uIndex = m_ClientsList.GetNextItem(uIndex, LVNI_ALL); } // Set clients info in the class ((CPropertySheetDlg*)GetParent())->m_MWListSCP.SetWorkingDBName((L_CHAR*)(LPCTSTR)m_sDataBasePath); L_INT nRet =((CPropertySheetDlg*)GetParent())->m_MWListSCP.SetClientsInfo(AllClientsInfo, uClientsCount); if (nRet != DICOM_SUCCESS) { MessageBox("Number of clients is not as in the list.\n\rThe SCP will not started!", "Modality work-list provider", MB_OK | MB_ICONEXCLAMATION); CurWait.Restore(); m_ButStart.EnableWindow(TRUE); return; } // Free the allocated structure if (AllClientsInfo) { delete [] AllClientsInfo; AllClientsInfo = NULL; } // Save values in registry SaveInRegistry(); // Start the SCP nRet = ((CPropertySheetDlg*)GetParent())->m_MWListSCP.StartListening(m_uServerPort, m_uMaxClients, (L_CHAR*)(LPCTSTR)m_sServerName); if (nRet != DICOM_SUCCESS) { MessageBox("SCP failed to start listening!", "Modality work-list provider", MB_OK | MB_ICONEXCLAMATION); CurWait.Restore(); return; } // Status m_ButStop.EnableWindow(TRUE); CurWait.Restore(); ((CPropertySheetDlg*)GetParent())->SetActivePage(2); }