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

📄 quoteform.cpp

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

		CString checked;
		checked=((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pQuoteRecordset->GetCollect("checked"));
		if(checked=="T")
		{
			SetDlgItemText(IDC_auditing,"弃审");
			bt_modify->EnableWindow(false);
		}
		else
		{
			SetDlgItemText(IDC_auditing,"审核");
			bt_modify->EnableWindow(true);
		}

		strSQL="select * from testView where quoteID='";
		strSQL=strSQL+((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pQuoteRecordset->GetCollect("quoteID"));
		strSQL+="'";
	}
	
	hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
	hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
		((CSaleApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
		adOpenDynamic,adLockPessimistic,adCmdText);

	int i=0;
	m_quoteList.DeleteAllItems();
	while(!(m_pRecordset->adoEOF))
	{
		m_quoteList.InsertItem(i,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("commodityID")));
		m_quoteList.SetItemText(i,1,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("commodityName")));
		m_quoteList.SetItemText(i,2,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("standardPrice")));
		m_quoteList.SetItemText(i,3,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("num")));				
		m_quoteList.SetItemText(i,4,((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pRecordset->GetCollect("truePrice")));
		if (!(m_pRecordset->adoEOF))
		{
			m_pRecordset->MoveNext();
			i++;
		}
	}
	bt_lastPage->EnableWindow(false);
	bt_nextPage->EnableWindow(false);
	bt_firstPage->EnableWindow(true);
	bt_prevPage->EnableWindow(true);
	UpdateData(false);	
}





void CQuoteForm::OnModify() 
{
	CString str;
	str=((CSaleApp*)AfxGetApp())->GetStringFromVariant(m_pQuoteRecordset->GetCollect("checked"));
	if(str=="T")
	{
		AfxMessageBox("已经通过审核,不可以修改!");
		return;
	}
	else
	{
		SetDlgItemText(IDC_auditing,"审核");
		flag=2;	

		tx_quoteID->EnableWindow(false);
		tx_formDate->EnableWindow(true);
		tx_client->EnableWindow(true);
		tx_transportType->EnableWindow(true);
		tx_payCondition->EnableWindow(true);
		tx_seller->EnableWindow(true);
		tx_department->EnableWindow(true);
		tx_consignmentAddreess->EnableWindow(true);
		tx_remark->EnableWindow(true);

		bt_save->EnableWindow(true);
		bt_prevPage->EnableWindow(false);
		bt_firstPage->EnableWindow(false);
		bt_nextPage->EnableWindow(false);
		bt_lastPage->EnableWindow(false);
		bt_add->EnableWindow(false);
		bt_addLine->EnableWindow(true);
		bt_deleteLine->EnableWindow(true);
		}
	UpdateData(false);	
}

void CQuoteForm::OnDelete() 
{
	CAffirm dlg;
	if(dlg.DoModal()!=IDOK)
	{
		return;
	}
	_variant_t RecordsAffected;
	CString strSQL;
	strSQL="delete from quote where quoteID='";
	strSQL=strSQL+m_quoteID+"'";
	(((CSaleApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
	m_quoteList.DeleteAllItems();
	UpdateData(false);
	AfxMessageBox("该报价单已删除!");

	OnNextPage();	
}

void CQuoteForm::OnAddLine() 
{
	CSelectCommodityForQuote dlg;
	if(dlg.DoModal()==IDOK)
	{
		UpdateData(true);
		int i=m_quoteList.GetItemCount();
		m_quoteList.InsertItem(i,dlg.commodityID);
		m_quoteList.SetItemText(i,1,dlg.commodityName);				
		m_quoteList.SetItemText(i,2,dlg.price);
		CString str;
		str.Format("%f",dlg.m_truePrice);
		m_quoteList.SetItemText(i,4,str);
		str.Format("%d",dlg.m_num);
		m_quoteList.SetItemText(i,3,str);
		UpdateData(false);
	}
	else
	{
		AfxMessageBox("没有添加任何商品!");
	}

}

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

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

	CString strSQL;
	//	AfxMessageBox(TreeCurrent);
	if(flag==1)         //添加
	{
		m_pQuoteRecordset->AddNew();
		m_pQuoteRecordset->PutCollect("quoteID",_variant_t(m_quoteID.Left(25)));
		m_pQuoteRecordset->PutCollect("formDate",_variant_t(m_formDate));
		m_pQuoteRecordset->PutCollect("client",_variant_t(m_client.Left(50)));
		m_pQuoteRecordset->PutCollect("transportType",_variant_t(m_transportType.Left(50)));
		m_pQuoteRecordset->PutCollect("payCondition",_variant_t(m_payCondition.Left(50)));
		m_pQuoteRecordset->PutCollect("seller",_variant_t(m_seller.Left(50)));
		m_pQuoteRecordset->PutCollect("department",_variant_t(m_department.Left(50)));
		m_pQuoteRecordset->PutCollect("consignmentAddress",_variant_t(m_consignmentAddreess.Left(50)));
		m_pQuoteRecordset->PutCollect("remark",_variant_t(m_remark.Left(100)));
		m_pQuoteRecordset->PutCollect("checked",_variant_t("F"));
		m_pQuoteRecordset->Update();
		strSQL="SELECT * FROM quoteProduct" ;	

		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_quoteList.GetItemCount();i++)
					{
						m_pRecordset->AddNew();
						m_pRecordset->PutCollect("quoteID",_variant_t(m_quoteID.Left(25)));
						m_pRecordset->PutCollect("productID",_variant_t(m_quoteList.GetItemText(i,0).Left(25)));
						m_pRecordset->PutCollect("num",_variant_t(m_quoteList.GetItemText(i,3)));
						m_pRecordset->PutCollect("price",_variant_t(m_quoteList.GetItemText(i,4)));
						m_pRecordset->Update();
					}
					
					AfxMessageBox("保存成功!");
				}
			}
		}
		catch(_com_error e)///捕捉异常
		{
			CString errormessage;
			MessageBox("创建记录集失败!","错误");
		}
	}
	else if(flag==2)      //修改
	{
		_variant_t RecordsAffected;
		CString strSQL;
		strSQL="delete from quoteProduct where quoteID='";
		strSQL=strSQL+m_quoteID+"'";
		(((CSaleApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
		

		m_pQuoteRecordset->PutCollect("quoteID",_variant_t(m_quoteID.Left(25)));
		m_pQuoteRecordset->PutCollect("formDate",_variant_t(m_formDate));
		m_pQuoteRecordset->PutCollect("client",_variant_t(m_client.Left(50)));
		m_pQuoteRecordset->PutCollect("transportType",_variant_t(m_transportType.Left(50)));
		m_pQuoteRecordset->PutCollect("payCondition",_variant_t(m_payCondition.Left(50)));
		m_pQuoteRecordset->PutCollect("seller",_variant_t(m_seller.Left(50)));
		m_pQuoteRecordset->PutCollect("department",_variant_t(m_department.Left(50)));
		m_pQuoteRecordset->PutCollect("consignmentAddress",_variant_t(m_consignmentAddreess.Left(50)));
		m_pQuoteRecordset->PutCollect("remark",_variant_t(m_remark.Left(100)));
		m_pQuoteRecordset->PutCollect("checked",_variant_t("F"));
		m_pQuoteRecordset->Update();

		strSQL="SELECT * FROM quoteProduct" ;	

		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_quoteList.GetItemCount();i++)
					{
						m_pRecordset->AddNew();
						m_pRecordset->PutCollect("quoteID",_variant_t(m_quoteID.Left(25)));
						m_pRecordset->PutCollect("productID",_variant_t(m_quoteList.GetItemText(i,0)));
						m_pRecordset->PutCollect("num",_variant_t(m_quoteList.GetItemText(i,3)));
						m_pRecordset->PutCollect("price",_variant_t(m_quoteList.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_cancellation->EnableWindow(false);

	tx_quoteID->EnableWindow(false);
	tx_formDate->EnableWindow(false);
	tx_client->EnableWindow(false);
	tx_transportType->EnableWindow(false);
	tx_payCondition->EnableWindow(false);
	tx_seller->EnableWindow(false);
	tx_department->EnableWindow(false);
	tx_consignmentAddreess->EnableWindow(false);
	tx_remark->EnableWindow(false);
	UpdateData(false);
}


void CQuoteForm::OnCancellation() 
{
	int quoteFormID=((CSaleApp*)AfxGetApp())->m_pIDRecordset->GetCollect("quoteFormID").intVal;
	quoteFormID-=1;
	CString str;
	str.Format("%d",quoteFormID);
	((CSaleApp*)AfxGetApp())->m_pIDRecordset->PutCollect("quoteFormID",(_variant_t)str);
	((CSaleApp*)AfxGetApp())->m_pIDRecordset->Update();
	tx_quoteID->EnableWindow(false);
	tx_formDate->EnableWindow(false);
	tx_client->EnableWindow(false);
	tx_transportType->EnableWindow(false);
	tx_payCondition->EnableWindow(false);
	tx_seller->EnableWindow(false);
	tx_department->EnableWindow(false);
	tx_consignmentAddreess->EnableWindow(false);
	tx_remark->EnableWindow(false);

	bt_firstPage->EnableWindow(false);
	bt_prevPage->EnableWindow(false);
	bt_save->EnableWindow(false);
	bt_modify->EnableWindow(true);
	bt_delete->EnableWindow(true);
	bt_addLine->EnableWindow(false);
	bt_deleteLine->EnableWindow(false);
	bt_cancellation->EnableWindow(false);
	OnNextPage();		
}

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

⌨️ 快捷键说明

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