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

📄 consumer.cpp

📁 这是一个不错的商店管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// consumer.cpp : implementation file
//

#include "stdafx.h"
#include "shop.h"
#include "consumer.h"

#include <time.h>
#include <fstream.h>

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CShopApp theApp;
/////////////////////////////////////////////////////////////////////////////
// Cconsumer dialog

struct tm *ptrstudent;
Cconsumer::Cconsumer(CWnd* pParent /*=NULL*/)
	: CDialog(Cconsumer::IDD, pParent)
{
	//{{AFX_DATA_INIT(Cconsumer)
	m_condition = _T("");
	m_consumername = _T("");
	m_consumerno = _T("");
	m_leftmoney = _T("");
	m_mode = _T("");
	m_telephone = _T("");
	m_address = _T("");
	//}}AFX_DATA_INIT
}


void Cconsumer::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cconsumer)
	DDX_Control(pDX, IDC_USERLIST, m_userlist);
	DDX_Text(pDX, IDC_condition, m_condition);
	DDX_Text(pDX, IDC_consumername, m_consumername);
	DDX_Text(pDX, IDC_consumerno, m_consumerno);
	DDX_Text(pDX, IDC_leftmoney, m_leftmoney);
	DDX_CBString(pDX, IDC_mode, m_mode);
	DDX_Text(pDX, IDC_telephone, m_telephone);
	DDX_Text(pDX, IDC_address, m_address);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cconsumer, CDialog)
	//{{AFX_MSG_MAP(Cconsumer)
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_USERLIST, OnItemchangedUserlist)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cconsumer message handlers

BOOL Cconsumer::OnInitDialog() 
{
	CDialog::OnInitDialog();

	time_t lt;
	 lt = time(NULL);
	 ptrstudent = localtime(&lt);
	
	// TODO: Add extra initialization here
	::SendMessage(m_userlist.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);//当被选中时,所有子项都处于选中状态
	//////////为列表控件添加列//////////

	m_userlist.InsertColumn(0,"顾客编号",LVCFMT_LEFT,100);
	m_userlist.InsertColumn(1,"顾客名称",LVCFMT_LEFT,100);
    m_userlist.InsertColumn (2,"余额",LVCFMT_LEFT,100);
	m_userlist.InsertColumn(3,"地址",LVCFMT_LEFT,100);
	m_userlist.InsertColumn(4,"电话",LVCFMT_LEFT,100);
	 

	//////////读取数据库中的信息添加到列表控件///////////
	displayintheuserlist();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void Cconsumer::displayintheuserlist()
{
	//////////读取数据库中的信息添加到列表控件///////////
	

	try
	{
		
		m_userlist.DeleteAllItems();
		m_pRecordset.CreateInstance("ADODB.Recordset");
		m_pRecordset->Open("select  *  from consumer order by consumerno",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
	    
		
	
		//m_bSuccess = TRUE;
		while(!m_pRecordset->adoEOF)
		{
			 
			vconsumerno= m_pRecordset->GetCollect("consumerno");
			vconsumername= m_pRecordset->GetCollect("consumername");
			vleftmoney= m_pRecordset->GetCollect("leftmoney");
			vaddress = m_pRecordset->GetCollect("address");
			vtelephone= m_pRecordset->GetCollect("telephone");
			
			 
			 
			
			//this->AbleFalse();
	     	//this->LoadData();
			//this->GetDlgItem(IDC_BUTTON4)->EnableWindow(FALSE);
			//this->GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
			nItem=m_userlist.InsertItem(0xffff,(_bstr_t)vconsumerno);//先插第一个项
			m_userlist.SetItem(nItem,1,1,(_bstr_t)vconsumername,NULL,0,0,0);
			m_userlist.SetItem(nItem,2,1,(_bstr_t)vleftmoney,NULL,0,0,0);
			m_userlist.SetItem(nItem,3,1,(_bstr_t)vaddress ,NULL,0,0,0);
			m_userlist.SetItem(nItem,4,1,(_bstr_t)vtelephone ,NULL,0,0,0);
			 
			 
			

			m_pRecordset->MoveNext();
		}
	}
	catch(_com_error e)///捕捉异常
	{
		//AfxMessageBox("读取数据库失败!");///显示错误信息
	}
}

void Cconsumer::OnItemchangedUserlist(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if(pNMListView->uNewState&LVIS_SELECTED)
	{
	//UpdateData(true);
	//SaveData();///保存旧数据
	m_nCurrentSel = pNMListView->iItem;
	LoadData0();///加载新数据
	//m_cdelitem.EnableWindow();
	
	}	
	*pResult = 0;
}

void Cconsumer::LoadData0()
{
	m_pRecordset.CreateInstance("ADODB.Recordset");
	m_pRecordset->Open("select  *  from consumer order by consumerno",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
	   

    
	m_pRecordset->Move(m_nCurrentSel,_variant_t((long)adBookmarkFirst));//从第一条记录移动
	 
	vconsumerno = m_pRecordset->GetCollect("consumerno");
	vconsumername = m_pRecordset->GetCollect("consumername");
	vleftmoney = m_pRecordset->GetCollect("leftmoney");
	vaddress = m_pRecordset->GetCollect("address");
	vtelephone = m_pRecordset->GetCollect("telephone");
	 
	 
    UpdateData(true);//使得控件显示值
	//m_num = vNum.lVal;
//	m_name = (LPCTSTR)(_bstr_t)vName;
	//m_sex = vSex.lVal;
///	m_brithday = vBrithday.lVal;
	//m_tel=vTel.lVal;
	//m_addr=vAddr.lVal;


	 
	m_consumerno= (LPCTSTR)(_bstr_t)vconsumerno;
	m_consumername = (LPCTSTR)(_bstr_t)vconsumername;
	m_leftmoney = (LPCTSTR)(_bstr_t)vleftmoney;
	m_address = (LPCTSTR)(_bstr_t)vaddress;
	m_telephone= (LPCTSTR)(_bstr_t)vtelephone;
	 
	 
    //m_pRecordset->Move(m_nCurrentSel,_variant_t((long)adBookmarkFirst));//从第一条记录移动
	UpdateData(FALSE);//使得控件显示值

}

void Cconsumer::OnButton1() 
{
	//bool judge;
	//judge = false;

	UpdateData(true);//把控件的值传给相应的变量
	     if (m_consumerno == "" || m_consumername == "")
		 {
	   		 AfxMessageBox("顾客编号或顾客名称不能为空!!");
             goto tiaozhuan;
		 }
         
		 //UpdateData(true);//把控件的值传给相应的变量
        //m_pRecordset1->Close();
		 //m_pRecordset1 = NULL;

		   m_pRecordset.CreateInstance(_uuidof(Recordset));//
	       m_pRecordset->Open("select * from consumer",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
          
		 
	try
	   {
		
		   
	   	m_pRecordset->AddNew();
		
		 
	    vconsumerno = m_consumerno;
	    vconsumername = m_consumername;
		vleftmoney = m_leftmoney;
	    vaddress = m_address;
		vtelephone = m_telephone;
	     
	     
        //UpdateData(true);

		 
		m_pRecordset->PutCollect("consumerno",vconsumerno);
		m_pRecordset->PutCollect("consumername",vconsumername);
		m_pRecordset->PutCollect("leftmoney",vleftmoney);
		m_pRecordset->PutCollect("address",vaddress);
		m_pRecordset->PutCollect("telephone",vtelephone);
		 
		 
		

		//UpdateData(true);
                  
		 //m_pRecordset.CreateInstance("ADODB.Recordset");
		 //m_pRecordset->Open("insert into employee values(empno,empname,sex,salary,duty,deptno,birthday,address,telephone,remark)  ",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
	     
        //AfxMessageBox("添加记录成功!");

		 m_pRecordset->Update();
		 
		 m_pRecordset->Close();
		 m_pRecordset = NULL;
		 
		 //重建指针,以备下次添加记录时使用     
         //m_pRecordset1.CreateInstance(_uuidof(Recordset));//
	     //m_pRecordset1->Open("select * from employee",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
         
         displayintheuserlist();
		 
         AfxMessageBox("添加记录成功!");

⌨️ 快捷键说明

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