www.pudn.com > shangdianguanlixitong.rar > provide.cpp, change:2005-06-25,size:10501b


// provide.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "shop.h" 
#include "provide.h" 
#include "goodinformation.h" 
#include "offer.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
extern CShopApp theApp; 
//static int quanju; 
  
///////////////////////////////////////////////////////////////////////////// 
// Cprovide dialog 
 
 
Cprovide::Cprovide(CWnd* pParent /*=NULL*/) 
	: CDialog(Cprovide::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(Cprovide) 
	m_amount = _T(""); 
	m_date = _T(""); 
	m_goodno = _T(""); 
	m_offno = _T(""); 
	//}}AFX_DATA_INIT 
} 
 
 
void Cprovide::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(Cprovide) 
	DDX_Control(pDX, IDC_offno, m_offno1); 
	DDX_Control(pDX, IDC_goodno, m_goodno1); 
	DDX_Control(pDX, IDC_USERLIST, m_userlist); 
	DDX_Text(pDX, IDC_amount, m_amount); 
	DDX_Text(pDX, IDC_date, m_date); 
	DDX_CBString(pDX, IDC_goodno, m_goodno); 
	DDX_CBString(pDX, IDC_offno, m_offno); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(Cprovide, CDialog) 
	//{{AFX_MSG_MAP(Cprovide) 
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_USERLIST, OnItemchangedUserlist) 
	ON_CBN_DROPDOWN(IDC_offno, OnDropdownoffno) 
	ON_CBN_SELCHANGE(IDC_goodno, OnSelchangegoodno) 
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1) 
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2) 
	ON_CBN_KILLFOCUS(IDC_goodno, OnKillfocusgoodno) 
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3) 
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// Cprovide message handlers 
 
BOOL Cprovide::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	fun(); 
    quanju = 0; 
	fun11 = true; 
	fun22 = true; 
	 
	// TODO: Add extra initialization here 
	::SendMessage(m_userlist.m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE,LVS_EX_FULLROWSELECT, LVS_EX_FULLROWSELECT);//当被选中时,所有子项都处于选中状态 
	//////////为列表控件添加列////////// 
 
	m_userlist.InsertColumn(0,"供应商编号",LVCFMT_LEFT,80); 
	m_userlist.InsertColumn(1,"商品编号",LVCFMT_LEFT,80); 
    m_userlist.InsertColumn (2,"数量",LVCFMT_LEFT,80); 
	m_userlist.InsertColumn(3,"日期",LVCFMT_LEFT,100); 
	  
 
	//////////读取数据库中的信息添加到列表控件/////////// 
	displayintheuserlist(); 
	 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
void Cprovide::displayintheuserlist() 
{ 
	//////////读取数据库中的信息添加到列表控件/////////// 
	 
 
	try 
	{ 
		 
		m_userlist.DeleteAllItems(); 
		m_pRecordset.CreateInstance("ADODB.Recordset"); 
		m_pRecordset->Open("select  *  from provide order by offno",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
	     
		 
	 
		//m_bSuccess = TRUE; 
		while(!m_pRecordset->adoEOF) 
		{ 
			  
			voffno= m_pRecordset->GetCollect("offno"); 
			vgoodno= m_pRecordset->GetCollect("goodno"); 
			vamount = m_pRecordset->GetCollect("amount"); 
			vdate= m_pRecordset->GetCollect("date"); 
			  
			  
			 
			//this->AbleFalse(); 
	     	//this->LoadData(); 
			//this->GetDlgItem(IDC_BUTTON4)->EnableWindow(FALSE); 
			//this->GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE); 
			nItem=m_userlist.InsertItem(0xffff,(_bstr_t)voffno);//先插第一个项 
			m_userlist.SetItem(nItem,1,1,(_bstr_t)vgoodno,NULL,0,0,0); 
			m_userlist.SetItem(nItem,2,1,(_bstr_t)vamount ,NULL,0,0,0); 
			m_userlist.SetItem(nItem,3,1,(_bstr_t)vdate ,NULL,0,0,0); 
			  
			  
			 
 
			m_pRecordset->MoveNext(); 
		} 
	} 
	catch(_com_error e)///捕捉异常 
	{ 
		//AfxMessageBox("读取数据库失败!");///显示错误信息 
	} 
} 
 
void Cprovide::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 Cprovide::LoadData0() 
{ 
	m_pRecordset.CreateInstance("ADODB.Recordset"); 
	m_pRecordset->Open("select  *  from provide order by offno",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
	    
 
     
	m_pRecordset->Move(m_nCurrentSel,_variant_t((long)adBookmarkFirst));//从第一条记录移动 
	  
	voffno = m_pRecordset->GetCollect("offno"); 
	vgoodno = m_pRecordset->GetCollect("goodno"); 
	vamount = m_pRecordset->GetCollect("amount"); 
	vdate = m_pRecordset->GetCollect("date"); 
	  
	  
    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_offno= (LPCTSTR)(_bstr_t)voffno; 
	m_goodno = (LPCTSTR)(_bstr_t)vgoodno; 
	m_amount = (LPCTSTR)(_bstr_t)vamount; 
	m_date= (LPCTSTR)(_bstr_t)vdate; 
	  
	  
    //m_pRecordset->Move(m_nCurrentSel,_variant_t((long)adBookmarkFirst));//从第一条记录移动 
	UpdateData(FALSE);//使得控件显示值 
 
} 
 
void Cprovide::OnDropdownoffno()  
{ 
	//AfxMessageBox("读取数据库失败!"); 
//	AfxMessageBox("读取数据库失败!"); 
 
	//fun1(); 
 
} 
 
void Cprovide::fun1() 
{ 
	try 
	{ 
	m_pRecordset.CreateInstance("ADODB.Recordset"); 
	m_pRecordset->Open("select  offno  from provide order by offno",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
    while(!m_pRecordset->adoEOF) 
	{ 
 
     
////	m_pRecordset->Move(m_nCurrentSel,_variant_t((long)adBookmarkFirst));//从第一条记录移动 
	  
	voffno = m_pRecordset->GetCollect("offno"); 
	str1 = (LPCTSTR)(_bstr_t)voffno + '\r\n'; 
	} 
      m_offno = str1; 
	} 
	catch(_com_error e)///捕捉异常 
	   { 
		//  AfxMessageBox("删除记录失败!");///显示错误信息 
		   
	   } 
	  
	  
   // 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_offno 
 
 
	  
	 
	  
	  
	  
    //m_pRecordset->Move(m_nCurrentSel,_variant_t((long)adBookmarkFirst));//从第一条记录移动 
	UpdateData(FALSE);//使得控件显示值 
 
} 
 
void Cprovide::fun() 
{ 
	CString vgoodno1; 
	try 
	{ 
	m_pRecordset.CreateInstance("ADODB.Recordset"); 
	m_pRecordset->Open("select goodno from good",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
	 
	while(!m_pRecordset->adoEOF) 
	{ 
		vgoodno = m_pRecordset->GetCollect("goodno"); 
		vgoodno1 = (LPCTSTR)(_bstr_t)vgoodno; 
		m_goodno1.AddString(vgoodno1); 
		m_pRecordset->MoveNext(); 
	} 
	} 
	catch(_com_error e)///捕捉异常 
	{ 
		//AfxMessageBox("读取数据库失败!");///显示错误信息 
	} 
} 
void Cprovide::funoffno() 
{ 
	CString voffno1 ,vgoodno1,vgoodno11,vgoodno12,sql1; 
	UpdateData(true); 
	 
	for(int i=0;i<quanju;i++) 
		m_offno1.DeleteString(0); 
	quanju = 0; 
   try 
   { 
	   m_goodno = "'"+m_goodno + "'";  
	   sql1 = " select distinct offno from provide where goodno = " + m_goodno ;  
	   m_pRecordset->Close(); 
       m_pRecordset = NULL; 
        
	m_pRecordset.CreateInstance("ADODB.Recordset"); 
	m_pRecordset->Open((_variant_t)sql1,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
	//m_pRecordset->Open("select offno,goodno from provide",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
	 
	while(!m_pRecordset->adoEOF) 
	{   
		voffno = m_pRecordset->GetCollect("offno"); 
		//vgoodno = m_pRecordset->GetCollect("goodno"); 
		voffno1 = (LPCTSTR)(_bstr_t)voffno; 
		//vgoodno1 = (LPCTSTR)(_bstr_t)vgoodno; 
		  
		//AfxMessageBox("读取数vvvvv据库失败!");	 
		m_offno1.AddString(voffno1); 
		quanju = quanju + 1; 
		m_pRecordset->MoveNext(); 
		 
 
	} 
	} 
	catch(_com_error e)///捕捉异常 
	{ 
		//AfxMessageBox("读取数vvvvv据库失败!");///显示错误信息 
	} 
	 
 
	  
} 
 
void Cprovide::OnSelchangegoodno()  
{ 
	//AfxMessageBox("读取数据库失败!"); 
 
    //funoffno();	 
    //UpdateData(true); 
//	UpdateData(false); 
	 
} 
 
void Cprovide::OnButton1()  
{ 
UpdateData(true);//把控件的值传给相应的变量 
	     if (m_offno == "" || m_goodno == "") 
		 { 
	   		 AfxMessageBox("供应商编号或商品编号不能为空!!"); 
             goto tiaozhuan; 
		 } 
          
		   m_pRecordset.CreateInstance(_uuidof(Recordset));// 
	       m_pRecordset->Open("select * from provide",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); 
       	try 
	   { 
	   	m_pRecordset->AddNew(); 
	     
		voffno = m_offno; 
	    vgoodno = m_goodno; 
	    vamount = m_amount; 
		vdate = m_date; 
	      
		m_pRecordset->PutCollect("offno",voffno); 
		m_pRecordset->PutCollect("goodno",vgoodno); 
		m_pRecordset->PutCollect("amount",vamount); 
		m_pRecordset->PutCollect("date",vdate); 
		  
		  
		m_pRecordset->Update(); 
		  
		 m_pRecordset->Close(); 
		 m_pRecordset = NULL; 
		  
		   
         displayintheuserlist(); 
		  
         AfxMessageBox("添加记录成功!"); 
		} 
	 
	   catch(_com_error e)///捕捉异常 
	   { 
		    
		  AfxMessageBox("添加记录失败!");///显示错误信息 
		    
	   } 
	     
 
	 
 
 
	  
     tiaozhuan:  
	   //m_vdeptno = ""; 
	  // m_vdeptname = ""; 
	   UpdateData(false);	 
} 
 
void Cprovide::OnButton2()  
{ 
UpdateData(true); 
 
     
	if(MessageBox("确定要删除吗?",0, 
			MB_OKCANCEL|MB_DEFBUTTON2|MB_ICONWARNING)==IDOK) 
	{ 
	m_offno = "'"+m_offno + "'";  
	m_goodno = "'"+m_goodno + "'";  
	sql = "select * from provide where  offno = "+m_offno + " and 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); 
		  
		 displayintheuserlist(); 
 
		 AfxMessageBox("删除记录成功!!"); 
	} 
	 catch(_com_error e)///捕捉异常 
	   { 
		  AfxMessageBox("删除记录失败!");///显示错误信息 
		  
	   } 
	}	 
} 
 
void Cprovide::OnKillfocusgoodno()  
{ 
     funoffno(); 
	 //UpdateData(false); 
} 
 
void Cprovide::OnButton3()  
{ 
	Cgoodinformation dlg; 
	dlg.DoModal(); 
    	 
} 
 
void Cprovide::OnButton4()  
{ 
      Coffer dlg; 
	  dlg.DoModal(); 
}