?? ccdlg.cpp
字號:
// ccDlg.cpp : implementation file
//
#include "stdafx.h"
#include "cc.h"
#include "ccDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
extern CCcApp theApp;
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)
virtual BOOL OnInitDialog();
//}}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)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCcDlg dialog
CCcDlg::CCcDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCcDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCcDlg)
m_radio = -1;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCcDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCcDlg)
DDX_Control(pDX, IDC_RADIO4, m_radio4);
DDX_Control(pDX, IDC_LIST, m_listmsg);
DDX_Radio(pDX, IDC_RADIO4, m_radio);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCcDlg, CDialog)
//{{AFX_MSG_MAP(CCcDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_LOGON, OnButtonLogon)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit)
ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
ON_BN_CLICKED(IDC_BUTTON_SEARCH, OnButtonSearch)
ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
ON_BN_CLICKED(IDC_RADIO5, OnRadio4)
ON_BN_CLICKED(IDC_RADIO6, OnRadio4)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCcDlg message handlers
BOOL CCcDlg::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
//設(shè)置list控件的文字和背景顏色
m_listmsg.SetBkColor(RGB(240,247,233));
m_listmsg.SetTextBkColor(RGB(240,247,233));
//清空list控件的數(shù)據(jù)
for(int delcolumn=100;delcolumn>=0;delcolumn--)
m_listmsg.DeleteColumn(delcolumn);
//設(shè)置list對話框的列
DWORD dwStyle;
RECT rect;
LV_COLUMN lvc;
dwStyle = m_listmsg.GetStyle();
dwStyle |= LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS ;
m_listmsg.SetExtendedStyle(dwStyle);
m_listmsg.GetClientRect(&rect);
lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH |LVCF_FMT;
lvc.fmt=LVCFMT_LEFT;
lvc.iSubItem = 0;
lvc.pszText = _T("報銷");
lvc.cx = 40;
m_listmsg.InsertColumn(1,&lvc);
lvc.iSubItem = 1;
lvc.pszText = _T("出 差 醫(yī) 院");
lvc.cx = 120;
m_listmsg.InsertColumn(2,&lvc);
lvc.iSubItem = 2;
lvc.pszText = _T("科 室");
lvc.cx = 60;
m_listmsg.InsertColumn(3,&lvc);
lvc.iSubItem = 3;
lvc.pszText = _T(" 事 由 ");
lvc.cx = 220;
m_listmsg.InsertColumn(4,&lvc);
lvc.iSubItem = 4;
lvc.pszText = _T("開始日期");
lvc.cx = 60;
m_listmsg.InsertColumn(5,&lvc);
lvc.iSubItem = 5;
lvc.pszText = _T("結(jié)束日期");
lvc.cx = 60;
m_listmsg.InsertColumn(6,&lvc);
lvc.iSubItem = 6;
lvc.pszText = _T("備 注");
lvc.cx = 100;
m_listmsg.InsertColumn(7,&lvc);
//設(shè)置顯示所有記錄的按鈕為選中狀態(tài)。
m_radio4.SetCheck(1);
//顯示彈出的登錄框。
SetTimer(1,1,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void CCcDlg::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 CCcDlg::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 CCcDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CCcDlg::OnOK()
{
// TODO: Add extra validation here
CDialog::OnOK();
}
void CCcDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
//此函數(shù)用于用戶登錄框的彈出
#include "Logon.h"
void CCcDlg::OnButtonLogon()
{
// TODO: Add your control notification handler code here
//得到按鈕的字符
CString title;
GetDlgItemText(IDC_BUTTON_LOGON,title);
//如果字符為登錄則彈出登錄對話框
if(title=="登 錄")
{
CLogon dlglogon;
if(dlglogon.DoModal()==IDOK)
{
CString sql="SELECT * FROM cc where name='"+theApp.name+"'";
//使其它控件有效
GetDlgItem(IDC_BUTTON_ADD)->EnableWindow();
GetDlgItem(IDC_BUTTON_EDIT)->EnableWindow();
GetDlgItem(IDC_BUTTON_DEL)->EnableWindow();
GetDlgItem(IDC_BUTTON_SEARCH)->EnableWindow();
GetDlgItem(IDC_RADIO4)->EnableWindow();
GetDlgItem(IDC_RADIO5)->EnableWindow();
GetDlgItem(IDC_RADIO6)->EnableWindow();
GetDlgItem(IDC_LIST)->EnableWindow();
//使登錄按鈕變成注銷用戶按鈕
SetDlgItemText(IDC_BUTTON_LOGON,"注銷用戶");
//設(shè)置標(biāo)題
SetWindowText("出差記錄 V1.0 by lqp 登錄者:"+theApp.name);
//設(shè)顯示所有記錄的按鈕為選中狀態(tài)。
m_radio4.SetCheck(1);
//顯示此用戶的數(shù)據(jù)
ReadtoList(sql);
}
}
else if(title=="注銷用戶")
{
if(!(AfxMessageBox("真的要注銷嗎?",MB_YESNO)==IDYES))
return;
GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_EDIT)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_DEL)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_SEARCH)->EnableWindow(false);
GetDlgItem(IDC_RADIO4)->EnableWindow(false);
GetDlgItem(IDC_RADIO5)->EnableWindow(false);
GetDlgItem(IDC_RADIO6)->EnableWindow(false);
GetDlgItem(IDC_LIST)->EnableWindow(false);
theApp.name="";
theApp.pwd="";
m_listmsg.DeleteAllItems();
SetDlgItemText(IDC_BUTTON_LOGON,"登 錄");
SetWindowText("出差記錄 V1.0 by lqp 未登錄...");
}
}
//此函數(shù)用于顯示sql語句查詢出來的數(shù)據(jù)顯示到list控件中
void CCcDlg::ReadtoList(CString sql)
{
//刪除所有l(wèi)ist中的數(shù)據(jù)。
m_listmsg.DeleteAllItems();
int numline=0;
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(m_pRecordset->adoEOF)
{
;//AfxMessageBox("你的數(shù)據(jù)庫中還沒有出差記錄信息!");
}
else
{
LV_ITEM lvitem;
lvitem.pszText="";
lvitem.mask=LVIF_TEXT;
lvitem.iSubItem=0;
while(!m_pRecordset->adoEOF)
{
lvitem.iItem=numline;
m_listmsg.InsertItem(&lvitem);
//讀出數(shù)據(jù)寫入到list中
m_listmsg.SetItemText(numline,0,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("staus"));
m_listmsg.SetItemText(numline,1,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("adrr"));
m_listmsg.SetItemText(numline,2,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("ks"));
m_listmsg.SetItemText(numline,3,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("whatdo"));
m_listmsg.SetItemText(numline,4,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("date1"));
m_listmsg.SetItemText(numline,5,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("date2"));
m_listmsg.SetItemText(numline,6,(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("dome"));
numline++;
m_pRecordset->MoveNext();
}
}
m_pRecordset->Close();
}
catch(_com_error e)///捕捉異常
{
CString temp;
temp.Format("連接數(shù)據(jù)庫錯誤信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
//設(shè)置標(biāo)題
CString temp;
temp.Format("出差記錄 V1.0 by lqp 登錄者:%s [共有%d條記錄]",theApp.name,numline);
SetWindowText(temp);
}
//添加出差記錄
#include "Add.h"
void CCcDlg::OnButtonAdd()
{
// TODO: Add your control notification handler code here
//得到系統(tǒng)時間
CString nowtime;
CTime now=CTime::GetCurrentTime();
nowtime=now.Format(_T("%Y%m%d"));
CAdd dlgadd;
//轉(zhuǎn)遞用戶名到此對話框中
dlgadd.m_name=theApp.name;
dlgadd.dowhat=1;
dlgadd.m_date1=nowtime;
dlgadd.m_date2=nowtime;
dlgadd.DoModal();
//列出此用戶的記錄
CString sql="SELECT * FROM cc where name='"+theApp.name+"'";
ReadtoList(sql);
}
//查詢記錄
#include "Search.h"
void CCcDlg::OnButtonSearch()
{
//得到系統(tǒng)時間
CString sql,nowtime;
CTime now=CTime::GetCurrentTime();
nowtime=now.Format(_T("%Y%m%d"));
CSearch dlgsearch;
dlgsearch.m_1=nowtime;
dlgsearch.m_2=nowtime;
dlgsearch.DoModal();
//利用查詢框得到動態(tài)sql語句,列出查詢結(jié)果
sql="SELECT * FROM cc where name='"+theApp.name+"' and date1>='"+dlgsearch.m_1+"' and date2<='"+dlgsearch.m_2+"'";
ReadtoList(sql);
}
//雙擊list控件的函數(shù)
void CCcDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
//得到當(dāng)前選中的行
POSITION pos = m_listmsg.GetFirstSelectedItemPosition();
//如果選中一行
if(pos)
{
int nItem = m_listmsg.GetNextSelectedItem(pos);
CAdd dlgadd;
dlgadd.dowhat=2;
dlgadd.bx=false;
//轉(zhuǎn)遞數(shù)據(jù)到修改對話框中
if(m_listmsg.GetItemText(nItem,0)=="--")
dlgadd.bx=true;
dlgadd.m_name =theApp.name;
dlgadd.m_adrr =m_listmsg.GetItemText(nItem,1);
dlgadd.m_ks =m_listmsg.GetItemText(nItem,2);
dlgadd.m_whatdo =m_listmsg.GetItemText(nItem,3);
dlgadd.m_date1 =m_listmsg.GetItemText(nItem,4);
dlgadd.m_date2 =m_listmsg.GetItemText(nItem,5);
dlgadd.m_dome =m_listmsg.GetItemText(nItem,6);
//dlgadd.m_date1.
dlgadd.DoModal();
//列出用戶的數(shù)據(jù)
CString sql="SELECT * FROM cc where name='"+theApp.name+"'";
ReadtoList(sql);
}
else
AfxMessageBox("請選擇一行數(shù)據(jù)!");
*pResult = 0;
}
//修改用戶出差記錄,同void CCcDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult) 一樣。
void CCcDlg::OnButtonEdit()
{
// TODO: Add your control notification handler code here
//m_listmsg.GetItemText(1,1,temp,1);
POSITION pos = m_listmsg.GetFirstSelectedItemPosition();
if(pos)
{
int nItem = m_listmsg.GetNextSelectedItem(pos);
CAdd dlgadd;
dlgadd.dowhat=2;
dlgadd.m_name =theApp.name;
dlgadd.m_adrr =m_listmsg.GetItemText(nItem,1);
dlgadd.m_ks =m_listmsg.GetItemText(nItem,2);
dlgadd.m_whatdo =m_listmsg.GetItemText(nItem,3);
dlgadd.m_date1 =m_listmsg.GetItemText(nItem,4);
dlgadd.m_date2 =m_listmsg.GetItemText(nItem,5);
dlgadd.m_dome =m_listmsg.GetItemText(nItem,6);
//dlgadd.m_date1.
dlgadd.DoModal();
CString sql="SELECT * FROM cc where name='"+theApp.name+"'";
ReadtoList(sql);
}
else
AfxMessageBox("請選擇一行數(shù)據(jù)!");}
//刪除一條記錄
void CCcDlg::OnButtonDel()
{
CString sql;
POSITION pos = m_listmsg.GetFirstSelectedItemPosition();
//如果選中一行,則生成動態(tài)的sql語句
if(pos)
{
int nItem = m_listmsg.GetNextSelectedItem(pos);
sql="delete from cc where name='"+theApp.name+"' and adrr='"
+m_listmsg.GetItemText(nItem,1)+"' and ks='"
+m_listmsg.GetItemText(nItem,2)+"' and whatdo='"
+m_listmsg.GetItemText(nItem,3)+"' and date1='"
+m_listmsg.GetItemText(nItem,4)+"' and date2='"
+m_listmsg.GetItemText(nItem,5)+"' and dome='"
+m_listmsg.GetItemText(nItem,6)+"'";
_variant_t RecordsAffected;
//執(zhí)行此sql語句
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
AfxMessageBox("成功刪除此條數(shù)據(jù)!");
//顯示用戶數(shù)據(jù)
CString sql="SELECT * FROM cc where name='"+theApp.name+"'";
ReadtoList(sql);
}
else
AfxMessageBox("請選擇一行數(shù)據(jù)!");
}
//顯示三種的狀態(tài)。
//0:顯示所有記錄
//1:顯示未報銷記錄
//2:顯示已報銷記錄
void CCcDlg::OnRadio4()
{
// TODO: Add your control notification handler code here
UpdateData();
CString sql;
switch(m_radio)
{
case 0:
sql="SELECT * FROM cc where name='"+theApp.name+"'";
break;
case 1:
sql="SELECT * FROM cc where name='"+theApp.name+"' and staus='--'";
break;
case 2:
sql="SELECT * FROM cc where name='"+theApp.name+"' and staus='√'";
break;
default:
AfxMessageBox("error!");
}
//根據(jù)上面的動態(tài)生成的sql語句列出數(shù)據(jù)
ReadtoList(sql);
}
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//時間
void CCcDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
if(nIDEvent==1)
{
KillTimer(1);
//到登錄函數(shù)
OnButtonLogon();
}
CDialog::OnTimer(nIDEvent);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -