📄 inexpview.cpp
字号:
// InExpView.cpp : implementation file
//
#include "stdafx.h"
#include "FinanceMIS.h"
#include "InExpView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CInExpView
IMPLEMENT_DYNCREATE(CInExpView, CFormView)
CInExpView::CInExpView()
: CFormView(CInExpView::IDD)
{
//{{AFX_DATA_INIT(CInExpView)
m_nTypeSelected = 0;
m_dtInfo = COleDateTime::GetCurrentTime();
m_strDescrip = _T("");
m_dbMoney = 0.0;
//}}AFX_DATA_INIT
}
CInExpView::~CInExpView()
{
}
void CInExpView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CInExpView)
DDX_Control(pDX, IDC_LIST_INFO, m_listInfo);
DDX_Radio(pDX, IDC_RADIO1, m_nTypeSelected);
DDX_Control(pDX, IDC_COMBO_TYPE, m_datacomboType);
DDX_DateTimeCtrl(pDX, IDC_DT_INFO, m_dtInfo);
DDX_Text(pDX, IDC_EDIT_DESCRIP, m_strDescrip);
DDX_Text(pDX, IDC_EDIT_MONEY, m_dbMoney);
DDX_Control(pDX, IDC_ADODC1, m_adoCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CInExpView, CFormView)
//{{AFX_MSG_MAP(CInExpView)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_BTN_ADD, OnBtnAdd)
ON_BN_CLICKED(IDC_BTN_DEL, OnBtnDel)
ON_BN_CLICKED(IDC_BTN_REFRESH, OnBtnRefresh)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CInExpView diagnostics
#ifdef _DEBUG
void CInExpView::AssertValid() const
{
CFormView::AssertValid();
}
void CInExpView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CInExpView message handlers
void CInExpView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
if(m_nTypeSelected == 0)
OnRadio1();
else
OnRadio2();
}
BEGIN_EVENTSINK_MAP(CInExpView, CFormView)
//{{AFX_EVENTSINK_MAP(CInExpView)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CInExpView::InitControl()
{
//设置列表框控件扩展风格
DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES |
LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE | LVS_EX_UNDERLINEHOT;
m_listInfo.SetExtendedStyle(dwExStyle);
//初始收支信息列表框控件
m_listInfo.InsertColumn(0,"ID",LVCFMT_CENTER,80);
m_listInfo.InsertColumn(1,"日期",LVCFMT_CENTER,80);
m_listInfo.InsertColumn(2,"收入/支出",LVCFMT_CENTER,80);
m_listInfo.InsertColumn(3,"名称",LVCFMT_CENTER,100);
m_listInfo.InsertColumn(4,"金额",LVCFMT_CENTER,100);
m_listInfo.InsertColumn(5,"说明",LVCFMT_CENTER,120);
}
VOID CInExpView::InsertCtrlItem(CString item0,CString item1,CString item2, CString item3,CString item4,CString item5)
{
//获取当前的纪录条数.
int nIndex = m_listInfo.GetItemCount();
LV_ITEM lvItem;
lvItem.mask = LVIF_TEXT ;
lvItem.iItem = nIndex; //行数
lvItem.iSubItem = 0;
lvItem.pszText = (char*)(LPCTSTR)item0; //第一列
//在最后一行插入记录值.
m_listInfo.InsertItem(&lvItem);
//设置该行的其他列的值.
m_listInfo.SetItemText(nIndex,1,item1);
m_listInfo.SetItemText(nIndex,2,item2);
m_listInfo.SetItemText(nIndex,3,item3);
m_listInfo.SetItemText(nIndex,4,item4);
m_listInfo.SetItemText(nIndex,5,item5);
}
void CInExpView::InitCtrlData()
{
if(!g_adoDB.IsOpen())
return;
m_listInfo.DeleteAllItems();
CDStrs ixFields;
//获取收支信息表数据
g_adoDB.ExecuteQuery("Select * from in_exp_info_tab order by ix_date ",ixFields);
for(int i = 0 ; i < ixFields.size() ; i++)
{
CStrs strs = ixFields[i];
InsertCtrlItem(strs[0],strs[1].Left(10),strs[2]=="0"?"收入":"支出",
strs[3],strs[4],strs[5]);
}
}
void CInExpView::OnRadio1()
{
// TODO: Add your control notification handler code here
m_adoCtrl.SetRecordSource("select * from in_type_tab");
m_adoCtrl.Refresh();
m_datacomboType.SetListField("name");
m_datacomboType.Refresh();
m_nTypeSelected = 0 ;
}
void CInExpView::OnRadio2()
{
// TODO: Add your control notification handler code here
m_adoCtrl.SetRecordSource("select * from exp_type_tab");
m_adoCtrl.Refresh();
m_datacomboType.SetListField("name");
m_datacomboType.Refresh();
m_nTypeSelected = 1;
}
void CInExpView::OnBtnAdd()
{
// TODO: Add your control notification handler code here
if(!g_adoDB.IsOpen()){
AfxMessageBox("数据库未打开");
return;
}
if(!UpdateData())
return;
CString type = m_datacomboType.GetText();
if(type.IsEmpty()){
AfxMessageBox("请选择收入或支出的类型");
return;
}
CString strID ;
//获取最大的收支信息ID
g_adoDB.ExecuteQueryValue("Select max(ix_id) "
"from in_exp_info_tab",strID);
int newID = atoi(strID)+1;
//插入新的收支信息
CString strDT = m_dtInfo.Format("%Y-%m-%d");
CString sql ;
sql.Format("Insert into in_exp_info_tab(ix_id,"
"ix_date,ix_type,ix_name,money,description)"
" VALUES("
"%d,'%s',%d,'%s',%.2f,'%s')",
newID,strDT,m_nTypeSelected,type,m_dbMoney,m_strDescrip);
g_adoDB.Execute(sql);
InsertCtrlItem(Int2Str(newID),strDT,m_nTypeSelected==0?"收入":"支出",
type,float2Str(m_dbMoney),m_strDescrip);
}
void CInExpView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
//初始化列表框控件
InitControl();
InitCtrlData();
}
void CInExpView::OnBtnDel()
{
if(!g_adoDB.IsOpen()){
AfxMessageBox("数据库未打开");
return;
}
int nItem = m_listInfo.GetNextItem(-1, LVNI_SELECTED);
if(nItem == -1){
AfxMessageBox("没有选定要删除的收支信息");
return;
}
//获取选择的收支信息ID.
int id = atoi(m_listInfo.GetItemText(nItem,0));
CString sql;
//删除选择的收支信息
sql.Format("delete from in_exp_info_tab where ix_id = %d",id);
g_adoDB.Execute(sql);
m_listInfo.DeleteItem(nItem);
}
void CInExpView::OnBtnRefresh()
{
// TODO: Add your control notification handler code here
InitCtrlData();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -