📄 yhgldlg.cpp
字号:
// yhglDlg.cpp : implementation file
//
#include "stdafx.h"
#include "yhgl.h"
#include "yhglDlg.h"
#include "Choose.h"
#include "Tree.h"
#include ".\GrantPrivilegesForSDEUser.h"
#include ".\RegistryManager.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define Max 999
extern CYhglApp theApp;
int flag=0;
int i=0;
int uid[Max];
CString uname[Max],ucode[Max],pid[Max];
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CYhglDlg dialog
CYhglDlg::CYhglDlg(CWnd* pParent /*=NULL*/)
: CDialog(CYhglDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CYhglDlg)
m_uName = _T("");
m_uCode = _T("");
m_userType = -1;
m_serviceName = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_bSuccess = FALSE;
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
loginTime = 0;
}
void CYhglDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CYhglDlg)
DDX_Control(pDX, IDOK, m_OK);
DDX_Control(pDX, IDCANCEL, m_Cancel);
DDX_Text(pDX, IDC_EDIT2, m_uName);
DDX_Text(pDX, IDC_EDIT3, m_uCode);
DDX_Radio(pDX, IDC_RADIO1, m_userType);
DDX_Text(pDX, IDC_EDIT_DBSERVICENAME, m_serviceName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CYhglDlg, CDialog)
//{{AFX_MSG_MAP(CYhglDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CYhglDlg message handlers
BOOL CYhglDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_OK.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
m_OK.SetBkColor(RGB(234,216,187));
m_OK.SetTooltipText(_T("登陆系统"));
m_OK.SetRounded(TRUE);
m_Cancel.OffsetColor(CButtonST::BTNST_COLOR_BK_IN, 30);
m_Cancel.SetBkColor(RGB(234,216,187));
m_Cancel.SetTooltipText(_T("退出系统"));
m_Cancel.SetRounded(TRUE);
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
//读注册表信息,取username,server
RegistryManager regMgr;
m_uName = regMgr.GetProfileString(_T("Login"), _T("UserName"), NULL);
m_serviceName = regMgr.GetProfileString(_T("Login"), _T("ServiceName"), NULL);
//m_userType = regMgr.GetProfileInt(_T("Login"),_T("UserType"),0) - 1;
UpdateData(FALSE);
// 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
return TRUE; // return TRUE unless you set the focus to a control
}
void CYhglDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CYhglDlg::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 CYhglDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CYhglDlg::OnOK()
{
UpdateData();
if (m_userType <0)
{
MessageBox("您必须选择用户类型!","提示:",MB_OK|MB_ICONEXCLAMATION);
return;
}
BeginWaitCursor();
_ConnectionPtr pConn;
//连接数据库
HRESULT hr;
CString str,sql;
CString sysName("sys");//暂时规定为
CString sysPwd("ss");
try
{
hr = pConn.CreateInstance("ADODB.Connection");///创建Connection对象
if(SUCCEEDED(hr))
{
str.Format(_T("Provider=OraOLEDB.Oracle;Data Source=%s;User ID=%s;Password=%s;"),m_serviceName,sysName,sysPwd);
hr = pConn->Open((_bstr_t)str,"","",adModeUnknown);///连接数据库
}
}
catch(_com_error e)///捕捉异常
{
AfxMessageBox("连接数据库失败!");///显示错误信息
return;
}
theApp.m_pConnection = pConn;
//读取用户信息表,验证登陆用户名-密码的合法性
_RecordsetPtr m_pRecordset;
m_pRecordset.CreateInstance(__uuidof(Recordset));
try
{
sql.Format("SELECT LOGNAME,LOGPASSWORD,ROLEGROUPID FROM SDE.TB_DSUSER where LOGNAME=\'%s\' and LOGPASSWORD=\'%s\'",m_uName,m_uCode);
m_pRecordset->Open((_bstr_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if (m_pRecordset->GetRecordCount() <=0 )
{
MessageBox("您没有权限使用该系统!","警告:",MB_OK|MB_ICONSTOP);
loginTime++;
//用户一次登陆的次数如果大于3,则退出系统
if (loginTime >= 3) OnCancel();
return;
}
}
catch(_com_error e)///捕捉异常
{
AfxMessageBox("读取用户信息表失败!");
m_pRecordset->Close();
return;
}
vQid = m_pRecordset->GetCollect("RoleGroupID");
m_pRecordset->Close();
EndWaitCursor();
//写注册表信息,username,server
RegistryManager regMgr;
regMgr.WriteProfileString(_T("Login"), _T("UserName"), m_uName);
regMgr.WriteProfileString(_T("Login"), _T("ServiceName"), m_serviceName);
//regMgr.WriteProfileInt(_T("Login"),_T("UserType"),m_userType+1);
CDialog::OnOK();
if(flag==1)
{ //系统/数据库管理员
//初始化SDE连接
//DBSDE::InitSDELoginSetting (m_server,_T("esri_sde"),_T("sde"),_T("sde"),_T("sde"),_T("SDE.DEFAULT"));
//从SDE数据库中取Workspace
//IWorkspacePtr pSDEWorkspace;
//if (!DBSDE::IsSDEConnected()) pSDEWorkspace = DBSDE::ConnectSDE();
//else pSDEWorkspace = DBSDE::g_pSDEWorkspace;
//if (pSDEWorkspace == NULL)
//{
// MessageBox ("连接SDE数据库失败!","错误提示:",MB_OK|MB_ICONSTOP);
// return;
//}
CChoose dlg;
dlg.QID=vQid.iVal;
dlg.DoModal();
}
else if(flag==2)
{
//CTree *dlg = new CTree; dlg->Create();
CTree dlg;
dlg.transID=vQid.iVal;
dlg.DoModal();
}
}
void CYhglDlg::OnRadio1()
{
UpdateData();
flag = m_userType + 1;
}
void CYhglDlg::OnRadio2()
{
UpdateData();
flag = m_userType + 1;
//flag=2;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -