?? dadjust.cpp
字號:
// DAdjust.cpp : implementation file
//
#include "stdafx.h"
#include "商品庫存管理系統(tǒng).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[]={"商品名稱","庫存數(shù)量","調(diào)貨數(shù)量"};
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("同一倉庫內(nèi)無法調(diào)貨!","系統(tǒng)提示",MB_OK|MB_ICONSTOP);
m_ComAStore.SetFocus();
return;
}
m_Grid.Clear();
sSQL.Format("SELECT 商品名稱,庫存數(shù)量 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("庫存數(shù)量");
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("確定保存調(diào)貨信息嗎?","系統(tǒng)提示",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("庫存數(shù)量");
}
sSQL.Format("SELECT * FROM 庫存信息表 WHERE 倉庫編號=%d AND 商品編號='%s'",nStore,sWareNumber);
rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
//增加調(diào)貨倉庫的商品庫存數(shù)量
if(theApp.GetRecordCount(rst)>0)
{
rst->MoveFirst();
StoreNum=(char*)(_bstr_t)rst->GetCollect("庫存數(shù)量");
nStoreNum=atoi(StoreNum);
sSQL.Format("UpDate 庫存信息表 Set 庫存數(shù)量=%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);
//減少源倉庫的商品庫存數(shù)量
nStoreNum=atoi(sAStoreNum);
sSQL.Format("UpDate 庫存信息表 Set 庫存數(shù)量=%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 商品調(diào)撥表 values('%s',%d,%d,%s,%d)",sWareNumber,nStore,nAdjust,sAdjust,nOP);
cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
MessageBox("調(diào)貨成功!","系統(tǒng)提示",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;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -