📄 dlglose.cpp
字号:
// DlgLose.cpp : implementation file
//
#include "stdafx.h"
#include "ShoolCard.h"
#include "DlgLose.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgLose dialog
CDlgLose::CDlgLose(CWnd* pParent /*=NULL*/)
: CDialog(CDlgLose::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgLose)
m_strStudentId = _T("");
m_bByCard = -1;
m_bByStudent = -1;
//}}AFX_DATA_INIT
}
void CDlgLose::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgLose)
DDX_Control(pDX, IDC_BUTTON_UNLOSE, m_btnUnlose);
DDX_Control(pDX, IDC_BUTTON_LOSE, m_btnLose);
DDX_Control(pDX, IDC_LIST1, m_ListControl);
DDX_Control(pDX, IDC_MSCOMM1, m_ComPort);
DDX_Text(pDX, IDC_EDIT_STUDENT_ID, m_strStudentId);
DDX_Radio(pDX, IDC_RADIO_BY_CARD, m_bByCard);
DDX_Radio(pDX, IDC_RADIO_BY_STUDENT, m_bByStudent);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgLose, CDialog)
//{{AFX_MSG_MAP(CDlgLose)
ON_BN_CLICKED(IDC_RADIO_BY_CARD, OnRadioByCard)
ON_BN_CLICKED(IDC_RADIO_BY_STUDENT, OnRadioByStudent)
ON_WM_KEYUP()
ON_BN_CLICKED(IDC_BUTTON_LOSE, OnButtonLose)
ON_BN_CLICKED(IDC_BUTTON_UNLOSE, OnButtonUnlose)
ON_BN_CLICKED(IDC_BUTTON_QUERY, OnButtonQuery)
ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgLose message handlers
BOOL CDlgLose::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
InitListView();
//初始化为按员工号查询
m_bByStudent = true;
UpdateData(VAR2CON);//更新控件
ConfigButtons();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgLose::InitListView()
{
m_ListControl.InsertColumn(0,"卡号");
m_ListControl.InsertColumn(1,"学号");
m_ListControl.InsertColumn(2,"发卡日");
m_ListControl.InsertColumn(3,"金额");
m_ListControl.InsertColumn(4,"状态");
m_ListControl.SetColumnWidth(0,90);
m_ListControl.SetColumnWidth(1,150);
m_ListControl.SetColumnWidth(2,100);
m_ListControl.SetColumnWidth(3,120);
m_ListControl.SetColumnWidth(4,50);
}
void CDlgLose::FillListView(CCard& card)
{
ASSERT(card.IsOpen());
//删除老的显示数据
m_ListControl.DeleteAllItems();
//没有数据需要显示
if(card.GetRecordCount() <= 0) return ;
int nRow = 0;
card.MoveFirst();
while(!card.IsEOF())
{
m_ListControl.InsertItem(nRow,"");
m_ListControl.SetItemText(nRow,0,card.m_card_id);
m_ListControl.SetItemText(nRow,1,card.m_user_id);
m_ListControl.SetItemText(nRow,2,card.m_create_date.Format("%B %d, %Y"));
CString str;
str.Format("%f",card.m_money);
m_ListControl.SetItemText(nRow,3,str);
if(card.m_state == "0")
m_ListControl.SetItemText(nRow,4,"正常");
else if(card.m_state == "1")
m_ListControl.SetItemText(nRow,4,"挂失");
else
m_ListControl.SetItemText(nRow,4,"未知");
nRow++;
card.MoveNext();
}
}
void CDlgLose::OnRadioByCard()
{
// TODO: Add your control notification handler code here
UpdateData(CON2VAR);
if(m_bByCard)
{
CWnd *pWnd = GetDlgItem(IDC_STATIC1);
pWnd->SetWindowText("按卡号");
pWnd = GetDlgItem(IDC_RADIO_BY_CARD);
pWnd->SetFocus();
}
}
void CDlgLose::OnRadioByStudent()
{
// TODO: Add your control notification handler code here
UpdateData(CON2VAR);
if(m_bByStudent)
{
CWnd *pWnd = GetDlgItem(IDC_STATIC1);
pWnd->SetWindowText("按学号");
pWnd = GetDlgItem(IDC_RADIO_BY_STUDENT);
pWnd->SetFocus();
}
}
void CDlgLose::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnKeyUp(nChar, nRepCnt, nFlags);
}
short int CDlgLose::FindCard()
{
UpdateData(CON2VAR);
CString str;
if(m_bByStudent == 0)
str = "user_id = '" + m_strStudentId + "'";
else if(m_bByCard == 0)
str = "card_id = '" + m_strStudentId + "'";
else
return -2;
m_Card.m_strFilter = str;
if(m_Card.IsOpen()) m_Card.Close();
if(!m_Card.Open()) return -1;
//if(!m_Card.IsOpen()) m_Card.Open();
this->FillListView(m_Card);
//更新用户界面
ConfigButtons();
return 1;
}
void CDlgLose::ConfigButtons()
{
int nIndex = m_ListControl.GetNextItem(-1, LVNI_SELECTED);
if(nIndex == -1)
{
m_btnLose.EnableWindow(false);
m_btnUnlose.EnableWindow(false);
}
else
{
CString str;
str = m_ListControl.GetItemText(nIndex,4);
if(str == "正常")
{
m_btnLose.EnableWindow(true);
m_btnUnlose.EnableWindow(false);
}
else if(str == "挂失")
{
m_btnLose.EnableWindow(false);
m_btnUnlose.EnableWindow(true);
}
else
{
m_btnLose.EnableWindow(true);
m_btnUnlose.EnableWindow(true);
}
}
}
void CDlgLose::OnButtonLose()
{
// TODO: Add your control notification handler code here
if(!m_Card.IsOpen()||m_Card.GetRecordCount() <= 0) return;
int nIndex = m_ListControl.GetNextItem(-1, LVNI_SELECTED);
if(nIndex < 0) return;
CString strMsg;
strMsg = m_ListControl.GetItemText(nIndex,0);
int nRet = MessageBox("要将卡号为" + strMsg + "的卡挂失吗?",
"挂失确认",MB_ICONQUESTION|MB_OKCANCEL);
//用户确认
if (nRet!=1) return;
m_Card.MoveFirst();
m_Card.Move(nIndex);
m_Card.Edit();
m_Card.m_state = "1";
m_Card.Update();
this->FillListView(m_Card);
MessageBox("卡号" + strMsg + "的卡挂失成功!");
}
void CDlgLose::OnButtonUnlose()
{
// TODO: Add your control notification handler code here
if(!m_Card.IsOpen()||m_Card.GetRecordCount() <= 0) return;
int nIndex = m_ListControl.GetNextItem(-1, LVNI_SELECTED);
if(nIndex < 0) return;
CString strMsg;
strMsg = m_ListControl.GetItemText(nIndex,0);
int nRet = MessageBox("要将卡号为" + strMsg + "的卡解挂吗?",
"解挂确认",MB_ICONQUESTION|MB_OKCANCEL);
//用户确认要将卡解挂
if (nRet!=1) return;
m_Card.MoveFirst();
m_Card.Move(nIndex);
m_Card.Edit();
m_Card.m_state = "0";
m_Card.Update();
this->FillListView(m_Card);
MessageBox("卡号" + strMsg + "的卡解挂成功!");
}
void CDlgLose::OnButtonQuery()
{
FindCard();
}
void CDlgLose::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
//更新用户界面
ConfigButtons();
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -