-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTGdesk_add_car_form.cpp
236 lines (205 loc) · 6.13 KB
/
TGdesk_add_car_form.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
#include "TGdesk_add_car_form.h"
TGdesk_add_car_form::TGdesk_add_car_form( wxWindow* parent )
:
add_car_form( parent )
{
}
void TGdesk_add_car_form::add_car_formOnClose( wxCloseEvent& event )
{
GetParent()->Enable();
Destroy();
}
void TGdesk_add_car_form::nameOnChar( wxKeyEvent& event )
{
event.Skip();
}
void TGdesk_add_car_form::year_bOnChar( wxKeyEvent& event )
{
auto c = event.GetKeyCode();
if(is_num(c) || c=='\b') event.Skip(); // years format witch dash and BACKSPACE
else return;
}
void TGdesk_add_car_form::year_eOnChar( wxKeyEvent& event )
{
auto c = event.GetKeyCode();
if(is_num(c) || c=='\b') event.Skip(); // years format witch dash and BACKSPACE
else return;
}
void TGdesk_add_car_form::doors_numOnChar( wxKeyEvent& event )
{
auto c = event.GetKeyCode();
if(is_num(c) || c=='\b') event.Skip(); // numbers and BACKSPACE
else return;
}
void TGdesk_add_car_form::seat_numOnChar( wxKeyEvent& event )
{
auto c = event.GetKeyCode();
if(is_num(c) || c=='\b') event.Skip(); // numbers and BACKSPACE
else return;
}
void TGdesk_add_car_form::cargoOnChar( wxKeyEvent& event )
{
auto c = event.GetKeyCode();
if(is_num(c) || c=='-' || c=='\b') event.Skip(); // years format witch dash and BACKSPACE
else return;
}
void TGdesk_add_car_form::lengthOnChar( wxKeyEvent& event )
{
auto c = event.GetKeyCode();
if(is_num(c) || c=='\b') event.Skip(); // numbers and BACKSPACE
else return;
}
void TGdesk_add_car_form::widthOnChar( wxKeyEvent& event )
{
auto c = event.GetKeyCode();
if(is_num(c) || c=='\b') event.Skip(); // numbers and BACKSPACE
else return;
}
void TGdesk_add_car_form::heightOnChar( wxKeyEvent& event )
{
auto c = event.GetKeyCode();
if(is_num(c) || c=='\b') event.Skip(); // numbers and BACKSPACE
else return;
}
void TGdesk_add_car_form::axesOnChar( wxKeyEvent& event )
{
auto c = event.GetKeyCode();
if(is_num(c) || c=='\b') event.Skip(); // numbers and BACKSPACE
else return;
}
void TGdesk_add_car_form::fweelsOnChar( wxKeyEvent& event )
{
auto c = event.GetKeyCode();
if(is_num(c) || c=='\b') event.Skip(); // numbers and BACKSPACE
else return;
}
void TGdesk_add_car_form::rweelsOnChar( wxKeyEvent& event )
{
auto c = event.GetKeyCode();
if(is_num(c) || c=='\b') event.Skip(); // numbers and BACKSPACE
else return;
}
void TGdesk_add_car_form::descrOnChar( wxKeyEvent& event )
{
if(event.GetKeyCode() == '\b') event.Skip();
else if(descr->GetValue().size() >= 150) return;
else event.Skip();
}
void TGdesk_add_car_form::priceOnChar( wxKeyEvent& event )
{
static char c;
if(c=='\b')
dot=price->GetValue().rfind('.')!=wxString::npos || price->GetValue().rfind(',')!=wxString::npos;
c = event.GetKeyCode();
if(is_num(c) || c=='\b')event.Skip();
else if(c==',' || c=='.'){
if(dot) return;
else{
dot = true;
event.Skip();
}
}
else return;
}
void TGdesk_add_car_form::phone_numOnChar( wxKeyEvent& event )
{
auto c = event.GetKeyCode();
if(is_num(c) || c=='\b'){
if(phone_num->GetValue().size()<9 || c=='\b')
event.Skip(); // years format witch dash and BACKSPACE
else
return;
}
else return;
}
void TGdesk_add_car_form::emailOnChar( wxKeyEvent& event )
{
event.Skip();
}
void TGdesk_add_car_form::descr_offerOnChar( wxKeyEvent& event )
{
if(event.GetKeyCode() == '\b') event.Skip();
else if(descr->GetValue().size() >= 300) return;
else event.Skip();
}
void TGdesk_add_car_form::backOnButtonClick( wxCommandEvent& event )
{
Close();
}
void TGdesk_add_car_form::enterOnButtonClick( wxCommandEvent& event )
{
bool empty = year_b->GetLineLength(0) == 0;
empty |= year_e->GetLineLength(0) == 0;
empty |= name->GetLineLength(0) == 0;
empty |= doors_num->GetLineLength(0) == 0;
empty |= seat_num->GetLineLength(0) == 0;
empty |= cargo->GetLineLength(0) == 0;
empty |= length->GetLineLength(0) == 0;
empty |= width->GetLineLength(0) == 0;
empty |= height->GetLineLength(0) == 0;
empty |= axes->GetLineLength(0) == 0;
empty |= fweels->GetLineLength(0) == 0;
empty |= rweels->GetLineLength(0) == 0;
empty |= descr->GetValue().size() == 0;
empty |= descr_offer->GetValue().size() == 0;
empty |= price->GetValue().size() == 0;
empty |= email->GetValue().size() == 0;
empty |= phone_num->GetValue().size() == 0;
if(empty){
wxMessageDialog dlg(this, wxT("Wypełnij puste pola."), wxMessageBoxCaptionStr, wxOK|wxICON_ERROR);
dlg.ShowModal();
} else if(TGdesk_login_dial::mail_check(email->GetValue().ToStdString()) == false){
wxMessageDialog dlg(this, wxT("Błędny email."), wxMessageBoxCaptionStr, wxOK|wxICON_ERROR);
dlg.ShowModal();
} else {
wxMessageDialog dlg(this, wxT("Pomyślnie wprowadzono pojazd."), wxMessageBoxCaptionStr, wxOK);
dlg.ShowModal();
std::string client_id = dynamic_cast<TGdesk_main_frame*>(GetParent())->token;
size_t dot_pos = client_id.find_first_of('.');
client_id.erase(0,dot_pos+1);
dot_pos = client_id.find_last_of('.');
client_id.erase(dot_pos);
Backend_API api;
Json::Value response;
try{
response = api.post_offer(dynamic_cast<TGdesk_main_frame*>(GetParent())->token,
name->GetValue().ToStdString(),
descr->GetValue().ToStdString(),
year_b->GetValue().ToStdString(),
year_e->GetValue().ToStdString(),
doors_num->GetValue().ToStdString(),
seat_num->GetValue().ToStdString(),
cargo->GetValue().ToStdString(),
length->GetValue().ToStdString(),
width->GetValue().ToStdString(),
height->GetValue().ToStdString(),
axes->GetValue().ToStdString(),
rweels->GetValue().ToStdString(),
fweels->GetValue().ToStdString(),
gear_box->GetString(gear_box->GetSelection()).ToStdString() == "manualna" ? "manual" : "automatic",
drive_type->GetString(drive_type->GetSelection()).ToStdString(),
client_id,
price->GetValue().ToStdString(),
descr_offer->GetValue().ToStdString(),
email->GetValue().ToStdString(),
phone_num->GetValue().ToStdString()
);
} catch (std::exception& e){
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring message = converter.from_bytes(e.what());
wxMessageDialog dlg(this, message, wxMessageBoxCaptionStr, wxOK|wxICON_ERROR);
dlg.ShowModal();
return;
}
if(!(response["errors"].isNull())){
for(auto m : response["errors"]["appUser"]){
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
std::wstring message = converter.from_bytes(m.asString());
wxMessageDialog dlg(this, message, wxMessageBoxCaptionStr, wxOK|wxICON_ERROR);
dlg.ShowModal();
}
return;
}
Close();
}
}