⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 admin.aspx

📁 web asp.net, code c# and use xml.
💻 ASPX
字号:
<%@ Page Language="C#" %>
<%@Import Namespace="System.Data" %>
<%@Import Namespace="System.Data.OleDb" %>
<%@Import Namespace="System.Xml" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] != null)
        {            
            lbkq.Text ="Chào "+ Session["username"].ToString();
            lamtuoi();
        }
        else
        {
            Response.Redirect("Login.aspx");
        }
    }
    protected void lamtuoi()
    {
        string strCurrentPath = Request.PhysicalPath;
        string strXMLPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\"))
                            + "\\QuanlySinhVien.xml";
        XmlDocument doc = new XmlDocument();
        doc.Load(strXMLPath);
        XmlNodeList mssv, tho, lop, diem, monhoc,lopid,mlop;
        mssv = doc.DocumentElement.SelectNodes("//SVien/MSSV");
        tho = doc.DocumentElement.SelectNodes("//SVien/HoTen");
        lopid = doc.DocumentElement.SelectNodes("//SVien/LopID");
        mlop = doc.DocumentElement.SelectNodes("//Lop/MaLop");
        lop = doc.DocumentElement.SelectNodes("//Lop/Ten");
        diem = doc.DocumentElement.SelectNodes("//Diem/DiemThi");
        monhoc = doc.DocumentElement.SelectNodes("//Diem/MonHocID");
        DataTable s = new DataTable("table");
        s.Columns.Add("MSSV", Type.GetType("System.String"));
        s.Columns.Add("Họ Tên sv", Type.GetType("System.String"));
        s.Columns.Add("Lớp", Type.GetType("System.String"));
        s.Columns.Add("Điểm", Type.GetType("System.String"));
        s.Columns.Add("Môn", Type.GetType("System.String"));
        for (int i = 0; i < tho.Count; i++)
        {

            DataRow r = s.NewRow();
            r["MSSV"] = mssv[i].FirstChild.Value;
            r["Họ Tên sv"] = tho[i].FirstChild.Value;
            int co = 0;
            for (int j = 0; j < mlop.Count; j++)
            {
                if (lopid[i].FirstChild.Value == mlop[j].FirstChild.Value&&co==0)
                {
                    co++;
                    r["Lớp"] = lop[j].FirstChild.Value;
                }         
            }
            if (co == 0) r["Lớp"] = "";
            r["Điểm"] = diem[i].FirstChild.Value;
            r["Môn"] = monhoc[i].FirstChild.Value;
            s.Rows.Add(r);
        }
        s.ReadXml(strXMLPath);
        gr.DataSource = s;
        gr.DataBind();
    }
    protected void bttim_Click(object sender, EventArgs e)
    {
        string ttim = txtttimkiem.Value;
        string strCurrentPath = Request.PhysicalPath;
        string strXMLPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\"))
                            + "\\QuanlySinhVien.xml";
        XmlDocument doc = new XmlDocument();
        doc.Load(strXMLPath);
        XmlNodeList mssv, tho, lop, diem, monhoc;
        mssv = doc.DocumentElement.SelectNodes("//SVien/MSSV");
        tho = doc.DocumentElement.SelectNodes("//SVien/HoTen");
        lop = doc.DocumentElement.SelectNodes("//Lop/Ten");
        diem = doc.DocumentElement.SelectNodes("//Diem/DiemThi");
        monhoc = doc.DocumentElement.SelectNodes("//Diem/MonHocID");
        DataTable s = new DataTable("table");
        s.Columns.Add("MSSV", Type.GetType("System.String"));
        s.Columns.Add("Họ Tên sv", Type.GetType("System.String"));
        s.Columns.Add("Lớp", Type.GetType("System.String"));
        s.Columns.Add("Điểm", Type.GetType("System.String"));
        s.Columns.Add("Môn", Type.GetType("System.String"));
        for (int i = 0; i < tho.Count; i++)
        {
            if (ttim == mssv[i].FirstChild.Value)
            {
                DataRow r = s.NewRow();
                r["MSSV"] = mssv[i].FirstChild.Value;
                r["Họ Tên sv"] = tho[i].FirstChild.Value;
                r["Lớp"] = lop[0].FirstChild.Value;
                r["Điểm"] = diem[i].FirstChild.Value;
                r["Môn"] = monhoc[i].FirstChild.Value;
                s.Rows.Add(r);
            }
        }
        s.ReadXml(strXMLPath);
        gr.DataSource = s;
        gr.DataBind();
    }

    protected void bttrove_Click(object sender, EventArgs e)
    {
        Response.Redirect("Login.aspx");
    }

    protected void btthem_Click(object sender, EventArgs e)
    {
        Session["Them"] = "thêm";
        Response.Redirect("Them.aspx");
    }
    void gr_sua( object sender, GridViewEditEventArgs e)
    {
        string mssv = gr.Rows[e.NewEditIndex].Cells[1].Text;
        string hten = gr.Rows[e.NewEditIndex].Cells[2].Text;
        string lop = gr.Rows[e.NewEditIndex].Cells[3].Text;
        string diem = gr.Rows[e.NewEditIndex].Cells[4].Text;
        string mon = gr.Rows[e.NewEditIndex].Cells[5].Text;
        Session["mssv"] = mssv;
        Session["hten"] = hten;
        Session["lop"] = lop;
        Session["diem"] = diem;
        Session["mon"] = mon;
        Session["Capnhat"] = "Sửa";
        Response.Redirect("Capnhat.aspx");
    }
    void gr_xoa(object sender, GridViewDeleteEventArgs e)
    {
        string ms = gr.Rows[e.RowIndex].Cells[1].Text;
        string strCurrentPath = Request.PhysicalPath;
        string strXMLPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\"))
                            + "\\QuanLySinhVien.xml";
        XmlDocument doc = new XmlDocument();
        doc.Load(strXMLPath);
        XmlNode nsv = doc.SelectSingleNode("/CSDLTruong/SinhVien");
        XmlNodeList sv = doc.GetElementsByTagName("SVien");
        XmlNode ndiem = doc.SelectSingleNode("/CSDLTruong/DiemNode");
        XmlNodeList diem = doc.GetElementsByTagName("Diem");
        for (int i = 0; i < sv.Count; i++)
        {
            if (sv[i].FirstChild.InnerText == ms)
            {
                nsv.RemoveChild(sv[i]);
                ndiem.RemoveChild(diem[i]);
            }
        }
        doc.Save(strXMLPath);
        lamtuoi();
    }

    protected void btqllop_Click(object sender, EventArgs e)
    {
        Response.Redirect("Qllop.aspx");
    }

    protected void btqlbmon_Click(object sender, EventArgs e)
    {
        Response.Redirect("Qlbmon.aspx");
    }

    protected void btqlmon_Click(object sender, EventArgs e)
    {
        Response.Redirect("Qlmon.aspx");
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
    <script type="text/javascript" language="javascript">
	function Move()
	{
	    var lf=0;
	    var step=1;
		lf+=step;
		var s="Trường Đại Học Hùng Vương";
		document.all("chu").style.left = lf;
		if (lf >=550) 
			lf=0;
		setTimeout("Move()",10);
		document.all("chu").innerHTML = s;
	}
    </script>
</head>
<body onload="Move()">
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lbkq" runat="server" Height="25px" Style="z-index: 100; left: 21px;
            position: absolute; top: 11px"></asp:Label>
        &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
        <table border="0" cellpadding="0" cellspacing="0" style="z-index: 109; left: 107px;
            width: 269px; position: absolute; top: 14px">
            <tr>
                <td style="width: 100px; height: 19px"><div id="chu" style="position:absolute; left:-4px; top:333px; width: 238px; height: 8px;"></div>
                </td>
            </tr>
        </table>
        <br />
        <asp:Label ID="T" runat="server" Style="left: 0px; position: relative; top: 16px; z-index: 102;"
            Text="Tìm kiếm"></asp:Label><asp:Button ID="bttim" runat="server" OnClick="bttim_Click"
                Style="left: 192px; position: relative; top: 16px; z-index: 103;" Text="Tìm" /><input id="txtttimkiem"
                    runat="server" style="left: -6px; position: relative; top: 16px; z-index: 107;" type="text" /><asp:Button
                        ID="bttrove" runat="server" OnClick="bttrove_Click" Style="left: 56px; position: relative;
                        top: 16px; z-index: 104;" Text="Trở về" />
                        <asp:Button
                        ID="btthem" runat="server" OnClick="btthem_Click" Style="left: 56px; position: relative;
                        top: 16px; z-index: 104;" Text="Thêm" />
                        </div>
        <asp:GridView ID="gr" runat="server" Height="1px" Style="z-index: 106; left: 20px;
            position: absolute; top: 95px" Width="395px" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" OnRowEditing="gr_sua" OnRowDeleting ="gr_xoa" CellPadding="4" ForeColor="#333333" GridLines="None">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#EFF3FB" />
            <EditRowStyle BackColor="#2461BF" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
        &nbsp;&nbsp;
        <asp:Button ID="btqlbmon" runat="server"
                Style="left: 103px; position: relative; top: 220px; z-index: 103;" Text="Quản lý Bộ Môn" OnClick="btqlbmon_Click" /><asp:Button
                        ID="btqllop" runat="server"  Style="left: -147px; position: relative;
                        top: 219px; z-index: 104;" Text="Quản lý lớp" OnClick="btqllop_Click" /><asp:Button
                        ID="btqlmon" runat="server"  Style="left: 17px; position: relative;
                        top: 220px; z-index: 104;" Text="Quản lý Môn" OnClick="btqlmon_Click" /><br />
        <br />
        <br />
        <br />
    </form>
</body>
</html>
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -