📄 odbcdlg.cpp
字号:
// ODBCDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ODBC.h"
#include "ODBCDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CODBCDlg dialog
CODBCDlg::CODBCDlg(CWnd* pParent /*=NULL*/)
: CDialog(CODBCDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CODBCDlg)
m_strDir = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CODBCDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CODBCDlg)
DDX_Text(pDX, IDC_PATH, m_strDir);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CODBCDlg, CDialog)
//{{AFX_MSG_MAP(CODBCDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_CONFIG, OnConfig)
ON_BN_CLICKED(IDC_VIEW, OnView)
ON_BN_CLICKED(IDC_BTN_BANK, OnBtnBank)
ON_BN_CLICKED(IDC_BTN_ATM, OnBtnAtm)
ON_BN_CLICKED(IDC_BTN_SVR, OnBtnSvr)
ON_BN_CLICKED(IDC_BTN_COMPANY, OnBtnCompany)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CODBCDlg message handlers
BOOL CODBCDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
char CurPath[128];
GetCurrentDirectory(128,CurPath);
m_strDir=CurPath;
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CODBCDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CODBCDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
BOOL CODBCDlg::LoadDbSource(
CString strSourceName, //数据源名
CString strSourceDb, //数据库存放路径
CString strDescription //数据源描述字符串
)
{
HKEY hKey;
DWORD lDisp;
//注册数据源名
CString strSubKey="SOFTWARE\\ODBC\\ODBC.INI\\"+strSourceName;
RegCreateKeyEx(HKEY_CURRENT_USER,
strSubKey,
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
&lDisp);
//注册ODBC驱动程序
CString value1("C:\\WINNT\\System32\\odbcjt32.dll");
RegSetValueEx(hKey,
"Driver",
0,
REG_SZ,
(const unsigned char *)((LPCTSTR)value1),
strlen((LPCTSTR)value1)+1);
//注册数据库文件
CString value2 = strSourceDb;
RegSetValueEx(hKey,
"DBQ",
0,
REG_SZ,
(const unsigned char *)((LPCTSTR)value2),
strlen((LPCTSTR)value2)+1);
DWORD value3=(DWORD)25;
RegSetValueEx(hKey,
"DriverID",
0,
REG_DWORD,
(const BYTE *)&value3,
sizeof(DWORD));
CString value4("Ms Access");
RegSetValueEx(hKey,
"FIL",
0,
REG_SZ,
(const unsigned char *)((LPCTSTR)value4),
strlen((LPCTSTR)value4)+1);
DWORD value5=(DWORD)0;
RegSetValueEx(hKey,
"SafeTransactions",
0,
REG_DWORD,
(const BYTE *)&value5,
sizeof(DWORD));
CString value6("");
RegSetValueEx(hKey,
"UID",
0,
REG_SZ,
(const unsigned char *)((LPCTSTR)value6),
strlen((LPCTSTR)value6)+1);
return TRUE;
}
void CODBCDlg::OnConfig()
{
if(!LoadDbSource("accounts",m_strDir + "\\BankServer\\accounts.mdb",""))
{
MessageBox("在配置accounts据源时出错!\r\n","错误",MB_ICONEXCLAMATION);
return;
}
if(!LoadDbSource("dacl",m_strDir + "\\BankServer\\dacl.mdb",""))
{
MessageBox("在配置dacl数据源时出错!\r\n","错误",MB_ICONEXCLAMATION);
return;
}
if(!LoadDbSource("srvlog",m_strDir + "\\BankServer\\srvlog.mdb",""))
{
MessageBox("在配置srvlog数据源时出错!\r\n","错误",MB_ICONEXCLAMATION);
return;
}
if(!LoadDbSource("autosrv",m_strDir + "\\AutoSrv\\autosrv.mdb",""))
{
MessageBox("在配置autosrv数据源时出错!\r\n","错误",MB_ICONEXCLAMATION);
return;
}
if(!LoadDbSource("company",m_strDir + "\\Company\\company.mdb",""))
{
MessageBox("在配置company数据源时出错!\r\n","错误",MB_ICONEXCLAMATION);
return;
}
MessageBox("数据源配置完成!","信息:",MB_ICONINFORMATION);
}
void CODBCDlg::OnView()
{
BROWSEINFO bi;
TCHAR szDisplayName[MAX_PATH];
LPITEMIDLIST pidl;
LPMALLOC pMalloc = NULL;
ZeroMemory(&bi, sizeof(bi));
//bi.hwndOwner = GetParent(hDlg);
bi.pszDisplayName = szDisplayName;
bi.lpszTitle = TEXT("请选择ATM工程所在目录");
bi.ulFlags = BIF_RETURNONLYFSDIRS;
pidl = SHBrowseForFolder(&bi);
if(pidl) {
SHGetPathFromIDList(pidl, szDisplayName);
m_strDir=szDisplayName;
UpdateData(false);
}
}
void CODBCDlg::OnBtnBank()
{
// TODO: Add your control notification handler code here
ShellExecute(NULL,"open", m_strDir + "\\BankServer\\classes\\BankServer.jar", NULL, m_strDir + "\\\BankServer\\classes\\", SW_SHOWNORMAL);
}
void CODBCDlg::OnBtnAtm()
{
// TODO: Add your control notification handler code here
ShellExecute(NULL,"open", m_strDir + "\\ATMClient\\atm.jar", NULL, m_strDir + "\\ATMClient\\", SW_SHOWNORMAL);
}
void CODBCDlg::OnBtnSvr()
{
// TODO: Add your control notification handler code here
ShellExecute(NULL,"open", m_strDir + "\\AutoSrv\\classes\\AutoSrv.jar", NULL, m_strDir + "\\AutoSrv\\classes\\", SW_SHOWNORMAL);
}
void CODBCDlg::OnBtnCompany()
{
// TODO: Add your control notification handler code here
ShellExecute(NULL,"open", m_strDir + "\\Company\\classes\\Company.jar", NULL, m_strDir + "\\Company\\classes\\", SW_SHOWNORMAL);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -