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

📄 tel2006dlg.cpp

📁 本程序是一个宾馆程控电话系统
💻 CPP
📖 第 1 页 / 共 3 页
字号:
						SubLeaveMoney(structFB.strBattery,structFB.strPrice,strLeaveMoney);
					}
				}
				// 插入通话明细表
				//structData.strID	= GetID(); 
				structData.strID	= GetPserial();
				structData.strDate	= FormatDate(structData.strDate);
				structData.strTime	= FormatTime(structData.strTime);
				structData.strBillCode = structFB.strBillCode;
				structData.strBedNo = structFB.strBedNo;
				structData.strParlorCode = structFB.strParlorCode;
				structData.strTableCode = structFB.strTableCode;
				
				InsertCallList(structData);
				
				AddList(structData);
				
				//WriteData("log.txt","处理成功一条数据");
			}
		}
		//else 没有费率
	}
	else
	{	// 数据不正确
		strLog.Format("原始数据不规范%s",str);
		//WriteData("log.txt",strLog);
	}
	InitStructData(structData);
	InitStructFB(structFB);
}


/******************************************************** 
 *  函数名: CTel2006Dlg::AnalyseString
 * 
 *  功  能: 分析字符串,并填充结构体
 * 
 *  参  数: CString strData		// 待处理字符串	
 *          structData &data	// 通话明细结构体(返回)
 *
 *  返回值: BOOL	//	数据是否正确
 *********************************************************/

BOOL CTel2006Dlg::AnalyseString(CString strData,structData &data)
{
	//structData data;
	if(strData.GetLength()!=109)
		return false;
	data.strCalling	= TrimString(strData.Mid(25,4));
	data.strCalled	= TrimString(strData.Mid(50,20));
	data.strDate	= TrimString(strData.Mid(73,11));
	data.strTime	= TrimString(strData.Mid(85,6));
	data.strRelay	= TrimString(strData.Mid(38,2));
	
	return true;
}


/*********************************************** 
 *  函数名: CTel2006Dlg::FormatDate
 * 
 *  功  能: 格式化日期"060105 1410" -> "06年01月05日 14:10"
 * 
 *  参  数: CString strDate	// 待格式字符串
 *
 *  返回值: CString		//	格式化后的字符串
 ***********************************************/

CString CTel2006Dlg::FormatDate(CString strDate)
{
	//060105 1410
	strDate.Format("%s年%s月%s日 %s:%s",strDate.Mid(0,2),strDate.Mid(2,2),\
		strDate.Mid(4,2),strDate.Mid(7,2),strDate.Mid(9,2));
	
	return strDate;
}


/********************************************	
 *	FormatTime
 *
 *	Parameters:	strTime	// 待格式化字符串
 *
 *	Return Values:	strTime	// 格式化后字符串
 *
 *	Remark:	格式化时间	"000043"->"00:00:43"
 ********************************************/

CString CTel2006Dlg::FormatTime(CString strTime)
{
	//000043
	int nSec;
	int nHour,nMinute,nSecond;
	CString strHour,strMinute,strSecond;
	
	nSec = atoi(strTime);
	
	nHour = nSec/3600;
	nMinute  = nSec/60%60;
	nSecond	=  nSec%60;
	
	strTime.Format("%2d:%2d:%2d",nHour,nMinute,nSecond);
	strTime.Replace(" ","0");
	return strTime;
}


/************************************
 *	TrimStirng
 *
 *	Parameters:	str	
 *
 *	Return Values:	str
 *
 *	Remark:	Trim 字符串去掉左右空格
 ***********************************/

CString CTel2006Dlg::TrimString(CString str)
{
	str.TrimLeft();
	str.TrimRight();
	return str;
}


/*
*	根据根据 分机号 检索 分机信息表 得到房间号
*	
*	Parameters :	CString strNumber	// 电话号码	
*
*	Return Values:	structData &data	//	通话明细结构体
*					BOOL				//	数据是否正确	
*/

BOOL CTel2006Dlg::GetRTelPhone(structData& structData,structFB &structFB)
{
	_variant_t var;
	
	//ADOConn m_AdoConn;
	//m_AdoConn.OnInitADOConn(m_strDataBase);
	
	//设置SELECT语句
	CString strSQL;
	strSQL.Format("select T_Describe,T_RoomCode From R_TelPhone where T_Number = '%s'",structData.strCalling);
	_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();
		else	return false;
	}
	while(!m_pRecordset->adoEOF)
	{
		var = m_pRecordset->GetCollect("T_Describe");
		if(var.vt != VT_NULL)
			structData.strDescribe = (LPCSTR)_bstr_t(var);
		
		var = m_pRecordset->GetCollect("T_RoomCode");
		if(var.vt != VT_NULL)
			structFB.strTableCode = (LPCSTR)_bstr_t(var);
		
		m_pRecordset->MoveNext();
	}
	//m_AdoConn.ExitConnect();
	return true;
	
}


/************************************************
 *	FillCallList
 *	
 *	Parameters :	structData	// 结构体
 *
 *	Return Values:	bool	// 成功true	失败false
 *  
 *  Remark:		根据被叫号码检索数据库R_TelRate,
 *				得到相应信息计算话费,并填充结构体
 *************************************************/

BOOL CTel2006Dlg::FillCallList(structData& structData)
{
	CString strTmp;

	structRate structRate;
	InitStructRate(structRate);

	int nTwice=0;	float fFirstPrice=0;	float fEveryPrice=0;	float fPrice=0;
	
	_variant_t var;
	
	//ADOConn m_AdoConn;
	//m_AdoConn.OnInitADOConn(m_strDataBase);
	
	//设置SELECT语句
	CString strSQL;
	strSQL = "select * From R_TelRate where '"+structData.strCalled+"' like T_Code+'%'";
	//strSQL="select * From R_TelRate where '01012345678' like T_Code+'%'";
	_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();
		else
			return false;
	}
	while(!m_pRecordset->adoEOF)
	{
		var = m_pRecordset->GetCollect("T_TypeID");
		if(var.vt != VT_NULL)	structRate.strTypeID	= (LPCSTR)_bstr_t(var);
		var = m_pRecordset->GetCollect("T_TypeName");
		if(var.vt != VT_NULL)	structRate.strTypeName	= (LPCSTR)_bstr_t(var);
		var = m_pRecordset->GetCollect("T_Place");
		if(var.vt != VT_NULL)	structRate.strPlace		= (LPCSTR)_bstr_t(var);
		var = m_pRecordset->GetCollect("T_StaySec");
		if(var.vt != VT_NULL)	structRate.nStaySec		= atoi((LPCSTR)_bstr_t(var));
		var = m_pRecordset->GetCollect("T_FirstSec");
		if(var.vt != VT_NULL)	structRate.nFirstSec	= atoi((LPCSTR)_bstr_t(var));
		var = m_pRecordset->GetCollect("T_FirstPrice");
		if(var.vt != VT_NULL)	structRate.fFirstPrice	= (float)atof((LPCSTR)_bstr_t(var));
		var = m_pRecordset->GetCollect("T_EverySec");
		if(var.vt != VT_NULL)	structRate.nEverySec	= atoi((LPCSTR)_bstr_t(var));
		var = m_pRecordset->GetCollect("T_EveryPrice");
		if(var.vt != VT_NULL)	structRate.fEveryPrice	= (float)atof((LPCSTR)_bstr_t(var));
		var = m_pRecordset->GetCollect("T_Adrate1");
		if(var.vt != VT_NULL)	structRate.fAdrate1		= (float)atoi((LPCSTR)_bstr_t(var));
		var = m_pRecordset->GetCollect("T_Adrate2");
		if(var.vt != VT_NULL)	structRate.fAdrate2		= (float)atoi((LPCSTR)_bstr_t(var));
		var = m_pRecordset->GetCollect("T_Poundage1");
		if(var.vt != VT_NULL)	structRate.fPoundage1	= (float)atoi((LPCSTR)_bstr_t(var));
		var = m_pRecordset->GetCollect("T_Poundage2");
		if(var.vt != VT_NULL)	structRate.fPoundage2	= (float)atoi((LPCSTR)_bstr_t(var));
		var = m_pRecordset->GetCollect("T_IsCheapen");
		if(var.vt != VT_NULL)	structRate.strIsCheapen = (LPCSTR)_bstr_t(var);
		
		m_pRecordset->MoveNext();
	}
	// 没有超过起算秒数
	if(atoi(structData.strTime) < structRate.nStaySec)
		structData.strPrice = "0.00";
	// 没有超过首次
	if(atoi(structData.strTime) < structRate.nFirstSec)
		fPrice = structRate.fFirstPrice;
	else// 超过首次
	{
		nTwice = ((atoi(structData.strTime) - structRate.nFirstSec) /structRate.nEverySec) +1;
		fPrice = structRate.fFirstPrice + (nTwice * structRate.fEveryPrice);
	}
	//m_AdoConn.ExitConnect();
	fPrice+=(float)(fPrice*(structRate.fAdrate1/100));
	//if(structData.strTypeID =="02" )
	//	fPrice+=(float)(fPrice*0.1); 
	structData.strTypeID = structRate.strTypeID;
	structData.strTypeName = structRate.strTypeName;
	structData.strPlace = structRate.strPlace;
	structData.strPrice.Format("%.2f",fPrice);
	structData.strTwice.Format("%d",nTwice);
	structData.strAdrate.Format("%f",structRate.fAdrate1+structRate.fAdrate2);
	structData.strPoundage.Format("%f",structRate.fPoundage1+structRate.fPoundage2);
	structData.strBasic = structData.strPrice;
	return true;
}


/*****************************************
 *	InsertCallList
 *
 *	Parameters:	structData	//结构体数据
 *
 *	Remark:	插入通话明细表
 *****************************************/

void CTel2006Dlg::InsertCallList(structData structData)
{
	CString strSQL("");
	try
	{
	//ADOConn m_AdoConn;
	//m_AdoConn.OnInitADOConn(m_strDataBase);
	
	strSQL.Format ("INSERT INTO R_TelCallList(\
	T_ID,T_Number,T_CalledNum,T_TypeID,\
	T_TypeName,T_CallTime,T_Times,T_Time,\
	T_Basic,T_Adrate,T_Poundage,T_Money,\
	T_RelayLevel,T_Remark,T_BillCode,T_IsAccount,\
	T_Auto,T_Describe,T_Place,T_BedNo,T_ParlorCode,T_TableCode)\
	VALUES('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",\
	structData.strID,structData.strCalling,structData.strCalled,structData.strTypeID,\
	structData.strTypeName,structData.strDate,structData.strTime,structData.strTwice,\
	structData.strBasic,structData.strAdrate,structData.strPoundage,structData.strPrice,\
	structData.strRelay,structData.strRemark,structData.strBillCode,structData.strIsAccount,\
	structData.strAuto,structData.strDescribe,structData.strPlace,structData.strBedNo,\
	structData.strParlorCode,structData.strTableCode);
		
	_bstr_t vSQL =strSQL;
	m_AdoConn.ExecuteSQL(vSQL);
	//m_AdoConn.ExitConnect();
	}
	catch (_com_error e) 
	{
		CString errormessage;
		
		errormessage.Format("自定义错误信息1:%s",e.ErrorMessage());
		
		AfxMessageBox(errormessage);///显示错误信息
	}
}


/*********************************************************************
 *	GetID
 *
 *	Return Values: strID	//序列号
 *
 *	Remark:	获得R_TelCallList号,查找R_TelCallList中最大的strID然后加一
 *********************************************************************/

CString CTel2006Dlg::GetID()
{
	CString strID;
	int nID,nMaxID;
	nID = 0;
	nMaxID=0;
	_variant_t var;
	
	//ADOConn m_AdoConn;
	//m_AdoConn.OnInitADOConn(m_strDataBase);
	
	//设置SELECT语句
	CString strSQL;
	strSQL= "select T_ID From R_TelCallList";
	_bstr_t vSQL =strSQL;
	
	_RecordsetPtr m_pRecordset;
	m_pRecordset = m_AdoConn.GetRecordSet(vSQL);
	// Get RecordCout
	while(!m_pRecordset->adoEOF)
	{
		var = m_pRecordset->GetCollect("T_ID");
		if(var.vt != VT_NULL)
			strID = (LPCSTR)_bstr_t(var);
		nID = atoi(strID);
		if(nID>nMaxID)
			nMaxID = nID;
		m_pRecordset->MoveNext();
	}
	//m_AdoConn.ExitConnect();
	nMaxID+=1;
	strID.Format("%d",nMaxID);
	return strID;
}


/***************************************
 *	InsertPointCardFB
 *
 *	Parameters:	structFB	// 结构体
 *	
 *	Remark:	插入PointCardFB 表一条纪录
 ***************************************/

void CTel2006Dlg::InsertPointCardFB(structFB structFB)
{
	CString strSQL("");
	float fPrice = (float)atof(structFB.strPrice);
	CString strTypeName("");
	CString strTypeID("990605");

	if(structFB.strTypeID == "01")
	{
		strTypeID = "990601";strTypeName = "国际长途";
	}
	else if(structFB.strTypeID == "02")
	{
		strTypeID = "990602";strTypeName = "国内长途";
	}
	else if(structFB.strTypeID == "03")
	{
		strTypeID = "990603";strTypeName = "外地手机";
	}
	else if(structFB.strTypeID == "04")
	{
		strTypeID = "990604";strTypeName = "本地手机";
	}
	else if(structFB.strTypeID == "05")
	{
		strTypeID = "990605";strTypeName = "市话";
	}
	else if(structFB.strTypeID == "06")
	{
		strTypeID = "990606";strTypeName = "信息台";
	}
	else
	{
		strTypeID = "990605";strTypeName = "市话";
	}

	try
	{
	//ADOConn m_AdoConn;
	//m_AdoConn.OnInitADOConn(m_strDataBase);
	//strSQL.Format("INSERT INTO F_(PSerial) VALUES('%s')","123");
	strSQL.Format("INSERT INTO F_PointCardFB \
	(PSerial,		ParlorCode,		SourceParlor,	TableCode,	SourceCode,\
	 PointDate,		PointTime,		MenuID,			TypeCode,	TypeName,\
	 DishCode,		DishName,		DishName2,		StripCode,	Pquantity,\
	 Pprice,		Unit,			UnitSec,		SecQuantity,inputmark,\
	 largressmark,	printmark,		scode,			tjmark,		printremark,\
	 outmethod,		dishsize,		rsncode,		pClient,	pClientid,\
	 pcuserid,		pcuser,			pointpsn,		changeman,	spmark,\
	 tblwaiter,		printshow,		dishshow,		Cmoney,		secnumshow,\
	 checkpriv,		remitmark,		undomark,		groupmark,	groupno,\
	 groupcode,		groupprice,		groupnums,		Element01,	Element02,\
	 Element03,		Element04,		Element05,		Element06,	Element07,\
	 Element08,		Element09,		Element10,		Element11,	Element12,\
	 Element13,		Element14,		Element15,		decscore,	costm,\
	 remityzmrk,	sptellmrk,		spendtime,		bedno,		billcode,\
	 sbillcode,		pricetype,		sveprice,		nightcheck,	checkcode,\
	 checkoutcard,	partcode,		totalmoney,		partmark,	putout,\
	 parttype,		gfmark,			DishRemCode)\
	 VALUES(	'%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',\
	 '%s','%s','%s','%s','%d','%f','%s','%s','%d','%s',\
	 '%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',\
	 '%s','%s','%s','%s','%s','%s','%s','%s','%f','%s',\
	 '%d','%s','%s','%s','%s','%s','%d','%d','%d','%d',\
	 '%d','%d','%d','%d','%d','%d','%d','%d','%d','%d',\
	 '%d','%d','%d','%d','%d','%s','%s','%s','%s','%s',\
	 '%s','%s','%d','%s','%s','%s','%s','%d','%s','%s',\
	 '%s','%s','%s')",\
	 structFB.strPserial,	structFB.strParlorCode,	structFB.strParlorCode,	structFB.strTableCode,	structFB.strTableCode,	
	 structFB.strCurDate,	structFB.strCurTime,	structFB.strMenuID,		strTypeID,		strTypeName,	
	 "9905000004",	"话费",			"",				"",				1,
	 fPrice		,"次",			"",				0,				"0",
	 "0",			"0",			"",				"",				"",			
	 "0",			"0",			"00",			"",				"",		
	 "",			"",				"",				"",				"",			
	 "",			"·",			"←",			fPrice,			"",	
	 10,			"0",			"0",			"0",			"",
	 "",			0,				0,				0,				0,	
	  0,			0,				0,				0,				0,			
	  0,			0,				0,				0,				0,	
	  0,			0,				0,				0,				0,			
	 "",			"0",			"",				structFB.strBedNo,		structFB.strBillCode,
	 structFB.strBillCode,	"",				0,				"0",			"0000000000",
	 " ",			"100000",		0,				"0",			"0",			
	 "0",			structFB.strGfMark,			"HF");
	
	_bstr_t vSQL =strSQL;
	m_AdoConn.ExecuteSQL(vSQL);
	//m_AdoConn.ExitConnect();
	}
	catch (_com_error e) 
	{
		CString errormessage;
		
		errormessage.Format("自定义错误信息2:%s",e.ErrorMessage());
		
		AfxMessageBox(errormessage);///显示错误信息
	}
}


/********************************************
 *	GetPserial
 *	
 *	Return Values:	strPSerial	// PSerial串
 *
 *	Remark:	获得PSerial
 ********************************************/

CString CTel2006Dlg::GetPserial()
{
	CString strPSerial;
	CString strTmp;
	CString strZero("0");
	
	SYSTEMTIME st;
	GetLocalTime(&st);
	
	strTmp.Format(_T("%d"),st.wYear);
	if(strTmp.GetLength()>2)
		strTmp = strTmp.Right(2);
	strPSerial += strTmp;
	
	strTmp.Format(_T("%d"),st.wMonth);
	if(strTmp.GetLength()<2)
		strTmp = strZero + strTmp;
	strPSerial += strTmp;
	
	strTmp.Format(_T("%d"),st.wDay);
	if(strTmp.GetLength()<2)
		strTmp = strZero + strTmp;
	strPSerial += strTmp;
	
	strTmp.Format(_T("%d"),st.wHour);
	if(strTmp.GetLength()<2)
		strTmp = strZero+strTmp;
	strPSerial += strTmp;
	
	strTmp.Format(_T("%d"),st.wMinute);
	if(strTmp.GetLength()<2)
		strTmp = strZero + strTmp;
	strPSerial += strTmp;
	
	strTmp.Format(_T("%d"),st.wSecond);
	if(strTmp.GetLength()<2)
		strTmp = strZero + strTmp;
	strPSerial += strTmp;
	strPSerial +=GetRand();
	
	return strPSerial;
}


/*****************************************
 *	GetRand
 *	
 *	Return Values:	str	// 随机字符串
 *
 *	Remark:	获得随机字符串9位
 *****************************************/

CString CTel2006Dlg::GetRand()
{
	int i = rand();
	i = rand()%99999999;
	CString str;
	str = FormatString(i);
	return str;
}


/********************************************
 *	FormatString
 *
 *	Parameters:	nNum	// 待格式化字符串
 *
 *	Return Values:	str	// 格式化的字符串
 *	
 *	Remark:	格式化字符串 "12"->"0000012"
 ********************************************/

CString CTel2006Dlg::FormatString(int nNum)
{
	char sz[20];
	sprintf(sz,"%7d",nNum);
	CString str;

⌨️ 快捷键说明

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