-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwin-on_create_order_click.cpp
58 lines (48 loc) · 1.75 KB
/
mainwin-on_create_order_click.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
#include "mainwin.h"
#include <exception>
#include <stdexcept>
#include <iostream>
#include <sstream>
void Mainwin::on_create_order_click() {
if (_emp->num_containers() == 0 || _emp->num_scoops() == 0) {
Gtk::MessageDialog dialog{*this, "At least 1 container and 1 scoop\nmust be created first"};
dialog.run();
dialog.close();
return;
}
// Select a customer or quit
int customer = select_customer();
if (customer < 0) return;
Mice::Order order{_emp->customer(customer), _emp->next_id()};
// Add servings until the order is complete
int id = 0;
while(true) {
try {
Mice::Serving serving = create_serving();
// Convert the order to text using a string stream
std::ostringstream os;
os << serving << std::endl;
// Display the receipt in a dialog
Gtk::MessageDialog dialog{*this, "Serving " + std::to_string(++id)};
dialog.set_secondary_text("<tt>" + os.str() + "</tt>", true);
dialog.run();
dialog.close();
order.add_serving(serving);
} catch(std::runtime_error e) { // User canceled order
break;
}
}
// If any servings were added, add to orders and display the receipt
if (order.servings().size() > 0) {
// Add to the list of orders
_emp->add_order(order);
// Convert the order to text using a string stream
std::ostringstream os;
os << order << std::endl;
// Display the receipt in a dialog
Gtk::MessageDialog dialog{*this, "Order " + std::to_string(order.id())};
dialog.set_secondary_text("<tt>" + os.str() + "</tt>", true);
dialog.run();
dialog.close();
}
}