📄 departmentplanexecute.cpp
字号:
// DepartmentPlanExecute.cpp : implementation file
//
#include "stdafx.h"
#include "Sale.h"
#include "DepartmentPlanExecute.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDepartmentPlanExecute dialog
CDepartmentPlanExecute::CDepartmentPlanExecute(CWnd* pParent /*=NULL*/)
: CDialog(CDepartmentPlanExecute::IDD, pParent)
{
//{{AFX_DATA_INIT(CDepartmentPlanExecute)
m_year = _T("");
m_monthBegin = _T("");
m_monthEnd = _T("");
m_department = _T("");
//}}AFX_DATA_INIT
}
void CDepartmentPlanExecute::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDepartmentPlanExecute)
DDX_Control(pDX, IDC_department, m_departmentCombo);
DDX_Control(pDX, IDC_LIST1, m_departmentPlanExecuteList);
DDX_CBString(pDX, IDC_year, m_year);
DDX_CBString(pDX, IDC_monthBegin, m_monthBegin);
DDX_CBString(pDX, IDC_monthEnd, m_monthEnd);
DDX_CBString(pDX, IDC_department, m_department);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDepartmentPlanExecute, CDialog)
//{{AFX_MSG_MAP(CDepartmentPlanExecute)
ON_BN_CLICKED(IDC_search, OnSearch)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDepartmentPlanExecute message handlers
BOOL CDepartmentPlanExecute::OnInitDialog()
{
CDialog::OnInitDialog();
DWORD style;
style=m_departmentPlanExecuteList.GetExStyle();
style=(style|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT)&(~LVS_EX_CHECKBOXES) ;
m_departmentPlanExecuteList.SetExtendedStyle(style);
m_departmentPlanExecuteList.InsertColumn(0,"部门编号",LVCFMT_LEFT,100);
m_departmentPlanExecuteList.InsertColumn(1,"部门名称",LVCFMT_LEFT,100);
m_departmentPlanExecuteList.InsertColumn(2,"计划金额",LVCFMT_LEFT,100);
m_departmentPlanExecuteList.InsertColumn(3,"销售定额",LVCFMT_LEFT,100);
m_departmentPlanExecuteList.InsertColumn(4,"销售额",LVCFMT_LEFT,100);
m_departmentPlanExecuteList.InsertColumn(5,"较计划金额",LVCFMT_LEFT,100);
m_departmentPlanExecuteList.InsertColumn(6,"较销售定额",LVCFMT_LEFT,100);
m_departmentPlanExecuteList.InsertColumn(7,"计划金额完成率",LVCFMT_LEFT,100);
m_departmentPlanExecuteList.InsertColumn(8,"销售定额完成率",LVCFMT_LEFT,100);
CString strSQL;
HRESULT hTRes;
strSQL="select * from department";
_RecordsetPtr m_pDepartmentRecordset;
hTRes = m_pDepartmentRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = m_pDepartmentRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
TRACE(_T("连接成功!\n"));
while(!(m_pDepartmentRecordset->adoEOF))
{
m_departmentCombo.AddString(((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pDepartmentRecordset->GetCollect("departmentName")));
m_pDepartmentRecordset->MoveNext();
}
}
}
m_pDepartmentRecordset->Close();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDepartmentPlanExecute::OnSearch()
{
UpdateData(true);
CString strSQL;
HRESULT hTRes;
strSQL="select * from departmentSalePlanView where departmentName='";
strSQL=strSQL+m_department+"'";
strSQL=strSQL+" and planYear=";
strSQL=strSQL+m_year;
float totalPlan=0;
float totalRatio=0;
totalPlan=0;
totalRatio=0;
// AfxMessageBox(strSQL);
_RecordsetPtr m_pDepartmentSalePlanRecordset;
hTRes = m_pDepartmentSalePlanRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = m_pDepartmentSalePlanRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
int monthBegin,monthEnd;
m_departmentPlanExecuteList.DeleteAllItems();
monthBegin=atoi(m_monthBegin);
monthEnd=atoi(m_monthEnd);
int j=0;
if(!(m_pDepartmentSalePlanRecordset->adoEOF))
{
m_departmentPlanExecuteList.InsertItem(j,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pDepartmentSalePlanRecordset->GetCollect("departmentID")));
m_departmentPlanExecuteList.SetItemText(j,1,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pDepartmentSalePlanRecordset->GetCollect("departmentName")));
while(!(m_pDepartmentSalePlanRecordset->adoEOF))
{
_variant_t index;
for(int i=monthBegin;i<monthEnd;i++)
{
index=(long)(i*2+4-2);
totalPlan=totalPlan+atof((_bstr_t)m_pDepartmentSalePlanRecordset->GetCollect(index));
index=(long)(i*2+4-1);
totalRatio=totalRatio+atof((_bstr_t)m_pDepartmentSalePlanRecordset->GetCollect(index));
}
m_pDepartmentSalePlanRecordset->MoveNext();
}
}
CString str;
str.Format("%f",totalPlan);
m_departmentPlanExecuteList.SetItemText(j,2,(LPCTSTR)str);
str.Format("%f",totalRatio);
m_departmentPlanExecuteList.SetItemText(j,3,(LPCTSTR)str);
}
}
m_pDepartmentSalePlanRecordset->Close();
strSQL="select * from saleAllView where department='";
strSQL=strSQL+m_department+"'";
strSQL=strSQL+" and formDate>='";
strSQL=strSQL+m_year+"-";
strSQL=strSQL+m_monthBegin+"-1' and formDate<='";
strSQL=strSQL+m_year+"-";
strSQL=strSQL+m_monthEnd+"-1'";
_RecordsetPtr m_pConsignmentFormCommidityRecordset;
float total;
total=0;
hTRes = m_pConsignmentFormCommidityRecordset.CreateInstance(_T("ADODB.Recordset"));
if (SUCCEEDED(hTRes))
{
hTRes = m_pConsignmentFormCommidityRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(SUCCEEDED(hTRes))
{
TRACE(_T("连接成功!\n"));
if(!(m_pConsignmentFormCommidityRecordset->adoEOF))
{
while(!(m_pConsignmentFormCommidityRecordset->adoEOF))
{
total=total+(atoi(_bstr_t(m_pConsignmentFormCommidityRecordset->GetCollect("num"))))*
(atof((_bstr_t)(m_pConsignmentFormCommidityRecordset->GetCollect("price"))));
m_pConsignmentFormCommidityRecordset->MoveNext();
}
}
CString str;
str.Format("%f",total);
m_departmentPlanExecuteList.SetItemText(0,4,(LPCTSTR)str);
str.Format("%f",total-totalPlan);
m_departmentPlanExecuteList.SetItemText(0,5,(LPCTSTR)str);
str.Format("%f",total-totalRatio);
m_departmentPlanExecuteList.SetItemText(0,6,(LPCTSTR)str);
str.Format("%f",(total-totalPlan)/totalPlan);
m_departmentPlanExecuteList.SetItemText(0,7,(LPCTSTR)str);
str.Format("%f",(total-totalRatio)/totalRatio);
m_departmentPlanExecuteList.SetItemText(0,8,(LPCTSTR)str);
}
}
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -