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

📄 searchdlg.cpp

📁 宾馆程控电话计费系统
💻 CPP
字号:
// SearchDlg.cpp : implementation file
//

#include "stdafx.h"
#include "tel2006.h"
#include "SearchDlg.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] = {100,80,120,60,120,60,60,90,100};

/////////////////////////////////////////////////////////////////////////////
// CSearchDlg dialog


CSearchDlg::CSearchDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CSearchDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSearchDlg)
	m_strPhone = _T("");
	m_strEndPhone = _T("");
	m_strStartPhone = _T("");
	m_radio = -1;
	m_strPrice = _T("");
	//}}AFX_DATA_INIT
	//m_manager = new CDataManager();
}


void CSearchDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSearchDlg)
	DDX_Control(pDX, IDC_COMBO, m_comboDept);
	DDX_Control(pDX, IDC_LIST, m_list);
	DDX_Control(pDX, IDC_STARTDATE, m_dtpStartDate);
	DDX_Control(pDX, IDC_STARTTIME, m_dtpStartTime);
	DDX_Control(pDX, IDC_ENDDATE, m_dtpEndDate);
	DDX_Control(pDX, IDC_ENDTIME, m_dtpEndTime);
	DDX_Text(pDX, IDC_EDIT_PHONE, m_strPhone);
	DDX_Text(pDX, IDC_EDIT_ENDPHONE, m_strEndPhone);
	DDX_Text(pDX, IDC_EDIT_STARTPHONE, m_strStartPhone);
	DDX_Radio(pDX, IDC_RADIO_ONE, m_radio);
	DDX_Text(pDX, IDC_EDIT_PRICE, m_strPrice);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSearchDlg, CDialog)
	//{{AFX_MSG_MAP(CSearchDlg)
	ON_BN_CLICKED(IDC_SEARCH_BUTTON, OnSearchButton)
	ON_BN_CLICKED(IDC_CANCEL_BUTTON, OnCancelButton)
	ON_BN_CLICKED(IDC_SAVE_BUTTON, OnSaveButton)
	ON_BN_CLICKED(IDC_RADIO_ONE, OnRadioOne)
	ON_BN_CLICKED(IDC_RADIO_MORE, OnRadioMore)
	ON_BN_CLICKED(IDC_RADIO_DEPT, OnRadioDept)
	ON_BN_CLICKED(IDC_SEARCHSTAT_BUTTON, OnSearchstatButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSearchDlg message handlers

void CSearchDlg::OnSearchButton() 
{
	// TODO: Add your control notification handler code here
	SetSQLStr();
	ShowSearchData();
}

void CSearchDlg::OnCancelButton() 
{
	// TODO: Add your control notification handler code here
	m_AdoConn.ExitConnect();
	//delete(m_manager);
	CDialog::OnCancel();
}

void CSearchDlg::FormatDataTime()
{
	CString strStartDate,strStartTime,strEndDate,strEndTime;
	UpdateData(true);
	CString strStartYear("");
	CString strEndYear("");

	strStartYear.Format("%4d",m_dtpStartDate.GetYear().iVal);
	strStartYear = strStartYear.Right(2);
	strStartDate.Format("%s年%2d月%2d日",
		strStartYear,
		m_dtpStartDate.GetMonth().iVal,
		m_dtpStartDate.GetDay().iVal);
	strStartDate.Replace(" ","0");

	strStartTime.Format("%2d:%2d",
		m_dtpStartTime.GetHour().iVal,
		m_dtpStartTime.GetMinute().iVal);
	strStartTime.Replace(" ","0");

	strEndYear.Format("%4d",m_dtpEndDate.GetYear().iVal);
	strEndYear = strEndYear.Right(2);
	strEndDate.Format("%s年%2d月%2d日",
		strEndYear,
		m_dtpEndDate.GetMonth().iVal,
		m_dtpEndDate.GetDay().iVal);
	strEndDate.Replace(" ","0");

	strEndTime.Format("%2d:%2d",
		m_dtpEndTime.GetHour().iVal,
		m_dtpEndTime.GetMinute().iVal);
	strEndTime.Replace(" ","0");

	m_strStartDateTime = strStartDate + " " +strStartTime;
	m_strEndDateTime = strEndDate + " " +strEndTime;
}


BOOL CSearchDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	InitList();
	m_radio = 0;
	m_AdoConn.OnInitADOConn(".");	
	ShowDept();
	UpdateData(false);
	return TRUE;
}

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

void CSearchDlg::InitList()
{
	LV_COLUMN lvC;
	int i;
	
	ListView_SetExtendedListViewStyle(m_list.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_list.m_hWnd, i, &lvC) == -1) 
			return;
	}
	ListView_SetItemCount(m_list.m_hWnd, VIEW_COLCOUNT);
}


void CSearchDlg::ShowSearchData()
{
	_variant_t var;
	CString strCount("");

	float fPrice =0.00;

	//设置SELECT语句
	CString strSQL;
	
	strSQL.Format(m_strSQL);
	_bstr_t vSQL =strSQL;
	
	_RecordsetPtr m_pRecordset;
	m_pRecordset = m_AdoConn.GetRecordSet(vSQL);

	int n = 0;
	m_list.DeleteAllItems();
	m_list.Invalidate(TRUE);

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

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

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

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

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

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

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

		var = m_pRecordset->GetCollect("T_Money");
		if(var.vt != VT_NULL)
		{
			m_list.SetItemText(n,6,(LPCSTR)_bstr_t(var));
			fPrice += (float)atof((LPCSTR)_bstr_t(var));
		}
		var = m_pRecordset->GetCollect("T_RelayLevel");
		if(var.vt != VT_NULL)
			m_list.SetItemText(n,7,(LPCSTR)_bstr_t(var));
		
		var = m_pRecordset->GetCollect("T_Remark");
		if(var.vt != VT_NULL)
			m_list.SetItemText(n,8,(LPCSTR)_bstr_t(var));

		m_pRecordset->MoveNext();
		n++;
	}
	m_list.Invalidate(TRUE);
	m_strPrice.Format("%.2f",fPrice);
	UpdateData(false);
}


void CSearchDlg::OnSaveButton() 
{
	// TODO: Add your control notification handler code here
	/*UpdateData(true);
	CString strFileName;
	CString strTemp;
	CString strData;//("分机, 房间号码,被叫号码,被叫地址,通话时间,通话时长,通话费用,中继线号,备注);
	CString strTop("");
	strTop += FormatString(6,"分机");
	strTop += FormatString(14,"房间号码");
	strTop += FormatString(16,"被叫号码");
	strTop += FormatString(10,"被叫地址");
	strTop += FormatString(20,"通话时间");
	strTop += FormatString(16,"通话时长");
	strTop += FormatString(10,"通话费用");
	strTop += FormatString(4,"中继线号");
	strTop += FormatString(20,"备注");
	strTop+=0x0d; strTop+=0x0a;

	CString strLine("----------------------------------------------------------------------------------------------------------");
	strLine+=0x0d;strLine+=0x0a;
	CFileDialog dlg(TRUE,"*.txt","电话计费数据.txt",OFN_ALLOWMULTISELECT,"text files(*.txt)|*.txt",this);
	if(IDOK == dlg.DoModal())
	{
		POSITION pos = dlg.GetStartPosition();
		while(pos!=NULL)
		{
			strFileName = dlg.GetNextPathName(pos);
			//CreateSaveFile(strFileName);
			WriteSaveFile(strFileName,strTop);
			WriteSaveFile(strFileName,strLine);
			for(int n = 1; n<m_list.GetItemCount(); n++)
			{
				//WriteSaveFile(strFileName,strLine);
				strData = "";
				strData += FormatString(6,m_list.GetItemText(n,0));
				strData += FormatString(14,m_list.GetItemText(n,1));
				strData += FormatString(16,m_list.GetItemText(n,2));
				strData += FormatString(10,m_list.GetItemText(n,3));
				strData += FormatString(20,m_list.GetItemText(n,4));
				strData += FormatString(16,m_list.GetItemText(n,5));
				strData += FormatString(10,m_list.GetItemText(n,6));
				strData += FormatString(4,m_list.GetItemText(n,7));
				strData += FormatString(20,m_list.GetItemText(n,8));
				strData +=0x0d;	strData +=0x0a;
				WriteSaveFile(strFileName, strData);
			}
			WriteSaveFile(strFileName,strLine);
			strTemp= "合计: ";
			strTemp+=m_strPrice;
			strTemp+=" 元";
			
			WriteSaveFile(strFileName,strTemp);
		}
		AfxMessageBox("保存完毕");
	}*/
}
void CSearchDlg::CreateSaveFile(CString strFileName)
{
	CFile file;
	if( !file.Open(strFileName,CFile::modeCreate))
	{
		AfxMessageBox("写文件不能打开1");
	}
	file.Close();
}

void CSearchDlg::WriteSaveFile(CString strFileName, CString strData)
{
	CFile file;
	if( !file.Open(strFileName,CFile::modeCreate|CFile::modeWrite))
	{
		AfxMessageBox("写文件不能打开2");
	}
	file.SeekToEnd();
	file.Write(strData,strData.GetLength());
	file.Close();
}

CString CSearchDlg::FormatString(int nLen,CString str)
{
	CString strTemp = str;
	if(str.GetLength()<nLen)
	{
		for(int n=0; n<(nLen-str.GetLength()); n++)
		{
			strTemp = strTemp+ " ";
		}
	}
	return strTemp;
}


void CSearchDlg::ShowDept()
{
	_variant_t var;
	CString strCount("");
	CString strTemp;	
	
	//设置SELECT语句
	CString strSQL;
	
	strSQL.Format("select T_DeptID,T_DeptName from R_TelDept");
	_bstr_t vSQL =strSQL;
	
	_RecordsetPtr m_pRecordset;
	m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
	
	m_comboDept.ResetContent();

	while(!m_pRecordset->adoEOF)
	{
		strTemp = "";
		var = m_pRecordset->GetCollect("T_DeptID");
		if(var.vt != VT_NULL)
			strTemp += (LPCSTR)_bstr_t(var);

		var = m_pRecordset->GetCollect("T_DeptName");
		if(var.vt != VT_NULL)
			strTemp += (LPCSTR)_bstr_t(var);

		m_comboDept.AddString(strTemp);
		m_pRecordset->MoveNext();
	}
	m_comboDept.SetCurSel(0);
}

void CSearchDlg::OnRadioOne() 
{
	// TODO: Add your control notification handler code here
	m_radio =0 ;
}

void CSearchDlg::OnRadioMore() 
{
	// TODO: Add your control notification handler code here
	m_radio =1 ;
}

void CSearchDlg::OnRadioDept() 
{
	// TODO: Add your control notification handler code here
	m_radio =2;
}

void CSearchDlg::OnSearchstatButton() 
{
	SetSQLStr();
	ShowStatData();
}

void CSearchDlg::SetSQLStr()
{
	UpdateData(true);
	m_strSQL = "select * from R_TelCallList ";
	CString strWhere;

	FormatDataTime();
	if(m_strStartDateTime <= m_strEndDateTime)
	{
		strWhere = "Where T_CallTime >'" + m_strStartDateTime
			+ "' and T_callTime<'"+m_strEndDateTime+"'";
	}
	else
	{
		AfxMessageBox("日期条件错误");
		return;
	}
	switch(m_radio)
	{
	case 0:
		if(m_strPhone.GetLength()!=0)
		{
			strWhere += " and T_Number = '"+m_strPhone+"'";
			m_strSQL+=strWhere;
		}
		break;
	case 1:
		strWhere +=" and T_Number>='" + m_strStartPhone 
			+ "' and T_Number<='" + m_strEndPhone + "'";
		m_strSQL+=strWhere;
		break;
	case 2:
		CString strDeptID;
		m_comboDept.GetLBText(m_comboDept.GetCurSel(),strDeptID);
		strDeptID = strDeptID.Left(2);
		m_strSQL.Format("select * from R_TelCallList,R_telPhone \
			where R_TelCallList.T_Number = R_TelPhone.T_Number \
			and R_TelPhone.T_DeptID = '%s' \
			and T_CallTime >'%s' and T_callTime<'%s'",\
			strDeptID,m_strStartDateTime,m_strEndDateTime);
		break;
	}
}

void CSearchDlg::ShowStatData()
{
	_variant_t var;
	CString strCount("");
	CString strTemp ="";
	float fPrice =0.00;
	float fPrice01 = 0.00;
	float fPrice02 = 0.00;
	float fPrice03 = 0.00;
	float fPrice04 = 0.00;
	float fPrice05 = 0.00;
	float fPrice06 = 0.00;
	float fPrice07 = 0.00;
	float fPriceSum = 0.00;

	CString strPrice01,strPrice02,strPrice03,strPrice04,strPrice05;
	CString strPrice06,strPrice07,strPriceSum;
	CString strTypeID("");
	//设置SELECT语句
	CString strSQL;
	
	strSQL.Format(m_strSQL);
	_bstr_t vSQL =strSQL;
	
	_RecordsetPtr m_pRecordset;
	m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
	
	while(!m_pRecordset->adoEOF)
	{
		var = m_pRecordset->GetCollect("T_TypeID");
		if(var.vt != VT_NULL)
			strTypeID = (LPCSTR)_bstr_t(var);

		var = m_pRecordset->GetCollect("T_Money");
		if(var.vt != VT_NULL)
		{
			fPrice = (float)atof((LPCSTR)_bstr_t(var));
		}

		strTypeID.TrimLeft();
		strTypeID.TrimRight();

		fPriceSum+=fPrice;	// 总和

		if(strTypeID == "01")	// 国际长途
			fPrice01 +=fPrice;
		else if(strTypeID == "02")	// 国内长途
			fPrice02 +=fPrice;
		else if(strTypeID == "03")	// 外地手机
			fPrice03 +=fPrice;
		else if(strTypeID == "04")	// 本地手机
			fPrice04 +=fPrice;
		else if(strTypeID == "05")	// 市内
			fPrice05 +=fPrice;
		else if(strTypeID == "06")	// 信息台
			fPrice06 +=fPrice;
		else					// 其它
			fPrice07 +=fPrice;
		
		m_pRecordset->MoveNext();
	}

	strPrice01.Format("%.2f",fPrice01);
	strPrice02.Format("%.2f",fPrice02);
	strPrice03.Format("%.2f",fPrice03);
	strPrice04.Format("%.2f",fPrice04);
	strPrice05.Format("%.2f",fPrice05);
	strPrice06.Format("%.2f",fPrice06);
	strPrice07.Format("%.2f",fPrice07);
	strPriceSum.Format("%.2f",fPriceSum);

	m_list.InsertItem(0,"");
	m_list.SetItemText(0,0,"查询:");
	switch(m_radio)
	{
	case 0:
		m_list.SetItemText(0,1,m_strPhone);	
		break;
	case 1:
		strTemp =  m_strStartPhone;
		strTemp += "-";
		strTemp += m_strEndPhone;
		m_list.SetItemText(0,1,strTemp);	
		break;
	case 2:
		m_comboDept.GetLBText(m_comboDept.GetCurSel(),strTemp);
		m_list.SetItemText(0,1,strTemp);	
		break;
	}
	m_list.InsertItem(1,"");
	m_list.SetItemText(1,0,"国际长途:");
	m_list.SetItemText(1,1,strPrice01);

	m_list.InsertItem(2,"");
	m_list.SetItemText(2,0,"国内长途:");
	m_list.SetItemText(2,1,strPrice02);

	m_list.InsertItem(3,"");
	m_list.SetItemText(3,0,"外地手机:");
	m_list.SetItemText(3,1,strPrice03);

	m_list.InsertItem(4,"");
	m_list.SetItemText(4,0,"本地手机:");
	m_list.SetItemText(4,1,strPrice04);

	m_list.InsertItem(5,"");
	m_list.SetItemText(5,0,"市内:");
	m_list.SetItemText(5,1,strPrice05);

	m_list.InsertItem(6,"");
	m_list.SetItemText(6,0,"信息台:");
	m_list.SetItemText(6,1,strPrice06);

	m_list.InsertItem(7,"");
	m_list.SetItemText(7,0,"其他:");
	m_list.SetItemText(7,1,strPrice07);

	m_list.Invalidate(TRUE);
	m_strPrice.Format("%.2f",fPriceSum);
	UpdateData(false);
}

⌨️ 快捷键说明

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