📄 pagepwd.cpp
字号:
// PagePWD.cpp : implementation file
//
#include "stdafx.h"
#include "DK20DieselizeDynamotor.h"
#include "PagePWD.h"
#include "RecordPWD.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPagePWD dialog
CPagePWD::CPagePWD(CWnd* pParent /*=NULL*/)
: CDialog(CPagePWD::IDD, pParent)
{
//{{AFX_DATA_INIT(CPagePWD)
m_strPWD = _T("");
//}}AFX_DATA_INIT
}
void CPagePWD::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPagePWD)
DDX_Control(pDX, IDC_COMBO1, m_cbID);
DDX_Control(pDX, IDC_BTN_LOAD, m_btnLoad);
DDX_Control(pDX, IDC_STATIC_PWD, m_lbPWD);
DDX_Control(pDX, IDC_STATIC_ID, m_lbID);
DDX_Text(pDX, IDC_EDIT1, m_strPWD);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPagePWD, CDialog)
//{{AFX_MSG_MAP(CPagePWD)
ON_BN_CLICKED(IDC_BTN_LOAD, OnBtnLoad)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPagePWD message handlers
void CPagePWD::OnBtnLoad()
{
UpdateData(true);
CString strID = "";
CString strPwd = "";
m_cbID.GetWindowText(strID);
TRY
{
CString strSql = "select * from pwd where name ='" + strID + "'";
CRecordPWD rs1(&m_db);
rs1.Open(CRecordPWD::forwardOnly,strSql,CRecordPWD::readOnly);
if(!rs1.IsEOF())
{
rs1.GetFieldValue("PWD",strPwd );
}
rs1.Close();
}
CATCH(CDBException , e)
{
AfxMessageBox("Database Error:" + e->m_strError);
}
END_CATCH
if (!(strPwd == m_strPWD) )
{
bPass = false;
if (bChinese)
AfxMessageBox("密码不正确!");
else
AfxMessageBox(" Password is not correct!");
}
else
bPass = TRUE ;
CDialog::OnOK();
}
BOOL CPagePWD::OnInitDialog()
{
CDialog::OnInitDialog();
CenterWindow(GetDesktopWindow()) ;
VERIFY(m_fontP.CreateFont(
24, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_BOLD, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY,
DEFAULT_PITCH | FF_SWISS,
_T("Arial")));
if (!bChinese)
{
m_lbID.SetWindowText("UserID:");
m_lbPWD.SetWindowText("PassWord:");
m_btnLoad.SetWindowText("Enter");
}
TRY
{
CString strSql = "select * from pwd";
CString strID = "";
CRecordPWD rs1(&m_db);
rs1.Open(CRecordPWD::forwardOnly,strSql,CRecordPWD::readOnly);
while (!rs1.IsEOF())
{
strID = "";
rs1.GetFieldValue("name",strID );
m_cbID.AddString(strID);
rs1.MoveNext();
}
rs1.Close();
}
CATCH(CDBException , e)
{
AfxMessageBox("Database Error:" + e->m_strError);
}
END_CATCH
return TRUE;
}
void CPagePWD::DrawGradientFill(CDC *pDC, CRect *pRect, COLORREF crStart, COLORREF crEnd, int nSegments)
{
COLORREF cr;
int nR = GetRValue(crStart);
int nG = GetGValue(crStart);
int nB = GetBValue(crStart);
int neB = GetBValue(crEnd);
int neG = GetGValue(crEnd);
int neR = GetRValue(crEnd);
if(nSegments > pRect->Height())
nSegments = pRect->Height();
int nDiffR = (neR - nR);
int nDiffG = (neG - nG);
int nDiffB = (neB - nB);
int ndR = 256 * (nDiffR) / (max(nSegments,1));
int ndG = 256 * (nDiffG) / (max(nSegments,1));
int ndB = 256 * (nDiffB) / (max(nSegments,1));
nR *= 256;
nG *= 256;
nB *= 256;
neR *= 256;
neG *= 256;
neB *= 256;
int nCY = pRect->Height() / max(nSegments,1), nTop = pRect->top , nBottom =nTop;
CPen *hpen =(CPen*) pDC->SelectStockObject(NULL_PEN);
for (int i = 0; i < nSegments; i++, nR += ndR, nG += ndG, nB += ndB)
{
if (i == (nSegments - 1))
nTop = pRect->bottom;
else
nTop += nCY;
cr = RGB(nR / 256, nG / 256, nB / 256);
CBrush br(cr);
CBrush* pbrOld = pDC->SelectObject(&br);
pDC->Rectangle(pRect->left, nTop+1, pRect->right , nBottom);
pDC->SelectObject(pbrOld);
br.DeleteObject() ;
DeleteObject(pbrOld) ;
pbrOld =NULL ;
nBottom = nTop ;
}
pDC->SelectObject(hpen) ;
DeleteObject(hpen) ;
hpen = NULL ;
}
void CPagePWD::OnPaint()
{
CPaintDC dc(this);
CRect rcClient ;
GetClientRect(&rcClient) ;
CDC memDc ;
memDc.CreateCompatibleDC(&dc) ;
CBitmap bitmap1 ;
bitmap1.CreateCompatibleBitmap(&dc , rcClient.Width(),rcClient.Height()) ;
CBitmap *oldBitmp1 = memDc.SelectObject(&bitmap1) ;
memDc.FillSolidRect(&rcClient , RGB(173,211,198)) ;
CRect rc2(0 , 0 , 500, 20) ;
DrawGradientFill(&memDc , &rc2 , RGB(244,198,255) ,RGB(198,255,249),5) ;
memDc.SetTextColor(RGB(0,0,0)) ;
memDc.SetBkMode(TRANSPARENT) ;
if (bChinese)
memDc.DrawText(_T("请输入修改权限!"), &rc2 , DT_CENTER |DT_VCENTER );
else
memDc.DrawText(_T("Please enter your password !"), &rc2 , DT_CENTER |DT_VCENTER );
dc.BitBlt(0,0,rcClient.Width() , rcClient.Height() , &memDc , 0,0,SRCCOPY) ;
memDc.SelectObject(oldBitmp1) ;
bitmap1.DeleteObject() ;
memDc.DeleteDC() ;
DeleteObject(oldBitmp1) ; oldBitmp1 =NULL ;
ReleaseDC(&dc) ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -