飞机票定票和退票系统Dlg.cpp
上传用户:lilang
上传日期:2013-03-16
资源大小:35k
文件大小:12k
源码类别:

交通/航空行业

开发平台:

Visual C++

  1. // 飞机票定票和退票系统Dlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "飞机票定票和退票系统.h"
  5. #include "飞机票定票和退票系统Dlg.h"
  6. #include "string.h"
  7. #include "stdlib.h"
  8. #include "compare.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #undef THIS_FILE
  12. static char THIS_FILE[] = __FILE__;
  13. #endif
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAboutDlg dialog used for App About
  16. class CAboutDlg : public CDialog
  17. {
  18. public:
  19. CAboutDlg();
  20. // Dialog Data
  21. //{{AFX_DATA(CAboutDlg)
  22. enum { IDD = IDD_ABOUTBOX };
  23. //}}AFX_DATA
  24. // ClassWizard generated virtual function overrides
  25. //{{AFX_VIRTUAL(CAboutDlg)
  26. protected:
  27. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  28. //}}AFX_VIRTUAL
  29. // Implementation
  30. protected:
  31. //{{AFX_MSG(CAboutDlg)
  32. //}}AFX_MSG
  33. DECLARE_MESSAGE_MAP()
  34. };
  35. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  36. {
  37. //{{AFX_DATA_INIT(CAboutDlg)
  38. //}}AFX_DATA_INIT
  39. }
  40. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  41. {
  42. CDialog::DoDataExchange(pDX);
  43. //{{AFX_DATA_MAP(CAboutDlg)
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  47. //{{AFX_MSG_MAP(CAboutDlg)
  48. // No message handlers
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CMyDlg dialog
  53. CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
  54. : CDialog(CMyDlg::IDD, pParent)
  55. {
  56. //{{AFX_DATA_INIT(CMyDlg)
  57. m_remain = _T("");
  58. m_passenger = _T("");
  59. m_pt = _T("");
  60. m_destinenum = _T("");
  61. m_ticketnum = 0;
  62. //}}AFX_DATA_INIT
  63. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  64. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  65. }
  66. void CMyDlg::DoDataExchange(CDataExchange* pDX)
  67. {
  68. CDialog::DoDataExchange(pDX);
  69. //{{AFX_DATA_MAP(CMyDlg)
  70. DDX_Control(pDX, IDC_COMBO_fly, m_fly);
  71. DDX_Control(pDX, IDC_EDIT_information, m_information);
  72. DDX_Control(pDX, IDC_EDIT_p_information, m_p_information);
  73. DDX_Control(pDX, IDC_EDIT_name, m_name);
  74. DDX_Control(pDX, IDC_EDIT_destination, m_destination);
  75. DDX_Text(pDX, IDC_EDIT_remain, m_remain);
  76. DDX_Text(pDX, IDC_EDIT_passenger, m_passenger);
  77. DDX_Text(pDX, IDC_EDIT_pt, m_pt);
  78. DDX_Text(pDX, IDC_EDIT__destinenum, m_destinenum);
  79. DDX_Text(pDX, IDC_EDIT_ticketnum, m_ticketnum);
  80. DDV_MinMaxInt(pDX, m_ticketnum, 0, 100);
  81. //}}AFX_DATA_MAP
  82. }
  83. BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
  84. //{{AFX_MSG_MAP(CMyDlg)
  85. ON_WM_SYSCOMMAND()
  86. ON_WM_PAINT()
  87. ON_WM_QUERYDRAGICON()
  88. ON_BN_CLICKED(IDC_BUTTON_OK, OnButtonOk)
  89. ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnButtonCancel)
  90. ON_CBN_SELCHANGE(IDC_COMBO_fly, OnSelchangeCOMBOfly)
  91. ON_EN_CHANGE(IDC_EDIT_ticketnum, OnChangeEDITticketnum)
  92. //}}AFX_MSG_MAP
  93. END_MESSAGE_MAP()
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CMyDlg message handlers
  96. BOOL CMyDlg::OnInitDialog()
  97. {
  98. CDialog::OnInitDialog();
  99. // Add "About..." menu item to system menu.
  100. // IDM_ABOUTBOX must be in the system command range.
  101. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  102. ASSERT(IDM_ABOUTBOX < 0xF000);
  103. CMenu* pSysMenu = GetSystemMenu(FALSE);
  104. if (pSysMenu != NULL)
  105. {
  106. CString strAboutMenu;
  107. strAboutMenu.LoadString(IDS_ABOUTBOX);
  108. if (!strAboutMenu.IsEmpty())
  109. {
  110. pSysMenu->AppendMenu(MF_SEPARATOR);
  111. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  112. }
  113. }
  114. // Set the icon for this dialog.  The framework does this automatically
  115. //  when the application's main window is not a dialog
  116. SetIcon(m_hIcon, TRUE); // Set big icon
  117. SetIcon(m_hIcon, FALSE); // Set small icon
  118. // TODO: Add extra initialization here
  119. totlep=0;
  120. destinenum=0;
  121. m_ticketnum=1;
  122. totle[0]=100;totle[1]=100;totle[2]=100;
  123. remain[0]=100;remain[1]=100;remain[2]=100;
  124. now[0]=0;now[1]=0;now[2]=0;
  125. m_fly.AddString("CF_101");
  126. m_fly.AddString("CF_108");
  127. m_fly.AddString("CF_134");
  128. m_fly.SelectString(-1,"CF_101");
  129. fly=0;
  130. m_remain.Format("%d",remain[0]);
  131. m_passenger.Format("%d",now[1]);
  132. m_pt.Format("%d",totlep);
  133. m_destinenum.Format("%d",destinenum);
  134. m_destination.SetSel(0,-1);
  135. m_destination.ReplaceSel("武汉");
  136. UpdateData(0);
  137. return TRUE;  // return TRUE  unless you set the focus to a control
  138. }
  139. void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
  140. {
  141. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  142. {
  143. CAboutDlg dlgAbout;
  144. dlgAbout.DoModal();
  145. }
  146. else
  147. {
  148. CDialog::OnSysCommand(nID, lParam);
  149. }
  150. }
  151. // If you add a minimize button to your dialog, you will need the code below
  152. //  to draw the icon.  For MFC applications using the document/view model,
  153. //  this is automatically done for you by the framework.
  154. void CMyDlg::OnPaint() 
  155. {
  156. if (IsIconic())
  157. {
  158. CPaintDC dc(this); // device context for painting
  159. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  160. // Center icon in client rectangle
  161. int cxIcon = GetSystemMetrics(SM_CXICON);
  162. int cyIcon = GetSystemMetrics(SM_CYICON);
  163. CRect rect;
  164. GetClientRect(&rect);
  165. int x = (rect.Width() - cxIcon + 1) / 2;
  166. int y = (rect.Height() - cyIcon + 1) / 2;
  167. // Draw the icon
  168. dc.DrawIcon(x, y, m_hIcon);
  169. }
  170. else
  171. {
  172. CDialog::OnPaint();
  173. }
  174. }
  175. // The system calls this to obtain the cursor to display while the user drags
  176. //  the minimized window.
  177. HCURSOR CMyDlg::OnQueryDragIcon()
  178. {
  179. return (HCURSOR) m_hIcon;
  180. }
  181. void CMyDlg::OnCancel() 
  182. {
  183. // TODO: Add extra cleanup here
  184. CDialog::OnCancel();
  185. }
  186. void CMyDlg::OnButtonOk() 
  187. {
  188. // TODO: Add your control notification handler code here
  189. m_destination.GetWindowText(p[destinenum].destination,20);
  190. m_name.GetWindowText(p[destinenum].name,20);
  191. m_fly.GetWindowText(p[destinenum].fly,20);
  192. p[destinenum].ticketnum=m_ticketnum;
  193. int RADIO;
  194. RADIO=GetCheckedRadioButton(IDC_RADIO_man,IDC_RADIO_woman);
  195. p[destinenum].sex=RADIO;
  196. if(remain[fly]>=m_ticketnum&&m_name.GetWindowText(p[totlep].name,20)&&m_destination.GetWindowText(p[totlep].destination,20)&&(RADIO==IDC_RADIO_man||RADIO==IDC_RADIO_woman))
  197. {
  198. totlep+=m_ticketnum;
  199. destinenum++;
  200. now[fly]+=m_ticketnum;
  201. remain[fly]-=m_ticketnum;
  202. m_passenger.Format("%d",(now[fly]));
  203. m_remain.Format("%d",(remain[fly]));
  204. m_pt.Format("%d",totlep);
  205. m_destinenum.Format("%d",destinenum);
  206. //m_p_information.SetSel(0,-1);
  207. //m_p_information.ReplaceSel(p[now].destination);
  208. //m_p_information.ReplaceSel("   ");
  209. //if (RADIO==IDC_RADIO_man) m_p_information.ReplaceSel("男   ");
  210. //else if (RADIO==IDC_RADIO_woman) m_p_information.ReplaceSel("女   ");
  211. //m_p_information.ReplaceSel(p[now].name);
  212. m_information.SetSel(0,-1);
  213. m_information.ReplaceSel("定票成功");
  214. UpdateData(0);
  215. }
  216. else if (remain[fly]<m_ticketnum)
  217. {
  218. m_information.SetSel(0,-1);
  219. if (fly==1)
  220. {
  221. m_information.ReplaceSel("当前航线的票数已不能满足,定票失败");
  222. }
  223. else if (fly==0)
  224. {
  225. if (remain[2]>=m_ticketnum)
  226. m_information.ReplaceSel("当前航线的票数已不能满足,订票失败CF_134次航班能满足您的要求,请订CF_134次航班");
  227. else m_information.ReplaceSel("当前航线的票数已不能满足,定票失败");
  228. }
  229. else if (fly==2)
  230. {
  231. if (remain[0]>=m_ticketnum)
  232. m_information.ReplaceSel("当前航线的票数已不能满足,订票失败CF_101次航班能满足您的要求,请订CF_101次航班");
  233. else m_information.ReplaceSel("当前航线的票数已不能满足,定票失败");
  234. }
  235. UpdateData(0);
  236. }
  237. else
  238. {
  239. m_information.SetSel(0,-1);
  240. m_information.ReplaceSel("乘客信息填写不完整,定票失败");
  241. UpdateData(0);
  242. }
  243. if (now[fly]>100)
  244. {
  245. m_information.SetSel(0,-1);
  246. m_information.ReplaceSel("机票已售完,请选择其他航线");
  247. now[fly]=100;
  248. remain[fly]=100;
  249. }
  250. m_p_information.SetSel(0,-1);
  251. m_p_information.ReplaceSel("");
  252. qsort( (void *)p,destinenum,sizeof(p[1]),compare);
  253. for (int i=0;i<destinenum;i++)
  254. {
  255. m_p_information.SetSel(-1,0);
  256. m_p_information.ReplaceSel(p[i].name);
  257. m_p_information.ReplaceSel("   ");
  258. if (p[i].sex==IDC_RADIO_man) m_p_information.ReplaceSel("男   ");
  259. else if (p[i].sex==IDC_RADIO_woman) m_p_information.ReplaceSel("女   ");
  260. m_p_information.ReplaceSel(p[i].destination);
  261. m_p_information.ReplaceSel("   ");
  262. m_p_information.ReplaceSel(p[i].fly);
  263. m_p_information.ReplaceSel("   ");
  264. char temp[10];
  265. _gcvt(p[i].ticketnum,10,temp);
  266. m_p_information.ReplaceSel(temp);
  267. m_p_information.ReplaceSel("n");
  268. //m_p_information.FmtLines(NULL);
  269. }
  270. UpdateData(0);
  271. }
  272. void CMyDlg::OnButtonCancel() 
  273. {
  274. // TODO: Add your control notification handler code here
  275. char temp_name[20];
  276. int temp_sex;
  277. char temp_destination[20];
  278. m_destination.GetWindowText(temp_destination,20);
  279. m_name.GetWindowText(temp_name,20);
  280. temp_sex=GetCheckedRadioButton(IDC_RADIO_man,IDC_RADIO_woman);
  281. if (now[fly]==0)
  282. {
  283. m_information.SetSel(0,-1);
  284. m_information.ReplaceSel("当前无人定票,退票失败");
  285. }
  286. else
  287. {
  288. for (int i=0;i<destinenum;i++)
  289. {
  290. if (strcmp(p[i].destination,temp_destination)==0)
  291. {
  292. if (strcmp(p[i].name,temp_name)==0)
  293. {
  294. if (p[i].sex==temp_sex&&p[i].ticketnum==m_ticketnum)
  295. {
  296. //add your code here
  297. for (int j=i;j<destinenum-1;j++)
  298. {
  299. p[j]=p[j+1];
  300. }
  301. now[fly]-=m_ticketnum;
  302. remain[fly]+=m_ticketnum;
  303. totlep-=m_ticketnum;
  304. destinenum--;
  305. m_passenger.Format("%d",(now[fly]));
  306. m_remain.Format("%d",(remain[fly]));
  307. m_destinenum.Format("%d",destinenum);
  308. m_pt.Format("%d",totlep);
  309. m_information.SetSel(0,-1);
  310. m_information.ReplaceSel("退票成功");
  311. break;
  312. }
  313. else if(p[i].sex!=temp_sex)
  314. {
  315. m_information.SetSel(0,-1);
  316. m_information.ReplaceSel("查无此记录,退票失败");
  317. }
  318. else if (p[i].ticketnum>m_ticketnum)
  319. {
  320. now[fly]-=m_ticketnum;
  321. remain[fly]+=m_ticketnum;
  322. totlep-=m_ticketnum;
  323. p[i].ticketnum-=m_ticketnum;
  324. m_passenger.Format("%d",(now[fly]));
  325. m_remain.Format("%d",(remain[fly]));
  326. m_pt.Format("%d",totlep);
  327. m_information.SetSel(0,-1);
  328. m_information.ReplaceSel("退票成功");
  329. }
  330. else if (p[i].ticketnum<m_ticketnum)
  331. {
  332. m_information.SetSel(0,-1);
  333. m_information.ReplaceSel("此乘客所定票数少于所输入的票数,退票失败");
  334. }
  335. }
  336. else
  337. {
  338. m_information.SetSel(0,-1);
  339. m_information.ReplaceSel("查无此记录,退票失败");
  340. }
  341. }
  342. else
  343. {
  344. m_information.SetSel(0,-1);
  345. m_information.ReplaceSel("查无此记录,退票失败");
  346. }
  347. }
  348. m_p_information.SetSel(0,-1);
  349. m_p_information.ReplaceSel("");
  350. for (int k=0;k<destinenum;k++)
  351. {
  352. m_p_information.SetSel(-1,0);
  353. m_p_information.ReplaceSel(p[k].name);
  354. m_p_information.ReplaceSel("   ");
  355. if (p[k].sex==IDC_RADIO_man) m_p_information.ReplaceSel("男   ");
  356. else if (p[k].sex==IDC_RADIO_woman) m_p_information.ReplaceSel("女   ");
  357. m_p_information.ReplaceSel(p[k].destination);
  358. m_p_information.ReplaceSel("   ");
  359. m_p_information.ReplaceSel(p[k].fly);
  360. m_p_information.ReplaceSel("   ");
  361. char temp[10];
  362. _gcvt(p[k].ticketnum,10,temp);
  363. m_p_information.ReplaceSel(temp);
  364. m_p_information.ReplaceSel("n");
  365. }
  366. UpdateData(0);
  367. }
  368. }
  369. void CMyDlg::OnSelchangeCOMBOfly() 
  370. {
  371. // TODO: Add your control notification handler code here
  372. char tempstring[20];
  373. m_fly.GetWindowText(tempstring,20);
  374. if (strcmp(tempstring,"CF_101")==0) {fly=0;m_destination.SetSel(0,-1);m_destination.ReplaceSel("武汉");}
  375. else if (strcmp(tempstring,"CF_108")==0) {fly=1;m_destination.SetSel(0,-1);m_destination.ReplaceSel("长沙");}
  376. else if (strcmp(tempstring,"CF_134")==0) {fly=2;m_destination.SetSel(0,-1);m_destination.ReplaceSel("武汉");}
  377. m_passenger.Format("%d",(now[fly]));
  378. m_remain.Format("%d",(remain[fly]));
  379. UpdateData(0);
  380. }
  381. void CMyDlg::OnChangeEDITticketnum() 
  382. {
  383. // TODO: If this is a RICHEDIT control, the control will not
  384. // send this notification unless you override the CDialog::OnInitDialog()
  385. // function and call CRichEditCtrl().SetEventMask()
  386. // with the ENM_CHANGE flag ORed into the mask.
  387. // TODO: Add your control notification handler code here
  388. char temp[20];
  389. (GetDlgItem(IDC_EDIT_ticketnum))->GetWindowText(temp,20);
  390. m_ticketnum=(int)atof((LPCTSTR)temp);
  391. }