Ôn tập KTTMDT

743 views

Published on

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
743
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
8
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Ôn tập KTTMDT

  1. 1. <%@ 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 />
  2. 2. <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ã SP</th> <th scope="col">Tê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"
  3. 3. 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>
  4. 4. 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); }}
  5. 5. <%@ 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 />
  6. 6. <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ã SP</th> <th scope="col">Tê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>
  7. 7. <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>
  8. 8. 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); }}
  9. 9. 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(); }}
  10. 10. <%@ 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>
  11. 11. 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);
  12. 12. } //Response.Write(currentDirectory + fileName); } }}
  13. 13. <%@ 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>
  14. 14. 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
  15. 15. 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(); }}
  16. 16. <%@ 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; }
  17. 17. </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>
  18. 18. <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;
  19. 19. <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>
  20. 20. 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();
  21. 21. 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";
  22. 22. 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); }
  23. 23. 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(); }}
  24. 24. <%@ 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>
  25. 25. 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>
  26. 26. </form></body></html>
  27. 27. 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) {
  28. 28. //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."); } }}
  29. 29. <%@ 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>
  30. 30. 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();
  31. 31. ////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(); }}
  32. 32. <%@ 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
  33. 33. { 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 >
  34. 34. &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 />
  35. 35. </form></body></html>
  36. 36. 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);
  37. 37. 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; }}
  38. 38. <%@ 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>
  39. 39. <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>
  40. 40. </div> </form></body></html>
  41. 41. 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."; } }
  42. 42. 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"); }}
  43. 43. <%@ 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
  44. 44. { 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>
  45. 45. <%#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>
  46. 46. 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(); } }
  47. 47. <%@ 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>
  48. 48. </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>
  49. 49. </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" />
  50. 50. </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <br /> </div> </form></body></html>
  51. 51. 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
  52. 52. 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) { }}
  53. 53. <%@ 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>
  54. 54. <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>
  55. 55. <FooterTemplate> </table></FooterTemplate> </asp:Repeater> </form></body></html>
  56. 56. 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";
  57. 57. 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" %>
  58. 58. <!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>
  59. 59. <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>
  60. 60. </ItemTemplate> <FooterTemplate> </table></FooterTemplate> </asp:DataList> </div> </form></body></html>
  61. 61. 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
  62. 62. 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); }}
  63. 63. <%@ 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"
  64. 64. 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>
  65. 65. 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(
  66. 66. }}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{
  67. 67. 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; }
  68. 68. 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(); }}

×