?? dlgbookadjust2.cpp
字號:
{
if ((m_list.col ==0) || (m_list.col==1))
{
CString c_barcode,c_bookname;
c_barcode = m_list.GetItemText(m_list.row,0);
c_bookname = m_list.GetItemText(m_list.row,1);
if (m_list.col==0)
{
if (!c_barcode.IsEmpty()&&c_bookname.IsEmpty())
{
m_pRs->raw_Close();
CString sql;
sql.Format("select barcode,bookname,author,bookconcern from tb_bookinfo where barcode = '%s' or shortname = '%s'",c_barcode,c_barcode);
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
if (m_pRs->RecordCount>0)
{
m_list.SetItemText(m_list.row,0,(TCHAR*)(_bstr_t)m_pRs->GetFields()->GetItem((long)0)->Value);
m_list.SetItemText(m_list.row,1,(TCHAR*)(_bstr_t)m_pRs->GetFields()->GetItem((long)1)->Value);
m_list.SetItemText(m_list.row,2,(TCHAR*)(_bstr_t)m_pRs->GetFields()->GetItem((long)2)->Value);
m_list.SetItemText(m_list.row,3,(TCHAR*)(_bstr_t)m_pRs->GetFields()->GetItem((long)3)->Value);
}
else
{
m_list.SetItemText(m_list.row,0,"");
MessageBox("條形碼不存在","提示",64);
return;
}
}
}
else //m_list.col ==1
{
if (!c_bookname.IsEmpty()&&c_barcode.IsEmpty())
{
m_pRs->raw_Close();
CString sql;
sql.Format("select barcode,bookname from tb_bookinfo where barcode = '%s' or shortname = '%s'",c_bookname,c_bookname);
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
if (m_pRs->RecordCount>0)
{
m_list.SetItemText(m_list.row,0,(TCHAR*)(_bstr_t)m_pRs->GetFields()->GetItem((long)0)->Value);
m_list.SetItemText(m_list.row,1,(TCHAR*)(_bstr_t)m_pRs->GetFields()->GetItem((long)1)->Value);
m_list.SetItemText(m_list.row,2,(TCHAR*)(_bstr_t)m_pRs->GetFields()->GetItem((long)2)->Value);
m_list.SetItemText(m_list.row,3,(TCHAR*)(_bstr_t)m_pRs->GetFields()->GetItem((long)3)->Value);
}
else
{
m_list.SetItemText(m_list.row,1, "");
MessageBox("書籍名稱不存在","提示",64);
return;
}
}
}
}
m_list.col = m_list.col+1;
CString tempID,tempname;
tempID = m_list.GetItemText(m_list.row,0);
tempname = m_list.GetItemText(m_list.row,1);
m_list.showedit = true;
if ((tempname.IsEmpty()==false)&&(m_list.col == 0))
m_list.showedit =false;
else if((tempID.IsEmpty()==false)&&(m_list.col == 1))
m_list.showedit =false;
else if ((m_list.col==2 )||(m_list.col== 3))
m_list.showedit =false;
m_list.ShowEdit();
}
else
{
AddNewRow();
}
}
BOOL CDlgBookAdjust2::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message ==WM_KEYDOWN)
{
/****************************************************************
說明: 表格中編輯框獲得焦點時,按Enter鍵控制單元格焦點移動
****************************************************************/
if ((pMsg->wParam == 13)&&(pMsg->hwnd==m_list.edit.m_hWnd))
{
MoveFocus();
return true;
}
/****************************************************************
說明: 表格中獲得焦點時,按Enter鍵添加新行
****************************************************************/
if ((pMsg->wParam == 13)&&(pMsg->hwnd == m_list.m_hWnd))
{
AddNewRow();
return true;
}
if ((pMsg->wParam ==VK_DELETE)&&(pMsg->hwnd == m_list.m_hWnd))
{
DeleteCurRow();
//return true;
}
/****************************************************************
說明: 輔助錄入表格獲得焦點時,按Enter鍵會將當前數據顯示在表格中
****************************************************************/
else if ((pMsg->hwnd ==m_auxilist.m_hWnd)&&(pMsg->wParam == 13))
{
OnDblclkList2(NULL,NULL);
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 == m_list.edit.m_hWnd))
{
LimitEdit();
if (pMsg->wParam == 34)
{
ShowListinfo();
}
else if (pMsg->wParam ==VK_DELETE)//按delete鍵刪除表格當前行
DeleteCurRow();
}
/****************************************************************
說明: 表格中編輯框改變時的事件
****************************************************************/
if ((pMsg->message == WM_KEYUP)&&(pMsg->hwnd == m_list.edit.m_hWnd))
{
EditChange();
}
/****************************************************************
說明: 在窗體中控件獲得焦點時,使提示列表不可見
****************************************************************/
if (pMsg->message==WM_LBUTTONDOWN)
{
if (pMsg->hwnd!= m_auxilist.m_hWnd)
m_auxilist.ShowWindow(SW_HIDE);
}
/****************************************************************
說明: 在單擊表格時,根據當前列判斷是否顯示編輯框
****************************************************************/
if ((pMsg->message ==WM_LBUTTONDOWN)&&(pMsg->hwnd ==m_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 (m_list.SubItemHitTest(&pos)>=0)
{
m_list.SetFocus();
row = pos.iItem;
col = pos.iSubItem;
tempID = m_list.GetItemText(row,0);
tempname = m_list.GetItemText(row,1);
m_list.showedit =true;
if ((col==2)||(col ==3)) //如果單擊金額列,不顯示編輯框
m_list.showedit =false;
if ((tempname.IsEmpty()==false)&&(col == 0))
m_list.showedit =false;
else if((tempID.IsEmpty()==false)&&(col == 1))
m_list.showedit =false;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
void CDlgBookAdjust2::OnDblclkList2(NMHDR* pNMHDR, LRESULT* pResult)
{
int row = m_auxilist.GetSelectionMark();
if (row!=-1)
{
CString temp;
temp = m_auxilist.GetItemText(row,0);
//設置條形碼
m_list.SetItemText(m_list.row,0,temp);
//設置書籍名稱
m_list.SetItemText(m_list.row,1,m_auxilist.GetItemText(row,1));
//設置默認價格
m_list.SetItemText(m_list.row,2,m_auxilist.GetItemText(row,2));
m_list.SetItemText(m_list.row,3,m_auxilist.GetItemText(row,3));
m_auxilist.ShowWindow(SW_HIDE);
}
//移動編輯框
//MoveFocus();
m_list.col =4;
m_list.ShowEdit();
}
void CDlgBookAdjust2::AddOperate()
{
if ((m_storage.GetCurSel()==-1)||(m_counter.GetCurSel()==-1))
{
MessageBox("倉庫或柜臺信息不能為空.","提示",64);
return;
}
if (DetailInfoIsNull())
{
MessageBox("商品列表不能為空.","提示",64);
return;
}
CString c_storage,c_operator,c_counter,c_date,c_id;
m_storage.GetWindowText(c_storage);
m_operator.GetWindowText(c_operator);
m_counter.GetWindowText(c_counter);
m_date.GetWindowText(c_date);
m_pCom->ActiveConnection = m_pCon.GetInterfacePtr();
_ParameterPtr a,b,c,d,e;
a = m_pCom->CreateParameter("a1",adVarChar,adParamInput,30);
a->Value = (_bstr_t)c_storage;
b = m_pCom->CreateParameter("a2",adVarChar,adParamInput,30);
b->Value = (_bstr_t)c_counter;
c = m_pCom->CreateParameter("a3",adVarChar,adParamInput,30);
c->Value = (_bstr_t)c_operator;
d = m_pCom->CreateParameter("a4",adVarChar,adParamInput,30);
d->Value = (_bstr_t)c_date;
e = m_pCom->CreateParameter("a5",adVarChar,adParamOutput,30);
m_pCom->Parameters->Append(a);
m_pCom->Parameters->Append(b);
m_pCom->Parameters->Append(c);
m_pCom->Parameters->Append(d);
m_pCom->Parameters->Append(e);
m_pCom->CommandText = "sp_adjuststorage";
try
{
m_pCom->Execute(0,NULL,adCmdStoredProc);
c_id = (TCHAR*)(_bstr_t)e->Value;
m_pCom->Parameters->Delete("a1");
m_pCom->Parameters->Delete("a2");
m_pCom->Parameters->Delete("a3");
m_pCom->Parameters->Delete("a4");
m_pCom->Parameters->Delete("a5");
CString sql,c_barcode,c_booknum;
float f_booknum;
for (int row = 0 ;row<m_list.GetItemCount();row++)
{
m_pRs->raw_Close();
c_barcode = m_list.GetItemText(row,0);
c_booknum = m_list.GetItemText(row,4);
f_booknum = atof(c_booknum);
sql.Format("insert into tb_bookmove_sub values ('%s','%s',%f)",c_id,c_barcode,f_booknum);
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
m_pRs->raw_Close();
sql.Format("update tb_bookstorage set booknum = booknum- %f where barcode = '%s' and storagename = '%s'",f_booknum,c_barcode,c_storage);
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
m_pRs->raw_Close();
sql.Format("select * from tb_counterbook where barcode = '%s' and counter = '%s'",c_barcode,c_counter);
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
if (m_pRs->RecordCount>0)
{
m_pRs->raw_Close();
sql.Format("update tb_counterbook set booknum = booknum+ %f where barcode = '%s' and counter = '%s'",f_booknum,c_barcode,c_counter);
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
}
else
{
m_pRs->raw_Close();
sql.Format("insert into tb_counterbook values ('%s','%s',%f)",c_barcode,c_counter,f_booknum);
m_pRs->Open((_variant_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
}
}
MessageBox("操作成功.","提示",64);
CancelOperate();
}
catch(...)
{
MessageBox("操作失敗.","提示",64);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -