Trường Đại Học Công Nghiệp Hà Nội
Khoa Công Nghệ Thông Tin
--------------------
BÁO CÁO BÀI TẬP LỚN MÔN
Lập trình CSDL trên Web
Đề tài : Xây dựng website giới thiệu và bán các mặt hàng đồ uống.
Nhóm thực hiện:
Nhóm 4
Lớp:
CĐ Tin1_K15
Giáo viên hướng dẫn : Th.s Đỗ Ngọc Sơn
Sinh viên thực hiện:
Phạm Quang Huy
Tô Tuấn Anh
Hoàng Mạnh Tiến
Đoàn Văn Huy
Lã Chính Ngọc
Nguyễn Minh Tuấn
Hà Nội, Ngày 15, Tháng 1, Năm 2016
1
Bảng phân công công việc
Mã SV
1531060047
− Cho phép người xem có thể hiểu thêm về các loạiđồ uống khác nhau trước
khi mua
− Cho phép người xem có thể tìm kiếm nhanh nhất những sản phẩm mà họ
quan tâm theo tiêu chí tên sản phẩm hoặc giá sản phẩm.
− Tư vấn khiến thức cho các khác hàng mua sản phẩm.
− Cho phép các công ty, doanh nghiệp khác quảng cáo trên trang website của
công ty.
Phân tích thiết kế hệ thống
Cần có những trang sau:
Hiển thị tất cả các sản phẩm
Hiển thị chi tiết vè sản phẩm
Hiển thị từng loại sản phẩm
Đăng nhập vào tài khoản Admin thực hiện quyền
Trang thêm,xóa ,sửa dàng cho Admin
Trang tìm kiếm sản phẩm
3
Chương 2:Thiết kế và cài đặt chương trình
Giao diện và code 1 số trang chính
Trang Product
<asp:Content ID="Content1" ContentPlaceHolderID="main_body" Runat="Server">
<ItemTemplate>
</asp:HyperLink>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</asp:Content>
File cs
using System.Data;
using System.Data.SqlClient;
public partial class Page_Product : System.Web.UI.Page
{
Xuly xl = new Xuly();
public void HienThi()
{
DataList1.DataSource = xl.Hien();
DataList1.DataBind();
}
static DataTable tbGioHang = new DataTable();//khoi tao table chua gio hang
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack == false)
if ((int)row["Id"] == intId)
{
row["Quantity"] = (int)row["Quantity"] + 1;
goto GioHang;
}
}
tbGioHang.Rows.Add(intId, strTitle, flPrice, intQuantity);
GioHang:
Session["GioHang"] = tbGioHang;
}
protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}
Trang DetailsProduct
6
<asp:Content ID="Content1" ContentPlaceHolderID="main_body" Runat="Server">
<ItemTemplate>
<table style="width: 100%;" border="1px">
<tr>
</ItemTemplate>
</asp:DataList>
</asp:Content>
public partial class Page_DetailsProducts : System.Web.UI.Page
{
Xuly xl = new Xuly();
protected void Page_Load(object sender, EventArgs e)
{
int ID = Int32.Parse(Request.QueryString["Id"].ToString());
DataList1.DataSource = xl.HienCT(ID);
DataList1.DataBind();
}
protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
{
7
}
protected void btnAddToCart_Click(object sender, EventArgs e)
{
}
protected void btnShowCart_Click(object sender, EventArgs e)
{
}
<td style="width: 75px">
</td>
<td class="name" style="width: 90px" >
Giá:
</asp:TemplateField>
<asp:TemplateField HeaderText="Tiêu đề">
<ItemTemplate>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Đơn giá">
<ItemTemplate>
10
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Quantity" HeaderText="Số lượng" />
<asp:TemplateField HeaderText="Thành tiền">
<ItemTemplate>
</asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
</Columns>
<FooterStyle BackColor="#1C5E55" ForeColor="White" Font-Bold="True" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
load_data();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
load_data();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
11
tbGioHang.Rows.RemoveAt(e.RowIndex);
GridView1.EditIndex = -1;
load_data();
}
}
Trang Loginn
<asp:Content ID="Content1" ContentPlaceHolderID="main_body" Runat="Server">
<table align="center" width="200px">
<tr>
<td align="center" style="background-color:Purple; color:White;font-weight:bold">
Đăng nhập
</td>
</tr>
{
if (txtUserName.Text=="Huy" && txtPassword.Text=="123456")
{
Session.Contents["TrangThai"] = "OK";
Response.Redirect("Logacc.aspx");
}
else
Response.Write("Bạn đã đăng nhập sai");
}
}
13
Trang Them
<asp:Content ID="Content2" ContentPlaceHolderID="main_body" Runat="Server">
<table border="1px" cellpadding="0" cellspacing="0" style="width: 100%; height: 227px; fontweight:bold; font-size:medium ">
<tr>
<td style="height: 38px">Mã</td>
<td class="style1">
<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td style="width:150px; height: 27px;" >
Tên đồ uống:</td>
Số lượng:</td>
<td class="style4">
</asp:TextBox>
</td>
</tr>
<tr>
<td style="height: 49px">
Loại đồ uống:</td>
<td class="style5">
<asp:DropDownList ID="Droploai" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="height: 59px">
Hình ảnh:</td>
<td class="style6">
</td>
</tr>
<tr>
<td colspan="2">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="Id" HeaderText="Mã" />
<asp:BoundField DataField="Title" HeaderText="Tiêu đề" />
<asp:BoundField DataField="CategoryID" HeaderText="Loại" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</table>
</asp:Content>
public partial class Page_Them : System.Web.UI.Page
{
public void HienThi()
{
Xuly xl = new Xuly();
GridView1.DataSource = xl.Hien();
GridView1.DataBind();
}
}
protected void btnKhong_Click(object sender, EventArgs e)
{
HienThi();
}
}
Trang Sua
<asp:Content ID="Content1" ContentPlaceHolderID="main_body" Runat="Server">
<table border="1px" cellpadding="0" cellspacing="0" style="width: 100%; height: 227px; fontweight:bold; font-size:medium ">
<tr>
<td style="height: 38px">Mã</td>
<td class="style1">
<asp:TextBox ID="txtID" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
17
<td style="width:150px; height: 27px;" >
Tên sản phẩm:</td>
<td class="style2">
</asp:TextBox>
<td class="style5">
<asp:DropDownList ID="Droploai" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td style="height: 59px">
Hình ảnh:</td>
<td class="style6">
</td>
</tr>
<tr>
<td style="height: 79px" colspan="2">
18
ShowSelectButton="True" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</table>
</asp:Content>
public partial class Page_Quantri : System.Web.UI.Page
{
public void HienThi()
{
Xuly xl = new Xuly();
GridView1.DataSource = xl.Hien();
GridView1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
txtID.Enabled = false;
HienThi();
}
private void SaveFileUpload()
}
protected void btnSua_Click(object sender, EventArgs e)
{
txtTieude.Focus();
}
protected void btnGhi_Click(object sender, EventArgs e)
{
string sLoai = Droploai.SelectedValue;
string sAnh = FileUploadAnh.FileName;
Xuly xl = new Xuly(txtID.Text,txtTieude.Text, txtNoidung.Text, txtGia.Text,
txtSoluong.Text, sLoai, sAnh);
xl.Sua(txtID.Text);
HienThi();
}
protected void btnKhong_Click(object sender, EventArgs e)
{
}
}
Class Dulieu
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;
/// <summary>
/// Summary description for Dulieu
}
Class Xuly
using
using
using
using
using
using
System;
System.Collections.Generic;
System.Linq;
System.Web;
System.Data.SqlClient;
System.Data;
public class Xuly
{
Dulieu dl = new Dulieu();
string _tit, _des, _pri, _pt, _sl, _lo,_idd;
public string sl
{ get { return _sl; } set { _sl = value; } }
public string title
{ get { return _tit; } set { _tit = value; }
public string description
{ get { return _des; } set { _des = value; }
public string price
{ get { return _pri; } set { _pri = value; }
public string photo
string sql = "INSERT INTO Product(Id,Title,Description,Price,Quantity,CategoryId,Photo)
VALUES('" + Id + "',N'" + title + "',N'" + description + "','" + price + "','" + sl + "','" + loai
+ "','" + "~/images/products/" + photo + "')";
dl.CapNhat(sql);
}
public void Sua(string id)
{
string sql = "Update Product Set Title=N'" + title + "',Description=N'" + description +
"',Price='" + price + "',Quantity='" + sl + "',CategoryId='" + loai + "',Photo='" +
"~/images/products/" + photo + "' where Id='" + id + "'";
dl.CapNhat(sql);
}
public void Xoa(string id)
{
string sql = "delete from Product where Id='" + id + "'";
dl.CapNhat(sql);
}
public DataTable Tim(string ten)
{
string sql = "select Id,Title,Description,Price,CategoryId,Photo from Product where Title
like N'%" + ten + "%'";
return dl.Bang(sql);
}
public DataTable HienCT(int ma)
{
string sql = "select Id,Title,Description,Price,CategoryId,Photo from Product where
Id='"+ma+"'";
return dl.Bang(sql);
}
public DataTable Theoloai(int ID)
Class Dulieu..................................................................................................................................20
Class Xuly.....................................................................................................................................21
Kết Luận..........................................................................................................................................23
24