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

📄 marketmanagerview.cpp

📁 一个基于VC6.0MFC的超市管理系统,SQL SERVER 2000数据库.实现基本功能,
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					var=m_pRecordset->GetCollect("goods_no");
					str=(LPCSTR)_bstr_t(var);
					str.TrimRight(" ");
					if(str==no)
				         isexist=true;
					else
						m_pRecordset->MoveNext();
				}
				if(isexist==true)
				{//删除纪录
					str.Format("编号为 ");
					str+=no;
					str+=" 的仓储纪录将被删除\n确认点击OK!\n撤销点击Cancel!";
					if(MessageBox(str,"系统确认",MB_OKCANCEL|MB_ICONQUESTION)==IDOK)
					{//确认删除操作
                         m_pRecordset->Delete(adAffectCurrent);
						 m_pRecordset->Update();
						 m_pRecordset->MoveFirst();
						 if(m_pRecordset->BOF)
							 MessageBox("仓储纪录被清空!","系统提示",MB_OK|MB_ICONINFORMATION);
						 MessageBox("仓储纪录成功删除!","系统提示",MB_OK|MB_ICONINFORMATION);
						 rn=true;;
					}
				}
				else
				{
					MessageBox("查找纪录不存在\n请确认输入","系统提示",MB_OK|MB_ICONINFORMATION);

				}
			}
			else
				MessageBox("仓储纪录已被清空","系统提示",MB_OK|MB_ICONWARNING);
			m_pRecordset->Close();//关闭表
		}
        catch(_com_error *e)
		{
		  AfxMessageBox(e->ErrorMessage());
		}
	}
	return rn;
}

bool CMarketManagerView::GoodsModify()
{
    _variant_t var;
	CString str,gno,gname;
	int dlgrn,gquanitity,gprice;
	bool isexist=false;
	bool rn=false;
	CDeleteGoodsDlg dlg;
	CAddGoodsDlg AddDlg;

    if(m_Date.IsEmpty())
	{
		MessageBox("尚未登陆系统!","系统提示",MB_OK|MB_ICONSTOP);
		return false;
	}

	if(m_bManager==false)
	{
		MessageBox("权限不够!","系统提示",MB_OK|MB_ICONSTOP);
		return false;
	}

	dlg.m_title.Format("修改仓储纪录");

	if(dlg.DoModal()==IDOK)
	{
		
		UpdateData();
		gno=dlg.m_no;
		str.Format("select * from Goods");
		try
		{   //打开货物纪录表
            m_pRecordset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
			if(!m_pRecordset->BOF)
			{
				//循环遍历数据库,查找指定的纪录
				m_pRecordset->MoveFirst();
				while(!isexist&&!m_pRecordset->adoEOF)
				{
					var=m_pRecordset->GetCollect("goods_no");
					str=(LPCSTR)_bstr_t(var);
					str.TrimRight(" ");
					if(str==gno)
					    isexist=true;
					else
					   m_pRecordset->MoveNext();
				}
				if(isexist==true)
				{//显示将被修改纪录
					var=m_pRecordset->GetCollect("goods_no");
					str=(LPCSTR)_bstr_t(var);
					str.TrimRight(" ");
					AddDlg.m_no=str;
					var=m_pRecordset->GetCollect("goods_name");
					str=(LPCSTR)_bstr_t(var);
					str.TrimRight(" ");
					AddDlg.m_name=str;
					var=m_pRecordset->GetCollect("goods_quantity");
                    AddDlg.m_quantity=var.intVal;
					var=m_pRecordset->GetCollect("goods_price");
					AddDlg.m_price=var.intVal;
                    UpdateData(FALSE);
                    //显示修改纪录对话框
					AddDlg.m_title.Format("修改仓储纪录");
                    dlgrn=AddDlg.DoModal();
                    if(dlgrn==IDOK)
					{
                        UpdateData();
					   //gno=AddDlg.m_no;
						gname=AddDlg.m_name;
						gquanitity=AddDlg.m_quantity;
						gprice=AddDlg.m_price;

						//输入信息有效性检查
						if(gno.IsEmpty()||gname.IsEmpty())
						    MessageBox("货物信息错误\n请确认输入","系统提示",MB_OK|MB_ICONINFORMATION);
						else
						{//执行修改操作
						    m_pRecordset->PutCollect("goods_no",_variant_t(gno));
						    m_pRecordset->PutCollect("goods_name",_variant_t(gname));
						    var.iVal=gquanitity;
						    m_pRecordset->PutCollect("goods_quantity",var.iVal);
						    var.iVal=gprice;
						    m_pRecordset->PutCollect("goods_price",var.iVal);
						    m_pRecordset->Update();	
						    MessageBox("纪录修改成功","系统提示",MB_OK|MB_ICONINFORMATION);
							rn=true;
						}
					}

				}
				else
				{
					MessageBox("查找纪录不存在\n请确认输入","系统提示",MB_OK|MB_ICONINFORMATION);
				}
			}
			else
			{
				MessageBox("仓储纪录已被清空","系统提示",MB_OK|MB_ICONWARNING);
			}

			m_pRecordset->Close();//关闭表
		}
		catch(_com_error *e)
		{
			AfxMessageBox(e->ErrorMessage());
		}
	}
    return rn;
}


void CMarketManagerView::PersonSystem()
{
     CString str;
	 _variant_t var;
	 CPersonSystemDlg dlg;

    if(m_Date.IsEmpty())
	{
		MessageBox("尚未登陆系统!","系统提示",MB_OK|MB_ICONSTOP);
		return;
	}

	if(m_bManager==false)
	{
		MessageBox("权限不够!","系统提示",MB_OK|MB_ICONSTOP);
		return;
	}

	 str.Format("select * from Person");
	 try
	 {
		//打开人事纪录表
        m_pRecordset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
		if(!m_pRecordset->BOF)
		{
			//显示第一个记录内容
			m_pRecordset->MoveFirst();
            var=m_pRecordset->GetCollect("person_no");
			str=(LPCSTR)_bstr_t(var);
			str.TrimRight(" ");
			dlg.m_no=str;

			var=m_pRecordset->GetCollect("person_name");
			str=(LPCSTR)_bstr_t(var);
			str.TrimRight(" ");
			dlg.m_name=str;

			var=m_pRecordset->GetCollect("person_code");
			str=(LPCSTR)_bstr_t(var);
			str.TrimRight(" ");
			dlg.m_code=str;

			var=m_pRecordset->GetCollect("person_limit");
			dlg.m_limit=var.intVal;

			UpdateData(FALSE);
            m_pRecordset->Close();
			//转入人事管理系统对话框处理信息
			if(dlg.DoModal()==IDOK)
			{
				MessageBox("人事管理系统正常退出","系统提示",MB_OK|MB_ICONINFORMATION);
			}
		}
		else
		{
			m_pRecordset->Close();
			MessageBox("人事纪录已被清空","系统提示",MB_OK|MB_ICONWARNING);
		}
	 }
	 catch(_com_error *e)
	 {
		 AfxMessageBox(e->ErrorMessage());
	 }
}

void CMarketManagerView::StatisticSystem()
{
     CString str;
	 _variant_t var;
	 CStatDlg dlg;

    if(m_Date.IsEmpty())
	{
		MessageBox("尚未登陆系统!","系统提示",MB_OK|MB_ICONSTOP);
		return;
	}
	
	if(m_bManager==false)
	{
		MessageBox("权限不够!","系统提示",MB_OK|MB_ICONSTOP);
		return;
	}

	str.Format("select * from Record");

	 try
	 {  
		 //打开销售记录表
        m_pRecordset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
		if(!m_pRecordset->BOF)
		{
			m_pRecordset->Close();
			//转入销售统计系统处理信息
			if(dlg.DoModal()==IDOK)
			{
				MessageBox("统计系统正常退出","系统提示",MB_OK|MB_ICONINFORMATION);
			}
		}
		else
		{
			m_pRecordset->Close();
			MessageBox("历史纪录已被清除","系统提示",MB_OK|MB_ICONWARNING);
		}
	 }
	 catch(_com_error *e)
	 {
		 AfxMessageBox(e->ErrorMessage());
	 }

}

void CMarketManagerView::SaleCount()
{
	CSaleDlg dlg;
    int gquantity,SaleSum,inttmp;
	_variant_t var,vartmp,RecordsAffected;
	bool GoodsFind=false;
	bool SaleOK=false;
	bool RecordFind=false;
	CString str,strtmp,gno;

	_RecordsetPtr pRdset;

    if(m_Date.IsEmpty())
	{
		MessageBox("尚未登陆系统!","系统提示",MB_OK|MB_ICONSTOP);
		return;
	}

	//产生_RecordsetPtr实例
	pRdset.CreateInstance(__uuidof(Recordset));

	//弹出销售对话框,获得销售货物编号
	if(dlg.DoModal()==IDOK)
	{
		UpdateData();
		gno=dlg.m_no;
		gquantity=dlg.m_quantity;

		try
		{   
			//打开货物记录表
			str.Format("select * from Goods");
			m_pRecordset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
			//打开销售记录表
			str.Format("select * from Record");
			pRdset->Open(str.AllocSysString(),theApp.m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
            //事务开始
			theApp.m_pConnection->BeginTrans();

			if(!m_pRecordset->BOF)
			{//循环遍历数据库,查找输入的货物编号
				m_pRecordset->MoveFirst();
				while(!m_pRecordset->adoEOF&&!GoodsFind)
				{
                   var=m_pRecordset->GetCollect("goods_no");
				   str=(LPCSTR)_bstr_t(var);
				   str.TrimRight(" ");
				   if(str==gno)
					   GoodsFind=true;
				   else
					   m_pRecordset->MoveNext();
				}
				if(GoodsFind==true)
				{//找到指定货物
					var=m_pRecordset->GetCollect("goods_quantity");
					if(gquantity<=(var.intVal))
					{//库存量大于当前需求量,可以完成销售
						vartmp=m_pRecordset->GetCollect("goods_price");
						inttmp=vartmp.intVal;
						SaleSum=gquantity*inttmp;//计算货物总价格
                        
						vartmp.iVal=(var.intVal)-gquantity;//修改库存量
						m_pRecordset->PutCollect("goods_quantity",vartmp.iVal);
						m_pRecordset->Update();

						SaleOK=true;

						if(pRdset->BOF)
						{//销售记录为空,则直接增加第一个记录
                            pRdset->AddNew();

							pRdset->PutCollect("Record_Date",_variant_t(m_Date));
							pRdset->PutCollect("Record_No",_variant_t(gno));

							var.iVal=gquantity;
							pRdset->PutCollect("Record_Quantity",var.iVal);

							var.iVal=SaleSum;
							pRdset->PutCollect("Record_SaleSum",var.iVal);

							pRdset->Update();
						}
						else
						{
							//销售记录非空,循环遍历Database查找主键相同纪录
							pRdset->MoveFirst();
							while(!pRdset->adoEOF&&!RecordFind)
							{
								var=pRdset->GetCollect("Record_Date");
								str=(LPCSTR)_bstr_t(var);
								str.TrimRight(" ");

								var=pRdset->GetCollect("Record_No");
								strtmp=(LPCSTR)_bstr_t(var);
								strtmp.TrimRight(" ");

								if(str==m_Date&&strtmp==gno)
									RecordFind=true;
								else
									pRdset->MoveNext();
							}
							if(RecordFind==true)
							{//有主键相同纪录,则修改之
								var=pRdset->GetCollect("Record_SaleSum");
								inttmp=(var.intVal)+SaleSum; //增加销售总金额

								var.iVal=inttmp;
								pRdset->PutCollect("Record_SaleSum",var.iVal);
								pRdset->Update();

								var=pRdset->GetCollect("Record_Quantity");
								inttmp=(var.intVal)+gquantity;//增加销售总数量
								
								var.iVal=inttmp;
								pRdset->PutCollect("Record_Quantity",var.iVal);
								pRdset->Update();
							}
							else
							{//没有主键相同纪录,则新增纪录
                                pRdset->AddNew();

								pRdset->PutCollect("Record_Date",_variant_t(m_Date));
								pRdset->PutCollect("Record_No",_variant_t(gno));

								var.iVal=gquantity;
								pRdset->PutCollect("Record_Quantity",var.iVal);

								var.iVal=SaleSum;
								pRdset->PutCollect("Record_SaleSum",var.iVal);

								pRdset->Update();

							}
						}
					}
					else
					{
						MessageBox("库存不足\n请确认数量","系统提示",MB_OK|MB_ICONSTOP);
					}
				}
				else
				{
					MessageBox("货物不存在\n请确认编号","系统提示",MB_OK|MB_ICONSTOP);
				}
			}
			else
			{
				MessageBox("仓储纪录已被清空","系统提示",MB_OK|MB_ICONSTOP);
			}
		//提交事务
		 theApp.m_pConnection->CommitTrans();
		 if(SaleOK==true)
		 {//打印本次交易金额
		    str.Format("货物总金额 %d",SaleSum);
		    MessageBox(str,"系统提示",MB_OK|MB_ICONINFORMATION);
		 }
         m_pRecordset->Close();//关闭数据库
		 pRdset->Close();
		}

		catch(_com_error * e)
		{//出现错误,事务回滚
           theApp.m_pConnection->RollbackTrans();
		   AfxMessageBox(e->ErrorMessage());
		}
	}
}

void CMarketManagerView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) 
{	
	*pResult = 0;
    GoodsModify();
}

⌨️ 快捷键说明

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