📄 数据库设置dlg.cpp
字号:
// 数据库设置Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "数据库设置.h"
#include "数据库设置Dlg.h"
#include "SQLServer.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Control(pDX, IDC_STATIP, m_StaTip);
DDX_Control(pDX, IDC_COMBO2, m_ComDataBase);
DDX_Control(pDX, IDC_COMBO1, m_ComServer);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_CBN_DROPDOWN(IDC_COMBO1, OnDropdownCombo1)
ON_CBN_DROPDOWN(IDC_COMBO2, OnDropdownCombo2)
ON_BN_CLICKED(IDC_BUTSURE, OnButsure)
ON_BN_CLICKED(IDC_BUTEXIT, OnButexit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::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
char cPath[_MAX_DIR];
CString sPath,sServer,sDataBase;
::GetSystemDirectory(cPath,sizeof(cPath));
sPath.Format("%s\\SYSRX.ini",cPath);
::GetPrivateProfileString("CONFIG","SERVER",NULL,sServer.GetBuffer(128),128,sPath);
::GetPrivateProfileString("CONFIG","DATABASE",NULL,sDataBase.GetBuffer(128),128,sPath);
this->m_ComDataBase.SetWindowText(sDataBase);
this->m_ComServer.SetWindowText(sServer);
// TODO: Add extra initialization here
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 CMyDlg::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 CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyDlg::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
void CMyDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CMyDlg::OnDropdownCombo1()
{
SQLServer server;
CString sText=server.GetServer();
this->FormatString(sText,&m_ComServer);
}
void CMyDlg::OnDropdownCombo2()
{
SQLServer server;
CString sServer;
m_ComServer.GetWindowText(sServer);
CString sText=server.GetDataBase(sServer);
this->FormatString(sText,&m_ComDataBase);
}
void CMyDlg::FormatString(CString sText, CBaseComboBox *pComboBox)
{
pComboBox->ClearAllString();
int nPos=0,nOldPos=0;
CString sMem;
while(nPos!=-1)
{
nOldPos=nPos;
nPos=sText.Find(",",nPos+1);
if(nPos==-1)
nPos=sText.GetLength();
if(nOldPos==0)
sMem=sText.Mid(nOldPos,nPos-nOldPos);
else
sMem=sText.Mid(nOldPos+1,nPos-nOldPos-1);
if(nPos==sText.GetLength())
nPos=-1;
if(sMem.IsEmpty())
continue;
pComboBox->AddString(sMem);
}
}
void CMyDlg::OnButsure()
{
char cPath[_MAX_DIR];
CString sPath;
::GetSystemDirectory(cPath,sizeof(cPath));
sPath.Format("%s\\SYSRX.ini",cPath);
CString sServer,sDatabase;
this->m_ComDataBase.GetWindowText(sDatabase);
this->m_ComServer.GetWindowText(sServer);
if(sServer.IsEmpty()==true)
{
MessageBox("请选择一个活动的SQL-Server服务器!","系统提示",MB_OK|MB_ICONSTOP);
this->m_ComServer.SetFocus();
return;
}
if(sDatabase.IsEmpty()==true)
{
MessageBox("请选择数据库!","系统提示",MB_OK|MB_ICONSTOP);
this->m_ComDataBase.SetFocus();
return;
}
::WritePrivateProfileString("CONFIG","SERVER",sServer,sPath);
::WritePrivateProfileString("CONFIG","DATABASE",sDatabase,sPath);
MessageBox("数据库配置完毕!","系统提示",MB_OK|MB_ICONINFORMATION);
this->OnCancel();
}
void CMyDlg::OnButexit()
{
this->OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -