Пример #1
0
        public override void DataBind()
        {
            if (_bound)
            {
                return;
            }
            _bound = true;

            if (CMSMode == false && !CMSMode.Value && !this.MyPage.Editable)
            {
                StringBuilder cond = new StringBuilder();

                if (!String.IsNullOrWhiteSpace(Type))
                {
                    cond.Append(string.Format(" And (Type='{0}' or UniqueName='{0}')", StringUtils.SQLEncode(Type)));
                }

                if (status != DownloadStatus.All)
                {
                    cond.Append(string.Format(" And Status={0}", (int)Status));
                }

                if (NetworkBound)
                {
                    NetworkRelations networkRelations = new NetworkRelations();
                    cond.Append(" and " + networkRelations.GetRelationQueryByMember(cte.NetworkRelationTable, cte.NetworkRelateToField, WebContext.Profile.UserId));
                }

                if (NonMemberNetworkBound)
                {
                    NetworkRelations networkRelations = new NetworkRelations();
                    cond.Append(" and " + networkRelations.GetRelationQueryByNetwork(cte.NetworkRelationTable, cte.NetworkRelateToField, Int32.Parse(networkName)));
                }

                if (!string.IsNullOrWhiteSpace(Condition))
                {
                    cond.Append(string.Format(" And " + Condition));
                }

                if (DisplaySinceLastLogin)
                {
                    System.Data.DataRow member = lw.Members.Security.User.LoggedInUser(this, false) as System.Data.DataRow;
                    MemberLoginActivity mlMgr  = new MemberLoginActivity();
                    DataView            dv     = mlMgr.GetMemberActivity((int)member["MemberId"]);
                    dv.Sort = "Id Desc";
                    if (dv.Count >= 2)
                    {
                        cond.Append(string.Format(" and DateAdded>='{0}'", dv[1]["LoggedInDate"]));
                    }
                }

                this.SelectCommand = string.Format(" select Top {0} d.*,  '{1}/' + d.UniqueName + '/' + d.FileName as DownloadLink, FileSize/1024 as KB from DownloadsView d where Status<>{2} {3}",
                                                   Top,
                                                   Downloads.DownloadsVR,
                                                   (int)DownloadStatus.Disabled,
                                                   cond.ToString()
                                                   );

                if (!EnablePaging)
                {
                    this.SelectCommand += " Order By " + OrderBy;
                }
            }
            else
            {
                System.Web.HttpRequest Request = WebContext.Request;

                string cond = "1=1 ";

                if (!string.IsNullOrWhiteSpace(Condition))
                {
                    cond += string.Format(" And " + Condition);
                }
                if (!String.IsNullOrEmpty(Request["q"]))
                {
                    cond += string.Format(" and (Title like '%{0}%' or FileName like '%{0}%')", StringUtils.SQLEncode(Request["q"]));
                }

                if (!String.IsNullOrEmpty(Request["NetworkId"]))
                {
                    cond += string.Format(" and DownloadId in (select DownloadId from DownloadsNetwork where NetworkId = {0})", Int32.Parse(Request["NetworkId"]));
                }

                if (!String.IsNullOrWhiteSpace(Type))
                {
                    cond += (string.Format(" And (Type='{0}' or UniqueName='{0}')", StringUtils.SQLEncode(Type)));
                }

                if (!String.IsNullOrEmpty(Request["TypeId"]))
                {
                    string _type = Request["TypeId"];
                    cond += string.Format(" and DownloadType={0}", Int32.Parse(_type));
                }
                if (!String.IsNullOrEmpty(Request["Status"]))
                {
                    string _Status = Request["Status"];
                    cond += string.Format(" and Status={0}", Int32.Parse(_Status));
                }

                this.SelectCommand = string.Format(" select top {3} d.*,  '{1}/' + d.UniqueName + '/' + d.FileName as DownloadLink, FileSize/1024 as KB from DownloadsView d where {2}",
                                                   "100%",
                                                   Downloads.DownloadsVR,
                                                   cond,
                                                   Top
                                                   );


                if (!EnablePaging)
                {
                    this.SelectCommand += " Order By " + OrderBy;
                }
            }
            base.DataBind();
        }
Пример #2
0
        public override void DataBind()
        {
            if (_bound)
            {
                return;
            }
            _bound = true;

            StringBuilder query = new StringBuilder();

            query.Append("select ");

            // select top ..
            if (!String.IsNullOrWhiteSpace(Top))
            {
                query.Append("Top " + Top);
            }

            query.Append(" D.*, C.[Count] from DownloadTypes D ");
            query.Append("left outer Join");
            query.Append("(select count(*) as [Count],DownloadType as TypeId from Downloads ");

            bool whereAdded = false;

            if (status != DownloadStatus.All)
            {
                if (!whereAdded)
                {
                    query.Append(" where ");
                }
                else
                {
                    query.Append(" and ");
                }

                whereAdded = true;

                query.Append(string.Format("Status={0}", (int)status));
            }
            else
            {
                if (!whereAdded)
                {
                    query.Append(" where ");
                }
                else
                {
                    query.Append(" and ");
                }

                whereAdded = true;

                query.Append(string.Format("Status<>{0}", (int)DownloadStatus.Disabled));
            }

            if (NetworkBound)
            {
                NetworkRelations networkRelations = new NetworkRelations();
                if (!whereAdded)
                {
                    query.Append(" where ");
                }
                else
                {
                    query.Append(" and ");
                }

                whereAdded = true;

                query.Append(networkRelations.GetRelationQueryByMember(cte.NetworkRelationTable, cte.NetworkRelateToField, WebContext.Profile.UserId));
            }

            query.Append(" Group By DownloadType) C on D.TypeId = C.TypeId");


            if (!string.IsNullOrWhiteSpace(Condition))
            {
                query.Append(string.Format(" where " + Condition));
            }

            if (CMSMode == true)
            {
                query.Clear();
                query.Append("Select * from DownloadTypes");
            }

            this.SelectCommand = query.ToString();

            base.DataBind();
        }