📄 khgl.cpp
字号:
// Khgl.cpp : implementation file
//
#include "stdafx.h"
#include "图书销售管理系统.h"
#include "Khgl.h"
extern CDatabase pDb;//yingyong quanju bianliang
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CKhgl dialog
CKhgl::CKhgl(CWnd* pParent /*=NULL*/)
: CDialog(CKhgl::IDD, pParent)
{
//{{AFX_DATA_INIT(CKhgl)
// NOTE: the ClassWizard will add member initialization here
findkh = _T("");
//}}AFX_DATA_INIT
}
void CKhgl::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CKhgl)
// NOTE: the ClassWizard will add DDX and DDV calls here
DDX_Control(pDX,IDC_LISTKHGL,custom);
DDX_Text(pDX,IDC_EDITchxkh, findkh);
DDX_Control(pDX,IDC_BUTTONtjkh,m_tjkh);
DDX_Text(pDX,IDC_EDITkhkhmch,m_kehuname);
DDX_Text(pDX,IDC_EDITkhzhm,m_kehuzhouming);
DDX_Text(pDX,IDC_EDITkhdh,m_khdianhua);
DDX_Text(pDX,IDC_EDITkhshf,m_khshf);
DDX_Text(pDX,IDC_EDITkhgj,m_khguojia);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CKhgl, CDialog)
//{{AFX_MSG_MAP(CKhgl)
ON_BN_CLICKED(IDC_BUTTONchxkh, OnBUTTONchxkh)
ON_BN_CLICKED(IDC_BUTTONshchkh, OnBUTTONshchkh)
ON_BN_CLICKED(IDC_BUTTONtjkh, OnBUTTONtjkh)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKhgl message handlers
int CKhgl::DoModal()
{
// TODO: Add your specialized code here and/or call the base class
return CDialog::DoModal();
}
BOOL CKhgl::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CString strSQL=_T("select * from custom");
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));
custom.InsertColumn(i,strColTitle[i]);//title[i]);
}
CString item[MAX_PATH];
CString strField;
//显示记录
dbset->MoveFirst();
for(i=0;i<RecordCount;i++)
{
custom.InsertItem (i,"");
for(int j=0;j<FieldCount;j++)
{
dbset->GetFieldValue (j,strField);
custom.SetItemText (i,j,strField);
custom.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 CKhgl::OnBUTTONchxkh()
{
// TODO: Add your control notification handler code here
CString strSQL;
UpdateData(TRUE);
strSQL.Format("select * from custom where 客户名称='%s'",findkh);
custom.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++)
{
custom.InsertItem (i,"");
for(int j=0;j<FieldCount;j++)
{
dbset->GetFieldValue (j,strField);
custom.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 CKhgl::OnBUTTONshchkh()
{
// TODO: Add your control notification handler code here
CString strSQL;
UpdateData(TRUE);
strSQL.Format("select * from custom where 客户名称='%s'",findkh);
custom.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 custom where 客户名称='%s'",findkh);
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 CKhgl::OnBUTTONtjkh()
{
// TODO: Add your control notification handler code here
CString strSQL;
UpdateData(TRUE);
if(m_kehuname.IsEmpty())
{
MessageBox("请添加客户名称!");
}
else
{strSQL.Format("insert into custom values('%s','%s','%s','%s','%s')",
m_kehuname,m_kehuzhouming,m_khguojia,m_khdianhua,m_khshf);
pDb.ExecuteSQL(strSQL); MessageBox("添加订单记录成功!");//MessageBox();
}
m_kehuname="";
m_kehuzhouming="";
m_khguojia="";
m_khdianhua="";
m_khshf="";
UpdateData(FALSE);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -