📄 hrdbsdlg.cpp
字号:
// HRDBSDlg.cpp : implementation file
//
#include "stdafx.h"
#include "HRDBS.h"
#include "HRDBSDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// 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()
/////////////////////////////////////////////////////////////////////////////
// CHRDBSDlg dialog
CHRDBSDlg::CHRDBSDlg(CWnd* pParent /*=NULL*/)
: CDialog(CHRDBSDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CHRDBSDlg)
m_strSelectedApproach = _T("");
m_strSelectedArea = _T("");
m_strSelectedProfession = _T("");
m_strSelectedVocation = _T("");
m_strCompany = _T("");
m_strConfigApproach = _T("");
m_strConfigArea = _T("");
m_strConfigProfession = _T("");
m_strConfigVocation = _T("");
m_strEmail = _T("");
m_strInterest = _T("");
m_strMemo = _T("");
m_strMobile = _T("");
m_strName = _T("");
m_strPhone = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CHRDBSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CHRDBSDlg)
DDX_Control(pDX, IDC_LIST_VOCATION, m_listVocation);
DDX_Control(pDX, IDC_LIST_PROFESSION, m_listProfession);
DDX_Control(pDX, IDC_LIST_HR, m_listHR);
DDX_Control(pDX, IDC_LIST_AREA, m_listArea);
DDX_Control(pDX, IDC_LIST_APPROACH, m_listApproach);
DDX_Control(pDX, IDC_COMBO_VOCATION, m_comboVocation);
DDX_Control(pDX, IDC_COMBO_PROFESSION, m_comboProfession);
DDX_Control(pDX, IDC_COMBO_AREA, m_comboArea);
DDX_Control(pDX, IDC_COMBO_APPROACH, m_comboApproach);
DDX_CBString(pDX, IDC_COMBO_APPROACH, m_strSelectedApproach);
DDX_CBString(pDX, IDC_COMBO_AREA, m_strSelectedArea);
DDX_CBString(pDX, IDC_COMBO_PROFESSION, m_strSelectedProfession);
DDX_CBString(pDX, IDC_COMBO_VOCATION, m_strSelectedVocation);
DDX_Text(pDX, IDC_EDIT_COMPANY, m_strCompany);
DDX_Text(pDX, IDC_EDIT_CONFIG_APPROACH, m_strConfigApproach);
DDX_Text(pDX, IDC_EDIT_CONFIG_AREA, m_strConfigArea);
DDX_Text(pDX, IDC_EDIT_CONFIG_PROFESSION, m_strConfigProfession);
DDX_Text(pDX, IDC_EDIT_CONFIG_VOCATION, m_strConfigVocation);
DDX_Text(pDX, IDC_EDIT_EMAIL, m_strEmail);
DDX_Text(pDX, IDC_EDIT_INTEREST, m_strInterest);
DDX_Text(pDX, IDC_EDIT_MEMO, m_strMemo);
DDX_Text(pDX, IDC_EDIT_MOBILE, m_strMobile);
DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
DDX_Text(pDX, IDC_EDIT_PHONE, m_strPhone);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CHRDBSDlg, CDialog)
//{{AFX_MSG_MAP(CHRDBSDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SYS_EXIT, OnSysExit)
ON_BN_CLICKED(IDC_BTN_APPROACH_ADD, OnBtnApproachAdd)
ON_BN_CLICKED(IDC_BTN_APPROACH_DEL, OnBtnApproachDel)
ON_BN_CLICKED(IDC_BTN_APPROACH_MOD, OnBtnApproachMod)
ON_BN_CLICKED(IDC_BTN_AREA_ADD, OnBtnAreaAdd)
ON_BN_CLICKED(IDC_BTN_AREA_DEL, OnBtnAreaDel)
ON_BN_CLICKED(IDC_BTN_AREA_MOD, OnBtnAreaMod)
ON_BN_CLICKED(IDC_BTN_DETAIL_QUERY, OnBtnDetailQuery)
ON_BN_CLICKED(IDC_BTN_HR_ADD, OnBtnHrAdd)
ON_BN_CLICKED(IDC_BTN_HR_DEL, OnBtnHrDel)
ON_BN_CLICKED(IDC_BTN_HR_MOD, OnBtnHrMod)
ON_BN_CLICKED(IDC_BTN_HR_QUERY, OnBtnHrQuery)
ON_BN_CLICKED(IDC_BTN_PROFESSION_ADD, OnBtnProfessionAdd)
ON_BN_CLICKED(IDC_BTN_PROFESSION_DEL, OnBtnProfessionDel)
ON_BN_CLICKED(IDC_BTN_PROFESSION_MOD, OnBtnProfessionMod)
ON_BN_CLICKED(IDC_BTN_STAT_QUERY, OnBtnStatQuery)
ON_BN_CLICKED(IDC_BTN_VOCATION_ADD, OnBtnVocationAdd)
ON_BN_CLICKED(IDC_BTN_VOCATION_DEL, OnBtnVocationDel)
ON_BN_CLICKED(IDC_BTN_VOCATION_MOD, OnBtnVocationMod)
ON_NOTIFY(NM_CLICK, IDC_LIST_AREA, OnClickListArea)
ON_NOTIFY(NM_CLICK, IDC_LIST_APPROACH, OnClickListApproach)
ON_NOTIFY(NM_CLICK, IDC_LIST_PROFESSION, OnClickListProfession)
ON_NOTIFY(NM_CLICK, IDC_LIST_VOCATION, OnClickListVocation)
ON_NOTIFY(NM_CLICK, IDC_LIST_HR, OnClickListHr)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHRDBSDlg message handlers
BOOL CHRDBSDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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);
}
}
// 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
InitControl();
ConnectDB();
InitCtrlData();
return TRUE; // return TRUE unless you set the focus to a control
}
void CHRDBSDlg::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 CHRDBSDlg::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 CHRDBSDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CHRDBSDlg::OnSysExit()
{
// TODO: Add your control notification handler code here
if (MessageBox("您确定要退出么?",NULL,MB_OKCANCEL)==IDOK)
{
exit(0);
}
}
void CHRDBSDlg::OnBtnApproachAdd()
{
// TODO: Add your control notification handler code here
if (!UpdateData())
return;
if(m_strConfigApproach.IsEmpty())
return;
TRY
{
CRecordset rs(&m_db);
CString sql;
rs.Open(CRecordset::dynaset,
"select max(approach_id) from approach_info_tab");
int newID=1;
if (!rs.IsEOF())
{
CDBVariant var;
rs.GetFieldValue((short)0,var,SQL_C_SLONG);
if(var.m_dwType !=DBVT_NULL)
newID=var.m_iVal+1;
}
sql.Format("Insert into approach_info_tab(approach_id, "
"approach_name) "
"values("
"%d,'%s')",newID,m_strConfigApproach);
TRACE(sql);
m_db.ExecuteSQL(sql);
InsertConfigItem(&m_listApproach,newID,m_strConfigApproach);
RefreshAreaComboData();
}
CATCH (CDBException, ex)
{
AfxMessageBox(ex->m_strError);
AfxMessageBox(ex->m_strStateNativeOrigin);
}
AND_CATCH(CException, e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox(szError);
}
END_CATCH
}
void CHRDBSDlg::OnBtnApproachDel()
{
// TODO: Add your control notification handler code here
int nItem=m_listApproach.GetNextItem(-1,LVNI_SELECTED);
if(nItem==-1)
{
AfxMessageBox("没有选择要删除的认识途径信息");
return;
}
int id=atoi(m_listApproach.GetItemText(nItem,0));
TRY
{
CString deleteSql;
deleteSql.Format("delete from approach_info_tab where approach_id=%d",id);
m_db.ExecuteSQL(deleteSql);
m_listApproach.DeleteItem(nItem);
RefreshAreaComboData();
}
CATCH (CDBException, ex)
{
AfxMessageBox(ex->m_strError);
AfxMessageBox(ex->m_strStateNativeOrigin);
}
AND_CATCH(CException, e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox(szError);
}
END_CATCH
}
void CHRDBSDlg::OnBtnApproachMod()
{
// TODO: Add your control notification handler code here
if (!UpdateData())
return;
if(m_strConfigApproach.IsEmpty())
return;
int nItem=m_listApproach.GetNextItem(-1,LVNI_SELECTED);
if (nItem==-1)
{
AfxMessageBox("没有选择要修改的认识途径信息");
return;
}
int id=atoi(m_listApproach.GetItemText(nItem,0));
TRY
{
CRecordset rs(&m_db);
CString sql;
sql.Format("update approach_info_tab "
"set approach_name='%s' "
"where approach_id=%d",m_strConfigApproach,id);
TRACE(sql);
m_db.ExecuteSQL(sql);
m_listApproach.SetItemText(nItem,1,m_strConfigApproach);
RefreshAreaComboData();
}
CATCH (CDBException, ex)
{
AfxMessageBox(ex->m_strError);
AfxMessageBox(ex->m_strStateNativeOrigin);
}
AND_CATCH(CException, e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox(szError);
}
END_CATCH
}
void CHRDBSDlg::OnBtnAreaAdd()
{
// TODO: Add your control notification handler code here
if (!UpdateData())
return;
if(m_strConfigArea.IsEmpty())
return;
TRY
{
CRecordset rs(&m_db);
CString sql;
rs.Open(CRecordset::dynaset,
"select max(area_id) from area_info_tab");
int newID=1;
if (!rs.IsEOF())
{
CDBVariant var;
rs.GetFieldValue((short)0,var,SQL_C_SLONG);
if(var.m_dwType !=DBVT_NULL)
newID=var.m_iVal+1;
}
sql.Format("Insert into area_info_tab(area_id, "
"area_name) "
"values("
"%d,'%s')",newID,m_strConfigArea);
TRACE(sql);
m_db.ExecuteSQL(sql);
InsertConfigItem(&m_listArea,newID,m_strConfigArea);
RefreshAreaComboData();
}
CATCH (CDBException, ex)
{
AfxMessageBox(ex->m_strError);
AfxMessageBox(ex->m_strStateNativeOrigin);
}
AND_CATCH(CException, e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox(szError);
}
END_CATCH
}
void CHRDBSDlg::OnBtnAreaDel()
{
// TODO: Add your control notification handler code here
int nItem=m_listArea.GetNextItem(-1,LVNI_SELECTED);
if(nItem==-1)
{
AfxMessageBox("没有选择要删除的地区信息");
return;
}
int id=atoi(m_listArea.GetItemText(nItem,0));
TRY
{
CString deleteSql;
deleteSql.Format("delete from area_info_tab where area_id=%d",id);
m_db.ExecuteSQL(deleteSql);
m_listArea.DeleteItem(nItem);
RefreshAreaComboData();
}
CATCH (CDBException, ex)
{
AfxMessageBox(ex->m_strError);
AfxMessageBox(ex->m_strStateNativeOrigin);
}
AND_CATCH(CException, e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox(szError);
}
END_CATCH
}
void CHRDBSDlg::OnBtnAreaMod()
{
// TODO: Add your control notification handler code here
if (!UpdateData())
return;
if(m_strConfigArea.IsEmpty())
return;
int nItem=m_listArea.GetNextItem(-1,LVNI_SELECTED);
if (nItem==-1)
{
AfxMessageBox("没有选择要修改的地区信息");
return;
}
int id=atoi(m_listArea.GetItemText(nItem,0));
TRY
{
CRecordset rs(&m_db);
CString sql;
sql.Format("update area_info_tab "
"set area_name='%s' "
"where area_id=%d",m_strConfigArea,id);
TRACE(sql);
m_db.ExecuteSQL(sql);
m_listArea.SetItemText(nItem,1,m_strConfigArea);
RefreshAreaComboData();
}
CATCH (CDBException, ex)
{
AfxMessageBox(ex->m_strError);
AfxMessageBox(ex->m_strStateNativeOrigin);
}
AND_CATCH(CException, e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox(szError);
}
END_CATCH
}
void CHRDBSDlg::OnBtnDetailQuery()
{
// TODO: Add your control notification handler code here
CDetailQueryDlg dlg;
dlg.m_pDB=&m_db;
dlg.DoModal();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -