// Page1.cpp : implementation file // #include "stdafx.h" #include "DicomMWL.h" #include "Page1.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPage1 property page IMPLEMENT_DYNCREATE(CPage1, CPropertyPage) CPage1::CPage1(int nType) : CPropertyPage(CPage1::IDD, nType == CONFIGURE_MWL_SERVER ? IDS_PAGE1 : IDS_PAGE7) { m_nServerPort = 0; m_nType = nType; m_pSheet = NULL; m_bValidateServer = FALSE; m_bActive = FALSE; m_bWaitCursor = FALSE; NO_PAGE_HELP(); } CPage1::~CPage1() { } void CPage1::DoDataExchange(CDataExchange* pDX) { int bValidateServer = TRUE; CPropertyPage::DoDataExchange(pDX); CButton *pButton = (CButton *)GetDlgItem(IDC_RADIO_STORE_LOCAL); bValidateServer = (pButton==NULL) || (!pButton->GetCheck()); //{{AFX_DATA_MAP(CPage1) if ((bValidateServer) || (m_nType == CONFIGURE_MWL_SERVER)) { DDX_Text(pDX, IDC_EDIT_SERVER_AE, m_strServerAE); //DDV_MinChars(pDX, m_strServerAE, 1); DDX_Control(pDX, IDC_IPADDRESS_SERVER, m_ServerIP); DDX_Text(pDX, IDC_EDIT_SERVER_PORT, m_nServerPort); DDV_MinMaxInt(pDX, m_nServerPort, 0, 99999); DDX_Text(pDX, IDC_EDIT_CLIENT_AE, m_strClientAE); //DDV_MinChars(pDX, m_strClientAE, 1); } DDX_Control(pDX, IDC_BUTTON_VERIFY, m_ButtonVerify); DDX_Control(pDX, IDC_BUTTON_STORE, m_ButtonStore); DDX_Control(pDX, IDC_EDIT_LOG, m_Log); DDX_Text(pDX, IDC_STATIC_INSTRUCTIONS, m_strStaticInstructions); DDX_Radio(pDX, IDC_RADIO_STORE_REMOTE, m_bValidateServer); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPage1, CPropertyPage) //{{AFX_MSG_MAP(CPage1) ON_BN_CLICKED(IDC_BUTTON_VERIFY, OnButtonVerify) ON_BN_CLICKED(IDC_BUTTON_STORE, OnButtonStore) ON_EN_CHANGE(IDC_EDIT_CLIENT_AE, OnChangeEditClientAe) ON_EN_CHANGE(IDC_EDIT_SERVER_AE, OnChangeEditServerAe) ON_EN_CHANGE(IDC_EDIT_SERVER_PORT, OnChangeEditServerPort) ON_EN_CHANGE(IDC_IPADDRESS_SERVER, OnChangeEditServerIp) ON_WM_SETCURSOR() ON_BN_CLICKED(IDC_RADIO_STORE_LOCAL, OnRadioStoreLocal) ON_BN_CLICKED(IDC_RADIO_STORE_REMOTE, OnRadioStoreRemote) //}}AFX_MSG_MAP ON_MESSAGE(WM_DICOM_MSG, OnDicomMsg) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPage1 message handlers BOOL CPage1::OnInitDialog() { CPropertyPage::OnInitDialog(); if (m_nType == CONFIGURE_MWL_SERVER) { m_strServerAE = CGlobals::m_strMWLServerAE; m_nServerPort = CGlobals::m_nMWLServerPort; m_strClientAE = CGlobals::m_strMWLClientAE; m_ServerIP.SetAddress(CGlobals::m_lMWLServerIP); m_strStaticInstructions.LoadString(IDS_PAGE1_INSTR); } else { m_strServerAE = CGlobals::m_strStorageServerAE; m_nServerPort = CGlobals::m_nStorageServerPort; if (CGlobals::m_strStorageClientAE.GetLength() == 0) m_strClientAE = CGlobals::m_strMWLClientAE; else m_strClientAE = CGlobals::m_strStorageClientAE; m_ServerIP.SetAddress(CGlobals::m_lStorageServerIP); m_strStaticInstructions.LoadString(IDS_PAGE7_INSTR); GetDlgItem(IDC_BUTTON_STORE)->SetWindowText("&Send to Storage Server"); } UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } BOOL CPage1::OnSetActive() { m_bActive = TRUE; m_pSheet = (CMyPropertySheet *)GetParent(); int bServerValid = FALSE; if (m_nType == CONFIGURE_MWL_SERVER) { //GetDlgItem(IDC_CHECK_CONFIGURE_SERVER)->ShowWindow(SW_HIDE); ShowRadioButtons(SW_HIDE); bServerValid = IsMWLServerValid(); m_ButtonStore.ShowWindow(SW_HIDE); m_ButtonVerify.ShowWindow(SW_SHOWNORMAL); m_bValidateServer = TRUE; } else // (m_nType == CONFIGURE_STORAGE_SERVER) { CString strGroupBoxText; strGroupBoxText.LoadString(IDS_GROUP_SERVER); GetDlgItem(IDC_STATIC_SERVER)->SetWindowText(strGroupBoxText); //GetDlgItem(IDC_CHECK_CONFIGURE_SERVER)->ShowWindow(SW_SHOW); ShowRadioButtons(SW_SHOWNORMAL); bServerValid = IsStorageServerValid(); m_ButtonStore.ShowWindow(SW_SHOWNORMAL); m_ButtonStore.EnableWindow(CGlobals::m_pDS != NULL); m_ButtonVerify.ShowWindow(SW_HIDE); } m_pSheet->SetWizardButtons(PSWIZB_BACK | bServerValid * PSWIZB_NEXT); //m_bValidateServer = TRUE; UpdateData(FALSE); return CPropertyPage::OnSetActive(); } void CPage1::ShowRadioButtons(int nCmdShow) { GetDlgItem(IDC_RADIO_STORE_LOCAL)->ShowWindow(nCmdShow); GetDlgItem(IDC_RADIO_STORE_REMOTE)->ShowWindow(nCmdShow); } void CPage1::OnButtonVerify() { if (UpdateData(TRUE) == 0) return; EnableValidateServer(FALSE); m_bWaitCursor = TRUE; SendMessage(WM_SETCURSOR); m_pSheet->SetWizardButtons(0); m_Log.Clear(); LMyDicomNet *pMyDicomNet = m_pSheet->m_pMyDicomNet; if (pMyDicomNet) { pMyDicomNet->m_nCommandType = LMyDicomNet::CECHO; pMyDicomNet->m_pWnd = this; pMyDicomNet->m_pLog = &m_Log; //pMyDicomNet->m_pSheet = m_pSheet; pMyDicomNet->m_strServerAE = m_strServerAE; pMyDicomNet->m_strClientAE = m_strClientAE; CString strServerIP = m_ServerIP.IPtoString(); pMyDicomNet->Connect(NULL, 0, (LPSTR)(LPCSTR)strServerIP, m_nServerPort); } } /* void CPage1::OnCheckConfigureServer() { CButton *pButton = (CButton *)GetDlgItem(IDC_CHECK_CONFIGURE_SERVER); int bEnable = pButton->GetCheck(); EnableValidateServer(TRUE); m_pSheet->SetWizardButtons(bEnable ? PSWIZB_BACK : (PSWIZB_BACK | PSWIZB_NEXT)); } */ void CPage1::EnableValidateServer(int bEnable) { if (bEnable) { m_bWaitCursor = FALSE; SendMessage(WM_SETCURSOR); } // server GetDlgItem(IDC_STATIC_SERVER)->EnableWindow(bEnable); GetDlgItem(IDC_STATIC_SERVER_AE)->EnableWindow(bEnable); GetDlgItem(IDC_EDIT_SERVER_AE)->EnableWindow(bEnable); GetDlgItem(IDC_STATIC_SERVER_IP)->EnableWindow(bEnable); GetDlgItem(IDC_IPADDRESS_SERVER)->EnableWindow(bEnable); GetDlgItem(IDC_STATIC_SERVER_PORT)->EnableWindow(bEnable); GetDlgItem(IDC_EDIT_SERVER_PORT)->EnableWindow(bEnable); // client GetDlgItem(IDC_STATIC_CLIENT)->EnableWindow(bEnable); GetDlgItem(IDC_STATIC_CLIENT_AE)->EnableWindow(bEnable); GetDlgItem(IDC_EDIT_CLIENT_AE)->EnableWindow(bEnable); // Verify button GetDlgItem(IDC_BUTTON_VERIFY)->EnableWindow(bEnable); // Log //GetDlgItem(IDC_EDIT_LOG)->EnableWindow(bEnable); // Wizard buttons //m_pSheet->SetWizardButtons(bEnable ? 0 : (PSWIZB_BACK | PSWIZB_NEXT)); } LRESULT CPage1::OnDicomMsg(WPARAM wParam, LPARAM lParam) { EnableValidateServer(TRUE); m_pSheet->SetWizardButtons((wParam == LMyDicomNet::DICOM_MSG_SUCCESS)? (PSWIZB_BACK | PSWIZB_NEXT): PSWIZB_BACK ); CString strMsg; switch(wParam) { case LMyDicomNet::DICOM_MSG_SUCCESS: if (m_nType == CONFIGURE_MWL_SERVER) CGlobals::m_bMWLServerValid = TRUE; else // (m_nType == CONFIGURE_STORAGE_SERVER) { CGlobals::m_bStorageServerValid = TRUE; } break; case LMyDicomNet::DICOM_MSG_CONNECT_FAILED: strMsg.Format("Connect Failed Error[%d]\nPlease reconfigure server settings", lParam); MessageBox(strMsg, "Error", MB_ICONEXCLAMATION| MB_OK); if (m_nType == CONFIGURE_MWL_SERVER) CGlobals::m_bMWLServerValid = FALSE; else // (m_nType == CONFIGURE_STORAGE_SERVER) CGlobals::m_bStorageServerValid = FALSE; break; case LMyDicomNet::DICOM_MSG_ASSOCIATE_REJECT: strMsg.Format("Associate Reject. Server does not support requested operation."); MessageBox(strMsg, "Error", MB_ICONEXCLAMATION| MB_OK); if (m_nType == CONFIGURE_MWL_SERVER) CGlobals::m_bMWLServerValid = FALSE; else // (m_nType == CONFIGURE_STORAGE_SERVER) CGlobals::m_bStorageServerValid = FALSE; break; case LMyDicomNet::DICOM_MSG_CSTORE_RESULT: { L_UINT16 nStatus = (L_UINT16)lParam; strMsg = "CStore to Storage Server Result: " + LMyDicomNet::GetStatusString(nStatus); MessageBox(strMsg, "Upload Status", MB_OK); } break; case LMyDicomNet::DICOM_MSG_TIMEOUT: MessageBox(STR_TIMEOUT_MSG, "Warning", MB_ICONEXCLAMATION | MB_OK); break; } return 0; } LRESULT CPage1::OnWizardNext() { // TODO: Add your specialized code here and/or call the base class if (UpdateData(TRUE) == 0) return -1; if (m_nType == CONFIGURE_MWL_SERVER) { CGlobals::m_strMWLServerAE = m_strServerAE; CGlobals::m_nMWLServerPort = m_nServerPort; CGlobals::m_strMWLClientAE = m_strClientAE; m_ServerIP.GetAddress(CGlobals::m_lMWLServerIP); } else { CGlobals::m_strStorageServerAE = m_strServerAE; CGlobals::m_nStorageServerPort = m_nServerPort; CGlobals::m_strStorageClientAE = m_strClientAE; m_ServerIP.GetAddress(CGlobals::m_lStorageServerIP); } //return -1 to stay here CGlobals::SaveRegKeys(); return CPropertyPage::OnWizardNext(); } BOOL CPage1::OnKillActive() { m_bActive = FALSE; return CPropertyPage::OnKillActive(); } //Either //1. Stores the image locally //2. Sends image to a storage server void CPage1::OnButtonStore() { CButton *pButtonValidateServer = (CButton *)GetDlgItem(IDC_RADIO_STORE_REMOTE); if (pButtonValidateServer) m_bValidateServer = pButtonValidateServer->GetCheck(); if (m_bValidateServer) { if (0 == UpdateData(TRUE)) return; EnableValidateServer(FALSE); m_bWaitCursor = TRUE; SendMessage(WM_SETCURSOR); m_pSheet->SetWizardButtons(0); m_Log.Clear(); LMyDicomNet *pMyDicomNet = m_pSheet->m_pMyDicomNet; if (pMyDicomNet) { pMyDicomNet->m_nCommandType = LMyDicomNet::CSTORE; pMyDicomNet->m_pWnd = this; pMyDicomNet->m_pLog = &m_Log; pMyDicomNet->m_strServerAE = m_strServerAE; pMyDicomNet->m_strClientAE = m_strClientAE; pMyDicomNet->m_pStoreDS = CGlobals::m_pDS; CString strServerIP = m_ServerIP.IPtoString(); pMyDicomNet->Connect(NULL, 0, (LPSTR)(LPCSTR)strServerIP, m_nServerPort); } } else //store locally { StoreLocally(CGlobals::m_pDS); } } void CPage1::StoreLocally( LDicomDS *pDS) { if (!pDS)return; static CString strFileName = "mwl.dic"; static char szFilter[] = "Dicom (*.dic)|*.dic|All Files (*.*)|*.*||"; //MessageBox("Store Locally");CFileDialog dlg(FALSE); CFileDialog dlg( FALSE, ".dic", strFileName, OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST, szFilter ); if (dlg.DoModal() == IDOK) { L_UINT16 nRet = pDS->SaveDS((LPSTR)(LPCSTR)dlg.GetFileName(), DS_LITTLE_ENDIAN | DS_EXPLICIT_VR | DS_GROUP_LENGTHS); if (nRet != DICOM_SUCCESS) { CString strErr; strErr.Format("Error saving file %s: %d", dlg.GetFileName(), nRet); ::MessageBox(NULL, strErr, "Error", MB_OK | MB_ICONERROR); } } } int CPage1::IsStorageServerValid() { int nRet; DWORD lServerIP; m_ServerIP.GetAddress(lServerIP); nRet = (CGlobals::m_bStorageServerValid) && !m_strServerAE.CompareNoCase(CGlobals::m_strStorageServerAE) && (lServerIP == CGlobals::m_lStorageServerIP) && (m_nServerPort == CGlobals::m_nStorageServerPort) && !m_strClientAE.CompareNoCase(CGlobals::m_strStorageClientAE); return nRet; } int CPage1::IsMWLServerValid() { int nRet; DWORD lServerIP; m_ServerIP.GetAddress(lServerIP); nRet = (CGlobals::m_bMWLServerValid) && !m_strServerAE.CompareNoCase(CGlobals::m_strMWLServerAE) && (lServerIP == CGlobals::m_lMWLServerIP) && (m_nServerPort == CGlobals::m_nMWLServerPort) && !m_strClientAE.CompareNoCase(CGlobals::m_strMWLClientAE); return nRet; } void CPage1::UpdateWizardButtons() { m_pSheet->SetWizardButtons(PSWIZB_BACK); } void CPage1::OnChangeEditClientAe() { UpdateWizardButtons(); } void CPage1::OnChangeEditServerAe() { UpdateWizardButtons(); } void CPage1::OnChangeEditServerIp() { if (m_bActive) UpdateWizardButtons(); } void CPage1::OnChangeEditServerPort() { UpdateWizardButtons(); } BOOL CPage1::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { if (m_bWaitCursor) { SetCursor(LoadCursor(NULL, IDC_WAIT)); return TRUE; } else SetCursor(LoadCursor(NULL, IDC_ARROW)); return CPropertyPage::OnSetCursor(pWnd, nHitTest, message); } void CPage1::OnRadioStoreLocal() { EnableValidateServer(FALSE); m_pSheet->SetWizardButtons(PSWIZB_BACK | PSWIZB_NEXT); GetDlgItem(IDC_BUTTON_STORE)->SetWindowText("&Store Locally..."); } void CPage1::OnRadioStoreRemote() { int bServerValid = IsStorageServerValid(); EnableValidateServer(TRUE); m_pSheet->SetWizardButtons(PSWIZB_BACK | bServerValid * PSWIZB_NEXT); GetDlgItem(IDC_BUTTON_STORE)->SetWindowText("&Send to Storage Server"); }