PaymodeDlg.cpp
上传用户:sztwq510
上传日期:2013-06-26
资源大小:4045k
文件大小:6k
源码类别:

酒店行业

开发平台:

Java

  1. // PaymodeDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "MyPos.h"
  5. #include "PaymodeDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CPaymodeDlg dialog
  13. extern CMyPosApp theApp;
  14. CPaymodeDlg::CPaymodeDlg(CWnd* pParent /*=NULL*/)
  15. : CDialog(CPaymodeDlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CPaymodeDlg)
  18. // NOTE: the ClassWizard will add member initialization here
  19. //}}AFX_DATA_INIT
  20. }
  21. void CPaymodeDlg::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(CPaymodeDlg)
  25. DDX_Control(pDX, IDC_BUTTON_PADD2, m_oPadd2);
  26. DDX_Control(pDX, IDC_STATIC_SHOWHINT, m_oShowhint);
  27. DDX_Control(pDX, IDC_LIST_PAYMODE, m_oListpaymode);
  28. DDX_Control(pDX, IDC_EDIT_PAYMODE, m_oPaymode);
  29. //}}AFX_DATA_MAP
  30. }
  31. BEGIN_MESSAGE_MAP(CPaymodeDlg, CDialog)
  32. //{{AFX_MSG_MAP(CPaymodeDlg)
  33. ON_BN_CLICKED(IDC_BUTTON_PADD, OnButtonPadd)
  34. ON_BN_CLICKED(IDC_BUTTON_PDEL, OnButtonPdel)
  35. ON_BN_CLICKED(IDC_BUTTON_PADD2, OnButtonPadd2)
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CPaymodeDlg message handlers
  40. void CPaymodeDlg::OnButtonPadd() 
  41. {
  42. m_oShowhint.ShowWindow(SW_SHOW);
  43. m_oPaymode.ShowWindow(SW_SHOW);
  44. m_oPadd2.ShowWindow(SW_SHOW);
  45. }
  46. void CPaymodeDlg::OnButtonPdel() 
  47. {
  48. CString spaymode,sql;
  49. int iOption;
  50. _RecordsetPtr m_pRecordset;
  51. iOption = m_oListpaymode.GetCurSel();
  52. if(iOption>=0)
  53. {
  54. m_oListpaymode.GetText(iOption, spaymode);//得到选中项的文本
  55. if(spaymode=="人民币")
  56. {
  57. MessageBox("不能删除[人民币]付款方式!");
  58. return;
  59. }
  60. sql="Select * from PAYMODE where NAME='"+spaymode+"'";
  61. try
  62. m_pRecordset.CreateInstance("ADODB.Recordset");
  63. m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
  64. if(AfxMessageBox("确定要删除此付款方式吗?",MB_YESNO)==IDYES)
  65. {
  66. m_pRecordset->Delete(adAffectCurrent);///删除当前记录
  67. m_oListpaymode.DeleteString(iOption);
  68. }
  69. else
  70. return;
  71. }
  72. catch(_com_error e)///捕捉异常
  73. {
  74. CString temp;
  75. temp.Format("删除付款方式出错:%s",e.ErrorMessage());
  76. AfxMessageBox(temp);
  77. return;
  78. }
  79. }
  80. }
  81. long CPaymodeDlg::GenNewID()
  82. {
  83. CString sql;
  84. long NewID;
  85. _RecordsetPtr m_pRecordset; //Must define it in function!!!!
  86. sql="SELECT Max(ID) FROM PAYMODE";
  87. try
  88. m_pRecordset.CreateInstance("ADODB.Recordset");
  89. m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
  90. _variant_t vIndex = (long)0;//How to get field value in only 1 record and 1 field condition.
  91. _variant_t vtemp = m_pRecordset->GetCollect(vIndex);
  92. if(vtemp.lVal>0) 
  93. NewID =(long)(m_pRecordset->GetCollect(vIndex))+1;///取得第一个字段的值(MAX ID)加1后放入id变量.
  94. else
  95. NewID=1;
  96. m_pRecordset->Close();
  97. }
  98. catch(_com_error e)///捕捉异常
  99. {
  100. CString stemp;
  101. stemp.Format("获取付款方式ID最大值出错:%s",e.ErrorMessage());
  102. AfxMessageBox(stemp);
  103. }
  104. if(NewID==88)
  105. NewID=89;
  106. return NewID;
  107. }
  108. void CPaymodeDlg::OnButtonPadd2() 
  109. {
  110. CString spaymode,snewid,sql;
  111. long lnewid;
  112. _variant_t RecordsAffected;
  113. lnewid=GenNewID();
  114. snewid.Format("%d",lnewid);
  115. m_oPaymode.GetWindowText(spaymode);
  116. if(spaymode=="")
  117. {
  118. AfxMessageBox("请输入付款方式!");
  119. return;
  120. }
  121. if(bRepeat(spaymode))
  122. {
  123. AfxMessageBox("付款方式重复!请重新输入!");
  124. return;
  125. }
  126. sql="Insert into PAYMODE (ID,NAME) values("+snewid+",'"+spaymode+"')";
  127. try
  128. theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
  129. m_oListpaymode.AddString(spaymode);
  130. UpdateData(FALSE);
  131. }
  132. catch(_com_error e)///捕捉异常
  133. {
  134. CString temp;
  135. temp.Format("增加付款方式出错:%s",e.ErrorMessage());
  136. AfxMessageBox(temp);
  137. return;
  138. }
  139. m_oShowhint.ShowWindow(SW_HIDE);
  140. m_oPaymode.ShowWindow(SW_HIDE);
  141. m_oPadd2.ShowWindow(SW_HIDE);
  142. m_oPaymode.SetWindowText("");
  143. }
  144. void CPaymodeDlg::ReadToListbox()
  145. {
  146. int recordcount;
  147. _RecordsetPtr m_pRecordset;
  148. //Read paymode name from database into listbox.
  149. m_oListpaymode.ResetContent();
  150. CString sql="select * from PAYMODE";
  151. try
  152. {
  153. m_pRecordset.CreateInstance("ADODB.Recordset");
  154. m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
  155. recordcount=m_pRecordset->GetRecordCount();//Get records total.
  156. if(!m_pRecordset->adoEOF)
  157. {
  158. if(recordcount>0)
  159. {
  160. for (int i=0;i < recordcount;i++)//Read user name into listbox.
  161. {
  162. m_oListpaymode.AddString((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("NAME"));
  163. sql=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("NAME");
  164. m_pRecordset->MoveNext();
  165. }
  166. }
  167. }
  168. m_pRecordset->Close();
  169. }
  170. catch(_com_error e)///捕捉异常
  171. {
  172. CString temp;
  173. temp.Format("读取付款方式到列表框出错:%s",e.ErrorMessage());
  174. AfxMessageBox(temp);
  175. }
  176. }
  177. BOOL CPaymodeDlg::OnInitDialog() 
  178. {
  179. CDialog::OnInitDialog();
  180. ReadToListbox();
  181. return TRUE;  // return TRUE unless you set the focus to a control
  182.               // EXCEPTION: OCX Property Pages should return FALSE
  183. }
  184. BOOL CPaymodeDlg::bRepeat(CString strFieldValue)
  185. {
  186. CString sql;
  187. BOOL br;
  188. _RecordsetPtr m_pRecordset; //Must define it in function!!!!
  189. sql="SELECT * FROM PAYMODE WHERE NAME='";
  190. sql=sql+strFieldValue+"'";
  191. try
  192. m_pRecordset.CreateInstance("ADODB.Recordset");
  193. m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
  194. if(m_pRecordset->adoEOF)
  195. br=FALSE;
  196. if(!m_pRecordset->adoEOF)
  197. br=TRUE;
  198. m_pRecordset->Close();
  199. }
  200. catch(_com_error e)///捕捉异常
  201. {
  202. CString stemp;
  203. stemp.Format("查找付款方式名称出错:%s",e.ErrorMessage());
  204. AfxMessageBox(stemp);
  205. }
  206. return br;
  207. }