📄 ecx.cpp
字号:
/* EasyCICS v2.11 */
/******************************************************************************/
/*------------------------------- HEADER FILES -------------------------------*/
#include "ecx.h"
/******************************************************************************/
/*--------------------------------- DEFINES ----------------------------------*/
/*******************************************************************************/
/*Functions*/
/*******************************************************************************/
CEcx::CEcx(){
Trans[0]=Server[0]= UserID[0]= PassWd[0]= PrgName[0]= '\0';
EciLuwToken=ECI_LUW_NEW;
EciCallSyncType=ECI_SYNC;
ForPbUse=0;
pComm[0] = pRow[0] = pRtnBuf[0] = SysId1[0] = '\0';
RsRowNum=RsRowNum0=0;
RsColNum=0;
RsRow=1;
LongNum=0;
RsBlkCli=0;
BlockNum=0;
BlockSize=0;
EciTimeOut=0;
eci_version=ECI_VERSION_1;
}
/*******************************************************************************/
/***Encode-Decode***/
/*
*/
char CEcx::GetHexChr( char *p ){
int a, b;
a=b=0;
if( p[0] >= '0' && p[0] <= '9' )
a= p[0] - '0';
else if( p[0] >= 'A' && p[0] <= 'F' )
a= p[0] - 'A' +10;
if( p[1] >= '0' && p[1] <= '9' )
b= p[1] - '0';
else if( p[0] >= 'A' && p[1] <= 'F' )
b= p[1] - 'A' +10;
return (a*16 + b);
}
/*
*! change pRtnBuf
*/
char * CEcx::PbEncode(char *OrgStr){
unsigned char *p, cc[4];
*pRtnBuf =0;
for( p= (unsigned char *)OrgStr; *p; p++ ){
cc[0] = *p;
cc[1] = 0;
if( *p == '%' ){
strcpy( (char *)cc, "%25" );
}
else if( *p >= 128 ){
sprintf( (char *)cc, "%%%X", *p );
}
strcat( pRtnBuf, (char *)cc );
}
return pRtnBuf;
}
/*
*! change pRtnBuf
*/
char * CEcx::PbDecode(char *CodStr){
char *p, cc[4];
*pRtnBuf =0;
cc[1] = 0;
for( p=CodStr; *p; p++ ){
*cc = *p;
if( '%' == *p ){
/*-*/
if( !strncmp( "%25", p, 3 ) ){
*cc='%';
p= p+2;
}
else if( ( p[1] >= '8' && p[1] <= '9' ) || ( p[1] >= 'A' && p[1] <= 'F' ) ){
*cc= GetHexChr(p+1);
p= p+2;
}
/*-*/
}
strcat( pRtnBuf, cc );
}
return pRtnBuf;
}
/*
*/
void CEcx::Encode(char *OrgStr, char *CodStr, int len){
char *p, cc[4];
*CodStr =0;
for( p=OrgStr; (p-OrgStr)<len; p++ ){
cc[0] = *p;
cc[1] = 0;
switch(*p){
case '%':
strcpy( cc, "%25" );
break;
case '=':
strcpy( cc, "%3D" );
break;
case '&':
strcpy( cc, "%26" );
break;
}
strcat( CodStr, cc );
}
}
/*
*/
void CEcx::EncodeStr(char *OrgStr, char *CodStr){
Encode( OrgStr, CodStr, strlen(OrgStr) );
}
/*
*/
void CEcx::Decode(char *CodStr, char *OrgStr, int len){
char *p, cc[4];
*OrgStr =0;
cc[1] = 0;
for( p=CodStr; (p-CodStr)<len; p++ ){
*cc = *p;
if( '%' == *p ){
/*-*/
if( !strncmp( "%25", p, 3 ) ){
*cc = '%';
p= p+2;
}
else if( !strncmp( "%3D", p, 3 ) ){
*cc = '=';
p= p+2;
}
else if( !strncmp( "%26", p, 3 ) ){
*cc = '&';
p= p+2;
}
/*-*/
}
strcat( OrgStr, cc );
}
}
/*
*/
void CEcx::DecodeStr(char *CodStr, char *OrgStr){
Decode( CodStr, OrgStr, strlen(CodStr) );
}
/*
*/
void CEcx::Encode_(char *OrgStr, char *CodStr, int len){
char *p, cc[4];
*CodStr =0;
for( p=OrgStr; (p-OrgStr)<len; p++ ){
cc[0] = *p;
cc[1] = 0;
switch(*p){
case '%':
strcpy( cc, "%25" );
break;
case ',':
strcpy( cc, "%2C" );
break;
}
strcat( CodStr, cc );
}
}
/*
*/
void CEcx::EncodeStr_(char *OrgStr, char *CodStr){
Encode_( OrgStr, CodStr, strlen(OrgStr) );
}
/*
*/
void CEcx::Decode_(char *CodStr, char *OrgStr, int len){
char *p, cc[4];
*OrgStr =0;
cc[1] = 0;
for( p=CodStr; (p-CodStr)<len; p++ ){
*cc = *p;
if( '%' == *p ){
/*-*/
if( !strncmp( "%25", p, 3 ) ){
*cc='%';
p= p+2;
}
else if( !strncmp( "%2C", p, 3 ) ){
*cc=',';
p= p+2;
}
/*-*/
}
strcat( OrgStr, cc );
}
}
/*
*/
void CEcx::DecodeStr_(char *CodStr, char *OrgStr){
Decode_( CodStr, OrgStr, strlen(CodStr) );
}
/*******************************************************************************/
/***Key & Value***/
/*
*/
void CEcx::DelKey(char *KeyName){
char cod_key[200] ="&", *p1, *p2, cod_key0[200];
EncodeStr(KeyName, cod_key0);
strcat( cod_key0, "=" );
strcpy( cod_key+1, cod_key0 );
p1= strstr(pComm, cod_key);
if(p1){
p2= strchr( p1+ strlen(cod_key), '&' );
if(p2)
strcpy( p1, p2 );
else
*p1= 0;
}
else if( !memcmp( pComm, cod_key0, strlen(cod_key0) ) ){
p1=pComm;
p2= strchr( p1+ strlen(cod_key0), '&' );
if(p2)
strcpy( p1, p2+1 );
else
*p1= 0;
}
}
/*
*/
void CEcx::DelKeyX(char *KeyName, char *pBuf){
char cod_key[200] ="&", *p1, *p2, cod_key0[200];
EncodeStr(KeyName, cod_key0);
strcat( cod_key0, "=" );
strcpy( cod_key+1, cod_key0 );
p1= strstr(pBuf, cod_key);
if(p1){
p2= strchr( p1+ strlen(cod_key), '&' );
if(p2)
strcpy( p1, p2 );
else
*p1= 0;
}
else if( !memcmp( pBuf, cod_key0, strlen(cod_key0) ) ){
p1=pBuf;
p2= strchr( p1+ strlen(cod_key0), '&' );
if(p2)
strcpy( p1, p2+1 );
else
*p1= 0;
}
}
/*
*/
void CEcx::GetValue0( char *KeyName, char *Vlu ){
char cod_key[200] ="&", *p1, *p2, cod_key0[200];
if( !KeyName || !*KeyName ){
strcpy(Vlu, pComm);
return;
}
*Vlu= 0;
EncodeStr(KeyName, cod_key0);
strcat( cod_key0, "=" );
strcpy( cod_key+1, cod_key0 );
p1= strstr(pComm, cod_key);
if(p1){
p1= p1 + strlen(cod_key);
p2= strchr(p1, '&');
if(p2)
Decode( p1, Vlu, p2-p1 );
else
DecodeStr(p1, Vlu);
}
else if( !memcmp( pComm, cod_key0, strlen(cod_key0) ) ){
p1= pComm+ strlen(cod_key0);
p2= strchr(p1, '&');
if(p2)
Decode( p1, Vlu, p2-p1 );
else
DecodeStr(p1, Vlu);
}
}
/*
*/
void CEcx::GetValueX( char *KeyName, char *Vlu, char *pBuf ){
char cod_key[200] ="&", *p1, *p2, cod_key0[200];
if( !KeyName || !*KeyName ){
strcpy(Vlu, pBuf);
return;
}
*Vlu= 0;
EncodeStr(KeyName, cod_key0);
strcat( cod_key0, "=" );
strcpy( cod_key+1, cod_key0 );
p1= strstr(pBuf, cod_key);
if(p1){
p1= p1 + strlen(cod_key);
p2= strchr(p1, '&');
if(p2)
Decode( p1, Vlu, p2-p1 );
else
DecodeStr(p1, Vlu);
}
else if( !memcmp( pBuf, cod_key0, strlen(cod_key0) ) ){
p1= pBuf+ strlen(cod_key0);
p2= strchr(p1, '&');
if(p2)
Decode( p1, Vlu, p2-p1 );
else
DecodeStr(p1, Vlu);
}
}
/*
*/
void CEcx::SetValue0( char *KeyName, char *Vlu ){
char *p;
if( !KeyName || !*KeyName ){
strcpy(pComm, Vlu);
return;
}
DelKey(KeyName);
if( !Vlu || !*Vlu )return;
if(*pComm)
strcat(pComm, "&");
p= pComm+ strlen(pComm);
EncodeStr(KeyName, p);
strcat(pComm, "=");
p= pComm+ strlen(pComm);
EncodeStr(Vlu, p);
}
/*
*/
void CEcx::SetValueX( char *KeyName, char *Vlu, char *pBuf ){
char *p;
if( !KeyName || !*KeyName ){
strcpy(pBuf, Vlu);
return;
}
DelKeyX(KeyName, pBuf);
if( !Vlu || !*Vlu )return;
if(*pBuf)
strcat(pBuf, "&");
p= pBuf+ strlen(pBuf);
EncodeStr(KeyName, p);
strcat(pBuf, "=");
p= pBuf+ strlen(pBuf);
EncodeStr(Vlu, p);
}
/*
*/
void CEcx::GetValue( char *KeyName, char *Vlu ){
GetValue0( KeyName, Vlu );
if(ForPbUse)
strcpy( Vlu, PbDecode(Vlu) );
}
/*
*/
void CEcx::SetValue( char *KeyName, char *Vlu ){
if(!ForPbUse){
SetValue0( KeyName, Vlu );
}
else{
SetValue0( KeyName, PbEncode(Vlu) );
}
}
/*
*/
void CEcx::GetValue1(char *Key, char *Value, int Num){
char s[BUF_SIZE];
GetValue( Key, s );
strncpy(Value,s,Num);
Value[Num-1] = '\0';
}
/*
*/
void CEcx::RsGetCol1(int Col, char *Vlu, int Num){
char s[BUF_SIZE];
RsGetCol( Col, s );
strncpy(Vlu,s,Num);
Vlu[Num-1] = '\0';
}
/*******************************************************************************/
/***ResultSet***/
/*
*/
void CEcx::RsCreate(int ColNum){
char s[20];
RsColNum=ColNum;
RsRow=RsRowNum=RsRowNum0=0;
RsBlkCli=0;
sprintf( s, "%d", RsColNum );
SetValue( "_CC", s );
*TableLst = '\0';
}
/*
*/
void CEcx::RsNewTable(int ColNum){
char s[30];
int n_rows;
n_rows= RsRowNum-RsRowNum0;
if(n_rows){
sprintf( s, "%d:%d;", RsColNum, n_rows );
RsRowNum0=RsRowNum;
strcat( TableLst, s );
}
if(ColNum)
RsColNum=ColNum;
}
/*
*/
void CEcx::RsOpen(){
char s[20];
GetValue0( "_RC", s );
RsRowNum = atoi(s);
RsRowNum0=0;
/*-*/
GetValue0( "_CC", s );
RsColNum = atoi(s);
RsRow=0;
RsBlkCli=0;
LongNum=RsRowNum;
GetValue0( "_LONG", s );
if(*s)
LongNum= atoi(s);
GetValue0( "_TL", TableLst );
}
/*
*/
void CEcx::RsAddRow(){
char s[20];
RsRowNum++;
sprintf( s, "%d", RsRowNum );
SetValue( "_RC", s );
*pRow=0;
}
/*
*/
void CEcx::RsSetCol(int Col, char *Vlu){
int i,n;
char *p, *p0, *p1;
char buf[BUF_SIZE]="";
/*Make sure (RsColNum-1) ","*/
p0=pRow;
for( i=0; i<RsColNum; i++ ){
p= strchr( p0, ',' );
if(!p)break;
p0= p+1;
}
n= RsColNum-1-i;
if(n>0){
for(i=0; i<n; i++)
strcat( pRow, "," );
}
/*Find start-end*/
p0=pRow;
p1= pRow+ strlen(pRow);
p=p1;
for( i=1; i<Col; i++ ){
p= strchr( p0, ',' );
if(!p)return;
p0= p+1;
}
p= strchr( p0, ',' );
if(p)
p1=p;
/*Set value*/
strcpy( buf, p1 );
EncodeStr_(Vlu,p0);
strcat(p0,buf);
}
/*
*/
void CEcx::RsGetCol(int Col, char *Vlu){
int i,n;
char *p, *p0, *p1;
/*Init*/
*Vlu=0;
/*Find start-end*/
p0=pRow;
p1= pRow+ strlen(pRow);
p=p1;
for( i=1; i<Col; i++ ){
p= strchr( p0, ',' );
if(!p)return;
p0= p+1;
}
p= strchr( p0, ',' );
if(p)
p1=p;
/*Get the value*/
n= p1-p0;
Decode_(p0,Vlu,n);
if(ForPbUse)
strcpy( Vlu, PbDecode(Vlu) );
}
/*
*/
void CEcx::RsSaveRow(){
char s[20];
sprintf( s, "_%d", RsRowNum );
SetValue( s, pRow );
LongNum=RsRowNum;
}
/*
*/
void CEcx::RsFetchRow(){
char s[20], tsq[20], rcs[20];
*pRow =0;
RsRow++;
if(RsRow>LongNum){
GetValue( "_TSQ", tsq );
GetValue( "_RC", rcs );
RsBlkCli= RsBlkCli+1;
memset(pComm, 0, BUF_SIZE);
SetValue( "_TSQ", tsq );
sprintf( s, "%d", RsBlkCli );
SetValue( "_BLK", s );
if(*SysId1)
SetValue( "_SYSID", SysId1 );
CallProgramAndCommit0(PrgName);
LongNum=RsRowNum;
GetValue( "_LONG", s );
if(*s)
LongNum= atoi(s);
SetValue( "_TSQ", tsq );
SetValue( "_RC", rcs );
}
sprintf( s, "_%d", RsRow );
GetValue( s, pRow );
}
/*
*/
void CEcx::RsClose(){
char s[20], tsq[20], rcs[20];
if(LongNum==RsRowNum)
return;
GetValue( "_TSQ", tsq );
GetValue( "_RC", rcs );
RsBlkCli= RsBlkCli+1;
memset(pComm, 0, BUF_SIZE);
SetValue( "_TSQ", tsq );
sprintf( s, "%d", RsBlkCli );
SetValue( "_BLK", s );
if(*SysId1)
SetValue( "_SYSID", SysId1 );
SetValue0( "_DELTSQ", "Y" );
CallProgramAndCommit0(PrgName);
}
/*
*/
int CEcx::RsGetRowNum(){
return RsRowNum;
}
/*
*/
int CEcx::RsGetColNum(){
return RsColNum;
}
/*
*/
int CEcx::RsGetTableColNum(int nt){
int i;
char *p0, *p1;
for(i=1, p0=TableLst; i<nt; i++, p0++){
p0= strchr( p0, ';' );
if(!p0)return 0;
}
p1= strchr( p0, ':' );
if(!p1)return 0;
if( p0!=p1 )
return atoi(p0);
else
return 0;
}
/*
*/
int CEcx::RsGetTableRowNum(int nt){
int i;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -