using SiteCore;
using System;
using System.Data;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utils;
public partial class MasterPage_View : System.Web.UI.MasterPage
{
BasePage _bp = null;
protected override void OnInit(EventArgs e)
{
_bp = this.Page as BasePage;
if (!IsPostBack)
{
if (_bp._checkRight && !_bp.CheckRights()) return;
if (!_bp._selfCheckPermission) if (!InitPermission()) return;
if (!_bp._addVisible) btnAdd.Visible = false;
//else btnAdd.Visible = true;
//权限
if (_bp._selfAddVisible == 1) btnAdd.Visible = true;
}
//时间
//hUID.Value = _bp.CurrentUser.UserID.ToString();
hRepTitle.Value = _bp._repTitle;
_bp._b_sDate = _bp.GetString("sdt");
_bp._searchDate = _bp.GetString("dt");
if (_bp._searchDate == "") _bp._searchDate = _bp.GetString("edt");
if (_bp._searchDate == "")
{
_bp._filterDate = DateTime.Now;
_bp._searchDate = _bp._filterDate.ToString("yyyy-MM-dd");
}
else
{
if (_bp._searchDate.IndexOf("/") != -1)
{
_bp._searchDate = _bp._searchDate.Replace("/", "-");
}
else
{
if (_bp._searchDate.Split('-').Length == 1) _bp._searchDate += "-01-01";
else if (_bp._searchDate.Split('-').Length == 2) _bp._searchDate += "-01";
}
_bp._filterDate = Convert.ToDateTime(_bp._searchDate);
}
_bp._b_eDate = _bp._searchDate;
//显示刷新
btnRefresh.Visible = _bp._refreshVisible;
if (_bp._choiceVisible) btnChoice.Visible = true;
string path = CommonHelper.GetPrePath();
StringBuilder str = new StringBuilder();
str.AppendFormat("", path, BasePage.SiteVer);
str.AppendFormat("", path, BasePage.SiteVer);
str.AppendFormat("", path, BasePage.SiteVer);
str.AppendFormat("", path, BasePage.SiteVer);
Literal lt = new Literal();
lt.Text = str.ToString();
Page.Header.Controls.AddAt(1, lt);
base.OnInit(e);
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (_bp._searchDateEnum == SearchDateEnum.Empty && _bp._searchFilter != "") _bp._searchDateEnum = SearchDateEnum.Default;
if (_bp._searchDateEnum != SearchDateEnum.Empty) initSearch(_bp._searchFilter);
keyPlace.Visible = _bp._keyFilterVisible;
btnAdd.Visible = _bp._addVisible;
btnRefresh.Visible = _bp._refreshVisible;
//if (_bp._selfCheckPermission)
//{
// btnAdd.Visible = _bp._addVisible;
// btnRefresh.Visible = _bp._refreshVisible;
//}
//else if (_bp._addVisible || (_bp._permissions.Contains("save") || _bp._permissions.Contains("add")))
//{
// btnAdd.Visible = true;
//}
//if (_bp.gcTag != "")
//{
// hGcTag.Value = _bp.gcTag + "_" + _bp.CurrentUser.UserID;
// DataTable cDt = WebCache.GetGridColumns();
// DataView cDv = new DataView(cDt);
// cDv.RowFilter = "name='" + _bp.gcTag + "_" + _bp.CurrentUser.UserID + "'";
// if (cDv.Count > 0)
// {
// _bp.AppendScript("colsData=" + cDv[0]["con"] + ";");
// }
//}
//if (_bp._searchDateEnum == SearchDateEnum.DefaultTime)
//{
// _bp.GetSearchDateTime(ref _bp._b_sDate, ref _bp._b_eDate, _bp.onlyEndTime);
//}
if (!_bp._noneDefaultTime)
{
hSDate.Value = _bp._b_sDate;
hDate.Value = _bp._b_eDate;
}
if (_bp._keyFilterVisible || _bp._searchDateEnum != SearchDateEnum.Empty)
searchPlace.Visible = true;
else
searchPlace.Visible = false;
if (_bp._script.Length > 0)
litScript.Text = "";
}
}
private void initSearch(string filter)
{
StringBuilder str = new StringBuilder();
switch (_bp._searchDateEnum)
{
case SearchDateEnum.OneDay:
{
str.AppendLine("日期:");
break;
}
case SearchDateEnum.OneMonth:
{
str.AppendLine("日期:");
break;
}
case SearchDateEnum.OneYear:
{
str.AppendLine("日期:");
break;
}
case SearchDateEnum.TwoMonth:
{
str.AppendLine("日期:");
str.AppendLine("- ");
break;
}
case SearchDateEnum.DefaultTime:
{
str.AppendLine("日期:");
str.AppendLine("- ");
break;
}
default:
{
str.AppendLine("日期:");
str.AppendLine("- ");
break;
}
}
if (filter != "")
{
string[] sArr = filter.Split(',');
str.AppendLine("");
for (int i = 0; i < sArr.Length; i++)
{
str.AppendLine(" " + sArr[i] + "");
}
str.AppendLine("");
}
litSearch.Text = str.ToString();
}
private bool InitPermission()
{
//自己检测权限
if (_bp.PmTag == "")
{
_bp.ShowError("您当前没有权限查看该页面");
return false;
}
DataTable dt = WebUser.GetPermission(_bp.PKey);
System.Data.DataView dv = new System.Data.DataView(dt);
dv.RowFilter = string.Format("tag='{0}' or tag like '{0}_%'", _bp.PmTag);
if (dv.Count < 1)
{
_bp.ShowError("您当前没有权限查看该页面");
return false;
}
string tag;
StringBuilder str = new StringBuilder();
int i = 0;
foreach (DataRowView drv in dv)
{
tag = drv["Tag"].ToString();
if (tag.IndexOf("_") == -1) continue;
tag = tag.Replace(_bp.PmTag + "_", "");
_bp._permissions.Add(tag);//加入权限
if (tag == "view") continue;
if (tag == "add" && _bp._addVisible) btnAdd.Visible = true;
//else if (!_bp._addVisible) btnAdd.Visible = false;
str.Append((i > 0 ? "|" : "") + tag + "," + drv["Name"]);
i++;
}
if (str.Length > 0)
_bp.AppendScript("actionData=\"" + str.ToString() + "\";");
return true;
}
}