-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAddFlightDlg.cpp
More file actions
187 lines (166 loc) · 5.24 KB
/
Copy pathAddFlightDlg.cpp
File metadata and controls
187 lines (166 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// AddFlightDlg.cpp: 实现文件
//
#include "pch.h"
#include "MINI12306.h"
#include "afxdialogex.h"
#include "AddFlightDlg.h"
// AddFlightDlg 对话框
IMPLEMENT_DYNAMIC(AddFlightDlg, CDialogEx)
AddFlightDlg::AddFlightDlg(CWnd* pParent /*=nullptr*/)
: CDialogEx(IDD_ADD_DIALOG, pParent)
{
nIndex = -1;
p = 0;
}
AddFlightDlg::~AddFlightDlg()
{
}
void AddFlightDlg::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX, IDC_COMBO1, Ori);
DDX_Control(pDX, IDC_COMBO2, Dest);
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_DTCtrl);
DDX_Control(pDX, IDOK, Add);
DDX_Control(pDX, IDOK2, Edit);
}
BEGIN_MESSAGE_MAP(AddFlightDlg, CDialogEx)
ON_BN_CLICKED(IDOK, &AddFlightDlg::OnBnClickedOk)
ON_BN_CLICKED(IDC_RADIO1, &AddFlightDlg::OnBnClickedRadio1)
ON_BN_CLICKED(IDC_RADIO2, &AddFlightDlg::OnBnClickedRadio2)
ON_BN_CLICKED(IDOK2, &AddFlightDlg::OnBnClickedOk2)
ON_BN_CLICKED(IDC_RADIO3, &AddFlightDlg::OnBnClickedRadio3)
END_MESSAGE_MAP()
// AddFlightDlg 消息处理程序
BOOL AddFlightDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
extern CityManager CM;
int size = CM.CL.size();
for (int i = 0; i < size; ++i)
{
CityInfo NewCity = CM.CL[i];
Ori.AddString(NewCity.City.c_str());
Dest.AddString(NewCity.City.c_str());
}
if (p == 0)
Edit.EnableWindow(0);
else
{
Add.EnableWindow(0);
extern FlightInfo CurrentFlight;
SetDlgItemText(IDC_COMBO1, CurrentFlight.GetOrigin());
SetDlgItemText(IDC_COMBO2, CurrentFlight.GetDestination());
SetDlgItemText(IDC_EDIT4, CurrentFlight.GetNum());
SetDlgItemInt(IDC_EDIT12, CurrentFlight.GetFirst().price);
SetDlgItemInt(IDC_EDIT8, CurrentFlight.GetFirst().cnt);
SetDlgItemInt(IDC_EDIT9, CurrentFlight.GetSecond().cnt);
SetDlgItemInt(IDC_EDIT13, CurrentFlight.GetSecond().price);
SetDlgItemText(IDC_EDIT6, CurrentFlight.GetStartTime());
SetDlgItemText(IDC_EDIT7, CurrentFlight.GetArriveTime());
}
return TRUE; // return TRUE unless you set the focus to a control
}
void AddFlightDlg::OnBnClickedOk()
{
CString O, D, No, Fc, Fp, Sc, Sp, Day, Year, Month, Date, ST, AT;
GetDlgItemText(IDC_COMBO1, O);
GetDlgItemText(IDC_COMBO2, D);
GetDlgItemText(IDC_EDIT4, No);
GetDlgItemText(IDC_EDIT12, Fp);
GetDlgItemText(IDC_EDIT8, Fc);
GetDlgItemText(IDC_EDIT9, Sc);
GetDlgItemText(IDC_EDIT13, Sp);
GetDlgItemText(IDC_EDIT6, ST);
GetDlgItemText(IDC_EDIT7, AT);
if (O == "" || D == "" || No == "" || Fp == "" || Fc == "" || Sc == "" || Sp == "" || ST == "" || AT == "" || nIndex == -1)
AfxMessageBox("请完整填写信息!");
else
{
COleDateTime m_Date;
m_DTCtrl.GetTime(m_Date);
int year = m_Date.GetYear();
int month = m_Date.GetMonth();
int day = m_Date.GetDay();
Year.Format("%d", year);
Month.Format("%d", month);
Day.Format("%d", day);
Date = Year + "/" + Month + "/" + Day;
char* ori = O.GetBuffer(O.GetLength());
char* dest = D.GetBuffer(D.GetLength());
char* no = No.GetBuffer(No.GetLength());
char* date = Date.GetBuffer(Date.GetLength());
char* st = ST.GetBuffer(ST.GetLength());
char* at = AT.GetBuffer(AT.GetLength());
FlightInfo NewFlight(no, date);
NewFlight.SetFirstInfo(atoi(Fc), atoi(Fp));
NewFlight.SetSecondInfo(atoi(Sc), atoi(Sp));
NewFlight.SetTime(st, at);
NewFlight.SetOrigin(ori);
NewFlight.SetDestination(dest);
NewFlight.SetStatus(nIndex);
extern FlightManager FM;
extern CityManager CM;
if (FM.AddFlight(NewFlight))
{
CM.EditCity(ori, 0);
CM.EditCity(dest, 0);
MessageBox("航班添加成功!");
CDialogEx::OnOK();
}
else
AfxMessageBox("航班已存在!");
}
}
void AddFlightDlg::OnBnClickedRadio1() { nIndex = 1; }
void AddFlightDlg::OnBnClickedRadio2() { nIndex = 0; }
void AddFlightDlg::OnBnClickedRadio3() { nIndex = 2; }
void AddFlightDlg::OnBnClickedOk2()
{
CString O, D, No, Fc, Fp, Sc, Sp, Day, Year, Month, Date, ST, AT;
GetDlgItemText(IDC_COMBO1, O);
GetDlgItemText(IDC_COMBO2, D);
GetDlgItemText(IDC_EDIT4, No);
GetDlgItemText(IDC_EDIT12, Fp);
GetDlgItemText(IDC_EDIT8, Fc);
GetDlgItemText(IDC_EDIT9, Sc);
GetDlgItemText(IDC_EDIT13, Sp);
GetDlgItemText(IDC_EDIT6, ST);
GetDlgItemText(IDC_EDIT7, AT);
if (O == "" || D == "" || No == "" || Fp == "" || Fc == "" || Sc == "" || Sp == "" || ST == "" || AT == "" || nIndex == -1)
AfxMessageBox("请完整填写信息!");
else
{
COleDateTime m_Date;
m_DTCtrl.GetTime(m_Date);
int year = m_Date.GetYear();
int month = m_Date.GetMonth();
int day = m_Date.GetDay();
Year.Format("%d", year);
Month.Format("%d", month);
Day.Format("%d", day);
Date = Year + "/" + Month + "/" + Day;
char* ori = O.GetBuffer(O.GetLength());
char* dest = D.GetBuffer(D.GetLength());
char* no = No.GetBuffer(No.GetLength());
char* date = Date.GetBuffer(Date.GetLength());
char* st = ST.GetBuffer(ST.GetLength());
char* at = AT.GetBuffer(AT.GetLength());
FlightInfo NewFlight(no, date);
NewFlight.SetFirstInfo(atoi(Fc), atoi(Fp));
NewFlight.SetSecondInfo(atoi(Sc), atoi(Sp));
NewFlight.SetTime(st, at);
NewFlight.SetOrigin(ori);
NewFlight.SetDestination(dest);
NewFlight.SetStatus(nIndex);
extern FlightManager FM;
extern CityManager CM;
if (FM.EditFlight(no, date, NewFlight))
{
MessageBox("航班信息修改成功!");
CDialogEx::OnOK();
}
else
AfxMessageBox("航班不存在!修改失败!");
}
}