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