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

📄 goodinformation.cpp

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

#include "stdafx.h"
#include "shop.h"
#include "goodinformation.h"

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

/////////////////////////////////////////////////////////////////////////////
// Cgoodinformation dialog


Cgoodinformation::Cgoodinformation(CWnd* pParent /*=NULL*/)
	: CDialog(Cgoodinformation::IDD, pParent)
{
	//{{AFX_DATA_INIT(Cgoodinformation)
	m_condition1 = _T("");
	m_condition2 = _T("");
	m_mode1 = _T("");
	m_mode2 = _T("");
	//}}AFX_DATA_INIT
}


void Cgoodinformation::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cgoodinformation)
	DDX_Control(pDX, IDC_USERLIST, m_userlist);
	DDX_Text(pDX, IDC_condition1, m_condition1);
	DDX_Text(pDX, IDC_condition2, m_condition2);
	DDX_CBString(pDX, IDC_mode1, m_mode1);
	DDX_CBString(pDX, IDC_mode2, m_mode2);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cgoodinformation, CDialog)
	//{{AFX_MSG_MAP(Cgoodinformation)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	ON_BN_CLICKED(IDC_RADIO7, OnRadio7)
	ON_BN_CLICKED(IDC_RADIO8, OnRadio8)
	ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
	ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
	ON_BN_CLICKED(IDC_RADIO6, OnRadio6)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cgoodinformation message handlers

BOOL Cgoodinformation::OnInitDialog() 
{
	CDialog::OnInitDialog();
	mode1 = "";
	mode2 = "";
	option1 = "";
	option2 = "";
	andor = "";

	option11 = false;
	option22 = false;
	andor00 = false;

	::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);
	m_userlist.InsertColumn(6,"进价",LVCFMT_LEFT,100);
	m_userlist.InsertColumn(7,"预售价格",LVCFMT_LEFT,100);
	m_userlist.InsertColumn(8,"商品数量",LVCFMT_LEFT,100);
    m_userlist.InsertColumn (9,"进货日期",LVCFMT_LEFT,100);

	displayintheuserlist();
	 
	
	// TODO: Add extra initialization here
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

//////将记录集中的数据加载到编辑框/////
void Cgoodinformation::displayintheuserlist()
{
	try
	{
		m_userlist.DeleteAllItems();
		m_pRecordset.CreateInstance("ADODB.Recordset");
		m_pRecordset->Open("select  *  from goodview 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");
			vdeptname = m_pRecordset->GetCollect("deptname");
			voffno = m_pRecordset->GetCollect("offno");
			voffname= m_pRecordset->GetCollect("offname");
			vprovideprice= m_pRecordset->GetCollect("provideprice");
			vsellprice= m_pRecordset->GetCollect("sellprice");
			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)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)vdeptname ,NULL,0,0,0);
			m_userlist.SetItem(nItem,4,1,(_bstr_t)voffno,NULL,0,0,0);
			m_userlist.SetItem(nItem,5,1,(_bstr_t)voffname,NULL,0,0,0);
		    m_userlist.SetItem(nItem,6,1,(_bstr_t)vprovideprice,NULL,0,0,0);
			m_userlist.SetItem(nItem,7,1,(_bstr_t)vsellprice,NULL,0,0,0);
			m_userlist.SetItem(nItem,8,1,(_bstr_t)vamount ,NULL,0,0,0);
			m_userlist.SetItem(nItem,9,1,(_bstr_t)vdate ,NULL,0,0,0);
			 
			

			m_pRecordset->MoveNext();
		}


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



}

void Cgoodinformation::OnButton1() 
{
	UpdateData(true);
    ///////////////////////////////////
//	//商品编号
   //  商品名称
   // 所在部门名称
   // 供应商编号
    // 供应商姓名
    // 商品数量

	if (m_mode1=="商品编号")
		mode1="goodno";
	if (m_mode1=="商品名称")
		mode1="goodname";
    if (m_mode1=="所在部门名称")
		mode1="deptname";
	if (m_mode1=="供应商编号")
		mode1="offno";
	if (m_mode1=="供应商姓名")
		mode1="offname";
	if (m_mode1=="商品数量")
		mode1="amount";
	//////////////////////////////////
	if (m_mode2=="商品编号")
		mode2="goodno";
	if (m_mode2=="商品名称")
		mode2="goodname";
    if (m_mode2=="所在部门名称")
		mode2="deptname";
	if (m_mode2=="供应商编号")
		mode2="offno";
	if (m_mode2=="供应商姓名")
		mode2="offname";
	if (m_mode2=="商品数量")
		mode2="amount";

	condition1 = m_condition1;
	condition2 = m_condition2;
	//if (mode1 == "" && mode2 == "")
		//AfxMessageBox("请选择查询方式!");
	//else
	if(mode1 == "" && mode2 == "")
		AfxMessageBox("请选择查询方式!");
	
	if(option11 == true && option22 == true && andor00 == true)
	{
	 sql = "select * from goodview where " + mode1 +" "+ option1 +" " + "'"+ condition1 + "'" + " " + andor + " " + mode2 + " "+ option2 +" " + "'" + condition2 + "'" + " order by goodno";
	  
	}
	 else if(option11 == true && andor00 == false)
	 {
		 sql = "select * from goodview where " + mode1 + " " + option1 + " " + "'" + condition1+"'" + " order by goodno";
	      
	 }
	 else if(option22 == true && andor == false)
	 {
		 sql = "select * from goodview where " + mode2 + " " + option2 + " " + "'" + condition2 + "'" + " order by goodno";
	      
	 }
	
	 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();
		if(m_pRecordset->adoEOF)
			AfxMessageBox("没有符合您查询条件的结果!");

		
	    
		//m_pRecordset->Open("select  *  from employeeview where sql",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
	
	    
		//m_bSuccess = TRUE;
		
		while(!m_pRecordset->adoEOF)
		{
			
			//AfxMessageBox("请选择查询方式!");
			vgoodno= m_pRecordset->GetCollect("goodno");
			vgoodname = m_pRecordset->GetCollect("goodname");
            vunit=m_pRecordset->GetCollect("unit");
			vdeptname = m_pRecordset->GetCollect("deptname");
			voffno = m_pRecordset->GetCollect("offno");
			voffname= m_pRecordset->GetCollect("offname");
			vprovideprice= m_pRecordset->GetCollect("provideprice");
			vsellprice= m_pRecordset->GetCollect("sellprice");
			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)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)vdeptname ,NULL,0,0,0);
			m_userlist.SetItem(nItem,4,1,(_bstr_t)voffno,NULL,0,0,0);
			m_userlist.SetItem(nItem,5,1,(_bstr_t)voffname,NULL,0,0,0);
		    m_userlist.SetItem(nItem,6,1,(_bstr_t)vprovideprice,NULL,0,0,0);
			m_userlist.SetItem(nItem,7,1,(_bstr_t)vsellprice,NULL,0,0,0);
			m_userlist.SetItem(nItem,8,1,(_bstr_t)vamount ,NULL,0,0,0);
			m_userlist.SetItem(nItem,9,1,(_bstr_t)vdate ,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 Cgoodinformation::OnRadio1() 
{
	option1 = "<";
	option11 = true;

	// TODO: Add your control notification handler code here
	
}

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

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

void Cgoodinformation::OnRadio7() 
{
	andor = "or";
	andor00 = true;
	// TODO: Add your control notification handler code here
	
}

void Cgoodinformation::OnRadio8() 
{
	andor = "and";
	andor00 = true;
	// TODO: Add your control notification handler code here
	
}

void Cgoodinformation::OnRadio4() 
{
	option2 = "<";
	option22 = true;
	// TODO: Add your control notification handler code here
	
}

void Cgoodinformation::OnRadio5() 
{
	option2 = "=";
	option22 = true;
	// TODO: Add your control notification handler code here
	
}

void Cgoodinformation::OnRadio6() 
{
	option2 = ">";
	option22 = true;

	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

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