GroupCommentsDataSource _getParent(Control el) { GroupCommentsDataSource ret = el.Parent as GroupCommentsDataSource; if (ret != null) { return(ret); } if (el.Parent != null) { return(_getParent(el.Parent)); } return(null); }
public override void DataBind() { if (_bound) { return; } _bound = true; lw.Base.CustomPage page = this.Page as lw.Base.CustomPage; string GroupName = page.GetQueryValue("CommentTitle"); if (!StringUtils.IsNullOrWhiteSpace(GroupName)) { String[] Split = GroupName.Split('-'); CommentId = Int32.Parse(Split[Split.Length - 1]); } if (ChildComments) { object obj = DataBinder.Eval(this.NamingContainer, "DataItem.CommentId"); if (obj != null) { ParentId = (int)obj; } } if (ParentId == -1) { object relationValue = DataBinder.Eval(this.NamingContainer, "DataItem." + cte.CommentsRelateTo); if (relationValue != null) { RelationId = (int)relationValue; } } GenerateSelectCommand(int.Parse(Top), 0); this.Visible = HasViewPermission; if (InheritPermission) { GroupCommentsDataSource parentDataSource = null; Control parent = this.Parent; do { parentDataSource = parent as GroupCommentsDataSource; if (parentDataSource != null) { break; } parent = parent.Parent; }while (parent != null); if (parentDataSource != null) { _hasWritePermission = parentDataSource.HasWritePermission; _hasViewPermission = parentDataSource.HasViewPermission; _hasDeletePermission = parentDataSource.HasDeletePermission; } } base.DataBind(); }
public override void DataBind() { dataSrc = _getParent(this); if (dataSrc == null) { this.Visible = false; } if (_bound || !this.Visible) { return; } _bound = true; if (!dataSrc.HasWritePermission) { this.Visible = false; return; } HtmlInputHidden RelationId = new HtmlInputHidden(); RelationId.ID = "RelateToId"; RelationId.Value = dataSrc.RelationId.ToString(); this.Controls.Add(RelationId); HtmlInputHidden ParentId = new HtmlInputHidden(); ParentId.ID = "ParentId"; ParentId.Value = dataSrc.ParentId.ToString(); this.Controls.Add(ParentId); if (this.IsPostBack && this.GetValue(ParentId) == dataSrc.ParentId.ToString() && this.GetValue(RelationId) == dataSrc.RelationId.ToString()) { NameValueCollection values = this.GetValues(); string text = values["Comment"]; if (!String.IsNullOrWhiteSpace(text)) { _cMgr.AddMemberComment(cte.CommentsTable, dataSrc.ParentId, dataSrc.ParentId > 0 ? -1 : dataSrc.RelationId, values["Subject"], text, WebContext.Profile.UserId, CommentType.Text); if (this.IsAjax) { AjaxResponse resp = new AjaxResponse(); resp.data = string.Format(@"{{ UserName: ""{0}"", Name: ""{1}"", Picture: }}" , ""); } else { WebContext.Response.Redirect(WebContext.Request.RawUrl); } } } base.DataBind(); }