// Dlg_InsertDB.cpp : 实现文件 // #include "stdafx.h" #include "SupportSmsPlatform.h" #include "Dlg_InsertDB.h" #include ".\dlg_insertdb.h" #include "TCPClient.h" // CDlg_InsertDB 对话框 IMPLEMENT_DYNAMIC(CDlg_InsertDB, CDialog) CDlg_InsertDB::CDlg_InsertDB(CWnd* pParent /*=NULL*/) : CDialog(CDlg_InsertDB::IDD, pParent) , m_sComb_DBType(_T("")) , m_sEdit_DBIP(_T("")) , m_sEdit_DBName(_T("")) , m_sEdit_DBUser(_T("")) , m_sEdit_DBPwd(_T("")) , m_sEdit_SQL(_T("")) , m_sEdit_Key(_T("")) , m_bCheck_KeyAutoAdd(FALSE) , m_nEdit_KeyInit(0) { m_bDBThreadStart = false; } CDlg_InsertDB::~CDlg_InsertDB() { } void CDlg_InsertDB::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); DDX_Control(pDX, IDC_COMBO_DBTYEP, m_Comb_DBType); DDX_CBString(pDX, IDC_COMBO_DBTYEP, m_sComb_DBType); DDX_Text(pDX, IDC_EDIT_DBIP, m_sEdit_DBIP); DDX_Text(pDX, IDC_EDIT_DBNAME, m_sEdit_DBName); DDX_Text(pDX, IDC_EDIT_DBUSER, m_sEdit_DBUser); DDX_Text(pDX, IDC_EDIT_DBPWD, m_sEdit_DBPwd); DDX_Text(pDX, IDC_EDIT_CONTENT, m_sEdit_SQL); DDX_Text(pDX, IDC_EDIT_KEY, m_sEdit_Key); DDX_Text(pDX, IDC_EDIT_KEYINIT, m_nEdit_KeyInit); DDX_Check(pDX, IDC_CHECK_KEYAUTOADD, m_bCheck_KeyAutoAdd); } BEGIN_MESSAGE_MAP(CDlg_InsertDB, CDialog) ON_BN_CLICKED(IDC_CHECK_KEYAUTOADD, OnBnClickedCheckKeyautoadd) END_MESSAGE_MAP() // CDlg_InsertDB 消息处理程序 BOOL CDlg_InsertDB::OnInitDialog() { CDialog::OnInitDialog(); // TODO: 在此添加额外的初始化 GetIni(); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } void CDlg_InsertDB::GetIni() { g_IniFile.GetVarStr( "Database_RomoteDB","ServerName",m_sEdit_DBIP ); g_IniFile.GetVarStr( "Database_RomoteDB","DataBaseName",m_sEdit_DBName ); g_IniFile.GetVarStr( "Database_RomoteDB","UserName",m_sEdit_DBUser ); g_IniFile.GetVarStr( "Database_RomoteDB","Password",m_sEdit_DBPwd ); g_IniFile.GetVarStr( "Database_RomoteDB","DBType",m_sComb_DBType ); UpdateData( false ); } void CDlg_InsertDB::SetIni() { UpdateData( ); g_IniFile.SetVarStr( "Database_RomoteDB","ServerName",m_sEdit_DBIP ); g_IniFile.SetVarStr( "Database_RomoteDB","DataBaseName",m_sEdit_DBName ); g_IniFile.SetVarStr( "Database_RomoteDB","UserName",m_sEdit_DBUser ); g_IniFile.SetVarStr( "Database_RomoteDB","Password",m_sEdit_DBPwd ); g_IniFile.SetVarStr( "Database_RomoteDB","DBType",m_sComb_DBType ); } bool CDlg_InsertDB::Apply() { SetIni(); //数据库连接串 if (!_stricmp(m_sComb_DBType, "SQL SERVER")) sprintf(g_strConnectString, "Provider=sqloledb;Data Source=%s;Initial Catalog=%s;User Id=%s;Password=%s; ", m_sEdit_DBIP, m_sEdit_DBName, m_sEdit_DBUser, m_sEdit_DBPwd); //else if (!_stricmp(g_strDBType, "ACCESS97")) // sprintf(g_strConnectString, "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=%s", m_sEdit_AccessName); //else if (!_stricmp(g_strDBType, "ACCESS2000")) // sprintf(g_strConnectString, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s", m_sEdit_AccessName); else if(!_stricmp(m_sComb_DBType, "PGSQL")) sprintf(g_strConnectString, "DRIVER={PostgreSQL ODBC Driver(UNICODE)}; SERVER=%s; port=5432; DATABASE=%s; UID=%s; PWD=%s;", m_sEdit_DBIP, m_sEdit_DBName, m_sEdit_DBUser, m_sEdit_DBPwd); else sprintf(g_strConnectString, "Provider=sqloledb;Data Source=%s;Initial Catalog=%s;User Id=%s;Password=%s; ", m_sEdit_DBIP, m_sEdit_DBName, m_sEdit_DBUser, m_sEdit_DBPwd); if( !CDBConnection::GetInstancePtr()->OpenDataBase(g_strConnectString) ) { MessageBox( "连接数据库失败!" ); return false; } m_bDBThreadStart = true; CDBConnection::GetInstancePtr()->DBConnectionCheckThreadStart(); CDBInterface::GetInstancePtr()->SetDBType(g_strDBType); if( !CTCPClient::GetInstancePtr(0)->Connection( "127.0.0.1", "64326" ) ) { MessageBox( "连接服务器失败!" ); return false; } return true; } void CDlg_InsertDB::OnBnClickedCheckKeyautoadd() { UpdateData(); //if( m_bCheck_KeyAutoAdd ) //{ // GetDlgItem( IDC_EDIT_KEY )->EnableWindow( true ); // GetDlgItem( IDC_EDIT_KEYINIT )->EnableWindow( true ); //} //else //{ // GetDlgItem( IDC_EDIT_KEY )->EnableWindow( false ); // GetDlgItem( IDC_EDIT_KEYINIT )->EnableWindow( false ); //} }