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

📄 qlbmon.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 lamtuoi()
    {
        string strCurrentPath = Request.PhysicalPath;
        string strXMLPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\"))
                            + "\\QuanlySinhVien.xml";
        XmlDocument doc = new XmlDocument();
        doc.Load(strXMLPath);
        XmlNodeList tbm, khoaid, mbm;
        mbm = doc.DocumentElement.SelectNodes("//BoMon/MaBM");
        tbm = doc.DocumentElement.SelectNodes("//BoMon/Ten");
        khoaid = doc.DocumentElement.SelectNodes("//BoMon/KhoaID");
        DataTable s = new DataTable("table");
        s.Columns.Add("Mã bm", Type.GetType("System.String"));
        s.Columns.Add("Tên bm", Type.GetType("System.String"));
        s.Columns.Add("Khoa", Type.GetType("System.String"));
        for (int i = 0; i < mbm.Count;i++ )
        {
            DataRow r = s.NewRow();
            r["Mã bm"] = mbm[i].FirstChild.Value;
            r["Tên bm"] = tbm[i].FirstChild.Value;
            r["Khoa"] = khoaid[i].FirstChild.Value;
            s.Rows.Add(r);
        }
        s.ReadXml(strXMLPath);
        gr.DataSource = s;
        gr.DataBind();
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["username"] != null)
        {
           lbtrang.Text= "Bạn đang đăng nhập trang " + Session["username"].ToString();
            lamtuoi();
        }
        else
        {
            Response.Redirect("Login.aspx");
        }
    }
    void gr_sua(object sender, GridViewEditEventArgs e)
    {
        string mbm = gr.Rows[e.NewEditIndex].Cells[1].Text;
        string tbm = gr.Rows[e.NewEditIndex].Cells[2].Text;
        string khoaid = gr.Rows[e.NewEditIndex].Cells[3].Text;
        Session["mbm"] = mbm;
        Session["tbm"] = tbm;
        Session["khoaid"] = khoaid;
        Pan1.Visible = true;
        //lbkq.Text = "Bạn đang cập nhật lại dữ liệu";
        txttml.Value = Session["mbm"].ToString();
        txttlop.Value = Session["tbm"].ToString();
        txttkhoaid.Value = Session["khoaid"].ToString();
        
    }
    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 nbm = doc.SelectSingleNode("/CSDLTruong/BoMonNode");
        XmlNodeList bm = doc.GetElementsByTagName("BoMon");
       // XmlNode ndiem = doc.SelectSingleNode("/CSDLTruong/DiemNode");
       // XmlNodeList diem = doc.GetElementsByTagName("Diem");
        for (int i = 0; i <bm.Count; i++)
        {
            if (bm[i].FirstChild.InnerText == ms)
            {
                nbm.RemoveChild(bm[i]);
            }
        }
        doc.Save(strXMLPath);
        lamtuoi();
    }

    protected void btsua_Click(object sender, EventArgs e)
    {
        string strCurrentPath = Request.PhysicalPath;
        string strXMLPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\"))
                            + "\\QuanLySinhVien.xml";
        XmlDocument doc = new XmlDocument();
        doc.Load(strXMLPath);
        XmlNodeList mbm, tbm, khoaid;
        mbm = doc.DocumentElement.SelectNodes("//BoMon/MaBM");
        tbm = doc.DocumentElement.SelectNodes("//BoMon/Ten");
        khoaid = doc.DocumentElement.SelectNodes("//BoMon/KhoaID");
        int co = 0;
        for (int i = 0; i < mbm.Count; i++)
        {
            //lbkq.Text =mlop.Count + "Ban dang cap nhat";     
            if (Session["mbm"].ToString()== mbm[i].FirstChild.Value && co == 0)
            {
               co++;
                mbm[i].FirstChild.Value = txttml.Value;
                tbm[i].FirstChild.Value = txttlop.Value;
                khoaid[i].FirstChild.Value = txttkhoaid.Value;
                lbkq.Text = "Ban da cap nhat thanh cong";
                doc.Save(strXMLPath);
            }
        }
        lamtuoi();
    }

    protected void btthem_Click(object sender, EventArgs e)
    {
        string strCurrentPath = Request.PhysicalPath;
        string strXMLPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\"))
                            + "\\QuanLySinhVien.xml";
        XmlDocument doc = new XmlDocument();
        doc.Load(strXMLPath);
        XmlNode nodebm = doc.SelectSingleNode("/CSDLTruong/BoMonNode");
        XmlElement bm = doc.CreateElement("BoMon");
        XmlElement mbm = doc.CreateElement("MaBM");
        XmlElement tbm = doc.CreateElement("Ten");
        XmlElement khoaid = doc.CreateElement("KhoaID");
        mbm.InnerText = txttml.Value;
        tbm.InnerText = txttlop.Value;
        khoaid.InnerText = txttkhoaid.Value;
        bm.AppendChild(mbm);
        bm.AppendChild(tbm);
        bm.AppendChild(khoaid);
        nodebm.AppendChild(bm);
        doc.Save(strXMLPath);
        lamtuoi();
        lbkq.Text = "Thong tin đã dc them vao trong csdl";
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lbtrang" runat="server"></asp:Label><br />
        <br />
        <asp:GridView ID="gr" runat="server" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" OnRowEditing="gr_sua" OnRowDeleting ="gr_xoa" CellPadding="4" ForeColor="#333333" GridLines="None" Height="5px" Width="311px" HorizontalAlign="Left">
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle" />
            <RowStyle BackColor="#EFF3FB" />
            <EditRowStyle BackColor="#2461BF" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle" />
            <AlternatingRowStyle BackColor="White" />
            <EmptyDataRowStyle HorizontalAlign="Center" />
        </asp:GridView>
        &nbsp;<br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <asp:Panel ID="Pan1" runat="server" Height="166px" Visible="False" Width="306px">
            <asp:Label ID="lbkq" runat="server" Height="25px" Style="z-index: 100; left: 22px;
                position: absolute; top: 358px"></asp:Label>
            <table border="0" style="z-index: 103; left: 9px; position: relative; top: 48px">
                <tr>
                    <td style="width: 82px; height: 21px">
                        Mã bộ môn:</td>
                    <td colspan="2" style="width: 160px; height: 21px">
                        <input id="txttml" runat="server" type="text" />
                    </td>
                </tr>
                <tr>
                    <td style="width: 82px; height: 21px">
                        Tên bộ môn:</td>
                    <td colspan="2" style="width: 160px; height: 21px">
                        &nbsp;<input id="txttlop" runat="server" style="left: -3px; width: 149px; position: relative;
                            top: 0px" type="text" /></td>
                </tr>
                <tr>
                    <td style="width: 82px; height: 23px">
                        Khoa id:</td>
                    <td colspan="2" style="width: 160px; height: 23px">
                        <input id="txttkhoaid" runat="server" style="position: relative" type="text" /></td>
                </tr>
            </table>
            <asp:Button ID="btthem" runat="server" Style="z-index: 102;
                left: 204px; position: relative; top: -73px" Text="Thêm" OnClick="btthem_Click" />
            <asp:Button ID="Button1" runat="server" OnClick="btsua_Click" Style="z-index: 102;
                left: -39px; position: relative; top: -73px" Text="Sửa" /></asp:Panel>
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        <br />
        &nbsp;<br />
        <br />
        <br />
        <br />
    
    </div>
    </form>
</body>
</html>

⌨️ 快捷键说明

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