SimPage.master.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Web;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using Utils;
  10. using SiteCore;
  11. public partial class MasterPage_SimPage : System.Web.UI.MasterPage
  12. {
  13. BasePage _bp = null;
  14. protected override void OnInit(EventArgs e)
  15. {
  16. _bp = this.Page as BasePage;
  17. if (!IsPostBack)
  18. {
  19. if (!_bp.CheckRights()) return;
  20. if (!_bp._selfCheckPermission) if (!InitPermission()) return;
  21. }
  22. string path = CommonHelper.GetPrePath();
  23. StringBuilder str = new StringBuilder();
  24. str.AppendFormat("<script src=\"{0}js/boot.js?v={1}\" type=\"text/javascript\"></script>", path, BasePage.SiteVer);
  25. //str.AppendFormat("<link href=\"{0}css/view.css?v={1}\" rel=\"stylesheet\" />", path, BasePage.SiteVer);
  26. Literal lt = new Literal();
  27. lt.Text = str.ToString();
  28. Page.Header.Controls.AddAt(2, lt);
  29. base.OnInit(e);
  30. }
  31. protected void Page_Load(object sender, EventArgs e)
  32. {
  33. if (!IsPostBack)
  34. {
  35. if (_bp._script.Length > 0)
  36. litScript.Text = "<script type=\"text/javascript\">" + _bp._script.ToString() + "</script>";
  37. }
  38. }
  39. #region 初始化权限
  40. private bool InitPermission()
  41. {
  42. //自己检测权限
  43. if (_bp.PmTag == "")
  44. {
  45. _bp.ShowError("您当前没有权限查看该页面");
  46. return false;
  47. }
  48. DataTable dt = WebUser.GetPermission(_bp.PKey);
  49. System.Data.DataView dv = new System.Data.DataView(dt);
  50. dv.RowFilter = string.Format("tag='{0}' or tag like '{0}_%'", _bp.PmTag);
  51. if (dv.Count < 1)
  52. {
  53. _bp.ShowError("您当前没有权限查看该页面");
  54. return false;
  55. }
  56. string tag;
  57. StringBuilder str = new StringBuilder();
  58. int i = 0;
  59. foreach (DataRowView drv in dv)
  60. {
  61. tag = drv["Tag"].ToString();
  62. if (tag.IndexOf("_") == -1) continue;
  63. tag = tag.Replace(_bp.PmTag + "_", "");
  64. _bp._permissions.Add(tag);//加入权限
  65. if (tag == "view") continue;
  66. //else if (!_bp._addVisible) btnAdd.Visible = false;
  67. str.Append((i > 0 ? "|" : "") + tag + "," + drv["Name"]);
  68. i++;
  69. }
  70. if (str.Length > 0)
  71. _bp.AppendScript("actionData=\"" + str.ToString() + "\";");
  72. return true;
  73. }
  74. #endregion
  75. }