Professional Documents
Culture Documents
Code TMDT
Code TMDT
Code TMDT
Tạo database
2. Tạo thư mục ảnh
3. Nhập dl vào database
4. Tạo fooder css add new item web style sheet
/*Reset css*/
*{
padding:0;
margin:0;
list-style:none;
}
.css_danhmuc{
text-decoration:none;
font-family:Arial;
color:black;
cursor:pointer;
text-transform:uppercase;
padding-bottom:80px;
font-weight:bold;
}
.css_danhmuc:hover{
color:blue;
}
.banner_img{
object-fit:cover;
width:100%;
height:200px;
}
header {
background-image: url('../images/bg_img.jpg');
}
.css-link_btn{
color:black;
font-size:20px;
text-decoration:none;
font-weight:bold;
padding:20px 0px;
}
.item-container{
padding-left:10px;
margin-bottom:10px;
}
.item-container:hover .css-link_btn {
color: #2d58ff;
}
.item-container div:nth-child(2){
margin-bottom:8px;
}
.bold{
font-weight:bold;
}
.item-label-header{
font-weight:bold;
font-size:24px;
}
.margin-right{
margin-right: 16px;
}
WEB CONFIG :
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
</system.web>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" warningLevel="4"
compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" warningLevel="4"
compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\"
/optionInfer+" />
</compilers>
</system.codedom>
</configuration>
namespace HAOLONG_BANHOA
{
public class Lopketnoi : System.Web.UI.Page
{
//Khai bao bien
SqlConnection con;
<!DOCTYPE html>
<html>
<head runat="server">
<title>TRANG WEB BÁN HOA</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<%--Cách 2--%>
<center>
<img src="images/banner.jpg" />
</center>
</header>
<div>
<table style="width: 100%">
<%--1 hàng tr -- 3 cột td--%>
<tr>
<%--Phần danh mục--%>
<td style="width: 30%">
<center>
<h1 style="font-weight: bold; margin-bottom: 10px;">DANH MỤC
HOA</h1>
<asp:DataList ID="dl_DanhMuc" runat="server">
<ItemTemplate>
<asp:LinkButton CssClass="css_danhmuc"
ID="LinkButton1" runat="server" Text='<%# Eval("TENDM") %>' OnClick="LinkButton1_Click"
CommandArgument='<%# Eval("MADM") %>'></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
</center>
</td>
FN 7:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace HAOLONG_BANHOA
{
public partial class MasterPage : System.Web.UI.MasterPage
{
//Khai báo chuỗi kết nối
Lopketnoi kn = new Lopketnoi();
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) return;
try
{
//Lấy dữ liệu ra rồi đổ vào data table
DataTable dt = kn.getData(sql);
//Lấy dữ liệu từ dt đổ vào datalist
dl_DanhMuc.DataSource = dt;
dl_DanhMuc.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
string sql = "SELECT * FROM KHACHHANG WHERE TENDN='" + tendn + "' AND
MATKHAU='"+ matkh + "'";
DataTable dt = kn.getData(sql);
//Kiểm tra nếu trong bảng có thì chuyển sang trang Default
if (dt.Rows.Count > 0)
{
Response.Cookies["tendn"].Value = tendn;
Response.Redirect("Default.aspx");
}
//Nếu sai thì đưa ra thông báo
else
{
Login1.FailureText = "Tên đăng nhập hoặc mật khẩu không đúng";
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace HAOLONG_BANHOA
{
public partial class Default : System.Web.UI.Page
{
//Khai báo kết nối
Lopketnoi kn = new Lopketnoi();
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) return;
dl_HangHoa.DataSource = dt;
dl_HangHoa.DataBind();
}
catch { }
}
}
}
namespace HAOLONG_BANHOA
{
public partial class Chitietsp : System.Web.UI.Page
{
//Lấy tên đăng nhập được nhập vào login rồi Lưu vào biến tendangnhap
string tendangnhap = Request.Cookies["tendn"].Value + "";
//Chuỗi lệnh sql tìm các đơn hàng của người dùng đó
string sql_dh = "SELECT * FROM DONHANG WHERE TENDN='" + tendangnhap + "'
AND MAHANG="+mahang+"";
DataTable dt = kn.getData(sql_dh);
if (dt.Rows.Count > 0)
{
//UPDATE : Cập nhật thêm số lượng hàng
// Lưu ý : Trong csdl cái tabel mình thiết kế thứ tự các cột như thế
nào thì dòng ni mình phải add lần lượt các giá trị y như thế
// Lỗi nằm ở phần INSERT NI , do thứ tự của video thứ 15 ko giống với
thiết kế của csdl
str_sql = "INSERT INTO DONHANG VALUES('" + tendangnhap + "'," +
mahang + "," + soluong + ")";
}
//Reload lại trang để thấy
int row = kn.updateData(str_sql);
//Kiểm tra lại hàng và thông báo
if (row > 0)
chitiet_notifi.Text = "Mua hàng thành công!";
else
chitiet_notifi.Text = "Mua hàng không thành công";
}
}
}
}
namespace HAOLONG_BANHOA
{
/// <summary>
/// dl_ChiTiet control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.DataList dl_ChiTiet;
/// <summary>
/// chitiet_notifi control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label chitiet_notifi;
}
}
Giỏ hang.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
namespace HAOLONG_BANHOA
{
public partial class GioHang : System.Web.UI.Page
{
//Khai bao chuoi ket noi
Lopketnoi kn = new Lopketnoi();
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) return;
//Kiểm tra có tên đăng nhập không
if (Request.Cookies["tendn"] == null) return;
DocDL();
}
DataTable dt = kn.getData(sql);
dl_GioHang.DataSource = dt;
dl_GioHang.DataBind();
}
//SỬA
protected void Button1_Click(object sender, EventArgs e)
{
//Kiểm tra có tên đăng nhập không
if (Request.Cookies["tendn"] == null) return;
//Lấy giá trị tên đăng nhập được lưu trên client rồi chuyển nó thành chuỗi
xong gán cho biến tendn
string tendn = Request.Cookies["tendn"].Value;
//Từ thẻ button tìm được thoát ra ngoài tìm thẻ cha
GridViewRow item = (GridViewRow)bt.Parent.Parent; // thẻ cha lớn nhất là
<asp:GridView ID="dl_GioHang" runat="server" AutoGenerateColumns="False">
//Đứng từ thẻ cha lớn nhất đi tìm thẻ con TEXTBOX có id là txtSoLuong , xong
chuyển nó thành tex rồi gán cho string soluong
string soluong = ((TextBox)item.FindControl("txtSoLuong")).Text;
//XOÁ
protected void LinkButton2_Click(object sender, EventArgs e)
{
//Kiểm tra có tên đăng nhập không
if (Request.Cookies["tendn"] == null) return;
//Lấy giá trị tên đăng nhập được lưu trên client rồi chuyển nó thành chuỗi
xong gán cho biến tendn
string tendn = Request.Cookies["tendn"].Value;
namespace HAOLONG_BANHOA
{
/// <summary>
/// dl_GioHang control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.GridView dl_GioHang;
/// <summary>
/// GioHang_Notifi control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Label GioHang_Notifi;
}
}