123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394 |
- /****************************************************************/
- /* */
- /* DBServerApp.cpp */
- /* */
- /* Defines the class behaviors for the application. */
- /* */
- /* Programmed by LYFZ van der Meer */
- /* Copyright LYFZ Software Solutions 2002 */
- /* http://www.LYFZvandermeer.nl */
- /* */
- /* Last updated: 10 july 2002 */
- /* */
- /****************************************************************/
- #include "stdafx.h"
- #include "DBServer.h"
- #include "DBServerDlg.h"
- #include "theDBServer.h"
- #include "MyLock.h"
- #include "mysqldata.h"
- //#include "Def.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- BEGIN_MESSAGE_MAP(CDBServer, CWinApp)
- //{{AFX_MSG_MAP(CDBServer)
- ON_COMMAND(ID_APP_SHOW, OnAppShow)
- ON_COMMAND(ID_APP_EXIT, OnAppExit)
- ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
- ON_COMMAND(ID_HELP_INDEX, OnHelpIndex)
- //}}AFX_MSG_MAP
- ON_COMMAND(ID_HELP, CWinApp::OnHelp)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDBServer construction
- CDBServer::CDBServer()
- {
- // TODO: add construction code here,
- // Place all significant initialization in InitInstance
- }
- /////////////////////////////////////////////////////////////////////////////
- // The one and only CDBServer object
- CDBServer theApp;
- CtheDBServer theServer;
- /////////////////////////////////////////////////////////////////////////////
- // CDBServer initialization
- BOOL CDBServer::InitInstance()
- {
- // 1.只运行单实例;
- HANDLE hObject = CreateMutex(NULL,FALSE,_T("CDBServerXiao"));
- if(GetLastError() == ERROR_ALREADY_EXISTS)
- {
- return false;
- }
- // 2.配置数据库连接信息;
- char server[50];
- DWORD leng=50;
- memset(server, 0, 50);
- ::GetComputerName(server, &leng);
- g_localname = server;
-
- TCHAR szDir[MAX_PATH];
- ::GetModuleFileName(NULL, szDir, MAX_PATH);
- g_mainpath = szDir;
- g_mainpath = g_mainpath.Left (g_mainpath.ReverseFind ('\\'));
- if( GetIniInfo() == -1)
- {
- WriteTextLog("未找到配置文件:ServiceInfo.ini");
- return FALSE;
- }
- g_strdbpsw.Format("uid=%s;pwd=%s",g_szDBAccount,g_szDBPassWord);
- if ( g_dwDBServerPort != 0 )
- g_strdbServrename.Format("%s,%d",g_szDBSource,g_dwDBServerPort);
- else
- g_strdbServrename.Format("%s",g_szDBSource);
-
- WriteTextLog("启动");
-
- CString savedir=g_mainpath+"\\数据备份";
- if(!CheckFolderFileExist (savedir))
- ::CreateDirectory (savedir, NULL);
-
- ::CoInitialize( NULL );
-
- BOOL bMasterDb=0;
- BOOL bUserDb=0;
-
- // 4.连接master数据库,判断数据库连接是否正常;
- CDatabase g_masterdb; // Jeff:master用于附加与分离数据库;
- try
- {
- #if 0
- CString strCon;
- strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=master;%s"),g_strdbServrename,g_strdbpsw);//Jeff.使用可配置数据库信息方式;
- g_masterdb.OpenEx(strCon,CDatabase::noOdbcDialog);
- #else
- TCHAR szConnectString[MAX_PATH] = _T("");
- if( g_dwDBServerPort != 0)
- sprintf(szConnectString,
- "driver={SQL Server};Server=%s,%d;database=master;uid=%s;pwd=%s",
- g_szDBSource,g_dwDBServerPort,g_szDBAccount,g_szDBPassWord);
- else
- sprintf(szConnectString,
- "driver={SQL Server};Server=%s;database=master;uid=%s;pwd=%s",
- g_szDBSource,g_szDBAccount,g_szDBPassWord);
- g_masterdb.OpenEx(szConnectString,CDatabase::noOdbcDialog);
- #endif
- bMasterDb=1;
- }
- catch(CDBException * e)
- {
- e->Delete();
- }
-
- if(bMasterDb==0)
- {
- WriteTextLog("sql数据库未启动!");
- ShellExecute(NULL, _T("open"), g_mainpath+"\\AutoRun.exe", NULL, NULL, SW_HIDE);
- return false;
- }
-
- try
- {
- // 5.连接db数据库;
-
- #if 0
- CString strCon;
- strCon.Format(_T("driver={SQL Server};Server=%s;DATABASE=db;%s"),g_strdbServrename,g_strdbpsw);
- g_db.OpenEx(strCon,CDatabase::noOdbcDialog);
- #else
- if( g_dwDBServerPort != 0)
- sprintf(g_szConnectString,"driver={SQL Server};Server=%s,%d;database=%s;uid=%s;pwd=%s",
- g_szDBSource,g_dwDBServerPort,g_szDBName,g_szDBAccount,g_szDBPassWord);
- else
- sprintf(g_szConnectString,"driver={SQL Server};Server=%s;database=%s;uid=%s;pwd=%s",
- g_szDBSource,g_szDBName,g_szDBAccount,g_szDBPassWord);
- g_db.OpenEx(g_szConnectString,CDatabase::noOdbcDialog);
- #endif
- bUserDb=1;
- g_curdb=&g_db;
-
- // 6.
- BakData(savedir, 1, 0); // Jeff. savedir=\\数据备份
- g_masterdb.Close();
-
- CString sql;
- sql="create table [historydb]([year] varchar(50))";
- g_db.ExecuteSQL (sql);
- }
- catch(CDBException * e)
- {
- /* AfxMessageBox(e->m_strError);
- e->Delete();
- WriteLogin("sql数据库打开失败!");
- return false;*/
- e->Delete();
- }
-
- if(bUserDb==0 && bMasterDb)
- {
- CString autorunpath=g_mainpath+"\\AutoRun.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- WriteTextLog("数据库初始化中...");
- #if 0 // Jeff.deal
- if(::PathFileExists(g_mainpath+"\\数据\\db.mdf")==0 )
- #else
- TCHAR szDBFile[MAX_PATH] = _T("");
- sprintf(szDBFile,"%s\\数据\\%s.mdf",g_mainpath,g_szDBName);
- if(::PathFileExists(szDBFile) == 0 )
- #endif
- {
- WriteTextLog("数据库文件丢失!");
- return false;
- }
- BOOL bLog=0;
- #if 0
- if( ::PathFileExists(g_mainpath+"\\数据\\db_log.LDF"))
- #else
- TCHAR szDBLogFile[MAX_PATH] = _T("");
- sprintf(szDBLogFile,"%s\\数据\\%s_log.ldf",g_mainpath,g_szDBName);
- if(::PathFileExists(szDBLogFile) == 0 )
- #endif
- {
- bLog=1;
- }
- CString sql;
- try
- {
- // g_masterdb.ExecuteSQL ("exec sp_detach_db db");
- }
- catch(CDBException * e)
- {
- // WriteLogin(e->m_strError+"xxx");
- e->Delete();
- }
- #if 0 // Jeff.deal
- if(bLog) sql.Format("exec sp_attach_db 'db',@filename1='%s',@filename2='%s'", g_mainpath+"\\数据\\db.mdf", g_mainpath+"\\数据\\db_log.LDF");
- else sql.Format("exec sp_attach_db 'db',@filename1='%s'", g_mainpath+"\\数据\\db.mdf");
- #else
- if(bLog)
- sql.Format("exec sp_attach_db '%s',@filename1='%s\\数据\\%s.mdf',@filename2='%s\\数据\\%s_log.ldf'",g_szDBName,g_ModulePath,g_szDBName,g_ModulePath,g_szDBName);
- else
- sql.Format("exec sp_attach_db '%s',@filename1='%s\\数据\\%s.mdf'", g_szDBName,g_ModulePath,g_szDBName);
- #endif
- try
- {
- g_masterdb.ExecuteSQL (sql); // 同master数据库去执行附加和分离;
- }
- catch(CDBException * e)
- {
- g_masterdb.Close();
- WriteTextLog(e->m_strError);
- WriteTextLog("数据库初始化失败!");
- e->Delete();
- return false;
- }
- g_masterdb.Close();
- WriteTextLog("数据库初始化完成,请重新启动系统!");
- return false;
- }
-
- /* int nResult = Transport_Init();
- if( TRANSPORT_OK != nResult)
- {
- WriteLogin("网络初始化失败!");
- return 0;
- }*/
-
- #if 1
- // Jeff.在数据库完成初始化后,判断本地目录下是否有MSCHRT20.OCX文件,无则从数据库下载;2014.09.06
- // 客户端从dwToUserID==211里传递MSCHRT20.OCX;
- CString strMSCHRTOCX = g_mainpath+"\\系统文件\\MSCHRT20.OCX";
-
- OFSTRUCT ofStruct;
- OpenFile(strMSCHRTOCX,&ofStruct,OF_EXIST);
- if( ERROR_FILE_NOT_FOUND == GetLastError())
- {
- CRstUpdate rsSt;
- rsSt.m_pDatabase = &g_db;
- rsSt.Open();
- if(!rsSt.IsEOF())
- {
- CFile fp;
- if(fp.Open(strMSCHRTOCX, CFile::modeCreate|CFile::modeWrite))
- {
- void *pData = GlobalLock(rsSt.m_lbOCX.m_hData);
- fp.Write(pData, rsSt.m_lbOCX.m_dwDataLength);
- fp.Close();
- GlobalUnlock(rsSt.m_lbOCX.m_hData);
- }
- }
- rsSt.Close();
- }
- #endif
- ULONG_PTR gdiplusToken;
- GdiplusStartupInput gdiplusStartupInput;
- GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);
-
- CString path1="客户原片(管理软件)$";
- CString path2="修好的片(管理软件)$";
- CString path3="设计好的片(管理软件)$";
- CString path4="精修好的片(管理软件)$";
- CString path5="礼服图片(管理软件)$";
- CString path6="电话录音(管理软件)$";
- CString temp;
- if(CheckFolderFileExist (g_mainpath+"\\"+path1))
- {
- temp.Format ("net share %s=%s\\%s", path1, g_mainpath, path1);
- WinExec(temp,SW_HIDE);
- }
-
- if(CheckFolderFileExist (g_mainpath+"\\"+path2))
- {
- temp.Format ("net share %s=%s\\%s", path2, g_mainpath, path2);
- WinExec(temp,SW_HIDE);
- }
-
- if(CheckFolderFileExist (g_mainpath+"\\"+path3))
- {
- temp.Format ("net share %s=%s\\%s", path3, g_mainpath, path3);
- WinExec(temp,SW_HIDE);
- }
-
- if(CheckFolderFileExist (g_mainpath+"\\"+path4))
- {
- temp.Format ("net share %s=%s\\%s", path4, g_mainpath, path4);
- WinExec(temp,SW_HIDE);
- }
-
- if(CheckFolderFileExist (g_mainpath+"\\"+path5))
- {
- temp.Format ("net share %s=%s\\%s", path5, g_mainpath, path5);
- WinExec(temp,SW_HIDE);
- }
- if(CheckFolderFileExist (g_mainpath+"\\"+path6))
- {
- temp.Format ("net share %s=%s\\%s", path6, g_mainpath, path6);
- WinExec(temp,SW_HIDE);
- }
-
- CString autorunpath=g_mainpath+"\\AutoRun.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
-
- #ifdef ENTERPRISE_VERSION
- autorunpath=g_mainpath+"\\DataSyncReceive.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- autorunpath=g_mainpath+"\\DataSyncSend.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- autorunpath=g_mainpath+"\\CPhotoFTPReceive.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- autorunpath=g_mainpath+"\\CPhotoFTPSend.exe";
- ShellExecute(NULL, _T("open"), autorunpath, NULL, NULL, SW_HIDE);
- #endif
-
- // Standard initialization
- // If you are not using these features and wish to reduce the size
- // of your final executable, you should remove from the following
- // the specific initialization routines you do not need.
-
- #ifdef _AFXDLL
- Enable3dControls(); // Call this when using MFC in a shared DLL
- #else
- Enable3dControlsStatic(); // Call this when linking to MFC statically
- #endif
-
- InitCommonControls();
-
- CDBServerDlg dlg;
- m_pMainWnd = &dlg;
- int nResponse = dlg.DoModal();
- if (nResponse == IDOK)
- {
- }
- else if (nResponse == IDCANCEL)
- {
- }
- // Transport_UnInit();
-
- GdiplusShutdown(gdiplusToken);
- return FALSE;
- }
- void CDBServer::OnAppShow()
- {
- if (m_pMainWnd)
- m_pMainWnd->ShowWindow(SW_SHOW);
- }
- void CDBServer::OnAppExit()
- {
- m_pMainWnd->DestroyWindow();
- }
- void CDBServer::OnAppAbout()
- {
- }
- /********************************************************************/
- /* */
- /* Function name : OnHelpIndex */
- /* Description : Command to show help file. */
- /* */
- /********************************************************************/
- void CDBServer::OnHelpIndex()
- {
- // launch help
- // ::WinHelp(AfxGetMainWnd()->m_hWnd, AfxGetApp()->m_pszHelpFilePath, HELP_CONTENTS, 0L);
- }
|