⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dlgldlg.cpp

📁 可以帮助管理员进行图书的采购、销售记录管理
💻 CPP
字号:
// DlglDlg.cpp : implementation file
//

#include "stdafx.h"
#include "图书销售管理系统.h"
#include "DlglDlg.h"
extern CDatabase pDb;//yingyong quanju bianliang

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// DlglDlg dialog


DlglDlg::DlglDlg(CWnd* pParent /*=NULL*/)
	: CDialog(DlglDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(DlglDlg)
		// NOTE: the ClassWizard will add member initialization here
		finddl = _T("");
	//}}AFX_DATA_INIT
}


void DlglDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(DlglDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
		DDX_Control(pDX,IDC_LISTDLGL,lingshoushang);
		DDX_Text(pDX,IDC_EDITchxdl, finddl);
		DDX_Control(pDX,IDC_BUTTONtjdl,m_tjlshsh);
		DDX_Text(pDX,IDC_EDITdllshshxm,m_lingshoushangname);
		DDX_Text(pDX,IDC_EDITdlzhm,m_suozaizhouming);
		DDX_Text(pDX,IDC_EDITdlgj,m_guojia);
		DDX_Text(pDX,IDC_EDITdldh,m_dianhua);

	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(DlglDlg, CDialog)
	//{{AFX_MSG_MAP(DlglDlg)
	ON_BN_CLICKED(IDC_BUTTONchxdl, OnBUTTONchxdl)
	ON_BN_CLICKED(IDC_BUTTONshchdl, OnBUTTONshchdl)
	ON_BN_CLICKED(IDC_BUTTONtjdl, OnBUTTONtjdl)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// DlglDlg message handlers

int DlglDlg::DoModal() 
{
	// TODO: Add your specialized code here and/or call the base class
	
	return CDialog::DoModal();
}

BOOL DlglDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CString strSQL=_T("select * from lingshoushang");
	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));
				lingshoushang.InsertColumn(i,strColTitle[i]);//title[i]);
			 } 

	  CString item[MAX_PATH];
	  CString strField;

	  //显示记录
	  dbset->MoveFirst();
	  for(i=0;i<RecordCount;i++)
	  { 
	   lingshoushang.InsertItem (i,"");
	   for(int j=0;j<FieldCount;j++)
	   {
		dbset->GetFieldValue (j,strField);
		lingshoushang.SetItemText (i,j,strField);
		lingshoushang.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 DlglDlg::OnBUTTONchxdl() 
{
	// TODO: Add your control notification handler code here
	 CString strSQL;
	 UpdateData(TRUE);
	 strSQL.Format("select * from lingshoushang where 零售商姓名='%s'",finddl);
	 lingshoushang.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++)
		  { 
		   lingshoushang.InsertItem (i,"");
		   for(int j=0;j<FieldCount;j++)
		   {
			dbset->GetFieldValue (j,strField);
			lingshoushang.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 DlglDlg::OnBUTTONshchdl() 
{
	// TODO: Add your control notification handler code here
	 CString strSQL;
	 UpdateData(TRUE);
	 strSQL.Format("select * from lingshoushang where 零售商姓名='%s'",finddl);
	 lingshoushang.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 lingshoushang where 零售商姓名='%s'",finddl);
		  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 DlglDlg::OnBUTTONtjdl() 
{
	// TODO: Add your control notification handler code here
	CString strSQL;
	UpdateData(TRUE);
	if(m_lingshoushangname.IsEmpty())
	{
      MessageBox("请添加零售商名称!"); 
	}
	else
   
	{strSQL.Format("insert into lingshoushang values('%s','%s','%s','%s')",
	m_lingshoushangname,m_suozaizhouming,m_guojia,m_dianhua);

	pDb.ExecuteSQL(strSQL);	MessageBox("添加订单记录成功!");//MessageBox();
	}
	m_lingshoushangname="";
	m_suozaizhouming="";
	m_guojia="";
	m_dianhua="";
	UpdateData(FALSE);	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -