飞机票定票和退票系统Dlg.cpp
上传用户:lilang
上传日期:2013-03-16
资源大小:35k
文件大小:12k
- // 飞机票定票和退票系统Dlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "飞机票定票和退票系统.h"
- #include "飞机票定票和退票系统Dlg.h"
- #include "string.h"
- #include "stdlib.h"
- #include "compare.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyDlg dialog
- CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CMyDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CMyDlg)
- m_remain = _T("");
- m_passenger = _T("");
- m_pt = _T("");
- m_destinenum = _T("");
- m_ticketnum = 0;
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CMyDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMyDlg)
- DDX_Control(pDX, IDC_COMBO_fly, m_fly);
- DDX_Control(pDX, IDC_EDIT_information, m_information);
- DDX_Control(pDX, IDC_EDIT_p_information, m_p_information);
- DDX_Control(pDX, IDC_EDIT_name, m_name);
- DDX_Control(pDX, IDC_EDIT_destination, m_destination);
- DDX_Text(pDX, IDC_EDIT_remain, m_remain);
- DDX_Text(pDX, IDC_EDIT_passenger, m_passenger);
- DDX_Text(pDX, IDC_EDIT_pt, m_pt);
- DDX_Text(pDX, IDC_EDIT__destinenum, m_destinenum);
- DDX_Text(pDX, IDC_EDIT_ticketnum, m_ticketnum);
- DDV_MinMaxInt(pDX, m_ticketnum, 0, 100);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
- //{{AFX_MSG_MAP(CMyDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_BUTTON_OK, OnButtonOk)
- ON_BN_CLICKED(IDC_BUTTON_CANCEL, OnButtonCancel)
- ON_CBN_SELCHANGE(IDC_COMBO_fly, OnSelchangeCOMBOfly)
- ON_EN_CHANGE(IDC_EDIT_ticketnum, OnChangeEDITticketnum)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMyDlg message handlers
- BOOL CMyDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // Add "About..." menu item to system menu.
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // TODO: Add extra initialization here
- totlep=0;
- destinenum=0;
- m_ticketnum=1;
- totle[0]=100;totle[1]=100;totle[2]=100;
- remain[0]=100;remain[1]=100;remain[2]=100;
- now[0]=0;now[1]=0;now[2]=0;
- m_fly.AddString("CF_101");
- m_fly.AddString("CF_108");
- m_fly.AddString("CF_134");
- m_fly.SelectString(-1,"CF_101");
- fly=0;
- m_remain.Format("%d",remain[0]);
- m_passenger.Format("%d",now[1]);
- m_pt.Format("%d",totlep);
- m_destinenum.Format("%d",destinenum);
- m_destination.SetSel(0,-1);
- m_destination.ReplaceSel("武汉");
- UpdateData(0);
- return TRUE; // return TRUE unless you set the focus to a control
- }
- void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
- void CMyDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CMyDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
- void CMyDlg::OnCancel()
- {
- // TODO: Add extra cleanup here
-
- CDialog::OnCancel();
- }
- void CMyDlg::OnButtonOk()
- {
- // TODO: Add your control notification handler code here
- m_destination.GetWindowText(p[destinenum].destination,20);
- m_name.GetWindowText(p[destinenum].name,20);
- m_fly.GetWindowText(p[destinenum].fly,20);
- p[destinenum].ticketnum=m_ticketnum;
- int RADIO;
- RADIO=GetCheckedRadioButton(IDC_RADIO_man,IDC_RADIO_woman);
- p[destinenum].sex=RADIO;
- 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))
- {
- totlep+=m_ticketnum;
- destinenum++;
- now[fly]+=m_ticketnum;
- remain[fly]-=m_ticketnum;
- m_passenger.Format("%d",(now[fly]));
- m_remain.Format("%d",(remain[fly]));
- m_pt.Format("%d",totlep);
- m_destinenum.Format("%d",destinenum);
- //m_p_information.SetSel(0,-1);
- //m_p_information.ReplaceSel(p[now].destination);
- //m_p_information.ReplaceSel(" ");
- //if (RADIO==IDC_RADIO_man) m_p_information.ReplaceSel("男 ");
- //else if (RADIO==IDC_RADIO_woman) m_p_information.ReplaceSel("女 ");
- //m_p_information.ReplaceSel(p[now].name);
- m_information.SetSel(0,-1);
- m_information.ReplaceSel("定票成功");
- UpdateData(0);
- }
- else if (remain[fly]<m_ticketnum)
- {
- m_information.SetSel(0,-1);
- if (fly==1)
- {
- m_information.ReplaceSel("当前航线的票数已不能满足,定票失败");
- }
- else if (fly==0)
- {
- if (remain[2]>=m_ticketnum)
- m_information.ReplaceSel("当前航线的票数已不能满足,订票失败CF_134次航班能满足您的要求,请订CF_134次航班");
- else m_information.ReplaceSel("当前航线的票数已不能满足,定票失败");
- }
- else if (fly==2)
- {
- if (remain[0]>=m_ticketnum)
- m_information.ReplaceSel("当前航线的票数已不能满足,订票失败CF_101次航班能满足您的要求,请订CF_101次航班");
- else m_information.ReplaceSel("当前航线的票数已不能满足,定票失败");
- }
- UpdateData(0);
- }
- else
- {
- m_information.SetSel(0,-1);
- m_information.ReplaceSel("乘客信息填写不完整,定票失败");
- UpdateData(0);
- }
- if (now[fly]>100)
- {
- m_information.SetSel(0,-1);
- m_information.ReplaceSel("机票已售完,请选择其他航线");
- now[fly]=100;
- remain[fly]=100;
- }
- m_p_information.SetSel(0,-1);
- m_p_information.ReplaceSel("");
- qsort( (void *)p,destinenum,sizeof(p[1]),compare);
- for (int i=0;i<destinenum;i++)
- {
- m_p_information.SetSel(-1,0);
- m_p_information.ReplaceSel(p[i].name);
- m_p_information.ReplaceSel(" ");
- if (p[i].sex==IDC_RADIO_man) m_p_information.ReplaceSel("男 ");
- else if (p[i].sex==IDC_RADIO_woman) m_p_information.ReplaceSel("女 ");
- m_p_information.ReplaceSel(p[i].destination);
- m_p_information.ReplaceSel(" ");
- m_p_information.ReplaceSel(p[i].fly);
- m_p_information.ReplaceSel(" ");
- char temp[10];
- _gcvt(p[i].ticketnum,10,temp);
- m_p_information.ReplaceSel(temp);
- m_p_information.ReplaceSel("n");
- //m_p_information.FmtLines(NULL);
- }
- UpdateData(0);
- }
- void CMyDlg::OnButtonCancel()
- {
- // TODO: Add your control notification handler code here
- char temp_name[20];
- int temp_sex;
- char temp_destination[20];
- m_destination.GetWindowText(temp_destination,20);
- m_name.GetWindowText(temp_name,20);
- temp_sex=GetCheckedRadioButton(IDC_RADIO_man,IDC_RADIO_woman);
- if (now[fly]==0)
- {
- m_information.SetSel(0,-1);
- m_information.ReplaceSel("当前无人定票,退票失败");
- }
- else
- {
- for (int i=0;i<destinenum;i++)
- {
- if (strcmp(p[i].destination,temp_destination)==0)
- {
- if (strcmp(p[i].name,temp_name)==0)
- {
- if (p[i].sex==temp_sex&&p[i].ticketnum==m_ticketnum)
- {
- //add your code here
- for (int j=i;j<destinenum-1;j++)
- {
- p[j]=p[j+1];
- }
- now[fly]-=m_ticketnum;
- remain[fly]+=m_ticketnum;
- totlep-=m_ticketnum;
- destinenum--;
- m_passenger.Format("%d",(now[fly]));
- m_remain.Format("%d",(remain[fly]));
- m_destinenum.Format("%d",destinenum);
- m_pt.Format("%d",totlep);
- m_information.SetSel(0,-1);
- m_information.ReplaceSel("退票成功");
- break;
- }
- else if(p[i].sex!=temp_sex)
- {
- m_information.SetSel(0,-1);
- m_information.ReplaceSel("查无此记录,退票失败");
- }
- else if (p[i].ticketnum>m_ticketnum)
- {
- now[fly]-=m_ticketnum;
- remain[fly]+=m_ticketnum;
- totlep-=m_ticketnum;
- p[i].ticketnum-=m_ticketnum;
- m_passenger.Format("%d",(now[fly]));
- m_remain.Format("%d",(remain[fly]));
- m_pt.Format("%d",totlep);
- m_information.SetSel(0,-1);
- m_information.ReplaceSel("退票成功");
- }
- else if (p[i].ticketnum<m_ticketnum)
- {
- m_information.SetSel(0,-1);
- m_information.ReplaceSel("此乘客所定票数少于所输入的票数,退票失败");
- }
- }
- else
- {
- m_information.SetSel(0,-1);
- m_information.ReplaceSel("查无此记录,退票失败");
- }
- }
- else
- {
- m_information.SetSel(0,-1);
- m_information.ReplaceSel("查无此记录,退票失败");
- }
- }
- m_p_information.SetSel(0,-1);
- m_p_information.ReplaceSel("");
- for (int k=0;k<destinenum;k++)
- {
- m_p_information.SetSel(-1,0);
- m_p_information.ReplaceSel(p[k].name);
- m_p_information.ReplaceSel(" ");
- if (p[k].sex==IDC_RADIO_man) m_p_information.ReplaceSel("男 ");
- else if (p[k].sex==IDC_RADIO_woman) m_p_information.ReplaceSel("女 ");
- m_p_information.ReplaceSel(p[k].destination);
- m_p_information.ReplaceSel(" ");
- m_p_information.ReplaceSel(p[k].fly);
- m_p_information.ReplaceSel(" ");
- char temp[10];
- _gcvt(p[k].ticketnum,10,temp);
- m_p_information.ReplaceSel(temp);
- m_p_information.ReplaceSel("n");
- }
- UpdateData(0);
- }
- }
- void CMyDlg::OnSelchangeCOMBOfly()
- {
- // TODO: Add your control notification handler code here
- char tempstring[20];
- m_fly.GetWindowText(tempstring,20);
- if (strcmp(tempstring,"CF_101")==0) {fly=0;m_destination.SetSel(0,-1);m_destination.ReplaceSel("武汉");}
- else if (strcmp(tempstring,"CF_108")==0) {fly=1;m_destination.SetSel(0,-1);m_destination.ReplaceSel("长沙");}
- else if (strcmp(tempstring,"CF_134")==0) {fly=2;m_destination.SetSel(0,-1);m_destination.ReplaceSel("武汉");}
- m_passenger.Format("%d",(now[fly]));
- m_remain.Format("%d",(remain[fly]));
- UpdateData(0);
- }
- void CMyDlg::OnChangeEDITticketnum()
- {
- // TODO: If this is a RICHEDIT control, the control will not
- // send this notification unless you override the CDialog::OnInitDialog()
- // function and call CRichEditCtrl().SetEventMask()
- // with the ENM_CHANGE flag ORed into the mask.
-
- // TODO: Add your control notification handler code here
- char temp[20];
- (GetDlgItem(IDC_EDIT_ticketnum))->GetWindowText(temp,20);
- m_ticketnum=(int)atof((LPCTSTR)temp);
- }