/// <summary> /// 绑定权限及美化列表 /// </summary> /// <param name="rtpItem"></param> /// <param name="tablename"></param> private void BindItemPower(RepeaterItem rtpItem, String tablename) { DataRowView dv = rtpItem.DataItem as DataRowView; Int32 id = Convert.ToInt32(dv["id"].ToString()); Int32 layer = Convert.ToInt32(dv["layer"].ToString()); ActionType action = (ActionType)dv["actiontype"]; CheckBoxList chkaction = (CheckBoxList)rtpItem.FindControl("cbaction"); T_AccessControlEntity acl = ActionTypeList.Find(a => { return(a.Node == id && a.TableName == tablename); }); rtpItem.SetStyleLayer(layer); //绑定权限 foreach (ActionType item in ActionTypeValues) { if (!action.HasFlag(item) || item == ActionType.None || item == ActionType.ALL) { continue; } String text = item.ToString(); ListItem node = new ListItem(ActionTypeNames[text], text); if (acl != null && acl.ActionType.HasFlag(item)) { node.Selected = true; } chkaction.Items.Add(node); } }
/// <summary> /// 获取权限 /// </summary> /// <param name="rtpItem"></param> /// <param name="tablename"></param> /// <returns></returns> private T_AccessControlEntity GetItemPower(RepeaterItem rtpItem, String tablename) { HiddenField id = (HiddenField)rtpItem.FindControl("id"); HiddenField hidurl = (HiddenField)rtpItem.FindControl("link_url"); CheckBoxList chkaction = (CheckBoxList)rtpItem.FindControl("cbaction"); //权限 ActionType action = ActionType.None; foreach (ListItem n in chkaction.Items) { if (n.Selected) { ActionType value = (ActionType)Enum.Parse(typeof(ActionType), n.Value); action = action | value; } } T_AccessControlEntity acc = new T_AccessControlEntity { Link_Url = "", Role = EditID, ActionType = action, TableName = tablename, Node = Convert.ToInt32(id.Value) }; String strUrl = hidurl.Value.ToLower().Trim(); if (strUrl.IndexOf("?") > 0) { strUrl = strUrl.Substring(0, strUrl.IndexOf("?")); } acc.Link_Url = strUrl; return(acc); }
/// <summary> /// 批量删除 批量启用 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnCommand_Click(object sender, EventArgs e) { List <String> listid = new List <String>(); List <String> listtitle = new List <String>(); Int32 arg = Convert.ToInt32(Request.Form["__EVENTARGUMENT"]); if (arg == 0 || arg == 1 || arg == -1) { foreach (RepeaterItem item in Repeater1.Items) { CheckBox chkid = (CheckBox)item.FindControl("id"); HiddenField groupid = (HiddenField)item.FindControl("hidGroupid"); String title = ((HiddenField)item.FindControl("hidTitle")).Value; if (chkid.Checked) { //检查权限 T_AccessControlEntity acl = GroupAccessControl.Find(a => { return(a.Node == Convert.ToInt32(groupid.Value)); }); if (Admin.IsSuper || (acl.ActionType.HasFlag(ActionType.Setting) || acl.ActionType.HasFlag(ActionType.Delete))) { listid.Add(chkid.Text); listtitle.Add(title); } } } if (listid.Count > 0) { String idcoll = String.Join(",", listid.ToArray()); String titlecoll = String.Join(",", listtitle.ToArray()); switch (arg) { case 0: //禁用 db.ExecuteCommand(String.Format("UPDATE [T_News] SET isenable = 0 WHERE id IN({0})", idcoll)); AppendLogs("批量禁用内容:" + titlecoll, LogsAction.Edit); break; case -1: //删除 foreach (var _id in listid) { RemoveContent(_id); } break; case 1: //启用 db.ExecuteCommand(String.Format("UPDATE [T_News] SET isenable = 1 WHERE id IN({0})", idcoll)); AppendLogs("批量启用内容:" + titlecoll, LogsAction.Edit); break; } BindData(); } } }
/// <summary> /// 功能权限绑定 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DataRowView dv = e.Item.DataItem as DataRowView; Int32 id = Convert.ToInt32(dv["id"]); T_AccessControlEntity acl = data.Find(a => { return(a.Node == id && a.TableName == "t_sitemenu"); }); if (acl != null) { ((CheckBox)e.Item.FindControl("CheckBox1")).Checked = ActionTypeHelper.IsView(acl.ActionType); } } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { if (readaccess.SelectedIndex == -1) { readaccess.SelectedIndex = 0; } T_NewsEntity data = (T_NewsEntity)ViewState["data"]; data = this.GetFormValue <T_NewsEntity>(data); CmdType cmd = IsEdit ? CmdType.UPDATE : CmdType.INSERT; data.EditDate = DateTime.Now; if (!IsEdit) { data.PubDate = DateTime.Now; } T_AccessControlEntity acl = GetGroupAction(data.GroupId); if (acl.ActionType.HasFlag(ActionType.Create) || acl.ActionType.HasFlag(ActionType.Edit)) { #region 网络图片采集 HtmlDocument xml = new HtmlDocument(); xml.LoadHtml(data.Content); var html = xml.DocumentNode; var nodes = html.CssSelect("img[src^='http:']"); foreach (HtmlNode n in nodes) { HtmlAttribute src = n.Attributes["src"]; src.Value = DownloadImage(src.Value); } data.Content = xml.DocumentNode.WriteTo(); content.Text = data.Content; #endregion if (db.ExecuteCommand <T_NewsEntity>(data, cmd)) { if (!IsEdit) { this.ClearFromValue(); } Alert(Label1, "保存成功!", "line1px_3"); } } }
/// <summary> /// 加载编辑数据 /// </summary> protected void LoadData() { String sql = String.Format("SELECT a.*,b.groupname FROM [T_News] as a LEFT JOIN [T_Group] as b ON a.groupid = b.ID WHERE a.ID={0}", EditID); T_NewsEntity data = db.ExecuteObject <T_NewsEntity>(sql); ViewState["data"] = data; this.SetFormValue(data); T_AccessControlEntity acl = Access.Find(a => { return(a.Node == data.GroupId); }); if (!Admin.IsSuper && !ActionTypeHelper.IsSetting(acl.ActionType)) { nominate.Enabled = hotspot.Enabled = focus.Enabled = stick.Enabled = status.Enabled = false; } }
/// <summary> /// 批量删除 批量启用 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDelete_Click(object sender, EventArgs e) { List <Int32> list = new List <Int32>() { 0 }; Int32 arg = Convert.ToInt32(Request.Form["__EVENTARGUMENT"]); if (arg == 0 || arg == 1 || arg == -1) { foreach (RepeaterItem item in Repeater1.Items) { CheckBox chkbox = item.FindControl("id") as CheckBox; HiddenField groupid = item.FindControl("Groupid") as HiddenField; if (chkbox.Checked) { T_AccessControlEntity acl = Access.Find(a => { return(a.Node == Convert.ToInt32(groupid.Value)); }); if (Admin.IsSuper || (ActionTypeHelper.IsSetting(acl.ActionType) || ActionTypeHelper.IsDelete(acl.ActionType))) { list.Add(Convert.ToInt32(chkbox.Text)); } } } String id = String.Join(",", list.ToArray()); switch (arg) { case 0: //禁用 db.ExecuteCommand(String.Format("UPDATE [t_news] SET status = 0 WHERE id IN({0})", id)); break; case -1: //删除 foreach (var _id in list) { DELContentImages(_id); } db.ExecuteCommand(String.Format("DELETE FROM [t_news] WHERE id in ({0})", id)); break; case 1: //启用 db.ExecuteCommand(String.Format("UPDATE [t_news] SET status = 1 WHERE id IN({0})", id)); break; } BindData(); } }
/// <summary> /// 控件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DataRowView data = e.Item.DataItem as DataRowView; Int32 id = Convert.ToInt32(data["id"].ToString()); Int32 groupid = Convert.ToInt32(data["GroupID"].ToString()); ImageButton btndel = (ImageButton)e.Item.FindControl("del"); ImageButton btnedit = (ImageButton)e.Item.FindControl("edit"); btnedit.OnClientClick = String.Format("javascript:location.href='News_Edit.aspx?id={0}';return false;", id); btndel.OnClientClick = String.Format("javascript:dialogConfirm({{el:this,text:'将删除 {0} 且无法恢复!确定要删除吗?'}});return false;", data["title"].ToString()); if (!Admin.IsSuper) { T_AccessControlEntity acl = GroupAccessControl.Find(a => { return(a.Node == groupid); }); if (!acl.ActionType.HasFlag(ActionType.Edit)) { btnedit.Enabled = false; btnedit.ToolTip = "无权限修改."; btnedit.ImageUrl = "../skin/icos/write_disable.gif"; } if (!acl.ActionType.HasFlag(ActionType.Delete)) { btndel.Enabled = false; btndel.ToolTip = "无权限删除."; btndel.ImageUrl = "../skin/icos/del_disabled.gif"; } if (!acl.ActionType.HasFlag(ActionType.Setting)) { foreach (Control ctl in e.Item.Controls) { if (ctl is LinkButton) { LinkButton c = ((LinkButton)ctl); c.Enabled = false; c.ToolTip = "无权限操作."; } } } } } }
/// <summary> /// 加载编辑数据 /// </summary> protected void LoadData() { String strSql = String.Format("SELECT a.*,b.groupname FROM [T_News] as a LEFT JOIN [T_Group] as b ON a.groupid = b.ID WHERE a.ID={0}", EditID); T_NewsEntity data = db.ExecuteObject <T_NewsEntity>(strSql); ViewState["data"] = data; this.SetFormValue(data); T_AccessControlEntity acl = GetGroupAction(data.GroupId); if (acl == null || !acl.ActionType.HasFlag(ActionType.Edit)) { form1.Visible = false; btnSave.Visible = false; } if (acl != null && !acl.ActionType.HasFlag(ActionType.Setting)) { isnominate.Enabled = ishotspot.Enabled = isslide.Enabled = isstick.Enabled = isenable.Enabled = isaudit.Enabled = iscomments.Enabled = readaccess.Enabled = false; } }
/// <summary> /// 列表事件 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { String id = ((CheckBox)e.Item.FindControl("ID")).Text; Int32 groupid = Convert.ToInt32(((HiddenField)e.Item.FindControl("hidGroupid")).Value); String title = ((HiddenField)e.Item.FindControl("hidTitle")).Value; T_AccessControlEntity acl = GroupAccessControl.Find(a => { return(a.Node == groupid); }); switch (e.CommandName) { case "del": if (Admin.IsSuper || acl.ActionType.HasFlag(ActionType.Delete)) { RemoveContent(id); } break; case "iscomments": case "isstick": case "isnominate": case "ishotspot": case "isslide": case "isaudit": case "isenable": if (Admin.IsSuper || acl.ActionType.HasFlag(ActionType.Setting)) { ExecuteObject obj = new ExecuteObject(); obj.cmdtype = CmdType.UPDATE; obj.tableName = "T_News"; obj.terms.Add("id", id); obj.cells.Add(e.CommandName, !Convert.ToBoolean(e.CommandArgument)); db.ExecuteCommand(obj); AppendLogs(((LinkButton)e.CommandSource).ToolTip + ":" + title, LogsAction.Edit); } break; } BindData(); }
/// <summary> /// 控件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { DataRowView dv = e.Item.DataItem as DataRowView; Int32 ID = Convert.ToInt32(dv["id"]); Int32 GroupID = Convert.ToInt32(dv["GroupID"]); CheckBox chk = e.Item.FindControl("id") as CheckBox; ImageButton del = e.Item.FindControl("del") as ImageButton; ImageButton edit = e.Item.FindControl("edit") as ImageButton; ImageButton status = e.Item.FindControl("status") as ImageButton; ImageButton focus = e.Item.FindControl("focus") as ImageButton; ImageButton stick = e.Item.FindControl("stick") as ImageButton; if (Convert.ToBoolean(dv["status"])) { status.ImageUrl = "images/icos/checkbox_yes.png"; } if (Convert.ToBoolean(dv["focus"])) { focus.ImageUrl = "images/icos/checkbox_yes.png"; } if (Convert.ToBoolean(dv["stick"])) { stick.ImageUrl = "images/icos/checkbox_yes.png"; } edit.OnClientClick = String.Format("javascript:location.href='News_Edit.aspx?id={0}';return false;", ID); del.OnClientClick = String.Format("javascript:dialogConfirm({{el:this,text:'将删除 {0} 且无法恢复!确定要删除吗?'}});return false;", dv["title"]); if (!Admin.IsSuper) { T_AccessControlEntity acl = Access.Find(a => { return(a.Node == GroupID); }); if (!ActionTypeHelper.IsEdit(acl.ActionType)) { edit.Enabled = false; edit.ToolTip = "无权限修改."; edit.ImageUrl = "images/icos/write_disable.gif"; } if (!ActionTypeHelper.IsDelete(acl.ActionType)) { del.Enabled = false; del.ToolTip = "无权限删除."; del.ImageUrl = "images/icos/del_disabled.gif"; } if (!ActionTypeHelper.IsSetting(acl.ActionType)) { stick.Enabled = focus.Enabled = status.Enabled = false; stick.ToolTip = focus.ToolTip = status.ToolTip = "无权限设置."; if (Convert.ToBoolean(dv["status"])) { status.ImageUrl = "images/icos/checkbox_disabled.png"; } if (Convert.ToBoolean(dv["focus"])) { focus.ImageUrl = "images/icos/checkbox_disabled.png"; } if (Convert.ToBoolean(dv["stick"])) { stick.ImageUrl = "images/icos/checkbox_disabled.png"; } } } } }