You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
243 lines
4.4 KiB
C++
243 lines
4.4 KiB
C++
#include <QString>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <QCoreApplication>
|
|
#include "Global.h"
|
|
#include "CommonFunc.h"
|
|
#include "WriteLog.h"
|
|
|
|
int QStr2Utf8(const QString &str, char *pStr, int len)
|
|
{
|
|
int iret;
|
|
char * pData;
|
|
QByteArray btemp;
|
|
|
|
btemp = str.toUtf8();
|
|
pData = btemp.data();
|
|
if(! pStr)
|
|
{
|
|
WRITE_LOG("字符串转换 %s 失败, 缓冲区指针为空",pData);
|
|
return -1;
|
|
}
|
|
|
|
iret =strlen(pData);
|
|
if(iret >= len)
|
|
{
|
|
WRITE_LOG("字符串转换 %s 失败, 缓冲区长度不足 %d ",pData,len);
|
|
return -2;
|
|
}
|
|
|
|
strcpy(pStr,pData);
|
|
|
|
return iret;
|
|
}
|
|
int CreateJsonData(QDateTime dt,int ano,QString &qstr,char * buf,int iLen)
|
|
{
|
|
char tmpbuf[512];
|
|
char databuf[256];
|
|
QString qtemp;
|
|
int iret;
|
|
|
|
memset(tmpbuf, 0,sizeof(tmpbuf));
|
|
strcpy(tmpbuf,"{\"classNo\":");
|
|
|
|
sprintf(databuf,"%d",ano);
|
|
strcat(tmpbuf,databuf);
|
|
|
|
//strcpy(buf,"")
|
|
strcat(tmpbuf,",\"className\":\"");
|
|
memset(databuf, 0, sizeof(databuf));
|
|
iret = QStr2Utf8(qstr,databuf,200);
|
|
if(iret <0)
|
|
{
|
|
return -1;
|
|
}
|
|
|
|
strcat(tmpbuf,databuf);
|
|
strcat(tmpbuf,"\",\"classDate\":\"");
|
|
|
|
qtemp = dt.toString("yyyy-MM-dd");
|
|
memset(databuf, 0, sizeof(databuf));
|
|
iret = QStr2Utf8(qtemp,databuf,50);
|
|
if(iret <0)
|
|
{
|
|
return -2;
|
|
}
|
|
|
|
strcat(tmpbuf,databuf);
|
|
strcat(tmpbuf,"\"}");
|
|
|
|
iret =strlen(tmpbuf);
|
|
if(iret >=iLen)
|
|
{
|
|
return -3;
|
|
}
|
|
|
|
strcpy(buf,tmpbuf);
|
|
return 0;
|
|
}
|
|
|
|
void changechar(char * buf, char dest,char sourece)
|
|
{
|
|
int iLen;
|
|
if(! buf)
|
|
{
|
|
return;
|
|
}
|
|
|
|
iLen =strlen(buf);
|
|
if(0 == iLen)
|
|
{
|
|
return;
|
|
}
|
|
|
|
for(int i=0; i<iLen; i++)
|
|
{
|
|
if(sourece == (buf[i]))
|
|
{
|
|
buf[i] = dest;
|
|
}
|
|
}
|
|
}
|
|
|
|
void checkPathEnd(char * path)
|
|
{
|
|
int iLen;
|
|
if(! path)
|
|
{
|
|
return;
|
|
}
|
|
|
|
iLen = strlen(path);
|
|
if(0 == iLen)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if( '/' == path[iLen-1])
|
|
{
|
|
return;
|
|
}
|
|
|
|
path[iLen] = '/';
|
|
// iLen = strlen(path);;
|
|
}
|
|
|
|
int isDigitStr(QString src)
|
|
{
|
|
QByteArray ba = src.toLatin1();//QString 转换为 char*
|
|
|
|
const char *s = ba.data();
|
|
while(*s && *s>='0' && *s<='9') s++;
|
|
if (*s)
|
|
{
|
|
return -1;
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
int SetDllPath(char * path)
|
|
{
|
|
int ilen;
|
|
int inum;
|
|
//int iret;
|
|
char * ptr;
|
|
char buf[8192];
|
|
QString tmpPath;
|
|
QString SqlPath;
|
|
QString m_libPath;
|
|
QString qstr;
|
|
|
|
m_libPath =path;
|
|
m_libPath = m_libPath.left(m_libPath.size()-1);
|
|
tmpPath = QString("PATH=");
|
|
tmpPath += m_libPath;
|
|
tmpPath += ";";
|
|
|
|
SqlPath = m_libPath +"/sqldrivers"+";";
|
|
|
|
tmpPath += SqlPath;
|
|
|
|
// tmpPath += getenv("PATH");
|
|
ptr = getenv("PATH");
|
|
if(ptr)
|
|
{
|
|
ilen = strlen(ptr);
|
|
if(ilen >7000)
|
|
{
|
|
WRITE_LOG("getenv 字符串长度太大");
|
|
return -2;
|
|
}
|
|
qstr = GBK2QStr(ptr,ilen);
|
|
tmpPath += qstr;
|
|
}
|
|
|
|
tmpPath.replace("/","\\");
|
|
memset(buf,0,sizeof(buf));
|
|
QStr2GBK(tmpPath,buf,8000);
|
|
|
|
putenv(buf);
|
|
// putenv(tmpPath.toLocal8Bit().data());
|
|
// WRITE_LOG(tmpPath.toUtf8().data());
|
|
WRITE_LOG("putenv is %s",buf);
|
|
|
|
tmpPath = m_libPath;
|
|
tmpPath.replace("\\","/");
|
|
QCoreApplication::addLibraryPath(tmpPath);
|
|
WRITE_LOG("addlibrarypath is %s",tmpPath.toUtf8().data());
|
|
// tmpPath +=";";
|
|
SqlPath = m_libPath +"/sqldrivers";
|
|
SqlPath.replace("\\","/");
|
|
QCoreApplication::addLibraryPath(SqlPath);
|
|
WRITE_LOG("addlibrarypath is %s",SqlPath.toUtf8().data());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int SetLogPath(char * path)
|
|
{
|
|
int ilen;
|
|
int inum;
|
|
//int iret;
|
|
// char * ptr;
|
|
char buf[384];
|
|
QString tmpPath;
|
|
QString SqlPath;
|
|
QString m_libPath;
|
|
QString qstr;
|
|
|
|
|
|
memset(buf,0,sizeof(buf));
|
|
strcpy(buf, path);
|
|
ilen = strlen(buf);
|
|
inum =0;
|
|
for(int i=(ilen -1); i>0; i--)
|
|
{
|
|
if(buf[i] == '/')
|
|
{
|
|
inum++;
|
|
if(2 == inum)
|
|
{
|
|
buf[i] =0;
|
|
m_libPath =buf;
|
|
strcat(buf,"/log/");
|
|
InitLogDir(buf);
|
|
break;
|
|
//return 0;
|
|
}
|
|
}
|
|
}
|
|
|
|
if(inum != 2)
|
|
{
|
|
WRITE_LOG("SetlogPath fail %s",buf);
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|