📄 faxsrvview.cpp
字号:
// FaxSrvView.cpp : implementation of the CFaxSrvView class
//
#include "stdafx.h"
#include "FaxSrv.h"
#include "FaxSrvDoc.h"
#include "FaxSrvView.h"
#include "faxmail.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "faxsend.h"
#include "faxrecv.h"
#include "faxerror.h"
#include "faxuser.h"
#include "faxbill.h"
// #import "D:\Program Files\Common Files\Microsoft Shared\OFFICE10\mso.dll" rename_namespace("Word")
// #import "D:\Program Files\Microsoft Office\OFFICE11\xl5chs32.olb" ///Excel.exe 对象库
//#import "D:\Program Files\Microsoft Office\OFFICE11\excel.exe" ///Excel2003.exe 对象库
//import "D:\Program Files\Windows NT\Accessories\ImageVue\kodakimg.exe"
//#include "debug\mso.tlh"
// #import "D:\Program Files\Microsoft Office\OFFICE11\msword.olb"
// #include "debug\msword.tlh"
// #import "D:\Program Files\Microsoft Office\OFFICE11\msoutl.olb"
////////////SMTP
//typedef short VARIANT_BOOL;
// #import "D:\Program Files\Common Files\System\ado\msado26.tlb" no_namespace /*raw_interfaces_only*/
// #import <cdosys.dll> no_namespace /*raw_interfaces_only*/
#include "msado26.tlh"
#include "cdosys.tlh"
//#include "cdosys.h"
//#include "cdosys_i.c"
//#include "cdosysstr.h"
//#include "cdosyserr.h"
//////////////全局CDO接口变量
CString MailPath; //////邮件目录位置
CString FaxDocPath; /////传真文件位置
CString FaxMail; ///////传真油箱地址
CDatabase db;
CFaxSend faxSend(&db);
CFaxBill faxBill(&db);
CFaxRecv faxRecv(&db);
CFaxError faxError(&db);
CFaxUser faxUser(&db);
/////////////////////////////////////////////////////////////////////////////
// CFaxSrvView
CString m_dsn,m_uid,m_pwd;
CString m_DSN;
IMPLEMENT_DYNCREATE(CFaxSrvView, CFormView)
BEGIN_MESSAGE_MAP(CFaxSrvView, CFormView)
//{{AFX_MSG_MAP(CFaxSrvView)
ON_WM_TIMER()
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFaxSrvView construction/destruction
CFaxSrvView::CFaxSrvView()
: CFormView(CFaxSrvView::IDD)
{
//{{AFX_DATA_INIT(CFaxSrvView)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// TODO: add construction code here
CStdioFile file1;
if(!file1.Open("faxsrv.ini",CFile::modeRead))
{
AfxMessageBox("找不到初始化文件");
return;
}
CString str1;
while(file1.ReadString(str1))
{
str1.MakeLower( );
if(str1.Find("dsn=")==0)
{
m_dsn=str1.Mid(strlen("dsn="));
}
else if(str1.Find("uid=")==0)
{
m_uid=str1.Mid(strlen("uid="));
}
else if(str1.Find("pwd=")==0)
{
m_pwd=str1.Mid(strlen("pwd="));
}
else if(str1.Find("mailpath")==0)
{
MailPath=str1.Mid(strlen("mailpath="));
}
else if(str1.Find("faxpath")==0)
{
FaxDocPath=str1.Mid(strlen("faxpath="));
}
else if(str1.Find("faxmail=")==0)
{
FaxMail=str1.Mid(strlen("faxmail="));
}
}
file1.Close();
// MailPath="c:\\webeasymail\\mail\\lgy\\";
// FaxDocPath="c:\\FAX";
m_DSN.Format("DSN=%s;UID=%s;PWD=%s",m_dsn,m_uid,m_pwd);
try{
db.OpenEx(m_DSN);//"DSN=faxdata"UID=sa;PWD=;
faxSend.Open();
faxRecv.Open();
faxError.Open();
faxBill.Open();
faxUser.Open();
}
catch(CDBException*e)
{
AfxMessageBox("数据库联接异常\n"+e->m_strError);
e->Delete();
}
}
CFaxSrvView::~CFaxSrvView()
{
CStdioFile file1;
if(!file1.Open("faxsrv.ini",CFile::modeWrite|CFile::modeCreate|CFile::typeText ))
{
AfxMessageBox("找不到初始化文件");
return;
}
CString str1;
{
file1.WriteString("[ODBC]\n");
file1.WriteString("dsn="+m_dsn+"\n");
file1.WriteString("uid="+m_uid+"\n");
file1.WriteString("pwd="+m_pwd+"\n");
file1.WriteString("[PATH]\n");
file1.WriteString("mailpath="+MailPath+"\n");
file1.WriteString("faxpath="+FaxDocPath+"\n");
file1.WriteString("faxmail="+FaxMail+"\n");
}
file1.Close();
}
void CFaxSrvView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFaxSrvView)
DDX_Control(pDX, IDC_PHONICCTRL1, m_Phonic);
// DDX_Control(pDX, IDC_EDITCTRL1, m_Image1);
DDX_Control(pDX, IDC_EDITCTRL2, m_Image2);
//}}AFX_DATA_MAP
}
BOOL CFaxSrvView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CFormView::PreCreateWindow(cs);
}
CWinThread* pThread2;
CWinThread* pThread3;
CWinThread* pThread4;
void CFaxSrvView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
////////////////
/////////自动启动邮件采集线程、FAX线程、邮件回复线程
// m_Image1.SetBorderStyle(0);
// m_Image1.FitTo(1,_variant_t(true));
// m_Image1.Display();
m_Image2.FitTo(1,_variant_t(true));
m_Image2.Display();
pThread2=AfxBeginThread( MyFaxRecvByIp, (LPVOID)this);//, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );
if(pThread2)
{
}
pThread3=AfxBeginThread( MyFaxTX, (LPVOID)this);//, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );
if(pThread3)
{
}
pThread4=AfxBeginThread( MyFaxNotice, (LPVOID)this);//, int nPriority = THREAD_PRIORITY_NORMAL, UINT nStackSize = 0, DWORD dwCreateFlags = 0, LPSECURITY_ATTRIBUTES lpSecurityAttrs = NULL );
if(pThread4)
{
}
}
/////////////////////////////////////////////////////////////////////////////
// CFaxSrvView printing
BOOL CFaxSrvView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CFaxSrvView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CFaxSrvView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
void CFaxSrvView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
// TODO: add customized printing code here
}
/////////////////////////////////////////////////////////////////////////////
// CFaxSrvView diagnostics
#ifdef _DEBUG
void CFaxSrvView::AssertValid() const
{
CFormView::AssertValid();
}
void CFaxSrvView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
CFaxSrvDoc* CFaxSrvView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CFaxSrvDoc)));
return (CFaxSrvDoc*)m_pDocument;
}
#endif //_DEBUG
////////////////
///////////实现发送传真的功能 OnTimer()
#define CH_COUNT 8
#define CH_HALFCOUNT 4
#define ID_LENGTH 4
#define CH_ANALOG_TRUNK 2
enum
{
S_IDLE,
S_CALLIN,
S_CALLOUT,
S_CALLOK,
S_CALLDTMF,
S_RING,
S_ANSWER,
S_HANGUP,
S_SENDFAX,
S_RECVFAX,
S_RECVOK,
S_SENDOK,
S_RECVERR,
S_SENDERR,
S_STOPFAX,
S_ERROR
};
static int CH_State[CH_COUNT];
static CString CH_Uid[CH_COUNT];
static CString CH_RecvDtmf[CH_COUNT];
static CString CH_FaxPath[CH_COUNT];
static CString CH_Phone[CH_COUNT];
static CString CH_Phone2[CH_COUNT];
void CFaxSrvView::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
try
{
faxSend.m_strFilter="state='0'";
faxSend.m_strSort=" sendtime ";
if(faxSend.IsOpen())
faxSend.Requery();
else
faxSend.Open();
for(int i=0;i<CH_HALFCOUNT;i++)
{
if(CH_State[i]==S_IDLE)
{
if(!faxSend.IsEOF())
{
CH_Uid[i]=faxSend.m_userid;
CH_Phone[i]=faxSend.m_faxto;
CH_FaxPath[i]=faxSend.m_faxdoc;
int index=CH_Phone[i].Find(",",0);
if(index>0)
{ CH_Phone2[i]=CH_Phone[i].Mid(index);
CH_Phone[i]=CH_Phone[i].Left(index);
}
else
CH_Phone2[i]="";
m_Phonic.MakeCall(2,i,"",CH_Phone[i],100);
/// m_Phonic.MakeCall(2,i,"",CH_Phone[i].Left(index),100);
CH_State[i]=S_CALLOUT;
faxSend.Edit();
faxSend.m_state="1";
faxSend.m_callcount+=1;
faxSend.m_sendtime=time(NULL);
faxSend.Update();
faxSend.MoveNext();
}
else
break;
}
}
}
catch(CDBException* e)
{
if(!db.IsOpen())
{
db.Open("");
}
if(faxSend.IsOpen())
faxSend.Requery();
else
faxSend.Open();
// if(faxRecv.IsOpen())
// faxRecv.Requery();
// else faxRecv.Open();
}
CFormView::OnTimer(nIDEvent);
}
BEGIN_EVENTSINK_MAP(CFaxSrvView, CFormView)
//{{AFX_EVENTSINK_MAP(CFaxSrvView)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 1 /* State */, OnStatePhonicctrl1, VTS_I4 VTS_I4 VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 2 /* DeviceTimer */, OnDeviceTimerPhonicctrl1, VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 3 /* Idle */, OnIdlePhonicctrl1, VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 4 /* CallIn */, OnCallInPhonicctrl1, VTS_I4 VTS_I4 VTS_BSTR VTS_BSTR)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 5 /* Answer */, OnAnswerPhonicctrl1, VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 6 /* CallOutFinish */, OnCallOutFinishPhonicctrl1, VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 7 /* Hangup */, OnHangupPhonicctrl1, VTS_I4 VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 8 /* DTMF */, OnDTMFPhonicctrl1, VTS_I4 VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 9 /* PlayEnd */, OnPlayEndPhonicctrl1, VTS_I4 VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 10 /* RecordEnd */, OnRecordEndPhonicctrl1, VTS_I4 VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 11 /* FaxError */, OnFaxErrorPhonicctrl1, VTS_I4 VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 12 /* OneFaxPageOver */, OnOneFaxPageOverPhonicctrl1, VTS_I4 VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 13 /* Flash */, OnFlashPhonicctrl1, VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 14 /* SendCallerIDEnd */, OnSendCallerIDEndPhonicctrl1, VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 15 /* CallFail */, OnCallFailPhonicctrl1, VTS_I4 VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 16 /* SendV23End */, OnSendV23EndPhonicctrl1, VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 17 /* V23DataReady */, OnV23DataReadyPhonicctrl1, VTS_I4 VTS_I4 VTS_PI2 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 18 /* Ring */, OnRingPhonicctrl1, VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 19 /* Voice */, OnVoicePhonicctrl1, VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 20 /* Silence */, OnSilencePhonicctrl1, VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 21 /* Hanging */, OnHangingPhonicctrl1, VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 22 /* DtmfOn */, OnDtmfOnPhonicctrl1, VTS_I4 VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 23 /* DtmfOff */, OnDtmfOffPhonicctrl1, VTS_I4 VTS_I4 VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 24 /* RealTimeData */, OnRealTimeDataPhonicctrl1, VTS_I4 VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 25 /* Polarity */, OnPolarityPhonicctrl1, VTS_I4 VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 26 /* Energy */, OnEnergyPhonicctrl1, VTS_I4 VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 27 /* Vad */, OnVadPhonicctrl1, VTS_I4 VTS_I4 VTS_I4 VTS_I4)
ON_EVENT(CFaxSrvView, IDC_PHONICCTRL1, 33 /* FlashOver */, OnFlashOverPhonicctrl1, VTS_I4 VTS_I4)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CFaxSrvView::OnStatePhonicctrl1(long channelType, long channelID, long newChannelState, long oldChannelState)
{
// TODO: Add your control notification handler code here
}
void CFaxSrvView::OnDeviceTimerPhonicctrl1(long channelType, long channelID)
{
// TODO: Add your control notification handler code here
switch(CH_State[channelID])
{
case S_CALLIN:
m_Phonic.StopPlay(channelType, channelID);
m_Phonic.Hangup(channelType,channelID,0);
CH_RecvDtmf[channelID]="";
CH_State[channelID]=S_IDLE;
break;
case S_CALLOUT:
//break;
case S_CALLOK:
m_Phonic.Hangup(channelType, channelID,0);
OnHangupPhonicctrl1(channelType, channelID, 0);
break;
case S_CALLDTMF:
m_Phonic.PlayFile(channelType,channelID,"",0,0);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -