-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.cpp
More file actions
136 lines (114 loc) · 2.66 KB
/
ui.cpp
File metadata and controls
136 lines (114 loc) · 2.66 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
#include "ui.h"
UI::UI()
{
}
void UI::printMessage(QString message)
{
std::cout << message.toStdString() << std::endl;
}
void UI::setDataBase(DBManager* dataBase)
{
db = dataBase;
}
int UI::inputMainCommands()
{
printMessage("1 - add worker");
printMessage("2 - add subordinate to some worker");
printMessage("3 - print worker salary");
printMessage("4 - exit");
int command;
std::cin.clear();
std::cin >> command;
if(!(0 < command || command > 4))
{
QString e = "Error! Unknown command!";
throw e;
}
return command;
}
void UI::recordWorker()
{
QTextStream istream(stdin);
printMessage("Enter the name of the worker");
QString name;
istream >> name;
printMessage("Enter year of employment");
int year;
std::cin >> year;
printMessage("Enter month of employment");
int month;
std::cin >> month;
printMessage("Enter day of employment");
int day;
std::cin >> day;
printMessage("Enter base salary");
int salary;
std::cin >> salary;
printMessage("Enter employee position");
printMessage("1 - employee");
printMessage("2 - manager");
printMessage("3 - sales");
int workerTypeCode;
std::cin >> workerTypeCode;
QString workerType;
switch(workerTypeCode)
{
case 1:
workerType = "empoyee";
break;
case 2:
workerType = "manager";
break;
case 3:
workerType = "sales";
break;
default:
throw "unknown command " + QString::number(workerTypeCode);
}
db->addWorker(name, year, month, day, salary, workerType);
}
void UI::recordSubordinate()
{
QTextStream istream(stdin);
printMessage("Enter superior:");
QString superior;
istream >> superior;
printMessage("Enter bubordinate:");
QString subordinate;
istream >> subordinate;
db->addSubordinate(superior, subordinate);
}
void UI::printWorkerSalary()
{
QTextStream istream(stdin);
printMessage("Enter worker name");
QString name;
istream >> name;
QSqlQuery workerQuery = db->getWorker(name);
workerQuery.next();
QString workerType = workerQuery.value(6).toString();
Employee employee;
Manager manager;
Sales sales;
if(workerType == "employee")
{
setStrategy(&employee);
}
if(workerType == "manager")
{
setStrategy(&manager);
}
if(workerType == "sales")
{
setStrategy(&sales);
}
worker->setDB(db);
double salary;
salary = worker->getSalary(name);
std::cout << salary << std::endl;
//printMessage(salary);
}
void UI::setStrategy(IWorker* strategy)
{
worker = strategy;
}