-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.pl
162 lines (110 loc) · 4.15 KB
/
index.pl
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
#!/usr/bin/env perl
use Mojolicious::Lite;
use strict;
use DBI();
# Render template "templates/BuildHistory.html.ep"
any '/' => sub {
my @allItems;
itemListGet(\@allItems, "");
my $self = shift;
$self->stash(
allItemsRef => \@allItems
);
$self->render('index');
};
any '/tmpListAddPrint' => sub {
my $self = shift;
my $itemNo = $self->param('itemNo');
my $action = $self->param('action');
if ($itemNo > 0) {
if ($action eq "inc") {
itemListUpdate($itemNo, "tmpListCnt = tmpListCnt + 1");
}
elsif ($action eq "dec") {
itemListUpdate($itemNo, "tmpListCnt = tmpListCnt - 1");
}
elsif ($action eq "del") {
itemListUpdate($itemNo, "tmpListCnt = 0");
}
}
my @tmpList;
itemListGet(\@tmpList, "WHERE tmpListCnt > 0");
my $tmpListPrint = "";
my $listNum = 1;
foreach my $row (@tmpList) {
$tmpListPrint = $tmpListPrint . "<tr>
<td>$listNum</td>
<td>@$row[1]</td>
<td>@$row[5]
<span id=inc@$row[0] class=\"glyphicon glyphicon-circle-arrow-up\"></span>
<span id=dec@$row[0] class=\"glyphicon glyphicon-circle-arrow-down\"></span>
<span id=del@$row[0] class=\"glyphicon glyphicon-remove-sign\"></span>
</td>
</tr>";
$listNum++;
}
$self->render(text => $tmpListPrint);
};
any '/selectedListPrint' => sub {
my $self = shift;
my @tmpList;
itemListGet(\@tmpList, "WHERE tmpListCnt > 0");
my $tmpListPrint = "";
my $listNum = 1;
foreach my $row (@tmpList) {
my $itemStatus;
if (@$row[6] == @$row[5]) {
$itemStatus = "<span class=\"label label-success\">Good to Go</span>";
} elsif (@$row[6] > @$row[5]) {
$itemStatus = "<span class=\"label label-danger\">Excessive Items</span>";
} else {
$itemStatus = "<span class=\"label label-warning\">Missing Items</span>";
}
$tmpListPrint = $tmpListPrint . "<tr>
<td>$listNum</td>
<td>@$row[1]</td>
<td>@$row[6] out of @$row[5]</td>
<td>$itemStatus</td>
</tr>";
$listNum++;
}
$self->render(text => $tmpListPrint);
};
any '/RFID_checkOut' => sub {
my @allItems;
itemListGet(\@allItems, "");
my $self = shift;
$self->stash(
allItemsRef => \@allItems
);
$self->render('RFID_checkOut');
};
app->start;
sub itemListUpdate() {
my $itemNo = $_[0];
my $sqlCmd = $_[1];
# Connect to the database.
my $dbh = DBI->connect("DBI:mysql:database=RFID_CheckList;host=localhost",
"root", "123456",
{'RaiseError' => 1});
my $sql = "UPDATE itemList SET " . $sqlCmd . " WHERE tagNumber = $itemNo"; # the query to execute
my $sth = $dbh->prepare($sql); # prepare the query
$sth->execute(); # execute the query
}
sub itemListGet() {
my $array_ref = $_[0];
my $sql_cmd = $_[1];
# Connect to the database.
my $dbh = DBI->connect("DBI:mysql:database=RFID_CheckList;host=localhost",
"root", "123456",
{'RaiseError' => 1});
my $sql = "select * from itemList $sql_cmd"; # the query to execute
my $sth = $dbh->prepare($sql); # prepare the query
$sth->execute(); # execute the query
my @row;
my $table_row = 0;
while (@row = $sth->fetchrow_array) { # retrieve one row
$ { $array_ref }[$table_row] = [@row];
$table_row++;
}
}