📄 marketinformationform.cpp
字号:
// MarketInformationForm.cpp : implementation file
//
#include "stdafx.h"
#include "ClientRelationship.h"
#include "MarketInformationForm.h"
#include "MarketInformation.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMarketInformationForm dialog
CMarketInformationForm::CMarketInformationForm(CWnd* pParent /*=NULL*/)
: CDialog(CMarketInformationForm::IDD, pParent)
{
//{{AFX_DATA_INIT(CMarketInformationForm)
m_collectDate = COleDateTime::GetCurrentTime();
m_informationLevel = _T("");
m_collecter = _T("");
m_collectDepartment = _T("");
m_subject = _T("");
m_content = _T("");
m_marketInformationID = _T("");
is_search=0;
//}}AFX_DATA_INIT
}
void CMarketInformationForm::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMarketInformationForm)
DDX_Control(pDX, IDC_collectDepartment, m_departmentCombo);
DDX_Control(pDX, IDC_collecter, m_staffNameCombo);
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_DateTimeCtrl(pDX, IDC_collectDate, m_collectDate);
DDX_CBString(pDX, IDC_informationLevel, m_informationLevel);
DDX_CBString(pDX, IDC_collecter, m_collecter);
DDX_CBString(pDX, IDC_collectDepartment, m_collectDepartment);
DDX_Text(pDX, IDC_subject, m_subject);
DDX_Text(pDX, IDC_content, m_content);
DDX_Text(pDX, IDC_marketInformationID, m_marketInformationID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMarketInformationForm, CDialog)
//{{AFX_MSG_MAP(CMarketInformationForm)
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()
/////////////////////////////////////////////////////////////////////////////
// CMarketInformationForm message handlers
void CMarketInformationForm::Onadd()
{
CString m_formID;
int formID=((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->GetCollect("marketInformationID").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("marketInformationID",_variant_t(str));
((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->Update();
m_collectDate = COleDateTime::GetCurrentTime();
m_informationLevel = _T("");
m_collecter = _T("");
m_collectDepartment = _T("");
m_subject = _T("");
m_content = _T("");
m_marketInformationID = m_formID;
tx_collectDate->EnableWindow(true);
tx_informationLevel->EnableWindow(true);
tx_collecter->EnableWindow(true);
tx_collectDepartment->EnableWindow(true);
tx_subject->EnableWindow(true);
tx_content->EnableWindow(true);
tx_marketInformationID->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 CMarketInformationForm::OnDelete()
{
CMarketInformation marketInformation;
marketInformation.sqlDelete(m_marketInformationID);
m_collectDate = COleDateTime::GetCurrentTime();
m_informationLevel = _T("");
m_collecter = _T("");
m_collectDepartment = _T("");
m_subject = _T("");
m_content = _T("");
m_marketInformationID = "";
Refresh();
tx_collectDate->EnableWindow(false);
tx_informationLevel->EnableWindow(false);
tx_collecter->EnableWindow(false);
tx_collectDepartment->EnableWindow(false);
tx_subject->EnableWindow(false);
tx_content->EnableWindow(false);
tx_marketInformationID->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 CMarketInformationForm::OnModify()
{
tx_collectDate->EnableWindow(true);
tx_informationLevel->EnableWindow(true);
tx_collecter->EnableWindow(true);
tx_collectDepartment->EnableWindow(true);
tx_subject->EnableWindow(true);
tx_content->EnableWindow(true);
tx_marketInformationID->EnableWindow(false);
bt_add->EnableWindow(false);
bt_delete->EnableWindow(false);
bt_modify->EnableWindow(false);
bt_cancelation->EnableWindow(false);
bt_save->EnableWindow(true);
flag=2;
UpdateData(false);
}
void CMarketInformationForm::OnSave()
{
UpdateData(true);
CMarketInformation marketInformation;
marketInformation.SetMarketInformationID(m_marketInformationID);
marketInformation.SetCollectDate(m_collectDate);
marketInformation.SetInformationLevel(m_informationLevel);
marketInformation.SetCollecter(m_collecter);
marketInformation.SetCollectDepartment(m_collectDepartment);
marketInformation.SetSubject(m_subject);
marketInformation.SetContent(m_content);
if(flag==1)
{
marketInformation.sqlInsert();
int i=m_list.GetItemCount();
CString str;
m_list.InsertItem(i,m_marketInformationID);
str.Format("%d-%d-%d",m_collectDate.GetYear(),m_collectDate.GetMonth(),m_collectDate.GetDay());
m_list.SetItemText(i,1,str);
m_list.SetItemText(i,2,m_informationLevel);
m_list.SetItemText(i,3,m_subject);
m_list.SetItemText(i,4,m_collecter);
m_list.SetItemText(i,5,m_collectDepartment);
m_list.SetItemText(i,6,m_content);
}
else if(flag==2)
{
marketInformation.sqlUpdate(m_marketInformationID);
Refresh();
}
tx_collectDate->EnableWindow(false);
tx_informationLevel->EnableWindow(false);
tx_collecter->EnableWindow(false);
tx_collectDepartment->EnableWindow(false);
tx_subject->EnableWindow(false);
tx_content->EnableWindow(false);
tx_marketInformationID->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 CMarketInformationForm::OnCancelation()
{
m_collectDate = COleDateTime::GetCurrentTime();
m_informationLevel = _T("");
m_collecter = _T("");
m_collectDepartment = _T("");
m_subject = _T("");
m_content = _T("");
m_marketInformationID = "";
tx_collectDate->EnableWindow(false);
tx_informationLevel->EnableWindow(false);
tx_collecter->EnableWindow(false);
tx_collectDepartment->EnableWindow(false);
tx_subject->EnableWindow(false);
tx_content->EnableWindow(false);
tx_marketInformationID->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 CMarketInformationForm::OnExit()
{
this->OnCancel();
}
BOOL CMarketInformationForm::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);
m_list.InsertColumn(6,"信息内容",LVCFMT_LEFT,100);
_RecordsetPtr m_pRecordset;
CString strSQL;
HRESULT hTRes;
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
strSQL="select distinct departmentName from department";
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("departmentName")));
m_pRecordset->MoveNext();
i++;
}
m_pRecordset->Close();
strSQL="select distinct staffName from staff";
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 * from marketInformation ";
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
i=0;
CString str;
while (!(m_pRecordset->adoEOF))
{
m_list.InsertItem(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("marketInformationID")));
COleDateTime collectDate= m_pRecordset->GetCollect("collectDate");
str.Format("%d-%d-%d",collectDate.GetYear(),collectDate.GetMonth(),collectDate.GetDay());
m_list.SetItemText(i,1,str);
m_list.SetItemText(i,2, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("informationLevel")));
m_list.SetItemText(i,3, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("subject")));
m_list.SetItemText(i,4, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("collecter")));
m_list.SetItemText(i,5, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("collectDepartment")));
m_list.SetItemText(i,6, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("content")));
m_pRecordset->MoveNext();
i++;
}
tx_collectDate=GetDlgItem(IDC_collectDate);
tx_informationLevel=GetDlgItem(IDC_informationLevel);
tx_collecter=GetDlgItem(IDC_collecter);
tx_collectDepartment=GetDlgItem(IDC_collectDepartment);
tx_subject=GetDlgItem(IDC_subject);
tx_content=GetDlgItem(IDC_content);
tx_marketInformationID=GetDlgItem(IDC_marketInformationID);
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_collectDate->EnableWindow(false);
tx_informationLevel->EnableWindow(false);
tx_collecter->EnableWindow(false);
tx_collectDepartment->EnableWindow(false);
tx_subject->EnableWindow(false);
tx_content->EnableWindow(false);
tx_marketInformationID->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)
{
CMarketInformation marketInformation;
marketInformation.GetData(m_marketInformationID);
m_collectDate = marketInformation.GetCollectDate();
m_informationLevel = marketInformation.GetInformationLevel();
m_collecter = marketInformation.GetCollecter();
m_collectDepartment = marketInformation.GetCollectDepartment();
m_subject = marketInformation.GetSubject();
m_content = marketInformation.GetContent();
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 CMarketInformationForm::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
UpdateData(true);
POSITION pos = m_list.GetFirstSelectedItemPosition();
if(pos)
{
int nFirstSelItem = m_list.GetNextSelectedItem(pos);
m_marketInformationID=m_list.GetItemText(nFirstSelItem,0);
}
CMarketInformation marketInformation;
marketInformation.GetData(m_marketInformationID);
m_collectDate = marketInformation.GetCollectDate();
m_informationLevel = marketInformation.GetInformationLevel();
m_collecter = marketInformation.GetCollecter();
m_collectDepartment = marketInformation.GetCollectDepartment();
m_subject = marketInformation.GetSubject();
m_content = marketInformation.GetContent();
tx_collectDate->EnableWindow(false);
tx_informationLevel->EnableWindow(false);
tx_collecter->EnableWindow(false);
tx_collectDepartment->EnableWindow(false);
tx_subject->EnableWindow(false);
tx_content->EnableWindow(false);
tx_marketInformationID->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 CMarketInformationForm::Refresh()
{
m_list.DeleteAllItems();
CString strSQL;
HRESULT hTRes;
_RecordsetPtr m_pRecordset;
strSQL="select * from marketInformation ";
hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CClientRelationshipApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
int i=0;
CString str;
while (!(m_pRecordset->adoEOF))
{
m_list.InsertItem(i,((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("marketInformationID")));
COleDateTime collectDate= m_pRecordset->GetCollect("collectDate");
str.Format("%d-%d-%d",collectDate.GetYear(),collectDate.GetMonth(),collectDate.GetDay());
m_list.SetItemText(i,1,str);
m_list.SetItemText(i,2, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("informationLevel")));
m_list.SetItemText(i,3, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("subject")));
m_list.SetItemText(i,4, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("collecter")));
m_list.SetItemText(i,5, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("collectDepartment")));
m_list.SetItemText(i,6, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("content")));
m_pRecordset->MoveNext();
i++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -