📄 datasourceconfig.cpp
字号:
// DataSourceConfig.cpp : implementation file
//
#include "stdafx.h"
#include "CBA_SYSTEM.h"
#include "DataSourceConfig.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDataSourceConfig dialog
CDataSourceConfig::CDataSourceConfig(CWnd* pParent /*=NULL*/)
: CDialog(CDataSourceConfig::IDD, pParent)
{
//{{AFX_DATA_INIT(CDataSourceConfig)
m_username = _T("");
m_password = _T("");
m_instance = _T("");
//}}AFX_DATA_INIT
}
void CDataSourceConfig::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDataSourceConfig)
DDX_Control(pDX, IDC_IPADDRESS1, m_ipAddr);
DDX_Control(pDX,IDC_BUTTON1,m_surebutton);
DDX_Control(pDX,IDC_BUTTON2,m_savebutton);
DDX_Text(pDX, IDC_EDIT1, m_username);
DDX_Text(pDX, IDC_EDIT2, m_password);
DDX_Text(pDX, IDC_EDIT3, m_instance);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDataSourceConfig, CDialog)
//{{AFX_MSG_MAP(CDataSourceConfig)
ON_BN_CLICKED(IDC_BUTTON1, OnDataConfig)
ON_BN_CLICKED(IDC_BUTTON2, OnTestDataLink)
ON_WM_PAINT()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDataSourceConfig message handlers
void CDataSourceConfig::OnDataConfig()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_instance =="")
{
MessageBox("请输入数据库实例名!",NULL,MB_ICONINFORMATION);
return;
}
if(m_username=="")
{
MessageBox("请输入用户名!",NULL,MB_ICONINFORMATION);
return;
}
if(m_password=="")
{
MessageBox("请输入密码!",NULL,MB_ICONINFORMATION);
return;
}
CString tempstr = "";
unsigned char *pIP;
CString strIP;
DWORD dwIP;
m_ipAddr.GetAddress(dwIP);
pIP = (unsigned char*)&dwIP;
strIP.Format("%u.%u.%u.%u",*(pIP+3), *(pIP+2), *(pIP+1), *pIP);
tempstr = tempstr + strIP + "\r\n"+m_instance+"\r\n"+m_username +"\r\n"+ m_password;
if(WriteToSaveFile(tempstr,"DataConfig.txt"))
{
MessageBox("保存配置成功!",NULL,MB_OK|MB_ICONINFORMATION);
return;
}
else
{
MessageBox("保存配置失败!",NULL,MB_OK|MB_ICONINFORMATION);
return;
}
}
BOOL CDataSourceConfig::WriteToSaveFile(CString m_str,CString FileName)
{
CStdioFile file;
file.Open(FileName,CFile::modeCreate|CFile::modeReadWrite);
file.WriteString(m_str);
file.Close();
return TRUE;
}
void CDataSourceConfig::OnTestDataLink()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
if(m_instance =="")
{
MessageBox("请输入数据库实例名!",NULL,MB_ICONINFORMATION);
return;
}
if(m_username=="")
{
MessageBox("请输入用户名!",NULL,MB_ICONINFORMATION);
return;
}
if(m_password=="")
{
MessageBox("请输入密码!",NULL,MB_ICONINFORMATION);
return;
}
CString tempstr = "";
unsigned char *pIP;
CString strIP;
DWORD dwIP;
m_ipAddr.GetAddress(dwIP);
pIP = (unsigned char*)&dwIP;
strIP.Format("%u.%u.%u.%u",*(pIP+3), *(pIP+2), *(pIP+1), *pIP);
ADOConn testado;
if(testado.OnInitADOConn(strIP,m_instance,m_username,m_password))
{
MessageBox("数据库连接测试成功!",NULL,MB_ICONINFORMATION);
return;
}
}
void CDataSourceConfig::OnPaint()
{
CPaintDC dc(this); // device context for painting
CRect rect;
GetClientRect(rect);
dc.FillSolidRect(rect,RGB(255,255,255)); //设置为白色背景
// TODO: Add your message handler code here
CBitmap bmp;
bmp.LoadBitmap(IDB_BITMAPDATATOP);
BITMAP bmpInfo;
bmp.GetBitmap(&bmpInfo);
CDC mdc;
mdc.CreateCompatibleDC(&dc);
CBitmap *pOldBmp = mdc.SelectObject(&bmp);
dc.BitBlt(0,15,bmpInfo.bmWidth,bmpInfo.bmHeight,&mdc,0,0,SRCCOPY);
dc.SelectObject(*pOldBmp);
CDialog::OnPaint();
// Do not call CDialog::OnPaint() for painting messages
}
HBRUSH CDataSourceConfig::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if (pWnd->GetDlgCtrlID() == IDC_STATIC)
{
// Set the text color to red
hbr = CreateSolidBrush(RGB(255,255,255));
pDC->SetTextColor(RGB(0, 0, 0));
// Set the background mode for text to transparent
// so background will show thru.
pDC->SetBkMode(TRANSPARENT);
// Return handle to our CBrush object
//hbr = m_brush;
}
// TODO: Change any attributes of the DC here
// TODO: Return a different brush if the default is not desired
return hbr;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -