www.gusucode.com > VC++毕业设计-库存管理系统(Access)-源码程序 > VC++毕业设计-库存管理系统(Access)-源码程序/code/源程序/DAdjust.cpp

    //Download by http://www.NewXing.com
// DAdjust.cpp : implementation file
//

#include "stdafx.h"
#include "商品库存管理系统.h"
#include "DAdjust.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr cnn;
extern CMyApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDAdjust dialog


CDAdjust::CDAdjust(CWnd* pParent /*=NULL*/)
	: CDialog(CDAdjust::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDAdjust)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDAdjust::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDAdjust)
	DDX_Control(pDX, IDC_LIST, m_Grid);
	DDX_Control(pDX, IDC_COMFStore, m_ComFStore);
	DDX_Control(pDX, IDC_COMAStore, m_ComAStore);
	DDX_Control(pDX, IDC_BUTExit3, m_ButExit);
	DDX_Control(pDX, IDC_BUTSure, m_ButSure);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDAdjust, CDialog)
	//{{AFX_MSG_MAP(CDAdjust)
	ON_CBN_KILLFOCUS(IDC_COMAStore, OnKillfocusCOMAStore)
	ON_NOTIFY(HDN_ITEMCHANGING, IDC_LIST, OnItemchangingList)
	ON_BN_CLICKED(IDC_BUTSure, OnBUTSure)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDAdjust message handlers

void CDAdjust::OnOK() 
{
	// TODO: Add extra validation here
	
	//CDialog::OnOK();
}

BOOL CDAdjust::OnInitDialog() 
{
	CDialog::OnInitDialog();
	CString ColText[]={"商品名称","库存数量","调货数量"};
	int ColWidth[]={250,100,100};
	rst.CreateInstance(__uuidof(Recordset));
	rst=cnn->Execute(L"仓库信息表",NULL,adCmdTable);
	if(theApp.GetRecordCount(rst)>0)
	{
		this->m_ComAStore.SetRecordset(rst,"名称");
		this->m_ComFStore.SetRecordset(rst,"名称");
	}
	m_Grid.SetColumnCount(3);
	for(int i=0;i<3;i++)
	{
		m_Grid.InsertColumn(i,ColText[i]);
		m_Grid.SetColumnWidth(i,ColWidth[i]);
	}
	m_Grid.m_Edit.IsPopShow=false;
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDAdjust::OnKillfocusCOMAStore() 
{
	CString sSQL,AStore,FStore,sName,sNumber;
	
	m_ComAStore.GetWindowText(AStore);
	m_ComFStore	.GetWindowText(FStore);
	if(AStore==FStore)
	{
		MessageBox("同一仓库内无法调货!","系统提示",MB_OK|MB_ICONSTOP);
		m_ComAStore.SetFocus();
		return;
	}
	m_Grid.Clear();
	sSQL.Format("SELECT 商品名称,库存数量 FROM 库存查询 WHERE 仓库名称='%s'",FStore);
	rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
	for(int i=0;i<theApp.GetRecordCount(rst);i++)
	{
		m_Grid.InsertItem(i,"");
		rst->MoveFirst();
		rst->Move(i);
		sName=(char*)(_bstr_t)rst->GetCollect("商品名称");
		sNumber=(char*)(_bstr_t)rst->GetCollect("库存数量");
		m_Grid.SetItemText(i,0,sName);
		m_Grid.SetItemText(i,1,sNumber);
	}
	m_ComAStore.EnableWindow(false);
	m_ComFStore.EnableWindow(false);
	m_Grid.SetFocus();
	m_Grid.m_Col=2;
	m_Grid.m_Row=0;
	m_Grid.BeginEdit(0,2);
}

void CDAdjust::OnItemchangingList(NMHDR* pNMHDR, LRESULT* pResult) 
{
	HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
	*pResult = 0;
}

BOOL CDAdjust::PreTranslateMessage(MSG* pMsg) 
{			
	if(this->FromHandle(pMsg->hwnd)->GetParent()==&m_Grid && pMsg->message==WM_KEYDOWN && pMsg->wParam==13)
	{
		CString StoreNUM,AdjustNUM;
		StoreNUM=m_Grid.GetItemText(m_Grid.m_Row-1,1);
		AdjustNUM=m_Grid.GetItemText(m_Grid.m_Row-1,2);
		if(atoi(AdjustNUM)>atoi(StoreNUM))
			m_Grid.SetItemText(m_Grid.m_Row-1,2,StoreNUM);
	}
	return CDialog::PreTranslateMessage(pMsg);
}

void CDAdjust::OnBUTSure() 
{
	int a=MessageBox("确定保存调货信息吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION);
	if(a==1)
	{
		CString sWare,sWareNumber,sAStoreNum,sAdjust,sSQL,sStore,StoreNum,sPtrce,sSell;
		int nAdjust,nStore,nStoreNum;
		m_ComFStore.GetWindowText(sAdjust);
		m_ComAStore.GetWindowText(sStore);
		nAdjust=theApp.NumberTOName("仓库信息表","名称",sAdjust);
		nStore=theApp.NumberTOName("仓库信息表","名称",sStore);
		for(int i=0;i<m_Grid.GetItemCount();i++)
		{
			sWare=m_Grid.GetItemText(i,0);
			sWareNumber=theApp.NumberTOName("商品信息表","编号","名称",sWare);
			sAdjust=m_Grid.GetItemText(i,2);
			if(sAdjust.IsEmpty())
				continue;
			//取出源仓库的信息
			sSQL.Format("SELECT * FROM 库存信息表 WHERE 仓库编号=%d AND 商品编号='%s'",nAdjust,sWareNumber);
			rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
			if(theApp.GetRecordCount(rst)>0)
			{
				rst->MoveFirst();
				sPtrce=(char*)(_bstr_t)rst->GetCollect("单价");
				sSell=(char*)(_bstr_t)rst->GetCollect("销售价格");
				sAStoreNum=(char*)(_bstr_t)rst->GetCollect("库存数量");
			}
			sSQL.Format("SELECT * FROM 库存信息表 WHERE 仓库编号=%d AND 商品编号='%s'",nStore,sWareNumber);
			rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
			//增加调货仓库的商品库存数量
			if(theApp.GetRecordCount(rst)>0)
			{
				rst->MoveFirst();
				StoreNum=(char*)(_bstr_t)rst->GetCollect("库存数量");
				nStoreNum=atoi(StoreNum);
				sSQL.Format("UpDate 库存信息表 Set 库存数量=%d WHERE 仓库编号=%d AND 商品编号='%s' ",nStoreNum+atoi(sAdjust),nAdjust,sWareNumber);
			}
			else
			{	
					sSQL.Format("Insert into 库存信息表 values('%s',%d,%s,500,10,%s,%s)",sWareNumber,nStore,sAdjust,sPtrce,sSell);
			}
			cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
			//减少源仓库的商品库存数量
			nStoreNum=atoi(sAStoreNum);
			sSQL.Format("UpDate 库存信息表 Set 库存数量=%d WHERE 仓库编号=%d AND 商品编号='%s' ",nStoreNum-atoi(sAdjust),nStore,sWareNumber);
			cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
		}
		int nOP=theApp.NumberTOName("用户信息表","用户名",OP);
		sSQL.Format("Insert Into 商品调拨表 values('%s',%d,%d,%s,%d)",sWareNumber,nStore,nAdjust,sAdjust,nOP);
		cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
		MessageBox("调货成功!","系统提示",MB_OK|MB_ICONINFORMATION);
		m_Grid.Refresh();
		this->m_ComAStore.EnableWindow(true);
		this->m_ComFStore.EnableWindow(true);
		this->m_ComAStore.SetWindowText("");
		this->m_ComFStore.SetWindowText("");
		this->m_ComFStore.SetFocus();
	}
}

void CDAdjust::SetOP(CString sOP)
{
	OP=sOP;
}