⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clientmain.cpp

📁 客户端服务器源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	m_pMTemplate = new CMultiDocTemplate(
		IDR_CLIENTMATERIAL_TYPE,
		RUNTIME_CLASS(CClientMainDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CClientMainView));
	AddDocTemplate(m_pMTemplate);

	m_pSTemplate = new CMultiDocTemplate(
		IDR_CLIENTSELL_TYPE,
		RUNTIME_CLASS(CClientMainDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CClientSellView));
	AddDocTemplate(m_pSTemplate);

	m_pFTemplate = new CMultiDocTemplate(
		IDR_CLIENTFINANCE_TYPE,
		RUNTIME_CLASS(CClientMainDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CClientFinanceView));
	AddDocTemplate(m_pFTemplate);

	m_pMSellTemplate = new CMultiDocTemplate(
		IDR_MATERIAL_SELL,
		RUNTIME_CLASS(CClientMainDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CSellMaterialView));
	AddDocTemplate(m_pMSellTemplate);

	m_pMBuyTemplate = new CMultiDocTemplate(
		IDR_MATERIAL_BUY,
		RUNTIME_CLASS(CClientMainDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CBuyMaterialView));
	AddDocTemplate(m_pMBuyTemplate);

	m_pUserTemplate = new CMultiDocTemplate(
		IDR_USER_MANAGE,
		RUNTIME_CLASS(CClientMainDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CManageUserView));
	AddDocTemplate(m_pUserTemplate);

	// create main MDI Frame window
	CMainFrame* pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
	{
		delete m_pSplashWnd;
		return FALSE;
	}
	m_pMainWnd = pMainFrame;

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	// 添加如下代码,用来防止程序启动时候打开新的空文档
	cmdInfo.m_nShellCommand  = CCommandLineInfo::FileNothing;

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
	{
		delete m_pSplashWnd;
		return FALSE;
	}

	// 在此处理界面的具体显示情况,包括菜单等
	CMenu *pMainMenu = pMainFrame->GetMenu();
	
	if(g_tUserType != Adm_All)
	{
		// 菜单项的序号是自动调整的,因此在删除某些不需要的菜单项时,需要注意。
		// 下面这个代码块,比较好的保证了根据不同的登录用户枚举值,显示不同的菜单	
		//  这段代码要求:菜单的序号要与登录用户的枚举值一一相符合
		
		int i,nType,nMenuCount;
		nType = (int)g_tUserType;
		nMenuCount = (int)Adm_All - 1;

		for(i = 0; i<= nMenuCount; i++)
		{
			pMainMenu->GetSubMenu(3)->RemoveMenu(IDS_USER_MODIFY, MF_BYCOMMAND);

			if(nType == 0)
			{
				pMainMenu->RemoveMenu(nType+1, MF_BYPOSITION);
			}
			if((nType != 0) && (nType > i))
			{
				pMainMenu->RemoveMenu(i, MF_BYPOSITION);
				nType--;
			}
			if((nType != 0) && (nType == i))
			{
				pMainMenu->RemoveMenu(0, MF_BYPOSITION);
				nType--;
			}
			nMenuCount--;
		}
	}
	
	// The main window has been initialized, so show and update it.
	pMainFrame->SetWindowText("物资管理系统");
	m_nCmdShow = SW_SHOWMAXIMIZED;
	pMainFrame->ShowWindow(m_nCmdShow);
	pMainFrame->UpdateWindow();

	//m_pSplashWnd->HideSplashScreen();
	delete m_pSplashWnd;
//	CSplashWnd::HideSplashScreen();
	return TRUE;
}


BOOL CClientMainApp::InitAdoServer()
{
	HRESULT			hr;

	COSERVERINFO ServerInfo;	
	MULTI_QI MultiQI;		

	//***********************************
	//char* pszName= new char[255];
    //char* pszDomain = new char[255];
	//char* pszPassword = new char[255];

	//pszName = "Administrator";
	//pszDomain= "";//"WORKGROUP";
	//pszPassword = "gxp!@)";

	//COSERVERINFO serverInfo;
	ZeroMemory(&ServerInfo, sizeof(COSERVERINFO));

//	COAUTHINFO athn;
//	ZeroMemory(&athn, sizeof(COAUTHINFO));

	//COAUTHIDENTITY author_id;
	//ZeroMemory(&author_id, sizeof(COAUTHIDENTITY));

	//author_id.Flags = SEC_WINNT_AUTH_IDENTITY_ANSI ;
	//author_id.User = reinterpret_cast<unsigned short*>(pszName);
	//author_id.UserLength = strlen(pszName);
	//author_id.Domain = reinterpret_cast<unsigned short*>(pszDomain);
	//author_id.DomainLength = strlen(pszDomain);
	//author_id.Password = reinterpret_cast<unsigned short*>(pszPassword);
	//author_id.PasswordLength = strlen(pszPassword);


	// Set up the NULL security information
/*	athn.dwAuthnLevel = RPC_C_AUTHN_LEVEL_NONE;
	athn.dwAuthnSvc = RPC_C_AUTHN_WINNT;
	athn.dwAuthzSvc = RPC_C_AUTHZ_NONE;
	athn.dwCapabilities = EOAC_NONE;
	athn.dwImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE;
	athn.pAuthIdentityData = NULL; //&author_id;
	athn.pwszServerPrincName = NULL;
*/
	//CString	strU = "\\";
	//m_strComServer = strU + m_strComServer;

	_bstr_t szName(m_strComServer); // 注意数据类型
	ServerInfo.pwszName = szName;//L"GUOXP";//"\\\\Viz-06";
	ServerInfo.pAuthInfo = NULL;//&athn;
	ServerInfo.dwReserved1 = 0;
	ServerInfo.dwReserved2 = 0;
	//**************************************************

	//  old
//	ServerInfo.dwReserved1 = 0;	ServerInfo.dwReserved2 = 0;	ServerInfo.pAuthInfo = NULL;
//	ServerInfo.pwszName = L"GUOXP"; // L"\\\\GXP";//L"192.168.0.53";  (IADOTier);//

	MultiQI.hr = NOERROR;	MultiQI.pItf = NULL;	MultiQI.pIID = &__uuidof(IPos_ADO);
	
	//hr = CoCreateInstanceEx( CLSID_ADO_Server, NULL, CLSCTX_SERVER, &ServerInfo, 1, &MultiQI);
	hr = CoCreateInstanceEx( __uuidof(CPos_ADO), NULL, CLSCTX_SERVER, &ServerInfo, 1, &MultiQI);
	//hr = CoCreateInstanceEx( __uuidof(CADOTier), NULL, CLSCTX_SERVER, &ServerInfo, 1, &MultiQI);
	
	if(SUCCEEDED(hr))
	{
		g_pAdoServer = (IPos_ADO *)MultiQI.pItf;
		//g_pAdoServer = (IADOTier *)MultiQI.pItf;
	}
	else
	{
		return FALSE;
	}

	//m_strDBServer = strU + m_strDBServer;
	_bstr_t strServer(m_strDBServer);
	_bstr_t strDBName(m_strDBName);
	_bstr_t strDBUser(m_strDBUser);
	_bstr_t strDBPsw(m_strDBPsw);
	
	hr = g_pAdoServer->Open(strServer, strDBName, strDBUser, strDBPsw);
	
	if(!SUCCEEDED(hr))
	{
		MessageBox(NULL,"Can't Open(,,) database.","Client Error:", MB_OK);
		return FALSE;
	}
	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
		// No message handlers
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

// App command to run the dialog
void CClientMainApp::OnAppAbout()
{
	CAboutDlg aboutDlg;
	aboutDlg.DoModal();
}

/////////////////////////////////////////////////////////////////////////////
// CClientMainApp message handlers


int CClientMainApp::ExitInstance() 
{
	// TODO: Add your specialized code here and/or call the base class
	::CoUninitialize();
	return CWinApp::ExitInstance();
}

BOOL CClientMainApp::PreTranslateMessage(MSG* pMsg)
{
	// CG: The following lines were added by the Splash Screen component.//	if (m_pSplashWnd->PreTranslateAppMessage(pMsg))//		return TRUE;	return CWinApp::PreTranslateMessage(pMsg);
}

void CClientMainApp::InitCmbBox(_bstr_t strSql, CString strField, CComboBox *cmb)
{
	g_pAdoServer->CloseRecordset();
	g_pAdoServer->OpenRecordset(strSql);
	
	HRESULT hr;
	VARIANT_BOOL bEmpty;

	int nRecCount;
	string strItem;
	hr = g_pAdoServer->get_Empty(&bEmpty);
	if(!bEmpty)
	{
		g_pAdoServer->Last();
		g_pAdoServer->First();

		nRecCount = g_pAdoServer->RecordCount;
		for(int i =0; i < nRecCount; i++)
		{
			strItem = (_bstr_t)g_pAdoServer->Field[LPCSTR(strField)];
			if(CB_ERR == cmb->SendMessage(CB_FINDSTRING, -1,  (LPARAM)strItem.c_str() ))
			{
				cmb->InsertString(i, strItem.c_str());
			}
			g_pAdoServer->Next();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -