?? dlgproductorinput2.cpp
字號:
// DlgProductorInput2.cpp : implementation file
//
#include "stdafx.h"
#include "aaa.h"
#include "DlgProductorInput2.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;
/////////////////////////////////////////////////////////////////////////////
// CDlgProductorInput2 dialog
CDlgProductorInput2::CDlgProductorInput2(CWnd* pParent /*=NULL*/)
: CDialog(CDlgProductorInput2::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgProductorInput2)
//}}AFX_DATA_INIT
}
void CDlgProductorInput2::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgProductorInput2)
DDX_Control(pDX, IDC_REBATE, rebate);
DDX_Control(pDX, IDC_LISTBOX2, storage);
DDX_Control(pDX, IDC_LIST1, listinfo);
DDX_Control(pDX, IDC_DETAILLIST, list);
DDX_Control(pDX, IDC_LISTBOX, listbox);
DDX_Control(pDX, IDC_OPERATORNAME, operatorname);
DDX_Control(pDX, IDC_TOTALMONEY, totalmoney);
DDX_Control(pDX, IDC_PROVIDERNAME, providername);
DDX_Control(pDX, IDC_PAYMONEY, paymoney);
DDX_Control(pDX, IDC_INPUTDATE, inputdate);
DDX_Control(pDX, IDC_FACTMONEY, factmoney);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgProductorInput2, CDialog)
//{{AFX_MSG_MAP(CDlgProductorInput2)
ON_LBN_DBLCLK(IDC_LISTBOX, OnDblclkListbox)
ON_LBN_KILLFOCUS(IDC_LISTBOX, OnKillfocusListbox)
ON_NOTIFY(NM_CLICK, IDC_DETAILLIST, OnClickDetaillist)
ON_NOTIFY(HDN_ITEMCLICK, IDC_DETAILLIST, OnItemclickDetaillist)
ON_NOTIFY(NM_KILLFOCUS, IDC_LIST1, OnKillfocusList1)
ON_NOTIFY(NM_DBLCLK, IDC_LIST1, OnDblclkList1)
ON_LBN_KILLFOCUS(IDC_LISTBOX2, OnKillfocusListbox2)
ON_LBN_DBLCLK(IDC_LISTBOX2, OnDblclkListbox2)
ON_EN_CHANGE(IDC_REBATE, OnChangeRebate)
ON_EN_CHANGE(IDC_TOTALMONEY, OnChangeTotalmoney)
ON_NOTIFY(LVN_KEYDOWN, IDC_DETAILLIST, OnKeydownDetaillist)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgProductorInput2 message handlers
BOOL CDlgProductorInput2::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message ==WM_KEYDOWN)
{
/****************************************************************
說明: 在供應商編輯框獲得焦點并按PageDown鍵,調用DoEditKeyDown方法
****************************************************************/
if ((pMsg->wParam == 34)&&(pMsg->hwnd==providername.m_hWnd))
{
DoEditKeyDown(34,IDC_PROVIDERNAME);
}
/****************************************************************
說明: 表格中編輯框獲得焦點時,按Enter鍵控制單元格焦點移動
****************************************************************/
if ((pMsg->wParam == 13)&&(pMsg->hwnd==list.edit.m_hWnd))
{
MoveFocus();
return true;
}
/****************************************************************
說明: 表格中獲得焦點時,按Enter鍵添加新行
****************************************************************/
if ((pMsg->wParam == 13)&&(pMsg->hwnd == list.m_hWnd))
{
AddNewRow();
return true;
}
if ((pMsg->wParam ==VK_DELETE)&&(pMsg->hwnd == list.m_hWnd))
{
DeleteCurRow();
//return true;
}
/****************************************************************
說明: 列表框獲得焦點時,按Enter鍵會將當前數據顯示在編輯框中
****************************************************************/
else if ((pMsg->hwnd ==listbox.m_hWnd)&&(pMsg->wParam == 13))
{
OnDblclkListbox();
return true;
}
/****************************************************************
說明: 輔助錄入表格獲得焦點時,按Enter鍵會將當前數據顯示在表格中
****************************************************************/
else if ((pMsg->hwnd ==listinfo.m_hWnd)&&(pMsg->wParam == 13))
{
OnDblclkList1(NULL,NULL);
return true;
}
else if ((pMsg->wParam ==13)&&(pMsg->hwnd == storage.m_hWnd))
{
OnDblclkListbox2();
return true;
}
else if (pMsg->wParam ==13)
{
pMsg->wParam = 9;
//return;
}
else if (pMsg->wParam == VK_ESCAPE)
return true;
}
/****************************************************************
說明: 表格中編輯框按鍵時的事件,用于判斷是否限制字符輸入,如果用戶按
PageDown鍵,將使輔助錄入表格獲得焦點
****************************************************************/
if ((pMsg->message == WM_KEYDOWN)&&(pMsg->hwnd == list.edit.m_hWnd))
{
LimitEdit();
if (pMsg->wParam == 34)
{
ShowListinfo();
ShowStorage();
}
else if (pMsg->wParam ==VK_DELETE)//按delete鍵刪除表格當前行
DeleteCurRow();
}
/****************************************************************
說明: 表格中編輯框改變時的事件
****************************************************************/
if ((pMsg->message == WM_KEYUP)&&(pMsg->hwnd == list.edit.m_hWnd))
{
EditChage();
}
/****************************************************************
說明: 在窗體中控件獲得焦點時,使提示列表不可見
****************************************************************/
if (pMsg->message==WM_LBUTTONDOWN)
{
if (pMsg->hwnd!= listinfo.m_hWnd)
listinfo.ShowWindow(SW_HIDE);
if (pMsg->hwnd != storage.m_hWnd)
storage.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,1);
tempname = list.GetItemText(row,2);
if (col==6) //如果單擊金額列,不顯示編輯框
return true;
list.showedit =true;
if ((tempname.IsEmpty()==false)&&(col == 1))
list.showedit =false;
else if((tempID.IsEmpty()==false)&&(col == 2))
list.showedit =false;
}
}
//處理折扣編輯框的按鍵消息,屏蔽非法字符
if ((pMsg->message==WM_CHAR)&&(pMsg->hwnd == rebate.m_hWnd))
{
DWORD i = pMsg->wParam;
if (i!= 8)
if ((i<46)||(i>46)&&(i<47)||(i>57))
{
pMsg->wParam =0;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
BOOL CDlgProductorInput2::OnInitDialog()
{
CDialog::OnInitDialog();
//添加供應商
AddProvider();
//添加倉庫信息
AddStorage();
storage.SetParent(&list);
//讀取操作員名稱
operatorname.SetWindowText(theApp.strUser);
//設置表格風格
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.InsertColumn(0,"倉庫名稱");
list.InsertColumn(1,"商品編號");
list.InsertColumn(2,"商品名稱");
list.InsertColumn(3,"單價");
list.InsertColumn(4,"數量");
list.InsertColumn(5,"折扣");
list.InsertColumn(6,"金額");
//設置列寬度
listinfo.SetColumnWidth(0,80);
listinfo.SetColumnWidth(1,100);
listinfo.SetColumnWidth(2,60);
listinfo.SetColumnWidth(3,60);
listinfo.SetColumnWidth(4,60);
list.SetColumnWidth(0,100);
list.SetColumnWidth(1,140);
list.SetColumnWidth(2,60);
list.SetColumnWidth(3,60);
list.SetColumnWidth(4,60);
list.SetColumnWidth(5,60);
list.SetColumnWidth(6,100);
//添加空行
list.InsertItem(1,"");
list.SetItemText(0,5,"1.0");
listinfo.SetParent(&list);
rebate.SetWindowText("1.0");
return TRUE;
}
void CDlgProductorInput2::AddProvider()
{
listbox.SetRedraw(FALSE);
listbox.ResetContent();//刪除所有的數據
CString sql;
sql = "select providername from tb_providerinfo";
m_pRs->Close();
m_pRs->Open((_bstr_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
while (!m_pRs->adoEOF)
{
listbox.AddString((TCHAR *)(_bstr_t)m_pRs->GetFields()->GetItem("providername")->Value);
m_pRs->MoveNext();
}
listbox.SetRedraw(TRUE);
listbox.Invalidate();
}
void CDlgProductorInput2::OnDblclkListbox()
{
CString temp;
int index = listbox.GetCurSel();
if (index != -1)
{
listbox.GetText(index,temp);
if (! temp.IsEmpty())
providername.SetWindowText(temp);
providername.SetFocus();
listbox.ShowWindow(SW_HIDE);
}
}
void CDlgProductorInput2::DoEditKeyDown(UINT nChar,UINT CtrlID)
{
if ((nChar ==34)&&(CtrlID ==IDC_PROVIDERNAME))
{
CRect rect,rect1;
listbox.GetWindowRect(rect1);
providername.GetWindowRect(rect);
ScreenToClient(rect);
ScreenToClient(rect1);
listbox.MoveWindow(rect.left,rect.bottom+2,rect.right-rect.left,rect1.bottom-rect1.top);
listbox.ShowWindow(SW_SHOW);
SetWindowPos(&listbox.wndTopMost,rect.left,rect.bottom+2,rect.right-rect.left,rect1.bottom-rect1.top,SWP_SHOWWINDOW);
listbox.SetSel(0);
listbox.SetFocus();
}
}
void CDlgProductorInput2::OnKillfocusListbox()
{
listbox.ShowWindow(SW_HIDE);
}
void CDlgProductorInput2::OnClickDetaillist(NMHDR* pNMHDR, LRESULT* pResult)
{
if (list.GetSelectionMark()!=1)//有數據被選中
{
}
*pResult = 0;
}
void CDlgProductorInput2::OnItemclickDetaillist(NMHDR* pNMHDR, LRESULT* pResult)
{
HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
*pResult = 0;
}
void CDlgProductorInput2::MoveFocus()
{
list.DisposeEdit(true);
if (list.col <5)
{
list.col = list.col+1;
CString tempID,tempname;
tempID = list.GetItemText(list.row,1);
tempname = list.GetItemText(list.row,2);
list.showedit = true;
if ((tempname.IsEmpty()==false)&&(list.col == 1))
list.showedit =false;
else if((tempID.IsEmpty()==false)&&(list.col == 2))
list.showedit =false;
list.ShowEdit();
}
else
{
AddNewRow();
}
}
/*******************************************
說明: 判斷表格當前行是否為空
*******************************************/
bool CDlgProductorInput2::CurrentRowIsNull()
{
int row = list.GetSelectionMark();
if (row !=-1)
{
for (int index = 0;index <7;index++)
{
CString str;
str = list.GetItemText(list.row,index);
if (str.IsEmpty())
{
return true;
}
}
}
else
return true;
return false;
}
/*******************************************
說明: 在表格中添加新行
*******************************************/
void CDlgProductorInput2::AddNewRow()
{
int counts = list.GetItemCount();
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -