📄 qlmon.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 mmh, bmid, tmh,mbm;
mmh = doc.DocumentElement.SelectNodes("//MonHoc/MaMH");
tmh = doc.DocumentElement.SelectNodes("//MonHoc/Ten");
bmid = doc.DocumentElement.SelectNodes("//MonHoc/BoMonID");
mbm = doc.DocumentElement.SelectNodes("//BoMon/MaBM");
DataTable s = new DataTable("table");
s.Columns.Add("Mã mh", Type.GetType("System.String"));
s.Columns.Add("Tên mh", Type.GetType("System.String"));
s.Columns.Add("ID bm", Type.GetType("System.String"));
for (int i = 0; i < mmh.Count;i++ )
{
DataRow r = s.NewRow();
r["Mã mh"] = mmh[i].FirstChild.Value;
r["Tên mh"] = tmh[i].FirstChild.Value;
int co = 0;
for (int j = 0; j < mbm.Count; j++)
{
if (mbm[j].FirstChild.Value == bmid[i].FirstChild.Value && co == 0)
{
co++;
r["ID bm"] = bmid[i].FirstChild.Value;
}
}
if (co == 0) r["ID bm"] = "";
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 mmh = gr.Rows[e.NewEditIndex].Cells[1].Text;
string tmh = gr.Rows[e.NewEditIndex].Cells[2].Text;
string bmid = gr.Rows[e.NewEditIndex].Cells[3].Text;
Session["mmh"] = mmh;
Session["tmh"] = tmh;
Session["bmid"] = bmid;
Pan1.Visible = true;
//lbkq.Text = "Bạn đang cập nhật lại dữ liệu";
txttml.Value = Session["mmh"].ToString();
txttlop.Value = Session["tmh"].ToString();
txttkhoaid.Value = Session["bmid"].ToString();
lamtuoi();
}
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 nmh = doc.SelectSingleNode("/CSDLTruong/MonHocNode");
XmlNodeList mh = doc.GetElementsByTagName("MonHoc");
// XmlNode ndiem = doc.SelectSingleNode("/CSDLTruong/DiemNode");
// XmlNodeList diem = doc.GetElementsByTagName("Diem");
for (int i = 0; i <mh.Count; i++)
{
if (mh[i].FirstChild.InnerText == ms)
{
nmh.RemoveChild(mh[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 mmh, tmh, bmid;
mmh = doc.DocumentElement.SelectNodes("//MonHoc/MaMH");
tmh = doc.DocumentElement.SelectNodes("//MonHoc/Ten");
bmid = doc.DocumentElement.SelectNodes("//MonHoc/BoMonID");
int co = 0;
for (int i = 0; i < mmh.Count; i++)
{
//lbkq.Text =mlop.Count + "Ban dang cap nhat";
if (Session["mmh"].ToString()== mmh[i].FirstChild.Value && co == 0)
{
co++;
mmh[i].FirstChild.Value = txttml.Value;
tmh[i].FirstChild.Value = txttlop.Value;
bmid[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 nodemh = doc.SelectSingleNode("/CSDLTruong/MonHocNode");
XmlElement mh = doc.CreateElement("MonHoc");
XmlElement mmh = doc.CreateElement("MaMH");
XmlElement tmh = doc.CreateElement("Ten");
XmlElement bmid = doc.CreateElement("BoMonID");
mmh.InnerText = txttml.Value;
tmh.InnerText = txttlop.Value;
bmid.InnerText = txttkhoaid.Value;
mh.AppendChild(mmh);
mh.AppendChild(tmh);
mh.AppendChild(bmid);
nodemh.AppendChild(mh);
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>
<br />
<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: 17px;
position: absolute; top: 381px"></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">
<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 />
<br />
<br />
<br />
<br />
</div>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -