?? dlginputstoreback2.cpp
字號:
// DlgInputStoreBack2.cpp : implementation file
//
#include "stdafx.h"
#include "aaa.h"
#include "DlgInputStoreBack2.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDlgInputStoreBack2 dialog
extern _ConnectionPtr m_pCon;
extern _RecordsetPtr m_pRs;
extern CAaaApp theApp;
CDlgInputStoreBack2::CDlgInputStoreBack2(CWnd* pParent /*=NULL*/)
: CDialog(CDlgInputStoreBack2::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgInputStoreBack2)
//}}AFX_DATA_INIT
}
void CDlgInputStoreBack2::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgInputStoreBack2)
DDX_Control(pDX, IDC_LIST1, list);
DDX_Control(pDX, IDC_TOTALMONEY, totalmoney);
DDX_Control(pDX, IDC_REBATE, rebate);
DDX_Control(pDX, IDC_PAYMONEY, paymoney);
DDX_Control(pDX, IDC_FACTMONEY, factmoney);
DDX_Control(pDX, IDC_PROVIDERNAME, providername);
DDX_Control(pDX, IDC_OPERATORNAME, operatorname);
DDX_Control(pDX, IDC_LISTBOX2, storage);
DDX_Control(pDX, IDC_LISTBOX, listbox);
DDX_Control(pDX, IDC_LIST2, listinfo);
DDX_Control(pDX, IDC_INPUTDATE, inputdate);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgInputStoreBack2, CDialog)
//{{AFX_MSG_MAP(CDlgInputStoreBack2)
ON_EN_CHANGE(IDC_REBATE, OnChangeRebate)
ON_EN_CHANGE(IDC_TOTALMONEY, OnChangeTotalmoney)
ON_NOTIFY(NM_DBLCLK, IDC_LIST2, OnDblclkList2)
ON_LBN_KILLFOCUS(IDC_LISTBOX, OnKillfocusListbox)
ON_NOTIFY(NM_KILLFOCUS, IDC_LIST2, OnKillfocusList2)
ON_LBN_KILLFOCUS(IDC_LISTBOX2, OnKillfocusListbox2)
ON_LBN_DBLCLK(IDC_LISTBOX, OnDblclkListbox)
ON_LBN_DBLCLK(IDC_LISTBOX2, OnDblclkListbox2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDlgInputStoreBack2 message handlers
BOOL CDlgInputStoreBack2::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))
{
OnDblclkList2(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 CDlgInputStoreBack2::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; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgInputStoreBack2::AddNewRow()
{
int counts = list.GetItemCount();
// if (!CurrentRowIsNull()) //當前行不為空
if (list.row == counts-1)//當前行為最后一行
{
list.InsertItem(100,"");
list.row+=1;
list.SetItemText(list.row,5,"1.0");
//list.SetFocus();
list.col = 0;
//list.SetHotItem(1);
list.ShowEdit();
}
else
{
list.row+=1;
list.col = 0;
list.ShowEdit();
}
}
void CDlgInputStoreBack2::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();
}
float CDlgInputStoreBack2::CalculateMoney()
{
float money,temp;
money = 0.0;
CString c_money;
int rowcounts = list.GetItemCount();
for (int i = 0;i<rowcounts;i++)
{
c_money = list.GetItemText(i,6);
if (!c_money.IsEmpty())
{
temp = atof(c_money);
money += temp;
}
}
return money;
}
void CDlgInputStoreBack2::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,"");
}
}
CString temp;
temp.Format("%10.2f",CalculateMoney());//重新統計數據
temp.TrimLeft();
totalmoney.SetWindowText(temp);
}
}
}
bool CDlgInputStoreBack2::DetailInfoIsNull()
{
int rowcount = list.GetItemCount();
if (rowcount ==-1)
return true;
for (int r = 0;r <rowcount;r++)
for (int i = 0;i<7;i++)
{
CString temp;
temp = list.GetItemText(r,i);
if (temp.IsEmpty()==true)
return true;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -