📄 dlgbookinput2.cpp
字号:
m_pRs->MoveNext();
i +=1;
}
ShowListInfo();
}
else
m_auxilist.ShowWindow(SW_HIDE);
}
else
m_auxilist.ShowWindow(SW_HIDE);
}
bool CDlgBookInput2::InputInfoIsNull()
{
CString c_provider,c_totalmoney,c_rebate,c_paymoney,c_factmoney;
m_provider.GetWindowText(c_provider);
m_summoney.GetWindowText(c_totalmoney);
m_rebate.GetWindowText(c_rebate);
m_paymoney.GetWindowText(c_paymoney);
m_factmoney.GetWindowText(c_factmoney);
if ((c_provider.IsEmpty())||(c_totalmoney.IsEmpty())||(c_rebate.IsEmpty())||(c_paymoney.IsEmpty())||(c_factmoney.IsEmpty()))
return true;
else
return false;
}
void CDlgBookInput2::LimitEdit()
{
m_list.edit.IsNumber = false;
//在修改商品数据,价格,折扣时只允许输入数字
if ((m_list.col ==3)||(m_list.col ==4)||(m_list.col==5))
{
m_list.edit.IsNumber = true;
}
}
void CDlgBookInput2::MoveFocus()
{
m_list.SetFocus();
// m_list.edit.PostMessage(WM_KILLFOCUS,0,0);
if (m_list.col <7)
{
m_list.col = m_list.col+1;
CString tempID,tempname;
tempID = m_list.GetItemText(m_list.row,1);
tempname = m_list.GetItemText(m_list.row,2);
m_list.showedit = true;
if ((tempname.IsEmpty()==false)&&(m_list.col == 1))
m_list.showedit =false;
else if((tempID.IsEmpty()==false)&&(m_list.col == 2))
m_list.showedit =false;
m_list.ShowEdit();
}
else
{
AddNewRow();
}
}
void CDlgBookInput2::OnChangeRebate()
{
CString c_totalmoney,c_rebate,c_paymoney;
float f_totalmoney,f_rebate,f_paymoney;
m_summoney.GetWindowText(c_totalmoney);
m_rebate.GetWindowText(c_rebate);
if(!c_totalmoney.IsEmpty()&&!c_rebate.IsEmpty())
{
f_totalmoney = atof(c_totalmoney);
f_rebate = atof(c_rebate);
f_paymoney = f_totalmoney *f_rebate;
c_paymoney.Format("%10.2f",f_paymoney);
c_paymoney.TrimLeft();
m_paymoney.SetWindowText(c_paymoney);
}
else
{
m_paymoney.SetWindowText("");
}
}
void CDlgBookInput2::OnChangeSummoney()
{
//调用折扣改变时的事件
OnChangeRebate();
}
void CDlgBookInput2::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,1,temp);
//设置书籍名称
m_list.SetItemText(m_list.row,2,m_auxilist.GetItemText(row,1));
//设置默认价格
m_list.SetItemText(m_list.row,3,m_auxilist.GetItemText(row,4));
m_auxilist.ShowWindow(SW_HIDE);
}
//移动编辑框
//MoveFocus();
m_list.col =3;
m_list.ShowEdit();
}
void CDlgBookInput2::OnDblclkProviderlist()
{
CString temp;
int index = m_providerlist.GetCurSel();
if (index != -1)
{
m_providerlist.GetText(index,temp);
if (! temp.IsEmpty())
m_provider.SetWindowText(temp);
m_provider.SetFocus();
m_providerlist.ShowWindow(SW_HIDE);
}
}
void CDlgBookInput2::OnDblclkStoragelist()
{
CString temp;
int index = m_storagelist.GetCurSel();
if (index != -1)
{
m_storagelist.GetText(index,temp);
if (! temp.IsEmpty())
m_list.SetItemText(m_list.row,m_list.col,temp);
m_list.SetFocus();
m_storagelist.ShowWindow(SW_HIDE);
m_list.col+=1;
m_list.ShowEdit();
}
}
void CDlgBookInput2::OnKillfocusList2(NMHDR* pNMHDR, LRESULT* pResult)
{
m_auxilist.ShowWindow(SW_HIDE);
}
void CDlgBookInput2::OnKillfocusProviderlist()
{
m_providerlist.ShowWindow(SW_HIDE);
}
void CDlgBookInput2::OnKillfocusStoragelist()
{
m_storagelist.ShowWindow(SW_HIDE);
}
void CDlgBookInput2::ShowListinfo()
{
if (m_auxilist.IsWindowVisible())
{
m_auxilist.SetFocus();
m_auxilist.SetSelectionMark(1);
}
}
void CDlgBookInput2::ShowListInfo()
{
CRect rect;
m_list.GetSubItemRect(m_list.row,m_list.col,LVIR_BOUNDS,rect);
m_auxilist.MoveWindow(rect.left,rect.bottom+1,300,150);
m_auxilist.ShowWindow(SW_SHOW);
}
void CDlgBookInput2::ShowStorage()
{
if (m_list.col ==0)
if (!m_storagelist.IsWindowVisible())
{
CRect rect;
m_list.GetSubItemRect(m_list.row,m_list.col,LVIR_BOUNDS,rect);
m_storagelist.MoveWindow(rect.left,rect.bottom,100,80,0);
m_storagelist.ShowWindow(SW_SHOW);
m_storagelist.SetFocus();
m_storagelist.SetCurSel(0);
}
}
BOOL CDlgBookInput2::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message ==WM_KEYDOWN)
{
/****************************************************************
说明: 在供应商编辑框获得焦点并按PageDown键,调用DoEditKeyDown方法
****************************************************************/
if ((pMsg->wParam == 34)&&(pMsg->hwnd==m_provider.m_hWnd))
{
DoEditKeyDown(34,IDC_PROVIDER);
}
/****************************************************************
说明: 表格中编辑框获得焦点时,按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_providerlist.m_hWnd)&&(pMsg->wParam == 13))
{
OnDblclkProviderlist();
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->hwnd == m_storagelist.m_hWnd))
{
OnDblclkStoragelist();
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();
ShowStorage();
}
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->hwnd != m_storagelist.m_hWnd)
m_storagelist.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,1);
tempname = m_list.GetItemText(row,2);
if (col==6) //如果单击金额列,不显示编辑框
return true;
m_list.showedit =true;
if ((tempname.IsEmpty()==false)&&(col == 1))
m_list.showedit =false;
else if((tempID.IsEmpty()==false)&&(col == 2))
m_list.showedit =false;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
void CDlgBookInput2::AddOperator()
{
if (InputInfoIsNull())
{
MessageBox("入库信息不能为空","提示",64);
return;
}
if (DetailInfoIsNull())
{
MessageBox("商品信息不能为空","提示",64);
return;
}
try
{
CString sql;
CString c_provider,c_operator,c_rebate,c_sumtotal,c_paymoney,c_factmoney,c_intime;
float f_rebate,f_sumtotal,f_paymoney,f_factmoney;
m_provider.GetWindowText(c_provider);
m_operator.GetWindowText(c_operator);
m_rebate.GetWindowText(c_rebate);
m_summoney.GetWindowText(c_sumtotal);
m_paymoney.GetWindowText(c_paymoney);
m_factmoney.GetWindowText(c_factmoney);
f_rebate = atof(c_rebate);
f_sumtotal = atof(c_sumtotal);
f_paymoney = atof(c_paymoney);
f_factmoney = atof(c_factmoney);
CTime temptime;
m_date.GetTime(temptime);
c_intime = temptime.Format("%Y-%m-%d");
//m_pCon->BeginTrans();
sql.Format(" sp_instore '%s','%s',%10.2f,%10.2f,%10.2f,%10.2f,'%s','%s'",c_provider,c_operator,f_rebate,f_sumtotal,f_paymoney,f_factmoney,c_intime,"temp");
m_pRs->raw_Close();
//记录入库主表信息
m_pRs->Open((_bstr_t)sql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
CString id; //记录返回的票号
id = m_pRs->GetFields()->GetItem("tempID")->Value.bstrVal;
//记录入库明细信息
int rows = m_list.GetItemCount();
for (int c = 0;c<rows;c++)
{
CString c_id,c_storage,c_num,c_price,c_rebate,c_money;
float f_num,f_price,f_rebate,f_money;
c_id = m_list.GetItemText(c,1);
c_storage = m_list.GetItemText(c,0);
c_num = m_list.GetItemText(c,4);
c_price = m_list.GetItemText(c,3);
c_rebate = m_list.GetItemText(c,5);
c_money = m_list.GetItemText(c,6);
f_price = atof(c_price);
f_rebate = atof(c_rebate);
f_money = atof(c_money);
f_num = atof(c_num);
CString detailsql;
m_pRs->raw_Close();
detailsql.Format("insert into tb_instock_sub values ('%s','%s',%f,%f,%f,%f,'%s')",id,c_id,f_price,f_num,f_rebate,f_money,c_storage);
m_pRs->Open((_variant_t)detailsql,m_pCon.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
//修改商品库存
m_pRs1->raw_Close();
detailsql.Format("select * from tb_bookstorage where barcode = '%s' and storagename = '%s'",c_id,c_storage);
m_pRs1->Open((_bstr_t)detailsql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
if (m_pRs1->RecordCount>0) //修改商品库存数量
{
m_pRs1->raw_Close();
detailsql.Format("update tb_bookstorage set booknum = booknum + %f where barcode = '%s' and storagename = '%s'", f_num ,c_id,c_storage);
m_pRs1->Open((_bstr_t)detailsql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
}
else //添加商品库存信息
{
m_pRs1->raw_Close();
detailsql.Format("insert into tb_bookstorage values ( '%s','%s',%f)",c_id,c_storage,f_num );
m_pRs1->Open((_bstr_t)detailsql,m_pCon.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdText);
}
}
//m_pCon->CommitTrans();
InputCancel();
MessageBox("操作成功,票号为: "+id,"提示",64);
}
catch(...)
{
//m_pCon->CommitTrans();
MessageBox("操作失败.","提示",64);
}
}
void CDlgBookInput2::InputCancel()
{
m_rebate.SetWindowText("1.0");
CTime time = CTime::GetCurrentTime();
m_date.SetTime(&time);
m_list.DeleteAllItems();
m_list.InsertItem(1,"");
m_list.SetItemText(0,5,"1.0");
m_provider.SetWindowText("");
m_factmoney.SetWindowText("");
m_summoney.SetWindowText("");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -