【VC开源代码栏目提醒】:网学会员为广大网友收集整理了,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("sa");
m_strServer = _T("127.0.0.1");
m_strUser = _T("sa");
//}}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)
{
//获取当前的纪录条数.
int nIndex = pList->GetItemCount();
LV_ITEM lvItem;
lvItem.mask = LVIF_TEXT ;
lvItem.iItem = nIndex; //行数
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);
//建立数据库的连接和加载数据
if(g_adoDB.Open(sql) == TRUE)
InitCtrlData();
}
void CConfigView::InitCtrlData()
{
m_listInType.DeleteAllItems();
m_listExpType.DeleteAllItems();
CDStrs InFields,ExpFields;
//获取收入类型数据
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]);
}
//获取支出类型数据
g_adoDB.ExecuteQuery("Select * from exp_type_tab order by id",ExpFields);
for(int 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("数据库未打开");
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("数据库未打开");
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("数据库未打开");
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("数据库未打开");
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 cod
上一篇:
ConfigINIDlg.cpp
下一篇:
高职院理实一体信息技术论文