📄 shppsessioninterface.cpp
字号:
return m_shppRequest.SendError(shppTryAgain);
}
return KN_OK;
}
//需要发送打印时间
KN_Error CSHPPSessionInterface::SentPrintDate()
{
// char* printDate[FIELDBUFFER];
// m_shppRequest.PutParameter(printDate);
return KN_OK;
}
//打印表头
void CSHPPSessionInterface::PrintListHead(char *pTime)
{
char printTel[FIELDBUFFER];
m_shppRequest.PrintLine(m_chBusinessTitle,1);
/* if(pName)
{
sprintf(printTel,"客户姓名:%16s",pName);
m_shppRequest.PutParameter(printTel);
}
*/ sprintf(printTel,"号码:%11s, 打印月份:%6s",m_chPhone,pTime);
m_shppRequest.PutParameter(printTel);
m_shppRequest.PutParameter(s_chSeparator);
printf("IP =%s,%s\n",m_chClientIP,printTel);
}
//打印表尾
void CSHPPSessionInterface::PrintListTail()
{
char chtime[FIELDBUFFER];
char chParam[FIELDBUFFER*2];
//打印地点
sprintf(chParam,"打印地点:%s",m_chBusinessAddr);
m_shppRequest.PutParameter(chParam);
//打印时间
OS::GetSysDateTime(chtime);
sprintf(chParam,"打印时间:%s",chtime);
m_shppRequest.PutParameter(chParam);
//打印说明
m_shppRequest.PutParameter(s_chSeparator);
m_shppRequest.PutParameter(m_sysParamStruct.chPrintTail);
}
//分析包
void CSHPPSessionInterface::PrintFilde(char* pHead)
{
char *pCurr = pHead;
if(pHead == NULL)
return ;
while(*pCurr)
{
if((*pCurr) == '\t')
{
m_shppRequest.AddFieldVal(pHead,pCurr - pHead);
pHead = pCurr + 1;
}
else if((*pCurr) == '\r')
{
m_shppRequest.AddFieldVal(pHead,pCurr - pHead);
pHead = pCurr + 2;
}
pCurr++;
}
}
//
KN_Error CSHPPSessionInterface::GetPrintTime(char* pPrintTime,int nBeginDay,
int nEndDay,int nBack ,char bReal,char nPrintMonth)
{
time_t timer;
struct tm* pTime;
int nYear,nMonth,nDay,nLen;
time( &timer );
pTime = localtime( &timer );
nYear = pTime->tm_year + 1900;
nMonth = pTime->tm_mon + 1;
nDay = pTime->tm_mday ;
if(bReal != 0)
{
nLen = sprintf(pPrintTime,"按1键:打印%d/%02d/%02d---%02d/%02d/%02d话费详单\r\n\r\n",
nYear,nMonth,nBeginDay,nYear,nMonth,pTime->tm_mday);
sprintf(m_sysParamStruct.chPrintMonth[0],"%02d%02d",nYear,nMonth);
pPrintTime += nLen;
nBack = 0;
bReal = 2;
}
else
{
bReal = 1;
}
//取第一个月
nMonth--;
if(nDay <= nBack)
{
nMonth--;
}
if(nMonth < 1)
{
nYear--;
nMonth += 12;
}
//自然月查询
if(nEndDay == 31)
{
//按1键时间
nEndDay = GetEndDay(nYear,nMonth);
nLen = sprintf(pPrintTime,"按%d键:打印%d/%02d/%02d---%02d/%02d/%02d话费详单\r\n\r\n",
(int)bReal,nYear,nMonth,nBeginDay,nYear,nMonth,nEndDay);
pPrintTime += nLen;
sprintf(m_sysParamStruct.chPrintMonth[bReal-1],"%02d%02d",nYear,nMonth);
//按2,3键时间
for(nBack = 0;nBack < (nPrintMonth - 1);nBack++)
{
bReal++;
nMonth--;
if(nMonth < 1)
{
nYear--;
nMonth += 12;
}
nEndDay = GetEndDay(nYear,nMonth);
nLen = sprintf(pPrintTime,"按%d键:打印%02d/%02d/%02d---%02d/%02d/%02d话费详单\r\n\r\n",
bReal,nYear,nMonth,nBeginDay,nYear,nMonth,nEndDay);
pPrintTime += nLen;
sprintf(m_sysParamStruct.chPrintMonth[bReal-1],"%02d%02d",nYear,nMonth);
}
return 0;
}
else //按时间段如20---21
{
//按1,2,3键时间
for(int i = 0;i<nPrintMonth;i++)
{
nBack = nMonth - 1;
if(nBack < 1)
{
nBack += 12;
nLen = sprintf(pPrintTime,"按%d键:打印%d/%02d/%02d---%02d/%02d/%02d话费详单\r\n\r\n",
bReal,nYear-1,nBack,nBeginDay,nYear,nMonth,nEndDay);
sprintf(m_sysParamStruct.chPrintMonth[bReal-1],"%02d%02d",nYear,nMonth);
nYear--;
}
else
{
nLen = sprintf(pPrintTime,"按%d键:打印%d/%02d/%02d---%02d/%02d/%02d话费详单\r\n\r\n",
bReal,nYear,nBack,nBeginDay,nYear,nMonth,nEndDay);
sprintf(m_sysParamStruct.chPrintMonth[bReal-1],"%02d%02d",nYear,nMonth);
}
bReal++;
nMonth = nBack;
pPrintTime += nLen;
}
}
return 0;
}
KN_Error CSHPPSessionInterface::GetEndDay(int nYear,int nMonth)
{
if(nMonth == 2)
{
if(nYear == (nYear/4)*4)
return 29;
else
return 28;
}
else if(nMonth == 4 || nMonth == 6
|| nMonth == 9 || nMonth == 11)
return 30;
else
return 31;
return 30;
}
void CSHPPSessionInterface::InitSysParam(CDBAdmin *pDBAmin)
{
char chTpye[3][10],chDesc[50];
int nTypeCount = 0;
//调用数据库服务,获取:话单类型个数、是否打印预览、是否自定义查询
pDBAmin->DBGetSystemPara(m_chArea,"000300",chTpye[0],chDesc);
pDBAmin->DBGetSystemPara(m_chArea,"000500",chTpye[1],chDesc);
pDBAmin->DBGetSystemPara(m_chArea,"000400",chTpye[2],chDesc);
pDBAmin->DBGetSystemPara(m_chArea,"050100",m_sysParamStruct.chPrintTail,chDesc);
if(chTpye[0][0] != '0')
{
//取话单类型
char chType[512],*pHead,*pCurr,*pgTelType;
pDBAmin->DBGetCallType(m_chArea,chType,&nTypeCount);
pHead = chType;
pgTelType = m_sysParamStruct.chTelType;
for(int i = 0; i< nTypeCount;i++)
{
pCurr = strchr(pHead,'\t');
if(pCurr == NULL)
{
nTypeCount = 0;
break;
}
pCurr++;
memcpy(pgTelType,pHead,pCurr - pHead);
pgTelType += (pCurr - pHead);
pHead = pCurr;
pCurr = strchr(pHead,'\r');
if(pCurr == NULL)
{
nTypeCount = 0;
break;
}
*pCurr = '\0';
strcpy(m_sysParamStruct.chTelCode[i],pHead);
pHead = pCurr+2;
}
*(pgTelType - 1) = 0;
printf(m_sysParamStruct.chTelType);
}
else
{
strcpy(m_sysParamStruct.chTelCode[0],"000");
nTypeCount = 0;
}
if(chTpye[1][0] != '0' && chTpye[1][0] != '1')
chTpye[1][0] = '0';
if(chTpye[2][0] != '0' && chTpye[2][0] != '1')
chTpye[2][0] = '0';
//debug
// m_sysParamStruct.nIsView = 1;
m_sysParamStruct.nIsView = chTpye[1][0] - '0';
m_sysParamStruct.nIsSelfQuery = chTpye[2][0] - '0';
m_sysParamStruct.nTelType = nTypeCount;
pDBAmin->DBGetSystemPara(m_chArea,"010105",chTpye[0],chDesc); //延期天数
pDBAmin->DBGetSystemPara(m_chArea,"010106",chTpye[1],chDesc); //出帐开始时间
pDBAmin->DBGetSystemPara(m_chArea,"010107",chTpye[2],chDesc); //出帐结束时间?
m_sysParamStruct.nBackDay = atoi(chTpye[0]);
m_sysParamStruct.nBeginDay = atoi(chTpye[1]);
m_sysParamStruct.nEndDay = atoi(chTpye[2]);
if(m_sysParamStruct.nBeginDay == 0)
m_sysParamStruct.nBeginDay = 1;
if(m_sysParamStruct.nEndDay == 0)
m_sysParamStruct.nEndDay = 31;
// m_sysParamStruct.PrintDefPwd = 1;
// m_sysParamStruct.PrintIsFeeIs = 1;
pDBAmin->DBGetSystemPara(m_chArea,"010301",chTpye[0],chDesc); //默认密码是否充许打印
pDBAmin->DBGetSystemPara(m_chArea,"010302",chTpye[1],chDesc); //欠费是否可打:1为可打印
m_sysParamStruct.PrintDefPwd = chTpye[0][0]; //默认密码是否充许打印:1为充许
m_sysParamStruct.PrintIsFeeIs = chTpye[1][0]; //欠费是否可打:1为可打印
//实时话单是否能打印:1为可打印
pDBAmin->DBGetSystemPara(m_chArea,"010303",chTpye[0],chDesc); //实时话单是否能打印:1为可打印
if(chTpye[0][0] == '1')
m_sysParamStruct.bRealTimeQuery = 1;
else
m_sysParamStruct.bRealTimeQuery = 0;
// m_sysParamStruct.bRealTimeQuery = 1;
//H2信息
pDBAmin->DBGetSystemPara(m_chArea,"010201",chTpye[1],chDesc); //端口号
pDBAmin->DBGetSystemPara(m_chArea,"010202",m_sysParamStruct.chH2IP,chDesc); //服务器的IP
m_sysParamStruct.nH2Post = atoi(chTpye[1]);
if(nTypeCount == 0)
m_sysParamStruct.chTelType[0] = '\0';
// GetPrintTime(m_sysParamStruct.chPrintTime,m_sysParamStruct.nBeginDay ,
// m_sysParamStruct.nEndDay ,m_sysParamStruct.nBackDay ,
// m_sysParamStruct.bRealTimeQuery);
pDBAmin->DBGetSystemPara(m_chArea,"010109",chTpye[0],NULL); //可打印月份数
m_sysParamStruct.nMonthSize = atoi(chTpye[0]);
if(m_sysParamStruct.nMonthSize == 0)
m_sysParamStruct.nMonthSize = 3;
if(m_sysParamStruct.bRealTimeQuery)
{
m_sysParamStruct.nMonthSize = m_sysParamStruct.nMonthSize+1;
}
printf("打印月个数 %d\n",m_sysParamStruct.nMonthSize);
}
int CSHPPSessionInterface::SendMsg(char *strMsg)
{
sockaddr_in saClient;
CKNSocket knSTQSocket;
try
{
knSTQSocket.Create(SOCK_DGRAM);
memset((void*)&saClient,0,sizeof(sockaddr_in));
saClient.sin_family = AF_INET;
saClient.sin_port = htons(10514);
saClient.sin_addr.s_addr = inet_addr("10.110.0.69");
int nIndex=0;
nIndex=knSTQSocket.Connect((LPCSOCKADDR)&saClient);
if(nIndex != 0)
{
printf("连接接口失败!");
knSTQSocket.Cleanup();
return -1;
}
else
{
nIndex=0;
for(int i=0;i<3;i++)
{
nIndex=knSTQSocket.Send(strMsg,strlen(strMsg),0);
if(nIndex!=0)
break;
}
}
}
catch(...)
{
knSTQSocket.Cleanup();
return -2;
}
knSTQSocket.Cleanup();
return 0;
}
/***************class CSHPPSessionTemp*****************/
CSHPPSessionTemp::CSHPPSessionTemp(CKNSocket* pSocket,CDBAdmin *pDBAmin)
{
m_bInLine[0] = '0';
m_bInLine[1] = '\0';
m_knError = shppSystemErr;
m_knSocket.m_hSocket = pSocket->m_hSocket;
m_splLine.Set(m_bInLine);
}
CSHPPSessionTemp::~CSHPPSessionTemp()
{
m_knSocket.Cleanup();
}
void CSHPPSessionTemp:: SetSocket(CKNSocket* pSocket)
{
m_knSocket.Cleanup();
m_knSocket.m_hSocket = pSocket->m_hSocket;
}
SInt64 CSHPPSessionTemp::Run()
{
m_bInLine[0] = '1';
CSHPPRequest theRequest(&m_knSocket);
try{
theRequest.Parse();
theRequest.SendError(m_knError);
}
catch(...)
{
}
m_knSocket.Cleanup();
m_bInLine[0] = '0';
return KN_OK;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -