예제 #1
0
        public void SetFilter(string controlName, string filter)
        {
            var sessionKey = RemoveFilterGetSession(controlName);

            while (ControlFilterParameters.Count > 4)
            {
                ControlFilterParameters.RemoveAt(0);
            }
            if (filter != null && filter.Length > 100 && string.IsNullOrEmpty(sessionKey) && HttpContext.Current != null && HttpContext.Current.Session != null)
            {
                sessionKey = Guid.NewGuid().ToString();
            }
            if (!string.IsNullOrEmpty(sessionKey) && !string.IsNullOrEmpty(filter) && HttpContext.Current != null && HttpContext.Current.Session != null)
            {
                if (HttpContext.Current.Session[sessionKey] != null && (string)HttpContext.Current.Session[sessionKey] != filter)
                {
                    sessionKey = Guid.NewGuid().ToString();
                }
                HttpContext.Current.Session[sessionKey] = filter;
                ControlFilterParameters.Add(new FilterParameter {
                    Key = controlName, SessionKey = sessionKey
                });
            }
            else
            {
                ControlFilterParameters.Add(new FilterParameter {
                    Key = controlName, Value = filter
                });
            }
        }
예제 #2
0
        public string SetFilterBySessionKey(string controlName, string filter)
        {
            RemoveFilter(controlName);
            var sessionKey = Guid.NewGuid().ToString();

            // note: возмножно вместо удаления параметров нужно использовать сессию
            while (ControlFilterParameters.Count > 2)
            {
                ControlFilterParameters.RemoveAt(0);
            }
            if (!string.IsNullOrEmpty(sessionKey) && HttpContext.Current != null && HttpContext.Current.Session != null)
            {
                HttpContext.Current.Session[sessionKey] = filter;
                ControlFilterParameters.Add(new FilterParameter {
                    Key = controlName, SessionKey = sessionKey
                });
            }
            else
            {
                ControlFilterParameters.Add(new FilterParameter {
                    Key = controlName, Value = filter
                });
            }
            return(sessionKey);
        }
예제 #3
0
        public void CheckUseSession()
        {
            if (!ControlFilterParameters.All(r => string.IsNullOrEmpty(r.SessionKey)))
            {
                return;
            }
            var filters = new List <FilterParameter>(ControlFilterParameters);

            ControlFilterParameters = new List <FilterParameter>();
            foreach (var filterParameter in filters)
            {
                SetFilter(filterParameter.Key, filterParameter.Value);
            }
        }
예제 #4
0
        public string RemoveFilterGetSession(string controlName)
        {
            var row = ControlFilterParameters.
                      Select((r, ind) => new { r.Key, r.SessionKey, ind }).
                      Where(r => r.Key.Equals(controlName, StringComparison.OrdinalIgnoreCase)).
                      Select(r => new { r.SessionKey, r.ind }).
                      FirstOrDefault();

            if (row != null)
            {
                ControlFilterParameters.RemoveAt(row.ind);
                return(row.SessionKey);
            }
            return(null);
        }
예제 #5
0
        public string GetFilter(string controlName)
        {
            var filter = ControlFilterParameters.
                         Where(p => p.Key.Equals(controlName, StringComparison.OrdinalIgnoreCase)).
                         FirstOrDefault();

            if (!string.IsNullOrEmpty(filter.SessionKey))
            {
                return((string)HttpContext.Current.Session[filter.SessionKey]);
            }
            if (string.IsNullOrEmpty(filter.Value))
            {
                return(filter.Value);
            }
            return(filter.Value);
        }
예제 #6
0
        private void ParseQuery()
        {
            if (!string.IsNullOrEmpty(Query))
            {
                Match match = _queryRegex.Match(Query);
                while (match.Success)
                {
                    if (match.Groups["field"].Success && match.Groups["value"].Success)
                    {
                        var fieldValue = HttpUtility.UrlDecode(match.Groups["value"].Value);
                        if (match.Groups["field"].Value == "mode")
                        {
                            SelectMode = fieldValue;
                        }
                        else if (match.Groups["field"].Value == "viewmode")
                        {
                            ViewMode = fieldValue;
                        }
                        else if (match.Groups["field"].Value == "culture")
                        {
                            Culture = fieldValue;
                        }
                        else if (match.Groups["field"].Value == "storageValues")
                        {
                            StorageValuesSessionKey = fieldValue;
                        }
                        else if (match.Groups["field"].Value == "DataSessionKey")
                        {
                            DataSessionKey = match.Groups["value"].Value;
                        }
                        else if (match.Groups["field"].Value == "reportPluginName")
                        {
                            ReportPluginName = fieldValue;
                        }
                        else if (match.Groups["field"].Value == "__backurl")
                        {
                            BackUrl = HttpUtility.UrlDecode(Query.Substring(match.Groups["value"].Index));
                        }
                        else if (match.Groups["field"].Value == "__filter")
                        {
                            FilterQuery = fieldValue;
                        }
                        else if (match.Groups["field"].Value == "__historyOnDate")
                        {
                            HistoryOnDate = System.Convert.ToDateTime(fieldValue);
                        }
                        else if (match.Groups["field"].Value == "__selected")
                        {
                            SelectedValues = fieldValue;
                        }
                        else if (match.Groups["field"].Value == "__customFCN")
                        {
                            CustomFilterClassName = fieldValue;
                        }
                        else if (match.Groups["field"].Value.Equals("__SNColumn", StringComparison.OrdinalIgnoreCase))
                        {
                            SelectNameColumn = fieldValue;
                        }
                        else if (match.Groups["field"].Value.Equals("__SKVColumn", StringComparison.OrdinalIgnoreCase))
                        {
                            SelectKeyValueColumn = fieldValue;
                        }
                        else if (match.Groups["field"].Value.Equals("__SFAddType", StringComparison.OrdinalIgnoreCase))
                        {
                            SelectForAddType = fieldValue;
                        }
                        else if (match.Groups["field"].Value.Equals("__deniedShortFilters", StringComparison.OrdinalIgnoreCase) && fieldValue == "on")
                        {
                            DeniedUseShortFilters = true;
                        }
                        else if (match.Groups["field"].Value.Equals("__timeoutInSQL", StringComparison.OrdinalIgnoreCase) && fieldValue == "on")
                        {
                            TimeoutInSQL = true;
                        }
                        else if (match.Groups["field"].Value == "__filters")
                        {
                            string component = fieldValue;
                            var    jss       = new JavaScriptSerializer();
                            if (string.IsNullOrEmpty(component))
                            {
                                ControlFilterParameters.Clear();
                            }
                            else
                            {
                                ControlFilterParameters = jss.Deserialize <List <FilterParameter> >(component);
                            }
                        }
                        else if (match.Groups["field"].Value == "__selParams")
                        {
                            string component = fieldValue;
                            var    jss       = new JavaScriptSerializer();
                            SelectParameters = jss.Deserialize <SelectParameters>(component);
                        }
                        else if (match.Groups["field"].Value.StartsWith(CustomParameterPrefix))
                        {
                            string key = match.Groups["field"].Value.Substring(CustomParameterPrefix.Length);
                            CustomQueryParameters[key] = new QueryParameter {
                                Value = fieldValue
                            };
                        }
                        else// if (!QueryParameters.ContainsKey(match.Groups["field"].Value))
                        {
                            QueryParameters[match.Groups["field"].Value] = fieldValue;
                            if (match.Groups["field"].Value.StartsWith("refHistory"))
                            {
                                LookHistoryValues[match.Groups["field"].Value] = fieldValue;
                            }
                            else if (match.Groups["field"].Value.StartsWith("ref"))
                            {
                                LookHistoryValues[match.Groups["field"].Value] = fieldValue;
                            }
                        }
                    }

                    match = match.NextMatch();
                }
            }
        }
예제 #7
0
        private void ParseUrl(bool throwException)
        {
            Match match = _regex.Match(Url);

            UserControl         = "";
            IsDataControl       = false;
            NavigateTo          = false;
            ShowHistory         = false;
            IsSelect            = false;
            ShowFilter          = false;
            IsMultipleSelect    = false;
            IsNew               = false;
            IsRead              = false;
            IsDownload          = false;
            IsExecute           = false;
            IsFilterWindow      = false;
            IsCustomUserControl = false;
            QueryParameters.Clear();
            ParameterConverter.Clear();
            ControlFilterParameters.Clear();
            SelectParameters = null;
            BackUrl          = "";
            Query            = "";
            SelectedValues   = "";
            FilterQuery      = null;
            if (!match.Success)
            {
                match = _regex2.Match(Url);
                if (!match.Success)
                {
                    return;
                }
            }

            Page    = match.Groups["page"].Value;
            PageExt = match.Groups["pageExt"].Value;
            if (match.Groups["type"].Success)
            {
                if (match.Groups["type"].Value.Equals("data/"))
                {
                    IsDataControl = true;
                }
                else if (match.Groups["type"].Value.Equals("navigateto/"))
                {
                    NavigateTo = true;
                }
                else if (match.Groups["type"].Value.Equals("download/"))
                {
                    IsDownload = true;
                }
                else if (match.Groups["type"].Value.Equals("execute/"))
                {
                    IsExecute = true;
                }
                else if (match.Groups["type"].Value.Equals("custom/"))
                {
                    IsCustomUserControl = true;
                }
            }

            if ((IsDataControl || NavigateTo) && !match.Groups["usercontrol"].Success)
            {
                if (throwException)
                {
                    throw new Exception("Not set UserControls in url");
                }
                IsDataControl = false;
                NavigateTo    = false;
                return;
            }

            if (match.Groups["usercontrol"].Success)
            {
                var setUC = true;
                if (!match.Groups["type"].Success)
                {
                    if (match.Groups["usercontrol"].Value.Equals("download"))
                    {
                        IsDownload = true;
                        setUC      = false;
                    }
                    else if (match.Groups["usercontrol"].Value.Equals("execute"))
                    {
                        IsExecute = true;
                        setUC     = false;
                    }
                }

                if (setUC)
                {
                    UserControl = HttpUtility.UrlDecode(match.Groups["usercontrol"].Value);
                }
            }

            var dic = new Dictionary <string, string>();

            if (IsCustomUserControl)
            {
                UserControl += match.Groups["param1"].Success ? HttpUtility.UrlDecode(match.Groups["param1"].Value) : "";
            }
            else
            {
                AddParam(match, dic, "param1");
            }

            AddParam(match, dic, "param2");
            AddParam(match, dic, "param3");
            AddParam(match, dic, "param4");
            AddParam(match, dic, "param5");

            ShowHistory      = dic.ContainsKey("showhistory");
            IsMultipleSelect = dic.ContainsKey("multipleselect");
            IsSelect         = dic.ContainsKey("select") || IsMultipleSelect;
            ShowFilter       = dic.ContainsKey("showfilter");
            IsNew            = dic.ContainsKey("new");
            IsRead           = dic.ContainsKey("read");
            IsFilterWindow   = dic.ContainsKey("filter");

            if (match.Groups["query"].Success)
            {
                Query = match.Groups["query"].Value;
                ParseQuery();
            }
        }