?? configview.cpp
字號:
// ConfigView.cpp : implementation file
//
#include "stdafx.h"
#include "FinanceMIS.h"
#include "ConfigView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CConfigView
IMPLEMENT_DYNCREATE(CConfigView, CFormView)
CConfigView::CConfigView()
: CFormView(CConfigView::IDD)
{
//{{AFX_DATA_INIT(CConfigView)
m_strDBName = _T("FinanceDB");
m_strExpType = _T("");
m_strInType = _T("");
m_strPwd = _T("dbFin");
m_strServer = _T("LLITTLEMARK\\SQLDB");
m_strUser = _T("dbFin");
//}}AFX_DATA_INIT
}
CConfigView::~CConfigView()
{
}
void CConfigView::DoDataExchange(CDataExchange* pDX)
{
CFormView::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CConfigView)
DDX_Control(pDX, IDC_LIST_IN, m_listInType);
DDX_Control(pDX, IDC_LIST_EXP, m_listExpType);
DDX_Text(pDX, IDC_EDIT_DB, m_strDBName);
DDX_Text(pDX, IDC_EDIT_EXP, m_strExpType);
DDX_Text(pDX, IDC_EDIT_IN, m_strInType);
DDX_Text(pDX, IDC_EDIT_PWD, m_strPwd);
DDX_Text(pDX, IDC_EDIT_SERVER, m_strServer);
DDX_Text(pDX, IDC_EDIT_USER, m_strUser);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CConfigView, CFormView)
//{{AFX_MSG_MAP(CConfigView)
ON_BN_CLICKED(IDC_BTN_DBCON, OnBtnDbcon)
ON_BN_CLICKED(IDC_BTN_IN_ADD, OnBtnInAdd)
ON_BN_CLICKED(IDC_BTN_IN_MOD, OnBtnInMod)
ON_BN_CLICKED(IDC_BTN_IN_DEL, OnBtnInDel)
ON_BN_CLICKED(IDC_BTN_EXP_ADD, OnBtnExpAdd)
ON_BN_CLICKED(IDC_BTN_EXP_MOD, OnBtnExpMod)
ON_BN_CLICKED(IDC_BTN_EXP_DEL, OnBtnExpDel)
ON_NOTIFY(NM_CLICK, IDC_LIST_EXP, OnClickListExp)
ON_NOTIFY(NM_CLICK, IDC_LIST_IN, OnClickListIn)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CConfigView diagnostics
#ifdef _DEBUG
void CConfigView::AssertValid() const
{
CFormView::AssertValid();
}
void CConfigView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CConfigView message handlers
void CConfigView::InitControl()
{
//設置列表框控件擴展風格
DWORD dwExStyle = LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES |
LVS_EX_HEADERDRAGDROP | LVS_EX_ONECLICKACTIVATE | LVS_EX_UNDERLINEHOT;
m_listInType.SetExtendedStyle(dwExStyle);
m_listExpType.SetExtendedStyle(dwExStyle);
//初始化收入類型列表框控件
m_listInType.InsertColumn(0,"收入類型ID",LVCFMT_CENTER,80);
m_listInType.InsertColumn(1,"收入類型名稱",LVCFMT_CENTER,200);
//初始化支出類型列表框控件
m_listExpType.InsertColumn(0,"支出類型ID",LVCFMT_CENTER,80);
m_listExpType.InsertColumn(1,"支出類型名稱",LVCFMT_CENTER,200);
}
void CConfigView::InsertTypeItem(CListCtrl* pList, CString id, CString name)
{
//獲取當前的紀錄條數(shù).
int nIndex = pList->GetItemCount();
LV_ITEM lvItem;
lvItem.mask = LVIF_TEXT ;
lvItem.iItem = nIndex; //行數(shù)
lvItem.iSubItem = 0;
lvItem.pszText = (char*)(LPCTSTR)id; //第一列
//在最后一行插入記錄值.
pList->InsertItem(&lvItem);
//設置該行的其他列的值.
pList->SetItemText(nIndex,1,name);
}
void CConfigView::OnBtnDbcon()
{
// TODO: Add your control notification handler code here
CString sql;
sql.Format("Provider=SQLOLEDB.1;Password=%s;"
"Persist Security Info=True;User ID=%s;"
"Initial Catalog=%s;Data Source=%s",
m_strPwd,m_strUser,m_strDBName,m_strServer);
//建立數(shù)據(jù)庫的連接和加載數(shù)據(jù)
if(g_adoDB.Open(sql) == TRUE)
InitCtrlData();
}
void CConfigView::InitCtrlData()
{
m_listInType.DeleteAllItems();
m_listExpType.DeleteAllItems();
CDStrs InFields,ExpFields;
//獲取收入類型數(shù)據(jù)
g_adoDB.ExecuteQuery("Select * from in_type_tab order by id",InFields);
for(int i = 0 ; i < InFields.size() ; i++)
{
CStrs strs = InFields[i];
InsertTypeItem(&m_listInType,strs[0],strs[1]);
}
//獲取支出類型數(shù)據(jù)
g_adoDB.ExecuteQuery("Select * from exp_type_tab order by id",ExpFields);
for(i = 0 ; i < ExpFields.size() ; i++)
{
CStrs strs = ExpFields[i];
InsertTypeItem(&m_listExpType,strs[0],strs[1]);
}
}
void CConfigView::OnBtnInAdd()
{
// TODO: Add your control notification handler code here
if(!UpdateData())
return;
if(!g_adoDB.IsOpen()){
AfxMessageBox("數(shù)據(jù)庫未打開");
return;
}
if(m_strInType.IsEmpty())
return;
CString strID ;
//獲取最大的收入類型ID
g_adoDB.ExecuteQueryValue("Select max(id) "
"from in_type_tab",strID);
int newID = atoi(strID)+1;
//插入新的類型信息
CString sql ;
sql.Format("Insert into in_type_tab(id,"
"name) "
"VALUES("
"%d,'%s')",newID,m_strInType);
g_adoDB.Execute(sql);
InsertTypeItem(&m_listInType,Int2Str(newID),m_strInType);
}
void CConfigView::OnBtnInMod()
{
// TODO: Add your control notification handler code here
if(!g_adoDB.IsOpen()){
AfxMessageBox("數(shù)據(jù)庫未打開");
return;
}
if(!UpdateData())
return;
//獲取要修改類型信息
int nItem = m_listInType.GetNextItem(-1, LVNI_SELECTED);
if(nItem != -1){
//獲取要修改的收入類型ID.
CString id = m_listInType.GetItemText(nItem,0);
CString sql;
//更新收入類型信息.
sql.Format("update in_type_tab "
"set name = '%s' "
"where id = %d",m_strInType,atoi(id));
TRACE(sql);
g_adoDB.Execute(sql);
m_listInType.SetItemText(nItem,1,m_strInType);
}
}
void CConfigView::OnBtnInDel()
{
if(!g_adoDB.IsOpen()){
AfxMessageBox("數(shù)據(jù)庫未打開");
return;
}
int nItem = m_listInType.GetNextItem(-1, LVNI_SELECTED);
if(nItem == -1){
AfxMessageBox("沒有選定要刪除的收入類型信息");
return;
}
//獲取選擇的收入類型ID.
int id = atoi(m_listInType.GetItemText(nItem,0));
CString sql;
//刪除選擇的收入類型信息
sql.Format("delete from in_type_tab where id = %d",id);
g_adoDB.Execute(sql);
m_listInType.DeleteItem(nItem);
}
void CConfigView::OnBtnExpAdd()
{
// TODO: Add your control notification handler code here
if(!UpdateData())
return;
if(!g_adoDB.IsOpen()){
AfxMessageBox("數(shù)據(jù)庫未打開");
return;
}
if(m_strExpType.IsEmpty())
return;
CString strID ;
//獲取最大的支出類型ID
g_adoDB.ExecuteQueryValue("Select max(id) "
"from exp_type_tab",strID);
int newID = atoi(strID)+1;
//插入新的類型信息
CString sql ;
sql.Format("Insert into exp_type_tab(id,"
"name) "
"VALUES("
"%d,'%s')",newID,m_strExpType);
g_adoDB.Execute(sql);
InsertTypeItem(&m_listExpType,Int2Str(newID),m_strExpType);
}
void CConfigView::OnBtnExpMod()
{
// TODO: Add your control notification handler code here
if(!g_adoDB.IsOpen()){
AfxMessageBox("數(shù)據(jù)庫未打開");
return;
}
if(!UpdateData())
return;
//獲取要修改類型信息
int nItem = m_listExpType.GetNextItem(-1, LVNI_SELECTED);
if(nItem != -1){
//獲取要修改的支出類型ID.
CString id = m_listExpType.GetItemText(nItem,0);
CString sql;
//更新支出類型信息.
sql.Format("update exp_type_tab "
"set name = '%s' "
"where id = %d",m_strExpType,atoi(id));
TRACE(sql);
g_adoDB.Execute(sql);
m_listExpType.SetItemText(nItem,1,m_strExpType);
}
}
void CConfigView::OnBtnExpDel()
{
if(!g_adoDB.IsOpen()){
AfxMessageBox("數(shù)據(jù)庫未打開");
return;
}
int nItem = m_listExpType.GetNextItem(-1, LVNI_SELECTED);
if(nItem == -1){
AfxMessageBox("沒有選定要刪除的支出類型信息");
return;
}
//獲取選擇的支出類型ID.
int id = atoi(m_listExpType.GetItemText(nItem,0));
CString sql;
//刪除選擇的支出類型信息
sql.Format("delete from exp_type_tab where id = %d",id);
g_adoDB.Execute(sql);
m_listExpType.DeleteItem(nItem);
}
void CConfigView::OnInitialUpdate()
{
CFormView::OnInitialUpdate();
//初始化列表框控件
InitControl();
}
void CConfigView::OnClickListExp(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int nItem = m_listExpType.GetNextItem(-1, LVNI_SELECTED);
if(nItem != -1){
//從列表框控件中獲取選擇的類型信息.
CString name = m_listExpType.GetItemText(nItem,1);
//將選擇的類型信息顯示到收入類型文本框中
GetDlgItem(IDC_EDIT_EXP)->SetWindowText(name);
}
*pResult = 0;
}
void CConfigView::OnClickListIn(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int nItem = m_listInType.GetNextItem(-1, LVNI_SELECTED);
if(nItem != -1){
//從列表框控件中獲取選擇的類型信息.
CString name = m_listInType.GetItemText(nItem,1);
//將選擇的類型信息顯示到收入類型文本框中
GetDlgItem(IDC_EDIT_IN)->SetWindowText(name);
}
*pResult = 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -