⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setline.cpp

📁 航空订票系统 学校大作业开发的
💻 CPP
字号:
// SetLine.cpp : implementation file
//

#include "stdafx.h"
#include "AviationBS.h"
#include "SetLine.h"

#ifndef SYSLINE_H
#define SYSLINE_H
#include "SysLine.h"
#endif

#ifndef  USEDLINE_H
#define  USEDLINE_H
#include "UsedLine.h"
#endif
#include "Client.h"
#include "Queue.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// SetLine dialog

extern SysLine sysLine;
extern UsedLine usedLine;
extern CClient client;
extern Queue queue;
SetLine::SetLine(CWnd* pParent /*=NULL*/)
	: CDialog(SetLine::IDD, pParent)
{
	//{{AFX_DATA_INIT(SetLine)
	m_line = _T("");
	m_plnetype = _T("");
	m_fcNum = 0;
	m_fcPrice = 0.0;
	m_TcNum = 0;
	m_tcPrice = 0.0;
	m_PlaneNum = _T("");
	m_flyTime = COleDateTime::GetCurrentTime();
	//}}AFX_DATA_INIT
	
}


void SetLine::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(SetLine)
	DDX_Control(pDX, IDC_FLIGHTLIST, m_flightCtrl);
	DDX_Control(pDX, IDC_ADDLINEEDIT, m_lineCtrl);
	DDX_Control(pDX, IDC_ALLLINELIST, m_LinelistCtrl);
	DDX_Text(pDX, IDC_ADDLINEEDIT, m_line);
	DDX_Text(pDX, IDC_PLANETYPE, m_plnetype);
	DDV_MaxChars(pDX, m_plnetype, 6);
	DDX_Text(pDX, IDC_FCNUM, m_fcNum);
	DDV_MinMaxInt(pDX, m_fcNum, 0, 100);
	DDX_Text(pDX, IDC_FCPIRCE, m_fcPrice);
	DDV_MinMaxDouble(pDX, m_fcPrice, 0., 10000.);
	DDX_Text(pDX, IDC_TCNUM, m_TcNum);
	DDV_MinMaxInt(pDX, m_TcNum, 0, 100);
	DDX_Text(pDX, IDC_TCPRICE, m_tcPrice);
	DDV_MinMaxDouble(pDX, m_tcPrice, 0., 10000.);
	DDX_Text(pDX, IDC_PLANENUM, m_PlaneNum);
	DDV_MaxChars(pDX, m_PlaneNum, 6);
	DDX_DateTimeCtrl(pDX, IDC_TIMEPICKER, m_flyTime);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(SetLine, CDialog)
	//{{AFX_MSG_MAP(SetLine)
	ON_BN_CLICKED(IDC_ADDLINE, OnAddline)
	ON_BN_CLICKED(IDC_ADDFLIGHT, OnAddFlight)
	ON_BN_CLICKED(IDC_DELETEFLIGHT, OnDeletefFlight)
	ON_BN_CLICKED(IDC_DELETELINE, OnDeletelLine)
	ON_LBN_SELCHANGE(IDC_ALLLINELIST, OnSelchangeAlllinelist)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// SetLine message handlers
BOOL SetLine::OnInitDialog()
{
	CDialog::OnInitDialog();
    m_lineCtrl.SetLimitText(10);
	//设置航班的列表框的属性
    m_flightCtrl.SetExtendedStyle(m_flightCtrl.GetExtendedStyle() | LVS_EX_FULLROWSELECT |
		 LVS_EX_GRIDLINES | LVS_EX_SUBITEMIMAGES);
	//设置航班的列表框的第一行
    TCHAR ListHead[8][12] = {_T("目的地"),_T("航班号"), _T("飞机型号"),_T("起飞时间"),_T("头等舱位数"),
						    _T("头等舱票价"),_T("经济舱位数"),_T("经济舱票价")};
	 LV_COLUMN lvcolumn;
	 CRect rect;
	 m_flightCtrl.GetWindowRect(&rect);
	 for(int i=0;i<8;i++)
	 {
        lvcolumn.mask = LVCF_FMT | LVCF_SUBITEM | LVCF_TEXT | LVCF_WIDTH | LVCF_ORDER;
		lvcolumn.fmt = LVCFMT_LEFT;
		lvcolumn.pszText = ListHead[i];
		lvcolumn.iSubItem = i;
		lvcolumn.iOrder = i;
		lvcolumn.cx = rect.Width()*2/16;
		m_flightCtrl.InsertColumn(i, &lvcolumn);
	 }

	//将已有航线加入列表框中
	CString str;
    for(i=0;i<sysLine.AllLineSz;i++)
	{
		str.Format(_T("%s"),sysLine.lineArray[i].destination);
		str=str.Left(10);
		str.Remove(' ');
        m_LinelistCtrl.AddString(str);
	}
	        
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void SetLine::OnAddline() 
{

    UpdateData();
	m_line.Remove(' ');
	if(m_line.IsEmpty())MessageBox(_T("输入为空"));
	else {
     	  int index=sysLine.insertLine(m_line);
		  if(-1==index)MessageBox(_T("该航线已存在"));
		  else {
			  m_LinelistCtrl.InsertString(index,m_line);
		  }
		}
	  m_lineCtrl.SetSel(0,m_lineCtrl.LineLength(1));   
	  m_lineCtrl.Clear();    
}
void SetLine::OnDeletelLine() 
{

	int Linesel=m_LinelistCtrl.GetCurSel();
	if(Linesel==LB_ERR)MessageBox("请选择要删除的航线!");
 else if(IDOK==MessageBox("删除该航班,从今天起的所有关于该航线的 所有资料都将被删除! 你确定吗?",
	   "SmartBoy",MB_ICONQUESTION|MB_OKCANCEL))
		{
			m_LinelistCtrl.DeleteString(Linesel); 
			int index=sysLine.FindLine(Linesel);        
			if(sysLine.lineArray[Linesel].isEmpty==false)
			{
             client.deleteLine(index); 
             queue.deleteLine(index); 
			 usedLine.deleteLine(index); //处理usedLine中的航线
			}
			sysLine.deleteLine(Linesel);  //删除航线
			if(m_flightCtrl.GetItemCount( )>0)m_flightCtrl.DeleteAllItems();
		}	
	
}

void SetLine::OnAddFlight() 
{
	if(UpdateData()==0)return;      //航班信息输入有误
	bool isnew=false;               //新增的航班如果是所在航线的第一个航班即为true
	CString str;
	COleDateTime FlyTime;
	int Linesel=m_LinelistCtrl.GetCurSel();
	int flight=0;                   //插入的航班位置
    if(Linesel==LB_ERR)MessageBox("请选择航线!");
	  else  // 添加航班
	  {  
		 m_PlaneNum.Remove(' ');
		 m_plnetype.Remove(' ');
		 if(m_PlaneNum.IsEmpty()!=0 || m_plnetype.IsEmpty()!=0)
				{MessageBox("航班号,飞机型号不能为空!请正确输入!");return;}
		 int line=sysLine.FindFlightIndex(Linesel);    //找到合适的航线位置插进去
		 if(line==-1){MessageBox("对不起!一天最多只能有四个航班,谢谢合作!");return;}
		 FlyTime.SetDateTime(2007,2,27,m_flyTime.GetHour(),m_flyTime.GetMinute(),
			                  m_flyTime.GetSecond());  //只要比较飞机的起飞时间,故把日期设置为一样
       if(sysLine.lineArray[Linesel].isEmpty==false) //航班插入的位置
	   {
		   for(;flight<sysLine.flightArray[line].flightN;flight++)
		   {
			if(sysLine.flightArray[line].flightInfo[flight].FlyTime==FlyTime)
			{
				MessageBox("该航班已存在!");
				return;
			}
			if(sysLine.flightArray[line].flightInfo[flight].FlyTime>FlyTime)
			{
				for(int i=sysLine.flightArray[line].flightN;i>flight;i--)
                sysLine.flightArray[line].flightInfo[i]=sysLine.flightArray[line].flightInfo[i-1];
				break;
			}
		   }
	   } else {sysLine.LineSz++;sysLine.lineArray[Linesel].isEmpty=false;isnew=true;}
		//将新增航班写入系统对象 sysLine
	
		sysLine.flightArray[line].flightN++;
		sysLine.flightArray[line].flightInfo[flight].FirCNum=m_fcNum;
		sysLine.flightArray[line].flightInfo[flight].FirCP=m_fcPrice;
		sysLine.flightArray[line].flightInfo[flight].FlyTime=FlyTime;
	    for( int i=0;i<6;i++) //写入飞机型号,航班号
		{
		   if(i<m_PlaneNum.GetLength())
		        sysLine.flightArray[line].flightInfo[flight].PlaneNum[i]=m_PlaneNum.GetAt(i);
	        else sysLine.flightArray[line].flightInfo[flight].PlaneNum[i]=' ';
	       if(i<m_plnetype.GetLength())
			   sysLine.flightArray[line].flightInfo[flight].PlaneType[i]=m_plnetype.GetAt(i);
	        else sysLine.flightArray[line].flightInfo[flight].PlaneType[i]=' ';
		 }
		sysLine.flightArray[line].flightInfo[flight].TouCNum=m_TcNum;
        sysLine.flightArray[line].flightInfo[flight].TouCP=m_tcPrice;
        //在列表框加入新增的航班
		 str.Format(_T("%s"),sysLine.lineArray[Linesel].destination);
	     str.Remove(' ');
		 LV_ITEM   AddFlight={0};
		 AddFlight.mask=LVIF_TEXT;
		 AddFlight.iItem=flight ;
		 AddFlight.iSubItem=0;
		 AddFlight.pszText=str.GetBuffer(str.GetLength());
		 str.ReleaseBuffer();
		 
		if (m_flightCtrl.InsertItem(&AddFlight) != -1)
		 {
			LV_ITEM FlightInfo = {0};
			for(i=1;i<8;i++)
			{ 	
				FlightInfo.mask=LVIF_TEXT;
				FlightInfo.iItem=flight;
				FlightInfo.iSubItem =i;
				switch(i)
				{
				case 1:{ FlightInfo.pszText=m_PlaneNum.GetBuffer(m_PlaneNum.GetLength());m_PlaneNum.ReleaseBuffer();break;}
				case 2: {FlightInfo.pszText=m_plnetype.GetBuffer(m_plnetype.GetLength());m_plnetype.ReleaseBuffer();break;}
				case 3: {
						str.Format("%d:%d:%d",
							FlyTime.GetHour(),FlyTime.GetMinute(),FlyTime.GetSecond());
						FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();
						break;
						}
				case 4: {str.Format("%d",m_fcNum);FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();break;}
				case 5: {str.Format("%.1f",m_fcPrice);FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();break;}
				case 6: {str.Format("%d",m_TcNum);FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();break;}
				case 7: {str.Format("%.1f",m_tcPrice);FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();break;}
				}
				m_flightCtrl.SetItem(&FlightInfo);
			}
		 } 
		//处理usedLine,queue,client的数据
		if(isnew==true)  //新航线
			{
			 queue.addLine(line,flight,FlyTime);
             client.addLine(line);
			 usedLine.addLine(line,flight);
			}
		else{ //所在航线已经存在
			 queue.addFlight(line,flight,FlyTime);
			 usedLine.addFlight(line,flight);
			}
		}		  
}

void SetLine::OnDeletefFlight() 
{
 MessageBox("由于时间问题,这部分功能没有完成!");
}


void SetLine::OnSelchangeAlllinelist()    //当选中航线时,在航班的列表框中显示出航班的信息
{
	UpdateData();
	int Linesel=m_LinelistCtrl.GetCurSel();
    if(m_flightCtrl.GetItemCount( )>0)m_flightCtrl.DeleteAllItems();
	if(sysLine.lineArray[Linesel].isEmpty==false)
	{
    	CString str;
		int index=sysLine.FindLine(Linesel);
		LV_ITEM ListItem={0};
		ListItem.mask=LVIF_TEXT;
		for(int i=0;i<sysLine.flightArray[index].flightN;i++)
		{
			 ListItem.iItem=i;
			 ListItem.iSubItem=0;
			 str.Format(_T("%s"),sysLine.lineArray[Linesel].destination);
	         str=str.Left(10);
	         str.Remove(' ');
			 ListItem.pszText=str.GetBuffer(str.GetLength());
			 str.ReleaseBuffer();
			 if (m_flightCtrl.InsertItem(&ListItem) != -1)
			 {
				LV_ITEM FlightInfo = {0};
				for(int j=1;j<8;j++)
				{ 
					FlightInfo.mask=LVIF_TEXT;
					FlightInfo.iItem=i;
					FlightInfo.iSubItem =j;
					switch(j)
					{
					case 1: {
							 str.Format(_T("%s"),sysLine.flightArray[index].flightInfo[i].PlaneNum);
							 str=str.Left(6);
							 str.Remove(' ');
							 FlightInfo.pszText=str.GetBuffer(str.GetLength());
							 str.ReleaseBuffer();
							 break;
							}
					case 2: {
							 str.Format(_T("%s"),sysLine.flightArray[index].flightInfo[i].PlaneType);
							 str=str.Left(6);
							 str.Remove(' ');
							 FlightInfo.pszText=str.GetBuffer(str.GetLength());
							 str.ReleaseBuffer();
							 break;
							}
					case 3: {
							str.Format("%d:%d:%d",
								sysLine.flightArray[index].flightInfo[i].FlyTime.GetHour(),
								sysLine.flightArray[index].flightInfo[i].FlyTime.GetMinute(),
								sysLine.flightArray[index].flightInfo[i].FlyTime.GetSecond());
							FlightInfo.pszText=str.GetBuffer(str.GetLength());
							str.ReleaseBuffer();
							break;
							}
					case 4: {str.Format("%d",sysLine.flightArray[index].flightInfo[i].FirCNum);FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();break;}
					case 5: {str.Format("%.1f",sysLine.flightArray[index].flightInfo[i].FirCP);FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();break;}
					case 6: {str.Format("%d",sysLine.flightArray[index].flightInfo[i].TouCNum);FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();break;}
					case 7: {str.Format("%.1f",sysLine.flightArray[index].flightInfo[i].TouCP);FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();break;}
					}
					m_flightCtrl.SetItem(&FlightInfo);  
				}	
			 }
		 }
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -