CorpSms/DLG_Back_Export.cpp
2025-02-27 16:58:16 +08:00

398 lines
9.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// DLG_Back_Export.cpp : implementation file
//
#include "stdafx.h"
#include "corpsms.h"
#include "DLG_Back_Export.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// DLG_Back_Export dialog
DLG_Back_Export::DLG_Back_Export(CWnd* pParent /*=NULL*/)
: CDialog(DLG_Back_Export::IDD, pParent)
{
//{{AFX_DATA_INIT(DLG_Back_Export)
//}}AFX_DATA_INIT
}
void DLG_Back_Export::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DLG_Back_Export)
DDX_Control(pDX, IDD_SMSJS_EXPORT_SEL, m_B_OnlySel);
DDX_Control(pDX, IDD_SMSJS_EXPORT_LIST, m_L_List);
DDX_Control(pDX, IDD_SMSJS_EXPORT_HEAD, m_B_AddHead);
DDX_Control(pDX, IDD_SMSJS_EXPORT_FILENAME, m_E_FileName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(DLG_Back_Export, CDialog)
//{{AFX_MSG_MAP(DLG_Back_Export)
ON_BN_CLICKED(IDD_SMSJS_EXPORT_SELALL, OnSmsjsExportSelall)
ON_BN_CLICKED(IDD_SMSJS_EXPORT_CLEAR, OnSmsjsExportClear)
ON_BN_CLICKED(IDD_SMSJS_EXPORT_GETFILE, OnSmsjsExportGetfile)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DLG_Back_Export message handlers
BOOL DLG_Back_Export::OnInitDialog()
{
CDialog::OnInitDialog();
InitList();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void DLG_Back_Export::InitList()
{
m_L_List.Init(true,-1,-1,-1);
m_L_List.InsertColumn( 0 , _T("顺序") , LVCFMT_LEFT , 40 , 0);
m_L_List.InsertColumn( 1 , _T(" 字段名") , LVCFMT_LEFT , 120 , 1);
m_L_List.SetTextColor( RGB(0,0,255) );
TCHAR Buf[256];
if ( m_lExportType == 0 )
{
TCHAR * pItem[] =
{
_T("手机号码"),
_T("说明"),
_T("状态"),
};
int lCount=3;
for ( int i = 0 ; i<lCount ; i++ )
{
m_L_List.InsertItem( i , _itot(i+1,Buf,10) );
m_L_List.SetItemText(i , 1 , pItem[i] );
m_L_List.SetItemData(i , i ); //设置这个是为了顺序不至于打乱
}
}
if ( m_lExportType == 1 )
{
TCHAR * pItem[] =
{
_T("状态"),
_T("手机号码"),
_T("移动通道"),
_T("联通通道"),
_T("小灵通通道"),
_T("电信通道"),
_T("通道标识"),
_T("是否全网"),
_T("说明"),
};
int lCount=9;
for ( int i = 0 ; i<lCount ; i++ )
{
m_L_List.InsertItem( i , _itot(i+1,Buf,10) );
m_L_List.SetItemText(i , 1 , pItem[i] );
m_L_List.SetItemData(i , i ); //设置这个是为了顺序不至于打乱
}
}
m_L_List.CheckAll();
m_L_List.NoverCheck();
m_L_List.ReShowSort();
}
void DLG_Back_Export::SetParam(CAdoRecordSet *pAdo, CReportCtrl *pList, long lExportType)
{
m_pAdo = pAdo;
m_pList = pList;
m_lExportType=lExportType;
}
void DLG_Back_Export::OnSmsjsExportSelall()
{
m_L_List.CheckAll();
}
void DLG_Back_Export::OnSmsjsExportClear()
{
m_L_List.ClearAll();
}
void DLG_Back_Export::OnOK()
{
long lItemCount = m_L_List.GetItemCount();
long lExPortItem[50];memset(&lExPortItem,0,sizeof(lExPortItem));
for ( int j=0 ; j < 50 ; j++ ) lExPortItem[j] = -1;
long lCheckCount = 0;
for ( int i=0 ; i<lItemCount ; i++ )
{
if ( m_L_List.GetCheck(i) )
{
lExPortItem[lCheckCount] = m_L_List.GetItemData(i) ;
lCheckCount ++;
}
}
if ( lCheckCount <=0 )
{
MessageBox( _T("你必须从左边的字段列表中选择一个或多个导出字段。") , _T("选择错误") , MB_OK|MB_ICONWARNING );
return;
}
TCHAR szFileName[512];
m_E_FileName.GetWindowText( szFileName , sizeof(szFileName) );
if ( _tcslen(AllTrim(szFileName)) <=0 )
{
MessageBox( _T("你必须输入导出的文件名。") , _T("错误") , MB_OK|MB_ICONWARNING );
m_E_FileName.SetFocus();
return;
}
CFile fTalk;
if ( !fTalk.Open( szFileName , CFile::modeReadWrite|CFile::modeCreate ) )
{
TCHAR Buf[512];
_stprintf( Buf , _T("创建文件:%s\n产生错误!") , szFileName );
MessageBox( Buf , _T("错误") , MB_ICONWARNING|MB_OK );
return;
}
CString str;
CString strTemp,strTemp2;
long lAdrCount = m_pList->GetItemCount();
TCHAR Buf[1024];
TCHAR Buf2[1024];
TCHAR Buf3[1024];
#ifdef UNICODE
char szTempA[4096];
#endif
long lRecnCount= 0; //总记录数
long lFileSize = 0; //文件总字节数
long lBufLen = 0;
COleDateTime t;
if ( m_B_AddHead.GetCheck() )//增加字段头
{
_tcscpy(Buf,_T(";"));
if ( m_lExportType == 0 )
{
for ( int j = 0; j<lCheckCount ; j++ )
{
switch( lExPortItem[j] )
{
case 0: //收信人
_tcscat(Buf , _T("手机号码"));
break;
case 1: //接收号码
_tcscat(Buf , _T("说明"));
break;
case 2: //收信号码
_tcscat(Buf , _T("状态"));
break;
}
if ( j < lCheckCount-1 ) //最后一条不用加","号
_tcscat(Buf , _T(",") );
}
}
if ( m_lExportType == 1 )
{
for ( int j = 0; j<lCheckCount ; j++ )
{
switch( lExPortItem[j] )
{
case 0: //收信人
_tcscat(Buf , _T("状态"));
break;
case 1: //接收号码
_tcscat(Buf , _T("手机号码"));
break;
case 2: //收信号码
_tcscat(Buf , _T("移动通道"));
break;
case 3: //收信号码
_tcscat(Buf , _T("联通通道"));
break;
case 4: //收信号码
_tcscat(Buf , _T("小灵通通道"));
break;
case 5: //收信号码
_tcscat(Buf , _T("电信通道"));
break;
case 6: //收信号码
_tcscat(Buf , _T("通道标识"));
break;
case 7: //收信号码
_tcscat(Buf , _T("是否全网"));
break;
case 8: //收信号码
_tcscat(Buf , _T("说明"));
break;
}
if ( j < lCheckCount-1 ) //最后一条不用加","号
_tcscat(Buf , _T(",") );
}
}
_tcscat(Buf , _T("\r\n") ); //换行
#ifdef UNICODE
CAdoRecordSet::Ado_W2A(Buf,szTempA);
lBufLen = strlen(szTempA);
fTalk.Write( szTempA , lBufLen );
#else
lBufLen = _tcslen(Buf);
fTalk.Write( Buf , lBufLen );
#endif
lFileSize = lFileSize + lBufLen ; //取得总字节数
}
for ( i = 0; i<lAdrCount ; i++ )
{
memset(Buf , 0 , sizeof(Buf) );
BOOL bExport=true;
if ( m_B_OnlySel.GetCheck() )
{
UINT uStatus= m_pList->GetItemState(i,LVIS_SELECTED);
if ( uStatus&LVIS_SELECTED )
bExport = true;
else
bExport = false;
}
if ( bExport )
{
for( int j = 0 ; j< lCheckCount ; j++ ) //按按所选中的字段,取通讯录内容进行保存。
{
memset(Buf2 , 0 , sizeof(Buf2) );
memset(Buf3 , 0 , sizeof(Buf3) );
if ( m_lExportType == 0 )
{
switch( lExPortItem[j] )
{
case 0: //号码
m_pList->GetItemText(i,2,Buf2,sizeof(Buf2));
break;
case 1: //说明
m_pList->GetItemText(i,3,Buf2,sizeof(Buf2));
ExChar(Buf2 , _T("\r") );
ExChar(Buf2 , _T("\n") );
str=Buf2;
str.Replace( _T(",") , _T("") );
_tcscpy(Buf2 , str );
break;
case 2: //状态
m_pList->GetItemText(i,1,Buf2,sizeof(Buf2));
if ( !_tcscmp(Buf2 , _T("启用") ) )
_tcscpy(Buf2 , _T("1"));
else
_tcscpy(Buf2 , _T("0"));
break;
}
_tcscat(Buf , Buf2 );
if ( j < lCheckCount-1 ) //最后一条不用加","号
_tcscat(Buf , _T(",") );
}
if ( m_lExportType == 1 )
{
switch( lExPortItem[j] )
{
case 0: //号码
m_pList->GetItemText(i,1,Buf2,sizeof(Buf2));
break;
case 1: //号码
m_pList->GetItemText(i,2,Buf2,sizeof(Buf2));
break;
case 2: //号码
m_pList->GetItemText(i,3,Buf2,sizeof(Buf2));
break;
case 3: //号码
m_pList->GetItemText(i,4,Buf2,sizeof(Buf2));
break;
case 4: //号码
m_pList->GetItemText(i,5,Buf2,sizeof(Buf2));
break;
case 5: //号码
m_pList->GetItemText(i,6,Buf2,sizeof(Buf2));
break;
case 6: //号码
m_pList->GetItemText(i,7,Buf2,sizeof(Buf2));
break;
case 7: //号码
m_pList->GetItemText(i,8,Buf2,sizeof(Buf2));
break;
case 8: //说明
m_pList->GetItemText(i,9,Buf2,sizeof(Buf2));
ExChar(Buf2 , _T("\r") );
ExChar(Buf2 , _T("\n") );
str=Buf2;
str.Replace( _T(",") , _T("") );
_tcscpy(Buf2 , str );
break;
}
_tcscat(Buf , Buf2 );
if ( j < lCheckCount-1 ) //最后一条不用加","号
_tcscat(Buf , _T(",") );
}
}
_tcscat(Buf , _T("\r\n") ); //换行
#ifdef UNICODE
CAdoRecordSet::Ado_W2A(Buf,szTempA);
lBufLen = strlen(szTempA);
fTalk.Write( szTempA , lBufLen );
#else
lBufLen = _tcslen(Buf);
fTalk.Write( Buf , lBufLen );
#endif
lRecnCount++; //取得总记录数
lFileSize = lFileSize + lBufLen ; //取得总字节数
}
}
fTalk.Close();
this->EndWaitCursor();
_stprintf(Buf , _T("导出列表成功,具体如下:\n导出文件类型:TXT\n导出记录数:%d\n导出字节数:%d\n导出文件名:%s") , lRecnCount , lFileSize , szFileName);
MessageBox( Buf , _T("导出成功"),MB_OK|MB_ICONINFORMATION );
CDialog::OnOK();
}
void DLG_Back_Export::OnSmsjsExportGetfile()
{
#define FILE_FILTER_TEXT \
TEXT("txt文本文件 (*.txt)\0*.txt\0")\
TEXT("Excel csv 文件 (*.csv)\0*.csv\0")\
TEXT("所有文件 (*.*)\0*.*;\0\0")
TCHAR szFile[ 256 ];
TCHAR szFileB[ 256 ];
*szFileB = NULL;
_stprintf( szFile , _T("Back") );
if ( m_lExportType == 1 )
{
_stprintf( szFile , _T("TDSet") );
}
OPENFILENAME sOpen;
sOpen.lStructSize = sizeof( sOpen );
sOpen.hwndOwner = this->m_hWnd ;
sOpen.Flags = OFN_EXPLORER|OFN_OVERWRITEPROMPT|OFN_HIDEREADONLY;
sOpen.lpstrFilter = FILE_FILTER_TEXT;
sOpen.lpstrDefExt = _T("txt");
sOpen.lpstrCustomFilter = NULL;
sOpen.nMaxCustFilter = 0;
sOpen.lpstrFile = szFile;
sOpen.nMaxFile = sizeof( szFile );
sOpen.lpstrFileTitle = szFileB;
sOpen.nMaxFileTitle = sizeof( szFileB );
sOpen.lpstrInitialDir = NULL;
sOpen.lpstrTitle = _T("选择导出列表的文件");
if ( ::GetSaveFileName( &sOpen ) )
{
m_E_FileName.SetWindowText(sOpen.lpstrFile);
}
}