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

📄 global.cpp

📁 基础数据管理工具 主要针对政务系统的基础数据管理、分析、应用等功能! 项目代码
💻 CPP
字号:
// Global.cpp: implementation of the CGlobal class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "BaseFunc.h"
#include "Global.h"
#include "CommonUtil.h"
#include "DlgConnectionConfig.h"
#include "DlgDataBaseLinkConfig.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CGlobal::CGlobal()
{
}

CGlobal::~CGlobal()
{
}

bool CGlobal::InitInstance()
{
	m_sSysPath = CCommonUtil::GetSysPath();
	if(!InitConnection())
		return false;
	return true;
}

void CGlobal::Clean()
{
	m_ADOHandler.Clean();
}

bool CGlobal::InitConnection()
{
	try
	{
		CString sConfigFile = m_sSysPath + "Config\\Connective.xml";

		IXMLDOMDocumentPtr pDoc;
		pDoc.CreateInstance(__uuidof(DOMDocument));
		pDoc->Putasync(VARIANT_FALSE);
		pDoc->load(_bstr_t(sConfigFile));

		// get ado Cnn string
		IXMLDOMElementPtr pNode = pDoc->selectSingleNode(_bstr_t("/Config/Connective"));
		EBOraConnectionInfo coninfo;
		coninfo.sServerName = CCommonUtil::VarToStr(pNode->getAttribute((_bstr_t)"DataSource"));
		coninfo.sUserName = CCommonUtil::VarToStr(pNode->getAttribute((_bstr_t)"UserID"));
		coninfo.sPassword = CCommonUtil::VarToStr(pNode->getAttribute((_bstr_t)"Password"));
		if(!m_ADOHandler.InitInstance(coninfo))		
		{
			if(AfxMessageBox("数据库连接错误,是否重新配置原连接配置?\n选择[是]重新配置!",MB_YESNO) != IDYES)
				return false;
			CDlgConnectionConfig dlgConnection;
			dlgConnection.m_edtDataBaseServerName = coninfo.sServerName;
			dlgConnection.m_edtUserName = coninfo.sUserName;
			dlgConnection.m_edtUserPassWord = coninfo.sPassword;
			if(dlgConnection.DoModal() != IDOK)
				return false;
			coninfo.sServerName = dlgConnection.m_edtDataBaseServerName;
			coninfo.sUserName = dlgConnection.m_edtUserName;
			coninfo.sPassword = dlgConnection.m_edtUserPassWord;
			if(!m_ADOHandler.InitInstance(coninfo))
			{
				AfxMessageBox("重建连接仍然出错,请与开发人员联系!");
				return false;
			}
			pNode->setAttribute((_bstr_t)"DataSource",(_bstr_t)coninfo.sServerName);
			pNode->setAttribute((_bstr_t)"UserID",(_bstr_t)coninfo.sUserName);
			pNode->setAttribute((_bstr_t)"Password",(_bstr_t)coninfo.sPassword);
			pDoc->save(_bstr_t(sConfigFile));
		}
	}
	catch(_com_error&)
	{
		AfxMessageBox("读取配置文件失败!");
		return false;
	}
	return true;
}

bool CGlobal::DataBaseLinkManage(LPCTSTR pzsLinkType)
{
		try
	{
		//测试户政科连接是否正常
		CString sConfigFile = m_sSysPath + "Config\\Connective.xml";

		IXMLDOMDocumentPtr pDoc;
		pDoc.CreateInstance(__uuidof(DOMDocument));
		pDoc->Putasync(VARIANT_FALSE);
		pDoc->load(_bstr_t(sConfigFile));
		
		CString sNode;
		sNode.Format("/Config/DataBaseLink/%s",pzsLinkType);
		IXMLDOMElementPtr pNode = pDoc->selectSingleNode(_bstr_t(sNode));
		CString sLinkName = CCommonUtil::VarToStr(pNode->getAttribute((_bstr_t)"LinkName"));
		if(!m_ADOHandler.TestDBLinkConnective(sLinkName))
		{
			CString sCNName = CCommonUtil::VarToStr(pNode->getAttribute((_bstr_t)"SrvCNName"));
			if(AfxMessageBox(sCNName+"连接错误,是否现在更改原连接配置?\n选择[是]重新配置!\n如不更改将无法使用此功能!",MB_YESNO) != IDYES)
				return false;
			CString sUserName = CCommonUtil::VarToStr(pNode->getAttribute((_bstr_t)"UserName"));
			CString sUserPassword = CCommonUtil::VarToStr(pNode->getAttribute((_bstr_t)"PassWord"));
			CString sLinkTNS = CCommonUtil::VarToStr(pNode->getAttribute((_bstr_t)"TNS")); 
			CDlgDataBaseLinkConfig dlgdbLinkConfig;
			dlgdbLinkConfig.m_pOraHandler = &m_ADOHandler;
			dlgdbLinkConfig.m_edtLinkName = sLinkName;
			dlgdbLinkConfig.m_edtLinkUserName = sUserName;
			dlgdbLinkConfig.m_edtLinkUserPassWord = sUserPassword;
			if(dlgdbLinkConfig.DoModal() != IDOK)
				return false;
			sLinkTNS = dlgdbLinkConfig.m_edtLinkTNS;
			sUserName = dlgdbLinkConfig.m_edtLinkUserName;
			sUserPassword = dlgdbLinkConfig.m_edtLinkUserPassWord;
			pNode->setAttribute((_bstr_t)"UserName",(_bstr_t)sUserName);
			pNode->setAttribute((_bstr_t)"PassWord",(_bstr_t)sUserPassword);
			pNode->setAttribute((_bstr_t)"TNS",(_bstr_t)sLinkTNS);
			pDoc->save(_bstr_t(sConfigFile));
		}
	}
	catch(_com_error&)
	{
		AfxMessageBox("读取配置文件失败!");
		return false;
	}
	return true;
}

⌨️ 快捷键说明

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