www.pudn.com > shangdianguanlixitong.rar > good.cpp, change:2005-06-21,size:15800b


// good.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "shop.h" 
#include "good.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
extern CShopApp theApp; 
 
///////////////////////////////////////////////////////////////////////////// 
// Cgood dialog 
 
 
Cgood::Cgood(CWnd* pParent /*=NULL*/) 
	: CDialog(Cgood::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(Cgood) 
	m_deptno = _T(""); 
	m_goodname = _T(""); 
	m_goodno = _T(""); 
	m_provideprice = _T(""); 
	m_sellprice = _T(""); 
	m_unit = _T(""); 
	m_mode = _T(""); 
	m_condition = _T(""); 
	//}}AFX_DATA_INIT 
} 
 
 
void Cgood::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(Cgood) 
	DDX_Control(pDX, IDC_USERLIST, m_userlist); 
	DDX_Text(pDX, IDC_deptno, m_deptno); 
	DDX_Text(pDX, IDC_goodname, m_goodname); 
	DDX_Text(pDX, IDC_goodno, m_goodno); 
	DDX_Text(pDX, IDC_provideprice, m_provideprice); 
	DDX_Text(pDX, IDC_sellprice, m_sellprice); 
	DDX_Text(pDX, IDC_unit, m_unit); 
	DDX_CBString(pDX, IDC_mode, m_mode); 
	DDX_Text(pDX, IDC_condition, m_condition); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(Cgood, CDialog) 
	//{{AFX_MSG_MAP(Cgood) 
	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() 
 
///////////////////////////////////////////////////////////////////////////// 
// Cgood message handlers 
 
BOOL Cgood::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	// 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); 
    m_userlist.InsertColumn (5,"预售价格",LVCFMT_LEFT,100); 
 
	//////////读取数据库中的信息添加到列表控件/////////// 
	displayintheuserlist(); 
	 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void Cgood::displayintheuserlist() 
{ 
	//////////读取数据库中的信息添加到列表控件/////////// 
	 
 
	try 
	{ 
		 
		m_userlist.DeleteAllItems(); 
		m_pRecordset.CreateInstance("ADODB.Recordset"); 
		m_pRecordset->Open("select  *  from good order by goodno",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
	     
		 
	 
		//m_bSuccess = TRUE; 
		while(!m_pRecordset->adoEOF) 
		{ 
			  
			vgoodno= m_pRecordset->GetCollect("goodno"); 
			vgoodname= m_pRecordset->GetCollect("goodname"); 
			vunit = m_pRecordset->GetCollect("unit"); 
			vdeptno= m_pRecordset->GetCollect("deptno"); 
			vprovideprice= m_pRecordset->GetCollect("provideprice"); 
			vsellprice = m_pRecordset->GetCollect("sellprice"); 
			  
			 
			//this->AbleFalse(); 
	     	//this->LoadData(); 
			//this->GetDlgItem(IDC_BUTTON4)->EnableWindow(FALSE); 
			//this->GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE); 
			nItem=m_userlist.InsertItem(0xffff,(_bstr_t)vgoodno);//先插第一个项 
			m_userlist.SetItem(nItem,1,1,(_bstr_t)vgoodname,NULL,0,0,0); 
			m_userlist.SetItem(nItem,2,1,(_bstr_t)vunit ,NULL,0,0,0); 
			m_userlist.SetItem(nItem,3,1,(_bstr_t)vdeptno ,NULL,0,0,0); 
			m_userlist.SetItem(nItem,4,1,(_bstr_t)vprovideprice,NULL,0,0,0); 
			m_userlist.SetItem(nItem,5,1,(_bstr_t)vsellprice ,NULL,0,0,0); 
			  
			 
 
			m_pRecordset->MoveNext(); 
		} 
	} 
	catch(_com_error e)///捕捉异常 
	{ 
		//AfxMessageBox("读取数据库失败!");///显示错误信息 
	} 
} 
 
void Cgood::OnItemchangedUserlist(NMHDR* pNMHDR, LRESULT* pResult)  
{ 
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; 
	// TODO: Add your control notification handler code here 
	if(pNMListView->uNewState&LVIS_SELECTED) 
	{ 
	//UpdateData(true); 
	//SaveData();///保存旧数据 
	m_nCurrentSel = pNMListView->iItem; 
	LoadData0();///加载新数据 
	//m_cdelitem.EnableWindow(); 
	 
	} 
	 
	*pResult = 0; 
} 
 
void Cgood::LoadData0() 
{ 
	m_pRecordset.CreateInstance("ADODB.Recordset"); 
	m_pRecordset->Open("select  *  from good order by goodno",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
	    
 
     
	m_pRecordset->Move(m_nCurrentSel,_variant_t((long)adBookmarkFirst));//从第一条记录移动 
	  
	vgoodno = m_pRecordset->GetCollect("goodno"); 
	vgoodname = m_pRecordset->GetCollect("goodname"); 
	vunit = m_pRecordset->GetCollect("unit"); 
	vdeptno = m_pRecordset->GetCollect("deptno"); 
	vprovideprice = m_pRecordset->GetCollect("provideprice"); 
	vsellprice = m_pRecordset->GetCollect("sellprice"); 
	  
    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_goodno= (LPCTSTR)(_bstr_t)vgoodno; 
	m_goodname = (LPCTSTR)(_bstr_t)vgoodname; 
	m_unit = (LPCTSTR)(_bstr_t)vunit; 
	m_deptno= (LPCTSTR)(_bstr_t)vdeptno; 
	m_provideprice = (LPCTSTR)(_bstr_t)vprovideprice; 
	m_sellprice = (LPCTSTR)(_bstr_t)vsellprice; 
	  
    //m_pRecordset->Move(m_nCurrentSel,_variant_t((long)adBookmarkFirst));//从第一条记录移动 
	UpdateData(FALSE);//使得控件显示值 
 
} 
 
void Cgood::OnButton1()  
{ 
	//bool judge; 
	//judge = false; 
 
	UpdateData(true);//把控件的值传给相应的变量 
	     if (m_goodno == "" || m_goodname == "") 
		 { 
	   		 AfxMessageBox("商品编号或商品名称不能为空!!"); 
             goto tiaozhuan; 
		 } 
          
		 //UpdateData(true);//把控件的值传给相应的变量 
        //m_pRecordset1->Close(); 
		 //m_pRecordset1 = NULL; 
 
		   m_pRecordset.CreateInstance(_uuidof(Recordset));// 
	       m_pRecordset->Open("select * from good",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
           
		  
	try 
	   { 
		 
		    
	   	m_pRecordset->AddNew(); 
		 
		  
	    vgoodno = m_goodno; 
	    vgoodname = m_goodname; 
	    vunit = m_unit; 
		vdeptno = m_deptno; 
	    vprovideprice = m_provideprice; 
	    vsellprice = m_sellprice; 
	      
        //UpdateData(true); 
 
		  
		m_pRecordset->PutCollect("goodno",vgoodno); 
		m_pRecordset->PutCollect("goodname",vgoodname); 
		m_pRecordset->PutCollect("unit",vunit); 
		m_pRecordset->PutCollect("deptno",vdeptno); 
		m_pRecordset->PutCollect("provideprice",vprovideprice); 
		m_pRecordset->PutCollect("sellprice",vsellprice); 
		  
		 
 
		//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("添加记录成功!"); 
		  
          
		  
 
 
	 
	} 
	 
	   catch(_com_error e)///捕捉异常 
	   { 
		    
		  AfxMessageBox("此商品已存在!");///显示错误信息 
		    
	   } 
	     
 
	 
 
 
	  
     tiaozhuan:  
	   //m_vdeptno = ""; 
	  // m_vdeptname = ""; 
	   UpdateData(false); 
	// TODO: Add your control notification handler code here 
	 
} 
 
void Cgood::OnButton2()  
{ 
	UpdateData(true); 
 
   //_variant_t vclassnumber; 
   //int panduan = 1; 
   //CString sql,sql2,classnumber; 
    //m_insertstudentnum = "'"+m_insertstudentnum + "'";  
    //sql = "select * from student where  studentnum = "+m_insertstudentnum ; 
	if(MessageBox("确定要删除吗?",0, 
			MB_OKCANCEL|MB_DEFBUTTON2|MB_ICONWARNING)==IDOK) 
	{ 
	m_goodno = "'"+m_goodno + "'";  
	sql = "select * from good where  goodno = "+m_goodno ; 
	 
 
	////////////////////////////////////////////////////////////////////////////// 
	try 
	 { 
       m_pRecordset->Close(); 
       m_pRecordset = NULL; 
         m_pRecordset.CreateInstance(_uuidof(Recordset));// 
 
          
         m_pRecordset->Open( (_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
         m_pRecordset->Delete(adAffectCurrent); 
		  
		 //AfxMessageBox("删除记录成功!!"); 
 
		 displayintheuserlist(); 
 
		 AfxMessageBox("删除记录成功!!"); 
 
 
       
 
		 //m_pRecordset->Close(); 
         //m_pRecordset = NULL; 
     //  m_pRecordset.CreateInstance(_uuidof(Recordset));// 
     //  m_pRecordset->Open("select * from student",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
                
	 } 
	 catch(_com_error e)///捕捉异常 
	   { 
		  AfxMessageBox("删除记录失败!");///显示错误信息 
		 // panduan = 0; 
	   } 
	} 
	// TODO: Add your control notification handler code here 
	 
} 
 
void Cgood::OnButton3()  
{ 
	UpdateData(true); 
 
	CString sql1,sql2,sql3,sql4,sql5; 
m_goodno = "'"+m_goodno + "'";  
m_goodname = "'"+m_goodname+"'"; 
m_unit = "'"+m_unit+"'"; 
m_deptno = "'"+m_deptno + "'";  
m_provideprice = "'"+m_provideprice+"'"; 
m_sellprice = "'"+m_sellprice+"'"; 
sql1 = " update good set goodname = "+m_goodname+" where  goodno = "+m_goodno ;  
sql2 = " update good set unit = "+m_unit+" where goodno = "+m_goodno ;  
sql3 = " update good set deptno = "+m_deptno+" where  goodno = "+m_goodno ;  
sql4 = " update good set provideprice = "+m_provideprice+" where goodno = "+m_goodno ; 	 
sql5 = " update good set sellprice = "+m_sellprice+" where  goodno = "+m_goodno ;  
 	 
  
    try 
	 { 
       m_pRecordset->Close(); 
       m_pRecordset = NULL; 
         m_pRecordset.CreateInstance(_uuidof(Recordset));// 
         m_pRecordset->Open( (_variant_t)sql1,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
         m_pRecordset->Open( (_variant_t)sql2,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
		 m_pRecordset->Open( (_variant_t)sql3,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
		 m_pRecordset->Open( (_variant_t)sql4,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
         m_pRecordset->Open( (_variant_t)sql5,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
	 
		displayintheuserlist(); 
         AfxMessageBox("修改记录成功!");  
		 // m_pRecordset->Open( (_variant_t)sql1,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
		  
	//	 //m_pRecordset->Close(); 
        // m_pRecordset = NULL; 
	  // m_pRecordset.CreateInstance(_uuidof(Recordset));// 
     //  m_pRecordset->Open("select * from student",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
                
	 } 
	 catch(_com_error e)///捕捉异常 
	   { 
		  //AfxMessageBox("删除记录失败!");///显示错误信息 
		   
	   } 
//	 try 
//	 { 
	  //   m_pRecordset.CreateInstance(_uuidof(Recordset));// 
     //    m_pRecordset->Open( (_variant_t)sql2,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
          //AfxMessageBox("修改记录成功!"); 
		// m_pRecordset->Close(); 
        // m_pRecordset = NULL; 
 
		  
 
//	 } 
//	 catch(_com_error e)///捕捉异常 
	//   { 
		  //AfxMessageBox("删除记录失败!");///显示错误信息 
		   
//	   } 
	// TODO: Add your control notification handler code here 
	 
} 
 
void Cgood::OnButton4()  
{ 
	UpdateData(true); 
    /////////////////////////////////// 
	if (m_mode=="商品编号") 
		mode="goodno"; 
	if (m_mode=="商品名称") 
		mode="goodname"; 
    if (m_mode=="所在部门编号") 
		mode="deptno"; 
	  
	////////////////////////////////// 
	  
 
	condition = m_condition; 
	  
	//if (mode1 == "" && mode2 == "") 
		//AfxMessageBox("请选择查询方式!"); 
	//else 
	if(mode == "") 
		AfxMessageBox("请选择查询方式!"); 
	 
	if(option11 == true) 
	{ 
	 sql = "select * from good where " + mode +" "+ option1 +" " + "'"+ condition + "'" ; 
	   
	} 
	   
	 else 
		goto label; 
	 
 
	//sql = (mode1 + option1 + condition1) + (andor + mode2 + option2 + condition2); 
	try 
	{ 
		//AfxMessageBox("请选择查询方式!"); 
		m_pRecordset->Close(); 
		m_pRecordset = NULL; 
		 
	    m_userlist.DeleteAllItems(); 
 
		m_pRecordset.CreateInstance("ADODB.Recordset"); 
 
		//m_pRecordset->MoveFirst(); 
		//m_pRecordset.CreateInstance(_uuidof(Recordset));// 
		//m_pRecordset->Open("select  *  from employeeview",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
        m_pRecordset->Open( (_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
	    //AfxMessageBox("请选择查询方式!"); 
		//m_pRecordset->Close(); 
		 
	     
		//m_pRecordset->Open("select  *  from employeeview where sql",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
	    if(m_pRecordset->adoEOF) 
			AfxMessageBox("没有满足您查询的结果!"); 
	     
		//m_bSuccess = TRUE; 
		 
		while(!m_pRecordset->adoEOF) 
		{ 
			 
			//AfxMessageBox("请选择查询方式!"); 
			  
			vgoodno= m_pRecordset->GetCollect("goodno"); 
			vgoodname= m_pRecordset->GetCollect("goodname"); 
			vunit = m_pRecordset->GetCollect("unit"); 
			vdeptno= m_pRecordset->GetCollect("deptno"); 
			vprovideprice= m_pRecordset->GetCollect("provideprice"); 
			vsellprice = m_pRecordset->GetCollect("sellprice"); 
			  
			 
			//this->AbleFalse(); 
	     	//this->LoadData(); 
			//this->GetDlgItem(IDC_BUTTON4)->EnableWindow(FALSE); 
			//this->GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE); 
			nItem=m_userlist.InsertItem(0xffff,(_bstr_t)vgoodno);//先插第一个项 
			m_userlist.SetItem(nItem,1,1,(_bstr_t)vgoodname,NULL,0,0,0); 
			m_userlist.SetItem(nItem,2,1,(_bstr_t)vunit ,NULL,0,0,0); 
			m_userlist.SetItem(nItem,3,1,(_bstr_t)vdeptno ,NULL,0,0,0); 
			m_userlist.SetItem(nItem,4,1,(_bstr_t)vprovideprice,NULL,0,0,0); 
			m_userlist.SetItem(nItem,5,1,(_bstr_t)vsellprice ,NULL,0,0,0); 
			  
			 
 
			m_pRecordset->MoveNext(); 
		} 
	} 
	catch(_com_error e)///捕捉异常 
	{ 
		//AfxMessageBox("读取数据库失败!");///显示错误信息 
	} 
     
	//对逻辑运算的符号的恢复,以供下一次的查询 。 
 label:	 //AfxMessageBox("请选择查询方式!"); 
	//option11 = false; 
	    //option22 = false; 
	    //andor00 = false; 
	//////////////////////////////////////////////////////////////////// 
                 
	 
	//mode1 = ""; 
	//mode2 = ""; 
	//option1 = ""; 
	//option2 = ""; 
	//andor = ""; 
     
   UpdateData(false); 
   //UpdateData(true); 
   //AfxMessageBox("请选择查询方式!"); 
	// TODO: Add your control notification handler code here 
	 
} 
 
void Cgood::OnRadio1()  
{ 
	option1 = "<"; 
	option11 = true; 
	// TODO: Add your control notification handler code here 
	 
} 
 
void Cgood::OnRadio2()  
{ 
	option1 = "="; 
	option11 = true; 
	// TODO: Add your control notification handler code here 
	 
} 
 
void Cgood::OnRadio3()  
{ 
	option1 = ">"; 
	option11 = true; 
	// TODO: Add your control notification handler code here 
	 
}