View.master.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. using SiteCore;
  2. using System;
  3. using System.Data;
  4. using System.Text;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using Utils;
  8. public partial class MasterPage_View : System.Web.UI.MasterPage
  9. {
  10. BasePage _bp = null;
  11. protected override void OnInit(EventArgs e)
  12. {
  13. _bp = this.Page as BasePage;
  14. if (!IsPostBack)
  15. {
  16. if (_bp._checkRight && !_bp.CheckRights()) return;
  17. if (!_bp._selfCheckPermission) if (!InitPermission()) return;
  18. if (!_bp._addVisible) btnAdd.Visible = false;
  19. //else btnAdd.Visible = true;
  20. //权限
  21. if (_bp._selfAddVisible == 1) btnAdd.Visible = true;
  22. }
  23. //时间
  24. //hUID.Value = _bp.CurrentUser.UserID.ToString();
  25. hRepTitle.Value = _bp._repTitle;
  26. _bp._b_sDate = _bp.GetString("sdt");
  27. _bp._searchDate = _bp.GetString("dt");
  28. if (_bp._searchDate == "") _bp._searchDate = _bp.GetString("edt");
  29. if (_bp._searchDate == "")
  30. {
  31. _bp._filterDate = DateTime.Now;
  32. _bp._searchDate = _bp._filterDate.ToString("yyyy-MM-dd");
  33. }
  34. else
  35. {
  36. if (_bp._searchDate.IndexOf("/") != -1)
  37. {
  38. _bp._searchDate = _bp._searchDate.Replace("/", "-");
  39. }
  40. else
  41. {
  42. if (_bp._searchDate.Split('-').Length == 1) _bp._searchDate += "-01-01";
  43. else if (_bp._searchDate.Split('-').Length == 2) _bp._searchDate += "-01";
  44. }
  45. _bp._filterDate = Convert.ToDateTime(_bp._searchDate);
  46. }
  47. _bp._b_eDate = _bp._searchDate;
  48. //显示刷新
  49. btnRefresh.Visible = _bp._refreshVisible;
  50. if (_bp._choiceVisible) btnChoice.Visible = true;
  51. string path = CommonHelper.GetPrePath();
  52. StringBuilder str = new StringBuilder();
  53. str.AppendFormat("<script src=\"{0}js/boot.js?v={1}\" type=\"text/javascript\"></script>", path, BasePage.SiteVer);
  54. str.AppendFormat("<script src=\"{0}js/view.js?v={1}\" type=\"text/javascript\"></script>", path, BasePage.SiteVer);
  55. str.AppendFormat("<script src=\"{0}js/view.ex.js?v={1}\" type=\"text/javascript\"></script>", path, BasePage.SiteVer);
  56. str.AppendFormat("<link href=\"{0}css/view.css?v={1}\" rel=\"stylesheet\" />", path, BasePage.SiteVer);
  57. Literal lt = new Literal();
  58. lt.Text = str.ToString();
  59. Page.Header.Controls.AddAt(1, lt);
  60. base.OnInit(e);
  61. }
  62. protected void Page_Load(object sender, EventArgs e)
  63. {
  64. if (!IsPostBack)
  65. {
  66. if (_bp._searchDateEnum == SearchDateEnum.Empty && _bp._searchFilter != "") _bp._searchDateEnum = SearchDateEnum.Default;
  67. if (_bp._searchDateEnum != SearchDateEnum.Empty) initSearch(_bp._searchFilter);
  68. keyPlace.Visible = _bp._keyFilterVisible;
  69. btnAdd.Visible = _bp._addVisible;
  70. btnRefresh.Visible = _bp._refreshVisible;
  71. //if (_bp._selfCheckPermission)
  72. //{
  73. // btnAdd.Visible = _bp._addVisible;
  74. // btnRefresh.Visible = _bp._refreshVisible;
  75. //}
  76. //else if (_bp._addVisible || (_bp._permissions.Contains("save") || _bp._permissions.Contains("add")))
  77. //{
  78. // btnAdd.Visible = true;
  79. //}
  80. //if (_bp.gcTag != "")
  81. //{
  82. // hGcTag.Value = _bp.gcTag + "_" + _bp.CurrentUser.UserID;
  83. // DataTable cDt = WebCache.GetGridColumns();
  84. // DataView cDv = new DataView(cDt);
  85. // cDv.RowFilter = "name='" + _bp.gcTag + "_" + _bp.CurrentUser.UserID + "'";
  86. // if (cDv.Count > 0)
  87. // {
  88. // _bp.AppendScript("colsData=" + cDv[0]["con"] + ";");
  89. // }
  90. //}
  91. //if (_bp._searchDateEnum == SearchDateEnum.DefaultTime)
  92. //{
  93. // _bp.GetSearchDateTime(ref _bp._b_sDate, ref _bp._b_eDate, _bp.onlyEndTime);
  94. //}
  95. if (!_bp._noneDefaultTime)
  96. {
  97. hSDate.Value = _bp._b_sDate;
  98. hDate.Value = _bp._b_eDate;
  99. }
  100. if (_bp._keyFilterVisible || _bp._searchDateEnum != SearchDateEnum.Empty)
  101. searchPlace.Visible = true;
  102. else
  103. searchPlace.Visible = false;
  104. if (_bp._script.Length > 0)
  105. litScript.Text = "<script type=\"text/javascript\">" + _bp._script.ToString() + "</script>";
  106. }
  107. }
  108. private void initSearch(string filter)
  109. {
  110. StringBuilder str = new StringBuilder();
  111. switch (_bp._searchDateEnum)
  112. {
  113. case SearchDateEnum.OneDay:
  114. {
  115. str.AppendLine("日期:<input id=\"txtEdate\" class=\"mini-datepicker\" style=\"width:110px;\" onvaluechanged=\"view_search\" format=\"yyyy-MM-dd\" />");
  116. break;
  117. }
  118. case SearchDateEnum.OneMonth:
  119. {
  120. str.AppendLine("日期:<input id=\"txtEdate\" class=\"mini-monthpicker\" style=\"width:110px;\" onvaluechanged=\"view_search\" format=\"yyyy-M\"/>");
  121. break;
  122. }
  123. case SearchDateEnum.OneYear:
  124. {
  125. str.AppendLine("日期:<input id=\"txtEdate\" class=\"mini-datepicker\" style=\"width:110px;\" onvaluechanged=\"view_search\" format=\"yyyy\"/>");
  126. break;
  127. }
  128. case SearchDateEnum.TwoMonth:
  129. {
  130. str.AppendLine("日期:<input id=\"txtSdate\" class=\"mini-monthpicker\" style=\"width:110px;\" onvaluechanged=\"view_search\" format=\"yyyy-MM\" />");
  131. str.AppendLine("-&nbsp;<input id=\"txtEdate\" class=\"mini-monthpicker\" style=\"width:110px;\" onvaluechanged=\"view_search\" format=\"yyyy-MM\" />");
  132. break;
  133. }
  134. case SearchDateEnum.DefaultTime:
  135. {
  136. str.AppendLine("日期:<input id=\"txtSdate\" class=\"mini-datepicker\" style=\"width:170px;\" onvaluechanged=\"view_search\" format=\"yyyy-MM-dd HH:mm:ss\" showTime=\"true\" time=\"HH:mm:ss\" />");
  137. str.AppendLine("-&nbsp;<input id=\"txtEdate\" class=\"mini-datepicker\" style=\"width:170px;\" onvaluechanged=\"view_search\" format=\"yyyy-MM-dd HH:mm:ss\" showTime=\"true\" time=\"HH:mm:ss\" />");
  138. break;
  139. }
  140. default:
  141. {
  142. str.AppendLine("日期:<input id=\"txtSdate\" class=\"mini-datepicker\" style=\"width:110px;\" onvaluechanged=\"view_search\" format=\"yyyy-MM-dd\" />");
  143. str.AppendLine("-&nbsp;<input id=\"txtEdate\" class=\"mini-datepicker\" style=\"width:110px;\" onvaluechanged=\"view_search\" format=\"yyyy-MM-dd\" />");
  144. break;
  145. }
  146. }
  147. if (filter != "")
  148. {
  149. string[] sArr = filter.Split(',');
  150. str.AppendLine("<span id=\"sp_date_filter\">");
  151. for (int i = 0; i < sArr.Length; i++)
  152. {
  153. str.AppendLine(" &nbsp;<a href=\"###\">" + sArr[i] + "</a>");
  154. }
  155. str.AppendLine("</span>");
  156. }
  157. litSearch.Text = str.ToString();
  158. }
  159. private bool InitPermission()
  160. {
  161. //自己检测权限
  162. if (_bp.PmTag == "")
  163. {
  164. _bp.ShowError("您当前没有权限查看该页面");
  165. return false;
  166. }
  167. DataTable dt = WebUser.GetPermission(_bp.PKey);
  168. System.Data.DataView dv = new System.Data.DataView(dt);
  169. dv.RowFilter = string.Format("tag='{0}' or tag like '{0}_%'", _bp.PmTag);
  170. if (dv.Count < 1)
  171. {
  172. _bp.ShowError("您当前没有权限查看该页面");
  173. return false;
  174. }
  175. string tag;
  176. StringBuilder str = new StringBuilder();
  177. int i = 0;
  178. foreach (DataRowView drv in dv)
  179. {
  180. tag = drv["Tag"].ToString();
  181. if (tag.IndexOf("_") == -1) continue;
  182. tag = tag.Replace(_bp.PmTag + "_", "");
  183. _bp._permissions.Add(tag);//加入权限
  184. if (tag == "view") continue;
  185. if (tag == "add" && _bp._addVisible) btnAdd.Visible = true;
  186. //else if (!_bp._addVisible) btnAdd.Visible = false;
  187. str.Append((i > 0 ? "|" : "") + tag + "," + drv["Name"]);
  188. i++;
  189. }
  190. if (str.Length > 0)
  191. _bp.AppendScript("actionData=\"" + str.ToString() + "\";");
  192. return true;
  193. }
  194. }