Beispiel #1
0
        public static JQGridColumn GetGridColumn(GridColumnAttribute attribute, PropertyInfo prop)
        {
            JQGridColumn result = new JQGridColumn();

            result.DataField                   = (string.IsNullOrEmpty(attribute.DataField)) ? prop.Name : attribute.DataField;
            result.Visible                     = attribute.Visible;
            result.HeaderText                  = (string.IsNullOrEmpty(attribute.HeaderText)) ? prop.Name : attribute.HeaderText;
            result.DataFormatString            = attribute.DataFormatString;
            result.Fixed                       = attribute.Fixed;
            result.Width                       = attribute.Width;
            result.Sortable                    = attribute.Sortable;
            result.Frozen                      = attribute.Frozen;
            result.Resizable                   = attribute.Resizable;
            result.Editable                    = attribute.Editable;
            result.EditType                    = attribute.EditType;
            result.EditTypeCustomCreateElement = attribute.EditTypeCustomCreateElement;
            result.EditTypeCustomGetValue      = attribute.EditTypeCustomGetValue;
            result.EditorControlID             = attribute.EditorControlID;
            result.SearchType                  = attribute.SearchType;
            result.SearchControlID             = attribute.SearchControlID;
            result.DataType                    = attribute.DataType ?? prop.PropertyType;
            result.SearchCaseSensitive         = attribute.SearchCaseSensitive;
            result.EditDialogColumnPosition    = attribute.EditDialogColumnPosition;
            result.EditDialogRowPosition       = attribute.EditDialogRowPosition;
            result.EditDialogLabel             = attribute.EditDialogLabel;
            result.EditDialogFieldPrefix       = attribute.EditDialogFieldPrefix;
            result.EditDialogFieldSuffix       = attribute.EditDialogFieldSuffix;
            result.EditActionIconsColumn       = attribute.EditActionIconsColumn;
            result.TextAlign                   = attribute.TextAlign;
            result.Searchable                  = attribute.Searchable;
            result.HtmlEncode                  = attribute.HtmlEncode;
            result.HtmlEncodeFormatString      = attribute.HtmlEncodeFormatString;
            result.ConvertEmptyStringToNull    = attribute.ConvertEmptyStringToNull;
            result.NullDisplayText             = attribute.NullDisplayText;
            result.SearchToolBarOperation      = attribute.SearchToolBarOperation;
            result.FooterValue                 = attribute.FooterValue;
            result.CssClass                    = attribute.CssClass;
            result.Width                       = attribute.Width;
            result.GroupTemplate               = attribute.GroupTemplate;
            return(result);
        }
Beispiel #2
0
        internal static List <JQGridColumn> Parse <T>(List <JQGridColumn> cols) where T : class
        {
            PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public);
            //Get Key Attribute
            foreach (PropertyInfo prop in properties)
            {
                bool         key   = false;
                bool         IsNew = false;
                JQGridColumn col   = null;

                System.Object[] attributes = prop.GetCustomAttributes(true);
                foreach (object attr in attributes)
                {
                    //if ((attr as Attribute).TypeId.ToString() == "System.Data.Objects.DataClasses.EdmScalarPropertyAttribute")
                    //{
                    //    if ((attr as System.Data.Objects.DataClasses.EdmScalarPropertyAttribute).EntityKeyProperty == true)
                    //        col.PrimaryKey = true;
                    //}
                    //else


                    if ((attr as Attribute).TypeId.ToString() == "System.ComponentModel.DataAnnotations.KeyAttribute")
                    {
                        key = true;
                        if (col != null)
                        {
                            col.PrimaryKey = key;
                        }
                    }

                    if (attr is GridColumnAttribute)
                    {
                        GridColumnAttribute GridAttr = (attr as GridColumnAttribute);
                        string field = (string.IsNullOrEmpty(GridAttr.DataField)) ? prop.Name : GridAttr.DataField;
                        col = cols.Where(m => m.DataField.Equals(field)).FirstOrDefault();
                        if (col == null)
                        {
                            col           = new JQGridColumn();
                            col.DataField = (string.IsNullOrEmpty(GridAttr.DataField)) ? prop.Name : GridAttr.DataField;
                            IsNew         = true;
                        }
                        col.Visible                     = GridAttr.Visible;
                        col.HeaderText                  = (string.IsNullOrEmpty(GridAttr.HeaderText)) ? prop.Name : GridAttr.HeaderText;
                        col.DataType                    = GridAttr.DataType ?? prop.PropertyType;
                        col.PrimaryKey                  = key;
                        col.DataFormatString            = GridAttr.DataFormatString;
                        col.Fixed                       = GridAttr.Fixed;
                        col.Width                       = GridAttr.Width;
                        col.Sortable                    = GridAttr.Sortable;
                        col.Frozen                      = GridAttr.Frozen;
                        col.Resizable                   = GridAttr.Resizable;
                        col.Editable                    = GridAttr.Editable;
                        col.EditType                    = GridAttr.EditType;
                        col.EditTypeCustomCreateElement = GridAttr.EditTypeCustomCreateElement;
                        col.EditTypeCustomGetValue      = GridAttr.EditTypeCustomGetValue;
                        col.EditorControlID             = GridAttr.EditorControlID;
                        col.SearchType                  = GridAttr.SearchType;
                        col.SearchControlID             = GridAttr.SearchControlID;
                        col.SearchCaseSensitive         = GridAttr.SearchCaseSensitive;
                        col.EditDialogColumnPosition    = GridAttr.EditDialogColumnPosition;
                        col.EditDialogRowPosition       = GridAttr.EditDialogRowPosition;
                        col.EditDialogLabel             = GridAttr.EditDialogLabel;
                        col.EditDialogFieldPrefix       = GridAttr.EditDialogFieldPrefix;
                        col.EditDialogFieldSuffix       = GridAttr.EditDialogFieldSuffix;
                        col.EditActionIconsColumn       = GridAttr.EditActionIconsColumn;
                        col.TextAlign                   = GridAttr.TextAlign;
                        col.Searchable                  = GridAttr.Searchable;
                        col.HtmlEncode                  = GridAttr.HtmlEncode;
                        col.HtmlEncodeFormatString      = GridAttr.HtmlEncodeFormatString;
                        col.ConvertEmptyStringToNull    = GridAttr.ConvertEmptyStringToNull;
                        col.NullDisplayText             = GridAttr.NullDisplayText;
                        col.SearchToolBarOperation      = GridAttr.SearchToolBarOperation;
                        col.FooterValue                 = GridAttr.FooterValue;
                        col.CssClass                    = GridAttr.CssClass;
                        col.Width                       = GridAttr.Width;
                        col.GroupTemplate               = GridAttr.GroupTemplate;
                    }
                }
                if (IsNew)
                {
                    cols.Add(col);
                }
            }
            return(cols);
        }
Beispiel #3
0
        internal static JQGrid <T> Parse <T>() where T : class
        {
            JQGrid <T> result = new JQGrid <T>();

            result.Columns = new List <JQGridColumn>();
            GridAttribute gridAttr = typeof(T).GetCustomAttributes(typeof(GridAttribute), true).FirstOrDefault() as GridAttribute;

            if (gridAttr != null)
            {
                result.ID               = gridAttr.ID;
                result.AutoWidth        = gridAttr.AutoWidth;
                result.ShrinkToFit      = gridAttr.ShrinkToFit;
                result.DataUrl          = gridAttr.DataUrl;
                result.EditUrl          = gridAttr.EditUrl;
                result.ColumnReordering = gridAttr.ColumnReordering;
                result.RenderingMode    = gridAttr.RenderingMode;
                result.MultiSelect      = gridAttr.MultiSelect;
                result.MultiSelectMode  = gridAttr.MultiSelectMode;
                result.MultiSelectKey   = gridAttr.MultiSelectKey;
                result.Width            = (gridAttr.Width == 0) ? Unit.Empty : Unit.Pixel(gridAttr.Width);
                result.Height           = (gridAttr.Height == 0) ? Unit.Empty : Unit.Pixel(gridAttr.Height);
            }

            PropertyInfo[] properties = typeof(T).GetProperties(BindingFlags.Instance | BindingFlags.Public);
            //Get Key Attribute
            foreach (PropertyInfo prop in properties)
            {
                bool         key   = false;
                bool         IsNew = false;
                JQGridColumn col   = null;

                System.Object[] attributes = prop.GetCustomAttributes(true);
                foreach (object attr in attributes)
                {
                    //if ((attr as Attribute).TypeId.ToString() == "System.Data.Objects.DataClasses.EdmScalarPropertyAttribute")
                    //{
                    //    if ((attr as System.Data.Objects.DataClasses.EdmScalarPropertyAttribute).EntityKeyProperty == true)
                    //        col.PrimaryKey = true;
                    //}
                    //else


                    if ((attr as Attribute).TypeId.ToString() == "System.ComponentModel.DataAnnotations.KeyAttribute")
                    {
                        key = true;
                        if (col != null)
                        {
                            col.PrimaryKey = key;
                        }
                    }

                    if (attr is GridColumnAttribute)
                    {
                        IsNew = true;
                        GridColumnAttribute GridAttr = (attr as GridColumnAttribute);
                        col                             = new JQGridColumn();
                        col.DataField                   = (string.IsNullOrEmpty(GridAttr.DataField)) ? prop.Name : GridAttr.DataField;
                        col.Visible                     = GridAttr.Visible;
                        col.HeaderText                  = (string.IsNullOrEmpty(GridAttr.HeaderText)) ? prop.Name : GridAttr.HeaderText;
                        col.DataType                    = prop.DeclaringType;
                        col.PrimaryKey                  = key;
                        col.DataFormatString            = GridAttr.DataFormatString;
                        col.Fixed                       = GridAttr.Fixed;
                        col.Width                       = GridAttr.Width;
                        col.Sortable                    = GridAttr.Sortable;
                        col.Frozen                      = GridAttr.Frozen;
                        col.Resizable                   = GridAttr.Resizable;
                        col.Editable                    = GridAttr.Editable;
                        col.EditType                    = GridAttr.EditType;
                        col.EditTypeCustomCreateElement = GridAttr.EditTypeCustomCreateElement;
                        col.EditTypeCustomGetValue      = GridAttr.EditTypeCustomGetValue;
                        col.EditorControlID             = GridAttr.EditorControlID;
                        col.SearchType                  = GridAttr.SearchType;
                        col.SearchControlID             = GridAttr.SearchControlID;
                        col.DataType                    = GridAttr.DataType;
                        col.SearchCaseSensitive         = GridAttr.SearchCaseSensitive;
                        col.EditDialogColumnPosition    = GridAttr.EditDialogColumnPosition;
                        col.EditDialogRowPosition       = GridAttr.EditDialogRowPosition;
                        col.EditDialogLabel             = GridAttr.EditDialogLabel;
                        col.EditDialogFieldPrefix       = GridAttr.EditDialogFieldPrefix;
                        col.EditDialogFieldSuffix       = GridAttr.EditDialogFieldSuffix;
                        col.EditActionIconsColumn       = GridAttr.EditActionIconsColumn;
                        col.TextAlign                   = GridAttr.TextAlign;
                        col.Searchable                  = GridAttr.Searchable;
                        col.HtmlEncode                  = GridAttr.HtmlEncode;
                        col.HtmlEncodeFormatString      = GridAttr.HtmlEncodeFormatString;
                        col.ConvertEmptyStringToNull    = GridAttr.ConvertEmptyStringToNull;
                        col.NullDisplayText             = GridAttr.NullDisplayText;
                        col.SearchToolBarOperation      = GridAttr.SearchToolBarOperation;
                        col.FooterValue                 = GridAttr.FooterValue;
                        col.CssClass                    = GridAttr.CssClass;
                        col.Width                       = GridAttr.Width;
                        col.GroupTemplate               = GridAttr.GroupTemplate;
                    }
                }
                if (IsNew)
                {
                    result.Columns.Add(col);
                }
            }
            //return cols;
            return(result);
        }