⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gxrecorddlg.cpp

📁 电话录音系统程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// GXRecordDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GXRecord.h"
#include "GXRecordDlg.h"
#include "Shpa3api.h" //杭州三汇API头文件
#include "time.h"
#include "IniFile.h" 

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	CMSComm	m_Com;
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	virtual BOOL OnInitDialog();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	DDX_Control(pDX, IDC_MSCOMM1, m_Com);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGXRecordDlg dialog

CGXRecordDlg::CGXRecordDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGXRecordDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CGXRecordDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGXRecordDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CGXRecordDlg)
	DDX_Control(pDX, IDC_LIST1, m_ListCh);
	DDX_Control(pDX, IDC_COMBO1, m_CurLine);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CGXRecordDlg, CDialog)
	//{{AFX_MSG_MAP(CGXRecordDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_BUTTON_SetListen, OnBUTTONSetListen)
	ON_BN_CLICKED(IDC_BUTTON_UnSetListen, OnBUTTONUnSetListen)
	ON_WM_CLOSE()
	ON_WM_DESTROY()
	ON_WM_SIZE()
	ON_WM_DELETEITEM()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGXRecordDlg message handlers
CGXRecordApp theApp;

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

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	AfxEnableControlContainer();

/***********程序开始***********/
	
//AfxMessageBox("strat");
	HRESULT hr;
	AfxOleInit();
	CString ConnectSQL;
	/*try
	{
		//创建Connection对象
		hr = m_pConnection1.CreateInstance("ADODB.Connection");
		m_pRecordset1.CreateInstance("ADODB.Recordset");

		if(SUCCEEDED(hr))
		{
			CString SERVER="202.102.7.125",DATABASE="SQDxServerDB",UID="test",PWD="QZGATX3037555*@#";
			ConnectSQL = "provider=sqloledb;Server=" + SERVER + ";DATABASE="+DATABASE;
			ConnectSQL += ";UID=" + UID + ";Pwd=" + PWD;
			m_pConnection1->ConnectionTimeout=8000;
			hr=m_pConnection1->Open(_bstr_t(ConnectSQL),"","",adModeUnknown);
			
			m_pConnection1->PutCursorLocation(adUseClient);
		}
	}
	catch(_com_error e)///捕捉异常
	{
		CString errormessage;
		errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
		AfxMessageBox(errormessage);///显示错误信息
	    PostQuitMessage(0);
		m_pConnection1.Release();
		m_pRecordset1.Release();
		return FALSE;
	}*/

	if (InitCtiSystem() == FALSE)
	{
		PostQuitMessage(0);
		return FALSE;
	}



	CString temp;
	BOOL showlogindlg=TRUE;
//	AfxOleInit();
//	HRESULT hr;
	try
	{
		hr = m_pConnection.CreateInstance("ADODB.Connection");///创建Connection对象
		m_pRecordset.CreateInstance("ADODB.Recordset");
		if(SUCCEEDED(hr))
		{
			CString SERVER="",DATABASE="",UID="",PWD="";
			CIniFile IniFile;
			
			TCHAR exeFullPath[MAX_PATH];
			GetModuleFileName(NULL,exeFullPath,MAX_PATH);	
			CString inipath,cs;	
			inipath=_T(exeFullPath); //完整的应用目录
			
			//
			cs=(CString)theApp.m_pszExeName+".exe"; //可执行程序名称
			inipath.TrimRight(cs);	
		
			IniFile.SetPath(inipath);
			IniFile.SetName("DBInfo");
			BOOL bExist=IniFile.OpenIniFileForRead();
			if(bExist)
			{	IniFile.GetItemString("DBInfo","Path",RecordPath);
				IniFile.GetItemString("DBInfo","Path1",VirtualPath);
				for(int i=0;i<MaxLine;i++)
				{
					temp.Format("ZJNumber%d",i);
					IniFile.GetItemString("DBInfo",temp,ChannelState[i].ZJNumber);
				//	AfxMessageBox(ChannelState[i].ZJNumber);
				}
				
				IniFile.CloseIniFile();
				showlogindlg=TRUE;
			}
			else
			{				
				 return FALSE;
			}
		
				CString ConnectSQL;
				ConnectSQL="Driver={Microsoft Access Driver (*.mdb)};Dbq="+inipath+"record.mdb;Uid=Admin;Pwd=;";
				m_pConnection->ConnectionTimeout=8000;
				hr=m_pConnection->Open(_bstr_t(ConnectSQL),"","",adModeUnknown);
				
				m_pConnection->PutCursorLocation(adUseClient);
				
		}
	}
	catch(_com_error e)///捕捉异常
	{
		CString errormessage;
		errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
		AfxMessageBox(errormessage);///显示错误信息

		
		 m_pConnection.Release();
		 m_pRecordset.Release();
      	 return FALSE;
	} 
	InitChannelState();         //初始化通道信息
	InitChannelList();          //设置列表信息
	SetTimer(1, 100, NULL );    //每0.1秒发送一次WM_TIMER消息

	ListenChannel = MaxLine;
	char szTmp[100];
	for(int ch=0; ch<MaxLine; ch++)	
	{		
		_snprintf(szTmp, 100, "%d", ch);
		szTmp[99] = '\0';
		m_CurLine.InsertString(ch, szTmp);
    }
	m_CurLine.SetCurSel(0);

	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CGXRecordDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CGXRecordDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CGXRecordDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


//描述:初始化系统
bool CGXRecordDlg::InitCtiSystem()
{
	int nIsSsmStartCtiOK = SsmStartCti("ShConfig.ini", "ShIndex.ini");
	if(nIsSsmStartCtiOK != 0)
	{
		SsmGetLastErrMsg(szErrMsg);
		AfxMessageBox(szErrMsg, MB_OK, 0);
		return FALSE;
	}
	
	if(SsmGetMaxUsableBoard() != SsmGetMaxCfgBoard())
	{
		SsmGetLastErrMsg(szErrMsg);
		AfxMessageBox(szErrMsg, MB_OK, 0);
		return FALSE;
	}
	MaxLine = SsmGetMaxCh();
	if((MaxLine = SsmGetMaxCh()) == -1) //本函数取得应用程序在配置文件中声明的最大通道数
	{
		SsmGetLastErrMsg(szErrMsg);
		AfxMessageBox(szErrMsg, MB_OK, 0);	
		return FALSE;
	}
	
	CString str1;
	if(SsmGetAccreditIdEx(0)!=0002)
	{
		str1.Format("客户授权号!请联系软件开发商!");
		AfxMessageBox(str1, MB_OK) ;
		return false;
	}

	
	
	return TRUE;
}//InitCtiSystem End


void CGXRecordDlg::InitChannelState()
{
	int reGetChType;
	for(int i=0; i<MaxLine; i++)
	{
		reGetChType = SsmGetChType(i);
		if(reGetChType == -1)
		{
			SsmGetLastErrMsg(ChannelState[i].pErrMsg);
			WriteLog(ChannelState[i].pErrMsg);
		}

		if(reGetChType == 3)
		{
		    ChannelState[i].WorkState = CH_OUTLINE;     //"断线"  
			ChannelState[i].IsListen = UNLISTEN;        //"未监听"
            ChannelState[i].IsRecord = UNRECORD;        //"未录音"
			ChannelState[i].pCallerId[0] = '\0';        //号码为空
		    ChannelState[i].Lcd[0] = '\0' ;	            //LCD信息为空
			ChannelState[i].Dir = UNKNOWN ;             //呼叫方向未知
			ChannelState[i].Volume = 0 ;                //音量为0
            ChannelState[i].dwTimeOutCounter = 0;       //时间为0
 		}
	}
}//InitChannelState End


void CGXRecordDlg::InitChannelList()
{
	int reGetChType;
	static int VolumeWidth[10]={60, 80, 100, 120, 150, 100, 75, 55, 55};


	m_ListCh.SetExtendedStyle (LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_ONECLICKACTIVATE);
	


    LV_COLUMN lv;
	lv.mask = LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM ;
	
	lv.iSubItem = 0;
	lv.pszText = "通道号";
	lv.cx = VolumeWidth[0];
	m_ListCh.InsertColumn(0, &lv);

	lv.cx = VolumeWidth[1];
	lv.pszText = "通道状态";
	lv.iSubItem = 1;
	m_ListCh.InsertColumn(1, &lv);

	lv.cx = VolumeWidth[2];
	lv.pszText = "监听状态";
	lv.iSubItem = 2;
	m_ListCh.InsertColumn(2, &lv);

	lv.cx = VolumeWidth[3];
	lv.pszText = "录音状态";
	lv.iSubItem = 3;
	m_ListCh.InsertColumn(3, &lv);

	lv.cx = VolumeWidth[4];
	lv.pszText = "号码";
	lv.iSubItem = 4;
	m_ListCh.InsertColumn(4, &lv);

	lv.cx = VolumeWidth[5];
	lv.pszText = "LCD信息";
	lv.iSubItem = 5;
	m_ListCh.InsertColumn(5, &lv);

	lv.cx = VolumeWidth[6];
	lv.pszText = "呼叫方向";
	lv.iSubItem = 6;
	m_ListCh.InsertColumn(6, &lv);

	lv.cx = VolumeWidth[7];
	lv.pszText = "音量";
	lv.iSubItem = 7;
	m_ListCh.InsertColumn(7, &lv);

	lv.cx = VolumeWidth[8];
	lv.pszText = "时间";
	lv.iSubItem = 8;
	m_ListCh.InsertColumn(8, &lv);
   
    char ItemIndex[3];
	for(int i=0; i<MaxLine; i++)
	{
		reGetChType = SsmGetChType(i); //本函数取得指定通道编号对应的硬件通道类型 -1:失败
		if(reGetChType == -1)
		{
			SsmGetLastErrMsg(ChannelState[i].pErrMsg); //获取错误信息
			WriteLog(ChannelState[i].pErrMsg);	
		}

		if(reGetChType == 3)
		{
			wsprintf(ItemIndex, "%d", i);
            m_ListCh.InsertItem(i, ItemIndex);
		}
	}
}//InitChannelList End

void CGXRecordDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	UpdateData(TRUE);
	int i;
	i=0;
//	HRESULT hr;
	CString ConnectSQL;
	/*try
	{
	//	AfxMessageBox("ONT");
		//创建Connection对象
		hr = m_pConnection3.CreateInstance("ADODB.Connection");
		m_pRecordset3.CreateInstance("ADODB.Recordset");

		if(SUCCEEDED(hr))
		{
			CString SERVER="202.102.7.125",DATABASE="SQDxServerDB",UID="test",PWD="QZGATX3037555*@#";
			ConnectSQL = "provider=sqloledb;Server=" + SERVER + ";DATABASE="+DATABASE;
			ConnectSQL += ";UID=" + UID + ";Pwd=" + PWD;
			m_pConnection3->ConnectionTimeout=8000;
			hr=m_pConnection3->Open(_bstr_t(ConnectSQL),"","",adModeUnknown);
			
			m_pConnection3->PutCursorLocation(adUseClient);
		}
	}
	catch(_com_error e)///捕捉异常
	{
		CString errormessage;
		errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
		AfxMessageBox(errormessage);///显示错误信息
	    PostQuitMessage(0);
		m_pConnection3.Release();
		m_pRecordset3.Release();
		i=1;
		return ;
	}
		m_pConnection3.Release();
		m_pRecordset3.Release();*/
	if(2==1)
	{
		AfxMessageBox("ORR");
	}
	else
	{
	
		ScanChannelState();
		UpdateChannelState();
	}
	UpdateData(FALSE);
	CDialog::OnTimer(nIDEvent);
}


//描述:检查通道信息
void CGXRecordDlg::ScanChannelState()
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -