// DLG_UBoxLog_See.cpp : implementation file
//

#include "stdafx.h"
#include "corpsms.h"
#include "DLG_UBoxLog_See.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// DLG_UBoxLog_See dialog
#include "MainFrm.h"
#include "DLG_UserSelect.h"
#include "FUBoxLog.h"


DLG_UBoxLog_See::DLG_UBoxLog_See(CWnd* pParent /*=NULL*/)
	: CDialog(DLG_UBoxLog_See::IDD, pParent)
{
	//{{AFX_DATA_INIT(DLG_UBoxLog_See)
	m_strCallNum = _T("");
	m_strCallTime = _T("");
	//  m_strKH_Addr = _T("");
	m_strKH_LTD = _T("");
	//  m_strKH_Mobile = _T("");
	m_strKH_Name = _T("");
	//  m_strKH_Tel = _T("");
	//  m_strSendSms = _T("");
	//  m_strYWY_Mobile = _T("");
	//  m_strYWY_Name = _T("");
	//  m_strStatus = _T("");
	//}}AFX_DATA_INIT

	m_pCFUBoxLog = (CFUBoxLog *)pParent;
	m_bNewCall = false;

	memset(&m_UBox,0,sizeof(m_UBox));
	m_strCallBZ = _T("");
	m_strCallLocal = _T("");
	m_strCallStatus = _T("");
	m_strCallType = _T("");
	m_strCallWay = _T("");
	m_strName = _T("");
	m_strCallSC = _T("");

	m_bModify = false;
}


void DLG_UBoxLog_See::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DLG_UBoxLog_See)
	DDX_Text(pDX, IDD_UBOXLOG_SEE_CALLNUM, m_strCallNum);
	DDX_Text(pDX, IDD_UBOXLOG_SEE_CALLTIME, m_strCallTime);
	DDX_Text(pDX, IDD_UBOXLOG_SEE_KH_LTD, m_strKH_LTD);
	DDX_Text(pDX, IDD_UBOXLOG_SEE_KH_NAME, m_strKH_Name);
	//}}AFX_DATA_MAP
	DDX_Text(pDX, IDD_UBOXLOG_SEE_CALLBZ, m_strCallBZ);
	DDV_MaxChars(pDX, m_strCallBZ, 500);
	DDX_Text(pDX, IDD_UBOXLOG_SEE_CALLLOCAL, m_strCallLocal);
	DDX_Text(pDX, IDD_UBOXLOG_SEE_CALLSTATUS, m_strCallStatus);
	DDX_CBString(pDX, IDD_UBOXLOG_SEE_CALLTYPE, m_strCallType);
	DDV_MaxChars(pDX, m_strCallType, 30);
	DDX_Text(pDX, IDD_UBOXLOG_SEE_CALLWAY, m_strCallWay);
	DDX_Text(pDX, IDD_UBOXLOG_SEE_NAME, m_strName);
	DDX_Control(pDX, IDD_UBOXLOG_SEE_CALLTYPE, m_L_CallType);
	DDX_Text(pDX, IDD_UBOXLOG_SEE_CALLSC, m_strCallSC);
}


BEGIN_MESSAGE_MAP(DLG_UBoxLog_See, CDialog)
	//{{AFX_MSG_MAP(DLG_UBoxLog_See)
	ON_BN_CLICKED(IDD_UBOXLOG_SEE_YWY_SEL, OnUboxlogSeeYwySel)
	ON_BN_CLICKED(IDD_UBOXLOG_SEE_SENDSMS_CREATE, OnUboxlogSeeSendsmsCreate)
	ON_BN_CLICKED(IDD_UBOXLOG_SEE_SENDSMS_SEND, OnUboxlogSeeSendsmsSend)
	ON_WM_CLOSE()
	ON_WM_TIMER()
	ON_WM_MOUSEACTIVATE()
	ON_WM_LBUTTONDOWN()
	ON_WM_NCLBUTTONDOWN()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDOK, &DLG_UBoxLog_See::OnBnClickedOk)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// DLG_UBoxLog_See message handlers

void DLG_UBoxLog_See::OnOK() 
{
	CDialog::OnOK();
}

ANS_UBox_CallLog DLG_UBoxLog_See::GetParam()
{
	return m_UBox;
}

void DLG_UBoxLog_See::SetParam(ANS_UBox_CallLog ubox,BOOL bMoidfy)
{
	m_UBox = ubox;
	m_bModify = bMoidfy;
}

void DLG_UBoxLog_See::SetCallType(CCallType & callType)
{
	m_CallType.Copy(callType);
}

BOOL DLG_UBoxLog_See::OnInitDialog() 
{
	CDialog::OnInitDialog();
	

	m_strCallNum = m_UBox.szCallNumber;
	m_strCallTime.Format(_T("%04d.%02d.%02d %02d:%02d") , m_UBox.tCallTime.wYear,m_UBox.tCallTime.wMonth,m_UBox.tCallTime.wDay,m_UBox.tCallTime.wHour,m_UBox.tCallTime.wMinute);
	if ( m_UBox.lCallWay==0 )
		m_strCallWay = _T("����");
	else
		m_strCallWay = _T("����");
	if ( m_UBox.lCallStatus==0 )
		m_strCallStatus= _T("�");
	else
		m_strCallStatus = _T("�ѽ�");

	m_strCallLocal = m_UBox.szCallLocal;

	m_strKH_Name = 	m_UBox.szKHName;
	m_strKH_LTD  = m_UBox.szKHLTD;

	m_strName = m_UBox.szUserName;

	m_strCallType    = m_UBox.szCallType;
	m_strCallBZ      = m_UBox.szCallBZ;

	COleDateTimeSpan span(0,0,0,m_UBox.lCallSC);
	m_strCallSC.Format(_T("%02d:%02d:%02d"),span.GetHours(),span.GetMinutes(),span.GetSeconds());

	if ( m_bModify )
	{
		GetDlgItem(IDD_UBOXLOG_SEE_CALLTYPE)->EnableWindow(true);
		((CEdit*)GetDlgItem(IDD_UBOXLOG_SEE_CALLBZ))->SetReadOnly(false);
	}
	
	
	UpdateData(false);

	long lCount = m_CallType.GetCount();
	for ( int i=0 ; i<lCount ; i++ )
	{
		m_L_CallType.AddString(m_CallType[i].szType);
	}

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void DLG_UBoxLog_See::OnUboxlogSeeYwySel() 
{
}

void DLG_UBoxLog_See::OnUboxlogSeeSendsmsCreate() 
{

}

void DLG_UBoxLog_See::OnUboxlogSeeSendsmsSend() 
{
	return ;
/*
	UpdateData(true);

	if ( !::isMobileNum(m_strYWY_Mobile,m_strYWY_Mobile.GetLength()) )
	{
		MessageBox(_T("ҵ��Ա��Ŀ���ֻ���������޷����Ͷ���!"), _T("����") , MB_ICONWARNING );
		GetDlgItem(IDD_UBOXLOG_SEE_YWY_SEL)->SetFocus();
		return;
	}

	if ( m_strSendSms.GetLength()<=0 )
	{
		MessageBox(_T("����������Ҫ�·��Ķ������ݣ�") , _T("����") , MB_ICONWARNING );
		GetDlgItem(IDD_UBOXLOG_SEE_SENDSMS)->SetFocus();
		return;
	}
/*
#ifdef SUPPER_IM_MAS
	if ( this->m_pCFUBoxLog->m_pMainFrame->m_pFuncView->m_DLGSend.Mas_OK() && !_tcscmp(sms.szRecvNum,_T("Mas")) )  //MAS����
	{
		CString strMobile=m_strYWY_Mobile;
		CString strMsg=m_strSendSms;
		CString strSendTime;
		long lSmID=0; //��+ʱ+��+���
		long lSrcID=0;
		int iRet = (*this->m_pCFUBoxLog->m_pMainFrame->m_pFuncView->m_DLGSend.m_Mas_sendSMAdvTime)(strMobile, strMsg,strSendTime, lSmID,lSrcID);
	}
	else
#endif
*/
/*

	{
		//����Ϊ���Ͷ��Ŷ���
		//��������ʱ�����ռ�
		ANS_SendData2 * pTemp = new ANS_SendData2[5];
		memset( pTemp , 0 , sizeof(ANS_SendData2)*5 );
		long lSendCount=0;
		TCHAR szSendMsg[512]={0};
		TCHAR szSendMsg2[512]={0};

		
		//�ָ���Ϣ
		long lMaxMsgLen = this->m_pCFUBoxLog->m_pMainFrame->GetMaxSendMsgLen();  //ȡ����������ַ���
		CString strCM;
		BOOL bCMFirst   = this->m_pCFUBoxLog->m_pMainFrame->GetQJCM(strCM);
		long lMsgAll=0;
		long lMsgIndex = 1;
		BOOL bGetMsg;
		_tcscpy( szSendMsg , m_strSendSms ); //����Դ��Ϣ
		TCHAR szSendNum[32]={0};
		_tcscpy( szSendNum , m_strYWY_Mobile ); //����Ŀ�����
		while ( true )
		{
			memset( szSendMsg2 , 0 , sizeof(szSendMsg2) );
			if ( !_tcsncmp( szSendNum , _T("12") , 2 ) ||
			    !_tcsncmp( szSendNum , _T("13") , 2 ) ||
				!_tcsncmp( szSendNum , _T("15") , 2 ) ||
				!_tcsncmp( szSendNum , _T("14") , 2 ) ||
				!_tcsncmp( szSendNum , _T("16") , 2 ) ||
				!_tcsncmp( szSendNum , _T("17") , 2 ) ||
				!_tcsncmp( szSendNum , _T("18") , 2 ) ||
				!_tcsncmp( szSendNum , _T("19") , 2 ))  
			{
				//�ֻ��������֧��70������
				//if ( isChinese( m_szSendMsg,_tcslen(szSendMsg) ) )
				//{
				bGetMsg = GetSpiltUnicodeMsg( szSendMsg , szSendMsg2 , lMsgIndex , lMaxMsgLen ,lMsgAll);
				//}
				//else
				//{
				//	bGetMsg = GetSpiltAsciiMsg( szSendMsg , szSendMsg2   , lMsgIndex , lMaxMsgLen*2+lMaxMsgLen*2/7 ,lMsgAll);
				//}
			}
			else
			{
				//С��ͨ�ֻ��������֧��58������
				//if ( isChinese( m_szSendMsg,_tcslen(szSendMsg) ) )
				//{
				bGetMsg = GetSpiltUnicodeMsg( szSendMsg , szSendMsg2 , lMsgIndex , lMaxMsgLen-12 ,lMsgAll);
				//}
				//else
				//{
				//	bGetMsg = GetSpiltAsciiMsg( szSendMsg , szSendMsg2   , lMsgIndex , MOBILE_TYPE_PHS_MAXLEN ,lMsgAll);
				//}
			}
			if ( bGetMsg )  //��ȡ����Ϣ������
			{
				pTemp[lSendCount].lCorpID = this->m_pCFUBoxLog->m_pMainFrame->m_lCorpID;
				pTemp[lSendCount].lUserID = this->m_pCFUBoxLog->m_pMainFrame->m_lUserID;
				pTemp[lSendCount].lItem   = 0;
				pTemp[lSendCount].lItemID = 0;         //ItemID;
				if ( bCMFirst )
					_stprintf( pTemp[lSendCount].szMsg ,_T("%s%s") , strCM,szSendMsg2);
				else
					_stprintf( pTemp[lSendCount].szMsg ,_T("%s%s") , szSendMsg2,strCM);
				_tcscpy( pTemp[lSendCount].szName   , _T("")  );
				_tcscpy( pTemp[lSendCount].szMobile , szSendNum);
				lSendCount ++; //��¼�ż�1
				lMsgIndex  ++; //�ָ���1
			}
			else
			{
				break;
			}
		}
		
		
		//������Ϣ
		if ( lSendCount > 0 )
		{
			//����ָ�����
			long lSize = sizeof(REQ_Send2)+sizeof(ANS_SendData2)*lSendCount;
			BYTE * pData = new BYTE[lSize];
			REQ_Send2 * pSendSend = (REQ_Send2 *)pData;
			ANS_SendData2 * pDataSend = (ANS_SendData2 *)(pData + sizeof(REQ_Send2));
			pSendSend->lCount = lSendCount;
			//����
			memcpy( pDataSend , pTemp , sizeof(ANS_SendData2)*lSendCount );
			this->m_pCFUBoxLog->m_pMainFrame->SendFrame( SMSFUNC_SEND2 , pData , lSize );
		}
		delete pTemp;  //ɾ����ʱ����
	}
*/	
}

void DLG_UBoxLog_See::OnClose() 
{
	CDialog::OnClose();
}

void DLG_UBoxLog_See::OnTimer(UINT nIDEvent) 
{
/*
	if ( nIDEvent == 1 )
	{
		this->FlashWindow(true);
		this->m_pCFUBoxLog->m_pMainFrame->FlashWindow(true);
	}

	if ( nIDEvent == 2 )  //�Զ����ش˴���
	{
		KillTimer(nIDEvent);
		CDialog::OnCancel();
	}
*/
	CDialog::OnTimer(nIDEvent);
}


int DLG_UBoxLog_See::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message) 
{

	int i= CDialog::OnMouseActivate(pDesktopWnd, nHitTest, message);
	if ( this->m_bNewCall )
	{
		KillTimer(1);  //ȡ������
		KillTimer(2);  //ȡ���Զ��ر�
	}
	return i;
}

void DLG_UBoxLog_See::OnLButtonDown(UINT nFlags, CPoint point) 
{
	CDialog::OnLButtonDown(nFlags, point);

	if ( this->m_bNewCall )
	{
		KillTimer(1);  //ȡ������
		KillTimer(2);  //ȡ���Զ��ر�
	}
}

void DLG_UBoxLog_See::OnNcLButtonDown(UINT nHitTest, CPoint point) 
{
	CDialog::OnNcLButtonDown(nHitTest, point);

	if ( this->m_bNewCall )
	{
		KillTimer(1);  //ȡ������
		KillTimer(2);  //ȡ���Զ��ر�
	}
	
}

void DLG_UBoxLog_See::SetUBoxStatus(long lStatus)
{

}

void DLG_UBoxLog_See::OnDestroy() 
{
	CDialog::OnDestroy();
}

void DLG_UBoxLog_See::OnCancel() 
{

	CDialog::OnCancel();
}


void DLG_UBoxLog_See::OnBnClickedOk()
{
	if ( m_bModify )
	{
		if ( !UpdateData(true))
			return ;

		_tcscpy(m_UBox.szCallBZ , m_strCallBZ);
		_tcscpy(m_UBox.szCallType , m_strCallType);

		CDialog::OnOK();
		return ;
	}
	CDialog::OnCancel();
}