📄 clientmain.cpp
字号:
// clientMain.cpp : Defines the class behaviors for the application.
//
#include "stdafx.h"
#include "clientMain.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "SChildFrm.h"
#include "FChildFrm.h"
//#include "clientMainDoc.h"
#include "clientMainView.h"
#include "ClientFinanceView.h"
#include "ClientSellView.h"
//#include "Server_dbPos.h"
#include "SellMaterialView.h"
#include "BuyMaterialView.h"
#include "ManageUserView.h"
#include "InitDlg.h"
#include "SysLogInDlg.h"
#include "Splash.h"
#include <string>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
using namespace std;
//const GUID LIBID_SERVER_DBPOSLib =
// {0x44433dd3,0x7385,0x4d3d,{0x80,0x42,0xd8,0xbb,0xe2,0xc7,0xc9,0x0b}};
//const CLSID CLSID_ADO_Server =
// {0x7b99f55b,0x475f,0x42d7,{0xbe,0xa8,0xce,0xdf,0x38,0x5f,0xf8,0x6e}};
//const IID IID_IADO_Server =
// {0xccac3e1c,0xfd78,0x41a4,{0x82,0x23,0x93,0x96,0x90,0xf7,0x13,0x4c}};
/////////////////////////////////////////////////////////////////////////////
// CClientMainApp
BEGIN_MESSAGE_MAP(CClientMainApp, CWinApp)
//{{AFX_MSG_MAP(CClientMainApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CClientMainApp construction
CClientMainApp::CClientMainApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CClientMainApp object
CClientMainApp theApp;
CString g_strUserName;
CString g_strUserPsw;
CString g_strUserType;
User_Type g_tUserType;
/////////////////////////////////////////////////////////////////////////////
// CClientMainApp initialization
BOOL CClientMainApp::InitInstance()
{
// CG: The following block was added by the Splash Screen component. //{ //CCommandLineInfo cmdInfo;
//ParseCommandLine(cmdInfo); //CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);
AfxEnableControlContainer();
CSplashWnd *m_pSplashWnd = new CSplashWnd();
m_pSplashWnd->Create();
m_pSplashWnd->UpdateWindow();
//m_pSplashWnd->ShowSplashScreen();
//}
if (!AfxSocketInit())
{
AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
delete m_pSplashWnd;
return FALSE;
}
// 连接COM服务器
HRESULT hr;
hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
long lResult; // 操作注册表函数的返回值
HKEY lKey; // 定义一个键的句柄,用来存储被打开的键
DWORD lType;
DWORD lDataLen = 256;
// 调用对话框的变量
int InitRet;
CInitDlg InitDlg;
char *vComServer = new char[256];
char *vDBServer = new char[256];
char *vDBName = new char[256];
char *vDBUser = new char[256];
char *vDBPsw = new char[256];
lResult = RegOpenKeyEx(MAINKEY, LPCSTR(SUBKEY), 0, KEY_READ, &lKey);
if(ERROR_SUCCESS != lResult)
{
InitRet = InitDlg.DoModal();
switch(InitRet)
{
case -1:
MessageBox(NULL,"对话框创建失败!","Client Error:", MB_OK);
delete [] vDBServer;
delete [] vComServer;
delete [] vDBName;
delete [] vDBUser;
delete [] vDBPsw;
delete m_pSplashWnd;
return FALSE;
break;
case IDCANCEL:
delete [] vDBServer;
delete [] vComServer;
delete [] vDBName;
delete [] vDBUser;
delete [] vDBPsw;
delete m_pSplashWnd;
return FALSE;
break;
case IDOK:
m_strComServer = InitDlg.m_strComServer;
m_strDBServer = InitDlg.m_strDbServer;
m_strDBName = InitDlg.m_strDbName;
m_strDBUser = InitDlg.m_strDbUser;
m_strDBPsw = InitDlg.m_strDbPsw;
m_pSplashWnd->UpdateWindow();
break;
default:
// Do something
break;
}
}
else
{
RegQueryValueEx(lKey, "Com_Server", 0, &lType, (LPBYTE)vComServer, &lDataLen);
lDataLen = 256;
RegQueryValueEx(lKey, "DB_Server", 0, &lType, (LPBYTE)vDBServer, &lDataLen);
lDataLen = 256;
RegQueryValueEx(lKey, "DB_Name", 0, &lType, (LPBYTE)vDBName, &lDataLen);
lDataLen = 256;
RegQueryValueEx(lKey, "DB_User", 0, &lType, (LPBYTE)vDBUser, &lDataLen);
lDataLen = 256;
RegQueryValueEx(lKey, "DB_Psw", 0, &lType, (LPBYTE)vDBPsw, &lDataLen);
m_strComServer = vComServer;
m_strDBServer = vDBServer;
m_strDBName = vDBName;
m_strDBUser = vDBUser;
m_strDBPsw = vDBPsw;
}
lResult = RegCloseKey(lKey);
BOOL blnInit = InitAdoServer();
while(!blnInit)
{
InitRet = InitDlg.DoModal();
switch(InitRet)
{
case -1:
MessageBox(NULL,"对话框创建失败!","Client Error:", MB_OK);
delete [] vDBServer;
delete [] vComServer;
delete [] vDBName;
delete [] vDBUser;
delete [] vDBPsw;
delete m_pSplashWnd;
return FALSE;
break;
case IDCANCEL:
delete [] vDBServer;
delete [] vComServer;
delete [] vDBName;
delete [] vDBUser;
delete [] vDBPsw;
delete m_pSplashWnd;
return FALSE;
break;
case IDOK:
m_strComServer = InitDlg.m_strComServer;
m_strDBServer = InitDlg.m_strDbServer;
m_strDBName = InitDlg.m_strDbName;
m_strDBUser = InitDlg.m_strDbUser;
m_strDBPsw = InitDlg.m_strDbPsw;
m_pSplashWnd->UpdateWindow();
blnInit = InitAdoServer();
break;
default:
// Do something
break;
}
}
delete [] vDBServer;
delete [] vComServer;
delete [] vDBName;
delete [] vDBUser;
delete [] vDBPsw;
// 启动登录窗口
int nRet = -1;
CSysLogInDlg logDlg;
nRet = logDlg.DoModal();
switch(nRet)
{
case -1:
MessageBox(NULL,"对话框创建失败!","Client Error:", MB_OK);
delete m_pSplashWnd;
return FALSE;
break;
case IDCANCEL:
delete m_pSplashWnd;
return FALSE;
break;
case IDOK:
// 根据不同的用户类型,为枚举变量赋值
if(g_strUserType == "system")
{
g_tUserType = Adm_All;
}
if(g_strUserType == "finance")
{
g_tUserType = Finance;
}
if(g_strUserType == "material")
{
g_tUserType = Material;
}
if(g_strUserType == "sell")
{
g_tUserType = Sell;
}
break;
default:
// Do something
break;
}
//MessageBox(NULL,g_strUserType,"1", MB_OK);
// 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
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
// 利用成员变量来存储文档模板指针
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -