📄 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
//设置list控件的文字和背景颜色
m_listmsg.SetBkColor(RGB(240,247,233));
m_listmsg.SetTextBkColor(RGB(240,247,233));
//清空list控件的数据
for(int delcolumn=100;delcolumn>=0;delcolumn--)
m_listmsg.DeleteColumn(delcolumn);
//设置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("出 差 医 院");
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("结束日期");
lvc.cx = 60;
m_listmsg.InsertColumn(6,&lvc);
lvc.iSubItem = 6;
lvc.pszText = _T("备 注");
lvc.cx = 100;
m_listmsg.InsertColumn(7,&lvc);
//设置显示所有记录的按钮为选中状态。
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();
}
//此函数用于用户登录框的弹出
#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,"注销用户");
//设置标题
SetWindowText("出差记录 V1.0 by lqp 登录者:"+theApp.name);
//设显示所有记录的按钮为选中状态。
m_radio4.SetCheck(1);
//显示此用户的数据
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 未登录...");
}
}
//此函数用于显示sql语句查询出来的数据显示到list控件中
void CCcDlg::ReadtoList(CString sql)
{
//删除所有list中的数据。
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("你的数据库中还没有出差记录信息!");
}
else
{
LV_ITEM lvitem;
lvitem.pszText="";
lvitem.mask=LVIF_TEXT;
lvitem.iSubItem=0;
while(!m_pRecordset->adoEOF)
{
lvitem.iItem=numline;
m_listmsg.InsertItem(&lvitem);
//读出数据写入到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("连接数据库错误信息:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
//设置标题
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
//得到系统时间
CString nowtime;
CTime now=CTime::GetCurrentTime();
nowtime=now.Format(_T("%Y%m%d"));
CAdd dlgadd;
//转递用户名到此对话框中
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()
{
//得到系统时间
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();
//利用查询框得到动态sql语句,列出查询结果
sql="SELECT * FROM cc where name='"+theApp.name+"' and date1>='"+dlgsearch.m_1+"' and date2<='"+dlgsearch.m_2+"'";
ReadtoList(sql);
}
//双击list控件的函数
void CCcDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
//得到当前选中的行
POSITION pos = m_listmsg.GetFirstSelectedItemPosition();
//如果选中一行
if(pos)
{
int nItem = m_listmsg.GetNextSelectedItem(pos);
CAdd dlgadd;
dlgadd.dowhat=2;
dlgadd.bx=false;
//转递数据到修改对话框中
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();
//列出用户的数据
CString sql="SELECT * FROM cc where name='"+theApp.name+"'";
ReadtoList(sql);
}
else
AfxMessageBox("请选择一行数据!");
*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("请选择一行数据!");}
//删除一条记录
void CCcDlg::OnButtonDel()
{
CString sql;
POSITION pos = m_listmsg.GetFirstSelectedItemPosition();
//如果选中一行,则生成动态的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;
//执行此sql语句
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
AfxMessageBox("成功删除此条数据!");
//显示用户数据
CString sql="SELECT * FROM cc where name='"+theApp.name+"'";
ReadtoList(sql);
}
else
AfxMessageBox("请选择一行数据!");
}
//显示三种的状态。
//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!");
}
//根据上面的动态生成的sql语句列出数据
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);
//到登录函数
OnButtonLogon();
}
CDialog::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -