📄 bmgldlg.cpp
字号:
// BmglDlg.cpp : implementation file
//
#include "stdafx.h"
#include "图书销售管理系统.h"
#include "BmglDlg.h"
extern CDatabase pDb;//yingyong quanju bianliang
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBmglDlg dialog
CBmglDlg::CBmglDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBmglDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBmglDlg)
// NOTE: the ClassWizard will add member initialization here
findbm = _T("");
//}}AFX_DATA_INIT
}
void CBmglDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBmglDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
DDX_Control(pDX,IDC_LISTBMGL,saledepartment);
DDX_Text(pDX, IDC_EDITchxbm, findbm);
DDX_Control(pDX,IDC_BUTTONtjbm,m_tjbm);
DDX_Text(pDX,IDC_EDITbmmch, m_departmentname);
DDX_Text(pDX,IDC_EDITbmlshsh,m_lingshoushangname);
DDX_Text(pDX,IDC_EDITbmkc, m_kucun);
DDX_Text(pDX,IDC_EDITbmchb, m_changben);
DDX_Text(pDX,IDC_EDITbmjg, m_jiage);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBmglDlg, CDialog)
//{{AFX_MSG_MAP(CBmglDlg)
ON_BN_CLICKED(IDC_BUTTONchxbm, OnBUTTONchxbm)
ON_BN_CLICKED(IDC_BUTTONshchbm, OnBUTTONshchbm)
ON_BN_CLICKED(IDC_BUTTONtjbm, OnBUTTONtjbm)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBmglDlg message handlers
int CBmglDlg::DoModal()
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::DoModal();
}
BOOL CBmglDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString strSQL=_T("select * from saledepartment");
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));
saledepartment.InsertColumn(i,strColTitle[i]);//title[i]);
}
CString item[MAX_PATH];
CString strField;
//显示记录
dbset->MoveFirst();
for(i=0;i<RecordCount;i++)
{
saledepartment.InsertItem (i,"");
for(int j=0;j<FieldCount;j++)
{
dbset->GetFieldValue (j,strField);
saledepartment.SetItemText (i,j,strField);
saledepartment.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 CBmglDlg::OnBUTTONchxbm()
{
// TODO: Add your control notification handler code here
CString strSQL;
UpdateData(TRUE);
findbm="%"+findbm+"%";
// MessageBox(findbm);
strSQL.Format("select * from saledepartment where departmentname like '%s'",findbm);
saledepartment.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);
if(!dbset->GetRecordCount())
{
MessageBox("No Record!");
return;
}
//统计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++)
{
saledepartment.InsertItem (i,"");
for(int j=0;j<FieldCount;j++)
{
dbset->GetFieldValue (j,strField);
saledepartment.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 CBmglDlg::OnBUTTONshchbm()
{
// TODO: Add your control notification handler code here
CString strSQL;
UpdateData(TRUE);
strSQL.Format("select * from saledepartment where departmentname='%s'",findbm);
saledepartment.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 saledepartment where departmentname='%s'",findbm);
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 CBmglDlg::OnBUTTONtjbm()
{
// TODO: Add your control notification handler code here
CString strSQL;
UpdateData(TRUE);
if(m_departmentname.IsEmpty())
{
MessageBox("请添加部门名称!");
}
else
{strSQL.Format("insert into saledepartment values('%s','%s','%s','%s','%s')",
m_departmentname,m_lingshoushangname,m_kucun, m_changben,m_jiage);
pDb.ExecuteSQL(strSQL); MessageBox("添加部门记录成功!");//MessageBox();
}
m_departmentname="";
m_lingshoushangname="";
m_kucun="";
m_changben="";
m_jiage="";
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -