📄 spmldlg.cpp
字号:
// SpmlDlg.cpp : implementation file
//
#include "stdafx.h"
#include "图书销售管理系统.h"
#include "SpmlDlg.h"
extern CDatabase pDb;//yingyong quanju bianliang
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSpmlDlg dialog
CSpmlDlg::CSpmlDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSpmlDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSpmlDlg)
// NOTE: the ClassWizard will add member initialization here
findtsh = _T("");
//}}AFX_DATA_INIT
}
void CSpmlDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSpmlDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
DDX_Control(pDX,IDC_LISTSPML,booklist);
DDX_Text(pDX,IDC_EDITchxml, findtsh);
DDX_Control(pDX,IDC_BUTTONtjml,m_tjtsh);
DDX_Text(pDX,IDC_EDITmlshm,m_tshname);
DDX_Text(pDX,IDC_EDITmlbm,m_bmname);
DDX_Text(pDX,IDC_EDITmlzhk,m_tshzhk);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSpmlDlg, CDialog)
//{{AFX_MSG_MAP(CSpmlDlg)
ON_BN_CLICKED(IDC_BUTTONchxml, OnBUTTONchxml)
ON_BN_CLICKED(IDC_BUTTONshchml, OnBUTTONshchml)
ON_BN_CLICKED(IDC_BUTTONtjml, OnBUTTONtjml)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSpmlDlg message handlers
int CSpmlDlg::DoModal()
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::DoModal();
}
BOOL CSpmlDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString strSQL=_T("select * from booklist");
CRecordset* dbset=new CRecordset(&pDb);
TRY
{
if(!pDb.IsOpen ())
AfxMessageBox("Open dsnName Error.");//m_databaseinfo);
else
{
dbset->Open(CRecordset::dynaset,strSQL,CRecordset::readOnly);
//统计table信息
short FieldCount=dbset->GetODBCFieldCount();
do
{
dbset->MoveNext();
}
while (!dbset->IsEOF());
long RecordCount=dbset->GetRecordCount();
CString title[MAX_PATH]={""};
CODBCFieldInfo fieldinfo;
CStringArray strColTitle;
if(!dbset->IsBOF())
dbset->MoveFirst();
if(strColTitle.GetSize())
strColTitle.RemoveAll();
//显示列标题(字段名)
for(int i=0;i<FieldCount;i++)
{
dbset->GetODBCFieldInfo(i,fieldinfo);
strColTitle.Add(LPCTSTR(fieldinfo.m_strName));
booklist.InsertColumn(i,strColTitle[i]);//title[i]);
}
CString item[MAX_PATH];
CString strField;
//显示记录
dbset->MoveFirst();
for(i=0;i<RecordCount;i++)
{
booklist.InsertItem (i,"");
for(int j=0;j<FieldCount;j++)
{
dbset->GetFieldValue (j,strField);
booklist.SetItemText (i,j,strField);
booklist.SetColumnWidth (j,LVSCW_AUTOSIZE);
}
dbset->MoveNext ();
}
dbset->Close ();
delete dbset;
}
}
CATCH(CDBException, e)
{
dbset->Close ();
delete dbset;
CString strTip=_T("Database operate Fail!\n");
strTip+=_T("Because:\n")+e->m_strError;
AfxMessageBox(strTip);
}
END_CATCH
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSpmlDlg::OnBUTTONchxml()
{
// TODO: Add your control notification handler code here
CString strSQL;
UpdateData(TRUE);
strSQL.Format("select * from booklist where 图书名称='%s'",findtsh);
booklist.DeleteAllItems();
//MessageBox(strSQL);
CRecordset* dbset=new CRecordset(&pDb);
TRY
{
if(!pDb.IsOpen ())
AfxMessageBox("Open dsnName Error.");//m_databaseinfo);
else
{
dbset->Open(CRecordset::dynaset,strSQL,CRecordset::readOnly);
//统计table信息
short FieldCount=dbset->GetODBCFieldCount();
long RecordCount=dbset->GetRecordCount();
CString title[MAX_PATH]={""};
CODBCFieldInfo fieldinfo;
CStringArray strColTitle;
if(!dbset->IsBOF())
dbset->MoveFirst();
if(strColTitle.GetSize())
strColTitle.RemoveAll();
CString item[MAX_PATH];
CString strField;
//显示记录
dbset->MoveFirst();
for(int i=0;i<RecordCount;i++)
{
booklist.InsertItem (i,"");
for(int j=0;j<FieldCount;j++)
{
dbset->GetFieldValue (j,strField);
booklist.SetItemText (i,j,strField);
}
dbset->MoveNext ();
}
dbset->Close ();
delete dbset;
}
}
CATCH(CDBException, e)
{
dbset->Close ();
delete dbset;
CString strTip=_T("Database operate Fail!\n");
strTip+=_T("Because:\n")+e->m_strError;
AfxMessageBox(strTip);
}
END_CATCH
}
void CSpmlDlg::OnBUTTONshchml()
{
// TODO: Add your control notification handler code here
CString strSQL;
UpdateData(TRUE);
strSQL.Format("select * from booklist where 图书名称='%s'",findtsh);
booklist.DeleteAllItems();
//MessageBox(strSQL);
CRecordset* dbset=new CRecordset(&pDb);
TRY
{
if(!pDb.IsOpen ())
AfxMessageBox("Open dsnName Error.");//m_databaseinfo
else
{
dbset->Open(CRecordset::dynaset,strSQL,CRecordset::readOnly);
//统计table信息
short FieldCount=dbset->GetODBCFieldCount();
long RecordCount=dbset->GetRecordCount();
CString title[MAX_PATH]={""};
CODBCFieldInfo fieldinfo;
CStringArray strColTitle;
if(!dbset->IsBOF())
dbset->MoveFirst();
if(strColTitle.GetSize())
strColTitle.RemoveAll();
CString item[MAX_PATH];
CString strField;
strSQL.Format("delete from booklist where 图书名称='%s'",findtsh);
pDb.ExecuteSQL(strSQL);
MessageBox("此图书信息已删除~_~");
dbset->Close ();
delete dbset;
}
}
CATCH(CDBException, e)
{
dbset->Close ();
delete dbset;
CString strTip=_T("Database operate Fail!\n");
strTip+=_T("Because:\n")+e->m_strError;
AfxMessageBox(strTip);
}
END_CATCH
}
void CSpmlDlg::OnBUTTONtjml()
{
// TODO: Add your control notification handler code here
CString strSQL;
UpdateData(TRUE);
if(m_tshname.IsEmpty())
{
MessageBox("请添加图书名称!");
}
else
{strSQL.Format("insert into booklist values('%s','%s','%s')",
m_tshname,m_bmname,m_tshzhk);
pDb.ExecuteSQL(strSQL); MessageBox("添加图书记录成功!");//MessageBox();
}
m_tshname="";
m_bmname="";
m_tshzhk="";
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -