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

📄 marketinvestigateform.cpp

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

#include "stdafx.h"
#include "ClientRelationship.h"
#include "MarketInvestigateForm.h"
#include "MarketInvestigate.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMarketInvestigateForm dialog


CMarketInvestigateForm::CMarketInvestigateForm(CWnd* pParent /*=NULL*/)
	: CDialog(CMarketInvestigateForm::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMarketInvestigateForm)
	m_summary = _T("");
	m_object = _T("");
	m_investigatePerson = _T("");
	m_investigateDate = COleDateTime::GetCurrentTime();
	m_marketInvestigateID = _T("");
	is_search=0;
	//}}AFX_DATA_INIT
}


void CMarketInvestigateForm::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMarketInvestigateForm)
	DDX_Control(pDX, IDC_investigatePerson, m_staffNameCombo);
	DDX_Control(pDX, IDC_LIST1, m_list);
	DDX_Text(pDX, IDC_summary, m_summary);
	DDX_Text(pDX, IDC_object, m_object);
	DDX_CBString(pDX, IDC_investigatePerson, m_investigatePerson);
	DDX_DateTimeCtrl(pDX, IDC_investigateDate, m_investigateDate);
	DDX_Text(pDX, IDC_marketInvestigateID, m_marketInvestigateID);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMarketInvestigateForm, CDialog)
	//{{AFX_MSG_MAP(CMarketInvestigateForm)
	ON_BN_CLICKED(IDC_add, OnAdd)
	ON_BN_CLICKED(IDC_delete, OnDelete)
	ON_BN_CLICKED(IDC_modify, OnModify)
	ON_BN_CLICKED(IDC_save, OnSave)
	ON_BN_CLICKED(IDC_cancelation, OnCancelation)
	ON_BN_CLICKED(IDC_exit, OnExit)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMarketInvestigateForm message handlers

void CMarketInvestigateForm::OnAdd() 
{
	CString m_formID;
	int formID=((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->GetCollect("marketInvestigateID").intVal;
	if(formID<10)
		m_formID.Format("KHYG0000%d",formID);
	else if(formID<100&&formID>9)
		m_formID.Format("KHYG000%d",formID);
	else if(formID<1000&&formID>99)
		m_formID.Format("KHYG00%d",formID);

	CString str;
	str.Format("%d",formID+1);
	((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->PutCollect("marketInvestigateID",_variant_t(str));
	((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->Update();

	m_summary = _T("");
	m_object = _T("");
	m_investigatePerson = _T("");
	m_investigateDate = COleDateTime::GetCurrentTime();
	m_marketInvestigateID = m_formID;

	tx_summary->EnableWindow(true);
	tx_object->EnableWindow(true);
	tx_investigatePerson->EnableWindow(true);
	tx_investigateDate->EnableWindow(true);
	tx_marketInvestigateID->EnableWindow(false);

	bt_add->EnableWindow(false);
	bt_delete->EnableWindow(false);
	bt_modify->EnableWindow(false);
	bt_cancelation->EnableWindow(true);
	bt_save->EnableWindow(true);

	flag=1;

	UpdateData(false);
	
}

void CMarketInvestigateForm::OnDelete() 
{
	CMarketInvestigate marketInvestigate;
	marketInvestigate.sqlDelete(m_marketInvestigateID);

	m_summary = _T("");
	m_object = _T("");
	m_investigatePerson = _T("");
	m_investigateDate = COleDateTime::GetCurrentTime();
	m_marketInvestigateID = _T("");

	Refresh();

	tx_summary->EnableWindow(false);
	tx_object->EnableWindow(false);
	tx_investigatePerson->EnableWindow(false);
	tx_investigateDate->EnableWindow(false);
	tx_marketInvestigateID->EnableWindow(false);

	bt_add->EnableWindow(true);
	bt_delete->EnableWindow(false);
	bt_modify->EnableWindow(false);
	bt_cancelation->EnableWindow(false);
	bt_save->EnableWindow(false);

	UpdateData(false);
}

void CMarketInvestigateForm::OnModify() 
{
	tx_summary->EnableWindow(true);
	tx_object->EnableWindow(true);
	tx_investigatePerson->EnableWindow(true);
	tx_investigateDate->EnableWindow(true);
	tx_marketInvestigateID->EnableWindow(false);

	bt_add->EnableWindow(false);
	bt_delete->EnableWindow(false);
	bt_modify->EnableWindow(false);
	bt_cancelation->EnableWindow(true);
	bt_save->EnableWindow(true);

	flag=2;

	UpdateData(false);
}

void CMarketInvestigateForm::OnSave() 
{
	UpdateData(true);

	CMarketInvestigate marketInvestigate;

	marketInvestigate.SetMarketInvestigateID(m_marketInvestigateID);
	marketInvestigate.SetSummary(m_summary);
	marketInvestigate.SetObject(m_object);
	marketInvestigate.SetInvestigatePerson(m_investigatePerson);
	marketInvestigate.SetInvestigateDate(m_investigateDate);

	if(flag==1)
	{
		marketInvestigate.sqlInsert();

		int i=m_list.GetItemCount();
		CString str;		
		m_list.InsertItem(i,m_marketInvestigateID);
		str.Format("%d-%d-%d",m_investigateDate.GetYear(),m_investigateDate.GetMonth(),m_investigateDate.GetDay());
		m_list.SetItemText(i,1,str);
		m_list.SetItemText(i,2,m_investigatePerson);
		m_list.SetItemText(i,3,m_object);
		m_list.SetItemText(i,4,m_summary);
	}
	else if(flag==2)
	{
		marketInvestigate.sqlUpdate(m_marketInvestigateID);
		Refresh();
	}

	tx_summary->EnableWindow(false);
	tx_object->EnableWindow(false);
	tx_investigatePerson->EnableWindow(false);
	tx_investigateDate->EnableWindow(false);
	tx_marketInvestigateID->EnableWindow(false);

	bt_add->EnableWindow(true);
	bt_delete->EnableWindow(true);
	bt_modify->EnableWindow(true);
	bt_cancelation->EnableWindow(false);
	bt_save->EnableWindow(false);

	UpdateData(false);
}

void CMarketInvestigateForm::OnCancelation() 
{
	CString m_formID;
	int formID=((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->GetCollect("marketInvestigateID").intVal;
	if(formID<10)
		m_formID.Format("KHYG0000%d",formID);
	else if(formID<100&&formID>9)
		m_formID.Format("KHYG000%d",formID);
	else if(formID<1000&&formID>99)
		m_formID.Format("KHYG00%d",formID);

	CString str;
	str.Format("%d",formID-1);
	((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->PutCollect("marketInvestigateID",_variant_t(str));
	((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->Update();

	m_summary = _T("");
	m_object = _T("");
	m_investigatePerson = _T("");
	m_investigateDate = COleDateTime::GetCurrentTime();
	m_marketInvestigateID = _T("");

	tx_summary->EnableWindow(false);
	tx_object->EnableWindow(false);
	tx_investigatePerson->EnableWindow(false);
	tx_investigateDate->EnableWindow(false);
	tx_marketInvestigateID->EnableWindow(false);

	bt_add->EnableWindow(true);
	bt_delete->EnableWindow(false);
	bt_modify->EnableWindow(false);
	bt_cancelation->EnableWindow(false);
	bt_save->EnableWindow(false);

	UpdateData(false);
	
}

void CMarketInvestigateForm::OnExit() 
{
	this->OnCancel();
	
}

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

	CString strSQL;
	_RecordsetPtr m_pRecordset;
	HRESULT hTRes;
	hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));	
	strSQL="select distinct staffName from staff";
	hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
			((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
	int 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 * from marketInvestigate ";
	hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));				
	hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
			((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
	CString str;
	i=0;
	while(!(m_pRecordset->adoEOF))
	{
		m_list.InsertItem(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("marketInvestigateID")));
		COleDateTime investigateDate= m_pRecordset->GetCollect("investigateDate");
		str.Format("%d-%d-%d",investigateDate.GetYear(),investigateDate.GetMonth(),investigateDate.GetDay());
		m_list.SetItemText(i,1,str);
		m_list.SetItemText(i,2, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("investigatePerson")));
		m_list.SetItemText(i,3, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("object")));
		m_list.SetItemText(i,4, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("summary")));		
	
		m_pRecordset->MoveNext();
		i++;
	}

	tx_summary=GetDlgItem(IDC_summary);
	tx_object=GetDlgItem(IDC_object);
	tx_investigatePerson=GetDlgItem(IDC_investigatePerson);
	tx_investigateDate=GetDlgItem(IDC_investigateDate);
	tx_marketInvestigateID=GetDlgItem(IDC_marketInvestigateID);

	bt_add=GetDlgItem(IDC_add);
	bt_delete=GetDlgItem(IDC_delete);
	bt_modify=GetDlgItem(IDC_modify);
	bt_cancelation=GetDlgItem(IDC_cancelation);
	bt_save=GetDlgItem(IDC_save);

	tx_summary->EnableWindow(false);
	tx_object->EnableWindow(false);
	tx_investigatePerson->EnableWindow(false);
	tx_investigateDate->EnableWindow(false);
	tx_marketInvestigateID->EnableWindow(false);

	if(is_search==0)
	{
		bt_add->EnableWindow(true);
		bt_delete->EnableWindow(false);
		bt_modify->EnableWindow(false);
		bt_cancelation->EnableWindow(false);
		bt_save->EnableWindow(false);
	}
	else if(is_search==1)
	{
		CMarketInvestigate marketInvestigate;
		marketInvestigate.GetData(m_marketInvestigateID);

		m_summary = marketInvestigate.GetSummary();
		m_object = marketInvestigate.GetObject();
		m_investigatePerson = marketInvestigate.GetInvestigatePerson();
		m_investigateDate = marketInvestigate.GetInvestigateDate();
		
		bt_add->EnableWindow(true);
		bt_delete->EnableWindow(true);
		bt_modify->EnableWindow(true);
		bt_cancelation->EnableWindow(false);
		bt_save->EnableWindow(false);
	}

	UpdateData(false);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CMarketInvestigateForm::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	UpdateData(true);
	POSITION pos = m_list.GetFirstSelectedItemPosition();
	if(pos)
	{
		int nFirstSelItem = m_list.GetNextSelectedItem(pos);
		m_marketInvestigateID=m_list.GetItemText(nFirstSelItem,0);
	}

	CMarketInvestigate marketInvestigate;
	marketInvestigate.GetData(m_marketInvestigateID);

	m_summary = marketInvestigate.GetSummary();
	m_object = marketInvestigate.GetObject();
	m_investigatePerson = marketInvestigate.GetInvestigatePerson();
	m_investigateDate = marketInvestigate.GetInvestigateDate();

	tx_summary->EnableWindow(false);
	tx_object->EnableWindow(false);
	tx_investigatePerson->EnableWindow(false);
	tx_investigateDate->EnableWindow(false);
	tx_marketInvestigateID->EnableWindow(false);

	bt_add->EnableWindow(true);
	bt_delete->EnableWindow(true);
	bt_modify->EnableWindow(true);
	bt_cancelation->EnableWindow(false);
	bt_save->EnableWindow(false);

	UpdateData(false);	
	*pResult = 0;
}

void CMarketInvestigateForm::Refresh()
{
	m_list.DeleteAllItems();

	CString strSQL;
	_RecordsetPtr m_pRecordset;
	HRESULT hTRes;

	strSQL="select * from marketInvestigate ";
	hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));				
	hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
			((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
			adOpenDynamic,adLockPessimistic,adCmdText);
	CString str;
	int i=0;
	while(!(m_pRecordset->adoEOF))
	{
		m_list.InsertItem(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("marketInvestigateID")));
		COleDateTime investigateDate= m_pRecordset->GetCollect("investigateDate");
		str.Format("%d-%d-%d",investigateDate.GetYear(),investigateDate.GetMonth(),investigateDate.GetDay());
		m_list.SetItemText(i,1,str);
		m_list.SetItemText(i,2, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("investigatePerson")));
		m_list.SetItemText(i,3, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("object")));
		m_list.SetItemText(i,4, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("summary")));		
	
		m_pRecordset->MoveNext();
		i++;
	}
}

⌨️ 快捷键说明

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