/abac/abac/au/subject.aspx.cs

http://abaccn.codeplex.com · C# · 121 lines · 96 code · 22 blank · 3 comment · 17 complexity · 9e5a7bad4f4bebe6c1564dc9d8632684 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Web;
  4. using System.Web.UI;
  5. using System.Web.UI.WebControls;
  6. using System.Xml;
  7. using System.Text.RegularExpressions;
  8. using System.Data;
  9. using System.IO;
  10. using System.Text;
  11. namespace aucn.web.au
  12. {
  13. public partial class subject : System.Web.UI.Page
  14. {
  15. XmlDocument doc;
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18. this.Master.Attributes["submenu"] = "Undergrad";
  19. if (Request.QueryString["d"] != null)
  20. {
  21. string id = Request.QueryString["d"].Trim().ToUpper();
  22. if (Cache["DEPT_" + id] == null)
  23. {
  24. doc = new XmlDocument();
  25. doc.Load(Server.MapPath("~/App_Data/subjects.xml"));
  26. XmlNamespaceManager xm = new XmlNamespaceManager(doc.NameTable);
  27. xm.AddNamespace("ab", "http://tempuri.org/subject.xsd");
  28. XmlNode deptNode = doc.DocumentElement.SelectSingleNode("ab:department[@name='" + id + "']", xm);
  29. if (deptNode != null)
  30. {
  31. Department dpt = new Department(
  32. id,
  33. deptNode.SelectSingleNode("ab:name", xm).InnerText,
  34. deptNode.SelectSingleNode("ab:chname", xm).InnerText,
  35. deptNode.SelectSingleNode("ab:desc", xm) != null ? deptNode.SelectSingleNode("ab:desc", xm).InnerText : string.Empty,
  36. deptNode.SelectSingleNode("ab:career", xm) != null ? deptNode.SelectSingleNode("ab:career", xm).InnerText : string.Empty,
  37. deptNode.SelectSingleNode("ab:common", xm) != null ? deptNode.SelectSingleNode("ab:common", xm).InnerText : string.Empty,
  38. new List<Major>()
  39. );
  40. XmlNodeList majorNodes = deptNode.SelectNodes("ab:majors/ab:major", xm);
  41. foreach (XmlNode majorNode in majorNodes)
  42. {
  43. dpt.MajorList.Add(new Major(majorNode.Attributes["name"].Value,
  44. majorNode.SelectSingleNode("ab:name", xm) != null ? majorNode.SelectSingleNode("ab:name", xm).InnerText : string.Empty,
  45. majorNode.SelectSingleNode("ab:desc", xm) != null ? majorNode.SelectSingleNode("ab:desc", xm).InnerText : string.Empty,
  46. majorNode.SelectSingleNode("ab:career", xm) != null ? majorNode.SelectSingleNode("ab:career", xm).InnerText : string.Empty,
  47. majorNode.SelectSingleNode("ab:target", xm) != null ? majorNode.SelectSingleNode("ab:target", xm).InnerText : string.Empty,
  48. majorNode.SelectSingleNode("ab:subjects", xm) != null ? majorNode.SelectSingleNode("ab:subjects", xm).InnerText : string.Empty,
  49. majorNode.Attributes["new"] != null ? Convert.ToBoolean(int.Parse(majorNode.Attributes["new"].Value)) : false
  50. ));
  51. }
  52. Cache["DEPT_" + id] = dpt;
  53. //this.BindDeptData(deptName);
  54. }
  55. else
  56. {
  57. this.Title = "Error!";
  58. return;
  59. }
  60. }
  61. this.BindDeptData(id);
  62. }
  63. else
  64. {
  65. this.Title = "Error!";
  66. return;
  67. }
  68. }
  69. protected void BindDeptData(string deptId)
  70. {
  71. Department dept = (Department)Cache["DEPT_" + deptId];
  72. this.Title = string.Format("{1} {0}", dept.DeptName, dept.DeptChName);
  73. ltrDeptDesc.Text = dept.Description;
  74. //string dname = dept.DeptChName.Substring(dept.DeptChName.IndexOf(' ') + 1);
  75. ltrDeptName.Text = string.Format("{1}<br/>{0}", dept.DeptName, dept.DeptChName);
  76. if (dept.CommonSubjects != string.Empty)
  77. {
  78. string t = Regex.Replace(dept.CommonSubjects, @"\r\n", "</td></tr><tr><td>");
  79. t = Regex.Replace(t, @"\t{2,}", "</td><td class='last'>");
  80. t = Regex.Replace(t, "(First|Second|Third|Fourth) (Semester|Year)", "<em>$1 $2</em>");
  81. t = Regex.Replace(t, "?(?|?|?|?)(??|??)", "<em>?$1$2</em>");
  82. ltrCommonSubjects.Text = "<table class='subject'>" + t + "</table>";
  83. }
  84. else
  85. {
  86. pnCommon.Visible = false;
  87. }
  88. // get majors
  89. StringBuilder mhtml = new StringBuilder();
  90. mhtml.Append("<ul>");
  91. foreach (Major m in dept.MajorList)
  92. {
  93. mhtml.AppendFormat("<li><a href='major.aspx?d={0}&m={1}'>{2}</a> {3}</li>", Request.QueryString["d"], m.MajorName, m.MajorChName, m.IsNew?string.Format("<img src='{0}' />", (String)GetGlobalResourceObject("Resource1", "NewIconPathAbs")):"");
  94. }
  95. mhtml.Append("</ul>");
  96. ltrMajors.Text = mhtml.ToString();
  97. }
  98. }
  99. }