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

📄 offer.cpp

📁 这是一个不错的商店管理系统
💻 CPP
字号:
// offer.cpp : implementation file
//

#include "stdafx.h"
#include "shop.h"
#include "offer.h"

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

/////////////////////////////////////////////////////////////////////////////
// Coffer dialog


Coffer::Coffer(CWnd* pParent /*=NULL*/)
	: CDialog(Coffer::IDD, pParent)
{
	//{{AFX_DATA_INIT(Coffer)
	m_address = _T("");
	m_mode = _T("");
	m_offname = _T("");
	m_offno = _T("");
	m_telephone = _T("");
	m_condition = _T("");
	//}}AFX_DATA_INIT
}


void Coffer::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Coffer)
	DDX_Control(pDX, IDC_USERLIST, m_userlist);
	DDX_Text(pDX, IDC_address, m_address);
	DDX_CBString(pDX, IDC_mode, m_mode);
	DDX_Text(pDX, IDC_offname, m_offname);
	DDX_Text(pDX, IDC_offno, m_offno);
	DDX_Text(pDX, IDC_telephone, m_telephone);
	DDX_Text(pDX, IDC_condition, m_condition);
	//}}AFX_DATA_MAP
}


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

/////////////////////////////////////////////////////////////////////////////
// Coffer message handlers

BOOL Coffer::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);
	 

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


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

	try
	{
		
		m_userlist.DeleteAllItems();
		m_pRecordset.CreateInstance("ADODB.Recordset");
		m_pRecordset->Open("select  *  from offer 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");
			voffname= m_pRecordset->GetCollect("offname");
			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)voffno);//先插第一个项
			m_userlist.SetItem(nItem,1,1,(_bstr_t)voffname,NULL,0,0,0);
			m_userlist.SetItem(nItem,2,1,(_bstr_t)vaddress ,NULL,0,0,0);
			m_userlist.SetItem(nItem,3,1,(_bstr_t)vtelephone ,NULL,0,0,0);
			 
			 
			

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

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

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

		   m_pRecordset.CreateInstance(_uuidof(Recordset));//
	       m_pRecordset->Open("select * from offer",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
          
		 
	try
	   {
		
		   
	   	m_pRecordset->AddNew();
		
		 
	    voffno = m_offno;
	    voffname = m_offname;
	    vaddress = m_address;
		vtelephone = m_telephone;
	     
	     
        //UpdateData(true);

		 
		m_pRecordset->PutCollect("offno",voffno);
		m_pRecordset->PutCollect("offname",voffname);
		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("添加记录成功!");
		 
         
		 


	
	}
	
	   catch(_com_error e)///捕捉异常
	   {
		   
		  AfxMessageBox("此供应商已存在!");///显示错误信息
		   
	   }
	    

	


	 
     tiaozhuan: 
	   //m_vdeptno = "";
	  // m_vdeptname = "";
	   UpdateData(false);
	// TODO: Add your control notification handler code here
	
}

void Coffer::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 Coffer::LoadData0()
{
	m_pRecordset.CreateInstance("ADODB.Recordset");
	m_pRecordset->Open("select  *  from offer 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");
	voffname = m_pRecordset->GetCollect("offname");
	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_offno= (LPCTSTR)(_bstr_t)voffno;
	m_offname = (LPCTSTR)(_bstr_t)voffname;
	m_address = (LPCTSTR)(_bstr_t)vaddress;
	m_telephone= (LPCTSTR)(_bstr_t)vtelephone;
	 
	 
    //m_pRecordset->Move(m_nCurrentSel,_variant_t((long)adBookmarkFirst));//从第一条记录移动
	UpdateData(FALSE);//使得控件显示值

}

void Coffer::OnButton2() 
{
	UpdateData(true);

    
	if(MessageBox("确定要删除吗?",0,
			MB_OKCANCEL|MB_DEFBUTTON2|MB_ICONWARNING)==IDOK)
	{
	m_offno = "'"+m_offno + "'"; 
	sql = "select * from offer where  offno = "+m_offno ;
	

	//////////////////////////////////////////////////////////////////////////////
	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 Coffer::OnButton3() 
{
	UpdateData(true);

	CString sql1,sql2,sql3 ;
m_offno = "'"+m_offno + "'"; 
m_offname = "'"+m_offname+"'";
m_address = "'"+m_address+"'";
m_telephone = "'"+m_telephone + "'"; 
 
sql1 = " update offer set offname = "+m_offname+" where  offno = "+m_offno ; 
sql2 = " update offer set address = "+m_address+" where offno = "+m_offno ; 
sql3 = " update offer set telephone = "+m_telephone+" where  offno = "+m_offno ; 
 
 	
 
    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);
		  
		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("删除记录失败!");///显示错误信息
		  
//	   }
 
	
}

void Coffer::OnRadio1() 
{
	option1 = "<";
	option11 = true;
	// TODO: Add your control notification handler code here
	
}

void Coffer::OnRadio2() 
{
	option1 = "=";
	option11 = true;
	// TODO: Add your control notification handler code here
	
}

void Coffer::OnRadio3() 
{
	option1 = ">";
	option11 = true;
	// TODO: Add your control notification handler code here
	
}

void Coffer::OnButton4() 
{
	UpdateData(true);
    ///////////////////////////////////
//	供应商编号
 //   供应商名称
  //   地址
  //   电话
	if (m_mode=="供应商编号")
		mode="offno";
	if (m_mode=="供应商名称")
		mode="offname";
    if (m_mode=="地址")
		mode="address";
	if (m_mode=="电话")
		mode="telephone";

	 
	//////////////////////////////////
	 

	condition = m_condition;
	 
	//if (mode1 == "" && mode2 == "")
		//AfxMessageBox("请选择查询方式!");
	//else
	if(mode == "")
		AfxMessageBox("请选择查询方式!");
	
	if(option11 == true)
	{
	 sql = "select * from offer 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("请选择查询方式!");
			 
			voffno= m_pRecordset->GetCollect("offno");
			voffname= m_pRecordset->GetCollect("offname");
			vaddress = m_pRecordset->GetCollect("address");
			vtelephone= m_pRecordset->GetCollect("telephone");
			 
			 
			
			 
			nItem=m_userlist.InsertItem(0xffff,(_bstr_t)voffno);//先插第一个项
			m_userlist.SetItem(nItem,1,1,(_bstr_t)voffname,NULL,0,0,0);
			m_userlist.SetItem(nItem,2,1,(_bstr_t)vaddress ,NULL,0,0,0);
			m_userlist.SetItem(nItem,3,1,(_bstr_t)vtelephone ,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
	
}

⌨️ 快捷键说明

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