0% found this document useful (0 votes)
13 views2 pages

CSDL

The document describes a web application for managing flower categories and products. It includes classes for connecting to a database and retrieving data. The master page defines the layout with sections for the category list, login, and content area. Product and detail pages display lists of items and use context to pass identifiers between pages.

Uploaded by

lt12302004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

CSDL

The document describes a web application for managing flower categories and products. It includes classes for connecting to a database and retrieving data. The master page defines the layout with sections for the category list, login, and content area. Product and detail pages display lists of items and use context to pass identifiers between pages.

Uploaded by

lt12302004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Csdl :

DanhMucHoa:
MaDM:int (ko)
TenDM:Navachar50

MoTa:nvarchar50

Hoa:
TenHoa:nvarcha50

DonViTinh:nvarchar 10

HinhAnh:nvarchar50

MoTa:nvarchar max

MaDM:int (ko)

Xuly.cs
SqlConnection con;
private void connect()
{
con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=D:\newvv\WebApplication1\WebApplication1\App_Data\qlh.mdf;Integrated Security=True");
con.Open();
}
private void closeconnect()
{
if (con.State == ConnectionState.Open)
con.Close();
}
public DataTable GetData(String sql)
{
connect();
DataTable dt = new DataTable();
try
{
SqlDataAdapter adap = new SqlDataAdapter(sql, con);
adap.Fill(dt);
}
catch { dt = null; }
finally { closeconnect(); }
return dt;
}

Site1.Master

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="WebApplication1.Site1" %>

<!DOCTYPE html>

<html>
<head runat="server">
<title></title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<style>
.container {
height: 100%;
width: 100%;
}

.left {
float: left;
width: 20%;
height: auto;
}

.right {
float: right;
width: 20%;
height: auto;
}
</style>

</head>
<body>
<form id="form1" runat="server">
<div>
<div class="container">
<div class="left">
<h2>DanhMucHoa</h2>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>

<asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%# Eval("MaDM") %>' Text='<%# Eval("TenDM") %>' OnClick="LinkButton1_Click"></asp:LinkButton>

</ItemTemplate>
</asp:DataList>
</div>
<div class="right">
<div>
<h2>Thông tin đăng nhập</h2>
<table>
<tr>
<td>Tên đăng nhập </td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Pass </td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td cospan="2">
<asp:CheckBox ID="CheckBox1" runat="server" />Ghi nhớ Pass
<br />
<asp:Button ID="Button1" runat="server" Text="Đăng nhập " />
</td>
</tr>
</table>
</div>
</div>
<div class="content">
<asp:ContentPlaceHolder ID="ContentPlaceHolder2" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>

</div>
</form>
</body>
</html>
Site1.aspx.cs
xuly kn = new xuly();
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack) return;
String q = "select * from DanhMucHoa";
try
{
this.DataList1.DataSource = kn.GetData(q);
this.DataList1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}

protected void LinkButton1_Click(object sender, EventArgs e)


{
String madm = ((LinkButton)sender).CommandArgument;
Context.Items["mdm"] = madm;
Server.Transfer("sanpham.aspx");
}

Sanpham.aspx:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="sanpham.aspx.cs" Inherits="WebApplication1.sanpham" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<h1>Sản phẩm </h1>
<asp:DataList ID="DataList1" runat="server" RepeatColumns="3">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<br />
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl='<%# "~/img/"+Eval("HinhAnh") %>' Width="150px" Height="150px" CommandArgument='<%# Eval("MaHoa") %>' OnClick="ImageButton1_Click" />
<br />
<asp:Label ID="Label2" runat="server" Text='<%# Eval("DonGia","{0:0}") %>'></asp:Label>
</ItemTemplate>

</asp:DataList>
</asp:Content>
Sanpham.aspx.cs
xuly kn = new xuly();
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack) return;
String q;
if (Context.Items["mdm"] == null)
q = "Select * from Hoa ";
else
{
String madm = Context.Items["mdm"].ToString();
q = "Select * from Hoa where MaDM = '" + madm + "'";
}
try
{
this.DataList1.DataSource = kn.GetData(q);
this.DataList1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}

protected void ImageButton1_Click(object sender, ImageClickEventArgs e)


{
String mahoa = ((ImageButton)sender).CommandArgument;
Context.Items["mh"] = mahoa;
Server.Transfer("chitiet.aspx");
}

Chitiet.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="chitiet.aspx.cs" Inherits="WebApplication1.chitiet" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
<h1>Chi tiết </h1>
<asp:DataList ID="DataList1" runat="server">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("TenHoa") %>'></asp:Label>
<br />
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "~/img/"+Eval("HinhAnh") %>' />
<br />
<asp:Label ID="Label2" runat="server" Text='<%# Eval("DonGia") %>'></asp:Label>
<br />
<asp:Label ID="Label3" runat="server" Text='<%# Eval("MoTa") %>'></asp:Label>
</ItemTemplate>
</asp:DataList>

</asp:Content>
Chitiet.aspx.cs
xuly kn = new xuly();
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsPostBack) return;
String q;
if (Context.Items["md"] == null)
q = "Select * from Hoa ";
else
{
String mahoa = Context.Items["mh"].ToString();
q = "Select * from Hoa where MaDM = '" + mahoa + "'";
}
try
{
this.DataList1.DataSource = kn.GetData(q);
this.DataList1.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}

You might also like