1.
BOOL CDBPro::Init()
{
CString dir = GetModuleDir( ) + "\\cad_client.ini";
GetPrivateProfileString("DBRES", "SERVERIP", "", m_dbInfoRes.strip, sizeof(m_dbInfoRes.strip), dir );
GetPrivateProfileString("DBRES", "USERNAME", "", m_dbInfoRes.name, sizeof(m_dbInfoRes.name), dir ) ;
GetPrivateProfileString("DBRES", "USERPSWD", "", m_dbInfoRes.pswd, sizeof(m_dbInfoRes.pswd), dir ) ;
GetPrivateProfileString("DBRES", "DBNAME", "", m_dbInfoRes.db, sizeof(m_dbInfoRes.db), dir );
GetPrivateProfileString("DBRCD", "SERVERIP", "", m_dbInfoRcd.strip, sizeof(m_dbInfoRcd.strip), dir );
GetPrivateProfileString("DBRCD", "USERNAME", "", m_dbInfoRcd.name, sizeof(m_dbInfoRcd.name), dir ) ;
GetPrivateProfileString("DBRCD", "USERPSWD", "", m_dbInfoRcd.pswd, sizeof(m_dbInfoRcd.pswd), dir ) ;
GetPrivateProfileString("DBRCD", "DBNAME", "", m_dbInfoRcd.db, sizeof(m_dbInfoRcd.db), dir );
CString strLogin;
strLogin.Format("DRIVER=SQL Server;SERVER=%s;UID=%s;PWD=%s;DATABASE=%s", m_dbInfoRes.strip, m_dbInfoRes.name, m_dbInfoRes.pswd, m_dbInfoRes.db);
try
{
m_dbRes.OpenEx(strLogin, CDatabase::noOdbcDialog | CDatabase::useCursorLib);
}
catch(CException* e)
{
// e->ReportError();
e->Delete();
return FALSE;
}
strLogin.Format("DRIVER=SQL Server;SERVER=%s;UID=%s;PWD=%s;DATABASE=%s", m_dbInfoRcd.strip, m_dbInfoRcd.name, m_dbInfoRcd.pswd, m_dbInfoRcd.db);
try
{
m_dbRcd.OpenEx(strLogin, CDatabase::noOdbcDialog | CDatabase::useCursorLib);
}
catch(CException* e)
{
e->ReportError();
e->Delete();
return FALSE;
}
g_info.db = 1;
return TRUE;
}
2.
BOOL CCADClient4App::InitInstance()
{
bool CDBPro::CheckUser(CString strName, CString strPswd, int id)
{
CRecordset rs(&m_dbRes);
CString sql;
if(rs.IsOpen())
rs.Close();
sql.Format("select * from TUser where username='%s' and password='%s' and console_id=%d", strName, strPswd, id);
int nConID = 0;
try
{
rs.Open(CRecordset::forwardOnly, sql);
while(!rs.IsEOF())
{
CString strID = "";
rs.GetFieldValue("console_id",strID);
nConID = atoi(strID);
rs.MoveNext();
}
rs.Close();
}
catch(CDBException* e)
{
e->ReportError();
e->Delete();
return FALSE;
}
rs.Close();
return nConID!=0;
}
3.
void CDlgLogin::OnOK()
{
if( ! g_dbPro.CheckUser( m_strName, m_strPwd, pCons->id ) )
{
MessageBox("登录用户信息和调度台不匹配","系统提示",MB_OK|MB_ICONWARNING);
return;
}
memcpy(&g_conRes, pCons, sizeof(stDBTconRes));
g_strUser = m_strName;
sprintf(m_name, "%s", m_strName );
SaveConfig( GetModuleDir()+"\\user.dat" );
CDialog::OnOK();
}
}
BOOL CDBPro::Init()
{
CString dir = GetModuleDir( ) + "\\cad_client.ini";
GetPrivateProfileString("DBRES", "SERVERIP", "", m_dbInfoRes.strip, sizeof(m_dbInfoRes.strip), dir );
GetPrivateProfileString("DBRES", "USERNAME", "", m_dbInfoRes.name, sizeof(m_dbInfoRes.name), dir ) ;
GetPrivateProfileString("DBRES", "USERPSWD", "", m_dbInfoRes.pswd, sizeof(m_dbInfoRes.pswd), dir ) ;
GetPrivateProfileString("DBRES", "DBNAME", "", m_dbInfoRes.db, sizeof(m_dbInfoRes.db), dir );
GetPrivateProfileString("DBRCD", "SERVERIP", "", m_dbInfoRcd.strip, sizeof(m_dbInfoRcd.strip), dir );
GetPrivateProfileString("DBRCD", "USERNAME", "", m_dbInfoRcd.name, sizeof(m_dbInfoRcd.name), dir ) ;
GetPrivateProfileString("DBRCD", "USERPSWD", "", m_dbInfoRcd.pswd, sizeof(m_dbInfoRcd.pswd), dir ) ;
GetPrivateProfileString("DBRCD", "DBNAME", "", m_dbInfoRcd.db, sizeof(m_dbInfoRcd.db), dir );
CString strLogin;
strLogin.Format("DRIVER=SQL Server;SERVER=%s;UID=%s;PWD=%s;DATABASE=%s", m_dbInfoRes.strip, m_dbInfoRes.name, m_dbInfoRes.pswd, m_dbInfoRes.db);
try
{
m_dbRes.OpenEx(strLogin, CDatabase::noOdbcDialog | CDatabase::useCursorLib);
}
catch(CException* e)
{
// e->ReportError();
e->Delete();
return FALSE;
}
strLogin.Format("DRIVER=SQL Server;SERVER=%s;UID=%s;PWD=%s;DATABASE=%s", m_dbInfoRcd.strip, m_dbInfoRcd.name, m_dbInfoRcd.pswd, m_dbInfoRcd.db);
try
{
m_dbRcd.OpenEx(strLogin, CDatabase::noOdbcDialog | CDatabase::useCursorLib);
}
catch(CException* e)
{
e->ReportError();
e->Delete();
return FALSE;
}
g_info.db = 1;
return TRUE;
}
2.
BOOL CCADClient4App::InitInstance()
{
bool CDBPro::CheckUser(CString strName, CString strPswd, int id)
{
CRecordset rs(&m_dbRes);
CString sql;
if(rs.IsOpen())
rs.Close();
sql.Format("select * from TUser where username='%s' and password='%s' and console_id=%d", strName, strPswd, id);
int nConID = 0;
try
{
rs.Open(CRecordset::forwardOnly, sql);
while(!rs.IsEOF())
{
CString strID = "";
rs.GetFieldValue("console_id",strID);
nConID = atoi(strID);
rs.MoveNext();
}
rs.Close();
}
catch(CDBException* e)
{
e->ReportError();
e->Delete();
return FALSE;
}
rs.Close();
return nConID!=0;
}
3.
void CDlgLogin::OnOK()
{
if( ! g_dbPro.CheckUser( m_strName, m_strPwd, pCons->id ) )
{
MessageBox("登录用户信息和调度台不匹配","系统提示",MB_OK|MB_ICONWARNING);
return;
}
memcpy(&g_conRes, pCons, sizeof(stDBTconRes));
g_strUser = m_strName;
sprintf(m_name, "%s", m_strName );
SaveConfig( GetModuleDir()+"\\user.dat" );
CDialog::OnOK();
}
}