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

📄 clientssaleplan.cpp

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

#include "stdafx.h"
#include "Sale.h"
#include "ClientsSalePlan.h"
#include "SelectClient.h"
#include "Affirm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CClientsSalePlan dialog


CClientsSalePlan::CClientsSalePlan(CWnd* pParent /*=NULL*/)
	: CDialog(CClientsSalePlan::IDD, pParent)
{
	//{{AFX_DATA_INIT(CClientsSalePlan)
	m_planID = _T("");
	m_planYear = _T("");
	m_formDate = COleDateTime::GetCurrentTime();
	m_remark = _T("");
	//}}AFX_DATA_INIT
}


void CClientsSalePlan::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CClientsSalePlan)
	DDX_Control(pDX, IDC_LIST1, m_clientSalePlanList);
	DDX_Text(pDX, IDC_planID, m_planID);
	DDX_Text(pDX, IDC_planYear, m_planYear);
	DDX_Text(pDX, IDC_formDate, m_formDate);
	DDX_Text(pDX, IDC_remark, m_remark);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CClientsSalePlan, CDialog)
	//{{AFX_MSG_MAP(CClientsSalePlan)
	ON_BN_CLICKED(IDC_exit, OnExit)
	ON_BN_CLICKED(IDC_save, OnSave)
	ON_BN_CLICKED(IDC_deleteLine, OnDeleteLine)
	ON_BN_CLICKED(IDC_addLine, OnAddLine)
	ON_BN_CLICKED(IDC_delete, OnDelete)
	ON_BN_CLICKED(IDC_modify, OnModify)
	ON_BN_CLICKED(IDC_new, OnNew)
	ON_BN_CLICKED(IDC_lastPage, OnLastPage)
	ON_BN_CLICKED(IDC_nextPage, OnNextPage)
	ON_BN_CLICKED(IDC_prevPage, OnPrevPage)
	ON_BN_CLICKED(IDC_firstPage, OnFirstPage)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickClientSalePlanList)
	ON_BN_CLICKED(IDC_auditing, OnAuditing)
	ON_BN_CLICKED(IDC_cancellation, OnCancellation)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CClientsSalePlan message handlers

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

void CClientsSalePlan::OnSave() 
{
	UpdateData(true);
	_RecordsetPtr m_pRecordset;    //用于创建一个查询记录集


	//----------------------------------------------
	CString strSQL;
	//	AfxMessageBox(TreeCurrent);
	if(flag==1)         //添加
	{
		strSQL="SELECT * FROM clientSalePlan" ;	

		try
		{
			HRESULT hTRes;
			hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
			if (SUCCEEDED(hTRes))
			{
				//----------------------------------------------------
				hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
					((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
					adOpenDynamic,adLockPessimistic,adCmdText);
				if(SUCCEEDED(hTRes))
				{
					TRACE(_T("连接成功!\n"));
					m_pSalePlanRecordset->AddNew();
					m_pSalePlanRecordset->PutCollect("planID",_variant_t(m_planID));
					m_pSalePlanRecordset->PutCollect("planYear",_variant_t(m_planYear));
					m_pSalePlanRecordset->PutCollect("remark",_variant_t(m_remark));
					m_pSalePlanRecordset->PutCollect("planType",_variant_t("c"));
					m_pSalePlanRecordset->PutCollect("formDate",_variant_t(m_formDate));
					m_pSalePlanRecordset->PutCollect("checked",_variant_t("F"));
					m_pSalePlanRecordset->Update();
					//------------------------------------------
					for(int i=0;i<m_clientSalePlanList.GetItemCount();i++)
					{

						m_pRecordset->AddNew();
						
						m_pRecordset->PutCollect("planID",_variant_t(m_planID));
						m_pRecordset->PutCollect("clientID",_variant_t(m_clientSalePlanList.GetItemText(i,0)));
						//以下插入每月的销售计划数额
						m_pRecordset->PutCollect("yearPlan",_variant_t(m_clientSalePlanList.GetItemText(i,2)));
						m_pRecordset->PutCollect("yearRatio",_variant_t(m_clientSalePlanList.GetItemText(i,3)));
						m_pRecordset->PutCollect("JanPlan",_variant_t(m_clientSalePlanList.GetItemText(i,4)));
						m_pRecordset->PutCollect("JanRatio",_variant_t(m_clientSalePlanList.GetItemText(i,5)));
						m_pRecordset->PutCollect("FebPlan",_variant_t(m_clientSalePlanList.GetItemText(i,6)));
						m_pRecordset->PutCollect("FebRatio",_variant_t(m_clientSalePlanList.GetItemText(i,7)));
						m_pRecordset->PutCollect("MarPlan",_variant_t(m_clientSalePlanList.GetItemText(i,8)));
						m_pRecordset->PutCollect("MarRatio",_variant_t(m_clientSalePlanList.GetItemText(i,9)));
						m_pRecordset->PutCollect("AprPlan",_variant_t(m_clientSalePlanList.GetItemText(i,10)));
						m_pRecordset->PutCollect("AprRatio",_variant_t(m_clientSalePlanList.GetItemText(i,11)));
						m_pRecordset->PutCollect("MayPlan",_variant_t(m_clientSalePlanList.GetItemText(i,12)));
						m_pRecordset->PutCollect("MayRatio",_variant_t(m_clientSalePlanList.GetItemText(i,13)));
						m_pRecordset->PutCollect("JunPlan",_variant_t(m_clientSalePlanList.GetItemText(i,14)));
						m_pRecordset->PutCollect("JunRatio",_variant_t(m_clientSalePlanList.GetItemText(i,15)));
						m_pRecordset->PutCollect("JulPlan",_variant_t(m_clientSalePlanList.GetItemText(i,16)));
						m_pRecordset->PutCollect("JulRatio",_variant_t(m_clientSalePlanList.GetItemText(i,17)));
						m_pRecordset->PutCollect("AugPlan",_variant_t(m_clientSalePlanList.GetItemText(i,18)));
						m_pRecordset->PutCollect("AugRatio",_variant_t(m_clientSalePlanList.GetItemText(i,19)));
						m_pRecordset->PutCollect("SepPlan",_variant_t(m_clientSalePlanList.GetItemText(i,20)));
						m_pRecordset->PutCollect("SepRatio",_variant_t(m_clientSalePlanList.GetItemText(i,21)));
						m_pRecordset->PutCollect("OctPlan",_variant_t(m_clientSalePlanList.GetItemText(i,22)));
						m_pRecordset->PutCollect("OctRatio",_variant_t(m_clientSalePlanList.GetItemText(i,23)));
						m_pRecordset->PutCollect("NovPlan",_variant_t(m_clientSalePlanList.GetItemText(i,24)));
						m_pRecordset->PutCollect("NovRatio",_variant_t(m_clientSalePlanList.GetItemText(i,25)));
						m_pRecordset->PutCollect("DecPlan",_variant_t(m_clientSalePlanList.GetItemText(i,26)));
						m_pRecordset->PutCollect("DecRatio",_variant_t(m_clientSalePlanList.GetItemText(i,27)));
						m_pRecordset->Update();
					}
				
					AfxMessageBox("插入成功!");
				}
			}
		}
		catch(_com_error e)///捕捉异常
		{
			CString errormessage;
			MessageBox("创建记录集失败!","错误");
		}
	}
	else if(flag==2)      //修改
	{
		_variant_t RecordsAffected;
		strSQL="delete from clientSalePlan where planID='";
		strSQL=strSQL+m_planID+"'";
		(((CSaleApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
		strSQL="SELECT * FROM clientSalePlan " ;	
		try
		{
			HRESULT hTRes;
			hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
			if (SUCCEEDED(hTRes))
			{
				//----------------------------------------------------
				hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
					((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
					adOpenDynamic,adLockPessimistic,adCmdText);
				if(SUCCEEDED(hTRes))
				{
					TRACE(_T("连接成功!\n"));
				///	m_pSalePlanRecordset->PutCollect("planID",_variant_t(m_planID));
				//	m_pSalePlanRecordset->PutCollect("planYear",_variant_t(m_planYear));
					m_pSalePlanRecordset->PutCollect("remark",_variant_t(m_remark));
					m_pSalePlanRecordset->PutCollect("checked",_variant_t("F"));
					m_pSalePlanRecordset->Update();
					//------------------------------------------
					for(int i=0;i<m_clientSalePlanList.GetItemCount();i++)
					{
						m_pRecordset->AddNew();
						m_pRecordset->PutCollect("planID",_variant_t(m_planID));
						m_pRecordset->PutCollect("clientID",_variant_t(m_clientSalePlanList.GetItemText(i,0)));
						//以下插入每月的销售计划数额
						m_pRecordset->PutCollect("yearPlan",_variant_t(m_clientSalePlanList.GetItemText(i,2)));
						m_pRecordset->PutCollect("yearRatio",_variant_t(m_clientSalePlanList.GetItemText(i,3)));
						m_pRecordset->PutCollect("JanPlan",_variant_t(m_clientSalePlanList.GetItemText(i,4)));
						m_pRecordset->PutCollect("JanRatio",_variant_t(m_clientSalePlanList.GetItemText(i,5)));
						m_pRecordset->PutCollect("FebPlan",_variant_t(m_clientSalePlanList.GetItemText(i,6)));
						m_pRecordset->PutCollect("FebRatio",_variant_t(m_clientSalePlanList.GetItemText(i,7)));
						m_pRecordset->PutCollect("MarPlan",_variant_t(m_clientSalePlanList.GetItemText(i,8)));
						m_pRecordset->PutCollect("MarRatio",_variant_t(m_clientSalePlanList.GetItemText(i,9)));
						m_pRecordset->PutCollect("AprPlan",_variant_t(m_clientSalePlanList.GetItemText(i,10)));
						m_pRecordset->PutCollect("AprRatio",_variant_t(m_clientSalePlanList.GetItemText(i,11)));
						m_pRecordset->PutCollect("MayPlan",_variant_t(m_clientSalePlanList.GetItemText(i,12)));
						m_pRecordset->PutCollect("MayRatio",_variant_t(m_clientSalePlanList.GetItemText(i,13)));
						m_pRecordset->PutCollect("JunPlan",_variant_t(m_clientSalePlanList.GetItemText(i,14)));
						m_pRecordset->PutCollect("JunRatio",_variant_t(m_clientSalePlanList.GetItemText(i,15)));
						m_pRecordset->PutCollect("JulPlan",_variant_t(m_clientSalePlanList.GetItemText(i,16)));
						m_pRecordset->PutCollect("JulRatio",_variant_t(m_clientSalePlanList.GetItemText(i,17)));
						m_pRecordset->PutCollect("AugPlan",_variant_t(m_clientSalePlanList.GetItemText(i,18)));
						m_pRecordset->PutCollect("AugRatio",_variant_t(m_clientSalePlanList.GetItemText(i,19)));
						m_pRecordset->PutCollect("SepPlan",_variant_t(m_clientSalePlanList.GetItemText(i,20)));
						m_pRecordset->PutCollect("SepRatio",_variant_t(m_clientSalePlanList.GetItemText(i,21)));
						m_pRecordset->PutCollect("OctPlan",_variant_t(m_clientSalePlanList.GetItemText(i,22)));
						m_pRecordset->PutCollect("OctRatio",_variant_t(m_clientSalePlanList.GetItemText(i,23)));
						m_pRecordset->PutCollect("NovPlan",_variant_t(m_clientSalePlanList.GetItemText(i,24)));
						m_pRecordset->PutCollect("NovRatio",_variant_t(m_clientSalePlanList.GetItemText(i,25)));
						m_pRecordset->PutCollect("DecPlan",_variant_t(m_clientSalePlanList.GetItemText(i,26)));
						m_pRecordset->PutCollect("DecRatio",_variant_t(m_clientSalePlanList.GetItemText(i,27)));
						
						m_pRecordset->Update();
					}
				
					AfxMessageBox("插入成功!");
				}
			}
		}
		catch(_com_error e)///捕捉异常
		{
			CString errormessage;
			MessageBox("创建记录集失败!","错误");
		}
	}
	bt_checked->EnableWindow(true);
	bt_cancellation->EnableWindow(false);
	UpdateData(false);	
}

void CClientsSalePlan::OnDeleteLine() 
{
	CAffirm dlg;
	if(dlg.DoModal()!=IDOK)
	{
		return;
	}	
	POSITION pos = m_clientSalePlanList.GetFirstSelectedItemPosition();
	if(pos)
	{
		int nFirstSelItem = m_clientSalePlanList.GetNextSelectedItem(pos);
		m_clientSalePlanList.DeleteItem(nFirstSelItem);
	}
}

void CClientsSalePlan::OnAddLine() 
{
	CSelectClient dlg;
	if(dlg.DoModal()==IDOK)
	{
		UpdateData(true);
		int i=m_clientSalePlanList.GetItemCount();
		m_clientSalePlanList.InsertItem(i,dlg.clientID);
		m_clientSalePlanList.SetItemText(i,1,dlg.clientName);
		
		CString str;
		double yearPlan=0;
		double yearRatio=0;
		str.Format("%f",dlg.m_JanPlan);
		m_clientSalePlanList.SetItemText(i,4,str);
		yearPlan+=dlg.m_JanPlan;
		str.Format("%f",dlg.m_JanRatio);
		m_clientSalePlanList.SetItemText(i,5,str);
		yearRatio+=dlg.m_JanRatio;
		str.Format("%f",dlg.m_FebPlan);
		m_clientSalePlanList.SetItemText(i,6,str);
		yearPlan+=dlg.m_FebPlan;
		str.Format("%f",dlg.m_FebRatio);
		m_clientSalePlanList.SetItemText(i,7,str);
		yearRatio+=dlg.m_FebRatio;
		str.Format("%f",dlg.m_MarPlan);
		m_clientSalePlanList.SetItemText(i,8,str);
		yearPlan+=dlg.m_MarPlan;
		str.Format("%f",dlg.m_MarRatio);
		m_clientSalePlanList.SetItemText(i,9,str);

⌨️ 快捷键说明

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