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

📄 tel2006dlg.cpp

📁 本程序是一个宾馆程控电话系统
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// Tel2006Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "Tel2006.h"
#include "Tel2006Dlg.h"

#include "SettingDlg.h"
#include "SearchDlg.h"
#include "ManualDlg.h"
#include "PhoneDlg.h"
#include "DeptDlg.h"
#include "RateDlg.h"
#include "AssignDlg.h"
#include "AdrateDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

#define VIEW_COLCOUNT 9

static char s_view_colname[VIEW_COLCOUNT][10] = {"分机", "分机描述","被叫号码","被叫地址","通话时间","通话时长","通话费用","中继线号","备注"};
static int s_view_colwidth[VIEW_COLCOUNT] = {80,100,120,100,140,100,100,80,100};

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

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();
	
	// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}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)
	//}}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)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTel2006Dlg dialog

CTel2006Dlg::CTel2006Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CTel2006Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTel2006Dlg)
	m_strData = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	memset(rxdata,0,sizeof(rxdata));
	nIndex = 0;
	//m_manager = new CDataManager();
}

void CTel2006Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTel2006Dlg)
	DDX_Control(pDX, IDC_STORAGE, m_staticStorage);
	DDX_Control(pDX, IDC_LIST, m_lstShow);
	DDX_Text(pDX, IDC_EDIT_DATA, m_strData);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTel2006Dlg, CDialog)
//{{AFX_MSG_MAP(CTel2006Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(IDM_ABOUT, OnAbout)
ON_COMMAND(IDM_EXIT, OnExit)
ON_COMMAND(IDM_CLEAR, OnClear)
	ON_WM_TIMER()
	ON_COMMAND(IDM_SHOW, OnShow)
	ON_COMMAND(IDC_SETCOM, OnSetcom)
	ON_COMMAND(IDM_SEARCH, OnSearch)
	ON_COMMAND(IDM_PHONE, OnPhone)
	ON_COMMAND(IDM_DEPT, OnDept)
	ON_COMMAND(IDM_RATE, OnRate)
	ON_COMMAND(IDM_ASSGIN, OnAssgin)
	ON_COMMAND(IDM_MINISIZE, OnMinisize)
	ON_COMMAND(IDM_ADRATE, OnAdrate)
	//}}AFX_MSG_MAP
ON_MESSAGE(WM_COMM_RXCHAR,OnCommunication)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTel2006Dlg message handlers

BOOL CTel2006Dlg::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
	
	// TODO: Add extra initialization here

	// 最大化窗口
	ShowWindow(SW_SHOWMAXIMIZED);	

	// 取得当前窗口大小
	CRect rcWin;
	GetWindowRect(&rcWin);

	// 设定底部信息栏位置及大小
	this->GetDlgItem(IDC_STATIC_VER)->MoveWindow(rcWin.right - 100, rcWin.bottom - 75,
		90, 20);
	this->GetDlgItem(IDC_NOWTIME)->MoveWindow(rcWin.right - 220, rcWin.bottom - 75,
		120, 20);
	this->GetDlgItem(IDC_STORAGE)->MoveWindow(rcWin.right - 280, rcWin.bottom - 75,
		60, 20);
	this->GetDlgItem(IDC_STATIC_NOTECOUNT)->MoveWindow(rcWin.right - 340, rcWin.bottom - 75,
		60, 20);
	this->GetDlgItem(IDC_STARTTIME)->MoveWindow(rcWin.right - 460, rcWin.bottom - 75,
		120, 20);
	
	// 设定信息显示编辑框位置
	this->GetDlgItem(IDC_EDIT_DATA)->MoveWindow(rcWin.left + 5, rcWin.bottom - 270,
		rcWin.Width() - 10, 190);

	// 设定列表位置
	this->GetDlgItem(IDC_LIST)->MoveWindow(rcWin.left + 5, rcWin.top + 3,
		rcWin.Width() - 10, rcWin.Height() - 275);
		

	m_AdoConn.OnInitADOConn(".");
	
	// Init Port
	if(m_Ports.InitPort(this,1,4800))
		m_Ports.StartMonitoring();
	else
		AfxMessageBox("无此端口");
	
	// InitList
	InitList();
	//ShowList();

	// Init StartTime
	CString strStartTime;
	strStartTime.Format("%s %s",GetCurDate(),GetCurTime());
	GetDlgItem(IDC_STARTTIME)->SetWindowText(strStartTime);

	// Init NowTime
	SetTimer(1,500,NULL);
	UpdateData(false);

	return TRUE; 
}

void CTel2006Dlg::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 CTel2006Dlg::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 CTel2006Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


/*******************************
 *	InitList
 *
 *	Remark:	初始化List控件
 ******************************/

void CTel2006Dlg::InitList()
{
	LV_COLUMN lvC;
	int i;
	
	ListView_SetImageList(m_lstShow.m_hWnd, ImageList_Create(1, 16, ILC_COLOR, 1, 1), LVSIL_SMALL);
	ListView_SetExtendedListViewStyle(m_lstShow.m_hWnd, LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);
	
	lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
	lvC.fmt = LVCFMT_LEFT;
	for (i = 0; i < VIEW_COLCOUNT; i++) 
	{
		lvC.pszText = s_view_colname[i];
		lvC.cx = s_view_colwidth[i];
		lvC.iSubItem = i;
		if (ListView_InsertColumn(m_lstShow.m_hWnd, i, &lvC) == -1) return;
	}
	ListView_SetItemCount(m_lstShow.m_hWnd, VIEW_COLCOUNT);
}


/****************************
 *	OnExit
 *
 *	Remark:	退出
 ****************************/

void CTel2006Dlg::OnExit() 
{
	// TODO: Add your command handler code here
	m_AdoConn.ExitConnect();
	//delete(m_manager);
	CDialog::OnOK();
}


/***************************
 *	OnAbout
 *
 *	Remark:弹出关于窗口
 ***************************/

void CTel2006Dlg::OnAbout() 
{
	// TODO: Add your command handler code here
	CAboutDlg dlg;
	dlg.DoModal();
}


/*****************************
 *	OnClear
 *
 *	Remark:	清空listView控件
 ****************************/

void CTel2006Dlg::OnClear() 
{
	// TODO: Add your command handler code here
	m_lstShow.DeleteAllItems();
	m_lstShow.Invalidate(TRUE);
}


/*********************************************** 
 *  函数名: CTel2006Dlg::OnSearch
 * 
 *  功  能: 查询窗体
 *
 *  返回值: void 
 ***********************************************/

void CTel2006Dlg::OnSearch() 
{
	// TODO: Add your command handler code here
	CSearchDlg dlg;
	dlg.DoModal();
}

/*****************************************
 *	ShowList
 *
 *	Remark:	显示
 *****************************************/

void CTel2006Dlg::ShowList()
{
	_variant_t var;
	CString strCount("");
	
	//ADOConn m_AdoConn;
	//m_AdoConn.OnInitADOConn(m_strDataBase);	
	
	//设置SELECT语句
	CString strSQL;
	
	strSQL.Format("select * from R_TelCallList");
	_bstr_t vSQL =strSQL;
	
	_RecordsetPtr m_pRecordset;
	m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
	
	// Get RecordCout
	
	long lCount = 0;
	lCount = m_pRecordset->GetRecordCount();
	if (lCount == -1)
	{
		if (m_pRecordset->adoEOF != VARIANT_TRUE) 
			m_pRecordset->MoveFirst();
		
		while (m_pRecordset->adoEOF != VARIANT_TRUE)
		{
			lCount++;
			m_pRecordset->MoveNext();
		}
		if (lCount >=0) 
			m_pRecordset->MoveFirst();
	}
	lCount++;
	strCount.Format("%d 张",lCount);
	GetDlgItem(IDC_STORAGE)->SetWindowText(strCount);
	int n = 0;
	//"分机", "房间号码","被叫号码","被叫地址","通话时间","通话时长","通话费用","中继线号","备注"
	//T_Number,	T_TableCode,T_CalledNum,T_Place,	T_CallTime,T_Times,T_Money,	T_RelayLevel,T_Remark		
	m_lstShow.DeleteAllItems();
	m_lstShow.Invalidate(TRUE);

	while(!m_pRecordset->adoEOF)
	{
		m_lstShow.InsertItem(n,"");

		var = m_pRecordset->GetCollect("T_Number");
		if(var.vt != VT_NULL)
			m_lstShow.SetItemText(0,0,(LPCSTR)_bstr_t(var));

		var = m_pRecordset->GetCollect("T_Describe");
		if(var.vt != VT_NULL)
			m_lstShow.SetItemText(n,1,(LPCSTR)_bstr_t(var));

		var = m_pRecordset->GetCollect("T_CalledNum");
		if(var.vt != VT_NULL)
			m_lstShow.SetItemText(n,2,(LPCSTR)_bstr_t(var));

		var = m_pRecordset->GetCollect("T_Place");
		if(var.vt != VT_NULL)
			m_lstShow.SetItemText(n,3,(LPCSTR)_bstr_t(var));

		var = m_pRecordset->GetCollect("T_CallTime");
		if(var.vt != VT_NULL)
			m_lstShow.SetItemText(n,4,(LPCSTR)_bstr_t(var));

		var = m_pRecordset->GetCollect("T_Times");
		if(var.vt != VT_NULL)
			m_lstShow.SetItemText(n,5,(LPCSTR)_bstr_t(var));

		var = m_pRecordset->GetCollect("T_Money");
		if(var.vt != VT_NULL)
			m_lstShow.SetItemText(n,6,(LPCSTR)_bstr_t(var));

		var = m_pRecordset->GetCollect("T_RelayLevel");
		if(var.vt != VT_NULL)
			m_lstShow.SetItemText(n,7,(LPCSTR)_bstr_t(var));
		
		var = m_pRecordset->GetCollect("T_Remark");
		if(var.vt != VT_NULL)
			m_lstShow.SetItemText(n,8,(LPCSTR)_bstr_t(var));

		m_pRecordset->MoveNext();
	}
	//m_AdoConn.ExitConnect();
}


/*************************************
 *	AddList
 *
 *	Parameters:	structData	// 结构体
 *
 *	Remark:	添加入ListView中,显示
 ************************************/

void CTel2006Dlg::AddList(structData structData)
{
	int Count = m_lstShow.GetItemCount();
	CString strCount;
	int nCount;
	if (Count > 500)
	{
		m_lstShow.DeleteAllItems();
		m_lstShow.Invalidate(TRUE);
	}		
	//"分机", "房间号码","被叫号码","被叫地址","通话时间","通话时长","通话费用","中继线号","备注"
	m_lstShow.InsertItem(0,"");
	m_lstShow.SetItemText(0,0,structData.strCalling);
	m_lstShow.SetItemText(0,1,structData.strDescribe);
	m_lstShow.SetItemText(0,2,structData.strCalled);
	m_lstShow.SetItemText(0,3,structData.strPlace);
	m_lstShow.SetItemText(0,4,structData.strDate);
	m_lstShow.SetItemText(0,5,structData.strTime);
	m_lstShow.SetItemText(0,6,structData.strPrice);
	m_lstShow.SetItemText(0,7,structData.strRelay);
	m_lstShow.SetItemText(0,8,structData.strRemark);

	GetDlgItem(IDC_STORAGE)->GetWindowText(strCount);
	nCount = atoi(strCount);
	nCount++;
	strCount.Format("%d",nCount);
	GetDlgItem(IDC_STORAGE)->SetWindowText(strCount);
	UpdateData(false);
}


/*******************************************
 *	OnTest
 *
 *	Remark:	测试
 *******************************************/




/****************************************
 *	On Communication 
 *	
 *	Parameters:	WPARAM	ch		// 字符
 *				LPARAM	port	// 端口
 *
 *	Remark:	事件处理函数
 ****************************************/

LONG CTel2006Dlg::OnCommunication(WPARAM ch, LPARAM port)
{
	rxdata[nIndex]=(BYTE)ch;
	nIndex++;
	
	if(ch!=NULL)
	{
		m_strData+=ch;
		UpdateData(false);
	}
	if(ch == 10)// && rxdata[nIndex-2] == 13)
	{
		rxdata[nIndex] = 0x00;
		m_strData = rxdata;
		// 处理字符串
		if(m_strData.GetLength()>2)
			ProcessString(m_strData);
		else
			m_strData = "";
		
		memset(rxdata,0,sizeof(rxdata));
		nIndex = 0;

		UpdateData(false);
	}
	return 0;
}


/********************************************** 
 *	ProcessString	
 *	
 *	Parameters:	CString str	// 待处理字符串
 *
 *	Remark:	处理从串口接收的字符串
 *********************************************/

void CTel2006Dlg::ProcessString(CString str)
{
	CString strLog("");	CString strLeaveMoney;
	int nResult =0;

	BOOL bCalOk=false;

	structData	structData;
	structFB	structFB;

	InitStructData(structData);
	InitStructFB(structFB);
	/*1 判断数据是否合法
	  2 如果合法检索填充structData
	  3 如果不合法 跳出
	  4 检索R_TelRate表填充structData
	  5 根据被叫号码得到TableCode,描述
	  6 根据TableCode得到ParlorCode,BedNo,BillCode
	*/
	// 数据合法
	if(AnalyseString(str,structData))	
	{
		nResult = 1;
		// 检索R_TelRate 填充structData结构体
		if(FillCallList(structData))
		{
			nResult =2;
			if(GetRTelPhone(structData,structFB))	// Get TableCode,Describe by Called
			{
				if(GetRPointCardInfo(structFB))	// Get ParlorCode,BedNo,BillCode by TableCode
				{
					structFB.strMenuID  = GetMenuID(structFB.strParlorCode);
					structFB.strPserial = GetPserial();
					structFB.strCurDate = GetCurDate();
					structFB.strCurTime = GetCurTime();
					structFB.strPrice	= structData.strPrice;
					structFB.strTypeID	= structData.strTypeID;
					// 插入点单附表
					InsertPointCardFB(structFB);
					
					if(structFB.strGfMark =="0")
					{
						GetLeaveMoney(structFB.strBillCode,strLeaveMoney);
						SubLeaveMoney(structFB.strBillCode,structFB.strPrice,strLeaveMoney);
					}
					else
					{
						GetLeaveMoney(structFB.strBattery,strLeaveMoney);

⌨️ 快捷键说明

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