📄 maindlg.cpp
字号:
// MainDlg.cpp : implementation file
//
#include "stdafx.h"
#include "AddressList.h"
#include "MainDlg.h"
#include "UserDlg.h"
#include "QueryDlg.h"
#include "SetAdd.h"
#include "LoginDlg.h"
#include "ManageDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainDlg dialog
CMainDlg::CMainDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMainDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMainDlg)
//}}AFX_DATA_INIT
}
void CMainDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMainDlg)
DDX_Control(pDX, ID_MENU_MANAGEUSER, m_manage);
DDX_Control(pDX, IDC_DATAGRID1, m_DataGrid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMainDlg, CDialog)
//{{AFX_MSG_MAP(CMainDlg)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit)
ON_BN_CLICKED(IDC_BUTTON_UPDATE, OnButtonUpdate)
ON_BN_CLICKED(IDC_BUTTON_QUERY, OnButtonQuery)
ON_BN_CLICKED(IDC_BUTTON_EXIT, OnButtonExit)
ON_COMMAND(ID_MENU_LOGON, OnMenuLogon)
ON_COMMAND(ID_MENU_LOGIN, OnMenuLogin)
ON_COMMAND(ID_MENU_MANAGEUSER, OnMenuManageuser)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMainDlg message handlers
BOOL CMainDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
OnMenuLogon();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CMainDlg::OnButtonAdd()
{
// TODO: Add your control notification handler code here
CSetAdd saDlg;
if(saDlg.DoModal() == IDOK)
{
CString sex;
if(saDlg.m_sex == 0)
sex = "男";
else
sex = "女";
CString strSQL;
strSQL.Format("insert into AL_Attrib([User],姓名,性别,出生日期,籍贯,移动电话,住宅电话,腾讯QQ,MSN,EMail,家庭地址,单位名称,单位电话,单位地址)values('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')"
,m_name,saDlg.m_name,sex,saDlg.m_year,saDlg.m_native,saDlg.m_handSet,saDlg.m_homeTel,saDlg.m_qq,saDlg.m_msn,saDlg.m_email,saDlg.m_homeAddress,saDlg.m_comName,saDlg.m_comTel,saDlg.m_comAddress);
m_pCon->Execute((_bstr_t)strSQL,0,adCmdText);
OnButtonUpdate();
m_DataGrid.SetAllowUpdate(false);
}
}
void CMainDlg::OnButtonDelete()
{
// TODO: Add your control notification handler code here
try
{
if(MessageBox("是否要删除当前选择的记录?","提示",MB_OKCANCEL||MB_ICONQUESTION) == IDOK)
m_pSet->Delete(adAffectCurrent);
}
catch(_com_error &e)
{
CString strErr;
strErr.Format("错误!\n %ld(%x)",e.ErrorInfo(),e.Description());
MessageBox(strErr);
}
m_DataGrid.SetAllowUpdate(false);
}
void CMainDlg::OnButtonEdit()
{
// TODO: Add your control notification handler code here
try
{
if(MessageBox("是否要进行修改记录?","提示",MB_OKCANCEL||MB_ICONINFORMATION) == IDOK)
m_DataGrid.SetAllowUpdate(true);
}
catch(_com_error &e)
{
CString strErr;
strErr.Format("错误!\n %ld(%x)",e.ErrorInfo(),e.Description());
MessageBox(strErr);
}
}
void CMainDlg::OnButtonUpdate()
{
// TODO: Add your control notification handler code here
if(m_pSet->State == adStateOpen)
m_pSet->Close();
CString strSQL1;
strSQL1 = "select 姓名,性别,出生日期,籍贯,移动电话,住宅电话,腾讯QQ,MSN,EMail,家庭地址,单位名称,单位电话,单位地址 from al_attrib where [user]='" + m_name + "'";
m_pSet->Open((_bstr_t)strSQL1,m_pCon.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
m_DataGrid.SetRefDataSource(m_pSet);
m_DataGrid.SetAllowUpdate(false);
}
void CMainDlg::OnButtonQuery()
{
// TODO: Add your control notification handler code here
CQueryDlg qdlg;
if(qdlg.DoModal() == IDOK)
{
}
else
{
}
m_DataGrid.SetAllowUpdate(false);
}
void CMainDlg::OnButtonExit()
{
// TODO: Add your control notification handler code here
if(MessageBox("是否要退出?","提示",MB_OKCANCEL) == IDOK)
exit(0);
}
void CMainDlg::OnMenuLogon()
{
// TODO: Add your command handler code here
CUserDlg uDlg;
if(uDlg.DoModal() == IDOK)
{
m_name = uDlg.m_name;
m_purview = uDlg.m_purview;
if(uDlg.m_purview == "1")
{
//在这里设置管理员操作
}
else
{
//在这里设置普通用户操作
// CMenu menu;
//menu.LoadMenu(IDR_MENU_MAIN);
//this->SetMenu(&menu);
//menu.EnableMenuItem(ID_MENU_MANAGEUSER,false);//
this->GetMenu()->EnableMenuItem(ID_MENU_MANAGEUSER,false);
m_manage.ShowWindow(false);
}
}
else if(m_name == "")
{
exit(0);
}
else
{
return;
}
m_pCon.CreateInstance(__uuidof(Connection));
m_pCon->Open("driver={SQL Server};Server=192.168.1.13;DATABASE=AddressList;UID=sa;PWD=sa","","",adModeUnknown);
m_pCon->CursorLocation = adUseClient;
m_pSet.CreateInstance(__uuidof(Recordset));
if(m_pSet->State == adStateOpen)
m_pSet->Close();
CString strSQL;
strSQL = "select 姓名,性别,出生日期,籍贯,移动电话,住宅电话,腾讯QQ,MSN,EMail,家庭地址,单位名称,单位电话,单位地址 from al_attrib where [user]='" + m_name + "'";
m_pSet->Open((_bstr_t)strSQL,m_pCon.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
m_DataGrid.SetRefDataSource(m_pSet);
}
void CMainDlg::OnMenuLogin()
{
// TODO: Add your command handler code here
CLoginDlg lDlg;
lDlg.m_purview = atoi(m_purview);
lDlg.DoModal();
}
void CMainDlg::OnMenuManageuser()
{
// TODO: Add your command handler code here
CManageDlg mDlg;
if(mDlg.DoModal() == IDOK)
{
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -