//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "database.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TDataModule1 *DataModule1;
//---------------------------------------------------------------------------
__fastcall TDataModule1::TDataModule1(TComponent* Owner)
: TDataModule(Owner)
{
for(int i = 0; i < MAX_MENUSTYLE; ++i)
{
m_AllStyleGame[i].iCount = -1;
m_AllStyleGame[i].pGameInfo = NULL;
}
String QzMenuIni=ExtractFilePath( Application->ExeName )+"qzmenu.ini";
IniFile = new TIniFile(QzMenuIni);
if (1== IniFile->ReadInteger("app", "order", 0))
m_bOrder=true ;
else
m_bOrder=false;
ComputerName=GetJsjName();
falg=false;
InitShow();
}
//---------------------------------------------------------------------------
AnsiString __fastcall TDataModule1::GetJsjName()
{
AnsiString ret="";
char name[128];
memset( name, 0x00, 128 );
DWORD iLen=128;
GetComputerName( name, &iLen );
ret=AnsiString(name);
return ret;
}
//-----------------------------------------------------------------------------
//连接游戏数据库
void __fastcall TDataModule1::ConnMdb( void )
{
AnsiString DateFile = ExtractFilePath( Application->ExeName )+"data.mdb";
AnsiString Pwd = ";Jet OLEDB:Database Password =qznetwork2006";
AnsiString ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DateFile + Pwd + ";Mode=ReadWrite|Share Deny None";
try
{
Conn->Connected = false;
Conn->ConnectionString = (WideString)ConnStr;
Conn->Connected=true;
}
catch(...)
{
Application->MessageBoxA("连接指定数据库失败!", "错误", MB_OK|MB_ICONINFORMATION );
Application->Terminate();
}
}
//------------------------------------------------------------------------------
void __fastcall TDataModule1::InitShow( void )
{
ConnMdb(); //数据库连接
Query->SQL->Text = "select GOUPID from pc where PCNAME='"+ComputerName+"' and ISEXISTS=true";
Query->Open();
if( Query->RecordCount < 1 )
{
;
}
else
{
GoupId = Query->FieldByName( "GOUPID" )->AsInteger;
}
}
//------------------------------------------------------------------------------
void TDataModule1::LoadAllGame()
{
if(!falg)
{
falg=true;
AnsiString asGameName, asExeName, asIconPath, asGameExePath, asExtName;
String m_IconPath = ExtractFilePath( Application->ExeName ) + "icon\\";
bool bLocalRun = true;
for(int i = 0; i < MAX_MENUSTYLE ; ++i)
{
if(m_AllStyleGame[i].iCount == -1 && m_AllStyleGame[i].pGameInfo == NULL)
{
AnsiString str = "";
if(i == 0) //处理热门游戏
{
if( m_bOrder )
{
if( GoupId > 0 )
str = "select a.ID, GameName,EXENAME,b.RUNSTYLE,RUNCOUNT,PATH,gamestyle from game as a,goupgame as b "\
"where a.ID = b.GAMEID and goupid=(select GOUPID from pc where PCNAME='"+ComputerName+"' and ISEXISTS=true) and "\
"remark3='1' and isexists=true order by RUNCOUNT desc";
else
str = "select GAMENAME,EXENAME,RUNSTYLE,RUNCOUNT,PATH,gamestyle from game where remark3='1' and ISEXISTS=true order by RUNCOUNT desc";
}
else
{
if( GoupId > 0 )
str = "select a.ID, GameName,EXENAME,b.RUNSTYLE,RUNCOUNT,PATH,gamestyle from game as a,goupgame as b "\
"where a.ID = b.GAMEID and goupid=(select GOUPID from pc where PCNAME='"+
ComputerName+"' and ISEXISTS=true) and "\
"remark3='1' and isexists=true order by GAMENAME";
else
str = "select GAMENAME,EXENAME,RUNSTYLE,RUNCOUNT,PATH,gamestyle from game where remark3='1' and ISEXISTS=true order by GAMENAME";
}
}
else //处理正常游戏
{
if( m_bOrder )
{
if( GoupId > 0 )
str = "select a.ID, GameName,EXENAME,b.RUNSTYLE,RUNCOUNT,PATH,gamestyle from game as a,goupgame as b "\
"where a.ID = b.GAMEID and goupid=(select GOUPID from pc where PCNAME='"+ComputerName+"' and ISEXISTS=true) and "\
"gamestyle="+AnsiString(i)+" and isexists=true order by RUNCOUNT desc";
else
str = "select GAMENAME,EXENAME,RUNSTYLE,RUNCOUNT,PATH,gamestyle from game where GAMESTYLE="+AnsiString(i)+" and ISEXISTS=true order by RUNCOUNT desc";
}
else
{
if( GoupId > 0 )
str = "select a.ID, GameName,EXENAME,b.RUNSTYLE,RUNCOUNT,PATH,gamestyle from game as a,goupgame as b "\
"where a.ID = b.GAMEID and goupid=(select GOUPID from pc where PCNAME='"+
ComputerName+"' and ISEXISTS=true) and "\
"gamestyle="+AnsiString(i)+" and isexists=true order by GAMENAME";
else
str = "select GAMENAME,EXENAME,RUNSTYLE,RUNCOUNT,PATH,gamestyle from game where GAMESTYLE="+AnsiString(i)+" and ISEXISTS=true order by GAMENAME";
}
}
AllGame_Query->SQL->Text = str;
try
{
AllGame_Query->Open();
AllGame_Query->First();
}
catch(...)
{
continue;
}
m_AllStyleGame[i].iCount = AllGame_Query->RecordCount;
if(m_AllStyleGame[i].iCount <= 0)
{
continue;
}
m_AllStyleGame[i].pGameInfo = new GAMEINFO[ m_AllStyleGame[i].iCount ];
for( int iIndex = 0; !AllGame_Query->Eof; ++iIndex, AllGame_Query->Next() )
{
asGameName = AllGame_Query->FieldByName( "GAMENAME" )->AsString; //游戏名称
asExeName = AllGame_Query->FieldByName( "EXENAME" )->AsString;
asIconPath = m_IconPath + asGameName+".ico"; //ICO文件
if( GoupId > 0 )
{
switch( AllGame_Query->FieldByName("RUNSTYLE")->AsInteger )
{
case 0:
bLocalRun = false;
break;
case 1:
bLocalRun = true;
break;
default:
break;
}
}
else
{
bLocalRun = AllGame_Query->FieldByName("RUNSTYLE")->AsBoolean;
}
asGameExePath = AllGame_Query->FieldByName("PATH")->AsString + asExeName;
if( !FileExists( asIconPath ) )
{
asExtName = ExtractFileExt( asExeName ).UpperCase();
if( asExtName == ".BAT" )