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

📄 productoutputform.cpp

📁 企业库存管理系统, 企业库存管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
}

void CProductOutputForm::OnClickList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	
	*pResult = 0;
}

void CProductOutputForm::OnAdd() 
{
	flag=1;
	bt_add->EnableWindow(false);
	bt_delete->EnableWindow(false);
	bt_save->EnableWindow(true);
	bt_modify->EnableWindow(false);	
	bt_addLine->EnableWindow(true);
	bt_deleteLine->EnableWindow(true);
	bt_cancelation->EnableWindow(true);

	tx_storeHouse->EnableWindow(true);
	tx_department->EnableWindow(true);
	tx_seller->EnableWindow(true);
	tx_clientName->EnableWindow(true);
	tx_houseOutType->EnableWindow(true);
	tx_consignmentFormID->EnableWindow(true);
	tx_formDate->EnableWindow(true);
	tx_remark->EnableWindow(true);

	int formID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("productOutputFormID").intVal;
	if(formID<10)
		m_productOutputFormID.Format("CPCK0000%d",formID);
	else if(formID<100&&formID>9)
		m_productOutputFormID.Format("CPCK000%d",formID);
	else if(formID<1000&&formID>99)
		m_productOutputFormID.Format("CPCK00%d",formID);

	CString str;
	str.Format("%d",formID+1);
	((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("productOutputFormID",_variant_t(str));
	((CStoreApp*)AfxGetApp())->m_pIDRecordset->Update();

	m_list.DeleteAllItems();

	m_storeHouse = _T("");
	m_department = _T("");
	m_seller = _T("");
	m_clientName = _T("");
	m_houseOutType = _T("");
	m_consignmentFormID = _T("");
	m_formDate = COleDateTime::GetCurrentTime();
	m_remark = _T("");
	is_search=0;
	flag=1;

	UpdateData(false);
	
}

void CProductOutputForm::OnModify() 
{
	flag=2;
	bt_add->EnableWindow(false);
	bt_delete->EnableWindow(false);
	bt_save->EnableWindow(true);
	bt_modify->EnableWindow(false);
	bt_addLine->EnableWindow(true);
	bt_deleteLine->EnableWindow(true);

	tx_storeHouse->EnableWindow(true);
	tx_department->EnableWindow(true);
	tx_seller->EnableWindow(true);
	tx_clientName->EnableWindow(true);
	tx_houseOutType->EnableWindow(true);
	tx_consignmentFormID->EnableWindow(true);
	tx_formDate->EnableWindow(true);
	tx_remark->EnableWindow(true);	
}

void CProductOutputForm::OnDelete() 
{
	CAffirm dlg;
	if(dlg.DoModal()!=IDOK)
	{
		return;
	}
	_variant_t RecordsAffected;
	CString strSQL;
	strSQL="delete from productOutputForm where productOutputFormID='";
	strSQL=strSQL+m_productOutputFormID+"'";
	(((CStoreApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
	
	
	m_list.DeleteAllItems();
	UpdateData(false);
	AfxMessageBox("该单已删除!");

	tx_storeHouse->EnableWindow(false);
	tx_department->EnableWindow(false);
	tx_seller->EnableWindow(false);
	tx_clientName->EnableWindow(false);
	tx_houseOutType->EnableWindow(false);
	tx_consignmentFormID->EnableWindow(false);
	tx_formDate->EnableWindow(false);
	tx_remark->EnableWindow(false);


	m_productOutputFormID = _T("");
	m_storeHouse = _T("");
	m_department = _T("");
	m_seller = _T("");
	m_clientName = _T("");
	m_houseOutType = _T("");
	m_consignmentFormID = _T("");
	m_formDate = COleDateTime::GetCurrentTime();
	m_remark = _T("");

	bt_modify->EnableWindow(false);
	bt_delete->EnableWindow(false);


	is_search=0;
	flag=1;

	UpdateData(false);
	
}

void CProductOutputForm::OnAddLine() 
{
	CSelectProduct dlg;
	if(dlg.DoModal()==IDOK)
	{
		float total=dlg.m_num*dlg.m_price;
		int i=m_list.GetItemCount();
		CString str;
		m_list.InsertItem(i,dlg.m_productID);
		m_list.SetItemText(i,1,dlg.m_productName);
		m_list.SetItemText(i,2,dlg.m_unit);
		m_list.SetItemText(i,3,dlg.m_model);
		str.Format("%d",dlg.m_num);
		m_list.SetItemText(i,4,str);
		str.Format("%f",dlg.m_price);
		m_list.SetItemText(i,5,str);
		str.Format("%f",total);
		m_list.SetItemText(i,6,str);
	}
	
}

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

void CProductOutputForm::OnSave() 
{
	UpdateData(true);	
	CString strSQL;
	_RecordsetPtr m_pRecordset;    //用于创建一个查询记录集
	_RecordsetPtr m_pProductOutputFormRecordset;
	strSQL="select * from productOutputForm";
	HRESULT hTRes;
	hTRes = m_pProductOutputFormRecordset.CreateInstance(_T("ADODB.Recordset"));				
	hTRes = m_pProductOutputFormRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
		((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
		adOpenDynamic,adLockPessimistic,adCmdText);

	if(flag==1)         //添加
	{
		m_pProductOutputFormRecordset->AddNew();
		m_pProductOutputFormRecordset->PutCollect("productOutputFormID",_variant_t(m_productOutputFormID.Left(25)));
		m_pProductOutputFormRecordset->PutCollect("formDate",_variant_t(m_formDate));
		m_pProductOutputFormRecordset->PutCollect("consignmentFormID",_variant_t(m_consignmentFormID));
		m_pProductOutputFormRecordset->PutCollect("storeHouse",_variant_t(m_storeHouse.Left(50)));
		m_pProductOutputFormRecordset->PutCollect("sellDepartment",_variant_t(m_department.Left(50)));
		m_pProductOutputFormRecordset->PutCollect("seller",_variant_t(m_seller.Left(50)));
		m_pProductOutputFormRecordset->PutCollect("clientName",_variant_t(m_clientName.Left(50)));
		m_pProductOutputFormRecordset->PutCollect("houseOutType",_variant_t(m_houseOutType.Left(50)));
		m_pProductOutputFormRecordset->PutCollect("remark",_variant_t(m_remark.Left(100)));
		m_pProductOutputFormRecordset->Update();
		strSQL="SELECT * FROM productOutputFormCommidity" ;	

		try
		{
			hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
			if (SUCCEEDED(hTRes))
			{				
				hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
					((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
					adOpenDynamic,adLockPessimistic,adCmdText);

				if(SUCCEEDED(hTRes))
				{
					TRACE(_T("连接成功!\n"));
					for(int i=0;i<m_list.GetItemCount();i++)
					{
						m_pRecordset->AddNew();
						m_pRecordset->PutCollect("productOutputFormID",_variant_t(m_productOutputFormID.Left(25)));
						m_pRecordset->PutCollect("productID",_variant_t(m_list.GetItemText(i,0).Left(25)));
						m_pRecordset->PutCollect("num",_variant_t(m_list.GetItemText(i,4)));
						m_pRecordset->PutCollect("price",_variant_t(m_list.GetItemText(i,5)));
						m_pRecordset->Update();
					}
					
					AfxMessageBox("保存成功!");
				}
			}
		}
		catch(_com_error e)///捕捉异常
		{
			CString errormessage;
			MessageBox("创建记录集失败!","错误");
		}
	}
	else if(flag==2)      //修改
	{
		_variant_t RecordsAffected;
		CString strSQL;
		strSQL="delete from productOutputFormCommidity where productOutputFormID='";
		strSQL=strSQL+m_productOutputFormID+"'";
		(((CStoreApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
		

		m_pProductOutputFormRecordset->Update();

		strSQL="SELECT * FROM productOutputFormCommidity" ;	

		try
		{
			HRESULT hTRes;
			hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
			if (SUCCEEDED(hTRes))
			{
				hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
					((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
					adOpenDynamic,adLockPessimistic,adCmdText);

				if(SUCCEEDED(hTRes))
				{
					TRACE(_T("连接成功!\n"));
					for(int i=0;i<m_list.GetItemCount();i++)
					{
						m_pRecordset->AddNew();
						m_pRecordset->PutCollect("productOutputFormID",_variant_t(m_productOutputFormID.Left(25)));
						m_pRecordset->PutCollect("productID",_variant_t(m_list.GetItemText(i,0).Left(25)));
						m_pRecordset->PutCollect("num",_variant_t(m_list.GetItemText(i,4)));
						m_pRecordset->PutCollect("price",_variant_t(m_list.GetItemText(i,5)));
						m_pRecordset->Update();
					}
					
					AfxMessageBox("保存成功!");
				}
			}
		}
		catch(_com_error e)///捕捉异常
		{
			CString errormessage;
			MessageBox("创建记录集失败!","错误");
		}
	}
	bt_add->EnableWindow(true);
	bt_modify->EnableWindow(true);
	bt_delete->EnableWindow(true);
	bt_save->EnableWindow(false);
	bt_addLine->EnableWindow(false);
	bt_deleteLine->EnableWindow(false);
	bt_cancelation->EnableWindow(false);

	tx_storeHouse->EnableWindow(false);
	tx_department->EnableWindow(false);
	tx_seller->EnableWindow(false);
	tx_clientName->EnableWindow(false);
	tx_houseOutType->EnableWindow(false);
	tx_consignmentFormID->EnableWindow(false);
	tx_formDate->EnableWindow(false);
	tx_remark->EnableWindow(false);
	
	UpdateData(false);
	
}

void CProductOutputForm::OnCancelation() 
{
	int formID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("productOutputFormID").intVal;
	formID-=1;
	CString str;
	str.Format("%d",formID);
	((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("productOutputFormID",(_variant_t)str);
	((CStoreApp*)AfxGetApp())->m_pIDRecordset->Update();

	bt_cancelation->EnableWindow(false);
	bt_add->EnableWindow(true);
	bt_delete->EnableWindow(false);
	bt_modify->EnableWindow(false);
	bt_deleteLine->EnableWindow(false);
	bt_addLine->EnableWindow(false);
	bt_save->EnableWindow(false);

	tx_storeHouse->EnableWindow(false);
	tx_department->EnableWindow(false);
	tx_seller->EnableWindow(false);
	tx_clientName->EnableWindow(false);
	tx_houseOutType->EnableWindow(false);
	tx_consignmentFormID->EnableWindow(false);
	tx_formDate->EnableWindow(false);
	tx_remark->EnableWindow(false);

	m_productOutputFormID = _T("");
	m_storeHouse = _T("");
	m_department = _T("");
	m_seller = _T("");
	m_clientName = _T("");
	m_houseOutType = _T("");
	m_consignmentFormID = _T("");
	m_formDate = COleDateTime::GetCurrentTime();
	m_remark = _T("");

	is_search=0;
	flag=1;

	UpdateData(false);	
}

⌨️ 快捷键说明

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