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

📄 productviewdlg1.cpp

📁 本程序乃是一个简单的登陆连接
💻 CPP
字号:
// ProductViewDlg1.cpp : implementation file
//

#include "stdafx.h"
#include "Mproduct.h"
#include "add.h"

#include "ProductViewDlg1.h"
#include <afxdb.h>

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

/////////////////////////////////////////////////////////////////////////////
// CProductViewDlg1 dialog


CProductViewDlg1::CProductViewDlg1(CWnd* pParent /*=NULL*/)
	: CDialog(CProductViewDlg1::IDD, pParent)
{
	//{{AFX_DATA_INIT(CProductViewDlg1)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CProductViewDlg1::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CProductViewDlg1)
	DDX_Control(pDX, IDC_LIST1, m_view);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CProductViewDlg1, CDialog)
	//{{AFX_MSG_MAP(CProductViewDlg1)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
//	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CProductViewDlg1 message handlers



BOOL CProductViewDlg1::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_view.InsertColumn(0, "商品编号", LVCFMT_RIGHT,84);//第0列
    m_view.InsertColumn(1, "商品名称", LVCFMT_LEFT,83);//第1列

           

    m_view.SetExtendedStyle(LVS_EX_FULLROWSELECT);
    m_view.DeleteAllItems();
	CDatabase pDatabase  ;  
    pDatabase.OpenEx(_T("DSN=product"), CDatabase::noOdbcDialog);  
    CRecordset pRecordset(&pDatabase);//
    CString strSQL;
    strSQL = "select * from tb_product ";  
    pRecordset.Open(CRecordset::dynaset,strSQL); 
             
	int i=0;

    while (!pRecordset.IsEOF() )
       {

          CString pid, pname, price,number;

          pRecordset.GetFieldValue("pId", pid);
          pRecordset.GetFieldValue("pName", pname);

          m_view.InsertItem(i,  pid);  //插入第0列
          m_view.SetItemText(i, 1, pname);  // 插入第1列

          pRecordset.MoveNext();
          i++;
 
       }       

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CProductViewDlg1::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here

}


void CProductViewDlg1::OnButton1() 
{
	// TODO: Add your control notification handler code here
	int nSelected=-1;
    nSelected=m_view.GetNextItem(nSelected,LVNI_SELECTED);
    if(nSelected>=0)
    {
		if( MessageBox("你确定要删除该商品吗?","删除商品",MB_YESNO)==IDYES)
		 {
			  CDatabase     pDatabase  ;   
			  pDatabase.OpenEx(_T("DSN=product"),  CDatabase::noOdbcDialog); 
			  CString pid = m_view.GetItemText(nSelected,NULL); 
			  CString strSQL;
			  strSQL.Format("delete from tb_product where pid = \'%s\' ", pid) ;
			  pDatabase.ExecuteSQL(strSQL);
			  m_view.DeleteItem(nSelected);
			  MessageBox("商品删除成功!");
		  }
    }

}


⌨️ 快捷键说明

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