Пример #1
0
        public void CreateUrl(StringBuilder sb, bool setFilterQuery, bool addAllCustomParameters, bool removeSession)
        {
            sb.Append("/");
            sb.Append(Page ?? "MainPage");
            if (InitializerSection.UseMainPageExt)
            {
                sb.Append(".aspx");
            }
            if (IsDataControl)
            {
                sb.Append("/data");
            }
            if (NavigateTo)
            {
                sb.Append("/navigateto");
            }
            if (IsDownload)
            {
                sb.Append("/download");
            }
            if (IsExecute)
            {
                sb.Append("/execute");
            }
            if (IsCustomUserControl)
            {
                sb.Append("/custom");
            }
            if (new[] { IsDataControl, IsDownload, IsExecute, NavigateTo }.Count(r => r) > 1)
            {
                throw new Exception("заданы взаимоисключающие параметры IsDataControl, IsDownload, IsExecute, NavigateTo");
            }

            if (UserControl != null && !UserControl.Equals(""))
            {
                sb.Append("/" + UserControl);
            }
            else if (IsDownload || IsExecute)
            {
                sb.Append("/");
            }
            if (ShowHistory)
            {
                sb.Append("/showhistory");
            }
            if (IsNew)
            {
                sb.Append("/new");
            }
            if (IsMultipleSelect)
            {
                sb.Append("/multipleselect");
            }
            if (IsSelect && !IsMultipleSelect)
            {
                sb.Append("/select");
            }
            if (ShowFilter)
            {
                sb.Append("/showfilter");
            }
            if (IsRead)
            {
                sb.Append("/read");
            }
            if (IsFilterWindow)
            {
                sb.Append("/filter");
            }
            bool hasQuery = false;

            if (QueryParameters.Count > 0)
            {
                sb.Append("?");
                hasQuery = true;
                foreach (var pair in QueryParameters)
                {
                    if (ParameterConverter.ContainsKey(pair.Key))
                    {
                        sb.Append(ParameterConverter[pair.Key]);
                    }
                    else if (!string.IsNullOrEmpty(QueryParametersPrefix))
                    {
                        if (RemoveQueryParameterPrefix)
                        {
                            if (pair.Key.StartsWith(QueryParametersPrefix))
                            {
                                sb.Append(pair.Key.Substring(QueryParametersPrefix.Length));
                            }
                            else
                            {
                                sb.Append(pair.Key);
                            }
                        }
                        else
                        {
                            if (!pair.Key.StartsWith("ref"))
                            {
                                sb.Append(QueryParametersPrefix);
                            }
                            sb.Append(pair.Key);
                        }
                    }
                    else
                    {
                        sb.Append(pair.Key);
                    }
                    sb.Append("=");
                    sb.Append(pair.Value == "{0}" ? pair.Value : HttpUtility.UrlEncode(pair.Value));
                    sb.Append("&");
                }
                sb.Remove(sb.Length - 1, 1); //убираем симол "&"  конца строки
            }

            foreach (var pair in CustomQueryParameters)
            {
                if (!pair.Value.UseInUrl && !addAllCustomParameters)
                {
                    continue;
                }
                if (!hasQuery)
                {
                    sb.Append("?");
                    hasQuery = true;
                }
                else
                {
                    sb.Append("&");
                }
                sb.Append(CustomParameterPrefix);
                sb.Append(pair.Key);
                sb.Append("=");
                sb.Append(HttpUtility.UrlEncode(pair.Value.Value));
            }

            AddParameter(sb, "culture", Culture, ref hasQuery);
            AddParameter(sb, "DataSessionKey", DataSessionKey, ref hasQuery);
            AddParameter(sb, "reportPluginName", HttpUtility.UrlEncode(ReportPluginName), ref hasQuery);
            AddParameter(sb, "mode", HttpUtility.UrlEncode(SelectMode), ref hasQuery);
            AddParameter(sb, "viewmode", HttpUtility.UrlEncode(ViewMode), ref hasQuery);
            AddParameter(sb, "__historyOnDate", HistoryOnDate.ToString(), ref hasQuery);
            AddParameter(sb, "__SNColumn", HttpUtility.UrlEncode(SelectNameColumn), ref hasQuery);
            AddParameter(sb, "__SKVColumn", HttpUtility.UrlEncode(SelectKeyValueColumn), ref hasQuery);
            AddParameter(sb, "__SFAddType", HttpUtility.UrlEncode(SelectForAddType), ref hasQuery);
            AddParameter(sb, "__customFCN", HttpUtility.UrlEncode(CustomFilterClassName), ref hasQuery);
            if (DeniedUseShortFilters)
            {
                AddParameter(sb, "__deniedShortFilters", "on", ref hasQuery);
            }
            if (TimeoutInSQL)
            {
                AddParameter(sb, "__timeoutInSQL", "on", ref hasQuery);
            }

            if (SetSelectedValues)
            {
                AddParameter(sb, "__selected", HttpUtility.UrlEncode(SelectedValues), ref hasQuery);
            }

            if (FilterQuery != null && setFilterQuery)
            {
                if (hasQuery)
                {
                    sb.Append("&");
                }
                else
                {
                    sb.Append("?");
                    hasQuery = true;
                }
                sb.AppendFormat("__filter={0}", HttpUtility.UrlEncode(FilterQuery));
            }
            if (ControlFilterParameters.Count > 0)
            {
                if (hasQuery)
                {
                    sb.Append("&");
                }
                else
                {
                    sb.Append("?");
                    hasQuery = true;
                }
                List <FilterParameter> filters;
                if (removeSession)
                {
                    filters = new List <FilterParameter>(ControlFilterParameters.Count);
                    foreach (var filterParameter in ControlFilterParameters)
                    {
                        var value = string.IsNullOrEmpty(filterParameter.SessionKey)
                                           ? filterParameter.Value
                                           : (string)HttpContext.Current.Session[filterParameter.SessionKey];
                        filters.Add(new FilterParameter
                        {
                            Key   = filterParameter.Key,
                            Value = value,
                        });
                    }
                }
                else
                {
                    filters = ControlFilterParameters;
                }

                string serialize = new JavaScriptSerializer().Serialize(filters);
                sb.AppendFormat("__filters={0}", HttpUtility.UrlEncode(serialize));
            }
            if (SelectParameters != null)
            {
                if (hasQuery)
                {
                    sb.Append("&");
                }
                else
                {
                    sb.Append("?");
                    hasQuery = true;
                }
                string serialize = new JavaScriptSerializer().Serialize(SelectParameters);
                sb.AppendFormat("__selParams={0}", HttpUtility.UrlEncode(serialize));
            }
            if (CreateBackUrlByRequest)
            {
                if (hasQuery)
                {
                    sb.Append("&");
                }
                else
                {
                    sb.Append("?");
                    hasQuery = true;
                }
                string url = HttpContext.Current.Request.Url.PathAndQuery;
                url = _queryRegexBackUrl.Replace(url, "").Replace("&&", "&").Replace("?&", "?");
                sb.AppendFormat("__backurl={0}", HttpUtility.UrlEncode(url));
            }
            else if (!string.IsNullOrEmpty(BackUrl))
            {
                if (hasQuery)
                {
                    sb.Append("&");
                }
                else
                {
                    sb.Append("?");
                    hasQuery = true;
                }
                sb.AppendFormat("__backurl={0}", HttpUtility.UrlEncode(BackUrl));
            }
        }