コード例 #1
0
        private static ColumnOption GetColumnOption(string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(ColumnOption.Empty);
            }
            ColumnOption all = ColumnOption.Integer | ColumnOption.DecimalChars | ColumnOption.DateTimeChars | ColumnOption.Word;

            if (text.Length <= 40)
            {
                all |= ColumnOption.ShortText;
            }
            if (text.Length <= 10)
            {
                all |= ColumnOption.VeryShortText;
            }
            foreach (var c in text)
            {
                if (all.HasFlag(ColumnOption.Integer) && "0123456789".IndexOf(c) == -1)
                {
                    all &= ~ColumnOption.Integer;
                }
                if (all.HasFlag(ColumnOption.DecimalChars) && ".,-+ ".IndexOf(c) == -1)
                {
                    all &= ~ColumnOption.DecimalChars;
                }
                if (all.HasFlag(ColumnOption.DateTimeChars) && ":/\\.-T ".IndexOf(c) == -1)
                {
                    all &= ~ColumnOption.DateTimeChars;
                }
                if (all.HasFlag(ColumnOption.Word) && (c < 32 || c > 125))
                {
                    all &= ~ColumnOption.Word;
                }

                if (all == ColumnOption.None)
                {
                    return(ColumnOption.None);
                }
            }

            return(all);
        }
コード例 #2
0
 /// <inheritDoc/>
 public ITableBuilder ApplyToColumns(ColumnOption option)
 {
     _columns.ForEach(s => ApplyToColumn(s.InnerHtml, option.FieldName(), option.FieldValue() ?? true.ToStringLower()));
     return(this);
 }
コード例 #3
0
 /// <exclude/>
 public IColumnBuilder Apply(ColumnOption option, object[] value)
 {
     return(ApplyToColumn(option.FieldName(), string.Format("[{0}]", string.Join(",", value))));
 }
コード例 #4
0
 /// <exclude/>
 public IColumnBuilder Apply(ColumnOption option, object value)
 {
     return(ApplyToColumn(option.FieldName(), value));
 }
コード例 #5
0
        public ColumnOptionViewModel(ColumnOption columnOption, ColumnTypes type)
        {
            Columns          = new List <ColumnViewModel>();
            AvailableColumns = new List <AvailableColumnViewModel>();

            if (columnOption == null)
            {
                if (type == ColumnTypes.Route)
                {
                    string[] defaultRouteColumns = ConfigurationManager.AppSettings["DefaultRouteColumns"]?.Replace(" ", "").ToUpperInvariant().Split(',');
                    foreach (var e in Enum.GetValues(typeof(RouteColumns)).Cast <RouteColumns>().OrderBy(c => c).Select((value, i) => new { i, value }))
                    {
                        var value = e.value;
                        var index = e.i;
                        //if (value.GetGroupName().ToUpperInvariant() == "DEFAULT")
                        if (defaultRouteColumns.Any(c => c == ((int)value).ToString()))
                        {
                            Columns.Add(new ColumnViewModel(new Column {
                                ID = ((int)value).ToString(), ColumnIdentifier = value.GetDisplayName().ToString(), Visible = "true", Width = "0", DisplayOrder = (index + 1).ToString()
                            }));
                        }
                        else
                        {
                            AvailableColumns.Add(new AvailableColumnViewModel(new AvailableColumn {
                                ID = ((int)value).ToString(), ColumnIdentifier = value.GetDisplayName().ToString()
                            }));
                        }
                    }
                }
                else
                {
                    string[] defaultStopColumns = ConfigurationManager.AppSettings["DefaultStopColumns"]?.Replace(" ", "").ToUpperInvariant().Split(',');
                    foreach (var e in Enum.GetValues(typeof(StopColumns)).Cast <StopColumns>().OrderBy(c => c).Select((value, i) => new { i, value }))
                    {
                        var value = e.value;
                        var index = e.i;
                        //if (value.GetGroupName().ToUpperInvariant() == "DEFAULT")
                        if (defaultStopColumns.Any(c => c == ((int)value).ToString()))
                        {
                            Columns.Add(new ColumnViewModel(new Column {
                                ID = ((int)value).ToString(), ColumnIdentifier = value.GetDisplayName().ToString(), Visible = "true", Width = "0", DisplayOrder = (index + 1).ToString()
                            }));
                        }
                        else
                        {
                            AvailableColumns.Add(new AvailableColumnViewModel(new AvailableColumn {
                                ID = ((int)value).ToString(), ColumnIdentifier = value.GetDisplayName().ToString()
                            }));
                        }
                    }
                }
            }
            else
            {
                if (type == ColumnTypes.Route)
                {
                    string[] defaultRouteColumns = ConfigurationManager.AppSettings["DefaultRouteColumns"]?.Replace(" ", "").ToUpperInvariant().Split(',');
                    var      newColumns          = Enum.GetValues(typeof(RouteColumns))
                                                   .Cast <RouteColumns>()
                                                   .Select(e => e.GetDisplayName())
                                                   .Except(
                        columnOption.Columns.Select(c => c.ColumnIdentifier).Union(columnOption.AvailableColumns.Select(c => c.ColumnIdentifier))
                        );

                    foreach (var c in newColumns)
                    {
                        var newEnum = Enum.GetValues(typeof(RouteColumns)).Cast <RouteColumns>().First(e => e.GetDisplayName() == c);
                        //if (newEnum.GetGroupName().ToUpperInvariant() == "DEFAULT")
                        if (defaultRouteColumns.Any(co => co == ((int)newEnum).ToString()))
                        {
                            Columns.Add(new ColumnViewModel(new Column {
                                ID = ((int)newEnum).ToString(), ColumnIdentifier = newEnum.GetDisplayName().ToString(), Visible = "true", Width = "0", DisplayOrder = (columnOption.Columns.Count()).ToString()
                            }));
                        }
                        else
                        {
                            AvailableColumns.Add(new AvailableColumnViewModel(new AvailableColumn {
                                ID = ((int)newEnum).ToString(), ColumnIdentifier = newEnum.GetDisplayName().ToString()
                            }));
                        }
                    }
                }
                else
                {
                    string[] defaultStopColumns = ConfigurationManager.AppSettings["DefaultStopColumns"]?.Replace(" ", "").ToUpperInvariant().Split(',');
                    var      newColumns         = Enum.GetValues(typeof(StopColumns))
                                                  .Cast <StopColumns>()
                                                  .Select(e => e.GetDisplayName())
                                                  .Except(
                        columnOption.Columns.Select(c => c.ColumnIdentifier).Union(columnOption.AvailableColumns.Select(c => c.ColumnIdentifier))
                        );

                    foreach (var c in newColumns)
                    {
                        var newEnum = Enum.GetValues(typeof(StopColumns)).Cast <StopColumns>().First(e => e.GetDisplayName() == c);
                        //if (newEnum.GetGroupName().ToUpperInvariant() == "DEFAULT")
                        if (defaultStopColumns.Any(co => co == ((int)newEnum).ToString()))
                        {
                            Columns.Add(new ColumnViewModel(new Column {
                                ID = ((int)newEnum).ToString(), ColumnIdentifier = newEnum.GetDisplayName().ToString(), Visible = "true", Width = "0", DisplayOrder = (columnOption.Columns.Count()).ToString()
                            }));
                        }
                        else
                        {
                            AvailableColumns.Add(new AvailableColumnViewModel(new AvailableColumn {
                                ID = ((int)newEnum).ToString(), ColumnIdentifier = newEnum.GetDisplayName().ToString()
                            }));
                        }
                    }
                }

                if (columnOption.Columns != null)
                {
                    foreach (var c in columnOption.Columns)
                    {
                        Columns.Add(new ColumnViewModel(c));
                    }
                }
                if (columnOption.AvailableColumns != null)
                {
                    foreach (var c in columnOption.AvailableColumns)
                    {
                        AvailableColumns.Add(new AvailableColumnViewModel(c));
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Build table header for sorting
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="html"></param>
        /// <param name="gridOption"></param>
        /// <param name="column"></param>
        /// <returns></returns>
        public static TagBuilder BuildSortHeaderTag <T>(this HtmlHelper html, GridOption <T> gridOption, ColumnOption <T> column)
        {
            string sortColumn      = column.FieldName;
            string sortOptionValue = "";
            bool   currentSort     = false;
            string sortButton      = "";
            string upButtonCSS     = "sorted-asc";
            string downButtonCSS   = "sorted-desc";
            string unsortedCSS     = "unsorted";

            GetSortParams(html, ref sortColumn, ref sortOptionValue);
            if (string.IsNullOrEmpty(sortColumn) || string.IsNullOrEmpty(sortOptionValue))
            {
                if (!string.IsNullOrEmpty(gridOption.DefaultSortColumn) && gridOption.DefaultSortColumn.Equals(column.FieldName))
                {
                    currentSort     = true;
                    sortOptionValue = gridOption.DefaultSortOption;
                }
                else
                {
                    sortColumn      = column.FieldName;
                    sortOptionValue = column.DefaultSortOption;
                }
            }
            else
            {
                if (sortColumn.Equals(column.FieldName))
                {
                    currentSort = true;
                }
                else
                {
                    sortOptionValue = column.DefaultSortOption;
                }
            }

            #region build parameter list
            var param = html.ViewContext.HttpContext.Request.Form;
            //paging param
            var data = new RouteValueDictionary();
            foreach (var key in param.AllKeys)
            {
                if (!data.ContainsKey(key) && !key.Equals("SortColumn") && !key.Equals("SortOption"))
                {
                    string[] values = param.GetValues(key);
                    data.Add(key, values);
                }
            }
            int    page    = 1;
            string pageKey = "Page";
            if (html.ViewContext.HttpContext.Request.Params[pageKey] != null)
            {
                int.TryParse(html.ViewContext.HttpContext.Request.Params[pageKey], out page);
            }
            #endregion

            var dataObj = Json.Decode <Object>(Json.EncodeDictionary(data));
            var HtmlID  = gridOption.HtmlID;

            //parameters for sorting
            if (string.IsNullOrEmpty(sortOptionValue))
            {
                sortOptionValue = SortOption.Asc.ToString();
            }
            if (sortOptionValue.Equals(SortOption.Asc.ToString()))
            {
                sortOptionValue = SortOption.Desc.ToString();
                sortButton      = upButtonCSS;
            }
            else
            {
                sortOptionValue = SortOption.Asc.ToString();
                sortButton      = downButtonCSS;
            }
            var url = Javascript.addParamToURL(gridOption.URL, "SortColumn", column.FieldName);
            url = Javascript.addParamToURL(url, "SortOption", sortOptionValue);
            url = Javascript.addParamToURL(url, pageKey, page.ToString());

            //build sort header
            TagBuilder header = null;
            if (currentSort)
            {
                header = JavascriptHelper.TableHeaderForSort(column.Name, new RemoteOption {
                    URL = url, Update = HtmlID, Data = dataObj
                });
                header.AddCssClass(sortButton);
            }
            else
            {
                header = JavascriptHelper.TableHeaderForSort(column.Name, new RemoteOption {
                    URL = url, Update = HtmlID, Data = dataObj
                });
                header.AddCssClass(unsortedCSS);
            }

            return(header);
        }
コード例 #7
0
 public static string BuildSortHeader <T>(this HtmlHelper html, ColumnOption <T> column, GridOption <T> gridOption)
 {
     return(BuildSortHeaderTag <T>(html, gridOption, column).ToString());
 }
コード例 #8
0
 /// <exclude/>
 public IColumnBuilder Apply(ColumnOption option, object[] value)
 {
     return(ApplyToColumn(option.FieldName(), $"[{string.Join(",", value)}]"));
 }
コード例 #9
0
 /// <inheritDoc/>
 public new IColumnBuilderT <TModel> Apply(ColumnOption option, object[] value)
 {
     base.Apply(option, value);
     return(this);
 }
コード例 #10
0
 /// <inheritDoc/>
 public new ITableBuilderT <TModel> ApplyToColumns(ColumnOption option)
 {
     base.ApplyToColumns(option);
     return(this);
 }
コード例 #11
0
 /// <inheritDoc/>
 public IColumnBuilderT <TModel> Apply <TProperty>(Expression <Func <TModel, TProperty> > expression, ColumnOption option, object value)
 {
     ApplyToColumnT(expression, option.FieldName(), value);
     return(this);
 }
コード例 #12
0
 /// <inheritDoc/>
 public IColumnBuilderT <TModel> Apply <TProperty>(Expression <Func <TModel, TProperty> > expression, ColumnOption option, object[] value)
 {
     ApplyToColumnT(expression, option.FieldName(), string.Format("[{0}]", string.Join(",", value)));
     return(this);
 }
コード例 #13
0
 /// <inheritDoc/>
 IColumnBuilderT <TModel> IColumnApply <IColumnBuilderT <TModel> > .Apply(ColumnOption option, object value)
 {
     base.Apply(option, value);
     return(this);
 }
コード例 #14
0
 /// <inheritDoc/>
 public ITableBuilder ApplyToColumns(ColumnOption option)
 {
     _columns.ForEach(s => ApplyToColumn(s.InnerHtml, option.FieldName(), option.FieldValue() ?? true.ToStringLower()));
     return this;
 }
コード例 #15
0
 /// <exclude/>
 public IColumnBuilder Apply(ColumnOption option, object[] value)
 {
     return ApplyToColumn(option.FieldName(), string.Format("[{0}]", string.Join(",", value)));
 }
コード例 #16
0
 /// <exclude/>
 public IColumnBuilder Apply(ColumnOption option, object value)
 {
     return ApplyToColumn(option.FieldName(), value);
 }