📄 posdlg.cpp
字号:
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
sname=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("NAME");
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("获取商品名称出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
}
return sname;
}
void CPosDlg::OnButtonSelmateriel()
{
int iOption;
CString sbillid;
iOption = m_oListbill.GetCurSel();
if(iOption<0)
return;
m_oListbill.GetText(iOption, sbillid);//得到选中项的文本
if(bGetBillStatus(sbillid))
return;
CSelectDlg selectdlg;
selectdlg.DoModal();
}
void CPosDlg::ReadToFormlist(CString sbillid)
{
_RecordsetPtr m_pRecordset; //Must define it in function!!!!
CString sql,sname,sno,sqa,ssum;
long rowcount=0;
long lmid;
float fsum;
LV_ITEM lvitem;
//清空list控件的数据
m_oFormlist.DeleteAllItems();
int numline=0;
lvitem.pszText="";
lvitem.mask=LVIF_TEXT;
lvitem.iSubItem=0;
sql="Select * from SALEDETAIL where BILLID='"+sbillid+"'";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);
while(!m_pRecordset->adoEOF)
{
sno=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("ROWNO");
sqa=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("ITEMCOUNT");
lmid=(long)m_pRecordset->GetCollect("MATERIELID");
sname=GetMaterielName(lmid);
fsum=(float)m_pRecordset->GetCollect("ITEMTOTAL");
ssum.Format("%.2f",fsum);
lvitem.iItem=numline;
m_oFormlist.InsertItem(&lvitem);
//读出数据写入到list中
m_oFormlist.SetItemText(numline,0,sno);
m_oFormlist.SetItemText(numline,1,sname);
m_oFormlist.SetItemText(numline,2,sqa);
m_oFormlist.SetItemText(numline,3,ssum);
m_pRecordset->MoveNext();
numline++;
}
RECT rect;
m_oFormlist.GetWindowRect(&rect);
m_oButton.MoveWindow(440,95+numline*15, rect.right/40, rect.bottom/35);
m_oButton.BringWindowToTop();
m_oButton.ShowWindow(SW_SHOW);//从隐藏变为显示
m_pRecordset->Close();///关闭记录集rowcount
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("读取单据商品到列表中出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
}
}
void CPosDlg::OnDblclkListForm(NMHDR* pNMHDR, LRESULT* pResult)
{
CString sno,ssum,sname,scount,sql;
CString sbillid;
float fprice,fsum;
int ncount,nqa,iOption;
iOption = m_oListbill.GetCurSel();
m_oListbill.GetText(iOption, sbillid);//得到选中项的文本
if(bGetBillStatus(sbillid))
return;
//得到当前选中的行
POSITION pos = m_oFormlist.GetFirstSelectedItemPosition();
//如果选中一行
if(pos)
{
int nItem = m_oFormlist.GetNextSelectedItem(pos);
sno=m_oFormlist.GetItemText(nItem,0);
scount=m_oFormlist.GetItemText(nItem,2);
ncount=atoi(scount);
theApp.sqa=scount;
ssum=m_oFormlist.GetItemText(nItem,3);
fsum=atof(ssum);
fprice=fsum;
if(ncount>0)
fprice=fsum/ncount;
//Open the modifyqa dlg.
CModifyqaDlg modifydlg;
modifydlg.DoModal();
nqa=atoi(theApp.sqa);
fsum=nqa*fprice;
ssum.Format("%.2f",fsum);
m_oFormlist.SetItemText(nItem,2,theApp.sqa);
m_oFormlist.SetItemText(nItem,3,ssum);
//Update saledetail.
sql="Update SALEDETAIL set ITEMCOUNT="+theApp.sqa+",ITEMTOTAL="+ssum+" where BILLID='"+sbillid+"' and ROWNO="+sno+"";
try
{ _variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
UpdateData(FALSE);
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("[修改数量]更新商品出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
//Update salebill.
_RecordsetPtr m_pRecordset; //Must define it in function!!!!
float ftotal;
CString stotal;
sql="select Sum(ITEMTOTAL) as SSS from SALEDETAIL where BILLID='"+sbillid+"'";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
ftotal=(float)m_pRecordset->GetCollect("SSS");
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString stemp;
stemp.Format("[修改数量]计算单据金额出错:%s",e.ErrorMessage());
AfxMessageBox(stemp);
return;
}
stotal.Format("%.2f",ftotal);
sql="Update SALEBILL set TOTAL="+stotal+" where ID='"+sbillid+"'";
try
{ _variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("[修改数量]更新总金额出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
m_oTotal.SetWindowText(stotal);
}
*pResult = 0;
}
BOOL CPosDlg::PreTranslateMessage(MSG* pMsg)
{
int i,iState,iOption;
RECT rect;
CString sql,sno,sbillid,stotal;
if(pMsg->message==WM_KEYDOWN)
{
switch(pMsg->wParam)
{
case VK_F1:
OnButtonAddf();
break;
case VK_F2:
OnButtonDelf();
break;
case VK_F3:
OnButtonCallf();
break;
case VK_F4:
OnButtonHidef();
break;
case VK_F5:
OnButtonCheckf();
break;
case VK_F6:
break;
case VK_F7:
break;
case VK_F8:
break;
case VK_F9:
break;
case VK_F10:
OnButtonOff();
break;
}
}
// if(GetFocus()->GetDlgCtrlID()==IDC_LIST_FORM)//针对特定的控件,也可以不用判断
// {
if(pMsg->message==WM_KEYDOWN && pMsg->wParam==VK_DELETE)
{
iOption = m_oListbill.GetCurSel();
m_oListbill.GetText(iOption, sbillid);//得到选中项的文本
if(bGetBillStatus(sbillid))
return FALSE;
int nItemSelected=m_oFormlist.GetSelectedCount();//所选表项数
int nItemCount=m_oFormlist.GetItemCount();//表项总数
if(nItemSelected<1)
return FALSE;
for(i=nItemCount-1;i>=0;i--)
{
iState=m_oFormlist.GetItemState(i,LVIS_SELECTED);
if(iState!=0)
{
sno=m_oFormlist.GetItemText(i,0);
m_oFormlist.DeleteItem(i);
sql="delete * from SALEDETAIL where BILLID='"+sbillid+"' and ROWNO="+sno+"";
try
{ _variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
UpdateData(FALSE);
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("从数据库中删除单据出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
return FALSE;
}
}
}
ReadToFormlist(sbillid);//Refresh formlist.
m_oFormlist.GetWindowRect(&rect);
m_oButton.MoveWindow(440,95+(nItemCount-1)*15, rect.right/40, rect.bottom/35);
m_oButton.BringWindowToTop();
m_oButton.ShowWindow(SW_SHOW);//从隐藏变为显示
stotal=SumItemtotal(sbillid);
m_oTotal.SetWindowText(stotal);
sql="Update SALEBILL set TOTAL="+stotal+" where ID='"+sbillid+"'";
try
{
_variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("[删除商品]更新商品总金额出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
return FALSE;
}
}
// }
return CDialog::PreTranslateMessage(pMsg);
}
void CPosDlg::OnButtonCallf()
{
_RecordsetPtr m_pRecordset; //Must define it in function!!!!
CString sql;
if(!theApp.VerifyPower("CallBill"))
{
AfxMessageBox("没有权限调单!");
return;
}
CCallDlg calldlg;//Create a dialog to enter billid to call.
calldlg.dowhat="imhappy";
calldlg.DoModal();
if(!bGetBillStatus(theApp.scallid))
return;
sql="select * from SALEBILL where ID='"+theApp.scallid+"'";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
if(!m_pRecordset->adoEOF)
{
m_oTableno.SetWindowText((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("TABLENO"));
m_oPeasons.SetWindowText((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("PEOPLES"));
m_oCheck.SetWindowText((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("SALES"));
m_oStatus.SetWindowText((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("STATUS"));
m_oBegintime.SetWindowText((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("BEGINDATE"));
m_oEndtime.SetWindowText((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("ENDDATE"));
float ftotal=(float)m_pRecordset->GetCollect("TOTAL");
CString stotal;
stotal.Format("%.2f",ftotal);
m_oTotal.SetWindowText(stotal);
ftotal=(float)m_pRecordset->GetCollect("ACTTOTAL");
stotal.Format("%.2f",ftotal);
m_oActtotal.SetWindowText(stotal);
ReadToFormlist(theApp.scallid);//Get bill items from database.
m_oListbill.AddString(theApp.scallid);
m_oListbill.SelectString(-1,theApp.scallid);
}
if(m_pRecordset->adoEOF)
{
CString temp="单据 '"+theApp.scallid+"' 不存在!";
AfxMessageBox(temp);
theApp.scallid="";
}
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("从列表读取单据头到编辑框出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
m_oButton.ShowWindow(SW_HIDE);//从显示变为隐藏
}
long CPosDlg::GetRecordCount(CString sql)
{
long lcount;
_RecordsetPtr m_pRecordset; //Must define it in function!!!!
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
lcount=(long)m_pRecordset->GetCollect("XXX");
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString stemp;
stemp.Format("获得记录数出错:%s",e.ErrorMessage());
AfxMessageBox(stemp);
}
return lcount;
}
void CPosDlg::OnButtonDelf()
{
CString sql,sbillid;
int iOption;
_RecordsetPtr m_pRecordset;
if(!theApp.VerifyPower("DelBill"))
{
AfxMessageBox("没有权限删除单据!");
return;
}
iOption = m_oListbill.GetCurSel();
if(iOption==-1)
return;
m_oListbill.GetText(iOption, sbillid);//得到选中项的文本
if(bGetBillStatus(sbillid))
{
AfxMessageBox("不能删除已结帐单据!");
return;
}
if(AfxMessageBox("确定删除此单据吗?",MB_YESNO)==IDYES)
{
sql="Delete * from SALEBILL where ID='"+sbillid+"'";
try
{
_variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("Delete bill id error:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
sql="Delete * from SALEDETAIL where BILLID='"+sbillid+"'";
try
{
_variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("删除单据商品出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
m_oListbill.DeleteString(iOption);
if(m_oListbill.GetCount()>0)
{
if(m_oListbill.GetCount()>iOption)
m_oListbill.SetCurSel(iOption);
if(m_oListbill.GetCount()==iOption)
m_oListbill.SetCurSel(iOption-1);
iOption = m_oListbill.GetCurSel();
m_oListbill.GetText(iOption, sbillid);//Again得到选中项的文本
theApp.scallid=sbillid;//Get current bill id.
ReadBillHead(sbillid);
ReadToFormlist(sbillid);
}
}
else
return;
}
void CPosDlg::OnButtonHidef()
{
int iOption;
CString sbillid;
iOption = m_oListbill.GetCurSel();
if(iOption==-1)
return;
m_oListbill.GetText(iOption, sbillid);//Again得到选中项的文本
if(!bGetBillStatus(sbillid))
{
AfxMessageBox("未结帐单据不能隐藏!");
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -