📄 datafuncold.h
字号:
#if !defined(__HDATAFUNC_H__)
#define __HDATAFUNC_H__
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <fcntl.h>
#include <stdarg.h>
#include <afxmt.h>
#include <time.h>
//语音卡head
#include <srllib.h>
#include <dxxxlib.h>
#include <dtilib.h>
#include <sctools.h>
//自定义head
#include "hdefine.h"
#include "htypedef.h"
#include "Mydatabase.h"
#include "hfcjyykvar.h"
#include "myvc.h"
//void WinPrintf(char *szFormat, ...); //显示一个信息窗口
UINT Writedata(LPVOID pParam); //往主缓冲区写数据的线程
int Readrecord(MAIN_CJDATA *rddata); //读一条记录的函数
void GetTime(char* lstime); //取当前时间并转变成字符串
void CToSql(char* lstime); //转变时间字符串格式
UINT Maincontrol(LPVOID pParam); //催缴主线程
BOOL Cmpcjarg(CJ_ARG* lpcjarg); //判定是否到了催缴时间
int yin_seize(int i); //拨号
int chan_init(int i); //重置端口
UINT Cjwork(LPVOID pParam); //催缴工作线程函数
int Process(int channel,unsigned long evt_handle); //催缴工作线程中调用到的处理函数
int end_prog(); //关闭语音卡和语音文件
int yin_mfc(int channel); //MultiFrequencyControl Procedure
int yin_r2_playfsig(int channel, int forwardsig); //to play a forward signal
int playtone_init(void); //to initialize tonegen and r2_tpt
int yin_bwboff(int channel); //Backword hangup during MFC
int yin_getbksig(int channel,unsigned long evt_handle); //Get backward signal
int yin_fwaon(int channel); //Forward hangup after end of play
int yin_playf(int channel); //Set up IOTT and TPT's and Play-Back
int clr_output(int channel); //清除某通道屏显的函数
void time_process(void); //超时处理函数
int Readdata(int channel); //从缓冲区读一条数据
int Writeappdata(int channel); //往辅缓冲区写数据
int Index_sz(int channel); //索引语音数组
int Index_time(char *sz_time, DX_IOTT *iott_time,int filenum,int channum); //索引时间字串
int Index_value(char *sz_value,DX_IOTT *iott_value,int filenum,int channum); //索引金额字串
UINT DataConnect(LPVOID pParam); //校验数据库连接并自动处理的线程函数
UINT RecordData(LPVOID pParam); //写数据库日志记录
void Init_data(); //初始化数据库的函数
int get_bdname(int boardid); //To get boardname according board id
void Init_sys(); //初始化文件和语音卡的函数
int yin_r2_creatbsig(int channel); //to build backward signal detection
int Readwrite_data(int channel,MAIN_CJDATA *rddata,int rwflag); //操作数据库的函数(实现读写不同步)
int Write_data(int channel); //写数据库的函数
/************************************************************
* NAME: WinPrintf()
* DESCRIPTION: Popup error message box for cases where
* no child windows exist.
************************************************************/
/*void WinPrintf(char *szFormat, ...)
{
char szBuffer[256];
va_list pArguments;
HWND hWnd;
hWnd=AfxGetMainWnd()->m_hWnd;
va_start(pArguments,szFormat);
vsprintf(szBuffer, szFormat, pArguments);
MessageBox(hWnd, szBuffer, "信息窗口", MB_SYSTEMMODAL | MB_OK);
}*/
/************************************************************************
* 名称:UINT Writedata(LPVOID pParam)
* 功能:往主缓冲区写数据的线程
************************************************************************/
UINT Writedata(LPVOID pParam)
{
int rd_flag;
MAIN_CJDATA tmp_rddata;
char ls_time[TIME_LENGTH];
CString ls_month;
//CMydatabase* lpReaddata; //指向读数据库的指针
//CMutex* lpReadmutex; //指向读mutex类的指针
//CSemaphore* lpReadsemaphore; //指向读semaphore类的指针
//lpReaddata=&pDatabase;
//lpReadmutex=&(lpReaddata->m_myMutex);
//lpReadsemaphore=&(lpReaddata->m_mySemaphore);
//CSingleLock sLock(lpReadmutex); //同步锁类
//CSingleLock sLock(lpReadsemaphore); //同步锁类
//SysPrintf("读Mutex的地址为 %ld",lpReadmutex);
//SysPrintf("读semaphore的地址为 %ld",lpReadsemaphore);
CMutex* GlobalMutex;
//GlobalMutex=&pDatabase.m_myMutex;
GlobalMutex=&m_otherMutex;
while(1) {
if(stopdata==STOPTRUE){
//AfxMessageBox("Stop the writedata thread");
break;
}
/*if((cjdata_flag == CJDATA_NO)||(dba_connect == DBA_FALSE)) {
Sleep(60000);
continue;
}*/
//清空上次的内容
tmp_rddata.hth[0]='\0';
tmp_rddata.num[0]='\0';
tmp_rddata.cuijiao[0]='\0';
tmp_rddata.qfmonth[0]='\0';
tmp_rddata.cjcount=0;
tmp_rddata.cjmonth[0]='\0';
tmp_rddata.cjyin_flag=1;
if(maincounts < MAINDATA_COUNTS){
//读一条记录
CSingleLock* sLock = new CSingleLock(GlobalMutex);
sLock->Lock();
if((dba_connect == DBA_TRUE)&&(cjdata_flag == CJDATA_YES))
rd_flag=Readrecord(&tmp_rddata);
//rd_flag=Readwrite_data(0,&tmp_rddata,READDATA);
else
rd_flag=-1;
sLock->Unlock();
delete sLock;
//SysPrintf("主缓冲区读数据");
//取得当前催缴月份并判断是否超过当月最大催缴次数
GetTime(ls_time);
ls_time[7]='\0';
ls_month=&ls_time[5];
if(ls_month.Compare( tmp_rddata.cjmonth) != 0) {
tmp_rddata.cjcount=0;
sprintf(tmp_rddata.cjmonth,ls_month);
}
else
{
if((tmp_rddata.cjcount >= cjarg.max_count)&&(cjarg.maxcount_flag == 1))
rd_flag = -1;
}
//如果催缴音标志位为‘9’,不催
if(tmp_rddata.cjyin_flag==9){
rd_flag = -1;
}
if(rd_flag == 1) {
//清空上次的内容
maincjdata[writemain].hth[0]='\0';
maincjdata[writemain].num[0]='\0';
maincjdata[writemain].cuijiao[0]='\0';
maincjdata[writemain].qfmonth[0]='\0';
maincjdata[writemain].cjcount=0;
maincjdata[writemain].cjmonth[0]='\0';
maincjdata[writemain].cjyin_flag=1;
//赋新值
maincjdata[writemain]=tmp_rddata;
//计数器加一
maincounts++;
//if(maincounts>MAINDATA_COUNTS-1)
// maincounts=MAINDATA_COUNTS-1;
if(writemain>=MAINDATA_COUNTS-1)
writemain=0;
else
writemain++;
}
}
Sleep(100);
}
//退出时关闭数据库
//sLock.Lock();
//pCuijiaoSet.Close();
//pDatabase.Close();
//sLock.Unlock();
return(0);
}
/************************************************************************
* 名称:int Readrecord(MAIN_CJDATA *rddata)
* 功能:读一条记录的函数
************************************************************************/
int Readrecord(MAIN_CJDATA *rddata)
{
int qz_flag;
int dkh_flag;
int ht_flag;
int mc_flag;
CString szhth;
CString szqianfei;
CString szqfmonth;
CString szflag;
CString szcjcount;
CString szcjmonth;
CString sznum;
CString szcmphth;
CString szcjyinflag;
char tmp_querySQL[200];
char tmp_cjcount[10];
char tmp_cjyinflag[10];
CRecordsetStatus rStatus;
char errormsg[100];
SysPrintf("主缓冲区读数据");
if(pCuijiaoSet.IsEOF()){
//重新检索催缴表
try{
if(pCuijiaoSet.Requery() == 0){
pCuijiaoSet.Close();
cjdata_flag=CJDATA_NO;
return(0);
}
else{
if(pCuijiaoSet.GetRecordCount()==0){
pCuijiaoSet.Close();
cjdata_flag=CJDATA_NO;
return(0);
}
else{
cjdata_flag=CJDATA_YES;
}
}
}
catch(CDBException* e){
pCuijiaoSet.Close();
dba_connect=DBA_FALSE;
AfxMessageBox(e->m_strError, MB_ICONEXCLAMATION );
e->Delete();
return(-1);
}
catch(CMemoryException* e){
pCuijiaoSet.Close();
dba_connect=DBA_FALSE;
e->Delete();
return(-1);
}
}
try{
pCuijiaoSet.GetFieldValue( _T(hth) , szhth);
if(szhth.IsEmpty())
return(0);
pCuijiaoSet.GetFieldValue( _T(qianfei) , szqianfei);
if(szqianfei.IsEmpty())
return(0);
//pCuijiaoSet.GetFieldValue( _T(qfmonth) , szqfmonth);
//pCuijiaoSet.GetFieldValue( _T("qfmonth") , szqfmonth);
pCuijiaoSet.GetFieldValue( _T(flag) , szflag);
pCuijiaoSet.GetFieldValue( _T(cjcount) , szcjcount);
if(szcjcount.IsEmpty())
szcjcount="0";
pCuijiaoSet.GetFieldValue( _T(cjmonth) , szcjmonth);
pCuijiaoSet.GetFieldValue( _T(cjyinflag) , szcjyinflag);
if(szcjyinflag.IsEmpty())
szcjyinflag="1";
pCuijiaoSet.MoveNext();
}
catch(CDBException* e){
pCuijiaoSet.Close();
dba_connect=DBA_FALSE;
strcpy(errormsg, "数据库错误:");
strcat(errormsg, e->m_strError);
//AfxMessageBox(errormsg, MB_ICONEXCLAMATION );
e->Delete();
return(-1);
}
catch(CMemoryException* e){
pCuijiaoSet.Close();
dba_connect=DBA_FALSE;
e->Delete();
return(-1);
}
//取得催缴记录的当前指针
pCuijiaoSet.GetStatus(rStatus);
lcuijiaocurrent = rStatus.m_lCurrentRecord;
sprintf(tmp_querySQL,"select num from t_data_dakehu where hth=\'%s\'",szhth);
try{
if(pDakehuSet.Open( CRecordset::forwardOnly, _T(tmp_querySQL))==0){
pDakehuSet.Close();
dkh_flag=-1;
}
else{
if(pDakehuSet.GetRecordCount()==0){
pDakehuSet.Close();
dkh_flag=-1;
}
else{
dkh_flag=1;
}
}
}
catch(CDBException* e){
dba_connect=DBA_FALSE;
AfxMessageBox(e->m_strError, MB_ICONEXCLAMATION );
e->Delete();
return(-1);
}
catch(CMemoryException* e){
dba_connect=DBA_FALSE;
e->Delete();
return(-1);
}
if(dkh_flag == 1) {
while(!pDakehuSet.IsEOF())
{
try{
pDakehuSet.GetFieldValue(_T(num), sznum);
if(sznum.GetLength()>=TELE_LENGTH ) {
dkh_flag=1;
break;
}
pDakehuSet.MoveNext();
}
catch(CDBException* e){
pDakehuSet.Close();
AfxMessageBox(e->m_strError, MB_ICONEXCLAMATION );
dba_connect=DBA_FALSE;
e->Delete();
return(-1);
}
catch(CMemoryException* e){
pDakehuSet.Close();
dba_connect=DBA_FALSE;
e->Delete();
return(-1);
}
dkh_flag=-1;
}
pDakehuSet.Close();
}
if(dkh_flag == -1) {
sprintf(tmp_querySQL,"select tele from t_data_hetong where hetong=\'%s\'",szhth);
try{
if(pHetongSet.Open( CRecordset::forwardOnly, _T(tmp_querySQL))==0){
pHetongSet.Close();
ht_flag=-1;
}
else{
if(pHetongSet.GetRecordCount()==0){
pHetongSet.Close();
ht_flag=-1;
}
else{
ht_flag=1;
}
}
}
catch(CDBException* e){
dba_connect=DBA_FALSE;
AfxMessageBox(e->m_strError, MB_ICONEXCLAMATION );
e->Delete();
return(-1);
}
catch(CMemoryException* e){
dba_connect=DBA_FALSE;
e->Delete();
return(-1);
}
if(ht_flag == 1) {
while(!pHetongSet.IsEOF())
{
try{
pHetongSet.GetFieldValue(_T(tele), sznum);
if(sznum.GetLength()>=TELE_LENGTH ) {
ht_flag=1;
break;;
}
pHetongSet.MoveNext();
}
catch(CDBException* e){
pHetongSet.Close();
AfxMessageBox(e->m_strError, MB_ICONEXCLAMATION );
dba_connect=DBA_FALSE;
e->Delete();
return(-1);
}
catch(CMemoryException* e){
pHetongSet.Close();
dba_connect=DBA_FALSE;
e->Delete();
return(-1);
}
ht_flag=-1;
}
pHetongSet.Close();
}
}
if((dkh_flag == -1)&&(ht_flag == -1)){
return(-2); //-2表示没有取得号码
}
//szcmphth
sprintf(tmp_querySQL,"select hth from t_data_miancui where num=\'%s\'",sznum);
try{
if(pMiancuiSet.Open( CRecordset::forwardOnly, _T(tmp_querySQL))==0){
pMiancuiSet.Close();
mc_flag=-1;
}
else{
if(pMiancuiSet.GetRecordCount()==0){
pMiancuiSet.Close();
mc_flag=-1;
}
else{
mc_flag=1;
}
}
}
catch(CDBException* e){
dba_connect=DBA_FALSE;
AfxMessageBox(e->m_strError, MB_ICONEXCLAMATION );
e->Delete();
return(-1);
}
catch(CMemoryException* e){
dba_connect=DBA_FALSE;
e->Delete();
return(-1);
}
if(mc_flag == 1) {
while(!pMiancuiSet.IsEOF())
{
try{
pMiancuiSet.GetFieldValue(_T(hth), szcmphth);
//if(!szcmphth.IsEmpty()) {
mc_flag=1;
break;;
//}
pMiancuiSet.MoveNext();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -