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

📄 productmoveform.cpp

📁 企业库存管理系统, 企业库存管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	int formID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("productMoveFormID").intVal;
	if(formID<10)
		m_productMoveFormID.Format("CPDB0000%d",formID);
	else if(formID<100&&formID>9)
		m_productMoveFormID.Format("CPDB000%d",formID);
	else if(formID<1000&&formID>99)
		m_productMoveFormID.Format("CPDB00%d",formID);

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

	m_list.DeleteAllItems();

	m_storeHouseIn = _T("");
	m_storeHouseOut = _T("");
	m_dealer = _T("");
	m_houseOutType = _T("");
	m_formDate = COleDateTime::GetCurrentTime();
	m_remark = _T("");

	is_search=0;
	flag=1;

	UpdateData(false);
	
}

void CProductMoveForm::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_productMoveFormID->EnableWindow(true);
	tx_storeHouseIn->EnableWindow(true);
	tx_storeHouseOut->EnableWindow(true);
	tx_dealer->EnableWindow(true);
	tx_houseOutType->EnableWindow(true);
	tx_formDate->EnableWindow(true);
	tx_remark->EnableWindow(true);	
	
}

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

	tx_productMoveFormID->EnableWindow(false);
	tx_storeHouseIn->EnableWindow(false);
	tx_storeHouseOut->EnableWindow(false);
	tx_dealer->EnableWindow(false);
	tx_houseOutType->EnableWindow(false);
	tx_formDate->EnableWindow(false);
	tx_remark->EnableWindow(false);

	m_productMoveFormID = _T("");
	m_storeHouseIn = _T("");
	m_storeHouseOut = _T("");
	m_dealer = _T("");
	m_houseOutType = _T("");
	m_formDate = COleDateTime::GetCurrentTime();
	m_remark = _T("");

	is_search=0;
	flag=1;

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

	UpdateData(false);
	
	
}

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

	if(flag==1)         //添加
	{
		m_pProductMoveFormRecordset->AddNew();
		m_pProductMoveFormRecordset->PutCollect("productMoveFormID",_variant_t(m_productMoveFormID.Left(25)));
		m_pProductMoveFormRecordset->PutCollect("formDate",_variant_t(m_formDate));
		m_pProductMoveFormRecordset->PutCollect("storeHouseIn",_variant_t(m_storeHouseIn.Left(50)));
		m_pProductMoveFormRecordset->PutCollect("storeHouseOut",_variant_t(m_storeHouseOut.Left(50)));
		m_pProductMoveFormRecordset->PutCollect("dealer",_variant_t(m_dealer.Left(50)));
		m_pProductMoveFormRecordset->PutCollect("houseOutType",_variant_t(m_houseOutType.Left(50)));
		m_pProductMoveFormRecordset->PutCollect("remark",_variant_t(m_remark.Left(100)));
		m_pProductMoveFormRecordset->Update();
		strSQL="SELECT * FROM productMoveFormCommidity" ;	

		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("productMoveFormID",_variant_t(m_productMoveFormID.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 productMoveFormCommidity where productMoveFormID='";
		strSQL=strSQL+m_productMoveFormID+"'";
		(((CStoreApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
		

		m_pProductMoveFormRecordset->Update();

		strSQL="SELECT * FROM productMoveFormCommidity" ;	

		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("productMoveFormID",_variant_t(m_productMoveFormID.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_productMoveFormID->EnableWindow(false);
	tx_storeHouseIn->EnableWindow(false);
	tx_storeHouseOut->EnableWindow(false);
	tx_dealer->EnableWindow(false);
	tx_houseOutType->EnableWindow(false);
	tx_formDate->EnableWindow(false);
	tx_remark->EnableWindow(false);
	
	UpdateData(false);
	
}

void CProductMoveForm::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_productMoveFormID->EnableWindow(false);
	tx_storeHouseIn->EnableWindow(false);
	tx_storeHouseOut->EnableWindow(false);
	tx_dealer->EnableWindow(false);
	tx_houseOutType->EnableWindow(false);
	tx_formDate->EnableWindow(false);
	tx_remark->EnableWindow(false);

	m_productMoveFormID = _T("");
	m_storeHouseIn = _T("");
	m_storeHouseOut = _T("");
	m_dealer = _T("");
	m_houseOutType = _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 + -