?? 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 + -