-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBusApp_main_window.cpp
295 lines (233 loc) · 7.95 KB
/
BusApp_main_window.cpp
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#include "BusApp_main_window.h"
#include "BusApp_printout.h"
#include "BusApp_Insertion.h"
#include <wx/wx.h>
#include "query.h"
#include <string>
#include <sstream>
#include <codecvt>
#include <locale>
BusApp_main_window::BusApp_main_window( wxWindow* parent )
:
main_window( parent )
{
}
void BusApp_main_window::mainOnClose( wxCloseEvent& event )
{
event.Skip();
}
void BusApp_main_window::line_boxOnChoice( wxCommandEvent& event )
{
}
void BusApp_main_window::timetable_butOnButtonClick( wxCommandEvent& event )
{
if(line_box->GetSelection() == wxNOT_FOUND){
wxMessageDialog dlg(this, "Nie wybrano numeru linii.", wxMessageBoxCaptionStr, wxOK|wxICON_ERROR);
dlg.ShowModal();
} else {
printout *viewFrame = new BusApp_printout(this);
timetable_q(
std::stoi(line_boxChoices[line_box->GetSelection()].ToStdString()),
C,
viewFrame);
viewFrame->Show(true);
}
}
void BusApp_main_window::beg_boxOnChoice( wxCommandEvent& event )
{
// TODO: Implement beg_boxOnChoice
}
void BusApp_main_window::end_boxOnChoice( wxCommandEvent& event )
{
// TODO: Implement end_boxOnChoice
}
void BusApp_main_window::route_butOnButtonClick( wxCommandEvent& event )
{
if(beg_box->GetSelection() == wxNOT_FOUND){
wxMessageDialog dlg(this, L"Nie wybrano przystanku początkowego.", wxMessageBoxCaptionStr, wxOK|wxICON_ERROR);
dlg.ShowModal();
} else if(end_box->GetSelection() == wxNOT_FOUND){
wxMessageDialog dlg(this, L"Nie wybrano przystanku końcowego.", wxMessageBoxCaptionStr, wxOK|wxICON_ERROR);
dlg.ShowModal();
} else {
printout *viewFrame = new BusApp_printout(this);
int idp=bus_stop_ids[beg_box->GetSelection()];
int ide=bus_stop_ids[end_box->GetSelection()];
if(ide==idp){
wxMessageDialog dlg(this, L"Przystanki muszą być różne.", wxMessageBoxCaptionStr, wxOK|wxICON_ERROR);
if ( dlg.ShowModal() == wxID_OK )
return;
}
route_q(idp,ide,C,viewFrame);
viewFrame->Show(true);
}
}
void BusApp_main_window::bus_boxOnChoice( wxCommandEvent& event )
{
// TODO: Implement bus_boxOnChoice
}
void BusApp_main_window::bus_butOnButtonClick( wxCommandEvent& event )
{
if(bus_box->GetSelection() == wxNOT_FOUND){
wxMessageDialog dlg(this, "Nie wybrano numeru autobusu.", wxMessageBoxCaptionStr, wxOK|wxICON_ERROR);
dlg.ShowModal();
} else {
printout *viewFrame = new BusApp_printout(this);
bus_q(
std::stoi(bus_boxChoices[bus_box->GetSelection()].ToStdString()),
C,
viewFrame);
viewFrame->Show(true);
}
}
void BusApp_main_window::login_boxOnTextEnter( wxCommandEvent& event )
{
// TODO: Implement login_boxOnTextEnter
}
void BusApp_main_window::passwd_boxOnTextEnter( wxCommandEvent& event )
{
// TODO: Implement passwd_boxOnTextEnter
}
void BusApp_main_window::login_butOnButtonClick( wxCommandEvent& event )
{
if(loggedin){
insert_but->Disable();
print_but->Disable();
table_insert_box->Disable();
table_print_box->Disable();
login_box->Enable();
passwd_box->Enable();
login_but->SetLabel("Zaloguj");
loggedin=false;
} else {
std::stringstream sql1;
sql1 << "SELECT COUNT(*) FROM logowanie.kierowca WHERE login='"
<< login_box->GetLineText(0) << "' AND haslo='" << passwd_box->GetLineText(0) << "' GROUP BY login, haslo;";
std::stringstream sql2;
sql2 << "SELECT COUNT(*) FROM logowanie.czlonek_zarzadu WHERE login='"
<< login_box->GetLineText(0) << "' AND haslo='" << passwd_box->GetLineText(0) << "' GROUP BY login, haslo;";
pqxx::nontransaction N1(*C);
pqxx::result R1(N1.exec(sql1.str()));
pqxx::result R2(N1.exec(sql2.str()));
if(R2.size() > 0 && R2.begin()[0].as<int>() > 0){
insert_but->Enable();
print_but->Enable();
table_insert_box->Enable();
table_print_box->Enable();
login_box->Clear();
login_box->Disable();
passwd_box->Clear();
passwd_box->Disable();
login_but->SetLabel("Wyloguj");
loggedin=true;
}
else if(R1.size() > 0 && R1.begin()[0].as<int>() > 0){
print_but->Enable();
table_print_box->Enable();
login_box->Clear();
login_box->Disable();
passwd_box->Clear();
passwd_box->Disable();
login_but->SetLabel("Wyloguj");
loggedin=true;
} else {
wxMessageDialog dlg(this, L"Błędne dane logowania.", wxMessageBoxCaptionStr, wxOK|wxICON_ERROR);
dlg.ShowModal();
}
}
}
void BusApp_main_window::table_print_boxOnChoice( wxCommandEvent& event )
{
// TODO: Implement table_print_boxOnChoice
}
void BusApp_main_window::print_butOnButtonClick( wxCommandEvent& event )
{
if(table_print_box->GetSelection() == wxNOT_FOUND){
wxMessageDialog dlg(this, "Nie wybrano tabeli.", wxMessageBoxCaptionStr, wxOK|wxICON_ERROR);
dlg.ShowModal();
} else {
printout *viewFrame = new BusApp_printout(this);
show_table_q(
table_print_box->GetSelection(),
C,
viewFrame);
viewFrame->Show(true);
}
}
void BusApp_main_window::table_insert_boxOnChoice( wxCommandEvent& event )
{
// TODO: Implement table_insert_boxOnChoice
}
void BusApp_main_window::insert_butOnButtonClick( wxCommandEvent& event )
{
int col_n;
std::vector<std::wstring> labels;
int id = table_insert_box->GetSelection();
switch(id){
case 0:
labels={L"id", L"imie", L"nazwisko", L"uprawnienia przegubowe"};
break;
case 1:
labels={L"id", L"liczba miejsc", L"przegubowy", L"napęd"};
break;
case 2:
labels={L"id kierowcy", L"id autobusu"};
break;
case 3:
labels={L"id kierowca-autobus", L"godzina odjazdu", L"numer linii", L"kierunek powrotny"};
break;
case 4:
labels={L"numer linii", L"kierunek1", L"kierunek2"};
break;
case 5:
labels={L"nazwa"};
break;
case 6:
labels={L"id przystanku", L"numer linii", L"czas dojazdu", L"kolejnosc"};
break;
case 7:
case 8:
labels={L"login", L"hasło"};
break;
}
col_n = labels.size();
Insertion *inFrame = new BusApp_Insertion(this);
// Grid
inFrame->to_insert->CreateGrid( 1, col_n );
inFrame->to_insert->SetRowSize(0,25);
for(int i=0; i<col_n; ++i) inFrame->to_insert->SetColSize(i,150);
inFrame->to_insert->EnableEditing( true );
inFrame->to_insert->EnableGridLines( true );
inFrame->to_insert->EnableDragGridSize( false );
inFrame->to_insert->SetMargins( 0, 0 );
for(int i=0; i<col_n; ++i) inFrame->to_insert->SetColLabelValue(i,labels[i]);
inFrame->Show(true);
}
void BusApp_main_window::set_lines_list(size_t s, wxString* lst){
line_boxChoices = wxArrayString(s, lst);
line_box->Set(line_boxChoices);
}
void BusApp_main_window::set_stops_list(size_t s, wxString* lst, std::vector<int> &ids){
bus_stop_boxChoices = wxArrayString(s, lst);
bus_stop_ids=ids;
beg_box->Set(bus_stop_boxChoices);
end_box->Set(bus_stop_boxChoices);
}
void BusApp_main_window::set_buses_list(size_t s, wxString* lst){
bus_boxChoices = wxArrayString(s, lst);
bus_box->Set(bus_boxChoices);
}
void BusApp_main_window::add_line(wxString str){
line_boxChoices.Add(str);
line_box->Append(str);
}
void BusApp_main_window::add_stop(wxString str, int id){
bus_stop_boxChoices.Add(str);
bus_stop_ids.push_back(id);
beg_box->Append(str);
end_box->Append(str);
}
void BusApp_main_window::add_bus(wxString str){
bus_boxChoices.Add(str);
bus_box->Append(str);
}