📄 advertiseform.cpp
字号:
// AdvertiseForm.cpp : implementation file
//
#include "stdafx.h"
#include "ClientRelationship.h"
#include "AdvertiseForm.h"
#include "Advertise.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAdvertiseForm dialog
CAdvertiseForm::CAdvertiseForm(CWnd* pParent /*=NULL*/)
: CDialog(CAdvertiseForm::IDD, pParent)
{
//{{AFX_DATA_INIT(CAdvertiseForm)
m_formDate = COleDateTime::GetCurrentTime();
m_chargePerson = _T("");
m_trueInput = 0.0f;
m_planCompany = _T("");
m_productName = _T("");
m_inputCondition = _T("");
m_remark = _T("");
m_advertiseID = _T("");
is_search=0;
//}}AFX_DATA_INIT
}
void CAdvertiseForm::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAdvertiseForm)
DDX_Control(pDX, IDC_chargePerson, m_staffNameCombo);
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_DateTimeCtrl(pDX, IDC_formDate, m_formDate);
DDX_CBString(pDX, IDC_chargePerson, m_chargePerson);
DDX_Text(pDX, IDC_trueInput, m_trueInput);
DDX_Text(pDX, IDC_planCompany, m_planCompany);
DDX_CBString(pDX, IDC_productName, m_productName);
DDX_Text(pDX, IDC_inputCondition, m_inputCondition);
DDX_Text(pDX, IDC_remark, m_remark);
DDX_Text(pDX, IDC_advertiseID, m_advertiseID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAdvertiseForm, CDialog)
//{{AFX_MSG_MAP(CAdvertiseForm)
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()
/////////////////////////////////////////////////////////////////////////////
// CAdvertiseForm message handlers
void CAdvertiseForm::OnAdd()
{
CString m_formID;
int formID=((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->GetCollect("advertiseID").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("advertiseID",_variant_t(str));
((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->Update();
m_formDate = COleDateTime::GetCurrentTime();
m_chargePerson = _T("");
m_trueInput = 0.0f;
m_planCompany = _T("");
m_productName = _T("");
m_inputCondition = _T("");
m_remark = _T("");
m_advertiseID = m_formID;
tx_formDate->EnableWindow(true);
tx_chargePerson->EnableWindow(true);
tx_trueInput->EnableWindow(true);
tx_planCompany->EnableWindow(true);
tx_productName->EnableWindow(true);
tx_inputCondition->EnableWindow(true);
tx_remark->EnableWindow(true);
tx_advertiseID->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 CAdvertiseForm::OnDelete()
{
CAdvertise advertise;
advertise.sqlDelete(m_advertiseID);
m_formDate = COleDateTime::GetCurrentTime();
m_chargePerson = _T("");
m_trueInput = 0.0f;
m_planCompany = _T("");
m_productName = _T("");
m_inputCondition = _T("");
m_remark = _T("");
m_advertiseID = _T("");
Refresh();
tx_formDate->EnableWindow(false);
tx_chargePerson->EnableWindow(false);
tx_trueInput->EnableWindow(false);
tx_planCompany->EnableWindow(false);
tx_productName->EnableWindow(false);
tx_inputCondition->EnableWindow(false);
tx_remark->EnableWindow(false);
tx_advertiseID->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 CAdvertiseForm::OnModify()
{
tx_formDate->EnableWindow(true);
tx_chargePerson->EnableWindow(true);
tx_trueInput->EnableWindow(true);
tx_planCompany->EnableWindow(true);
tx_productName->EnableWindow(true);
tx_inputCondition->EnableWindow(true);
tx_remark->EnableWindow(true);
tx_advertiseID->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 CAdvertiseForm::OnSave()
{
UpdateData(true);
CAdvertise advertise;
advertise.SetAdvertiseID(m_advertiseID);
advertise.SetFormDate(m_formDate);
advertise.SetChargePerson(m_chargePerson);
advertise.SetTrueInput(m_trueInput);
advertise.SetPlanCompany(m_planCompany);
advertise.SetProductName(m_productName);
advertise.SetInputCondition(m_inputCondition);
advertise.SetRemark(m_remark);
if(flag==1)
{
advertise.sqlInsert();
int i=m_list.GetItemCount();
CString str;
m_list.InsertItem(i,m_advertiseID);
str.Format("%d-%d-%d",m_formDate.GetYear(),m_formDate.GetMonth(),m_formDate.GetDay());
m_list.SetItemText(i,1,str);
m_list.SetItemText(i,2,m_chargePerson);
str.Format("%f",m_trueInput);
m_list.SetItemText(i,3,str);
m_list.SetItemText(i,4,m_planCompany);
m_list.SetItemText(i,5,m_productName);
m_list.SetItemText(i,6,m_inputCondition);
m_list.SetItemText(i,7,m_remark);
}
else if(flag==2)
{
advertise.sqlUpdate(m_advertiseID);
Refresh();
}
tx_formDate->EnableWindow(false);
tx_chargePerson->EnableWindow(false);
tx_trueInput->EnableWindow(false);
tx_planCompany->EnableWindow(false);
tx_productName->EnableWindow(false);
tx_inputCondition->EnableWindow(false);
tx_remark->EnableWindow(false);
tx_advertiseID->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 CAdvertiseForm::OnCancelation()
{
CString m_formID;
int formID=((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->GetCollect("advertiseID").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("advertiseID",_variant_t(str));
((CClientRelationshipApp*)AfxGetApp())->m_pIDRecordset->Update();
m_formDate = COleDateTime::GetCurrentTime();
m_chargePerson = _T("");
m_trueInput = 0.0f;
m_planCompany = _T("");
m_productName = _T("");
m_inputCondition = _T("");
m_remark = _T("");
m_advertiseID = _T("");
tx_formDate->EnableWindow(false);
tx_chargePerson->EnableWindow(false);
tx_trueInput->EnableWindow(false);
tx_planCompany->EnableWindow(false);
tx_productName->EnableWindow(false);
tx_inputCondition->EnableWindow(false);
tx_remark->EnableWindow(false);
tx_advertiseID->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 CAdvertiseForm::OnExit()
{
this->OnCancel();
}
BOOL CAdvertiseForm::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);
m_list.InsertColumn(7,"备注",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 advertise ";
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("advertiseID")));
COleDateTime formDate= m_pRecordset->GetCollect("formDate");
str.Format("%d-%d-%d",formDate.GetYear(),formDate.GetMonth(),formDate.GetDay());
m_list.SetItemText(i,1,str);
m_list.SetItemText(i,2, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("chargePerson")));
m_list.SetItemText(i,3, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("trueInput")));
m_list.SetItemText(i,4, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("planCompany")));
m_list.SetItemText(i,5, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("productName")));
m_list.SetItemText(i,6, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("inputCondition")));
m_list.SetItemText(i,7, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("remark")));
m_pRecordset->MoveNext();
i++;
}
tx_formDate=GetDlgItem(IDC_formDate);
tx_chargePerson=GetDlgItem(IDC_chargePerson);
tx_trueInput=GetDlgItem(IDC_trueInput);
tx_planCompany=GetDlgItem(IDC_planCompany);
tx_productName=GetDlgItem(IDC_productName);
tx_inputCondition=GetDlgItem(IDC_inputCondition);
tx_remark=GetDlgItem(IDC_remark);
tx_advertiseID=GetDlgItem(IDC_advertiseID);
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_formDate->EnableWindow(false);
tx_chargePerson->EnableWindow(false);
tx_trueInput->EnableWindow(false);
tx_planCompany->EnableWindow(false);
tx_productName->EnableWindow(false);
tx_inputCondition->EnableWindow(false);
tx_remark->EnableWindow(false);
tx_advertiseID->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)
{
CAdvertise advertise;
advertise.GetData(m_advertiseID);
m_formDate = advertise.GetFormDate();
m_chargePerson = advertise.GetChargePerson();
m_trueInput = advertise.GetTrueInput();
m_planCompany = advertise.GetPlanCompany();
m_productName = advertise.GetProductName();
m_inputCondition = advertise.GetInputCondition();
m_remark = advertise.GetRemark();
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 CAdvertiseForm::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
UpdateData(true);
POSITION pos = m_list.GetFirstSelectedItemPosition();
if(pos)
{
int nFirstSelItem = m_list.GetNextSelectedItem(pos);
m_advertiseID=m_list.GetItemText(nFirstSelItem,0);
}
CAdvertise advertise;
advertise.GetData(m_advertiseID);
m_formDate = advertise.GetFormDate();
m_chargePerson = advertise.GetChargePerson();
m_trueInput = advertise.GetTrueInput();
m_planCompany = advertise.GetPlanCompany();
m_productName = advertise.GetProductName();
m_inputCondition = advertise.GetInputCondition();
m_remark = advertise.GetRemark();
tx_formDate->EnableWindow(false);
tx_chargePerson->EnableWindow(false);
tx_trueInput->EnableWindow(false);
tx_planCompany->EnableWindow(false);
tx_productName->EnableWindow(false);
tx_inputCondition->EnableWindow(false);
tx_remark->EnableWindow(false);
tx_advertiseID->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 CAdvertiseForm::Refresh()
{
m_list.DeleteAllItems();
CString strSQL;
_RecordsetPtr m_pRecordset;
HRESULT hTRes;
strSQL="select * from advertise ";
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("advertiseID")));
COleDateTime formDate= m_pRecordset->GetCollect("formDate");
str.Format("%d-%d-%d",formDate.GetYear(),formDate.GetMonth(),formDate.GetDay());
m_list.SetItemText(i,1,str);
m_list.SetItemText(i,2, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("chargePerson")));
m_list.SetItemText(i,3, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("trueInput")));
m_list.SetItemText(i,4, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("planCompany")));
m_list.SetItemText(i,5, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("productName")));
m_list.SetItemText(i,6, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("inputCondition")));
m_list.SetItemText(i,7, ((CClientRelationshipApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("remark")));
m_pRecordset->MoveNext();
i++;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -