📄 refund.cpp
字号:
// Refund.cpp : implementation file
//
#include "stdafx.h"
#include "AviationBS.h"
#include "Refund.h"
#include "UsedLine.h"
#include "Queue.h"
#include "DealWithQueue.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CRefund dialog
extern UsedLine usedLine;
extern CClient client;
extern Queue queue;
extern int Index[8];
CRefund::CRefund(CWnd* pParent /*=NULL*/)
: CDialog(CRefund::IDD, pParent)
{
//{{AFX_DATA_INIT(CRefund)
m_ID = _T("");
m_name = _T("");
m_date = COleDateTime::GetCurrentTime();
m_FCNum = 0;
m_TCNum = 0;
//}}AFX_DATA_INIT
}
BOOL CRefund::OnInitDialog()
{
CDialog::OnInitDialog();
//在查询框中的"目的地"下拉列表中加入已安排航班的航线
CString str;
for(int i=0;i<usedLine.LineSz;i++)
{
str.Format(_T("%s"),usedLine.lineArray[i].destination);
str=str.Left(10);
str.Remove(' ');
m_LineCtrl.AddString(str);
}
//设置航班的列表框的属性,用于显示退票时的客户的一些信息
m_ClientDataCtrl.SetExtendedStyle(m_ClientDataCtrl.GetExtendedStyle() | LVS_EX_FULLROWSELECT |
LVS_EX_GRIDLINES | LVS_EX_SUBITEMIMAGES);
//设置航班的列表框的第一行
TCHAR ListHead[7][113] = {_T("目的地"),_T("客户姓名"),_T("身份号"),_T("起飞日期"),
_T("起飞时间"),_T("头等舱订票数"), _T("经济舱订票数")};
LV_COLUMN lvcolumn;
CRect rect;
m_ClientDataCtrl.GetWindowRect(&rect);
for(i=0;i<7;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;
if(i<5)lvcolumn.cx = rect.Width()*2/14.5;
else lvcolumn.cx = rect.Width()*2/13.1;
m_ClientDataCtrl.InsertColumn(i, &lvcolumn);
}
return TRUE;
}
void CRefund::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CRefund)
DDX_Control(pDX, IDC_LIST, m_ClientDataCtrl);
DDX_Control(pDX, IDC_CHECK3, m_AllCtrl);
DDX_Control(pDX, IDC_COMBO1, m_LineCtrl);
DDX_Text(pDX, IDC_IDEDIT, m_ID);
DDV_MaxChars(pDX, m_ID, 20);
DDX_Text(pDX, IDC_NAMEEDIT, m_name);
DDV_MaxChars(pDX, m_name, 20);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_date);
DDX_Text(pDX, IDC_FCEDIT, m_FCNum);
DDV_MinMaxInt(pDX, m_FCNum, 0, 1000);
DDX_Text(pDX, IDC_TCEDIT, m_TCNum);
DDV_MinMaxInt(pDX, m_TCNum, 0, 1000);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CRefund, CDialog)
//{{AFX_MSG_MAP(CRefund)
ON_BN_CLICKED(IDC_FINDBUTTON, OnFind)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CRefund message handlers
void CRefund::OnFind()
{
// TODO: Add your control notification handler code here
m_ClientDataCtrl.DeleteAllItems();
UpdateData();
int Lindex;//所选航线的下标
m_ID.Remove(' ');
m_name.Remove(' ');
if(m_name.IsEmpty()!=0){MessageBox("请输入您的姓名!");return;}
if(m_ID.IsEmpty()!=0){MessageBox("请输入身份证号码!");return;}
else for(int i=0;i<m_ID.GetLength();i++)
if(m_ID.GetAt(i)>'9'||m_ID.GetAt(i)<'0'){MessageBox("身份证号码不能为字符");return;}
Lindex=m_LineCtrl.GetCurSel();
if(CB_ERR == Lindex){MessageBox("请选择目的地!");return;}
if(m_date>=usedLine.GetNextNDay(7))
{MessageBox("对不起,本系统只能查询七天以内的航班信息!谢谢合作!");return;}
else if(m_date<usedLine.GetNextNDay(0))
{MessageBox("对不起,你查询的日期已过期!");return;}
int dayInWeek=m_date.GetDayOfWeek()-1;
Line=client.BClient[dayInWeek].Find(Lindex);//查找订票客户时,存放退票信息所在的航线的指针
if(Line->LineData.size==0)
{MessageBox("找不到订票信息,请正确输入身份证,目的地和乘机时间,谢谢!");return;}
ClientIndex=Line->Find(m_ID,m_name);//查询到的退票客户信息的下标
if(ClientIndex==-1)
{MessageBox("找不到订票信息,请正确输入身份证,目的地和乘机时间,谢谢!");return;}
COleDateTime Time=COleDateTime::GetCurrentTime();
if(Line->LineData.ClientData[ClientIndex].FlyTime<=Time)
{
MessageBox("你所订的票已过期(飞机已起飞),不可进行退票!");
Line->remove(ClientIndex);
return;
}
//把找到的订票信息,在列表框中显示出来
CString str;
str.Format("%s",usedLine.lineArray[Lindex].destination);
str=str.Left(10);
str.Remove(' ');
LV_ITEM ListItem={0};
ListItem.mask=LVIF_TEXT;
ListItem.iItem=0;
ListItem.iSubItem=0;
ListItem.pszText=str.GetBuffer(str.GetLength());
str.ReleaseBuffer();
if (m_ClientDataCtrl.InsertItem(&ListItem) != -1)
{
LV_ITEM FlightInfo = {0};
for(int j=1;j<7;j++)
{
FlightInfo.mask=LVIF_TEXT;
FlightInfo.iItem=0;
FlightInfo.iSubItem =j;
switch(j)
{
case 1: {
FlightInfo.pszText=m_name.GetBuffer(m_name.GetLength());
m_name.ReleaseBuffer();
break;
}
case 2: {
FlightInfo.pszText=m_ID.GetBuffer(m_ID.GetLength());
m_ID.ReleaseBuffer();
break;
}
case 3:{
str.Format("%d-%d-%d",
Line->LineData.ClientData[ClientIndex].FlyTime.GetYear(),
Line->LineData.ClientData[ClientIndex].FlyTime.GetMonth(),
Line->LineData.ClientData[ClientIndex].FlyTime.GetDay());
FlightInfo.pszText=str.GetBuffer(str.GetLength());
str.ReleaseBuffer();
break;
}
case 4: {
str.Format("%d:%d:%d",
Line->LineData.ClientData[ClientIndex].FlyTime.GetHour(),
Line->LineData.ClientData[ClientIndex].FlyTime.GetMinute(),
Line->LineData.ClientData[ClientIndex].FlyTime.GetSecond());
FlightInfo.pszText=str.GetBuffer(str.GetLength());
str.ReleaseBuffer();
break;
}
case 5: {str.Format("%d",Line->LineData.ClientData[ClientIndex].FriCTicket);FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();break;}
case 6: {str.Format("%d",Line->LineData.ClientData[ClientIndex].TouCTicket);FlightInfo.pszText=str.GetBuffer(str.GetLength());str.ReleaseBuffer();break;}
}
m_ClientDataCtrl.SetItem(&FlightInfo);
}
}
}
void CRefund::OnOK()
{
// TODO: Add extra validation here
UpdateData();
if(m_ClientDataCtrl.GetItemCount()==0)
{
MessageBox("请先查询你的订票信息,谢谢!");
return;
}
////////////////////退票处理////////////////////////////////
int FC=m_FCNum,TC=m_TCNum; //头等舱,跟经济舱的退票额;
if(m_AllCtrl.GetCheck ()==1) //退全票
{
FC=Line->LineData.ClientData[ClientIndex].FriCTicket;
TC=Line->LineData.ClientData[ClientIndex].TouCTicket;
Line->remove(ClientIndex);
}
else
{
if(m_FCNum==0&&m_TCNum==0)
{MessageBox("请输入你的退票额!");return;}
if(m_FCNum>Line->LineData.ClientData[ClientIndex].FriCTicket ||
m_TCNum>Line->LineData.ClientData[ClientIndex].TouCTicket)
{MessageBox("你输入的退票额,已超过你的订票额,请重新输入,谢谢!");return;}
//部分退票处理
Line->modify(ClientIndex,FC,TC);
}
MessageBox("恭喜你,退票成功!");
//找出目前总共还剩下多少票数,以便查找候补队列时,将票卖出去
int LIndex=m_LineCtrl.GetCurSel();
int FlightIndex; //退票航班在usedLine中对应的下标
FlightIndex=usedLine.flightArray[LIndex].Find(Line->LineData.ClientData[ClientIndex].FlyTime);
//把所退的票加在一起,以便查找候补队列时,将票卖出去
FC+=usedLine.flightArray[LIndex].flight[FlightIndex].FirCFreeNum;
TC+=usedLine.flightArray[LIndex].flight[FlightIndex].TouCFreeNum;
//查找候补队列,询问排队的人,是否需要订票
int dayInWeek=usedLine.flightArray[LIndex].flight[FlightIndex].FlyTime.GetDayOfWeek()-1;
//找出退票航班在排队队列中的地址
int index=queue.queueData[dayInWeek].LineLink[LIndex].Find(
usedLine.flightArray[LIndex].flight[FlightIndex].FlyTime);
Index[6]=LIndex;
Index[7]=FlightIndex; //记住退票航班在usedLine中对应的下标
if(index>=0)
{
QLink* temp=queue.queueData[dayInWeek].LineLink[LIndex].qFlight[index].start;
for(int i=0;i<queue.queueData[dayInWeek].LineLink[LIndex].qFlight[index].size;i++)
{
if(temp->queuer.isTry==true ||(FC>=temp->queuer.FCNum && TC>=temp->queuer.TCNum))
{
Index[0]=FC; //通过全局变量把参数传给DealWithQueue对话框处理,不安全,笨!
Index[1]=TC;
Index[2]=index;
Index[3]=dayInWeek;
DealWithQueue dlg;
dlg.Exchange(&queue.queueData[dayInWeek].LineLink[LIndex],temp,Line);
temp=temp->next;
dlg.DoModal();
}
FC=Index[0];
TC=Index[1];
if(FC==0 && TC==0)break; //所有空闲票处理完毕
}
}
//将剩下的票放回到usedLine中
usedLine.flightArray[LIndex].flight[FlightIndex].FirCFreeNum=FC;
usedLine.flightArray[LIndex].flight[FlightIndex].TouCFreeNum=TC;
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -