Ôn tập KTTMDT
Upcoming SlideShare
Loading in...5
×
 

Ôn tập KTTMDT

on

  • 722 views

 

Statistics

Views

Total Views
722
Views on SlideShare
718
Embed Views
4

Actions

Likes
1
Downloads
6
Comments
0

2 Embeds 4

http://cafewifi.tk 3
http://www.slideshare.net 1

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Ôn tập KTTMDT Ôn tập KTTMDT Document Transcript

    • <%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false"CodeFile="Default2.aspx.cs" Inherits="Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> GridView:<br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True"> <RowStyle BackColor="#EFF3FB" /> <Columns> <asp:BoundField DataField="masp" HeaderText="Mã SP" /> <asp:BoundField DataField="tensanpham" HeaderText="Tên sản phẩm" /> <asp:ImageField DataImageUrlField="hinhanh"> </asp:ImageField> <asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:Button ID="Button1" runat="server" CausesValidation="false"CommandName=<%#Eval("masp")%> ToolTip=<%#Eval("tensanpham")%> Text="Mua hàng" onclick="Button1_Click" Height="26px" /> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <EmptyDataTemplate> Không có dữ liệu </EmptyDataTemplate> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#2461BF" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView> <br /> Repeater:<br /> <br />
    • <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table cellspacing="0" cellpadding="4" border="0" id="GridView1"style="color:#333333;border-collapse:collapse;"> <tr style="color:White;background-color:#507CD1;font-weight:bold;"> <th scope="col">M&#227; SP</th> <th scope="col">T&#234;n sản phẩm</th> <th scope="col">&nbsp;</th><th scope="col">&nbsp;</th> </tr> </HeaderTemplate> <ItemTemplate> <tr style="background-color:#EFF3FB;"> <td><%#Eval("masp") %></td> <td><%#Eval("tensanpham") %></td> <td><img src=<%#Eval("hinhanh") %> style="border-width:0px;"/></td> <td><asp:Button ID="Button2" runat="server" CausesValidation="false"CommandName=<%#Eval("masp")%> ToolTip=<%#Eval("tensanpham")%> Text="Mua hàng" onclick="Button1_Click" Height="26px" /></td> </tr> </ItemTemplate> <FooterTemplate></table></FooterTemplate> </asp:Repeater> <br /> DataList:<br /> <br /> <asp:DataList ID="DataList1" runat="server" style="margin-right: 2px" RepeatDirection="Horizontal"> <ItemTemplate> <table> <tr style="background-color:#EFF3FB;"> <th>Mã SP</th> <td><%#Eval("masp") %></td> </tr> <tr style="background-color:#EFF3FB;"> <th scope="col">Tên sản phẩm</th> <td><%#Eval("tensanpham") %></td> </tr> <tr style="background-color:#EFF3FB;"> <th scope="col">Hình ảnh</th> <td><img src=<%#Eval("hinhanh") %> style="border-width:0px;" /></td> </tr> <tr style="background-color:#EFF3FB;"> <th scope="col">Mua hàng</th> <td><asp:Button ID="Button2" runat="server" CausesValidation="false"
    • CommandName=<%#Eval("masp")%> ToolTip=<%#Eval("tensanpham")%> Text="Mua hàng" onclick="Button1_Click" Height="26px" /></td> </tr> </table> </ItemTemplate> </asp:DataList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ThanhPhoConn %>" SelectCommand="SELECT * FROM [vidu_gridview]"></asp:SqlDataSource> </div> File DFF<br /> <asp:FileUpload ID="FileUpload1" runat="server" /> <br /> <br /> <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox> <br /> <br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> <br /> <asp:TextBox ID="TextBox1" runat="server" EnableViewState="False" ontextchanged="TextBox1_TextChanged"></asp:TextBox> </form></body></html>
    • using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;using System.IO;public partial class Default2 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) return; CoSoDuLieu cs = new CoSoDuLieu(); DataSet dataSet = cs.docDataSet("select * from vidu_gridview"); GridView1.DataSource = dataSet.Tables[0]; GridView1.DataBind(); Repeater1.DataSource = dataSet.Tables[0]; Repeater1.DataBind(); DataList1.DataSource = dataSet.Tables[0]; DataList1.DataBind(); } protected void Button1_Click(object sender, EventArgs e) { Button a = (Button)sender;//Chuyển sender thành đối tượng Button để lấyCommandName. Response.Write(a.CommandName + " "+ a.ToolTip); a.BackColor = System.Drawing.Color.Green; } protected void TextBox1_TextChanged(object sender, EventArgs e) { Response.Write(TextBox1.Text); }}
    • <%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false"CodeFile="Default2.aspx.cs" Inherits="Default2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> GridView:<br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"CellPadding="4" ForeColor="#333333" GridLines="None" AllowSorting="True"> <RowStyle BackColor="#EFF3FB" /> <Columns> <asp:BoundField DataField="masp" HeaderText="Mã SP" /> <asp:BoundField DataField="tensanpham" HeaderText="Tên sản phẩm" /> <asp:ImageField DataImageUrlField="hinhanh"> </asp:ImageField> <asp:TemplateField ShowHeader="False"> <ItemTemplate> <asp:Button ID="Button1" runat="server" CausesValidation="false"CommandName=<%#Eval("masp")%> ToolTip=<%#Eval("tensanpham")%> Text="Mua hàng" onclick="Button1_Click" Height="26px" /> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <EmptyDataTemplate> Không có dữ liệu </EmptyDataTemplate> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#2461BF" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView> <br /> Repeater:<br /> <br />
    • <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table cellspacing="0" cellpadding="4" border="0" id="GridView1"style="color:#333333;border-collapse:collapse;"> <tr style="color:White;background-color:#507CD1;font-weight:bold;"> <th scope="col">M&#227; SP</th> <th scope="col">T&#234;n sản phẩm</th> <th scope="col">&nbsp;</th><th scope="col">&nbsp;</th> </tr> </HeaderTemplate> <ItemTemplate> <tr style="background-color:#EFF3FB;"> <td><%#Eval("masp") %></td> <td><%#Eval("tensanpham") %></td> <td><img src=<%#Eval("hinhanh") %> style="border-width:0px;"/></td> <td><asp:Button ID="Button2" runat="server" CausesValidation="false"CommandName=<%#Eval("masp")%> ToolTip=<%#Eval("tensanpham")%> Text="Mua hàng" onclick="Button1_Click" Height="26px" /></td> </tr> </ItemTemplate> <FooterTemplate></table></FooterTemplate> </asp:Repeater> <br /> DataList:<br /> <br /> <asp:DataList ID="DataList1" runat="server" style="margin-right: 2px" RepeatDirection="Horizontal"> <ItemTemplate> <table> <tr style="background-color:#EFF3FB;"> <th>Mã SP</th> <td><%#Eval("masp") %></td> </tr> <tr style="background-color:#EFF3FB;"> <th scope="col">Tên sản phẩm</th> <td><%#Eval("tensanpham") %></td> </tr> <tr style="background-color:#EFF3FB;"> <th scope="col">Hình ảnh</th> <td><img src=<%#Eval("hinhanh") %> style="border-width:0px;" /></td> </tr> <tr style="background-color:#EFF3FB;"> <th scope="col">Mua hàng</th>
    • <td><asp:Button ID="Button2" runat="server" CausesValidation="false"CommandName=<%#Eval("masp")%> ToolTip=<%#Eval("tensanpham")%> Text="Mua hàng" onclick="Button1_Click" Height="26px" /></td> </tr> </table> </ItemTemplate> </asp:DataList> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ThanhPhoConn %>" SelectCommand="SELECT * FROM [vidu_gridview]"></asp:SqlDataSource> </div> File DFF<br /> <asp:FileUpload ID="FileUpload1" runat="server" /> <br /> <br /> <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox> <br /> <br /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <br /> <br /> <asp:TextBox ID="TextBox1" runat="server" EnableViewState="False" ontextchanged="TextBox1_TextChanged"></asp:TextBox> </form></body></html>
    • using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;using System.IO;public partial class Default2 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) return; CoSoDuLieu cs = new CoSoDuLieu(); DataSet dataSet = cs.docDataSet("select * from vidu_gridview"); GridView1.DataSource = dataSet.Tables[0]; GridView1.DataBind(); Repeater1.DataSource = dataSet.Tables[0]; Repeater1.DataBind(); DataList1.DataSource = dataSet.Tables[0]; DataList1.DataBind(); } protected void Button1_Click(object sender, EventArgs e) { Button a = (Button)sender;//Chuyển sender thành đối tượng Button để lấyCommandName. Response.Write(a.CommandName + " "+ a.ToolTip); a.BackColor = System.Drawing.Color.Green; } protected void TextBox1_TextChanged(object sender, EventArgs e) { Response.Write(TextBox1.Text); }}
    • using System;using System.Data;using System.Data.SqlClient;using System.Collections.Generic;using System.Linq;using System.Web;public class DBAccess{ public DBAccess() { // TODO: Add constructor logic here } public SqlConnection con = null; public void KetNoi() { con = new SqlConnection(); con.ConnectionString = "Data Source=MRCOFFEE-PCSQLEXPRESS;InitialCatalog=qlsv;Integrated Security=True"; con.Open(); } public SqlDataReader xulyExecuteReader(string query) { SqlCommand da = new SqlCommand(query, con); SqlDataReader result = da.ExecuteReader(); return result; } public DataSet xulyDataset(string query) { KetNoi(); SqlDataAdapter da = new SqlDataAdapter(query, con); DataSet ds = new DataSet(); da.Fill(ds); con.Close(); return ds; } public void xulyExecuteNoneQuery(string query) { KetNoi(); SqlCommand da = new SqlCommand(query, con); da.ExecuteNonQuery(); con.Close(); }}
    • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Upload.aspx.cs"Inherits="Upload" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server" enctype="multipart/form-data"> <div> <asp:FileUpload ID="fuNhac" runat="server" /> <br /> <asp:FileUpload ID="fuNhac0" runat="server" /> <br /> <asp:FileUpload ID="fuNhac1" runat="server" /> <br /> <asp:FileUpload ID="fuNhac2" runat="server" /> <br /> <asp:FileUpload ID="fuNhac3" runat="server" /> <br /> <br /> <asp:Button ID="btnUpload" runat="server" Text="Upload" onclick="btnUpload_Click" /> </div> </form></body></html>
    • using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;public partial class Upload : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void btnUpload_Click(object sender, EventArgs e) { string currentDirectory = Server.MapPath("~/"); string fileName; for (int i = 0; i < 5; i++) { HttpPostedFile file = Request.Files[i]; if (file.ContentLength > 0) { fileName = file.FileName; System.IO.FileInfo fi = new System.IO.FileInfo(currentDirectory + fileName); if (fi.Exists) file.SaveAs(currentDirectory + fileName + "123"); else file.SaveAs(currentDirectory + fileName);
    • } //Response.Write(currentDirectory + fileName); } }}
    • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DataSet.aspx.cs"Inherits="DataSet" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title> <style type="text/css"> #form1 { width: 343px; } </style></head><body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </form></body></html>
    • using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.OleDb;public partial class DataSet : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { OleDbConnection con = new OleDbConnection(); con.ConnectionString = " Provider=Microsoft.ACE.OLEDB.12.0;Data Source="D:BTASP.NETLoginDataLogin.accdb""; //Mo ket noi con.Open(); //Doc du lieu ra DataSet
    • string OleDb = "SELECT * FROM HANG"; OleDbDataAdapter sda = new OleDbDataAdapter(OleDb, con); DataSet ds = new DataSet(); //sda.Fill(ds); //Dan du lieu vao GridView de hien thi GridView1.DataSource = ds.Table[0]; GridView1.DataBind(); //Dong ket noi con.Close(); }}
    • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs"Inherits="Login" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Log In</title> <style type="text/css"> .style1 { } .style2 { width: 109px; } #form1 { width: 556px; } .style3 { width: 355px; }
    • </style></head><body> <form id="form1" runat="server"> <table style="width:81%; margin-left: 0px; height: 257px;" border=1> <tr> <td colspan="2"> <b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ĐĂNG NHẬP HỆ THỐNG&nbsp;</b></td> </tr> <tr> <td class="style2"> User Name</td> <td class="style3"> <asp:TextBox ID="txtUserName" runat="server" Width="126px" style="margin-left: 0px"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvTaiKhoan" runat="server" ControlToValidate="txtUserName" ErrorMessage="Tai khoan khong duoc botrong"></asp:RequiredFieldValidator> </td> </tr> <tr>
    • <td class="style2"> Pass Word</td> <td class="style3"> <asp:TextBox ID="txtPassWord" runat="server" Width="121px"TextMode="Password"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvPassWord" runat="server" ControlToValidate="txtPassWord" ErrorMessage="Pass Word khong duoc botrong"></asp:RequiredFieldValidator> </td> </tr> <tr> <td class="style1" colspan="2"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<asp:Label ID="lbTB" runat="server" style="color: #FF0000; text-align:center"></asp:Label> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:CheckBox ID="cbGhiNho" runat="server" Text="Ghi nho tai khoan" style="text-align: center" /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    • <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Button ID="btxDangNhap" runat="server" onclick="btxDangNhap_Click" Text="DangNhap" style="text-align: center" /> </td> </tr> </table> </form></body></html>
    • using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;public partial class Login : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["UserName"] != null && Request.Cookies["PassWord"] != null) { string un = Request.Cookies["UserName"].Value; string pw = Request.Cookies["PassWord"].Value; //Kết nối được với CSDL SqlConnection con = new SqlConnection();
    • con.ConnectionString = @"Data Source=NGOCCHUNG-PCSQLEXPRESS;InitialCatalog=WEBSITE;Integrated Security=True"; con.Open(); //Thao tac voi CSDL string sql = " SELECT *" + " FROM THANH_VIEN" + " WHERE (UserName = " + un + ") AND " + " ([PassWord] = " + pw + ") "; SqlDataAdapter sqlDA = new SqlDataAdapter(sql, con); DataSet DS = new DataSet(); sqlDA.Fill(DS); if (DS.Tables[0].Rows.Count > 0) { Session["HoTen"] = DS.Tables[0].Rows[0]["HoTen"].ToString(); Response.Redirect("Welcome.aspx"); } } } protected void btxDangNhap_Click(object sender, EventArgs e) { //Kết nối được với CSDL SqlConnection con = new SqlConnection(); con.ConnectionString = @"Data Source=NGOCCHUNG-PCSQLEXPRESS;InitialCatalog=WEBSITE;Integrated Security=True";
    • con.Open();//Thao tac voi CSDLstring sql = " SELECT *" + " FROM THANH_VIEN" + " WHERE (UserName = " + txtUserName.Text + ") AND " + " ([PassWord] = " + txtPassWord.Text + ") ";SqlDataAdapter sqlDA = new SqlDataAdapter(sql, con);DataSet DS = new DataSet();sqlDA.Fill(DS);if (DS.Tables[0].Rows.Count > 0){ if (cbGhiNho.Checked == true) { HttpCookie ckun = new HttpCookie("UserName"); ckun.Value = txtUserName.Text; ckun.Expires = DateTime.Today.AddDays(1); Response.Cookies.Add(ckun); HttpCookie ckpw = new HttpCookie("PassWord"); ckpw.Value = txtPassWord.Text; ckpw.Expires = DateTime.Today.AddDays(1); Response.Cookies.Add(ckpw); }
    • Session["HoTen"] = DS.Tables[0].Rows[0]["HoTen"].ToString(); Response.Redirect("Welcome.aspx"); } else { lbTB.Text = "Nhập sai tài khoản hoặc password!"; } //Dong ket noi con.Close(); }}
    • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MatHang.aspx.cs"Inherits="MatHang" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title> <style type="text/css"> .style1 { width: 415px; } </style></head><body> <form id="form1" runat="server"> <table style="width: 52%;"> <tr> <td colspan="2"> BẢNG NHẬP HÀNG</td> </tr> <tr> <td>
    • Mã Hàng</td> <td class="style1"> <asp:TextBox ID="txtMaHang" runat="server" Width="388px"></asp:TextBox> </td> </tr> <tr> <td> Tên Hàng</td> <td class="style1"> <asp:TextBox ID="txtTenHang" runat="server" Width="387px"></asp:TextBox> </td> </tr> <tr> <td colspan="2"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<asp:Button ID="btNhap" runat="server" onclick="btNhap_Click" Text="Nhap Hang" /> </td> </tr> </table>
    • </form></body></html>
    • using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.OleDb;public partial class MatHang : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void btNhap_Click(object sender, EventArgs e) {
    • //Kết nối được với CSDL OleDbConnection con = new OleDbConnection(); con.ConnectionString = " Provider=Microsoft.ACE.OLEDB.12.0;Data Source="D:BTASP.NETLoginDataLogin.accdb""; try { con.Open(); //Thao tac voi CSDL string query = " INSERT INTO HANG(MaHang, TenHang) VALUES (" +txtMaHang.Text + " , " + txtTenHang.Text + ") "; OleDbCommand cmd = new OleDbCommand(); cmd.CommandText = query; cmd.Connection = con; object tenHang = cmd.ExecuteScalar(); Response.Write("Ban da cap nhat thanh cong: " + tenHang + "(" + txtTenHang.Text+ ")"); //Dong ket noi con.Close(); } catch { Response.Write("Cap nhat khong thanh cong."); } }}
    • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="SinhVien.aspx.cs"Inherits="SinhVien" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </form></body></html>
    • using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;public partial class SinhVien : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { ////Ket noi CSDl //string ConnectionString = @"Data Source=NGOC_CHUNG;InitialCatalog=QL_WEBSITE;Integrated Security=True"; //SqlConnection sqlConn = new SqlConnection(ConnectionString); ////Mo ket noi // sqlConn.Open();
    • ////Doc du lieu ra DataSet // string sqlCmd = "SELECT * FROM SINH_VIEN"; // SqlDataAdapter sqlDA = new SqlDataAdapter(sqlCmd, sqlConn); // DataSet DS = new DataSet(); // sqlDA.Fill(DS); ////Dan du lieu vao GridView de hien thi //GridView1.DataSource = DS.Tables[0]; //GridView1.DataBind(); ////Dong ket noi //sqlConn.Close(); }}
    • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TracNghiem.aspx.cs"Inherits="TracNghiem" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title> <style type="text/css"> .style1 { width: 583px; } .style2 { width: 283px; } .style3 { width: 283px; height: 19px; } .style4
    • { width: 583px; height: 19px; } .style5 { height: 19px; } </style></head><body> <form id="form1" runat="server"> <table style="width:100%;"> <tr> <td colspan="3"> &nbsp;&nbsp; TRAC NGHIEM KIEN THUC&nbsp;</td> </tr> <tr> <td class="style2"> HINH ANH</td> <td class="style1"> NOI DUNG</td> <td >
    • &nbsp;</td> </tr> <tr> <td class="style3"> </td> <td class="style4"> &nbsp;</td> <td class="style5"> CAU HOI</td> </tr> <tr> <td class="style2"> &nbsp;</td> <td class="style1"> &nbsp;</td> <td> &nbsp;</td> </tr> </table><asp:GridView ID="GridView1" runat="server"></asp:GridView><br />
    • </form></body></html>
    • using System;using System.Collections;using System.Configuration;using System.Data;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Data.SqlClient;public partial class TracNghiem : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) return; String query = "SELECT ID_CAU_HOI FROM CAU_HOI"; DataSet ds = new DataSet(); //docDataSet(query); for (int i = 0; i < ds.Tables.Count; i++) { Button bt = new Button(); bt.ID = ds.Tables[0].Rows[i]["ID_CAU_HOI"]+""; bt.Text = "Cau hoi " + (i+1);
    • hienThiNut.Controls.Add(bt); } } public DataSet docDataSet(string ChuoiTruyVan) { //Ket noi CSDl string ConnectionString = @"Data Source=NGOC_CHUNG;InitialCatalog=QL_WEBSITE;Integrated Security=True"; SqlConnection sqlConn = new SqlConnection(ConnectionString); //Mo ket noi sqlConn.Open(); SqlDataAdapter sqlDA = new SqlDataAdapter(ChuoiTruyVan, sqlConn); DataSet DS = new DataSet(); sqlDA.Fill(DS); sqlConn.Close(); return DS; }}
    • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Welcome.aspx.cs"Inherits="Welcome" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Welcome</title> <style type="text/css"> .style1 { color: #FF0000; font-weight: bold; } .style2 { text-align: center; } </style></head><body> <form id="form1" runat="server"> <div> <table style="width: 43%;" border=1>
    • <tr> <td class="style2"> &nbsp; <span class="style1">THONG BAO!!!!!!!!!</span></td> </tr> <tr> <td> &nbsp; <b> <asp:Label ID="lblTen" runat="server" style="text-align: center; color: #3333FF"></asp:Label> </b> </td> </tr> <tr> <td> <asp:Button ID="btLogout" runat="server" onclick="btLogout_Click" style="text-align: center" Text="Log Out" /> </td> </tr></table>
    • </div> </form></body></html>
    • using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;public partial class Welcome : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { if (Session["HoTen"] != null) { lblTen.Text = "Chao mung ban *** " + Session["HoTen"] + " *** da tham gia vaoWebSite."; } }
    • protected void btLogout_Click(object sender, EventArgs e) { Session["HoTen"] = null; HttpCookie ckun = new HttpCookie("UserName"); ckun.Expires = DateTime.Now; Response.Cookies.Add(ckun); HttpCookie ckpw = new HttpCookie("PassWord"); ckpw.Expires = DateTime.Now; Response.Cookies.Add(ckpw); Response.Redirect("Login.aspx"); }}
    • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title> <style type="text/css"> .style1 { width: 188px; } .style3 { width: 162px; } .style4 { width: 188px; height: 35px; } .style5
    • { height: 35px; } </style></head><body> <form id="form1" runat="server"> <asp:Repeater ID="rpSinhVien" runat="server"> <ItemTemplate> <table style="width: 54%; height: 162px; margin-left: 0px;" border = "1"> <tr> <td class="style3" rowspan="4"> <img src="images/<%#Eval ("HINH_ANH") %>" /> </td> <td class="style4"> Ma Sinh Vien</td> <td class="style5"> <%#Eval ("MA_SINH_VIEN") %></td> </tr> <tr> <td class="style1"> Ho Ten</td> <td>
    • <%#Eval ("HO_TEN") %></td> </tr> <tr> <td class="style1"> Ngay Sinh</td> <td> <%#Eval ("NGAY_SINH") %></td> </tr> <tr> <td class="style1"> Ten Lop</td> <td> <%#Eval ("TEN_LOP") %></td> </tr> </table> </ItemTemplate> </asp:Repeater> </form> </body></html>
    • using System;using System.Collections;using System.Configuration;using System.Data;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Data.SqlClient;public partial class _Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { string sql = "SELECT SINH_VIEN.MA_SINH_VIEN,SINH_VIEN.HO_TEN,SINH_VIEN.NGAY_SINH, LOP.TEN_LOP, HINH_ANH" + " FROM SINH_VIEN INNER JOIN" + " LOP ON SINH_VIEN.MA_LOP =LOP.MA_LOP"; LopKetNoi kn = new LopKetNoi(); DataSet ds = kn.XuLyDataSet(sql); rpSinhVien.DataSource = ds.Tables[0]; rpSinhVien.DataBind(); } }
    • <%@ Page Language="C#" AutoEventWireup="true" EnableEventValidation="false"CodeFile="MuaHang.aspx.cs" Inherits="MuaHang" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Mua Hang</title> <style type="text/css"> .style1 { color: #FF0000; font-weight: bold; text-align: center; } .style2 { } .style3 { width: 111px; } </style>
    • </head><body> <form id="form1" runat="server"> <div> <table style="width: 23%;" border=1> <tr> <td class="style1" colspan="2"> THONG KE</td> </tr> <tr> <td class="style3"> So SP</td> <td> <asp:Label ID="lbSP" runat="server" Text="0"></asp:Label> </td> </tr> <tr> <td class="style3"> So Tien</td> <td> <asp:Label ID="lbST" runat="server" Text="0"></asp:Label> </td>
    • </tr> <tr> <td class="style2" colspan="2"> <asp:Button ID="btXem" runat="server" Text="Xem Hang"onclick="btXem_Click" /> </td> </tr> </table> <br /> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundField DataField="MaSo" HeaderText="Mã Số" /> <asp:BoundField DataField="TenHang" HeaderText="Tên Hàng" /> <asp:BoundField DataField="NgaySX" HeaderText="Ngày Sản Xuất" /> <asp:BoundField DataField="DonGia" HeaderText="Đơn Giá" /> <asp:ImageField DataImageUrlField="HinhAnh" DataImageUrlFormatString="./images/{0}" HeaderText="Hinh Anh"> </asp:ImageField> <asp:TemplateField HeaderText="Mua Hàng"> <ItemTemplate> <asp:Button CommandName= <%#Eval("DonGia") %> ToolTip = <%#Eval("TenHang") %> ID="Button1" runat="server" Text="Mua Hang" onclick="Button1_Click" />
    • </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <br /> </div> </form></body></html>
    • using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;public partial class MuaHang : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = @"Data Source=NGOCCHUNG-PCSQLEXPRESS;InitialCatalog=WEBSITE;Integrated Security=True"; con.Open(); //Doc du lieu ra DataSet
    • string sql = "SELECT * FROM SAN_PHAM"; SqlDataAdapter sda = new SqlDataAdapter(sql, con); DataSet ds = new DataSet(); sda.Fill(ds); //Dan du lieu vao GridView de hien thi GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); //Dong ket noi con.Close(); } protected void Button1_Click(object sender, EventArgs e) { Button bt = (Button)sender; Response.Write("Ban da kich vao nut mua hang: "+ bt.CommandName + bt.ToolTip); lbSP.Text = "" + (Convert.ToInt32(lbSP.Text) + 1); lbST.Text = "" + (Convert.ToInt32(lbST.Text) + Convert.ToInt32(bt.CommandName)); } protected void btXem_Click(object sender, EventArgs e) { }}
    • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MuaHang2.aspx.cs"EnableEventValidation="false" Inherits="MuaHang2" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Mua Hang</title></head><body> <form id="form1" runat="server"> <asp:Repeater ID="Repeater1" runat="server"> <HeaderTemplate> <table style="width: 66%;" border="1"> <tr> <td> Mã Số</td> <td> Tên Hàng</td> <td> Ngày Sản Xuất</td> <td> Đơn Giá</td>
    • <td> Hình Ảnh</td> <td> Mua Hàng</td> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <%#Eval ("MaSo") %></td> <td> <%#Eval ("TenHang") %></td> <td> <%#Eval ("NgaySX") %></td> <td> <%#Eval ("DonGia") %></td> <td> <img src="images/<%#Eval ("HinhAnh") %>" /></td> <td> <asp:Button CommandName= <%#Eval("MaSo") %> ToolTip = <%#Eval("TenHang") %> ID="Button1" runat="server" Text="Mua Hang" onclick="Button1_Click" /></td> </tr> </ItemTemplate>
    • <FooterTemplate> </table></FooterTemplate> </asp:Repeater> </form></body></html>
    • using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;public partial class MuaHang2 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = @"Data Source=NGOCCHUNG-PCSQLEXPRESS;InitialCatalog=WEBSITE;Integrated Security=True"; con.Open(); //Doc du lieu ra DataSet string sql = "SELECT * FROM SAN_PHAM";
    • SqlDataAdapter sda = new SqlDataAdapter(sql, con); DataSet ds = new DataSet(); sda.Fill(ds); //Dan du lieu vao GridView de hien thi Repeater1.DataSource = ds.Tables[0]; Repeater1.DataBind(); //Dong ket noi con.Close(); } protected void Button1_Click(object sender, EventArgs e) { Button bt = (Button)sender; Response.Write("Ban da kich vao nut mua hang: " + bt.CommandName + bt.ToolTip); }}<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MuaHang3.aspx.cs"EnableEventValidation="false" Inherits="MuaHang3" %>
    • <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Mua Hang 3</title></head><body> <form id="form1" runat="server"> <div> <asp:DataList ID="DataList1" runat="server" Width="982px"> <HeaderTemplate> <table style="width: 66%;" border="1"> <tr> <td> Mã Số</td> <td> Tên Hàng</td> <td> Ngày Sản Xuất</td> <td> Đơn Giá</td>
    • <td> Hình Ảnh</td> <td> Mua Hàng</td> </tr> </HeaderTemplate> <ItemTemplate> <tr> <td> <%#Eval ("MaSo") %></td> <td> <%#Eval ("TenHang") %></td> <td> <%#Eval ("NgaySX") %></td> <td> <%#Eval ("DonGia") %></td> <td> <img src="images/<%#Eval ("HinhAnh") %>" /></td> <td> <asp:Button CommandName= <%#Eval("MaSo") %> ToolTip = <%#Eval("TenHang") %> ID="Button1" runat="server" Text="Mua Hang" onclick="Button1_Click" /></td> </tr>
    • </ItemTemplate> <FooterTemplate> </table></FooterTemplate> </asp:DataList> </div> </form></body></html>
    • using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;public partial class MuaHang3 : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { SqlCommand. SqlConnection con = new SqlConnection(); con.ConnectionString = @"Data Source=NGOCCHUNG-PCSQLEXPRESS;InitialCatalog=WEBSITE;Integrated Security=True"; con.Open(); //Doc du lieu ra DataSet
    • string sql = "SELECT * FROM SAN_PHAM"; SqlDataAdapter sda = new SqlDataAdapter(sql, con); DataSet ds = new DataSet(); sda.Fill(ds); //Dan du lieu vao GridView de hien thi DataList1.DataSource = ds.Tables[0]; DataList1.DataBind(); //Dong ket noi con.Close(); } protected void Button1_Click(object sender, EventArgs e) { Button bt = (Button)sender; Response.Write("Ban da kich vao nut mua hang: "+ bt.CommandName + bt.ToolTip); }}
    • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TimDiem.aspx.cs"Inherits="TimDiem" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title>Untitled Page</title> <style type="text/css"> .style1 { } .style2 { width: 206px; } </style></head><body> <form id="form1" runat="server"> <table style="width:61%;" border = "1"> <tr> <td class="style1"> <asp:DropDownList ID="ddlLop" runat="server" DataTextField="TEN_LOP"
    • DataValueField="MA_LOP"> </asp:DropDownList> </td> <td class="style2"> <asp:DropDownList ID="ddlMonHoc" runat="server" DataTextField="TEN_MON" DataValueField="MA_MON"> </asp:DropDownList> </td> <td> <asp:Button ID="btTim" runat="server" Text=" TIM KIEM" /> </td> </tr> <tr> <td class="style1" colspan="3"> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </td> </tr> </table> </form></body></html>
    • using System;using System.Collections;using System.Configuration;using System.Data;using System.Linq;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Xml.Linq;using System.Data.SqlClient;public partial class TimDiem : System.Web.UI.Page{ LopKetNoi lkn = new LopKetNoi(); protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) return; DataSet ds=lkn.XuLyDataSet(
    • }}using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Data.SqlClient;/// <summary>/// Summary description for LopKetNoi/// </summary>public class LopKetNoi{
    • public LopKetNoi() { // // TODO: Add constructor logic here // } public SqlConnection sqlConn = null; public SqlConnection KetNoi() { string sql_con = @"Data Source=NGOCCHUNG-PCSQLEXPRESS;InitialCatalog=WEBSITE;Integrated Security=True"; sqlConn = new SqlConnection(sql_con); sqlConn.Open(); return sqlConn; } public SqlDataReader XuLyExecuteReader(string query) { KetNoi(); SqlCommand da = new SqlCommand(query, sqlConn); SqlDataReader result = da.ExecuteReader(); return result; }
    • public DataSet XuLyDataSet(string query) { KetNoi(); SqlDataAdapter da = new SqlDataAdapter(query, sqlConn); DataSet ds = new DataSet(); da.Fill(ds); sqlConn.Close(); return ds; } public void XuLyExecuteNonQuery(string query) { KetNoi(); SqlCommand da = new SqlCommand(query, sqlConn); da.ExecuteNonQuery(); sqlConn.Close(); }}