www.pudn.com > gamedata.rar > common.c
#include "stdafx.h"
#include "common.h"
extern struct optiondata option;
extern struct OBJECT_INFO object_info[MAX_NUM_OBJ];
extern BYTE G_BYTE_DOII_XorTable[D_XORTABLE_LENGTH];
extern BYTE G_BYTE_XorTable[D_XORTABLE_LENGTH];
void SaveLog(char *p)
{
FILE *fp = fopen("c:\\Game.txt", "a+");
if(fp != NULL)
{
fprintf(fp,"%s\n",p);
fclose(fp);
}
}
void Encode_Decode(LPBYTE lpTarget, LPBYTE lpSource, int nLen)
{
BYTE l_BYTE_Xor1 = (WORD)nLen * D_WORD_XOR1MUL, l_BYTE_Xor3;
WORD l_WORD_Xor3 = D_WORD_XOR3BASE, nCir;
for (nCir=0; nCir<(WORD)nLen; nCir++)
{
l_BYTE_Xor3 = HIBYTE(l_WORD_Xor3);
lpTarget[nCir] = lpSource[nCir] ^ l_BYTE_Xor1 ^ G_BYTE_XorTable[nCir % D_XORTABLE_LENGTH] ^ l_BYTE_Xor3;
l_WORD_Xor3 *= D_WORD_XOR3MUL;
}
}
long min_(long n1, long n2)
{
if (n2 > n1) return n1; else return n2;
return n1;
}
long max_(long n1, long n2)
{
if (n2 > n1) return n2; else return n1;
return n1;
}
BOOL getprobabilitystatus(int probability)
{
if ((rand()%10001)<= probability)
return TRUE;
return FALSE;
};
BOOL getpercentageprobabilitystatus(int probability)
{
if ((rand()%101)<= probability)
return TRUE;
return FALSE;
}
void Encode1(BYTE buf, int data)
{
buf = data % 256;
}
void Encode2(BYTE buf[2], int data)
{
// buf[0] = (data / 256) % 256;
/// buf[1] = data % 256;
buf[0] = (data >> 8) % 256;
buf[1] = data % 256;
}
void Encode4(BYTE buf[4], long data)
{
/* buf[0] = ((data / 256 / 256 / 256) % 256);
buf[1] = ((data / 256 / 256) % 256);
buf[2] = ((data / 256) % 256);
buf[3] = (data % 256);
*/
buf[0] = ((data >> 8 >> 8 >> 8) % 256);
buf[1] = ((data >> 8 >> 8) % 256);
buf[2] = ((data >> 8) % 256);
buf[3] = (data % 256);
}
int Decode1(BYTE buf)
{
return buf;
}
int Decode2(BYTE n1, BYTE n2)
{
return ((int)n1 * (int)n2 * 256 + (int)n2);
//return ((int)n1 * (int)n2 << 8 + (int)n2);
}
long Decode4(BYTE buf[4])
{
return buf[0] * 256 * 256 * 256 + buf[1] * 256 * 256 + buf[2] * 256 + buf[3];
// return buf[0] << 8 << 8 << 8 + buf[1] << 8 << 8 + buf[2] << 8 + buf[3];
}
void GetExeDir(char* szExeDir)
{
char buf[MAX_PATH];
char *cptr;
GetModuleFileNameA(NULL, buf, MAX_PATH);
//move pointer to end of string
cptr = buf + lstrlenA(buf);
//find the end of the path
do
{
cptr--;
} while (*cptr != '\\');
cptr++;
*cptr='\0';
strcpy(szExeDir,buf);
}
int myrand(int min, int max)
{
if( min == max ) return min;
if (min > max) return (rand() % (min-max+1)) + max;
return (rand() % (max-min+1)) + min;
}
int DisplayErrorMsg(char *fun, SQLHANDLE hstmt)
{
SQLCHAR SqlState[6], Msg[1024];
SQLINTEGER NativeError;
SQLSMALLINT i, MsgLen;
SQLRETURN rc2;
char logstr[512];
memcpy(logstr, NULL, 0);
while ((rc2 = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, i, SqlState, &NativeError, Msg, sizeof(Msg), &MsgLen)) != SQL_NO_DATA)
i = 1;
// rc2 = SQLGetDiagRec(SQL_HANDLE_STMT, hstmt, i, SqlState, &NativeError, Msg, sizeof(Msg), &MsgLen);
{
sprintf( logstr, "*** function %s, %s, %d, %s, %d ***\r\n", fun, SqlState,NativeError,Msg,MsgLen );
SaveLog(logstr);
i++;
}
if(strcmp((char *)SqlState, "08S01") == 0 )
return -1;
else
return 0;
}
BOOL savechar(struct OBJECT_INFO info)
{
SQLHSTMT hstmt;
SQLHDBC hdbc;
SQLRETURN retcode;
char szSQL[8196];
BOOL retval;
SQLINTEGER cbParmRet;
int i;
char face[255];
char spell[100];
char skill1[255];
char skill2[100];
char item[39][100];
memset( szSQL, 0x00, 8196);
cbParmRet = SQL_NTS; hstmt = NULL;
sprintf(face, "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d",
info.face[0], info.face[1], info.face[2], info.face[3], info.face[4], info.face[5],
info.face[6], info.face[7], info.face[8], info.face[9], info.face[10], info.face[11],
info.face[12], info.face[13], info.face[14], info.face[15], info.face[16], info.face[17],
info.face[18], info.face[19]);
sprintf(spell, "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d",
info.spell_[0], info.spell_[1], info.spell_[2], info.spell_[3], info.spell_[4],
info.spell_[5], info.spell_[6], info.spell_[7], info.spell_[8], info.spell_[9],
info.spell_[10], info.spell_[11]);
sprintf(skill1, "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d",
info.skill1[0], info.skill1[1], info.skill1[2], info.skill1[3], info.skill1[4],
info.skill1[5], info.skill1[6], info.skill1[7], info.skill1[8], info.skill1[9],
info.skill1[10], info.skill1[11], info.skill1[12], info.skill1[13], info.skill1[14],
info.skill1[15], info.skill1[16], info.skill1[17], info.skill1[18], info.skill1[19]);
sprintf(skill2, "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d",
info.skill2[0], info.skill2[1], info.skill2[2], info.skill2[3], info.skill2[4],
info.skill2[5], info.skill2[6], info.skill2[7], info.skill2[8], info.skill2[9],
info.skill2[10], info.skill2[11]);
for(i=0;i<39;i++)
{
sprintf(item[i], "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d",
info.Novelity[i][0], info.Novelity[i][1], info.Novelity[i][2], info.Novelity[i][3], info.Novelity[i][4],
info.Novelity[i][5], info.Novelity[i][6], info.Novelity[i][7], info.Novelity[i][8], info.Novelity[i][9],
info.Novelity[i][10], info.Novelity[i][11], info.Novelity[i][12], info.Novelity[i][13], info.Novelity[i][14],
info.Novelity[i][15], info.Novelity[i][16]);
}
sprintf(szSQL, "UPDATE TBL_CHAR SET FLD_APPELLATION = '%s', FLD_JOB = '%d', FLD_EXP = '%d', FLD_LEVEL='%d', FLD_FACE='%s', FLD_SPELL='%s', FLD_DIRECTION='%d', FLD_FIGHT_EXP='%d', FLD_PK='%d', FLD_MONEY='%d', FLD_NUMBER1_NOW='%d', FLD_NUMBER2_NOW='%d', FLD_NUMBER3_NOW='%d', FLD_NUMBER1__NOW='%d', FLD_NUMBER2__NOW='%d', FLD_ATTRIBUTION1='%d', FLD_ATTRIBUTION2='%d', FLD_ATTRIBUTION3='%d', FLD_ATTRIBUTION4='%d', FLD_ATTRIBUTION5='%d', FLD_CITIZEN_LEVEL='%d', FLD_CITIZEN_EXP='%d', FLD_SKILL1='%d', FLD_SKILL2='%d', FLD_SKILL3='%d', FLD_SKILL_NUMBER1='%s', FLD_SKILL_NUMBER2='%s', FLD_ITEM1='%s', FLD_ITEM2='%s', FLD_ITEM3='%s', FLD_ITEM4='%s', FLD_ITEM5='%s', FLD_ITEM6='%s', FLD_ITEM7='%s', FLD_ITEM8='%s', FLD_ITEM9='%s', FLD_ITEM10='%s', FLD_ITEM11='%s', FLD_ITEM12='%s', FLD_ITEM13='%s', FLD_ITEM14='%s', FLD_ITEM15='%s', FLD_ITEM16='%s', FLD_ITEM17='%s', FLD_ITEM18='%s', FLD_ITEM19='%s', FLD_ITEM20='%s', FLD_ITEM21='%s', FLD_ITEM22='%s', FLD_ITEM23='%s', FLD_ITEM24='%s', FLD_ITEM25='%s', FLD_ITEM26='%s', FLD_ITEM27='%s', FLD_ITEM28='%s', FLD_ITEM29='%s', FLD_ITEM30='%s', FLD_ITEM31='%s', FLD_ITEM32='%s', FLD_ITEM33='%s', FLD_ITEM34='%s', FLD_ITEM35='%s', FLD_ITEM36='%s', FLD_ITEM37='%s', FLD_ITEM38='%s', FLD_ITEM39='%s', FLD_MENOW1='%d', FLD_MENOW2='%d', FLD_ME_X='%d', FLD_ME_Y='%d', FLD_SERVER_INDEX='%d' WHERE (FLD_ID='%s') AND (FLD_CHAR_NAME='%s')",
info.appellation, info.job, info.exp, info.level, face, spell, info.direction, info.fight_exp, info.pkexp, info.money, info.life_now, info.mental_now, info.brawn_now,
info.biglifenumber, info.bigspellnumber, info.force, info.somatic, info.celerity, info.wisdom, info.intellect, info.citizenlevel, info.citizenexp, info.surplusskill1,
info.surplusskill2, info.surplusskill3, skill1, skill2, item[0], item[1], item[2], item[3], item[4], item[5], item[6], item[7], item[8], item[9], item[10], item[11], item[12],
item[13], item[14], item[15], item[16], item[17], item[18], item[19], item[20], item[21], item[22], item[23], item[24], item[25], item[26], item[27], item[28], item[29], item[30],
item[31], item[32], item[33], item[34], item[35], item[36], item[37], item[38], info.menow1, info.menow2, info.now_x, info.now_y, info.serverindex, info.id, info.name);
hdbc = connectDB(option.chardsn, option.charuid, option.charpwd); if (hdbc == NULL) return FALSE;
retcode = SQLAllocHandle((SQLSMALLINT)SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect(hstmt, (unsigned char *)szSQL, 8196);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
retval = TRUE;
}
else
{
DisplayErrorMsg("savechar", hstmt);
retval = FALSE;
}
}
else
retval = FALSE;
disconnectDB(hdbc, hstmt);
return retval;
}
struct OBJECT_INFO loadchar(char *id, char *name)
{
SQLHSTMT hstmt;
SQLHDBC hdbc;
char tmp[255];
SQLRETURN retcode;
BOOL bData, retval;
char szSQL[1024];
struct OBJECT_INFO info;
SQLINTEGER Indexind, nPoints;
int i;
memset( szSQL, 0x00, 1024 );
Indexind = SQL_NTS; nPoints = 0; bData = TRUE; retval = FALSE; hstmt = NULL;
sprintf(szSQL, "SELECT * FROM TBL_CHAR WHERE FLD_ID='%s' AND FLD_CHAR_NAME='%s'", id, name);
hdbc = connectDB(option.chardsn, option.charuid, option.charpwd); if (hdbc == NULL) { info.have = FALSE; return info; }
retcode = SQLAllocHandle((SQLSMALLINT)SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect(hstmt, (unsigned char *)szSQL, 1024);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
retcode = SQLFetch(hstmt);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
SQLGetData(hstmt, 1, SQL_C_CHAR, info.id, 32, &Indexind); // 帐号
SQLGetData(hstmt, 2, SQL_C_CHAR, info.name, 32, &Indexind); // 角色名称
SQLGetData(hstmt, 3, SQL_C_CHAR, info.appellation, 32, &Indexind); // 称号
SQLGetData(hstmt, 4, SQL_INTEGER, &info.job, 0, &Indexind); // 职业
SQLGetData(hstmt, 5, SQL_C_CHAR, tmp, 32, &Indexind); // 经验
info.exp = atol(tmp);
SQLGetData(hstmt, 6, SQL_INTEGER, &info.level, 0, &Indexind); // 等级
SQLGetData(hstmt, 7, SQL_C_CHAR, tmp, 255, &Indexind); // 脸型
sscanf(tmp, "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d",
&info.face[0], &info.face[1], &info.face[2], &info.face[3], &info.face[4], &info.face[5],
&info.face[6], &info.face[7], &info.face[8], &info.face[9], &info.face[10], &info.face[11],
&info.face[12], &info.face[13], &info.face[14], &info.face[15], &info.face[16], &info.face[17],
&info.face[18], &info.face[19]);
SQLGetData(hstmt, 8, SQL_C_CHAR, tmp, 255, &Indexind); // 学习的魔法
sscanf(tmp, "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d",
&info.spell_[0], &info.spell_[1], &info.spell_[2], &info.spell_[3], &info.spell_[4],
&info.spell_[5], &info.spell_[6], &info.spell_[7], &info.spell_[8], &info.spell_[9],
&info.spell_[10], &info.spell_[11]);
SQLGetData(hstmt, 9, SQL_INTEGER, &info.direction, 0, &Indexind); // 方向
SQLGetData(hstmt, 10, SQL_C_CHAR, tmp, 32, &Indexind); // 战斗经验
info.fight_exp = atol(tmp);
SQLGetData(hstmt, 11, SQL_INTEGER, &info.pkexp, 0, &Indexind); // PK值
SQLGetData(hstmt, 12, SQL_C_CHAR, tmp, 32, &Indexind); // 钱
info.money = atol(tmp);
SQLGetData(hstmt, 13, SQL_INTEGER, &info.life_now, 0, &Indexind); // 现在的生命数值
SQLGetData(hstmt, 14, SQL_INTEGER, &info.mental_now, 0, &Indexind); // 现在的精神数值
SQLGetData(hstmt, 15, SQL_INTEGER, &info.brawn_now , 0, &Indexind); // 现在的体力数值
SQLGetData(hstmt, 16, SQL_INTEGER, &info.biglifenumber, 0, &Indexind); // 现在的大号生命数值
SQLGetData(hstmt, 17, SQL_INTEGER, &info.bigspellnumber, 0, &Indexind); // 现在的大号精神数值
SQLGetData(hstmt, 18, SQL_INTEGER, &info.force, 0, &Indexind); // 力量
SQLGetData(hstmt, 19, SQL_INTEGER, &info.somatic, 0, &Indexind); // 体质
SQLGetData(hstmt, 20, SQL_INTEGER, &info.celerity, 0, &Indexind); // 敏捷
SQLGetData(hstmt, 21, SQL_INTEGER, &info.wisdom, 0, &Indexind); // 智慧
SQLGetData(hstmt, 22, SQL_INTEGER, &info.intellect, 0, &Indexind); // 智力
SQLGetData(hstmt, 23, SQL_INTEGER, &info.citizenlevel, 0, &Indexind); // 市民等级
SQLGetData(hstmt, 24, SQL_INTEGER, &info.citizenexp, 0, &Indexind); // 市民经验
SQLGetData(hstmt, 25, SQL_INTEGER, &info.surplusskill1, 0, &Indexind); // 剩余点数
SQLGetData(hstmt, 26, SQL_INTEGER, &info.surplusskill2, 0, &Indexind); // 剩余点数
SQLGetData(hstmt, 27, SQL_INTEGER, &info.surplusskill3, 0, &Indexind); // 剩余点数
SQLGetData(hstmt, 28, SQL_C_CHAR, tmp, 255, &Indexind); // 技能
sscanf(tmp, "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d",
&info.skill1[0], &info.skill1[1], &info.skill1[2], &info.skill1[3], &info.skill1[4],
&info.skill1[5], &info.skill1[6], &info.skill1[7], &info.skill1[8], &info.skill1[9],
&info.skill1[10], &info.skill1[11], &info.skill1[12], &info.skill1[13], &info.skill1[14],
&info.skill1[15], &info.skill1[16], &info.skill1[17], &info.skill1[18], &info.skill1[19]);
SQLGetData(hstmt, 29, SQL_C_CHAR, tmp, 255, &Indexind); // 超能
sscanf(tmp, "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d",
&info.skill2[0], &info.skill2[1], &info.skill2[2], &info.skill2[3], &info.skill2[4],
&info.skill2[5], &info.skill2[6], &info.skill2[7], &info.skill2[8], &info.skill2[9],
&info.skill2[10], &info.skill2[11]);
for (i=0;i<39;i++)
{
SQLGetData(hstmt, (SQLSMALLINT)(30 + i), SQL_C_CHAR, tmp, 255, &Indexind); // 物品
sscanf(tmp, "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d",
&info.Novelity[i][0], &info.Novelity[i][1], &info.Novelity[i][2], &info.Novelity[i][3], &info.Novelity[i][4],
&info.Novelity[i][5], &info.Novelity[i][6], &info.Novelity[i][7], &info.Novelity[i][8], &info.Novelity[i][9],
&info.Novelity[i][10], &info.Novelity[i][11], &info.Novelity[i][12], &info.Novelity[i][13], &info.Novelity[i][14],
&info.Novelity[i][15], &info.Novelity[i][16]);
}
SQLGetData(hstmt, 69, SQL_INTEGER, &info.menow1, 0, &Indexind); // 位置
SQLGetData(hstmt, 70, SQL_INTEGER, &info.menow2, 0, &Indexind); // 位置
SQLGetData(hstmt, 71, SQL_INTEGER, &info.now_x, 0, &Indexind); // 坐标x
SQLGetData(hstmt, 72, SQL_INTEGER, &info.now_y, 0, &Indexind); // 坐标y
SQLGetData(hstmt, 73, SQL_INTEGER, &info.serverindex, 0, &Indexind); // 服务器号
if (info.money < 0) info.money = 0;
/*
info.menow1 = option.menow1;
info.menow2 = option.menow2;
info.now_x = option.now_x;
info.now_y = option.now_y;
*/
// MessageBox(NULL, id, name, 0);
strcpy(info.team, "\\");
// info.life_max = info.life_now;
// info.mental_max = info.mental_now;
// info.brawn_max = info.brawn_now;
info.npc = 0;
info.status = TRUE;
info.life = TRUE;
info.have = TRUE;
}
}
else
{
DisplayErrorMsg("loadchar", hstmt);
info.have = FALSE;
}
}
else
info.have = FALSE;
disconnectDB(hdbc, hstmt);
return info;
}
BOOL loaddoor(char *name, struct DOOR_INFO info[30])
{
SQLHSTMT hstmt;
SQLHDBC hdbc;
char tmp[100];
BOOL retval;
SQLRETURN retcode;
char szSQL[512];
SQLINTEGER Indexind;
int a, i;
char n1[20], n2[20], n3[20], n4[20], n5[20];
memset(szSQL, 0x00, 512);
hstmt = NULL; Indexind = SQL_NTS;
a = i = 0;
sprintf(szSQL, "SELECT * FROM TBL_DOOR_30 WHERE FLD_CHAR_NAME='%s'", name);
hdbc = connectDB(option.doordsn, option.dooruid, option.doorpwd); if (hdbc == NULL) return FALSE;
retcode = SQLAllocHandle((SQLSMALLINT)SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 512);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
retcode=SQLFetch(hstmt);
if (retcode == SQL_SUCCESS|| retcode == SQL_SUCCESS_WITH_INFO)
{
for (i=0;i<30;i++)
{
SQLGetData(hstmt, (SQLSMALLINT)(2 + i), SQL_C_CHAR, tmp, 255, &Indexind); // 物品
sscanf(tmp, "%s - %s - %s - %s - %s", n1, n2, n3, n4, n5);
strcpy(info[i].name, n1); info[i].Code1 = (BYTE)atoi(n2); info[i].Code2 = (BYTE)atoi(n3); info[i].x = atoi(n4); info[i].y = atoi(n5);
if ((strcmp(info[i].name, "") != 0) && (strcmp(info[i].name, "\\") != 0)) info[i].have = TRUE; else info[i].have = FALSE;
}
retval = TRUE;
}
else
{
retval = FALSE;
}
}
else
{
DisplayErrorMsg("loaddoor", hstmt);
retval = FALSE;
}
}
else
retval = FALSE;
disconnectDB(hdbc, hstmt);
return retval;
}
long loadprivatewarehouse(char *name, struct WAREHOUSE_INFO info[48])
{
SQLHSTMT hstmt;
SQLHDBC hdbc;
char tmp[255];
SQLRETURN retcode;
char szSQL[1024];
SQLINTEGER Indexind;
int a, i;
long money;
memset(szSQL, 0x00, 1024);
hstmt = NULL; Indexind = SQL_NTS;
a = i = 0;
sprintf(szSQL, "SELECT * FROM TBL_PRIVATE WHERE FLD_CHAR_NAME='%s'", name);
hdbc = connectDB(option.warehousedsn, option.warehouseuid, option.warehousepwd); if (hdbc == NULL) return FALSE;
retcode = SQLAllocHandle((SQLSMALLINT)SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 1024);
if (retcode == SQL_SUCCESS|| retcode == SQL_SUCCESS_WITH_INFO)
{
retcode=SQLFetch(hstmt);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
SQLGetData(hstmt, 2, SQL_INTEGER, &money, 0, &Indexind); // 物品
for (i=0;i<48;i++)
{
SQLGetData(hstmt, (SQLSMALLINT)(3 + i), SQL_C_CHAR, tmp, 255, &Indexind); // 物品
sscanf(tmp, "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d", &info[i].code[0], &info[i].code[1], &info[i].code[2], &info[i].code[3],
&info[i].code[4], &info[i].code[5], &info[i].code[6], &info[i].code[7], &info[i].code[8], &info[i].code[9],
&info[i].code[10], &info[i].code[11], &info[i].code[12], &info[i].code[13], &info[i].code[14], &info[i].code[15], &info[i].code[16]);
}
}
else
{
money = -1;
}
}
else
{
DisplayErrorMsg("loadprivatewarehouse", hstmt);
money = -1;
}
}
else
money = -1;
disconnectDB(hdbc, hstmt);
return money;
}
long loadpublicwarehouse(char *id, struct WAREHOUSE_INFO info[50])
{
SQLHSTMT hstmt;
SQLHDBC hdbc;
char tmp[255];
SQLRETURN retcode;
char szSQL[1024];
SQLINTEGER Indexind;
int a, i;
long money;
memset( szSQL, 0x00, 1024 );
hstmt = NULL; Indexind = SQL_NTS;
a = i = 0;
sprintf(szSQL, "SELECT * FROM TBL_PUBLIC WHERE FLD_ID='%s'", id);
hdbc = connectDB(option.warehousedsn, option.warehouseuid, option.warehousepwd); if (hdbc == NULL) return FALSE;
retcode = SQLAllocHandle((SQLSMALLINT)SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 1024);
if (retcode == SQL_SUCCESS|| retcode == SQL_SUCCESS_WITH_INFO)
{
retcode=SQLFetch(hstmt);
if (retcode == SQL_SUCCESS|| retcode == SQL_SUCCESS_WITH_INFO)
{
SQLGetData(hstmt, 2, SQL_INTEGER, &money, 0, &Indexind); //
for (i=0;i<50;i++)
{
SQLGetData(hstmt, (SQLSMALLINT)(3 + i), SQL_C_CHAR, tmp, 255, &Indexind); //
sscanf(tmp, "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d", &info[i].code[0], &info[i].code[1], &info[i].code[2], &info[i].code[3],
&info[i].code[4], &info[i].code[5], &info[i].code[6], &info[i].code[7], &info[i].code[8], &info[i].code[9],
&info[i].code[10], &info[i].code[11], &info[i].code[12], &info[i].code[13], &info[i].code[14], &info[i].code[15], &info[i].code[16]);
}
}
else
{
money = -1;
}
}
else
{
DisplayErrorMsg("loadpublicwarehouse", hstmt);
money = -1;
}
}
else
money = -1;
disconnectDB(hdbc, hstmt);
return -1;
}
// 新传送门
BOOL newdoor(char *name, struct DOOR_INFO info[30])
{
SQLHSTMT hstmt;
SQLHDBC hdbc;
BOOL retval;
SQLRETURN retcode;
char szSQL[8196];
int i;
char item[30][255];
hstmt = NULL;
memset( szSQL, 0x00, 8196);
for(i=0;i<30;i++)
{
sprintf(item[i], "%s - %d - %d - %d - %d", info[i].name, info[i].Code1, info[i].Code2, info[i].x, info[i].y);
}
sprintf(szSQL, "INSERT INTO TBL_DOOR_30 (FLD_CHAR_NAME, FLD_ITEM1, FLD_ITEM2, FLD_ITEM3, FLD_ITEM4, FLD_ITEM5, FLD_ITEM6, FLD_ITEM7, FLD_ITEM8, FLD_ITEM9, FLD_ITEM10, FLD_ITEM11, FLD_ITEM12, FLD_ITEM13, FLD_ITEM14, FLD_ITEM15, FLD_ITEM16, FLD_ITEM17, FLD_ITEM18, FLD_ITEM19, FLD_ITEM20, FLD_ITEM21, FLD_ITEM22, FLD_ITEM23, FLD_ITEM24, FLD_ITEM25, FLD_ITEM26, FLD_ITEM27, FLD_ITEM28, FLD_ITEM29, FLD_ITEM30) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
name, item[0], item[1], item[2], item[3], item[4], item[5], item[6], item[7], item[8], item[9],
item[10], item[11], item[12], item[13], item[14], item[15], item[16], item[17], item[18], item[19],
item[20], item[21], item[22], item[23], item[24], item[25], item[26], item[27], item[28], item[29]);
hdbc = connectDB(option.doordsn, option.dooruid, option.doorpwd); if (hdbc == NULL) return FALSE;
retcode = SQLAllocHandle((SQLSMALLINT)SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect(hstmt, (unsigned char *)szSQL, 8196);
if (retcode == SQL_SUCCESS)
{
retval = TRUE;
}
else
{
DisplayErrorMsg("newdoor", hstmt);
retval = FALSE;
}
}
else
retval = FALSE;
disconnectDB(hdbc, hstmt);
return retval;
}
BOOL newpublicwarehouse(char *id, long money, struct WAREHOUSE_INFO info[50])
{
SQLHSTMT hstmt;
SQLHDBC hdbc;
SQLRETURN retcode;
BOOL retval;
char szSQL[8196];
int i;
char item[50][255];
hstmt = NULL;
memset(szSQL, 0x00, 8196);
for(i=0;i<50;i++)
{
sprintf(item[i], "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d", info[i].code[0], info[i].code[1], info[i].code[2], info[i].code[3],
info[i].code[4], info[i].code[5], info[i].code[6], info[i].code[7], info[i].code[8], info[i].code[9], info[i].code[10],
info[i].code[11], info[i].code[12], info[i].code[13], info[i].code[14], info[i].code[15], info[i].code[16]);
}
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
sprintf(szSQL, "INSERT INTO TBL_PUBLIC (FLD_ID, FLD_MONEY, FLD_ITEM1, FLD_ITEM2, FLD_ITEM3, FLD_ITEM4, FLD_ITEM5, FLD_ITEM6, FLD_ITEM7, FLD_ITEM8, FLD_ITEM9, FLD_ITEM10, FLD_ITEM11, FLD_ITEM12, FLD_ITEM13, FLD_ITEM14, FLD_ITEM15, FLD_ITEM16, FLD_ITEM17, FLD_ITEM18, FLD_ITEM19, FLD_ITEM20, FLD_ITEM21, FLD_ITEM22, FLD_ITEM23, FLD_ITEM24, FLD_ITEM25, FLD_ITEM26, FLD_ITEM27, FLD_ITEM28, FLD_ITEM29, FLD_ITEM30, FLD_ITEM31, FLD_ITEM32, FLD_ITEM33, FLD_ITEM34, FLD_ITEM35, FLD_ITEM36, FLD_ITEM37, FLD_ITEM38, FLD_ITEM39, FLD_ITEM40, FLD_ITEM41, FLD_ITEM42, FLD_ITEM43, FLD_ITEM44, FLD_ITEM45, FLD_ITEM46, FLD_ITEM47, FLD_ITEM48, FLD_ITEM49, FLD_ITEM50) VALUES ('%s', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
id, money, item[0], item[1], item[2], item[3], item[4], item[5], item[6], item[7], item[8], item[9],
item[10], item[11], item[12], item[13], item[14], item[15], item[16], item[17], item[18], item[19],
item[20], item[21], item[22], item[23], item[24], item[25], item[26], item[27], item[28], item[29],
item[30], item[31], item[32], item[33], item[34], item[35], item[36], item[37], item[38], item[39],
item[40], item[41], item[42], item[43], item[44], item[45], item[46], item[47], item[48], item[49]);
hdbc = connectDB(option.warehousedsn, option.warehouseuid, option.warehousepwd); if (hdbc == NULL) return FALSE;
retcode = SQLAllocHandle((SQLSMALLINT)SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 8196);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
retval = TRUE;
}
else
{
DisplayErrorMsg("newpublicwarehouse", hstmt);
retval = FALSE;
}
}
else
retval = FALSE;
disconnectDB(hdbc, hstmt);
return retval;
}
BOOL newprivatewarehouse(char *name, long money, struct WAREHOUSE_INFO info[48])
{
SQLHSTMT hstmt;
SQLHDBC hdbc;
SQLRETURN retcode;
BOOL retval;
char szSQL[8196];
int i;
char item[48][255];
hstmt = NULL;
memset( szSQL, 0x00, 8196);
for(i=0;i<48;i++)
{
sprintf(item[i], "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d", info[i].code[0], info[i].code[1], info[i].code[2], info[i].code[3],
info[i].code[4], info[i].code[5], info[i].code[6], info[i].code[7], info[i].code[8], info[i].code[9], info[i].code[10],
info[i].code[11], info[i].code[12], info[i].code[13], info[i].code[14], info[i].code[15], info[i].code[16]);
}
sprintf(szSQL, "INSERT INTO TBL_PRIVATE (FLD_CHAR_NAME, FLD_MONEY, FLD_ITEM1, FLD_ITEM2, FLD_ITEM3, FLD_ITEM4, FLD_ITEM5, FLD_ITEM6, FLD_ITEM7, FLD_ITEM8, FLD_ITEM9, FLD_ITEM10, FLD_ITEM11, FLD_ITEM12, FLD_ITEM13, FLD_ITEM14, FLD_ITEM15, FLD_ITEM16, FLD_ITEM17, FLD_ITEM18, FLD_ITEM19, FLD_ITEM20,"
"FLD_ITEM21, FLD_ITEM22, FLD_ITEM23, FLD_ITEM24, FLD_ITEM25, FLD_ITEM26, FLD_ITEM27, FLD_ITEM28, FLD_ITEM29, FLD_ITEM30, FLD_ITEM31, FLD_ITEM32, FLD_ITEM33, FLD_ITEM34, FLD_ITEM35, FLD_ITEM36, FLD_ITEM37, FLD_ITEM38, FLD_ITEM39, FLD_ITEM40,"
"FLD_ITEM41, FLD_ITEM42, FLD_ITEM43, FLD_ITEM44, FLD_ITEM45, FLD_ITEM46, FLD_ITEM47, FLD_ITEM48) VALUES ('%s', '%d', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s',"
"'%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s')",
name, money, item[0], item[1], item[2], item[3], item[4], item[5], item[6], item[7], item[8], item[9],
item[10], item[11], item[12], item[13], item[14], item[15], item[16], item[17], item[18], item[19],
item[20], item[21], item[22], item[23], item[24], item[25], item[26], item[27], item[28], item[29],
item[30], item[31], item[32], item[33], item[34], item[35], item[36], item[37], item[38], item[39],
item[40], item[41], item[42], item[43], item[44], item[45], item[46], item[47]);
hdbc = connectDB(option.warehousedsn, option.warehouseuid, option.warehousepwd); if (hdbc == NULL) return FALSE;
retcode = SQLAllocHandle((SQLSMALLINT)SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect(hstmt, (unsigned char *)szSQL, 8196);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
retval = TRUE;
}
else
{
DisplayErrorMsg("newprivatewarhouse", hstmt);
retval = FALSE;
}
}
else
retval = FALSE;
disconnectDB(hdbc, hstmt);
return retval;
}
BOOL savedoor(char *name, struct DOOR_INFO info[30])
{
SQLHSTMT hstmt;
SQLHDBC hdbc;
SQLRETURN retcode;
char szSQL[8196];
int i;
BOOL retval;
char item[30][255];
retval = FALSE; hstmt = NULL;
memset(szSQL, 0x00, 8196);
for(i=0;i<30;i++)
{
sprintf(item[i], "%s - %d - %d - %d - %d", info[i].name, info[i].Code1, info[i].Code2, info[i].x, info[i].y);
}
sprintf(szSQL, "UPDATE TBL_DOOR_30 SET FLD_ITEM1='%s', FLD_ITEM2='%s', FLD_ITEM3='%s', FLD_ITEM4='%s', FLD_ITEM5='%s', FLD_ITEM6='%s', FLD_ITEM7='%s', FLD_ITEM8='%s', FLD_ITEM9='%s', FLD_ITEM10='%s', FLD_ITEM11='%s', FLD_ITEM12='%s', FLD_ITEM13='%s', FLD_ITEM14='%s', FLD_ITEM15='%s', FLD_ITEM16='%s', FLD_ITEM17='%s', FLD_ITEM18='%s', FLD_ITEM19='%s', FLD_ITEM20='%s', FLD_ITEM21='%s', FLD_ITEM22='%s', FLD_ITEM23='%s', FLD_ITEM24='%s', FLD_ITEM25='%s', FLD_ITEM26='%s', FLD_ITEM27='%s', FLD_ITEM28='%s', FLD_ITEM29='%s', FLD_ITEM30='%s' WHERE (FLD_CHAR_NAME = '%s')",
item[0], item[1], item[2], item[3], item[4], item[5], item[6], item[7], item[8], item[9],
item[10], item[11], item[12], item[13], item[14], item[15], item[16], item[17], item[18], item[19],
item[20], item[21], item[22], item[23], item[24], item[25], item[26], item[27], item[28], item[29], name);
hdbc = connectDB(option.doordsn, option.dooruid, option.doorpwd); if (hdbc == NULL) return FALSE;
retcode = SQLAllocHandle((SQLSMALLINT)SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 8196);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
retval = TRUE;
}
else
{
DisplayErrorMsg("savedoor", hstmt);
retval = FALSE;
}
}
else
retval = FALSE;
disconnectDB(hdbc, hstmt);
return retval;
}
BOOL saveprivatewarehouse(char *name, long money, struct WAREHOUSE_INFO info[48])
{
SQLHSTMT hstmt;
SQLHDBC hdbc;
SQLRETURN retcode;
char szSQL[8196];
int i;
BOOL retval;
char item[48][255];
retval = FALSE; hstmt = NULL;
memset( szSQL, 0x00, 8196);
for(i=0;i<48;i++)
{
sprintf(item[i], "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d", info[i].code[0], info[i].code[1], info[i].code[2], info[i].code[3],
info[i].code[4], info[i].code[5], info[i].code[6], info[i].code[7], info[i].code[8], info[i].code[9], info[i].code[10],
info[i].code[11], info[i].code[12], info[i].code[13], info[i].code[14], info[i].code[15], info[i].code[16]);
}
sprintf(szSQL, "UPDATE TBL_PRIVATE SET FLD_MONEY='%d', FLD_ITEM1='%s', FLD_ITEM2='%s', FLD_ITEM3='%s', FLD_ITEM4='%s', FLD_ITEM5='%s', FLD_ITEM6='%s', FLD_ITEM7='%s', FLD_ITEM8='%s', FLD_ITEM9='%s', FLD_ITEM10='%s', FLD_ITEM11='%s', FLD_ITEM12='%s', FLD_ITEM13='%s', FLD_ITEM14='%s', FLD_ITEM15='%s', FLD_ITEM16='%s', FLD_ITEM17='%s', FLD_ITEM18='%s', FLD_ITEM19='%s', FLD_ITEM20='%s', FLD_ITEM21='%s', FLD_ITEM22='%s', FLD_ITEM23='%s', FLD_ITEM24='%s', FLD_ITEM25='%s', FLD_ITEM26='%s', FLD_ITEM27='%s', FLD_ITEM28='%s', FLD_ITEM29='%s', FLD_ITEM30='%s', FLD_ITEM31='%s', FLD_ITEM32='%s', FLD_ITEM33='%s', FLD_ITEM34='%s', FLD_ITEM35='%s', FLD_ITEM36='%s', FLD_ITEM37='%s', FLD_ITEM38='%s', FLD_ITEM39='%s', FLD_ITEM40='%s', FLD_ITEM41='%s', FLD_ITEM42='%s', FLD_ITEM43='%s', FLD_ITEM44='%s', FLD_ITEM45='%s', FLD_ITEM46='%s', FLD_ITEM47='%s', FLD_ITEM48='%s' WHERE (FLD_CHAR_NAME = '%s')",
money, item[0], item[1], item[2], item[3], item[4], item[5], item[6], item[7], item[8], item[9],
item[10], item[11], item[12], item[13], item[14], item[15], item[16], item[17], item[18], item[19],
item[20], item[21], item[22], item[23], item[24], item[25], item[26], item[27], item[28], item[29],
item[30], item[31], item[32], item[33], item[34], item[35], item[36], item[37], item[38], item[39],
item[40], item[41], item[42], item[43], item[44], item[45], item[46], item[47], name);
hdbc = connectDB(option.warehousedsn, option.warehouseuid, option.warehousepwd); if (hdbc == NULL) return FALSE;
retcode = SQLAllocHandle((SQLSMALLINT)SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 8196);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
retval = TRUE;
}
else
{
DisplayErrorMsg("saveprivatewarehouse", hstmt);
retval = FALSE;
}
}
else
retval = FALSE;
disconnectDB(hdbc, hstmt);
return retval;
}
BOOL savepublicwarehouse(char *id, long money, struct WAREHOUSE_INFO info[50])
{
SQLHSTMT hstmt;
SQLHDBC hdbc;
SQLRETURN retcode;
BOOL retval;
char szSQL[8196];
int i;
char item[50][255];
hstmt = NULL;
memset( szSQL, 0x00, 8196);
for(i=0;i<50;i++)
{
sprintf(item[i], "%d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d - %d", info[i].code[0], info[i].code[1], info[i].code[2], info[i].code[3],
info[i].code[4], info[i].code[5], info[i].code[6], info[i].code[7], info[i].code[8], info[i].code[9], info[i].code[10],
info[i].code[11], info[i].code[12], info[i].code[13], info[i].code[14], info[i].code[15], info[i].code[16]);
}
sprintf(szSQL, "UPDATE TBL_PUBLIC SET FLD_MONEY='%d', FLD_ITEM1='%s', FLD_ITEM2='%s', FLD_ITEM3='%s', FLD_ITEM4='%s', FLD_ITEM5='%s', FLD_ITEM6='%s', FLD_ITEM7='%s', FLD_ITEM8='%s', FLD_ITEM9='%s', FLD_ITEM10='%s', FLD_ITEM11='%s', FLD_ITEM12='%s', FLD_ITEM13='%s', FLD_ITEM14='%s', FLD_ITEM15='%s', FLD_ITEM16='%s', FLD_ITEM17='%s', FLD_ITEM18='%s', FLD_ITEM19='%s', FLD_ITEM20='%s', FLD_ITEM21='%s', FLD_ITEM22='%s', FLD_ITEM23='%s', FLD_ITEM24='%s', FLD_ITEM25='%s', FLD_ITEM26='%s', FLD_ITEM27='%s', FLD_ITEM28='%s', FLD_ITEM29='%s', FLD_ITEM30='%s', FLD_ITEM31='%s', FLD_ITEM32='%s', FLD_ITEM33='%s', FLD_ITEM34='%s', FLD_ITEM35='%s', FLD_ITEM36='%s', FLD_ITEM37='%s', FLD_ITEM38='%s', FLD_ITEM39='%s', FLD_ITEM40='%s', FLD_ITEM41='%s', FLD_ITEM42='%s', FLD_ITEM43='%s', FLD_ITEM44='%s', FLD_ITEM45='%s', FLD_ITEM46='%s', FLD_ITEM47='%s', FLD_ITEM48='%s', FLD_ITEM49='%s', FLD_ITEM50='%s' WHERE (FLD_ID = '%s')",
money, item[0], item[1], item[2], item[3], item[4], item[5], item[6], item[7], item[8], item[9],
item[10], item[11], item[12], item[13], item[14], item[15], item[16], item[17], item[18], item[19],
item[20], item[21], item[22], item[23], item[24], item[25], item[26], item[27], item[28], item[29],
item[30], item[31], item[32], item[33], item[34], item[35], item[36], item[37], item[38], item[39],
item[40], item[41], item[42], item[43], item[44], item[45], item[46], item[47], item[48], item[49], id);
hdbc = connectDB(option.warehousedsn, option.warehouseuid, option.warehousepwd); if (hdbc == NULL) return FALSE;
retcode = SQLAllocHandle((SQLSMALLINT)SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 8196);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
retval = TRUE;
}
else
{
DisplayErrorMsg("savepublicwarehouse", hstmt);
retval = FALSE;
}
}
else
retval = FALSE;
disconnectDB(hdbc, hstmt);
return retval;
}
BOOL checkaccount(struct logindata *login, char* id, char* psd)
{
SQLHSTMT hstmt;
SQLHDBC hdbc;
SQLRETURN retcode;
BOOL bData, retval;
char szSQL[1024];
SQLINTEGER Indexind, nPoints;
memset( szSQL, 0x00, 1024 );
Indexind = SQL_NTS; nPoints = 0; bData = TRUE; retval = FALSE; hstmt = NULL;
// wsprintf(szSQL, TEXT("SELECT * FROM TBL_ACCOUNT WHERE FLD_ID='%s' AND FLD_PASSWORD='%s'"), id, psd);
sprintf(szSQL, "SELECT * FROM TBL_ACCOUNT WHERE FLD_ID='%s'", id);
hdbc = connectDB(option.accountdsn, option.accountuid, option.accountpwd); if (hdbc == NULL) return FALSE;
retcode = SQLAllocHandle((SQLSMALLINT)SQL_HANDLE_STMT, hdbc, &hstmt);
if (retcode == SQL_SUCCESS)
{
retcode = SQLExecDirect (hstmt, (unsigned char *)szSQL, 1024);
if (retcode == SQL_SUCCESS|| retcode == SQL_SUCCESS_WITH_INFO)
{
retcode = SQLFetch(hstmt);
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
SQLGetData(hstmt, 1, SQL_INTEGER, &login->vip, 0, &Indexind); //
SQLGetData(hstmt, 12, SQL_C_CHAR, login->idcard, 50, &Indexind); // 身份证
strcpy(login->id, id);
strcpy(login->password, psd);
retval = TRUE;
}
}
else
{
DisplayErrorMsg("checkaccount", hstmt);
retval = FALSE;
}
}
else
retval = FALSE;
disconnectDB(hdbc, hstmt);
return retval;
}
BOOL FAR PASCAL InitSQLEnvironment()
{
// Allocate an Environment Handle
if (SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &option.account_henv) != SQL_SUCCESS)
return FALSE;
if(SQLSetEnvAttr(option.account_henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER) != SQL_SUCCESS) return FALSE;
if (SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &option.char_henv) != SQL_SUCCESS)
return FALSE;
if(SQLSetEnvAttr(option.char_henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER) != SQL_SUCCESS) return FALSE;
if (SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &option.door_henv) != SQL_SUCCESS)
return FALSE;
if(SQLSetEnvAttr(option.door_henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER) != SQL_SUCCESS) return FALSE;
if (SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &option.warehouse_henv) != SQL_SUCCESS)
return FALSE;
if(SQLSetEnvAttr(option.warehouse_henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER) != SQL_SUCCESS) return FALSE;
if (SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &option.info_henv) != SQL_SUCCESS)
return FALSE;
if(SQLSetEnvAttr(option.info_henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER) != SQL_SUCCESS) return FALSE;
if (SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &option.lump_henv) != SQL_SUCCESS)
return FALSE;
if(SQLSetEnvAttr(option.lump_henv, SQL_ATTR_ODBC_VERSION,
(SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER) != SQL_SUCCESS) return FALSE;
return TRUE;
}
SQLHDBC connectDB(char dsn[24], char uid[24], char pwd[24])
{
SQLRETURN nResult;
SQLHENV henv;
SQLHDBC hdbc;
if (SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv) != SQL_SUCCESS)
return NULL;
if(SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_INTEGER) != SQL_SUCCESS) return NULL;
if ((nResult = SQLAllocHandle(SQL_HANDLE_DBC, henv, (SQLHDBC FAR *)&hdbc)) != SQL_SUCCESS)
{
// DisplayError(nResult, hWnd, SQL_HANDLE_ENV, henv);
return NULL;
}
nResult = SQLConnect(hdbc, (LPSTR)dsn, SQL_NTS, (LPSTR)uid, SQL_NTS,(LPSTR)pwd, SQL_NTS);
if (nResult != SQL_SUCCESS && nResult != SQL_SUCCESS_WITH_INFO)
{
// DisplayErrorMsg("connect", hWnd, SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
return NULL;
}
return hdbc;
}
void disconnectDB(SQLHDBC hdbc, SQLHSTMT hstmt)
{
SQLRETURN retcode;
if (hstmt != NULL)
{
retcode = SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
if (retcode != SQL_SUCCESS)
return;
}
if (hdbc != NULL)
{
retcode = SQLDisconnect(hdbc);
if (retcode != SQL_SUCCESS)
return;
}
if (hdbc != NULL)
{
retcode = SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
if (retcode != SQL_SUCCESS)
return;
}
/*
retcode = SQLFreeStmt(hstmt, SQL_DROP);
//*S调用SQLDisconnect函数关闭连接,例如:
retcode = SQLDisconnect(hdbc);
//*S调用SQLFreeConnect函数释放连接句柄及其相关的系统资源,例如:
retcode = SQLFreeConnect(hdbc);
//*S调用SQLFreeEnv函数释放环境句柄及其相关的系统资源,停止ODBC操作,例如:
// retcode = SQLFreeEnv(henv);
*/
}
BOOL FAR PASCAL ConnectDatabase()
{
SQLRETURN nResult; // Result code
if ((nResult = SQLAllocHandle(SQL_HANDLE_DBC, option.account_henv, (SQLHDBC FAR *)&option.account_hdbc)) != SQL_SUCCESS) {
// DisplayError(nResult, hWnd, SQL_HANDLE_ENV, henv);
return (FALSE);
}
nResult = SQLConnect(option.account_hdbc, (LPSTR)option.accountdsn, SQL_NTS, (LPSTR)option.accountuid, SQL_NTS,(LPSTR)option.accountpwd, SQL_NTS);
if (nResult != SQL_SUCCESS && nResult != SQL_SUCCESS_WITH_INFO) {
// DisplayError(nResult, hWnd, SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_DBC, option.account_hdbc);
return (FALSE);
}
if ((nResult = SQLAllocHandle(SQL_HANDLE_DBC, option.char_henv, (SQLHDBC FAR *)&option.char_hdbc)) != SQL_SUCCESS) {
// DisplayError(nResult, hWnd, SQL_HANDLE_ENV, henv);
return (FALSE);
}
nResult = SQLConnect(option.char_hdbc, (LPSTR)option.chardsn, SQL_NTS, (LPSTR)option.charuid, SQL_NTS,(LPSTR)option.charpwd, SQL_NTS);
if (nResult != SQL_SUCCESS && nResult != SQL_SUCCESS_WITH_INFO) {
// DisplayError(nResult, hWnd, SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_DBC, option.account_hdbc);
return (FALSE);
}
if ((nResult = SQLAllocHandle(SQL_HANDLE_DBC, option.door_henv, (SQLHDBC FAR *)&option.door_hdbc)) != SQL_SUCCESS) {
// DisplayError(nResult, hWnd, SQL_HANDLE_ENV, henv);
return (FALSE);
}
nResult = SQLConnect(option.door_hdbc, (LPSTR)option.doordsn, SQL_NTS, (LPSTR)option.dooruid, SQL_NTS,(LPSTR)option.doorpwd, SQL_NTS);
if (nResult != SQL_SUCCESS && nResult != SQL_SUCCESS_WITH_INFO) {
// DisplayError(nResult, hWnd, SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_DBC, option.door_hdbc);
return (FALSE);
}
if ((nResult = SQLAllocHandle(SQL_HANDLE_DBC, option.info_henv, (SQLHDBC FAR *)&option.info_hdbc)) != SQL_SUCCESS) {
// DisplayError(nResult, hWnd, SQL_HANDLE_ENV, henv);
return (FALSE);
}
nResult = SQLConnect(option.info_hdbc, (LPSTR)option.infodsn, SQL_NTS, (LPSTR)option.infouid, SQL_NTS,(LPSTR)option.infopwd, SQL_NTS);
if (nResult != SQL_SUCCESS && nResult != SQL_SUCCESS_WITH_INFO) {
// DisplayError(nResult, hWnd, SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_DBC, option.info_hdbc);
return (FALSE);
}
if ((nResult = SQLAllocHandle(SQL_HANDLE_DBC, option.warehouse_henv, (SQLHDBC FAR *)&option.warehouse_hdbc)) != SQL_SUCCESS) {
// DisplayError(nResult, hWnd, SQL_HANDLE_ENV, henv);
return (FALSE);
}
nResult = SQLConnect(option.warehouse_hdbc, (LPSTR)option.warehousedsn, SQL_NTS, (LPSTR)option.warehouseuid, SQL_NTS,(LPSTR)option.warehousepwd, SQL_NTS);
if (nResult != SQL_SUCCESS && nResult != SQL_SUCCESS_WITH_INFO) {
// DisplayError(nResult, hWnd, SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_DBC, option.warehouse_hdbc);
return (FALSE);
}
if ((nResult = SQLAllocHandle(SQL_HANDLE_DBC, option.lump_henv, (SQLHDBC FAR *)&option.lump_hdbc)) != SQL_SUCCESS) {
// DisplayError(nResult, hWnd, SQL_HANDLE_ENV, henv);
return (FALSE);
}
nResult = SQLConnect(option.lump_hdbc, (LPSTR)option.lumpdsn, SQL_NTS, (LPSTR)option.lumpuid, SQL_NTS,(LPSTR)option.lumppwd, SQL_NTS);
if (nResult != SQL_SUCCESS && nResult != SQL_SUCCESS_WITH_INFO) {
// DisplayError(nResult, hWnd, SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_DBC, option.lump_hdbc);
return (FALSE);
}
return TRUE;
}
void saveserveruser()
{
int i;
InsertLogMsg("正在保存用户数据");
for(i=0;i