Ejemplo n.º 1
0
        public override void DataBind()
        {
            if (!_bound)
            {
                _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 (!NoRelations)
                {
                    Comments.Comments_Tables_View table = cMgr.GetTableDetails(TableName);
                    if (table == null)
                    {
                        return;
                    }

                    object relationValue = ControlUtils.GetBoundedDataField(this.NamingContainer, table.RelationField);
                    if (MembersOnly)
                    {
                        this.SelectCommand = cMgr.GetMemberCommentsQueryWithRelations(TableName, (int)relationValue, -1, Top);
                    }
                    else
                    {
                        this.SelectCommand = cMgr.GetCommentsQueryWithRelations(TableName, (int)relationValue, -1, Top);
                    }
                }
                else
                {
                    if (MembersOnly)
                    {
                        if (ChildComments)
                        {
                            object obj = DataBinder.Eval(this.NamingContainer, "DataItem.CommentId");

                            if (obj != null)
                            {
                                ParentId = (int)obj;
                            }
                        }

                        this.SelectCommand  = cMgr.GetMemberCommentsQueryWithNoRelations(TableName, ParentId, Top);
                        this.SelectCommand += string.Format(" And C.Status&{0}={0}", (int)Status.Enabled);

                        if (ChildComments)
                        {
                            this.SelectCommand += string.Format(" And C.CommentId>{0} Order by C.CommentId ASC", 0);
                        }
                        else
                        {
                            if (CommentId != -2)
                            {
                                this.SelectCommand += string.Format("And (CommentId={0} or ParentId={0})", CommentId);
                            }
                        }
                    }
                    else
                    {
                        this.SelectCommand = cMgr.GetCommentsQueryNoRelations(TableName, -1, Top);
                    }
                }
                //TODO: Display Disabled Comments in case an administrator is logged in
                if (!MembersOnly)
                {
                    //this.SelectCommand += String.Format(" And Status&{0}={0}", (int)Status.Enabled);

                    if (!EnablePaging)
                    {
                        this.SelectCommand += " Order By DateCreated DESC";
                    }
                }
            }
            base.DataBind();
        }