?? crdbsdlg.cpp
字號:
// CRDBSDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CRDBS.h"
#include "CRDBSDlg.h"
#include "LoginDlg.h"
#include "DetailQueryDlg.h"
#include "StatQueryDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
CDatabase m_db;
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()
/////////////////////////////////////////////////////////////////////////////
// CCRDBSDlg dialog
CCRDBSDlg::CCRDBSDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCRDBSDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCRDBSDlg)
m_strConfigArea = _T("");
m_strConfigApproach = _T("");
m_strConfigProfession = _T("");
m_strConfigVocation = _T("");
m_strName = _T("");
m_strSelectedArea = _T("");
m_strSelectedProfession = _T("");
m_strSelectedVocation = _T("");
m_strCompany = _T("");
m_strSelectedApproach = _T("");
m_strEmail = _T("");
m_strPhone = _T("");
m_strMobile = _T("");
m_strInterest = _T("");
m_strMemo = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCRDBSDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCRDBSDlg)
DDX_Control(pDX, IDC_COMBO_VOCATION, m_comboVocation);
DDX_Control(pDX, IDC_COMBO_PROFESSION, m_comboProfession);
DDX_Control(pDX, IDC_COMBO_APPROACH, m_comboApproach);
DDX_Control(pDX, IDC_COMBO_AREA, m_comboArea);
DDX_Control(pDX, IDC_LIST_HR, m_listHR);
DDX_Control(pDX, IDC_LIST_VOCATION, m_listVocation);
DDX_Control(pDX, IDC_LIST_PROFESSION, m_listProfession);
DDX_Control(pDX, IDC_LIST_APPROACH, m_listApproach);
DDX_Control(pDX, IDC_LIST_AREA, m_listArea);
DDX_Text(pDX, IDC_EDIT_CONFIG_AREA, m_strConfigArea);
DDX_Text(pDX, IDC_EDIT_CONFIG_APPROACH, m_strConfigApproach);
DDX_Text(pDX, IDC_EDIT_CONFIG_PROFESSION, m_strConfigProfession);
DDX_Text(pDX, IDC_EDIT_CONFIG_VOCATION, m_strConfigVocation);
DDX_Text(pDX, IDC_EDIT_NAME, m_strName);
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_CBString(pDX, IDC_COMBO_APPROACH, m_strSelectedApproach);
DDX_Text(pDX, IDC_EDIT_EMAIL, m_strEmail);
DDX_Text(pDX, IDC_EDIT_PHONE, m_strPhone);
DDX_Text(pDX, IDC_EDIT_MOBILE, m_strMobile);
DDX_Text(pDX, IDC_EDIT_INTEREST, m_strInterest);
DDX_Text(pDX, IDC_EDIT_MEMO, m_strMemo);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCRDBSDlg, CDialog)
//{{AFX_MSG_MAP(CCRDBSDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BTN_AREA_ADD, OnBtnAreaAdd)
ON_BN_CLICKED(IDC_BTN_APPROACH_ADD, OnBtnApproachAdd)
ON_BN_CLICKED(IDC_BTN_PROFESSION_ADD, OnBtnProfessionAdd)
ON_BN_CLICKED(IDC_BTN_VOCATION_ADD, OnBtnVocationAdd)
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_BN_CLICKED(IDC_BTN_AREA_MOD, OnBtnAreaMod)
ON_BN_CLICKED(IDC_BTN_APPROACH_MOD, OnBtnApproachMod)
ON_BN_CLICKED(IDC_BTN_PROFESSION_MOD, OnBtnProfessionMod)
ON_BN_CLICKED(IDC_BTN_VOCATION_MOD, OnBtnVocationMod)
ON_BN_CLICKED(IDC_BTN_AREA_DEL, OnBtnAreaDel)
ON_BN_CLICKED(IDC_BTN_APPROACH_DEL, OnBtnApproachDel)
ON_BN_CLICKED(IDC_BTN_PROFESSION_DEL, OnBtnProfessionDel)
ON_BN_CLICKED(IDC_BTN_VOCATION_DEL, OnBtnVocationDel)
ON_BN_CLICKED(IDC_BTN_HR_ADD, OnBtnHrAdd)
ON_NOTIFY(NM_CLICK, IDC_LIST_HR, OnClickListHr)
ON_BN_CLICKED(IDC_BTN_HR_MOD, OnBtnHrMod)
ON_BN_CLICKED(IDC_BTN_HR_DEL, OnBtnHrDel)
ON_BN_CLICKED(IDC_BTN_HR_QUERY, OnBtnHrQuery)
ON_BN_CLICKED(IDC_BTN_DETAIL_QUERY, OnBtnDetailQuery)
ON_BN_CLICKED(IDC_BTN_STATIC_QUERY, OnBtnStaticQuery)
ON_BN_CLICKED(IDC_SYS_EXIT, OnSysExit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCRDBSDlg message handlers
BOOL CCRDBSDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CLoginDlg login;
if(login.DoModal()!=IDOK) return FALSE;
// 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();
//連接數據庫
//在列表框控件中顯示數據
InitCtrlData();
return TRUE; // return TRUE unless you set the focus to a control
}
void CCRDBSDlg::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 CCRDBSDlg::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 CCRDBSDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCRDBSDlg::InitControl()
{
DWORD dwExStyle=LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|LVS_EX_HEADERDRAGDROP|LVS_EX_ONECLICKACTIVATE|LVS_EX_UNDERLINEHOT;
m_listArea.SetExtendedStyle(dwExStyle);
m_listApproach.SetExtendedStyle(dwExStyle);
m_listProfession.SetExtendedStyle(dwExStyle);
m_listVocation.SetExtendedStyle(dwExStyle);
m_listHR.SetExtendedStyle(dwExStyle);
m_listArea.InsertColumn(0,"地區ID",LVCFMT_CENTER,50);
m_listArea.InsertColumn(1,"地區名稱",LVCFMT_CENTER,90);
m_listApproach.InsertColumn(0,"結識途徑",LVCFMT_CENTER,50);
m_listApproach.InsertColumn(1,"結識途徑名稱",LVCFMT_CENTER,90);
m_listProfession.InsertColumn(0,"職位ID",LVCFMT_CENTER,50);
m_listProfession.InsertColumn(1,"職位名稱",LVCFMT_CENTER,90);
m_listVocation.InsertColumn(0,"行業ID",LVCFMT_CENTER,50);
m_listVocation.InsertColumn(1,"行業名稱",LVCFMT_CENTER,90);
m_listHR.InsertColumn(0,"客戶電話",LVCFMT_CENTER,60);
m_listHR.InsertColumn(1,"姓名",LVCFMT_CENTER,80);
m_listHR.InsertColumn(2,"所在地區",LVCFMT_CENTER,80);
m_listHR.InsertColumn(3,"職業",LVCFMT_CENTER,80);
m_listHR.InsertColumn(4,"行業",LVCFMT_CENTER,80);
m_listHR.InsertColumn(5,"所在單位",LVCFMT_CENTER,80);
m_listHR.InsertColumn(6,"結識途徑",LVCFMT_CENTER,80);
m_listHR.InsertColumn(7,"E-mail",LVCFMT_CENTER,80);
m_listHR.InsertColumn(8,"固定電話",LVCFMT_CENTER,80);
m_listHR.InsertColumn(9,"移動電話",LVCFMT_CENTER,80);
m_listHR.InsertColumn(10,"愛好",LVCFMT_CENTER,80);
m_listHR.InsertColumn(11,"說明",LVCFMT_CENTER,140);
}
void CCRDBSDlg::InsertConfigItem(CListCtrl *pList, int id, CString name)
{
int nIndex=pList->GetItemCount();
LV_ITEM lvItem;
lvItem.mask=LVIF_TEXT;
lvItem.iItem=nIndex;
lvItem.iSubItem=0;
CString temp;
temp.Format("%d",id);
lvItem.pszText=(char*)(LPCTSTR)temp;
pList->InsertItem(&lvItem);
pList->SetItemText(nIndex,1,name);
}
void CCRDBSDlg::InsertHRInfoItem(int id, CString name, CString area, CString prof, CString voc, CString com, CString appr, CString email, CString phone, CString mobile, CString interest, CString memo)
{
int nIndex=m_listHR.GetItemCount();
LV_ITEM lvItem;
lvItem.mask=LVIF_TEXT;
lvItem.iItem=nIndex;
lvItem.iSubItem=0;
CString temp;
temp.Format("%d",id);
lvItem.pszText=(char*)(LPCTSTR)temp;
m_listHR.InsertItem(&lvItem);
m_listHR.SetItemText(nIndex,1,name);
m_listHR.SetItemText(nIndex,2,area);
m_listHR.SetItemText(nIndex,3,prof);
m_listHR.SetItemText(nIndex,4,voc);
m_listHR.SetItemText(nIndex,5,com);
m_listHR.SetItemText(nIndex,6,appr);
m_listHR.SetItemText(nIndex,7,email);
m_listHR.SetItemText(nIndex,8,phone);
m_listHR.SetItemText(nIndex,9,mobile);
m_listHR.SetItemText(nIndex,10,interest);
m_listHR.SetItemText(nIndex,11,memo);
}
void CCRDBSDlg::InitCtrlData()
{
if(!m_db.IsOpen())
{
MessageBox("數據庫未打開");
return;
}
TRY
{
CRecordset rs(&m_db);
rs.Open(CRecordset::dynaset,"select * from area_info_tab order by area_id");
while(!rs.IsEOF())
{
int id;
CString area;
CDBVariant var;
rs.GetFieldValue((short)0,var,SQL_C_SLONG);
if(var.m_dwType!=DBVT_NULL)
id=var.m_iVal;
var.Clear();
rs.GetFieldValue(1,area);
InsertConfigItem(&m_listArea,id,area);
rs.MoveNext();
}
rs.Close();
rs.Open(CRecordset::dynaset,"select * from approach_info_tab order by approach_id");
while(!rs.IsEOF())
{
int id;
CString approach;
CDBVariant var;
rs.GetFieldValue((short)0,var,SQL_C_SLONG);
if(var.m_dwType!=DBVT_NULL)
id=var.m_iVal;
var.Clear();
rs.GetFieldValue(1,approach);
InsertConfigItem(&m_listApproach,id,approach);
rs.MoveNext();
}
rs.Close();
rs.Open(CRecordset::dynaset,"select * from profession_info_tab order by profession_id");
while(!rs.IsEOF())
{
int id;
CString profession;
CDBVariant var;
rs.GetFieldValue((short)0,var,SQL_C_SLONG);
if(var.m_dwType!=DBVT_NULL)
id=var.m_iVal;
var.Clear();
rs.GetFieldValue(1,profession);
InsertConfigItem(&m_listProfession,id,profession);
rs.MoveNext();
}
rs.Close();
rs.Open(CRecordset::dynaset,"select * from vocation_info_tab order by vocation_id");
while(!rs.IsEOF())
{
int id;
CString vocation;
CDBVariant var;
rs.GetFieldValue((short)0,var,SQL_C_SLONG);
if(var.m_dwType!=DBVT_NULL)
id=var.m_iVal;
var.Clear();
rs.GetFieldValue(1,vocation);
InsertConfigItem(&m_listVocation,id,vocation);
rs.MoveNext();
}
rs.Close();
rs.Open(CRecordset::dynaset,"select * from customer_info_tab order by id");
while(!rs.IsEOF())
{
int id;
CString name,area,profession,vocation,company;
CString approach,email,phone,mobile,interest,memo;
CDBVariant var;
rs.GetFieldValue((short)0,var,SQL_C_SLONG);
if(var.m_dwType!=DBVT_NULL)
id=var.m_iVal;
var.Clear();
rs.GetFieldValue(1,name);
rs.GetFieldValue(2,area);
rs.GetFieldValue(3,profession);
rs.GetFieldValue(4,vocation);
rs.GetFieldValue(5,company);
rs.GetFieldValue(6,approach);
rs.GetFieldValue(7,email);
rs.GetFieldValue(8,phone);
rs.GetFieldValue(9,mobile);
rs.GetFieldValue(10,interest);
rs.GetFieldValue(11,memo);
InsertHRInfoItem(id,name,area,profession,vocation,company,approach,email,phone,mobile,interest,memo);
rs.MoveNext();
}
rs.Close();
RefreshAreaComboData();
RefreshApprComboData();
RefreshProfComboData();
RefreshVocComboData();
}
CATCH(CDBException,ex)
{
AfxMessageBox(ex->m_strError);
AfxMessageBox(ex->m_strStateNativeOrigin);
}
AND_CATCH(CMemoryException,pEx)
{
pEx->ReportError();
AfxMessageBox("memory exception");
}
AND_CATCH(CException,e)
{
TCHAR szError[100];
e->GetErrorMessage(szError,100);
AfxMessageBox(szError);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -