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

📄 salecontract.cpp

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

void CSaleContract::OnDelete() 
{
	CAffirm dlg;
	if(dlg.DoModal()!=IDOK)
	{
		return;
	}
	_variant_t RecordsAffected;
	CString strSQL;
	strSQL="delete from saleContract where contractID='";
	strSQL=strSQL+m_contractID+"'";
	(((CSaleApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
	
	
	m_contractList.DeleteAllItems();
	UpdateData(false);
	AfxMessageBox("该合同已删除!");
	OnNextPage();	
	
}

void CSaleContract::OnAddLine() 
{
	CSelectCommodityForQuote dlg;
	if(dlg.DoModal()==IDOK)
	{					
		int i=m_contractList.GetItemCount();
		m_contractList.InsertItem(i,dlg.commodityID);
		m_contractList.SetItemText(i,1,dlg.commodityName);				
		m_contractList.SetItemText(i,2,dlg.price);
		CString str;
		str.Format("%f",dlg.m_truePrice);
		m_contractList.SetItemText(i,3,str);
		str.Format("%d",dlg.m_num);
		m_contractList.SetItemText(i,4,str);				
		AfxMessageBox("插入成功!");
	}
			
	else
	{
		AfxMessageBox("没有增加商品!");
	}
	UpdateData(false);
}

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

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

	CString strSQL;
	//	AfxMessageBox(TreeCurrent);
	if(flag==1)         //添加
	{
		m_psaleContractRecordset->AddNew();
		
		m_psaleContractRecordset->PutCollect("quoteID",_bstr_t(m_planID.Left(25)));
		m_psaleContractRecordset->PutCollect("contractID",_bstr_t(m_contractID.Left(25)));
		m_psaleContractRecordset->PutCollect("formDate",_variant_t(m_formDate));
		m_psaleContractRecordset->PutCollect("saleType",_bstr_t(m_saleType.Left(50)));
		m_psaleContractRecordset->PutCollect("department",_bstr_t(m_department.Left(50)));
		m_psaleContractRecordset->PutCollect("contractType",_bstr_t(m_contractType.Left(50)));
		m_psaleContractRecordset->PutCollect("sellor",_bstr_t(m_seller.Left(50)));
		m_psaleContractRecordset->PutCollect("companyContractPerson",_bstr_t(m_companyContractPerson.Left(50)));
		m_psaleContractRecordset->PutCollect("transportType",_bstr_t(m_transportType.Left(50)));
		m_psaleContractRecordset->PutCollect("consignmentAddress",_bstr_t(m_consignmentAddress.Left(50)));
		m_psaleContractRecordset->PutCollect("clientContractPerson",_bstr_t(m_clientContractPerson.Left(50)));
		m_psaleContractRecordset->PutCollect("payCondition",_bstr_t(m_payCondition.Left(50)));
		m_psaleContractRecordset->PutCollect("subscription",_bstr_t(m_subscription));
		m_psaleContractRecordset->PutCollect("contractEndDate",_variant_t(m_contractEndDate));
		m_psaleContractRecordset->PutCollect("clientName",_variant_t(m_clientName));
		m_psaleContractRecordset->PutCollect("checked",_variant_t("F"));
		
		m_psaleContractRecordset->Update();
		AfxMessageBox(m_contractID);
		strSQL="SELECT * FROM saleContractCommidity" ;	

		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"));
					for(int i=0;i<m_contractList.GetItemCount();i++)
					{
						m_pRecordset->AddNew();
						m_pRecordset->PutCollect("contractID",_bstr_t(m_contractID.Left(25)));
						m_pRecordset->PutCollect("commidityID",_variant_t(m_contractList.GetItemText(i,0).Left(30)));
						m_pRecordset->PutCollect("num",_variant_t(m_contractList.GetItemText(i,3)));
						m_pRecordset->PutCollect("price",_variant_t(m_contractList.GetItemText(i,4)));
						m_pRecordset->Update();
					}
					
					AfxMessageBox("保存成功!");
				}
			}
		}
		catch(_com_error e)///捕捉异常
		{
			CString errormessage;
			MessageBox("创建记录集失败!","错误");
		}
	}
	else if(flag==2)      //修改
	{
		m_psaleContractRecordset->PutCollect("quoteID",_bstr_t(m_planID.Left(25)));
		m_psaleContractRecordset->PutCollect("contractID",_bstr_t(m_contractID.Left(25)));
		m_psaleContractRecordset->PutCollect("formDate",_variant_t(m_formDate));
		m_psaleContractRecordset->PutCollect("saleType",_bstr_t(m_saleType.Left(50)));
		m_psaleContractRecordset->PutCollect("department",_bstr_t(m_department.Left(50)));
		m_psaleContractRecordset->PutCollect("contractType",_bstr_t(m_contractType.Left(50)));
		m_psaleContractRecordset->PutCollect("sellor",_bstr_t(m_seller.Left(50)));
		m_psaleContractRecordset->PutCollect("companyContractPerson",_bstr_t(m_companyContractPerson.Left(50)));
		m_psaleContractRecordset->PutCollect("transportType",_bstr_t(m_transportType.Left(50)));
		m_psaleContractRecordset->PutCollect("consignmentAddress",_bstr_t(m_consignmentAddress.Left(50)));
		m_psaleContractRecordset->PutCollect("clientContractPerson",_bstr_t(m_clientContractPerson.Left(50)));
		m_psaleContractRecordset->PutCollect("payCondition",_bstr_t(m_payCondition.Left(50)));
		m_psaleContractRecordset->PutCollect("subscription",_bstr_t(m_subscription));
		m_psaleContractRecordset->PutCollect("contractEndDate",_variant_t(m_contractEndDate));
		m_psaleContractRecordset->PutCollect("clientName",_variant_t(m_clientName));
		m_psaleContractRecordset->PutCollect("checked",_variant_t("F"));
		
		m_psaleContractRecordset->Update();
		
		_variant_t RecordsAffected;
		CString strSQL;
		strSQL="delete from saleContractCommidity where contractID='";
		strSQL=strSQL+m_contractID+"'";
		(((CSaleApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
		

		strSQL="SELECT * FROM saleContractCommidity" ;	

		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"));
					for(int i=0;i<m_contractList.GetItemCount();i++)
					{
						m_pRecordset->AddNew();
						m_pRecordset->PutCollect("contractID",_variant_t(m_contractID.Left(25)));
						m_pRecordset->PutCollect("commidityID",_variant_t(m_contractList.GetItemText(i,0)));
						m_pRecordset->PutCollect("num",_variant_t(m_contractList.GetItemText(i,3)));
						m_pRecordset->PutCollect("price",_variant_t(m_contractList.GetItemText(i,4)));
						m_pRecordset->Update();
					}
					
					AfxMessageBox("保存成功!");
				}
			}
		}
		catch(_com_error e)///捕捉异常
		{
			CString errormessage;
			MessageBox("创建记录集失败!","错误");
		}
	}
	bt_add->EnableWindow(true);
	bt_prevPage->EnableWindow(true);
	bt_firstPage->EnableWindow(true);
	bt_nextPage->EnableWindow(true);
	bt_lastPage->EnableWindow(true);
	bt_modify->EnableWindow(true);
	bt_addLine->EnableWindow(false);
	bt_deleteLine->EnableWindow(false);
	bt_checked->EnableWindow(true);
	bt_cancellaion->EnableWindow(false);
	UpdateData(false);
	
}

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

void CSaleContract::OnClickContractList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	UpdateData(true);
	POSITION pos = m_contractList.GetFirstSelectedItemPosition();
	if(pos)
	{
		int nFirstSelItem = m_contractList.GetNextSelectedItem(pos);
	}
	bt_addLine->EnableWindow(true);
	bt_deleteLine->EnableWindow(true);
	UpdateData(false);
	
	*pResult = 0;
}

void CSaleContract::OnKillfocusQuoteID() 
{
	CString strSQL;
	HRESULT hTRes;

	UpdateData(true);
	_RecordsetPtr m_pQuoteRecordset;
	_RecordsetPtr m_pRecordset;    //用于创建一个查询记录集

	strSQL="SELECT * FROM quote where quoteID='";
	strSQL=strSQL+m_planID+"'";
	try
	{			
		hTRes = m_pQuoteRecordset.CreateInstance(_T("ADODB.Recordset"));
		if (SUCCEEDED(hTRes))
		{
			hTRes = m_pQuoteRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
				((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
				adOpenDynamic,adLockPessimistic,adCmdText);
			if(SUCCEEDED(hTRes))
			{
				TRACE(_T("连接成功!\n"));
				if (!(m_pQuoteRecordset->adoEOF))
				{					
//					m_formDate =((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pQuoteRecordset->GetCollect("formDate"));
					m_clientName = ((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pQuoteRecordset->GetCollect("client"));
					m_transportType=((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pQuoteRecordset->GetCollect("transportType"));
					m_payCondition=((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pQuoteRecordset->GetCollect("payCondition"));
					m_seller =((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pQuoteRecordset->GetCollect("seller"));
					m_department = ((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pQuoteRecordset->GetCollect("department"));
					m_consignmentAddress = ((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pQuoteRecordset->GetCollect("consignmentAddress"));
					m_remark = ((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pQuoteRecordset->GetCollect("remark"));

					strSQL="select * from quoteProduct where productID='";
					strSQL=strSQL+((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pQuoteRecordset->GetCollect("quoteID"));
					strSQL+="'";
				}
				else
				{
					return;
				}
					
				hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
				hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
				((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
				adOpenDynamic,adLockPessimistic,adCmdText);
				
				m_contractList.DeleteAllItems();
					
				int i=0;
				while(!(m_pRecordset->adoEOF))
				{
					m_contractList.InsertItem(i,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("commidityID")));
					m_contractList.SetItemText(i,1,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("num")));				
					m_contractList.SetItemText(i,2,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("price")));
					if (!(m_pRecordset->adoEOF))
					{
						m_pRecordset->MoveNext();
						i++;
					}
				}
			}
		}
	}
	catch(_com_error e)///捕捉异常
	{
		CString errormessage;
	//	MessageBox("创建记录集失败!","错误");
	}
	UpdateData(false);
}

void CSaleContract::Onauditing() 
{
	CString str;
	GetDlgItemText(IDC_auditing,str);
	if(str=="审核")
	{
		if(m_psaleContractRecordset->adoEOF)
			m_psaleContractRecordset->MovePrevious();
		m_psaleContractRecordset->PutCollect("checked",_variant_t("T"));
		m_psaleContractRecordset->Update();
		AfxMessageBox("通过审核!");
		bt_modify->EnableWindow(false);
		SetDlgItemText(IDC_auditing,"弃审");
	}
	else
	{
		if(m_psaleContractRecordset->adoEOF)
			m_psaleContractRecordset->MovePrevious();
		m_psaleContractRecordset->PutCollect("checked",_variant_t("F"));
		m_psaleContractRecordset->Update();
		AfxMessageBox("审核取消!");
		bt_modify->EnableWindow(true);
		SetDlgItemText(IDC_auditing,"审核");
	}	
}

void CSaleContract::OnCancellation() 
{
	int saleContractID=((CSaleApp*)AfxGetApp())->m_pIDRecordset->GetCollect("saleContractID").intVal;
	CString str;
	str.Format("%d",saleContractID-1);
	((CSaleApp*)AfxGetApp())->m_pIDRecordset->PutCollect("saleContractID",_variant_t(str));
	((CSaleApp*)AfxGetApp())->m_pIDRecordset->Update();
	bt_cancellaion->EnableWindow(false);
	OnNextPage();	
	tx_planID->EnableWindow(false);
	tx_formDate->EnableWindow(false);
	tx_saleType->EnableWindow(false);
	tx_department->EnableWindow(false);
	tx_clientName->EnableWindow(false);
	tx_contractType->EnableWindow(false);
	tx_seller->EnableWindow(false);
	tx_companyContractPerson->EnableWindow(false);
	tx_transportType->EnableWindow(false);
	tx_consignmentAddress->EnableWindow(false);
	tx_clientContractPerson->EnableWindow(false);
	tx_payCondition->EnableWindow(false);
	tx_subscription->EnableWindow(false);
	tx_contractEndDate->EnableWindow(false);
	tx_remark->EnableWindow(false);
	tx_contractID->EnableWindow(false);
}

⌨️ 快捷键说明

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