-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_technician.cpp
122 lines (117 loc) · 3.43 KB
/
add_technician.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
#include "add_technician.h"
#include "ui_add_technician.h"
extern int count_technician;
extern Technician technician[1000];
extern bool isread;
add_technician::add_technician(QWidget *parent) :
QWidget(parent),
ui(new Ui::add_technician)
{
ui->setupUi(this);
}
add_technician::~add_technician()
{
delete ui;
}
void add_technician::on_pushButton_clicked()
{
QString name = ui->textEdit_name->toPlainText();
QString hours = ui->textEdit_hours->toPlainText();
QString hoursalary = ui->textEdit_hoursalary->toPlainText();
char temp[1000];
QByteArray ba = hours.toLocal8Bit();
memcpy(temp, ba.data(), ba.size() + 1);
int i, point_location = -1, length = strlen(temp);
bool flaga = true, flagb = true;
double newhours = 0, newhoursalary = 0;
if(length == 0) {
flaga = false;
}
for(i = 0; i < length; i++) {
if(temp[i] < '.' || (temp[i] > '.' && temp[i] < '0') || temp[i] > '9') {
flaga = false;
break;
}
if(temp[i] == '.' && (point_location != -1)) {
flaga = false;
break;
}
if(temp[i] == '.') {
if(i == 0 || i == length - 1) {
flaga = false;
break;
}
point_location = i;
}
}
if(flaga) {
for(i = 0; i < length; i++) {
if(point_location == -1) {
newhours += (temp[i] - '0') * pow(10, length - i - 1);
}
else {
if(i < point_location) {
newhours += (temp[i] - '0') * pow(10, point_location - i - 1);
}
if(i > point_location) {
newhours += (temp[i] - '0') * pow(0.1, i - point_location);
}
}
}
}
else {
ui->textEdit_hours->clear();
}
ba = hoursalary.toLocal8Bit();
memcpy(temp, ba.data(), ba.size() + 1);
point_location = -1, length = strlen(temp);
if(length == 0) {
flagb = false;
}
for(i = 0; i < length; i++) {
if(temp[i] < '.' || (temp[i] > '.' && temp[i] < '0') || temp[i] > '9') {
flagb = false;
break;
}
if(temp[i] == '.' && (point_location != -1)) {
flagb = false;
break;
}
if(temp[i] == '.') {
if(i == 0 || i == length - 1) {
flagb = false;
break;
}
point_location = i;
}
}
if(flagb) {
for(i = 0; i < length; i++) {
if(point_location == -1) {
newhoursalary += (temp[i] - '0') * pow(10, length - i - 1);
}
else {
if(i < point_location) {
newhoursalary += (temp[i] - '0') * pow(10, point_location - i - 1);
}
if(i > point_location) {
newhoursalary += (temp[i] - '0') * pow(0.1, i - point_location);
}
}
}
}
else {
ui->textEdit_hoursalary->clear();
}
if(flaga == false || flagb == false) {
QMessageBox::warning(this, "警告", "输入有误,请重新输入");
}
if(flaga && flagb) {
count_technician++;
technician[count_technician].set(name, newhours, newhoursalary);
ui->textEdit_name->clear();
ui->textEdit_hours->clear();
ui->textEdit_hoursalary->clear();
isread = true;
}
}