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

📄 sellerplanexecute.cpp

📁 基于VC+SQL SERVER环境开发的企业商品销售系统.完整的数据库和原代码
💻 CPP
字号:
// SellerPlanExecute.cpp : implementation file
//

#include "stdafx.h"
#include "Sale.h"
#include "SellerPlanExecute.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSellerPlanExecute dialog


CSellerPlanExecute::CSellerPlanExecute(CWnd* pParent /*=NULL*/)
	: CDialog(CSellerPlanExecute::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSellerPlanExecute)
	m_year = _T("");
	m_monthBegin = _T("");
	m_monthEnd = _T("");
	m_seller = _T("");
	//}}AFX_DATA_INIT
}


void CSellerPlanExecute::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSellerPlanExecute)
	DDX_Control(pDX, IDC_COMBO4, m_sellerCombo);
	DDX_Control(pDX, IDC_LIST1, m_sellerPlanExecuteList);
	DDX_CBString(pDX, IDC_COMBO1, m_year);
	DDX_CBString(pDX, IDC_COMBO2, m_monthBegin);
	DDX_CBString(pDX, IDC_COMBO3, m_monthEnd);
	DDX_CBString(pDX, IDC_COMBO4, m_seller);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSellerPlanExecute, CDialog)
	//{{AFX_MSG_MAP(CSellerPlanExecute)
	ON_BN_CLICKED(IDC_BUTTON1, OnSearch)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSellerPlanExecute message handlers

void CSellerPlanExecute::OnSearch() 
{
	UpdateData(true);
	CString strSQL;
	HRESULT hTRes;
	strSQL="select * from staffSalePlanView where staffName='";
	strSQL=strSQL+m_seller+"'";
	strSQL=strSQL+" and planYear=";
	strSQL=strSQL+m_year;

//	AfxMessageBox(strSQL);

	float totalPlan=0;
	float totalRatio=0;
	totalPlan=0;
	totalRatio=0;
	_RecordsetPtr m_pSellerSalePlanRecordset;
	hTRes = m_pSellerSalePlanRecordset.CreateInstance(_T("ADODB.Recordset"));
	if (SUCCEEDED(hTRes))
	{
		hTRes = m_pSellerSalePlanRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
		((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
				adOpenDynamic,adLockPessimistic,adCmdText);
		if(SUCCEEDED(hTRes))
		{
			TRACE(_T("连接成功!\n"));
			
			int monthBegin,monthEnd;
			m_sellerPlanExecuteList.DeleteAllItems();
			
			monthBegin=atoi(m_monthBegin);
			monthEnd=atoi(m_monthEnd);
			int j=0;
			if(!(m_pSellerSalePlanRecordset->adoEOF))
			{
				m_sellerPlanExecuteList.InsertItem(j,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pSellerSalePlanRecordset->GetCollect("staffID")));
				m_sellerPlanExecuteList.SetItemText(j,1,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pSellerSalePlanRecordset->GetCollect("staffName")));
			
				while(!(m_pSellerSalePlanRecordset->adoEOF))
				{	
					_variant_t index;
					for(int i=monthBegin;i<monthEnd;i++)
					{					
						index=(long)(i*2+4-2);
						totalPlan=totalPlan+atof((_bstr_t)m_pSellerSalePlanRecordset->GetCollect(index));
						index=(long)(i*2+4-1);
						totalRatio=totalRatio+atof((_bstr_t)m_pSellerSalePlanRecordset->GetCollect(index));
					}
					m_pSellerSalePlanRecordset->MoveNext();		
				}
				CString str;
				str.Format("%f",totalPlan);
				m_sellerPlanExecuteList.SetItemText(j,2,(LPCTSTR)str);
				str.Format("%f",totalRatio);
				m_sellerPlanExecuteList.SetItemText(j,3,(LPCTSTR)str);
			}
		}
	}
	m_pSellerSalePlanRecordset->Close();
	
	strSQL="select * from saleAllView where seller ='";
	strSQL=strSQL+m_seller+"'";
	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_sellerPlanExecuteList.SetItemText(0,4,(LPCTSTR)str);
				str.Format("%f",total-totalPlan);
				m_sellerPlanExecuteList.SetItemText(0,5,(LPCTSTR)str);
				str.Format("%f",total-totalRatio);
				m_sellerPlanExecuteList.SetItemText(0,6,(LPCTSTR)str);
				str.Format("%f",(total-totalPlan)/totalPlan);
				m_sellerPlanExecuteList.SetItemText(0,7,(LPCTSTR)str);
				str.Format("%f",(total-totalRatio)/totalRatio);
				m_sellerPlanExecuteList.SetItemText(0,8,(LPCTSTR)str);		
		}
	}
	UpdateData(false);	
}

BOOL CSellerPlanExecute::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	DWORD style;
	style=m_sellerPlanExecuteList.GetExStyle();
	style=(style|LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT)&(~LVS_EX_CHECKBOXES) ;
	m_sellerPlanExecuteList.SetExtendedStyle(style);

	m_sellerPlanExecuteList.InsertColumn(0,"销售员编号",LVCFMT_LEFT,100);
	m_sellerPlanExecuteList.InsertColumn(1,"销售员姓名",LVCFMT_LEFT,100);
	m_sellerPlanExecuteList.InsertColumn(2,"计划金额",LVCFMT_LEFT,100);
	m_sellerPlanExecuteList.InsertColumn(3,"销售定额",LVCFMT_LEFT,100);
	m_sellerPlanExecuteList.InsertColumn(4,"销售额",LVCFMT_LEFT,100);
	m_sellerPlanExecuteList.InsertColumn(5,"较计划金额",LVCFMT_LEFT,100);
	m_sellerPlanExecuteList.InsertColumn(6,"较销售定额",LVCFMT_LEFT,100);
	m_sellerPlanExecuteList.InsertColumn(7,"计划金额完成率",LVCFMT_LEFT,100);
	m_sellerPlanExecuteList.InsertColumn(8,"销售定额完成率",LVCFMT_LEFT,100);



	CString strSQL;
	HRESULT hTRes;
	

	strSQL="select * from staff";
	_RecordsetPtr m_pSellerRecordset;
	hTRes = m_pSellerRecordset.CreateInstance(_T("ADODB.Recordset"));
	if (SUCCEEDED(hTRes))
	{
		hTRes = m_pSellerRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
		((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
				adOpenDynamic,adLockPessimistic,adCmdText);
		if(SUCCEEDED(hTRes))
		{
			TRACE(_T("连接成功!\n"));
			while(!(m_pSellerRecordset->adoEOF))
			{		
				m_sellerCombo.AddString(((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pSellerRecordset->GetCollect("staffName")));
				m_pSellerRecordset->MoveNext();
			}
		}
	}
	m_pSellerRecordset->Close();

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

⌨️ 快捷键说明

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