RoomDestine.cpp
上传用户:czfddz
上传日期:2013-03-20
资源大小:1517k
文件大小:10k
源码类别:

酒店行业

开发平台:

C/C++

  1. // RoomDestine.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "qq.h"
  5. #include "RoomDestine.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CRoomDestine dialog
  13. CRoomDestine::CRoomDestine(CWnd* pParent /*=NULL*/)
  14. : CDialog(CRoomDestine::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CRoomDestine)
  17. m_DestineCerityType = 0;
  18. m_SexType = 0;
  19. //}}AFX_DATA_INIT
  20. nDestineRoomSum=0;
  21. }
  22. void CRoomDestine::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CRoomDestine)
  26. DDX_Control(pDX, IDC_ROOMDESTINE_BILLCODE, m_BillCode);
  27. DDX_Control(pDX, IDC_ROOMDES_CERTIFYCODE, CerifyCode);
  28. DDX_Control(pDX, IDC_ROOMNUM, m_DestineRoomSum);
  29. DDX_Control(pDX, IDC_ROOMDESTINE_TYPE, m_RoomType);
  30. DDX_Control(pDX, IDC_ROOMDESTINE_TIME, m_DestineTime);
  31. DDX_Control(pDX, IDC_ROOMDESTINE_ROOMCODE, m_RoomCodeList);
  32. DDX_Control(pDX, IDC_ROOMDESTINE_PRICE, m_RoomPrice);
  33. DDX_Control(pDX, IDC_ROOMDESTINE_NAME, m_DestinerName);
  34. DDX_Control(pDX, IDC_ROOMDESTINE_MONEY, m_DestineMoney);
  35. DDX_Control(pDX, IDC_ROOMDESTINE_DESTINEBILL, m_DestineBill);
  36. DDX_Radio(pDX, IDC_RADIO1, m_DestineCerityType);
  37. DDX_Radio(pDX, IDC_RADIO4, m_SexType);
  38. //}}AFX_DATA_MAP
  39. }
  40. BEGIN_MESSAGE_MAP(CRoomDestine, CDialog)
  41. //{{AFX_MSG_MAP(CRoomDestine)
  42. ON_CBN_SELCHANGE(IDC_ROOMDESTINE_TYPE, OnSelchangeRoomdestineType)
  43. ON_BN_CLICKED(IDC_ADD, OnAdd)
  44. ON_BN_CLICKED(IDC_DELETE, OnDelete)
  45. ON_BN_CLICKED(IDC_RADIO1, OnRadio)
  46. ON_BN_CLICKED(IDC_RADIO2, OnRadio)
  47. ON_BN_CLICKED(IDC_RADIO3, OnRadio)
  48. ON_BN_CLICKED(IDC_RADIO4, OnRadio)
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CRoomDestine message handlers
  53. BOOL CRoomDestine::OnInitDialog() 
  54. {
  55. CDialog::OnInitDialog();
  56. // TODO: Add extra initialization here
  57. m_RoomType.SetWindowText("标准单人房");
  58. m_RoomType.AddString("标准单人房");//index==0
  59. m_RoomType.AddString("标准双人房");
  60. m_RoomType.AddString("贵族单人房");
  61. m_RoomType.AddString("贵族双人房");//index==3
  62. //产生帐单号码
  63. CCreateBillCode billcode;
  64. m_BillCode.SetWindowText(billcode.GenereBillCode());
  65. //////////////////////////////////////////////////////////////////////////
  66. CTime time=CTime::GetCurrentTime();//构造时间对象
  67.     CTime tm(time);
  68. int year,month,day,hour,minute,second;
  69.     year=tm.GetYear();
  70.     month=tm.GetMonth();
  71. day=tm.GetDay();
  72. hour=tm.GetHour();
  73. minute=tm.GetMinute();
  74. second=tm.GetSecond();
  75. CString strYear,strMonth,strDay,strHour,strMinute,strSecond;
  76. strYear.Format("%d",year);
  77. strMonth.Format("%d",month);
  78. strDay.Format("%d",day);
  79. strHour.Format("%d",hour);
  80. strMinute.Format("%d",minute);
  81. strSecond.Format("%d",second);
  82. CString strShowText;
  83. strShowText=strYear+"-"+strMonth+"-"+strDay;
  84.     strShowText=strShowText+" "+strHour+":"+strMinute+":"+strSecond;
  85.     m_DestineTime.SetWindowText(strShowText);
  86. //设置预定额为0
  87. m_DestineMoney.SetWindowText("0");
  88. return TRUE;  // return TRUE unless you set the focus to a control
  89.               // EXCEPTION: OCX Property Pages should return FALSE
  90. }
  91. void CRoomDestine::OnSelchangeRoomdestineType() 
  92. {
  93. // TODO: Add your control notification handler code here
  94. m_RoomCodeList.ResetContent();//清除所有的项目
  95. CString strComboText;//combobox中的文本
  96.     m_RoomType.GetLBText(m_RoomType.GetCurSel(),strComboText);//获得选择的文本
  97.     /////////////////////////////////////////////////////////////////
  98.     // 进行数据库的查询
  99.     //roomprice fill
  100. CString SQLstr;
  101. SQLstr="SELECT * FROM RoomInfo where RoomType='" ;
  102.     SQLstr=SQLstr+strComboText;
  103.     SQLstr=SQLstr+"'";
  104. if(!m_RoomInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr))
  105. {//查询数据库得到数据集合
  106. AfxMessageBox("打开数据库失败!");
  107. return ;
  108. }
  109. CString str;
  110. str.Format("%5.00f",m_RoomInfoSet.m_Price);
  111. m_RoomPrice.SetWindowText(str);
  112. m_RoomInfoSet.Close(); //关闭数据库 
  113. /////////////////////////////////////////////////////////////
  114. if(!m_RoomInfoSet.Open())
  115. {
  116. MessageBox("打开数据库失败!","数据库错误",MB_OK);
  117. return;
  118. }
  119. m_RoomInfoSet.MoveFirst();
  120. while(!m_RoomInfoSet.IsEOF())
  121. {
  122. if(m_RoomInfoSet.m_RoomType==strComboText)
  123. {
  124. if(m_RoomInfoSet.m_RoomStatus=="空")
  125. {
  126.                 m_RoomCodeList.AddString(m_RoomInfoSet.m_RoomCode);
  127. }
  128. }
  129. m_RoomInfoSet.MoveNext();
  130. }
  131. m_RoomInfoSet.Close();
  132. ////////////////////////////////////////////////////////
  133. /////////////////////////////////////////////////////////////////////
  134. }
  135. void CRoomDestine::OnAdd() 
  136. {
  137. // TODO: Add your control notification handler code here
  138. CString strRoomCode;
  139. if(m_RoomCodeList.GetCount()==0)
  140. {
  141. return;
  142. }
  143. else
  144. {
  145. if(m_RoomCodeList.GetCurSel()!=-1)
  146. {
  147.             m_RoomCodeList.GetText(m_RoomCodeList.GetCurSel(),strRoomCode);
  148. }
  149. }
  150. if(m_RoomCodeList.GetCurSel()==-1)
  151. {
  152. MessageBox("你至少要选择一项!","选择项为空",MB_OK);
  153. return;
  154. }
  155.     if(m_RoomCodeList.GetCurSel()!=-1)
  156. {
  157. int n=m_DestineBill.GetCount();
  158. CString strTemp=" ";
  159. bool bSame=false;
  160. if(n!=0)
  161. for(int i=0;i<n;i++)
  162. {
  163. m_DestineBill.GetText(i,strTemp);
  164. char* s=strTemp.GetBuffer(strTemp.GetLength());//there is a bug!
  165. char* str=strtok(s," ");
  166. str=strtok(NULL," ");
  167. strTemp=str;
  168. if(strTemp==strRoomCode)
  169. {
  170. MessageBox("你已经添加了这个房间!","选择错误",MB_OK);
  171. bSame=true;
  172. return;
  173. }
  174. }
  175. }
  176. CString BillinfoText;
  177. if(!bSame)
  178. {
  179. m_RoomType.GetWindowText(BillinfoText);
  180. BillinfoText=BillinfoText+" "+strRoomCode;
  181. m_DestineBill.AddString(BillinfoText);
  182. nDestineRoomSum++;
  183. CString strSum;
  184. strSum.Format("%d",nDestineRoomSum);
  185. m_DestineRoomSum.SetWindowText(strSum);
  186. }
  187. }
  188. ////////////////////////////////////////////////////////////////////
  189. }
  190. void CRoomDestine::OnDelete() 
  191. {
  192. // TODO: Add your control notification handler code here
  193. int nCurSel=m_DestineBill.GetCurSel();
  194. if(nCurSel==-1)
  195. {
  196. MessageBox("请选择一个要删除的房间号","数据为空错误",MB_OK);
  197. return;
  198. }
  199. m_DestineBill.DeleteString(nCurSel);
  200.     /////////更新显示
  201. nDestineRoomSum--;
  202. CString strSum;
  203. strSum.Format("%d",nDestineRoomSum);
  204. m_DestineRoomSum.SetWindowText(strSum);
  205. }
  206. void CRoomDestine::OnOK() 
  207. {//  [7/1/2003-11:21]
  208. // TODO: Add extra validation here
  209. /*
  210.  * 将下面的一些代码放在OnOK()函数中是为了放在写入到数据库中时,证件类型或者
  211.     性别为空的情况的发生
  212. 若在OnRaido()函数中写入这些代码,如果使用者没有点击Radio按钮的话,就不会进行
  213. 赋值的操作,从而导致写入到数据库中的为空
  214.  */
  215. UpdateData(TRUE);//状态更新
  216. if(m_DestineCerityType==0)
  217. {
  218. m_CerityTypeName="身份证";
  219. }
  220. if(m_DestineCerityType==1)
  221. {
  222. m_CerityTypeName="军人证";
  223. }
  224. if(m_DestineCerityType==2)
  225. {
  226. m_CerityTypeName="学生证";
  227. }
  228. if(m_SexType==0)
  229. {
  230. m_DestinerSexType="男";
  231. }
  232. if(m_SexType==1)
  233. {
  234. m_DestinerSexType="女";
  235. }
  236. /*
  237.  * 先进行检查,看是否有些项目为空
  238.  */
  239. CString strDestinerName,strDestinerMoney,strCerityCode,strBillCode,strDestinetime;
  240. m_DestinerName.GetWindowText(strDestinerName);
  241. m_DestineMoney.GetWindowText(strDestinerMoney);
  242.     CerifyCode.GetWindowText(strCerityCode);
  243.     m_BillCode.GetWindowText(strBillCode);
  244.     m_DestineTime.GetWindowText(strDestinetime);
  245. if(atof(strDestinerMoney)<0)
  246. {
  247. MessageBox("必须要缴纳预定金","预定金错误",MB_OK);
  248. return;
  249. }
  250. if(m_DestineBill.GetCount()==0)
  251. {
  252. MessageBox("帐单为空","错误",MB_OK);
  253. return;
  254. }
  255. if(strDestinerName==""||strDestinerMoney==""||strCerityCode=="")
  256. {
  257. MessageBox("请填写完整","为空错误",MB_OK);
  258. return;
  259. }
  260. ////保存数据到数据库中
  261. if(!m_DestineRoomSet.Open())
  262. {
  263. MessageBox("数据库打开失败!","数据库错误",MB_OK);
  264. return;
  265. }
  266. bool bHadSameRecordSet=false;//是否已经有了这条记录
  267. m_DestineRoomSet.MoveFirst();
  268. while (!m_DestineRoomSet.IsEOF())
  269. {
  270. if(strCerityCode==m_DestineRoomSet.m_CeritifyCode)
  271. {
  272. bHadSameRecordSet=true;
  273. break;
  274. }
  275. m_DestineRoomSet.MoveNext();
  276. }
  277.     m_DestineRoomSet.Close();//数据库关闭
  278. if(bHadSameRecordSet)
  279. {
  280. MessageBox("该客人已经预定了房间!","错误",MB_OK);
  281. return;
  282. }
  283. else
  284. {
  285. //写入到数据库的表中
  286. if(!m_DestineRoomSet.Open())
  287. {
  288. MessageBox("数据库打开失败!","数据库错误",MB_OK);
  289. return;
  290. }
  291. m_DestineRoomSet.AddNew();//添加一条新的记录
  292.         m_DestineRoomSet.m_BillCode=strBillCode;//帐单号码
  293. m_DestineRoomSet.m_CeritifyCode=strCerityCode;
  294.         m_DestineRoomSet.m_Certificate=m_CerityTypeName;
  295. m_DestineRoomSet.m_DestineMoney=strDestinerMoney;
  296. m_DestineRoomSet.m_DestinerName=strDestinerName;
  297. m_DestineRoomSet.m_DestinerSex=m_DestinerSexType;
  298. m_DestineRoomSet.m_DestineTime=strDestinetime;
  299. //写入预定了哪些房间
  300. CString strRoomCodes,strTemp;
  301. for(int i=0;i<m_DestineBill.GetCount();i++)
  302. {
  303. m_DestineBill.GetText(i,strTemp);
  304. char* s=strTemp.GetBuffer(strTemp.GetLength());//there is a bug!
  305. char* str=strtok(s," ");
  306. str=strtok(NULL," ");
  307. strRoomCodes=strRoomCodes+str+",";
  308. }
  309. m_DestineRoomSet.m_DestineRoomCode=strRoomCodes;
  310. m_DestineRoomSet.Update();//更新记录
  311. m_DestineRoomSet.Close();//关闭数据库,写入了一条新的记录
  312. //改写CRoomInfoSet表中的信息
  313. //将预定的房间的状态改为“预定”
  314. for(i=0;i<m_DestineBill.GetCount();i++)
  315. {
  316. CString strRoomCode;
  317. m_DestineBill.GetText(i,strTemp);
  318. char* s=strTemp.GetBuffer(strTemp.GetLength());//there is a bug!
  319. char* str=strtok(s," ");
  320. str=strtok(NULL," ");
  321.             strRoomCode=str;
  322.             if(!m_RoomInfoSet.Open())
  323. {
  324.     MessageBox("数据库打开失败!","数据库错误",MB_OK);
  325.     return;
  326. }
  327.     m_RoomInfoSet.MoveFirst();
  328.     while (!m_RoomInfoSet.IsEOF())
  329. {
  330.     if(strRoomCode==m_RoomInfoSet.m_RoomCode)
  331. {
  332. m_RoomInfoSet.Edit();
  333. m_RoomInfoSet.m_RoomStatus="预定";
  334. m_RoomInfoSet.Update();
  335. }
  336. m_RoomInfoSet.MoveNext();
  337. }
  338. m_RoomInfoSet.Close();
  339. }
  340. }
  341. CDialog::OnOK();
  342. }
  343. void CRoomDestine::OnRadio() 
  344. {
  345. // TODO: Add your control notification handler code here
  346. }