// FFaxDF.cpp : implementation file // #include "stdafx.h" #include "CorpSms.h" #include "FFaxDF.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CFFaxDF dialog #include "MainFrm.h" #include "ProcessSocket.h" #include "DLG_Find_SmsBox.h" #include "DLG_SmsList_Export.h" CFFaxDF::CFFaxDF(CWnd* pParent /*=NULL*/) : CDialog(CFFaxDF::IDD, pParent) { //{{AFX_DATA_INIT(CFFaxDF) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_bInit = false; m_bRefresh = false; } void CFFaxDF::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CFFaxDF) DDX_Control(pDX, IDC_FAXDF_LIST, m_wndList); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CFFaxDF, CDialog) //{{AFX_MSG_MAP(CFFaxDF) ON_WM_SIZE() ON_NOTIFY(NM_RCLICK, IDC_FAXDF_LIST, OnRclickSmsdfList) ON_NOTIFY(NM_DBLCLK, IDC_FAXDF_LIST, OnDblclkSmsdfList) ON_NOTIFY(LVN_KEYDOWN, IDC_FAXDF_LIST, OnKeydownSmsdfList) //}}AFX_MSG_MAP ON_COMMAND( MENU_DF_ADD , On_User_Add ) ON_COMMAND( MENU_DF_MODIFY , On_User_Modify ) ON_COMMAND( MENU_DF_RESEND , On_User_ReSend ) ON_COMMAND( MENU_DF_DEL , On_User_Del ) ON_COMMAND( MENU_DF_REFRESH , On_User_Refresh ) ON_COMMAND( MENU_DF_FIND , On_User_Find ) ON_COMMAND( MENU_DF_EXPORT , On_User_Export ) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CFFaxDF message handlers BOOL CFFaxDF::OnInitDialog() { CDialog::OnInitDialog(); //取得共用参数 //CMainFrame * pFrame = static_cast ((CMainFrame *)AfxGetMainWnd()); this->GetParent()->GetParentFrame(); m_pMainFrame = (CMainFrame *)this->GetParent()->GetParentFrame(); m_pSocket = &m_pMainFrame->m_Socket; m_AdoRS.SetAdoConnection( &m_pMainFrame->m_adoConnection ); m_AdoRS2.SetAdoConnection( &m_pMainFrame->m_adoConnection ); //初始化List m_Image.Create(16,16,ILC_COLOR32|ILC_MASK,5,5); m_Image.Add(AfxGetApp()->LoadIcon(IDI_L_SMSDF) ); m_Image.Add(AfxGetApp()->LoadIcon(IDI_L_LOCK) ); m_wndList.SubClassWindow2(); m_wndList.SetHeadings(_T("序号,50; 撰写时间,135;号码数,60; 传真标题,200; 附件1,120; 附件2,120; 附件3,120; 附件4,120; 附件5,120;")); m_wndList.SetGridLines(true); m_wndList.SetImageList(&m_Image,LVSIL_SMALL); //m_wndList.SetBkColor( RGB(237,191,175) ); //m_wndList.SetTextBkColor( RGB(237,191,175) ); m_bInit = true; return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } BOOL CFFaxDF::ReHide() { ShowWindow( SW_HIDE ); return true; } BOOL CFFaxDF::ReShow(BOOL bRefresh) { ShowWindow( SW_SHOW ); if ( bRefresh || !m_bRefresh ) { RefreshInfo(); } return true; } BOOL CFFaxDF::RefreshInfo() { m_wndList.ShowWindow( SW_HIDE ); //为了加快显示速度 m_bRefresh = true; m_wndList.DeleteAllItems(); CString str; str.Format(_T("select * from faxbox where BoxType='0' %s order by CreateTime"),m_strFindAdd ); //查询待发短信 BOOL b = m_AdoRS.Open( str ); CAdoRecordSet AdoRS; AdoRS.SetAdoConnection( &m_pMainFrame->m_adoConnection ); long lCount = 0; COleDateTime ot; SYSTEMTIME t={0}; TCHAR szTemp[64]={0}; CString strTitle; CString strAttach1,strAttach2,strAttach3,strAttach4,strAttach5; long lBoxID=0; long lSMSCount=0; CString strID; CString strCreateTime; CString strUserCount; if ( b && m_AdoRS.GetRecordCount() ) { m_AdoRS.MoveFirst(); while( !m_AdoRS.IsEOF() ) { m_AdoRS.GetCollect( _T("BoxID") , lBoxID ); m_AdoRS.GetCollect( _T("CreateTime") , ot ); ot.GetAsSystemTime(t); m_AdoRS.GetCollect( _T("Title") , strTitle ); m_AdoRS.GetCollect( _T("FileName1") , strAttach1 ); m_AdoRS.GetCollect( _T("FileName2") , strAttach2 ); m_AdoRS.GetCollect( _T("FileName3") , strAttach3 ); m_AdoRS.GetCollect( _T("FileName4") , strAttach4 ); m_AdoRS.GetCollect( _T("FileName5") , strAttach5 ); strAttach1=ExPath(strAttach1); strAttach2=ExPath(strAttach2); strAttach3=ExPath(strAttach3); strAttach4=ExPath(strAttach4); strAttach5=ExPath(strAttach5); //取记录总数 lSMSCount = 0; _stprintf( szTemp , _T("select Count(*) from faxitem where BoxID=%d") , lBoxID ); BOOL b2 = AdoRS.Open(szTemp); if ( b2 && AdoRS.GetRecordCount() ) { AdoRS.MoveFirst(); long lIndex = 0; AdoRS.GetCollect( lIndex , lSMSCount ); } strID.Format( _T("%d") , lCount+1 ); strCreateTime.Format(_T("%04d.%02d.%02d %02d:%02d") , t.wYear,t.wMonth,t.wDay,t.wHour,t.wMinute); strUserCount.Format(_T("%d"),lSMSCount); m_wndList.InsertItemAndCol(0,strID,strCreateTime,strUserCount,strTitle,strAttach1,strAttach2,strAttach3,strAttach4,strAttach5); m_wndList.SetItemData(0,lBoxID); /* //显示记录总数 m_wndList.SetItemText( 0 , 2 , _itot(lSMSCount , szTemp , 10 ) ); */ lCount++; m_AdoRS.MoveNext(); } } m_wndList.ShowWindow( SW_SHOW ); //为了加快显示速度 return true; } void CFFaxDF::OnSize(UINT nType, int cx, int cy) { CDialog::OnSize(nType, cx, cy); if ( m_bInit ) { m_wndList.MoveWindow( 0 , 0 , cx,cy); } } void CFFaxDF::OnRclickSmsdfList(NMHDR* pNMHDR, LRESULT* pResult) { *pResult = 0; ShowRMenu(); } void CFFaxDF::ShowRMenu() { // if (!m_pMainFrame->GetUserPurview(PURVIEW_GADDRESS_SEE,false)) //没有查看权限 // return ; CMenu menu; menu.CreatePopupMenu(); BOOL bLock = false; long lItem = this->GetCurrentSelected(); menu.AppendMenu(MF_STRING , MENU_DF_ADD, _T(" 新建列表 ") ); if ( lItem >= 0 ) { menu.AppendMenu(MF_STRING , MENU_DF_MODIFY, _T(" 继续发送 ") ); menu.AppendMenu(MF_STRING , MENU_DF_RESEND, _T(" 重新发送 ") ); menu.AppendMenu(MF_STRING , MENU_DF_DEL, _T(" 删 除 ") ); } else { menu.AppendMenu(MF_STRING|MF_DISABLED|MF_GRAYED , MENU_DF_MODIFY, _T(" 继续发送 ") ); menu.AppendMenu(MF_STRING|MF_DISABLED|MF_GRAYED , MENU_DF_RESEND, _T(" 重新发送 ") ); menu.AppendMenu(MF_STRING|MF_DISABLED|MF_GRAYED , MENU_DF_DEL, _T(" 删 除 ") ); } menu.AppendMenu(MF_SEPARATOR ); //刷新 menu.AppendMenu(MF_STRING , MENU_DF_EXPORT, _T(" 导出... ") ); menu.AppendMenu(MF_STRING , MENU_DF_FIND , _T(" 查找... ") ); menu.AppendMenu(MF_SEPARATOR ); //刷新 menu.AppendMenu(MF_STRING , MENU_DF_REFRESH, _T(" 刷 新 ") ); //显示菜单 POINT pt ; ::GetCursorPos( &pt ); //this->ClientToScreen( &pt); menu.TrackPopupMenu(TPM_LEFTBUTTON | TPM_RIGHTBUTTON,pt.x,pt.y, this, NULL); menu.DestroyMenu(); } long CFFaxDF::GetCurrentSelected() { POSITION pos = m_wndList.GetFirstSelectedItemPosition(); if ( pos ) { return m_wndList.GetNextSelectedItem(pos); } return -1; } void CFFaxDF::On_User_Add() { m_pMainFrame->m_pFuncView->On_User_List_Add_Fax(); } void CFFaxDF::On_User_Modify() { long lItem = GetCurrentSelected(); if ( lItem < 0 ) return ; CString strTemp = _T("你选择的是\"继续发送\",本任务中所有未发的传真将被继续发送!\r\n") \ _T("是否继续?"); int iRet = MessageBox( strTemp,_T("提问") , MB_ICONQUESTION|MB_YESNO ); if ( iRet != IDYES ) return ; long lBoxID = m_wndList.GetItemData( lItem ); if ( lBoxID <= 0 ) return ; m_pMainFrame->m_pFuncView->On_User_List_Read_Fax( lBoxID ); } void CFFaxDF::On_User_ReSend() { long lItem = GetCurrentSelected(); if ( lItem < 0 ) return ; CString strTemp = _T("你选择的是\"重新发送\",本任务中所有传真将会被再次重新发送!\r\n") \ _T("是否继续?"); int iRet = MessageBox( strTemp,_T("提问") , MB_ICONQUESTION|MB_YESNO ); if ( iRet != IDYES ) return ; long lBoxID = m_wndList.GetItemData( lItem ); if ( lBoxID <= 0 ) return ; m_pMainFrame->m_pFuncView->On_User_List_ReSend_Fax( lBoxID ); } void CFFaxDF::On_User_Del() { long lCount = m_wndList.GetSelectedCount(); long *lDel = new long[lCount+2]; POSITION pos = m_wndList.GetFirstSelectedItemPosition(); long i = 0; while(pos) { lDel[i]= m_wndList.GetNextSelectedItem(pos); i ++; } //倒转删除 m_wndList.ShowWindow( SW_HIDE ); //加快显示的速度 for ( i = lCount ; i>0 ; i-- ) { long lBoxID = m_wndList.GetItemData( lDel[i-1] ); if ( lBoxID <= 0 ) continue ; if ( m_pMainFrame->m_pFuncView->m_DLGSendFax.GetBoxID() == lBoxID ) { long lRet = MessageBox( _T("要删除的列表正中编辑,是否确实删除?") , _T("提问") , MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2); if ( lRet != IDYES ) continue ; if ( !m_pMainFrame->m_pFuncView->m_DLGSendFax.List_Save() ) continue; if ( !m_pMainFrame->m_pFuncView->m_DLGSendFax.List_New() ) continue; } TCHAR szSelect[128]={0}; _stprintf( szSelect , _T("delete from faxbox where BoxID=%d") , lBoxID ); //先删除smsBox BOOL b = m_AdoRS.Open( szSelect ); _stprintf( szSelect , _T("delete from faxitem where BoxID=%d") , lBoxID );//再删除BoxItem b = m_AdoRS.Open( szSelect ); m_wndList.DeleteItem( lDel[i-1] ); //删除List中的Item } m_wndList.ShowWindow( SW_SHOW ); //加快显示的速度 delete lDel; } void CFFaxDF::On_User_Refresh() { RefreshInfo(); } void CFFaxDF::On_User_Find() { CString strTemp; DLG_Find_SmsBox dlg(this); dlg.SetType(2);//fax if ( dlg.DoModal() == IDOK ) { strTemp.Format( _T(" AND CreateTime>=#%04d-%02d-%02d# AND CreateTime<=#%04d-%02d-%02d 23:59:59#"),dlg.m_TBegin.GetYear(),dlg.m_TBegin.GetMonth(),dlg.m_TBegin.GetDay(),dlg.m_TEnd.GetYear(),dlg.m_TEnd.GetMonth(),dlg.m_TEnd.GetDay()); m_strFindAdd = strTemp; if ( dlg.m_strMsg.GetLength()>0 ) { strTemp.Format( _T(" AND Title like '%%%s%%'"),dlg.m_strMsg ); m_strFindAdd += strTemp; } On_User_Refresh(); m_strFindAdd = _T(""); //刷新后,查询结束 } } void CFFaxDF::On_User_Export() { DLG_SmsList_Export dlg(this); dlg.SetParam(&m_AdoRS2,&m_wndList,2); dlg.DoModal(); } void CFFaxDF::OnDblclkSmsdfList(NMHDR* pNMHDR, LRESULT* pResult) { *pResult = 0; On_User_Modify(); } void CFFaxDF::OnKeydownSmsdfList(NMHDR* pNMHDR, LRESULT* pResult) { LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR; *pResult = 0; if ( pLVKeyDow->wVKey == VK_DELETE ) { On_User_Del(); } if ( pLVKeyDow->wVKey == VK_INSERT) { On_User_Add(); } if ( pLVKeyDow->wVKey == VK_SPACE) { On_User_Modify(); } if ( pLVKeyDow->wVKey == 'S' || pLVKeyDow->wVKey == 's') { On_User_ReSend(); } if ( pLVKeyDow->wVKey == 'R' || pLVKeyDow->wVKey == 'r') { On_User_Refresh(); } if ( pLVKeyDow->wVKey == 'F' || pLVKeyDow->wVKey == 'f') { On_User_Find(); } if ( pLVKeyDow->wVKey == 'A' || pLVKeyDow->wVKey == 'a') { m_wndList.SelectAllItems(); } } void CFFaxDF::OnOK() { //CDialog::OnOK(); } void CFFaxDF::OnCancel() { //CDialog::OnCancel(); } CString CFFaxDF::ExPath(CString strFileName) { CString strRet=strFileName; long lLen=strFileName.GetLength(); for ( int i=lLen-1;i>=0 ; i-- ) { CString str = strFileName.Mid(i,1); if ( str==CString(_T("\\")) ||str==CString(_T("/")) ) { strRet = strFileName.Right(lLen-i-1); break; } } return strRet; }