📄 datafunc.c
字号:
int Index_time(char *sz_time, DX_IOTT *iott_time,int filenum,int channum)
{
int count;
int count_a;
for(count=0;count<4;count++) {
iott_time[count].io_offset = fastnumfilewz[sz_time[count]-48].offset;
iott_time[count].io_length = fastnumfilewz[sz_time[count]-48].length;
}
iott_time[count].io_offset = YEARF_OFFSET;
iott_time[count].io_length = YEARF_LENGTH;
count++;
if(sz_time[4]==48) {
iott_time[count].io_offset = fastnumfilewz[sz_time[5]-48].offset;
iott_time[count].io_length = fastnumfilewz[sz_time[5]-48].length;
}
else
{
iott_time[count].io_offset = TENF_OFFSET;
iott_time[count].io_length = TENF_LENGTH;
count++;
iott_time[count].io_offset = fastnumfilewz[sz_time[5]-48].offset;
iott_time[count].io_length = fastnumfilewz[sz_time[5]-48].length;
}
count++;
iott_time[count].io_offset = MONTHF_OFFSET;
iott_time[count].io_length = MONTHF_LENGTH;
count++;
if(sz_time[6]==48) {
iott_time[count].io_offset = fastnumfilewz[sz_time[7]-48].offset;
iott_time[count].io_length = fastnumfilewz[sz_time[7]-48].length;
}
else if(sz_time[6]==49) {
iott_time[count].io_offset = TENF_OFFSET;
iott_time[count].io_length = TENF_LENGTH;
count++;
iott_time[count].io_offset = fastnumfilewz[sz_time[7]-48].offset;
iott_time[count].io_length = fastnumfilewz[sz_time[7]-48].length;
}
else
{
iott_time[count].io_offset = fastnumfilewz[sz_time[6]-48].offset;
iott_time[count].io_length = fastnumfilewz[sz_time[6]-48].length;
count++;
iott_time[count].io_offset = TENF_OFFSET;
iott_time[count].io_length = TENF_LENGTH;
count++;
iott_time[count].io_offset = fastnumfilewz[sz_time[7]-48].offset;
iott_time[count].io_length = fastnumfilewz[sz_time[7]-48].length;
}
count++;
iott_time[count].io_offset = DAYF_OFFSET;
iott_time[count].io_length = DAYF_LENGTH;
for(count_a=0;count_a<count;count_a++) {
iott_time[count_a].io_type = IO_DEV|IO_LINK;
iott_time[count_a].io_nextp = &iott_time[count_a+1];
iott_time[count_a].io_fhandle=szfile[filenum].filehandle;
iott_time[count_a].io_bufp = 0;
}
iott_time[count].io_type = IO_DEV|IO_EOT;
iott_time[count].io_nextp = NULL;
iott_time[count].io_fhandle=szfile[filenum].filehandle;
iott_time[count].io_bufp = 0;
count++;
return(count);
}
/**************************************************************************************
* Index_value(char *sz_value,DX_IOTT *iott_value,int filenum,int channum)
* 函数说明: 索引金额字串,并将索引后的语音内容填入 *iott_value,返回语音串的长度
* 参数: DX_IOTT *iott_value 索引数组的指针
* int filenum 传递时间语音文件在数组中的位置
* int channum 指定操作的通道
* 金额 *sz_value
**************************************************************************************/
int Index_value(char *sz_value,DX_IOTT *iott_value,int filenum,int channum)
{
int count_tmp;
int length_tmp;
int count_position; //金额字串索引到的当前位置
int count; //语音串的计数器
int count_a;
int account; //暂存金额字串中各位的值
int tmp_allzero; //后面的值全为零的标志
int ling_flag; //是否播'零'语音的标志
int zero_yuan; //元部分为0的标志
int zero_jiao; //角为0的标志
int length; //金额字串的长度
int point; //小数点在字串中所在的位置
int length_integer; //整数部分的长度
int length_decimal; //小数点后的长度
length=0;
while(sz_value[length]!=0)
length++;
for(point=1;point<=length;point++) {
if(sz_value[point-1]==46)
break;
}
if(point<=length) {
length_integer=point-1;
length_decimal=length-point;
if(length_decimal>2) {
length_decimal=2;
length=point+2;
}
}
else
{
length_integer=length;
length_decimal=0;
}
count_position=0;
count=0;
ling_flag=1;
while((count_position<length_integer)&&(count<=JE_LENGTH)) {
account=sz_value[count_position];
if(((account == 49)&&(count_position == 0)&&(length_integer%4 == 2))||
(( account == 48)&&( ling_flag == 1))){
iott_value[count].io_offset = 0;
iott_value[count].io_length = 0;
}
else
{
iott_value[count].io_offset = numberfilewz[account-48].offset;
iott_value[count].io_length = numberfilewz[account-48].length;
if( account== 48)
ling_flag=1;
else
ling_flag=0;
}
length_tmp=(length_integer-count_position-1)%4+1;
count_tmp=1;
while(count_tmp<length_tmp) {
if((sz_value[count_position+count_tmp]>48)&&(sz_value[count_position+count_tmp]<=57)) {
tmp_allzero=0;
break;
}
count_tmp++;
tmp_allzero=1;
}
if((tmp_allzero==1)&&(length_tmp>1)) {
ling_flag=1;
}
if(length_tmp == 1) {
for(count_tmp=count_position+1;count_tmp<length_integer;count_tmp++) {
if(( sz_value[count_tmp]>48)&&(sz_value[count_tmp]<=57)) {
tmp_allzero=0;
break;
}
tmp_allzero=1;
}
if(tmp_allzero==1) {
ling_flag=1;
}
else
{
ling_flag=0;
}
}
count++;
switch ((length_integer-count_position)%4) {
case 0:
if((account<=48)||(account>57)){
iott_value[count].io_offset = 0;
iott_value[count].io_length = 0;
}
else
{
iott_value[count].io_offset = THOUSAND_OFFSET;
iott_value[count].io_length = THOUSAND_LENGTH;
}
break;
case 3:
if((account<=48)||(account>57)){
iott_value[count].io_offset = 0;
iott_value[count].io_length = 0;
}
else
{
iott_value[count].io_offset = HUNDRED_OFFSET;
iott_value[count].io_length = HUNDRED_LENGTH;
}
break;
case 2:
if((account<=48)||(account>57)){
iott_value[count].io_offset = 0;
iott_value[count].io_length = 0;
}
else
{
iott_value[count].io_offset = TEN_OFFSET;
iott_value[count].io_length = TEN_LENGTH;
}
break;
case 1:
if((length_integer-count_position) > 8) {
iott_value[count].io_offset = YI_OFFSET;
iott_value[count].io_length = YI_LENGTH;
}
else if((length_integer-count_position) > 4) {
iott_value[count].io_offset = MYRIAD_OFFSET;
iott_value[count].io_length = MYRIAD_LENGTH;
}
else
{
if(( length_integer == 1)&&( account == 48)) {
zero_yuan = 1;
iott_value[count].io_offset = 0;
iott_value[count].io_length = 0;
}
else
{
zero_yuan=0;
iott_value[count].io_offset = YUAN_OFFSET;
iott_value[count].io_length = YUAN_LENGTH;
}
}
break;
}
count++;
count_position++;
}
count_position=point;
ling_flag=1;
while ((count_position<length)&&(count<=JE_LENGTH)) {
account=sz_value[count_position];
if((account==48)&&(count_position+1<length)) {
if((sz_value[count_position+1]>48)&&(sz_value[count_position+1]<=57)&&(zero_yuan==0)) {
ling_flag=0;
}
else
ling_flag=1;
}
if((account==48)&&(ling_flag==1)) {
iott_value[count].io_offset = 0;
iott_value[count].io_length = 0;
}
else
{
iott_value[count].io_offset = numberfilewz[account-48].offset;
iott_value[count].io_length = numberfilewz[account-48].length;
ling_flag=1;
}
count++;
switch (length-count_position) {
case 2:
if((account<=48)||(account>57)){
iott_value[count].io_offset = 0;
iott_value[count].io_length = 0;
zero_jiao = 1;
}
else
{
zero_jiao = 0;
iott_value[count].io_offset = JIAO_OFFSET;
iott_value[count].io_length = JIAO_LENGTH;
}
break;
case 1:
if((account<=48)||(account>57)){
if((zero_yuan==1)&&(zero_jiao==1)) {
iott_value[count].io_offset = numberfilewz[0].offset ;
iott_value[count].io_length = numberfilewz[0].length ;
}
else
{
iott_value[count].io_offset = 0;
iott_value[count].io_length = 0;
}
}
else
{
iott_value[count].io_offset = FEN_OFFSET;
iott_value[count].io_length = FEN_LENGTH;
}
break;
}
count++;
count_position++;
}
for(count_tmp=0;count_tmp<count;count_tmp++){
iott_value[count_tmp].io_type = IO_DEV|IO_LINK;
iott_value[count_tmp].io_nextp = &iott_value[count_tmp+1];
iott_value[count_tmp].io_fhandle=szfile[filenum].filehandle;
iott_value[count_tmp].io_bufp = 0;
}
iott_value[count-1].io_type = IO_DEV|IO_EOT;
iott_value[count-1].io_nextp = NULL;
return(count);
}
/***************************************************************
* 名称:UINT DataConnect(LPVOID pParam)
* 功能:校验数据库连接并自动处理的线程函数
***************************************************************/
UINT DataConnect(LPVOID pParam)
{
int channum;
TCB * tcb;
CDatabase ls_database;
while(1){
::WaitForSingleObject(JiaoYan.m_hObject, INFINITE);
tcb=(TCB *)pParam;
channum=tcb->chdevno;
if(stopdata==STOPTRUE){
//AfxMessageBox("Stop the data thread");
break;
}
if((dba_connect==DBA_TRUE)&&(cjdata_flag==CJDATA_YES)){
continue;
}
if(dba_connect==DBA_FALSE) {
try{
if(ls_database.Open( _T( "XTCJ170" ), FALSE, FALSE, _T( "ODBC;UID=xt170;PWD=VCplus170" ))==FALSE){
TRACE("连接数据库失败");
dba_connect=DBA_FALSE;
continue;
}
}
catch(CDBException* pEx)
{
TRACE("连接数据库失败");
dba_connect=DBA_FALSE;
pEx->Delete();
continue;
}
catch(CMemoryException* pEx)
{
TRACE("连接数据库失败");
dba_connect=DBA_FALSE;
pEx->Delete();
continue;
}
ls_database.Close();
if(pDatabase.IsOpen())
pDatabase.Close();
cjdata_flag=CJDATA_NO;
sLock.Lock();
try{
if(pDatabase.Open( _T( "XTCJ170" ), FALSE, FALSE, _T( "ODBC;UID=xt170;PWD=VCplus170" ))==FALSE){
TRACE("连接数据库失败");
dba_connect=DBA_FALSE;
//continue;
}
else{
dba_connect=DBA_TRUE;
}
}
catch(CDBException* pEx)
{
TRACE("连接数据库失败");
dba_connect=DBA_FALSE;
pEx->Delete();
//continue;
}
catch(CMemoryException* pEx)
{
TRACE("连接数据库失败");
dba_connect=DBA_FALSE;
pEx->Delete();
//continue;
}
sLock.Unlock();
//pCuijiaoSet.Close();
}
if((cjdata_flag==CJDATA_NO)&&(dba_connect==DBA_TRUE)){
sLock.Lock();
if(pCuijiaoSet.IsOpen())
pCuijiaoSet.Close();
try{
if(pCuijiaoSet.Open( CRecordset::dynaset , _T(cuijiaoSQL))==0){
pCuijiaoSet.Close();
cjdata_flag=CJDATA_NO;
//continue;
}
else{
pCuijiaoSet.Move(lcuijiaocurrent);
cjdata_flag=CJDATA_YES;
}
}
catch(CDBException* e){
dba_connect=DBA_FALSE;
cjdata_flag=CJDATA_NO;
e->Delete();
//continue;
}
catch(CMemoryException* e){
dba_connect=DBA_FALSE;
cjdata_flag=CJDATA_NO;
e->Delete();
//continue;
}
sLock.Unlock();
}
}
return (0);
}
/***************************************************************
* 名称:UINT UpdateData(LPVOID pParam)
* 功能:写数据库日志记录
***************************************************************/
UINT UpdateData(LPVOID pParam)
{
int channel;
TCB * tcb;
char InsertSQL[INSERTSQL_LENGTH];
char UpdateSQL[UPDATESQL_LENGTH];
while(1){
::WaitForSingleObject(pUpdateData.m_hObject, INFINITE);
tcb=(TCB *)pParam;
channel=tcb->chdevno;
if(stopdata==STOPTRUE){
//AfxMessageBox("Stop the data thread");
break;
}
if(dba_connect==DBA_TRUE) {
sLock.Lock();
try{
sprintf(InsertSQL, "insert into t_data_cjlog(hth,num,cj_money,cj_starttime,cj_endtime) values(\'%s\',\'%s\',\'%s\',TO_DATE(\'%s\', \'YYYY/MM/DD HH24:MI:SS\'),TO_DATE(\'%s\',\'YYYY/MM/DD HH24:MI:SS\'))",
teleinfo[channel].hth,teleinfo[channel].num,teleinfo[channel].cuijiao,teleinfo[channel].qssj_time,teleinfo[channel].zzsj_time);
sprintf(UpdateSQL, "update t_data_cuijiao set cjcount=%d, cjmonth=\'%s\' where hth=\'%s\'",
teleinfo[channel].cjcount,teleinfo[channel].cjmonth,teleinfo[channel].hth);
if(pDatabase.BeginTrans()){
pDatabase.ExecuteSQL(_T(InsertSQL));
pDatabase.ExecuteSQL(_T(UpdateSQL));
if(pDatabase.CommitTrans()) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -