📄 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 + -