www.gusucode.com > VC++毕业设计-库存管理系统(Access)-源码程序 > VC++毕业设计-库存管理系统(Access)-源码程序/code/源程序/DInput.cpp
// DInput.cpp : implementation file // Download by http://www.NewXing.com #include "stdafx.h" #include "商品库存管理系统.h" #include "DInput.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif extern _ConnectionPtr cnn; extern CMyApp theApp; ///////////////////////////////////////////////////////////////////////////// // CDInput dialog CDInput::CDInput(CWnd* pParent /*=NULL*/) : CDialog(CDInput::IDD, pParent) { m_hBrush=::CreateSolidBrush(RGB(96,96,96)); //}}AFX_DATA_INIT } void CDInput::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CDInput) DDX_Control(pDX, IDC_EDTSum, m_EdtSum); DDX_Control(pDX, IDC_EDTMoney, m_EdtMoney); 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); DDX_Control(pDX, IDC_LIST, m_Grid); DDX_Control(pDX, IDC_STAID, m_StaID); DDX_Control(pDX, IDC_STADate, m_StaDate); DDX_Control(pDX, IDC_EDTProvider, m_EdtProvider); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CDInput, CDialog) //{{AFX_MSG_MAP(CDInput) ON_WM_CTLCOLOR() ON_BN_CLICKED(IDC_BUTEnrol, OnBUTEnrol) ON_NOTIFY(LVN_ITEMCHANGING, IDC_LIST, OnItemchangingList) ON_BN_CLICKED(IDC_BUTSave, OnBUTSave) ON_BN_CLICKED(IDC_BUTUndo, OnBUTUndo) ON_BN_CLICKED(IDC_BUTExit, OnBUTExit) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDInput message handlers void CDInput::OnOK() { // TODO: Add extra validation here //CDialog::OnOK(); } BOOL CDInput::OnInitDialog() { CString FieldName[]={"商品名称","规格","产地","计量单位","出厂日期","保质期","进货仓库","进货数量","进货单价","销售价格"}; int ColWidth[]={150,60,100,60,80,80,100,100,100,100}; CDialog::OnInitDialog(); m_EdtProvider.DataBase="供应商信息查询"; m_EdtProvider.Field="名称"; m_EdtProvider.assn=true; m_EdtProvider.GridParent=this; for(int i=0;i<10;i++) { m_Grid.InsertColumn(i,FieldName[i]); m_Grid.SetColumnWidth(i,ColWidth[i]); } m_Grid.SetColumnCount(10); m_Grid.AutoInsert=true; m_Grid.SetDataBase("商品信息查询"); m_Grid.SetAssn(true); m_Grid.SetField("名称"); this->IsPopShow=false; return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } HBRUSH CDInput::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_EdtProvider) { 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 } return hbr; } BOOL CDInput::DestroyWindow() { ::DeleteObject(m_hBrush); return CDialog::DestroyWindow(); } void CDInput::OnBUTEnrol() { CTime tDate; CString cID,cDate; cID=theApp.AutoNumber("入库信息表","RK",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_EdtProvider.EnableWindow(true); m_EdtProvider.IsPopShow=true; m_EdtProvider.SetFocus(); } BOOL CDInput::PreTranslateMessage(MSG* pMsg) { if(FromHandle(pMsg->hwnd)->GetParent()==&m_Grid && pMsg->message==WM_KEYDOWN &&pMsg->wParam==13) { ItemChange(); int nSum=0; float 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+(atof(sMoney)*atoi(sSum)); } sSum.Format("%d",nSum); sMoney.Format("%f",nMoney); m_EdtSum.SetWindowText(sSum); m_EdtMoney.SetWindowText(sMoney); } if(pMsg->hwnd==m_EdtProvider.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 CDInput::ItemChange() { if(m_Grid.GetCol()==7) { m_Grid.m_Edit.IsPopShow=false; } if(m_Grid.GetCol()==9) { m_Grid.m_Edit.IsPopShow=true; m_Grid.SetDataBase("商品信息查询"); m_Grid.SetAssn(true); m_Grid.SetField("名称"); } 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.SetDataBase("仓库信息表"); m_Grid.SetAssn(true); m_Grid.SetField("名称"); } ResameNext: return; } void CDInput::OnItemchangingList(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; if(m_Grid.GetCol()==0) m_Grid.m_Col=5; *pResult = 0; } void CDInput::OnBUTSave() { int a=MessageBox("确定保存此入库单吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION); if(a==1) { CString cSQL,cStoreNumber,cID,cStore,cWareID,cTime,cProvider,cMoney,cSum,cSell,cNum,cPrice; int nOP,nStoreNumber,nStoreSum; m_StaID.GetWindowText(cID); m_StaDate.GetWindowText(cTime); m_EdtProvider.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,7); cPrice=m_Grid.GetItemText(r,8); cStore=m_Grid.GetItemText(r,6); cSell=m_Grid.GetItemText(r,9); 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,单价= %s,销售价格=%s WHERE 商品编号='%s' and 仓库编号=%d",nStoreSum,cPrice,cSell,cWareID,nStoreNumber); } else cSQL.Format("INSERT INTO 库存信息表 values('%s',%d,%s,500,10,%s,%s)",cWareID,nStoreNumber,cNum,cPrice,cSell); 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_EdtProvider.EnableWindow(false); m_EdtProvider.IsPopShow=false; m_EdtProvider.SetWindowText(""); m_Grid.Clear(); } } void CDInput::SetOP(CString sOP) { OP=sOP; } void CDInput::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_EdtProvider.EnableWindow(false); m_EdtProvider.IsPopShow=false; m_EdtProvider.SetWindowText(""); m_Grid.ClearGrid(); } } void CDInput::OnBUTExit() { this->OnCancel(); }