deptmentquery.cpp

来自「这是一个不错的商店管理系统」· C++ 代码 · 共 255 行

CPP
255
字号
// deptmentquery.cpp : implementation file
//

#include "stdafx.h"
#include "shop.h"
#include "deptmentquery.h"
#include "deptment.h"

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

/////////////////////////////////////////////////////////////////////////////
// Cdeptmentquery dialog


Cdeptmentquery::Cdeptmentquery(CWnd* pParent /*=NULL*/)
	: CDialog(Cdeptmentquery::IDD, pParent)
{
	//{{AFX_DATA_INIT(Cdeptmentquery)
	m_mode = _T("");
	m_condition = _T("");
	//}}AFX_DATA_INIT
}


void Cdeptmentquery::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(Cdeptmentquery)
	DDX_Control(pDX, IDC_USERLIST, m_userlist);
	DDX_CBString(pDX, IDC_COMBO1, m_mode);
	DDX_Text(pDX, IDC_EDIT1, m_condition);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(Cdeptmentquery, CDialog)
	//{{AFX_MSG_MAP(Cdeptmentquery)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// Cdeptmentquery message handlers

void Cdeptmentquery::OnOK() 
{
	// TODO: Add extra validation here
	
	CDialog::OnOK();
	Cdeptment dlg;
	dlg.DoModal();
}

BOOL Cdeptmentquery::OnInitDialog() 
{
	CDialog::OnInitDialog();
	::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);

	//////////读取数据库中的信息添加到列表控件///////////
	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 Cdeptmentquery::displayintheuserlist()
{
	//////////读取数据库中的信息添加到列表控件///////////
	

	try
	{
		
		m_userlist.DeleteAllItems();
		m_pRecordset.CreateInstance("ADODB.Recordset");
		m_pRecordset->Open("select  *  from deptment order by deptno",_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
	    
		
	
		//m_bSuccess = TRUE;
		while(!m_pRecordset->adoEOF)
		{
			 
			vdeptno= m_pRecordset->GetCollect("deptno");
			vdeptname= m_pRecordset->GetCollect("deptname");
			vmanagername = m_pRecordset->GetCollect("managername");
			 
			
			//this->AbleFalse();
	     	//this->LoadData();
			//this->GetDlgItem(IDC_BUTTON4)->EnableWindow(FALSE);
			//this->GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
			nItem=m_userlist.InsertItem(0xffff,(_bstr_t)vdeptno);//先插第一个项
			m_userlist.SetItem(nItem,1,1,(_bstr_t)vdeptname,NULL,0,0,0);
			m_userlist.SetItem(nItem,2,1,(_bstr_t)vmanagername ,NULL,0,0,0);
			 
			

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


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

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

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

void Cdeptmentquery::OnButton1() 
{
	UpdateData(true);
    ///////////////////////////////////
	if (m_mode=="部门编号")
		mode="deptno";
	if (m_mode=="部门名称")
		mode="deptname";
    if (m_mode=="部门经理")
		mode="managername";
	 
	//////////////////////////////////
	 

	condition = m_condition;
	 
	//if (mode1 == "" && mode2 == "")
		//AfxMessageBox("请选择查询方式!");
	//else
	if(mode == "")
		AfxMessageBox("请选择查询方式!");
	
	if(option11 == true)
	{
	 sql = "select * from deptment 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("请选择查询方式!");
			 
			vdeptno= m_pRecordset->GetCollect("deptno");
			vdeptname= m_pRecordset->GetCollect("deptname");
			vmanagername = m_pRecordset->GetCollect("managername");
			 
			
			//this->AbleFalse();
	     	//this->LoadData();
			//this->GetDlgItem(IDC_BUTTON4)->EnableWindow(FALSE);
			//this->GetDlgItem(IDC_BUTTON2)->EnableWindow(FALSE);
			nItem=m_userlist.InsertItem(0xffff,(_bstr_t)vdeptno);//先插第一个项
			m_userlist.SetItem(nItem,1,1,(_bstr_t)vdeptname,NULL,0,0,0);
			m_userlist.SetItem(nItem,2,1,(_bstr_t)vmanagername ,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
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

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