Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
project-melon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
65160381
project-melon
Commits
e16f5dde
Commit
e16f5dde
authored
3 months ago
by
65160381
Browse files
Options
Downloads
Patches
Plain Diff
Update 3 files
- /views/order.ejs - /controllers/orderController.js - /db.js
parent
cfeffbc4
No related branches found
No related tags found
No related merge requests found
Pipeline
#537
passed with warnings
3 months ago
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
controllers/orderController.js
+20
-11
20 additions, 11 deletions
controllers/orderController.js
db.js
+7
-1
7 additions, 1 deletion
db.js
views/order.ejs
+39
-152
39 additions, 152 deletions
views/order.ejs
with
66 additions
and
164 deletions
controllers/orderController.js
+
20
−
11
View file @
e16f5dde
// แสดงหน้าสั่งซื้อ
exports
.
showOrderPage
=
(
req
,
res
)
=>
{
if
(
!
req
.
session
.
userId
)
{
req
.
flash
(
'
error
'
,
'
คุณต้องเข้าสู่ระบบก่อนถึงจะ
สั่งซื้อ
ได้
'
);
req
.
flash
(
'
error
'
,
'
คุณต้องเข้าสู่ระบบก่อนถึงจะ
เพิ่มสินค้า
ได้
'
);
return
res
.
redirect
(
'
/login
'
);
}
res
.
render
(
'
order
'
,
{
title
:
'
หน้าสั่งซื้อ
'
});
res
.
render
(
'
order
'
,
{
title
:
'
เพิ่มสินค้า
'
});
};
//
ส่งคำสั่งซื้อ
//
บันทึกสินค้าใหม่
exports
.
submitOrder
=
(
req
,
res
)
=>
{
const
{
product
Id
,
quantity
,
address
}
=
req
.
body
;
const
{
product
Name
,
price
,
quantity
,
description
}
=
req
.
body
;
// ตรวจสอบ
ความถูกต้องและกระบวนการสั่งซื้อ
if
(
!
product
Id
||
!
quantity
||
!
address
)
{
// ตรวจสอบ
ว่าได้กรอกข้อมูลครบหรือไม่
if
(
!
product
Name
||
!
price
||
!
quantity
||
!
description
)
{
req
.
flash
(
'
error
'
,
'
กรุณากรอกข้อมูลให้ครบถ้วน
'
);
return
res
.
redirect
(
'
/order
'
);
}
// สมมุติว่าบันทึกคำสั่งซื้อในฐานข้อมูล
// db.saveOrder({ productId, quantity, address, userId: req.session.userId });
// สมมุติว่าบันทึกข้อมูลสินค้าในฐานข้อมูล
// ตัวอย่างการใช้ MySQL (ตัวอย่างนี้ใช้ `mysql2`):
const
db
=
require
(
'
../db
'
);
// เชื่อมต่อฐานข้อมูล
req
.
flash
(
'
success
'
,
'
คำสั่งซื้อของคุณถูกบันทึกเรียบร้อยแล้ว!
'
);
const
query
=
'
INSERT INTO products (product_name, price, quantity, description) VALUES (?, ?, ?, ?)
'
;
db
.
execute
(
query
,
[
productName
,
price
,
quantity
,
description
])
.
then
(()
=>
{
req
.
flash
(
'
success
'
,
'
สินค้าได้ถูกเพิ่มเรียบร้อยแล้ว!
'
);
res
.
redirect
(
'
/order
'
);
})
.
catch
(
err
=>
{
req
.
flash
(
'
error
'
,
'
เกิดข้อผิดพลาดในการเพิ่มสินค้า
'
);
res
.
redirect
(
'
/order
'
);
});
};
\ No newline at end of file
This diff is collapsed.
Click to expand it.
db.js
+
7
−
1
View file @
e16f5dde
...
...
@@ -10,5 +10,11 @@ const pool = mysql.createPool({
connectionLimit
:
10
,
queueLimit
:
0
});
db
.
connect
((
err
)
=>
{
if
(
err
)
{
console
.
error
(
'
Error connecting to the database:
'
,
err
);
}
else
{
console
.
log
(
'
Connected to the database
'
);
}
});
module
.
exports
=
pool
;
This diff is collapsed.
Click to expand it.
views/order.ejs
+
39
−
152
View file @
e16f5dde
<!DOCTYPE html>
<html
lang=
"
en
"
>
<html
lang=
"
th
"
>
<head>
<!-- basic -->
<meta
charset=
"utf-8"
>
<meta
http-equiv=
"X-UA-Compatible"
content=
"IE=edge"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1"
>
<title>
ASA
</title>
<meta
name=
"keywords"
content=
""
>
<meta
name=
"description"
content=
""
>
<meta
name=
"author"
content=
""
>
<!-- bootstrap css -->
<link
rel=
"stylesheet"
type=
"text/css"
href=
"css/bootstrap.min.css"
>
<!-- style css -->
<link
rel=
"stylesheet"
type=
"text/css"
href=
"css/style.css"
>
<!-- Responsive-->
<link
rel=
"stylesheet"
href=
"css/responsive.css"
>
<!-- fevicon -->
<link
rel=
"icon"
href=
"images/fevicon.png"
type=
"image/gif"
/>
<!-- Scrollbar Custom CSS -->
<link
rel=
"stylesheet"
href=
"css/jquery.mCustomScrollbar.min.css"
>
<!-- Tweaks for older IEs-->
<link
rel=
"stylesheet"
href=
"https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css"
>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
เพิ่มสินค้า
</title>
<link
rel=
"stylesheet"
href=
"/css/style.css"
>
</head>
<body>
<!--header section start -->
<div
class=
"header_section"
>
<nav
class=
"navbar navbar-expand-lg navbar-light bg-dark"
>
<div
class=
"logo"
><a
href=
"/"
><img
src=
"images/logo.png"
></a></div>
<button
class=
"navbar-toggler"
type=
"button"
data-toggle=
"collapse"
data-target=
"#navbarNav"
aria-controls=
"navbarNav"
aria-expanded=
"false"
aria-label=
"Toggle navigation"
>
<span
class=
"navbar-toggler-icon"
></span>
</button>
<div
class=
"collapse navbar-collapse"
id=
"navbarNav"
>
<ul
class=
"navbar-nav ml-auto"
>
<li
class=
"nav-item active"
>
<a
class=
"nav-link"
href=
"/"
>
Home
</a>
</li>
<
%
if
(
loggedIn
)
{
%
>
<li
class=
"nav-item"
>
<a
class=
"nav-link text-danger"
href=
"/logout"
>
Logout
</a>
</li>
<
%
}
%
>
<
%
if
(!
loggedIn
)
{
%
>
<li
class=
"nav-item"
>
<a
class=
"nav-link"
href=
"/login"
>
Login
</a>
</li>
<li
class=
"nav-item"
>
<a
class=
"nav-link"
href=
"/register"
>
Register
</a>
</li>
<
%
}
%
>
<li
class=
"nav-item"
>
<a
class=
"nav-link"
href=
"#"
><i
class=
"fa fa-search"
aria-hidden=
"true"
></i></a>
</li>
</ul>
</div>
</nav>
</div>
<!--header section end -->
<h1>
เพิ่มสินค้าใหม่
</h1>
<!-- Add Product section start -->
<div
class=
"add_product_section layout_padding"
>
<div
class=
"container"
>
<h1
class=
"gallery_taital"
>
Add New Product
</h1>
<
%
if
(
loggedIn
)
{
%
>
<form
action=
"/product/add"
method=
"POST"
enctype=
"multipart/form-data"
>
<!-- Show error message -->
<
%
if
(
message
&&
message.length
>
0) { %>
<div
class=
"alert alert-danger"
role=
"alert"
>
<
%=
message
%
>
<
%
if
(
flash.error
&&
flash.error.length
>
0) { %>
<div
class=
"alert alert-danger"
>
<
%=
flash.error
%
>
</div>
<
%
}
%
>
<
%
if
(
flash.success
&&
flash.success.length
>
0) { %>
<div
class=
"alert alert-success"
>
<
%=
flash.success
%
>
</div>
<
%
}
%
>
<div
class=
"form-floating mb-3"
>
<label
for=
"productName"
>
Product Name
</label>
<input
type=
"text"
class=
"form-control"
id=
"productName"
name=
"product_name"
placeholder=
"Product Name"
required
>
<form
action=
"/order"
method=
"POST"
>
<div
class=
"form-group"
>
<label
for=
"productName"
>
ชื่อสินค้า:
</label>
<input
type=
"text"
id=
"productName"
name=
"productName"
class=
"form-control"
required
>
</div>
<div
class=
"form-
floating mb-3
"
>
<label
for=
"pr
oductDescription"
>
Product Description
</label>
<textarea
class=
"form-control"
id=
"productDescription"
name=
"product_description"
placeholder=
"Product Description"
required
></textarea
>
<div
class=
"form-
group
"
>
<label
for=
"pr
ice"
>
ราคา:
</label>
<input
type=
"number"
id=
"price"
name=
"price"
class=
"form-control"
required
>
</div>
<div
class=
"form-
floating mb-3
"
>
<label
for=
"
productPrice"
>
Product Price
</label>
<input
type=
"number"
class=
"form-control"
id=
"productPrice"
name=
"product_price"
placeholder=
"Product Price
"
required
>
<div
class=
"form-
group
"
>
<label
for=
"
quantity"
>
จำนวน:
</label>
<input
type=
"number"
id=
"quantity"
name=
"quantity"
class=
"form-control
"
required
>
</div>
<div
class=
"form-
floating mb-3
"
>
<label
for=
"
productImage"
>
Product Image
</label>
<input
type=
"file"
class=
"form-control"
id=
"productImage"
name=
"product_image"
required
>
<div
class=
"form-
group
"
>
<label
for=
"
description"
>
คำอธิบายสินค้า:
</label>
<textarea
id=
"description"
name=
"description"
class=
"form-control"
required
></textarea
>
</div>
<button
class=
"btn btn-primary
w-100 py-2"
type=
"submit"
>
Add Product
</button>
<button
type=
"submit"
class=
"btn btn-primary
"
>
เพิ่มสินค้า
</button>
</form>
<
%
}
else
{
%
>
<p>
Please log in to add a product.
</p>
<
%
}
%
>
</div>
</div>
<!-- Add Product section end -->
<!-- footer section start -->
<div
class=
"footer_section layout_padding"
>
<div
class=
"container"
>
<div
class=
"row"
>
<div
class=
"col-lg-3 col-sm-6"
>
<h3
class=
"useful_text"
>
About
</h3>
<p
class=
"footer_text"
>
Let's use our time to do good things and earn volunteer hours.
</p>
</div>
<div
class=
"col-lg-3 col-sm-6"
>
<h3
class=
"useful_text"
>
Menu
</h3>
<div
class=
"footer_menu"
>
<ul>
<li><a
href=
"/"
>
Home
</a></li>
</ul>
</div>
</div>
<div
class=
"col-lg-3 col-sm-6"
>
<h3
class=
"useful_text"
>
Contact Us
</h3>
<div
class=
"location_text"
>
<ul>
<li>
<a
href=
"#"
>
<i
class=
"fa fa-map-marker"
aria-hidden=
"true"
></i><span
class=
"padding_left_10"
>
Address : Loram Ipusm
</span>
</a>
</li>
<li>
<a
href=
"#"
>
<i
class=
"fa fa-phone"
aria-hidden=
"true"
></i><span
class=
"padding_left_10"
>
Call : +01 1234567890
</span>
</a>
</li>
<li>
<a
href=
"#"
>
<i
class=
"fa fa-envelope"
aria-hidden=
"true"
></i><span
class=
"padding_left_10"
>
Email : demo@gmail.com
</span>
</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<!-- footer section end -->
<!-- copyright section start -->
<div
class=
"copyright_section"
>
<div
class=
"container"
>
<p
class=
"copyright_text"
>
@ASA 2025
</p>
</div>
</div>
<!-- copyright section end -->
<!-- Javascript files-->
<script
src=
"js/jquery.min.js"
></script>
<script
src=
"js/popper.min.js"
></script>
<script
src=
"js/bootstrap.bundle.min.js"
></script>
<script
src=
"js/jquery-3.0.0.min.js"
></script>
<script
src=
"js/plugin.js"
></script>
<!-- sidebar -->
<script
src=
"js/jquery.mCustomScrollbar.concat.min.js"
></script>
<script
src=
"js/custom.js"
></script>
</body>
</html>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment