// DOutPut.cpp : implementation file
//
#include "stdafx.h"
#include "商品库存管理系统.h"
#include "DOutPut.h"
#include "ExtendEdit.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr cnn;
extern CMyApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDOutPut dialog
CDOutPut::CDOutPut(CWnd* pParent /*=NULL*/)
: CDialog(CDOutPut::IDD, pParent)
{
m_hBrush=::CreateSolidBrush(RGB(96,96,96));
//{{AFX_DATA_INIT(CDOutPut)
//}}AFX_DATA_INIT
}
void CDOutPut::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDOutPut)
DDX_Control(pDX, IDC_STAID, m_StaID);
DDX_Control(pDX, IDC_STADate, m_StaDate);
DDX_Control(pDX, IDC_LIST, m_Grid);
DDX_Control(pDX, IDC_EDTSum, m_EdtSum);
DDX_Control(pDX, IDC_EDTMoney, m_EdtMoney);
DDX_Control(pDX, IDC_EDTClient, m_EdtClient);
DDX_Control(pDX, IDC_BUTUndo, m_ButUndo);
DDX_Control(pDX, IDC_BUTSave, m_ButSave);
DDX_Control(pDX, IDC_BUTExit, m_ButExit);
DDX_Control(pDX, IDC_BUTEnrol, m_ButEnrol);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDOutPut, CDialog)
//{{AFX_MSG_MAP(CDOutPut)
ON_WM_CTLCOLOR()
ON_NOTIFY(LVN_ITEMCHANGING, IDC_LIST, OnItemchangingList)
ON_BN_CLICKED(IDC_BUTEnrol, OnBUTEnrol)
ON_BN_CLICKED(IDC_BUTSave, OnBUTSave)
ON_BN_CLICKED(IDC_BUTUndo, OnBUTUndo)
ON_BN_CLICKED(IDC_BUTExit, OnBUTExit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDOutPut message handlers
void CDOutPut::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
BOOL CDOutPut::OnInitDialog()
{
CDialog::OnInitDialog();
CString FieldName[]={"商品名称","规格","产地","计量单位","出厂日期","保质期","出货仓库","出货单价","出货数量"};
int ColWidth[]={150,60,100,60,80,80,100,100,100};
CDialog::OnInitDialog();
m_EdtClient.DataBase="客户信息查询";
m_EdtClient.Field="名称";
m_EdtClient.assn=true;
m_EdtClient.GridParent=this;
for(int i=0;i<9;i++)
{
m_Grid.InsertColumn(i,FieldName[i]);
m_Grid.SetColumnWidth(i,ColWidth[i]);
}
m_Grid.SetColumnCount(9);
CString sSQL;
m_Grid.m_Edit.Changed=false;
m_Grid.m_Edit.IsPopShow=true;
sSQL.Format("SELECT 商品名称,规格,产地,计量单位,出厂日期,保质期 FROM 库存查询 ");
rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
m_Grid.SetField("商品名称");
m_Grid.m_Edit.SetPopRecordset(rst);
this->IsPopShow=false;
m_Grid.AutoInsert=true;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDOutPut::SetOP(CString cOP)
{
OP=cOP;
}
BOOL CDOutPut::DestroyWindow()
{
::DeleteObject(m_hBrush);
return CDialog::DestroyWindow();
}
void CDOutPut::ItemChange()
{
CString sSQL,sWare,sStore,sInput;
if(m_Grid.GetCol()==6)
{
try{
sInput=(char*)(_bstr_t)m_Grid.m_Edit.rst->GetCollect("销售价格");
m_Grid.SetItemText(m_Grid.GetRow(),7,sInput);
}
catch(...)
{
goto ResameNext;
}
m_Grid.m_Edit.IsPopShow=false;
}
/* if(m_Grid.GetCol()==8)
{
m_Grid.m_Edit.IsPopShow=false;
sSQL.Format("SELECT 商品名称,规格,产地,计量单位,出厂日期,保质期 FROM 库存查询 ");
rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
m_Grid.m_Edit.SetPopRecordset(rst);
}
*/
if(m_Grid.GetCol()==0) //自动添充
{
CString sSpec,sArer,sUnit,sOutFactroyDate,sKeepDate;
try{
sSpec=(char*)(_bstr_t)m_Grid.m_Edit.rst->GetCollect("规格");
}
catch(...)
{
goto ResameNext;
}
sArer=(char*)(_bstr_t)m_Grid.m_Edit.rst->GetCollect("产地");
sUnit=(char*)(_bstr_t)m_Grid.m_Edit.rst->GetCollect("计量单位");
sOutFactroyDate=(char*)(_bstr_t)m_Grid.m_Edit.rst->GetCollect("出厂日期");
sKeepDate=(char*)(_bstr_t)m_Grid.m_Edit.rst->GetCollect("保质期");
m_Grid.SetItemText(m_Grid.GetRow(),1,sSpec);
m_Grid.SetItemText(m_Grid.GetRow(),2,sArer);
m_Grid.SetItemText(m_Grid.GetRow(),3,sUnit);
m_Grid.SetItemText(m_Grid.GetRow(),4,sOutFactroyDate);
m_Grid.SetItemText(m_Grid.GetRow(),5,sKeepDate);
m_Grid.m_Edit.IsPopShow=true;
m_Grid.m_Edit.GetWindowText(sWare);
m_Grid.SetField("仓库名称");
sSQL.Format("SELECT 仓库名称,销售价格 FROM 库存查询 WHERE 商品名称='%s'",sWare);
rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
m_Grid.m_Edit.SetPopRecordset(rst);
IsShow=true;
}
ResameNext:
return;
}
HBRUSH CDOutPut::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(pWnd==&m_StaDate || pWnd==&m_StaID)
{
pDC->SetBkColor(RGB(96,96,96));
pDC->SetTextColor(RGB(255,255,255));
}
if(pWnd==&m_EdtClient)
{
pDC->SetBkColor(RGB(96,96,96));
pDC->SetTextColor(RGB(255,255,255));
return m_hBrush; // TODO: Return a different brush if the default is not desired
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CDOutPut::OnItemchangingList(NMHDR* pNMHDR, LRESULT* pResult)
{
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if(m_Grid.GetCol()==0)
m_Grid.m_Col=5;
*pResult = 0;
}
BOOL CDOutPut::PreTranslateMessage(MSG* pMsg)
{
if(FromHandle(pMsg->hwnd)->GetParent()==&m_Grid && pMsg->message==WM_KEYDOWN &&pMsg->wParam==13)
{
if(m_Grid.GetCol()==0 && this->IsShow==true)
{
CString sSQL;
m_Grid.m_Edit.IsPopShow=true;
sSQL.Format("SELECT 商品名称,规格,产地,计量单位,出厂日期,保质期 FROM 库存查询 ");
rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
m_Grid.m_Edit.SetPopRecordset(rst);
IsShow=false;
m_Grid.SetField("商品名称");
}
ItemChange();
int nSum=0,nMoney=0;
CString sSum,sMoney;
for(int i=0;i<m_Grid.GetItemCount();i++)
{
sSum=m_Grid.GetItemText(i,7);
sMoney=m_Grid.GetItemText(i,8);
nSum=nSum+atoi(sSum);
nMoney=nMoney+(atoi(sMoney)*atoi(sSum));
}
sSum.Format("%d",nSum);
sMoney.Format("%d",nMoney);
m_EdtSum.SetWindowText(sSum);
m_EdtMoney.SetWindowText(sMoney);
}
if(pMsg->hwnd==m_EdtClient.GetSafeHwnd() && pMsg->message==WM_KEYDOWN &&pMsg->wParam==13)
{
this->m_Grid.InsertItem(0,"");
m_Grid.SetFocus();
m_Grid.m_Col=0;
m_Grid.m_Row=0;
m_Grid.BeginEdit(0,0);
}
return CDialog::PreTranslateMessage(pMsg);
}
void CDOutPut::OnBUTEnrol()
{
CTime tDate;
CString cID,cDate;
cID=theApp.AutoNumber("出库信息表","CK",2);
m_StaID.SetWindowText(cID);
tDate=tDate.GetCurrentTime();
cDate=theApp.CTimeToCString(tDate);
m_StaDate.SetWindowText(cDate);
m_ButEnrol.EnableWindow(false);
m_ButSave.EnableWindow(true);
m_ButUndo.EnableWindow(true);
m_ButExit.EnableWindow(false);
m_EdtClient.EnableWindow(true);
m_EdtClient.SetFocus();
}
void CDOutPut::OnBUTSave()
{
int a=MessageBox("确定保存此出库单吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION);
if(a==1)
{
CString cSQL,cStoreNumber,cID,cStore,cWareID,cTime,cProvider,cSum,cMoney,cNum;
int nOP,nStoreNumber,nStoreSum;
m_StaID.GetWindowText(cID);
m_StaDate.GetWindowText(cTime);
m_EdtClient.GetWindowText(cProvider);
m_EdtSum.GetWindowText(cSum);
m_EdtMoney.GetWindowText(cMoney);
nOP=theApp.NumberTOName("用户信息表","用户名",OP);
cSQL.Format("Insert Into 出库信息表 values('%s',#%s#,%s,%s,%d)",cID,cTime,cSum,cMoney,nOP);
cnn->Execute((_bstr_t)cSQL,NULL,adCmdText);
for(int r=0;r<m_Grid.GetItemCount()-1;r++)
{
cWareID=theApp.NumberTOName("商品信息表","编号","名称",m_Grid.GetItemText(r,0));
cNum=m_Grid.GetItemText(r,8);
cStore=m_Grid.GetItemText(r,6);
nStoreNumber=theApp.NumberTOName("仓库信息表","名称",cStore);
cSQL.Format("Insert Into 出库明细表 values('%s','%s',%d,%s)",cID,cWareID,nStoreNumber,cNum);
cnn->Execute((_bstr_t)cSQL,NULL,adCmdText);
//更新仓库信息表
cSQL.Format("SELECT * FROM 库存信息表 WHERE 商品编号='%s' and 仓库编号=%d ",cWareID,nStoreNumber);
rst=cnn->Execute((_bstr_t)cSQL,NULL,adCmdText);
if(theApp.GetRecordCount(rst)>0)
{
rst->MoveFirst();
cStoreNumber=(char*)(_bstr_t)rst->GetCollect("库存数量");
nStoreSum=atoi(cStoreNumber)-atoi(cNum);
cSQL.Format("UPDATE 库存信息表 set 库存数量=%d WHERE 商品编号='%s' and 仓库编号=%d",nStoreSum,cWareID,nStoreNumber);
cnn->Execute((_bstr_t)cSQL,NULL,adCmdText);
rst->Close();
}
}
m_ButEnrol.EnableWindow(true);
m_ButSave.EnableWindow(false);
m_ButUndo.EnableWindow(false);
m_ButExit.EnableWindow(true);
m_EdtClient.EnableWindow(false);
m_EdtClient.IsPopShow=false;
m_EdtClient.SetWindowText("");
m_Grid.ClearGrid();
this->m_ButEnrol.SetFocus();
}
}
void CDOutPut::OnBUTUndo()
{
int a=MessageBox("确定要撤消操作吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION);
if (a==1)
{
m_ButEnrol.EnableWindow(true);
m_ButSave.EnableWindow(false);
m_ButUndo.EnableWindow(false);
m_ButExit.EnableWindow(true);
m_EdtClient.EnableWindow(false);
m_EdtClient.IsPopShow=false;
m_EdtClient.SetWindowText("");
m_Grid.ClearGrid();
}
}
void CDOutPut::OnBUTExit()
{
this->OnCancel();
}