datebookdlg.cpp
Upload User: syx6615
Upload Date: 2007-06-17
Package Size: 99k
Code Size: 5k
Development Platform:

Visual C++

  1. // datebookdlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ticketbook.h"
  5. #include "datebookdlg.h"
  6. #include "ticketset.h"
  7. #include "ticketpriceset1.h"
  8. #include "ticketbookedset1.h"
  9. #include "trainclassset1.h"
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15. /////////////////////////////////////////////////////////////////////////////
  16. // datebookdlg dialog
  17. datebookdlg::datebookdlg(CWnd* pParent /*=NULL*/)
  18. : CDialog(datebookdlg::IDD, pParent)
  19. {
  20. //{{AFX_DATA_INIT(datebookdlg)
  21. m_stop1 = _T("西安");
  22. m_stoop2 = _T("");
  23. m_day = 0;
  24. m_month = 0;
  25. //}}AFX_DATA_INIT
  26. }
  27. void datebookdlg::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CDialog::DoDataExchange(pDX);
  30. //{{AFX_DATA_MAP(datebookdlg)
  31. DDX_Control(pDX, IDC_LIST1, m_listbox);
  32. DDX_Text(pDX, IDC_stop1, m_stop1);
  33. DDX_Text(pDX, IDC_stop2, m_stoop2);
  34. DDX_Text(pDX, IDC_day, m_day);
  35. DDX_Text(pDX, IDC_month, m_month);
  36. //}}AFX_DATA_MAP
  37. }
  38. BEGIN_MESSAGE_MAP(datebookdlg, CDialog)
  39. //{{AFX_MSG_MAP(datebookdlg)
  40. ON_BN_CLICKED(ID_dabook, Ondabook)
  41. ON_BN_CLICKED(IDC_book, Onbook)
  42. //}}AFX_MSG_MAP
  43. END_MESSAGE_MAP()
  44. /////////////////////////////////////////////////////////////////////////////
  45. // datebookdlg message handlers
  46. CString datebookdlg::n=" ";
  47. CString datebookdlg::sit=" ";
  48. CString datebookdlg::sit1=" ";
  49. CString datebookdlg::p=" ";
  50. int datebookdlg::c=13;
  51. int datebookdlg::s=0;
  52. void datebookdlg::Ondabook() 
  53. {ticketset set;
  54. trainclassset1 trainclass;
  55. ticketbookedset1 booked;
  56. ticketpriceset1 price;
  57. CString p;
  58. this->UpdateData(true);
  59. CString laststop=m_stoop2;
  60. price.Open();
  61. price.MoveFirst();
  62. set.Open();
  63. set.MoveFirst();
  64. trainclass.Open();
  65. trainclass.MoveFirst();
  66. while(!set.IsEOF())
  67. {
  68. if(set.m_stop1==laststop||set.m_stop2==laststop||set.m_stop3==laststop||set.m_stop4==laststop||set.m_stop5==laststop||set.m_stop6==laststop)
  69. { n=set.m_trainNO;
  70. char y[10],m[10],d[10],h[10],M[10];
  71. sprintf(y,"%d",set.m_traintime.GetYear());
  72. sprintf(m,"%d",set.m_traintime.GetMonth());
  73. sprintf(d,"%d",set.m_traintime.GetDay());
  74. sprintf(h,"%d",set.m_traintime.GetHour());
  75. sprintf(M,"%d",set.m_traintime.GetMinute());
  76. if(set.m_traintime.GetMonth()==m_month&&set.m_traintime.GetDay()==m_day&&set.m_ISsell==0)
  77. {  n=set.m_trainNO;
  78.    s=set.m_sitclass;
  79.    sit=set.m_sitNO;
  80. while(!trainclass.IsEOF())
  81. {if(trainclass.m_trainNo==n)
  82. {c=trainclass.m_trainclass;
  83. break;
  84. }else trainclass.MoveNext();
  85. }
  86. if(s==1&&c==0)
  87. {
  88. while(!price.IsEOF())
  89. if(m_stoop2==price.m_column1)
  90. {p=price.m_column7;
  91. sit1="硬座";
  92. break;}
  93. else
  94. price.MoveNext();
  95. if(s==2&&c==0)
  96. {while(!price.IsEOF())
  97.  if(m_stoop2==price.m_column1)
  98.  {p=price.m_column6;
  99.  sit1="硬卧";
  100. break;}
  101.  else
  102.  price.MoveNext();
  103. }
  104. if(s==3&&c==0)
  105. {while(!price.IsEOF())
  106.  if(m_stoop2==price.m_column1)
  107.  {p=price.m_column5;
  108.  sit1="软卧";
  109.  break;}
  110.  else
  111.  price.MoveNext();
  112. }
  113. if(s==1&&c==1)
  114. {while(!price.IsEOF())
  115.  if(m_stoop2==price.m_column1)
  116.  {p=price.m_column4;
  117.  sit1="硬座";
  118.  break;}
  119.  else
  120.  price.MoveNext();
  121. }
  122. if(s==2&&c==1)
  123. {while(!price.IsEOF())
  124.  if(m_stoop2==price.m_column1)
  125.  {p=price.m_column3;
  126.  sit1="硬卧";
  127. break;}
  128.  else
  129.  price.MoveNext();
  130. }
  131. if(s==3&&c==1)
  132. {while(!price.IsEOF())
  133.  if(m_stoop2==price.m_column1)
  134.  {p=price.m_column2;
  135.  sit1="软卧";
  136.  break;}
  137.  else
  138.  price.MoveNext();
  139. }
  140. m_listbox.AddString("    "+n+"        "+y+"-"+m+"-"+d+" "+h+":"+M+"         "+sit1+" "+sit+"            "+p);
  141.  }}
  142. set.MoveNext();
  143. if(set.IsEOF())
  144. return;
  145. }}
  146. BOOL datebookdlg::OnInitDialog() 
  147. {
  148. CDialog::OnInitDialog();
  149. m_listbox.AddString("    车次             发车时间                座号               票价    ");
  150. return TRUE;  
  151. }
  152. void datebookdlg::Onbook() 
  153. {int t;
  154. ticketset set;
  155. ticketbookedset1 set1;
  156. int m=this->m_listbox.GetCurSel();
  157. CString strtmp;
  158. this->m_listbox.GetText(m,strtmp);
  159. CString w;
  160. CString w1;
  161. //取车次
  162. for(int i=0;;i++)
  163. {w1=strtmp.Mid(i,1);
  164. if(w1!=" ")break;
  165. }
  166. t=i;
  167. for(int l=t;;l++)
  168. {w1=strtmp.Mid(l,1);
  169. if(w1==" ")
  170. break;}
  171. for(int h=l+3;;h++)
  172. {w1=strtmp.Mid(h,1);
  173. if(w1==" ")
  174. break;}
  175. //取座位号
  176. w1=strtmp.Mid(t,l);
  177. w=strtmp.Mid(l+37,h);
  178. if(w==" ")
  179. {set.Open(CRecordset::dynaset,_T("select * from traininfo where  trainNo='"+w1+"'and sitclass=0 "));
  180. int tem=set.m_ISsell;
  181. set.Edit();
  182. set.m_ISsell=tem-1;
  183. set.Update();
  184. set.Close();
  185. }
  186. set.Open(CRecordset::dynaset,_T("select * from traininfo where  trainNo='"+w1+"' and sitNO='"+w+"'"));
  187. set.Edit();
  188. set.m_ISsell=1;
  189. set.Update();
  190. ::MessageBox(NULL,"订票成功!","信息",MB_ICONINFORMATION);
  191. //添加已买票记录到表ticketbooked
  192. set1.Open();
  193. set1.AddNew();
  194. set1.m_trainNO=w1;
  195. set1.m_startstop=m_stop1;
  196. set1.m_laststop=m_stoop2;
  197. set1.m_sitNO=w;
  198. set1.Update();
  199. set1.Close();
  200. }