?? dlgstorepd3.cpp
字號:
// DlgStorePD3.cpp : implementation file
//
#include "stdafx.h"
#include "aaa.h"
#include "DlgStorePD3.h"
#include "CustomGrid.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr m_pCon;
extern _RecordsetPtr m_pRs;
extern CAaaApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDlgStorePD3 dialog
CDlgStorePD3::CDlgStorePD3(CWnd* pParent /*=NULL*/)
: CDialog(CDlgStorePD3::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgStorePD3)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CDlgStorePD3::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgStorePD3)
DDX_Control(pDX, IDC_STORE_PD_PERSON, memo);
DDX_Control(pDX, IDC_STORE_MARK, checkman);
DDX_Control(pDX, IDC_DATETIMEPICKER1, checktime);
DDX_Control(pDX, IDC_COMBO2, checkspec);
DDX_Control(pDX, IDC_LIST3, listinfo);
DDX_Control(pDX, IDC_LIST1, list);
DDX_Control(pDX, IDC_COMBO1, storagename);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgStorePD3, CDialog)
//{{AFX_MSG_MAP(CDlgStorePD3)
ON_NOTIFY(NM_DBLCLK, IDC_LIST3, OnDblclkList3)
ON_NOTIFY(LVN_KEYDOWN, IDC_LIST3, OnKeydownList3)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgStorePD3 message handlers
void CDlgStorePD3::AddStorage()
{
storagename.ResetContent();
m_pRs->Close();
CString sql;
sql.Format("select storagename from tb_storageinfo");
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
while (! m_pRs->adoEOF)
{
storagename.AddString((TCHAR*)(_bstr_t)m_pRs->GetFields()->GetItem((long)0)->Value);
m_pRs->MoveNext();
}
}
BOOL CDlgStorePD3::OnInitDialog()
{
CDialog::OnInitDialog();
//添加倉庫名稱
AddStorage();
list.InsertColumn(0,"商品編號");
list.InsertColumn(1,"商品名稱");
list.InsertColumn(2,"規格");
list.InsertColumn(3,"數量");
listinfo.ModifyStyle(LVS_EDITLABELS,0);//禁止編輯標題
listinfo.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE|LVS_EX_INFOTIP|LVS_EX_SUBITEMIMAGES|LVS_EX_GRIDLINES );
listinfo.InsertColumn(0,"商品編號");
listinfo.InsertColumn(1,"商品名稱");
listinfo.InsertColumn(2,"規格");
listinfo.InsertColumn(3,"助記碼");
listinfo.InsertColumn(4,"默認價格");
//設置列寬度
list.SetColumnWidth(0,150);
list.SetColumnWidth(1,250);
list.SetColumnWidth(2,80);
list.SetColumnWidth(3,80);
listinfo.SetColumnWidth(0,80);
listinfo.SetColumnWidth(1,100);
listinfo.SetColumnWidth(2,60);
listinfo.SetColumnWidth(3,60);
listinfo.SetColumnWidth(4,60);
//添加一行
list.InsertItem(0,"");
listinfo.SetParent(&list);
return TRUE; // EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CDlgStorePD3::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN)
{
if (pMsg->hwnd == list.edit.m_hWnd)
{
LimitEdit();
if (pMsg->wParam == 34)
{
ShowListinfo();
}
else if (pMsg->wParam ==VK_DELETE)//按delete鍵刪除表格當前行
DeleteCurRow();
}
else if ((pMsg->hwnd ==listinfo.m_hWnd)&&(pMsg->wParam == 13))
{
OnDblclkList3(NULL,NULL);
return true;
}
/****************************************************************
說明: 表格中編輯框獲得焦點時,按Enter鍵控制單元格焦點移動
****************************************************************/
if ((pMsg->wParam == 13)&&(pMsg->hwnd==list.edit.m_hWnd))
{
MoveFocus();
return true;
}
if (pMsg->wParam==13)
pMsg->wParam = 9;
}
/****************************************************************
說明: 表格中編輯框改變時的事件
****************************************************************/
if ((pMsg->message == WM_KEYUP)&&(pMsg->hwnd == list.edit.m_hWnd))
{
EditChange();
}
if (pMsg->message==WM_LBUTTONDOWN)
{
if (pMsg->hwnd!= listinfo.m_hWnd)
listinfo.ShowWindow(SW_HIDE);
}
/****************************************************************
說明: 在單擊表格時,根據當前列判斷是否顯示編輯框
****************************************************************/
if ((pMsg->message ==WM_LBUTTONDOWN)&&(pMsg->hwnd ==list.m_hWnd))
{
//當前列為商品編號,商品名稱為空,顯示編輯框,在當前列為商品名稱,商品編號為空,顯示編輯框,
CString tempID,tempname;
LVHITTESTINFO pos;
pos.pt.x = LOWORD(pMsg->lParam);
pos.pt.y = HIWORD(pMsg->lParam);
pos.flags = LVHT_ABOVE;
int row,col;
row = -1;
col = -1;
if (list.SubItemHitTest(&pos)>=0)
{
list.SetFocus();
row = pos.iItem;
col = pos.iSubItem;
tempID = list.GetItemText(row,0);
tempname = list.GetItemText(row,1);
list.showedit =true;
if ((tempname.IsEmpty()==false)&&(col == 0))
list.showedit =false;
else if((tempID.IsEmpty()==false)&&(col == 1))
list.showedit =false;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
void CDlgStorePD3::OnOK()
{
}
void CDlgStorePD3::OnCancel()
{
}
void CDlgStorePD3::LimitEdit()
{
list.edit.IsNumber = false;
//在修改商品數據時只允許輸入數字
if (list.col ==3)
{
list.edit.IsNumber = true;
}
}
void CDlgStorePD3::DeleteCurRow()
{
int currow;
currow = list.row;
if (currow!=-1)
{
if (MessageBox("確實要刪除當前行嗎?","提示",MB_YESNO)==IDYES)
{
int m = list.GetItemCount();
if (m >1)
{
for (int i = currow+1;i<list.GetItemCount();i++)
{
for(int c = 0; c<7 ;c++)
{
list.SetItemText(i-1,c,list.GetItemText(i,c));
}
}
list.DeleteItem(list.GetItemCount()-1);
}
else
{
for (int i = 0;i< 7;i++)
{
list.SetItemText(0,i,"");
}
}
}
}
}
void CDlgStorePD3::EditChange()
{
CString str;
list.edit.GetWindowText(str);
CString sql = "";
switch (list.col)
{
case 0 :
{
if (!str.IsEmpty())
sql.Format("select * from tb_merchandiseinfo where id like '%s%%' or shortname like '%s%%' ",str,str);
break;
}
case 1 :
{
if (!str.IsEmpty())
sql.Format("select * from tb_merchandiseinfo where name like '%s%%' or shortname like '%s%%'",str,str);
break;
}
default:
break;
}
if (! sql.IsEmpty())
{
m_pRs->raw_Close();
m_pRs->Open((_bstr_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
if (m_pRs->RecordCount>0)
{
listinfo.DeleteAllItems();
int i=0;
while(! m_pRs->adoEOF)
{
listinfo.InsertItem(100,"");
for (int m = 0;m<5;m++)
listinfo.SetItemText(i,m,(TCHAR*)(_bstr_t)m_pRs->GetFields()->GetItem((long)m)->Value);
m_pRs->MoveNext();
i +=1;
}
ShowListInfo();
}
else
listinfo.ShowWindow(SW_HIDE);
}
else
listinfo.ShowWindow(SW_HIDE);
}
void CDlgStorePD3::ShowListInfo()
{
CRect rect;
list.GetSubItemRect(list.row,list.col,LVIR_BOUNDS,rect);
listinfo.MoveWindow(rect.left,rect.bottom+1,300,150);
listinfo.ShowWindow(SW_SHOW);
}
void CDlgStorePD3::OnDblclkList3(NMHDR* pNMHDR, LRESULT* pResult)
{
int row = listinfo.GetSelectionMark();
if (row!=-1)
{
CString temp;
temp = listinfo.GetItemText(row,0);
//設置商品編號
list.SetItemText(list.row,0,temp);
//設置商品名稱
list.SetItemText(list.row,1,listinfo.GetItemText(row,1));
list.SetItemText(list.row,2,listinfo.GetItemText(row,2));
listinfo.ShowWindow(SW_HIDE);
}
//移動編輯框
//MoveFocus();
list.col =3;
list.ShowEdit();
//*pResult = 0;
}
void CDlgStorePD3::OnKeydownList3(NMHDR* pNMHDR, LRESULT* pResult)
{
LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
// TODO: Add your control notification handler code here
*pResult = 0;
}
void CDlgStorePD3::MoveFocus()
{
list.DisposeEdit(true);
if (list.col <4)
{
list.col = list.col+1;
CString tempID,tempname;
tempID = list.GetItemText(list.row,0);
tempname = list.GetItemText(list.row,1);
list.showedit = true;
if ((tempname.IsEmpty()==false)&&(list.col == 0))
list.showedit =false;
else if((tempID.IsEmpty()==false)&&(list.col == 1))
list.showedit =false;
list.ShowEdit();
}
else
{
AddNewRow();
}
}
void CDlgStorePD3::AddNewRow()
{
int counts = list.GetItemCount();
if (list.row == counts-1)//當前行為最后一行
{
list.InsertItem(100,"");
list.row+=1;
list.col = 0;
list.ShowEdit();
}
else
{
list.row+=1;
list.col = 0;
list.ShowEdit();
}
}
void CDlgStorePD3::ShowListinfo()
{
if (listinfo.IsWindowVisible())
{
listinfo.SetFocus();
listinfo.SetSelectionMark(1);
}
}
bool CDlgStorePD3::InfoIsNull(int main)
{
if (main ==0)
{
CString c_storage,c_checkspec,c_checkman,c_memo;
storagename.GetWindowText(c_storage);
checkspec.GetWindowText(c_checkspec);
checkman.GetWindowText(c_checkman);
memo.GetWindowText(c_memo);
if (c_storage.IsEmpty()||c_checkspec.IsEmpty()||c_checkman.IsEmpty()||c_memo.IsEmpty())
return true;
}
else if (main ==1)
{
int rowcount = list.GetItemCount();
if (rowcount ==-1)
return true;
for (int r = 0;r <rowcount;r++)
for (int i = 0;i<4;i++)
{
CString temp;
temp = list.GetItemText(r,i);
if (temp.IsEmpty()==true)
return true;
}
}
return false;
}
void CDlgStorePD3::CheckOporate()
{
if (InfoIsNull(0))
{
MessageBox("盤點信息不能為空.","提示",64);
return;
}
if (InfoIsNull(1))
{
MessageBox("商品信息不能為空.","提示",64);
return;
}
CString c_storage,c_checkspec,c_checkman,c_memo,c_time;
CString c_mercandiseid,c_num;
float f_num;
int spec;
spec = checkspec.GetCurSel(); //0報損 1 報溢
storagename.GetWindowText(c_storage);
checkspec.GetWindowText(c_checkspec);
checkman.GetWindowText(c_checkman);
memo.GetWindowText(c_memo);
CTime temp;
checktime.GetTime(temp);
c_time = temp.Format("%Y-%m-%d");
CString sql;
sql.Format("sp_check '%s','%s','%s',%i,'%s','%s'",c_storage,c_checkman,c_time,spec,c_memo,"temp");
try
{
m_pRs->raw_Close();
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdUnknown);
CString id ;//記錄盤點單號
id =(TCHAR*)(_bstr_t) m_pRs->GetFields()->GetItem("tempid")->Value;
int row = 0;
int rows = list.GetItemCount();
for (int i = 0;i<rows;i++)
{
c_mercandiseid = list.GetItemText(row,0);
c_num = list.GetItemText(row,3);
f_num = atof(c_num);
sql.Format("insert into tb_check_sub values ('%s','%s',%f)",id,c_mercandiseid,f_num);
m_pRs->raw_Close();
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
//修改商品庫存
if (spec == 0)//報損
{
sql.Format("update tb_merchandisestorage set storagenum = storagenum - %f where merchandiseid = '%s' and storagename = '%s'",f_num,c_mercandiseid,c_storage);
}
else //報溢
{
sql.Format("update tb_merchandisestorage set storagenum = storagenum + %f where merchandiseid = '%s' and storagename = '%s'",f_num,c_mercandiseid,c_storage);
}
m_pRs->raw_Close();
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
row +=1;
}
CancelOperate();
MessageBox("操作成功,票號為 "+id,"提示",64);
}
catch(_com_error)
{
MessageBox("操作失敗","提示",64);
}
}
void CDlgStorePD3::CancelOperate()
{
list.DeleteAllItems();
list.InsertItem(0,"");
storagename.SetCurSel(-1);
checkspec.SetCurSel(-1);
CTime time = CTime::GetCurrentTime();
checktime.SetTime(&time);
checkman.SetWindowText("");
memo.SetWindowText("");
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -