-
Notifications
You must be signed in to change notification settings - Fork 0
/
parts.asp
180 lines (123 loc) · 5.48 KB
/
parts.asp
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Add Parts</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
</head>
<body>
<!--#include file ="Admin/navbar.asp"-->
<h1 style="text-align: center; margin-top: 5%;">Add Parts (Company)</h1>
<div class="" style="margin-left: 30%; margin-right: 30%;">
<form method="post" id="form1">
<div class="mb-3">
<label for="" class="form-label">Parts Name</label>
<input type="text" class="form-control" name="name" id="" aria-describedby="">
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">Price</label>
<input type="text" name="price" class="form-control" id="">
</div>
<div class="mb-3">
<label for="exampleInputPassword1" class="form-label">Quantity</label>
<input type="text" name="quantity" class="form-control" id="">
</div>
<!-- <div class="input-group mb-3">
<label class="input-group-text" for="inputGroupSelect01">Producer ID</label>
<select class="form-select" name="maker_id" id="dropdown">
<option selected>Choose...</option>
<option value="1">One</option>
<option value="2">Two</option>
<option value="3">Three</option>
</select>
</div> -->
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<textarea id="xmlSrc" cols="70" rows="5"></textarea>
<div id="results">
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js"
integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
crossorigin="anonymous"></script>
<script>
if(localStorage.getItem("name") === "Admin"){
//alert("Yes")
var btn = document.getElementById("logout")
btn.onclick = function () {
localStorage.removeItem("name")
location.reload()
}
}
else{
window.location.replace("http://localhost/project/admin/adminlogin.asp")
// alert("No")
}
const parts_id_sku = Math.floor(Math.random() * (20000 - 2000 + 1)) + 2000;
function buildXmlFromForm(form) {
var xml = $('<XMLDocument />');
xml.append(
$('<Parts />').append(
$('<Name />').text(form.find("input[name='name']").val())
).append(
$('<Price />').text(form.find("input[name='price']").val())
).append(
$('<Quantity />').text(form.find("input[name='quantity']").val())
).append(
// $('<maker_id />').text(form.find("select[name='maker_id']").val())
$('<maker_id />').text(1)
).append(
// $('<maker_id />').text(form.find("select[name='maker_id']").val())
$('<parts_id_sku />').text(parts_id_sku)
)
);
return xml.html();
}
// you should use POST or PUT method (not GET) to post xml-data to server side
$("#form1").submit(function (event) {
event.preventDefault();
$("#results").append("<ul></ul>");
var xmlString = buildXmlFromForm($(this));
$("#xmlSrc").val(xmlString);
$.ajax({
type: "POST",
dataType: 'xml',
// url: 'response.xml',
url: 'partsInsert.asp',
data: xmlString,
// success: function(respData) {
// $("<li></li>").html("ok: "+respData).appendTo("#results ul");
// // $post("myfile.asp",{libid:respData})
// console.log(respData);
// },
// error: function(errorData) {
// $("<li></li>").html("error: "+errorData.statusText).appendTo("#results ul");
// console.log(errorData);
// }
});
$.post("partsInsert.asp", {
file: xmlString
})
console.log(xmlString)
});
$.ajax({
type: 'GET',
url: 'http://localhost/project/supplierfulllist.asp', // The file path.
dataType: 'xml',
success: function (xml) {
//find all book tags, loop them and append to table body
$(xml).find('supplier').each(function () {
myData = xml;
$('#dropdown').append(
'<option value=' + $(this).find('supplier_id').text() + ' >' + $(this).find('name').text() + '</option> '
);
});
}
});
</script>
</body>
</html>