📄 ys1api.pc
字号:
ZDFile->yffs=atol(cLine);
}
/*** convert yssj to stZDYSDBRec from yssjfile and yssmfile ***/
int ConvZDYS( long int v_fsxh,char *Zzfj,struct stZDYSFileRec ZDFile,struct stZDYSDBRec *ZDDBRec )
{
ZDDBRec->xh=v_fsxh;
strcpy(ZDDBRec->zfjbh,Zzfj);
ZDDBRec->yffs=ZDFile.yffs;
ZDDBRec->qzlss=0;
return(0);
}
/*** insert yssj to database ***/
int InsertSndZDYS(struct stZDYSDBRec ZDDBRec)
{
short qzlss_id;
ERROR=0;
EXEC SQL WHENEVER SQLERROR DO sqlerror();
EXEC SQL INSERT INTO t_fszdyssj (yffs,zfjbh,fsxh) VALUES
(:ZDDBRec.yffs,
/* :ZDDBRec.qzlss :qzlss_id,
*/ :ZDDBRec.zfjbh,
:ZDDBRec.xh);
if( ERROR!=0 )
{
ERROR=0;
return(-1);
}
CHECK_TOTAL_YSSJ+=ZDDBRec.yffs;
return(0);
}
/*** insert a record of yssm and yssj into database ***/
int RecDBSingleZDYS( struct stZDYSSMDBRec ZDYSSMDBRec,char *Filename,long int v_fsxh,char *cLine )
{
int flag;
int fsfbh;
char datatype='1';
char tempstring[MID_NUM];
char Zzfj[SHORT_NUM];
struct stZDYSFileRec ZDFile;
struct stZDYSDBRec ZDDBRec;
int i,j,k;
int zfCount;
char wjbh[SHORT_NUM];
int retcode=0;
flag=CreateSndLogAndHZRec( datatype,ZDYSSMDBRec.jsfbh,v_fsxh );
if( flag!=1 )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error when use function ","CreateSndLogAndHZRec");
return(-1);
}
for(i=0,j=0;i<10;i++)
{
if(Filename[i]=='.')
{
wjbh[j]=Filename[i+1];
j++;
if( Filename[i+2]!='\0' )
{
wjbh[j]=Filename[i+2];
j++;
}
wjbh[j]='\0';
break;
}
}
flag=InsertSndZDYSSM( ZDYSSMDBRec, v_fsxh );
if( flag!=0 )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error when insert zdyssm into database",END);
return(-1);
}
zfCount=0;
EXEC SQL VAR Zzfj IS string;
EXEC SQL DECLARE cur_zfj CURSOR FOR
SELECT zfjbh FROM t_zfj WHERE sjbh=:ZDYSSMDBRec.fsfbh and yxnf=:ZDYSSMDBRec.nf ORDER BY zfjxh;
EXEC SQL SELECT count(*) INTO :zfCount FROM t_zfj WHERE sjbh=:ZDYSSMDBRec.fsfbh AND yxnf=:ZDYSSMDBRec.nf;
if( zfCount==0 )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error the number of zfj is zero, please check it",END);
return(-1);
}
j=0;
if( Filename[1]=='Z'&&Filename[2]=='Z' )
{
EXEC SQL OPEN cur_zfj;
for( i=0;i<zfCount;i++ )
{
if( cLine[j]=='\0' )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error in zdyssj, the number of yffs not enough",END);
return(-1);
}
for( k=0;; )
{
if(cLine[j]==',')
{
tempstring[k]='0';
tempstring[k+1]='\0';
j++;
break;
}
else
{
tempstring[k]=cLine[j];
k++;
if( cLine[j+1]==',' )
{
tempstring[k]='\0';
j+=2;
break;
}
else j++;
}
}
GetZDYSFileRec( tempstring,&ZDFile );
EXEC SQL FETCH cur_zfj INTO :Zzfj;
ConvZDYS( v_fsxh,Zzfj,ZDFile,&ZDDBRec );
flag=InsertSndZDYS( ZDDBRec );
if( flag!=0 )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error when use function ","InsertSndZDYS");
return(-1);
}
}
EXEC SQL CLOSE cur_zfj;
}
else if (Filename[1]=='Z'&&Filename[2]=='J' )
{
for( i=0,j=0;i<MAX_LINE_LEN;i++ )
{
for( k=0;k<SHORT_NUM;j++,k++ )
{
if( cLine[j]==',' )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error in zdyssj, ',' at the begin of a line or connected with another ','",END);
return(-1);
}
tempstring[k]=cLine[j];
if( cLine[j+1]==','||cLine[j+1]=='\n' )
break;
}
k++;
j+=2;
tempstring[k]='\0';
ZDDBRec.xh=v_fsxh;
strcpy(ZDDBRec.zfjbh,tempstring);
for( k=0;k<SHORT_NUM;j++,k++ )
{
if( cLine[j]==',' )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error in zdyssj, ',' connected with another ','",END);
return(-1);
}
if( cLine[j]=='\n'||cLine[j]==EOF )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error in zdyssj, zfjbh without its yffs",END);
return(-1);
}
tempstring[k]=cLine[j];
if( cLine[j+1]==','||cLine[j+1]=='\n' )
break;
}
k++;
j+=2;
tempstring[k]='\0';
trim(tempstring);
ZDDBRec.yffs=atoi(tempstring);
/* ZDDBRec.qzlss=0;
*/ flag=InsertSndZDYS( ZDDBRec );
if( flag!=0 )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error when use function ","InsertSndZDYS");
return(-1);
}
if( cLine[j]=='\0'||cLine[j]==EOF )
{
return(0);
}
}
}
return(0);
}
/*
//Process ZDYS data convert, put them into DB, send the data
//The divided character is ','
*/
int ConvRecDBZDYS( char *cLine,struct stZDYSSMDBRec ZDYSSMDB,char *buf2,char *Filename,int *n )
{
int flag,i;
long int v_fsxh;
int retcode=0;
EXEC SQL SELECT s_fsxh.NEXTVAL INTO :v_fsxh FROM SYS.DUAL ;
myapi_ReadALine(cLine,buf2,n);
flag=RecDBSingleZDYS( ZDYSSMDB, Filename,v_fsxh,cLine );
if( flag!=0 )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error when insert yssm and yssj into database",END);
return(-1);
}
UpdateSndLogRecStatus( v_fsxh );
return(0);
}
/*Fill in the struct: stPDYSSMDBRec with the content of a stYSSMFileRec struct,*/
/*Add and modify some components of the struct during the process. */
/*This procedure should not fail. */
int myapi_ConvertToPDYSSMDBRec(struct stYSSMFileRec stYSSMFilePoint,struct stPDYSSMDBRec *stPDYSSMDBPoint,char *FileName )
{
char temp_string[STR_LEN];
char datatype;
char *temp_Str;
int flag;
if(FileName[6]=='\0') /* Get xh of the struct */
myapi_ReadString(FileName,temp_string,5,5);
else
myapi_ReadString(FileName,temp_string,5,6);
strcpy(stPDYSSMDBPoint->wjbh,temp_string);
strcpy(stPDYSSMDBPoint->bkdh,stYSSMFilePoint.bkdh);
myapi_ReadString(FileName,temp_string,0,3);
if( temp_string[0]=='B'&&temp_string[1]=='P'&&temp_string[2]=='Z' )
datatype=BPZ;
else if(temp_string[0]=='B'&&temp_string[1]=='P'&&temp_string[2]=='J' )
datatype=BPJ;
else if(temp_string[0]=='K'&&temp_string[1]=='P'&&temp_string[2]=='Z' )
datatype=KPZ;
else if(temp_string[0]=='K'&&temp_string[1]=='P'&&temp_string[2]=='J' )
datatype=KPJ;
else
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: yslx error when convert pdys",END);
return(-1);
}
temp_string[0]=datatype;
temp_string[1]='\0';
strcpy(stPDYSSMDBPoint->yslx,temp_string);
stPDYSSMDBPoint->qdqa =atoi(stYSSMFilePoint.qdqa);
stPDYSSMDBPoint->zdqa =atoi(stYSSMFilePoint.zdqa);
if( datatype==BPZ||datatype==BPJ )
{
stPDYSSMDBPoint->qdqb =atoi(stYSSMFilePoint.qdqb);
stPDYSSMDBPoint->zdqb =atoi(stYSSMFilePoint.zdqb);
}
/* else
{
stPDYSSMDBPoint->qdqb =0;
stPDYSSMDBPoint->zdqb =0;
}
*/ strcpy(stPDYSSMDBPoint->kq,stYSSMFilePoint.kq);
stPDYSSMDBPoint->dingj=atof( stYSSMFilePoint.dj);
stPDYSSMDBPoint->dyzs =atol(stYSSMFilePoint.dyzs);
stPDYSSMDBPoint->dyk =atof(stYSSMFilePoint.dyk);
stPDYSSMDBPoint->lszs =atol(stYSSMFilePoint.lszs);
stPDYSSMDBPoint->lsk =atof(stYSSMFilePoint.lsk);
temp_string[0]='\0';
EXEC SQL SELECT to_char(sysdate,'yyyy') INTO :temp_string FROM SYS.DUAL;
temp_string[4]='\0';
stPDYSSMDBPoint->nf =atoi(temp_string);
if(stYSSMFilePoint.dsn[0]=='0')
{
if((atoi(temp_string)%2)!=0)
stPDYSSMDBPoint->nf=atoi(temp_string)+1;
}
else
{
if((atoi(temp_string)%2)==0)
stPDYSSMDBPoint->nf=atoi(temp_string)+1;
}
strcpy(stPDYSSMDBPoint->fsfbh,stYSSMFilePoint.fsfbh);
strcpy(stPDYSSMDBPoint->jsfbh,stYSSMFilePoint.jsfbh);
return(0);
}
/*** use the functions beyond to convert a string to a struct to insert to database ***/
int ConvertPDYSSMFormat( char *cLine,char *FileName,struct stPDYSSMDBRec *stPDYSSMDB )
{
char tempstring[100];
char *EndFlag;
int flag;
int i;
int Control;
struct stYSSMFileRec stYSSMFile;
int retcode=0;
for(i=0;cLine[i]!='\0';i++);
if( i!=73 )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error in pdyssm the length of yssm is incorrect",END);
return(-1);
}
myapi_ConvertToYSSMFileRec( cLine,&stYSSMFile );
flag=myapi_ConvertToPDYSSMDBRec( stYSSMFile,stPDYSSMDB,FileName );
if( flag!=0 )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error in pdyssm when convert struct stYSSMFile to struct stPDYSSMDB",END);
return(-1);
}
return(0);
}
/*** insert yssm struct to database ***/
int InsertSndPDYSSM( struct stPDYSSMDBRec st,int v_fsxh )
{
char year[SHORT_NUM];
char datatype='2';
short qdqa_id,qdqb_id,zdqa_id,zdqb_id,dingj_id,dyzs_id,dyk_id,lszs_id,lsk_id,nf_id;
ERROR=0;
EXEC SQL WHENEVER SQLERROR DO sqlerror();
/* printf(",%s,%s,%s,%d,%d,\n",st.bkdh,st.yslx,st.wjbh,st.qdqa,st.qdqb);
printf(",%d,%d,%s,%.2f\n",st.zdqa,st.zdqb,st.kq,st.dingj);
printf(",%ld,%.2f,%ld,%.2f,%d,%ld\n",st.dyzs,st.dyk,st.lszs,st.lsk,st.nf,v_fsxh);
*/ EXEC SQL INSERT INTO t_fspdyssm VALUES
( :st.bkdh,
:st.yslx,
:st.wjbh,
:st.qdqa,
:st.qdqb :qdqb_id,
:st.zdqa :zdqa_id,
:st.zdqb :zdqb_id,
:st.kq,
:st.dingj :dingj_id,
:st.dyzs :dyzs_id,
:st.dyk :dyk_id,
:st.lszs :lszs_id,
:st.lsk :lsk_id,
:st.nf,
:v_fsxh);
if( ERROR!=0 )
{
ERROR=0;
return(-1);
}
return(0);
}
/*** insert yssj to database ***/
int InsertSndPDYS(struct stPDYSDBRec PDDBRec)
{
short lszjfs_id;
EXEC SQL WHENEVER SQLERROR DO sqlerror();
EXEC SQL INSERT INTO t_fspdyssj (zjfs,zfjbh,fsxh) VALUES
(:PDDBRec.zjfs,
/* :PDDBRec.lszjfs :lszjfs_id,
*/ :PDDBRec.zfjbh,
:PDDBRec.xh);
if( ERROR!=0 )
{
ERROR=0;
return(-1);
}
CHECK_TOTAL_YSSJ+=PDDBRec.zjfs;
return(0);
}
/*** insert a record of yssm and yssj into database ***/
int RecDBSinglePDYS( struct stPDYSSMDBRec PDYSSMDBRec,char *Filename,long int v_fsxh,char *cLine )
{
int flag;
char tempstring[100];
char datatype='2';
char Zzfj[MID_NUM][SHORT_NUM];
struct stPDYSDBRec PDDBRec;
int i,j,k;
int zfCount;
char wjbh[SHORT_NUM];
int retcode=0;
flag=CreateSndLogAndHZRec( datatype,PDYSSMDBRec.jsfbh,v_fsxh );
if( flag!=1 )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error when use function ","CreateSndLogAndHZRec");
return(-1);
}
flag=InsertSndPDYSSM( PDYSSMDBRec, v_fsxh );/**/
if( flag!=0 )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error when insert pdyssm into database",END);
return(-1);
}
for( i=0,j=0;i<STR_LEN;i++ )
{
for( k=0;k<SHORT_NUM;j++,k++ ) /** get zfjbh **/
{
if( cLine[j]==',' )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error in pdyssj, ',' at the begin of a line or connected with another ','",END);
return(-1);
}
tempstring[k]=cLine[j];
if( cLine[j+1]==','||cLine[j+1]=='\n' )
break;
}
k++;
j+=2;
tempstring[k]='\0';
PDDBRec.xh=v_fsxh;
strcpy(PDDBRec.zfjbh,tempstring);
for( k=0;k<SHORT_NUM;j++,k++ ) /** get yffs **/
{
if( cLine[j]==',' )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error in pdyssj, ',' connected with another ','",END);
return(-1);
}
if( cLine[j]=='\n'||cLine[j]==EOF ) /** need yffs but without **/
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error in pdyssj, zfjbh without its yffs",END);
return(-1);
}
tempstring[k]=cLine[j];
if( cLine[j+1]==','||cLine[j+1]=='\n' )
break;
}
k++;
j+=2;
tempstring[k]='\0';
PDDBRec.zjfs=atoi(tempstring);
PDDBRec.lszjfs=0;
flag=InsertSndPDYS( PDDBRec );
if( flag!=0 )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error when use function ","InsertSndPDYS");
return(-1);
}
if( cLine[j]=='\0'||cLine[j]==EOF )
{
return(0);
}
}
return(0);
}
/*
//Process PDYS data convert, put them into DB, send the data
//The divided character is ','
*/
int ConvRecDBPDYS( char *cLine,struct stPDYSSMDBRec PDYSSMDB,char *buf2,char *Filename,int *n )
{
int flag,i,j;
long int v_fsxh;
int retcode=0;
EXEC SQL SELECT s_fsxh.NEXTVAL INTO :v_fsxh FROM SYS.DUAL ;
myapi_ReadALine(cLine,buf2,n);
flag=RecDBSinglePDYS( PDYSSMDB, Filename,v_fsxh,cLine );
if( flag!=0 )
{
ProcessError(LOG_ERROR,"PCS_Snd_YS1: error when insert yssm and yssj into database",END);
return(-1);
}
UpdateSndLogRecStatus( v_fsxh );
return(0);
}
/* get filename from input path/filename */
/* the target is trim the path from input */
void trimpath( char *string,char *filename )
{
int len;
int i,k;
filename[0]='\0';
len=strlen(string);
for( i=len ; i>=0 ; i-- )
if( string[i]=='/' )
break;
if( i==0 )
strcpy(filename,string);
else
{
for( k=0 ; k<len-i ; k++ )
filename[k]=string[i+k+1];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -