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

📄 searchinformationissue.cpp

📁 关于客户关系管理系统的源码
💻 CPP
字号:
// SearchInformationIssue.cpp : implementation file
//

#include "stdafx.h"
#include "ClientRelationship.h"
#include "SearchInformationIssue.h"
#include "InformationIssueForm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSearchInformationIssue dialog


CSearchInformationIssue::CSearchInformationIssue(CWnd* pParent /*=NULL*/)
	: CDialog(CSearchInformationIssue::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSearchInformationIssue)
	m_issueDateBegin = COleDateTime::GetCurrentTime();
	m_issueDateEnd = COleDateTime::GetCurrentTime();
	m_staffName = _T("");
	m_department = _T("");
	m_subject = _T("");
	//}}AFX_DATA_INIT
}


void CSearchInformationIssue::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSearchInformationIssue)
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Control(pDX, IDC_subject, m_subjectCombo);
	DDX_Control(pDX, IDC_department, m_departmentCombo);
	DDX_Control(pDX, IDC_staffName, m_staffNameCombo);
	DDX_DateTimeCtrl(pDX, IDC_issueDateBegin, m_issueDateBegin);
	DDX_DateTimeCtrl(pDX, IDC_issueDateEnd, m_issueDateEnd);
	DDX_CBString(pDX, IDC_staffName, m_staffName);
	DDX_CBString(pDX, IDC_department, m_department);
	DDX_CBString(pDX, IDC_subject, m_subject);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSearchInformationIssue, CDialog)
	//{{AFX_MSG_MAP(CSearchInformationIssue)
	ON_BN_CLICKED(IDC_search, OnSearch)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSearchInformationIssue message handlers

void CSearchInformationIssue::OnSearch() 
{
	UpdateData(true);

	CString strSQL;
	_RecordsetPtr m_pRecordset;
	HRESULT hTRes;
	hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));	
	//构造查询语句
	strSQL="select * from informationIssue";
	CString str;
	//开始日期
	str.Format("%d-%d-%d",m_issueDateBegin.GetYear(),m_issueDateBegin.GetMonth(),m_issueDateBegin.GetDay());
	strSQL+=" where issueDate>'"+str+"' and issueDate<'";
	//结束日期
	str.Format("%d-%d-%d",m_issueDateEnd.GetYear(),m_issueDateEnd.GetMonth(),m_issueDateEnd.GetDay());
	strSQL+=str+"' ";
	if(m_department!="")
	{
		strSQL+=" and Department='"+m_department+"' ";  //部门
	}
	if(m_staffName!="")
	{
		strSQL+=" and StaffName='"+m_staffName+"' ";  //发布人员
	}
	if(m_subject!="")
	{
		strSQL+=" and subject='"+m_subject+"'";  //公告主题
	}

//	AfxMessageBox(strSQL);

	hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
			((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);//执行sql语句,并打开查询结果记录集
	int i=0;
	m_list.DeleteAllItems();//清除列表框控件中的数据
	//将查询结果在列表框控件中显示出来
	while(!(m_pRecordset->adoEOF))
	{
		m_list.InsertItem(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("informationIssueID")));//公告编码
		COleDateTime issueDate= m_pRecordset->GetCollect("issueDate");//发布日期
		str.Format("%d-%d-%d",issueDate.GetYear(),issueDate.GetMonth(),issueDate.GetDay());//将发布日期转换成字符串
		m_list.SetItemText(i,1,str);
		m_list.SetItemText(i,2, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("Department")));//发布部门
		m_list.SetItemText(i,3, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("StaffName"))); //发布人员
		m_list.SetItemText(i,4, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("Subject"))); //公告主题
		m_list.SetItemText(i,5, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("content"))); //公告内容		
		m_pRecordset->MoveNext();//记录集指针向后移动
		i++;
	}
	m_pRecordset->Close();//关闭记录集	
	UpdateData(false);//更新对话框数据
}

BOOL CSearchInformationIssue::OnInitDialog() 
{
	CDialog::OnInitDialog();

	DWORD style;
	style=m_list.GetExStyle();
	style=(style|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT)&(~LVS_EX_CHECKBOXES) ;
	m_list.SetExtendedStyle(style);
	
	m_list.InsertColumn(0,"公告编号",LVCFMT_LEFT,100);
	m_list.InsertColumn(1,"公告日期",LVCFMT_LEFT,100);
	m_list.InsertColumn(2,"发布部门",LVCFMT_LEFT,100);
	m_list.InsertColumn(3,"发布人员",LVCFMT_LEFT,100);
	m_list.InsertColumn(4,"公告主题",LVCFMT_LEFT,100);
	m_list.InsertColumn(5,"公告内容",LVCFMT_LEFT,100);
	
	CString strSQL;
	_RecordsetPtr m_pRecordset;
	HRESULT hTRes;
	hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));	

	strSQL="select distinct Department from informationIssue";	
				
	hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
			((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
	int i=0;
	while(!(m_pRecordset->adoEOF))
	{
		m_departmentCombo.InsertString(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("Department")));
		m_pRecordset->MoveNext();
		i++;
	}
	m_pRecordset->Close();

	strSQL="select distinct StaffName from informationIssue";	
				
	hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
			((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
	i=0;
	while(!(m_pRecordset->adoEOF))
	{
		m_staffNameCombo.InsertString(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("StaffName")));
		m_pRecordset->MoveNext();
		i++;
	}
	m_pRecordset->Close();

	strSQL="select distinct Subject from informationIssue";	
				
	hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
			((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
	i=0;
	while(!(m_pRecordset->adoEOF))
	{
		m_subjectCombo.InsertString(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("Subject")));
		m_pRecordset->MoveNext();
		i++;
	}
	m_pRecordset->Close();
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSearchInformationIssue::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	CString str;
	int flag=0;
	POSITION pos = m_list.GetFirstSelectedItemPosition();
	if(pos)
	{
		int nFirstSelItem = m_list.GetNextSelectedItem(pos);		
		str=m_list.GetItemText(nFirstSelItem,0);
	}
	CInformationIssueForm dlg;
	dlg.m_informationIssueID=str;
	dlg.is_search=1;
	dlg.DoModal();
	
	*pResult = 0;
}

⌨️ 快捷键说明

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