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

📄 buyinputform.cpp

📁 企业库存管理系统, 企业库存管理系统
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		tx_houseInType->EnableWindow(true);
		tx_remark->EnableWindow(true);
		//生成采购入库单号,该编号以后不能修改
		int formID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("buyInputFormID").intVal;
		if(formID<10)
			m_buyInputFormID.Format("CLRK0000%d",formID);
		else if(formID<100&&formID>9)
			m_buyInputFormID.Format("CLRK000%d",formID);
		else if(formID<1000&&formID>99)
			m_buyInputFormID.Format("CLRK00%d",formID);
		//更新下一个可用的采购入库单号码
		CString str;
		str.Format("%d",formID+1);
		((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("buyInputFormID",_variant_t(str));
		((CStoreApp*)AfxGetApp())->m_pIDRecordset->Update();
	}

	UpdateData(false); //更新对话框数据
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

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

void CBuyInputForm::OnNew() 
{
	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_formDate->EnableWindow(true);
	tx_materialReceiveID->EnableWindow(true);
	tx_storeHouse->EnableWindow(true);
	tx_provider->EnableWindow(true);
	tx_buyDepartment->EnableWindow(true);
	tx_buyer->EnableWindow(true);
	tx_transportCompany->EnableWindow(true);
	tx_transportType->EnableWindow(true);
	tx_houseInType->EnableWindow(true);
	tx_remark->EnableWindow(true);
	//获取新的采购入库单号
	int formID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("buyInputFormID").intVal;
	if(formID<10)//为采购入库单号设定格式
		m_buyInputFormID.Format("CLRK0000%d",formID);
	else if(formID<100&&formID>9)
		m_buyInputFormID.Format("CLRK000%d",formID);
	else if(formID<1000&&formID>99)
		m_buyInputFormID.Format("CLRK00%d",formID);
	//更新下一个可用的采购入库单号
	CString str;
	str.Format("%d",formID+1);//将当前采购入库单号加1作为下一个可用的采购入库单号
	((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("buyInputFormID",_variant_t(str));
	((CStoreApp*)AfxGetApp())->m_pIDRecordset->Update();//更新数据库

	m_list.DeleteAllItems();//删除列表框控件中的条目
	//为控件变量赋初始值
	m_formDate = COleDateTime::GetCurrentTime();
	m_materialReceiveID = _T("");
	m_storeHouse = _T("");
	m_provider = _T("");
	m_buyDepartment = _T("");
	m_buyer = _T("");
	m_transportCompany = _T("");
	m_transportType = _T("");
	m_houseInType = _T("");
	m_remark = _T("");
	flag=1;

	UpdateData(false);//更新对话框数据
}

void CBuyInputForm::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_formDate->EnableWindow(true);
	tx_materialReceiveID->EnableWindow(true);
	tx_storeHouse->EnableWindow(true);
	tx_provider->EnableWindow(true);
	tx_buyDepartment->EnableWindow(true);
	tx_buyer->EnableWindow(true);
	tx_transportCompany->EnableWindow(true);
	tx_transportType->EnableWindow(true);
	tx_houseInType->EnableWindow(true);
	tx_remark->EnableWindow(true);	
}

void CBuyInputForm::OnDelete() 
{
	CAffirm dlg; //构造确认删除对话框
	if(dlg.DoModal()!=IDOK)//显示确认删除对话框
	{
		return;
	}
	_variant_t RecordsAffected;
	CString strSQL;
	strSQL="delete from buyInputForm where buyInputFormID='";
	strSQL=strSQL+m_buyInputFormID+"'"; //构造删除指定采购入库单号的单据的sql语句
	//执行删除的sql语句
	(((CStoreApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
	m_list.DeleteAllItems();//清除列表框控件中的条目
	AfxMessageBox("该单已删除!"); //提示信息
	//设定所有的编辑控件均不可用
	tx_formDate->EnableWindow(false);
	tx_materialReceiveID->EnableWindow(false);
	tx_storeHouse->EnableWindow(false);
	tx_provider->EnableWindow(false);
	tx_buyDepartment->EnableWindow(false);
	tx_buyer->EnableWindow(false);
	tx_transportCompany->EnableWindow(false);
	tx_transportType->EnableWindow(false);
	tx_houseInType->EnableWindow(false);
	tx_remark->EnableWindow(false);
	//为编辑控件变量赋默认值
	m_formDate = COleDateTime::GetCurrentTime();
	m_buyInputFormID = _T("");
	m_materialReceiveID = _T("");
	m_storeHouse = _T("");
	m_provider = _T("");
	m_buyDepartment = _T("");
	m_buyer = _T("");
	m_transportCompany = _T("");
	m_transportType = _T("");
	m_houseInType = _T("");
	m_remark = _T("");

	UpdateData(false);	//将数据更新到对话框
}

void CBuyInputForm::OnAddLine() 
{
	CSelectMaterial 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_materialID);//物料编号
		m_list.SetItemText(i,1,dlg.m_materialName);//物料名称
		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 CBuyInputForm::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 CBuyInputForm::OnSave() 
{
	UpdateData(true);	
	CString strSQL;
	_RecordsetPtr m_pRecordset;    //用于创建一个查询记录集
	_RecordsetPtr m_pBuyInputFormRecordset;
	strSQL="select * from buyInputForm"; //构造查询采购入库单基本信息的sql语句
	HRESULT hTRes;
	hTRes = m_pBuyInputFormRecordset.CreateInstance(_T("ADODB.Recordset"));				
	hTRes = m_pBuyInputFormRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
		((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
		adOpenDynamic,adLockPessimistic,adCmdText);//打开查询结果记录集
	if(flag==1)         //添加
	{
		m_pBuyInputFormRecordset->AddNew();//添加新的记录
		m_pBuyInputFormRecordset->PutCollect("buyInputFormID",_variant_t(m_buyInputFormID.Left(25)));//采购入库单号
		m_pBuyInputFormRecordset->PutCollect("formDate",_variant_t(m_formDate));//制单日期
		m_pBuyInputFormRecordset->PutCollect("materialAcceptFormID",_variant_t(m_materialReceiveID.Left(50)));//收料单号
		m_pBuyInputFormRecordset->PutCollect("storeHouse",_variant_t(m_storeHouse.Left(50)));//仓库名称
		m_pBuyInputFormRecordset->PutCollect("provider",_variant_t(m_provider.Left(50)));//供应商
		m_pBuyInputFormRecordset->PutCollect("stockDepartment",_variant_t(m_buyDepartment.Left(50)));//采购部门
		m_pBuyInputFormRecordset->PutCollect("buyer",_variant_t(m_buyer.Left(50)));//采购员
		m_pBuyInputFormRecordset->PutCollect("transportCompany",_variant_t(m_transportCompany.Left(50)));//承运单位
		m_pBuyInputFormRecordset->PutCollect("transportType",_variant_t(m_transportType.Left(50)));//运输方式
		m_pBuyInputFormRecordset->PutCollect("houseInType",_variant_t(m_houseInType.Left(50)));//入库类别
		m_pBuyInputFormRecordset->PutCollect("remark",_variant_t(m_remark.Left(100)));//备注
		m_pBuyInputFormRecordset->Update();
		
		strSQL="SELECT * FROM buyInputFormCommidity" ;//构造查询采购入库单物料信息的sql语句	
		try
		{		
			hTRes = m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
			hTRes = m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(130),
					((CStoreApp*)AfxGetApp())->m_pConn.GetInterfacePtr(),
					adOpenDynamic,adLockPessimistic,adCmdText);//打开查询结果记录集
			if(SUCCEEDED(hTRes))
			{
				//将列表框中的条目依次加入数据库中
				for(int i=0;i<m_list.GetItemCount();i++)
				{
					m_pRecordset->AddNew();//添加新的记录
					m_pRecordset->PutCollect("buyInputFormID",_variant_t(m_buyInputFormID.Left(25)));//采购入库单号
					m_pRecordset->PutCollect("materialID",_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 buyInputFormCommidity where buyInputFormID='";
		strSQL=strSQL+m_buyInputFormID+"'";  //构造删除指定采购入库单号的物料信息的sql语句
		//执行删除的sql语句
		(((CStoreApp*)AfxGetApp())->m_pConn)->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);
		m_pBuyInputFormRecordset->Update();
		
		strSQL="SELECT * FROM buyInputFormCommidity" ;	//构造查询采购入库单物料信息的sql语句

		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))
				{
					//将列表框中的条目依次添加进数据库中
					for(int i=0;i<m_list.GetItemCount();i++)
					{
						m_pRecordset->AddNew();//添加新的记录
						m_pRecordset->PutCollect("buyInputFormID",_variant_t(m_buyInputFormID.Left(25)));//采购入库单号
						m_pRecordset->PutCollect("materialID",_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_formDate->EnableWindow(false);
	tx_materialReceiveID->EnableWindow(false);
	tx_storeHouse->EnableWindow(false);
	tx_provider->EnableWindow(false);
	tx_buyDepartment->EnableWindow(false);
	tx_buyer->EnableWindow(false);
	tx_transportCompany->EnableWindow(false);
	tx_transportType->EnableWindow(false);
	tx_houseInType->EnableWindow(false);
	tx_remark->EnableWindow(false);
	UpdateData(false);//更新对话框数据	
}

void CBuyInputForm::OnCancelation() 
{
	int formID=((CStoreApp*)AfxGetApp())->m_pIDRecordset->GetCollect("buyInputFormID").intVal;
	formID-=1;
	CString str;
	str.Format("%d",formID);
	((CStoreApp*)AfxGetApp())->m_pIDRecordset->PutCollect("buyInputFormID",(_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);
	
}

⌨️ 快捷键说明

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