コード例 #1
0
        /// <summary>
        /// returns a List object of SearchColumnConfig type
        /// </summary>
        /// <param name="type"></param>
        /// <param name="columns"></param>
        /// <returns></returns>
        public static List <SearchColumnConfig> GetColumnConfig(Type type, List <SearchColumnConfig> columns)
        {
            PropertyDescriptorCollection lstPropertie = TypeDescriptor.GetProperties(type);
            List <SearchColumnConfig>    columnConfig = new List <SearchColumnConfig>();
            string caption = string.Empty;

            foreach (PropertyDescriptor objPropertie in lstPropertie)
            {
                SearchColumnConfig item = columns.Find(p => p.ColumnName == objPropertie.Name);
                if (item != null)
                {
                    columnConfig.Add(new SearchColumnConfig {
                        ColumnName = objPropertie.Name, Caption = item.Caption, DisplayPosition = item.DisplayPosition
                    });
                }
                else
                {
                    columnConfig.Add(new SearchColumnConfig {
                        ColumnName = objPropertie.Name, Hiden = true
                    });
                }
            }
            return(columnConfig);
        }
コード例 #2
0
        private String GetGridColumn(IEnumerable retrievedData)
        {
            try
            {
                String HideColumns = HttpContext.Current.Request.QueryString["HideColumns"];
                if (HideColumns.IsNullOrEmpty())
                {
                    HideColumns = String.Empty;
                }
                String[] arrayColumn = HideColumns.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                Type     actualType  = retrievedData.GetType();
                if (actualType == typeof(Object))
                {
                    throw new System.ArgumentException("Object is not a CustomList<T> or List<T> instance.", "Obj");
                }

                Type          objectType     = actualType.GetGenericArguments()[0];
                String        columnsCaption = "VID,";
                StringBuilder tempCols       = new StringBuilder();
                StringBuilder columnsString  = new StringBuilder();
                PropertyDescriptorCollection        properties = TypeDescriptor.GetProperties(objectType);
                List <FRAMEWORK.SearchColumnConfig> congigList = (List <FRAMEWORK.SearchColumnConfig>)HttpContext.Current.Session[StaticInfo.SearchColumnConfigSessionVarName];

                String caption = String.Empty;
                tempCols.Append("{ 'name': 'VID', 'key': true, 'hidden': true, 'index': 'VID' }@ ");
                foreach (PropertyDescriptor propDes in properties)
                {
                    caption = propDes.DisplayName;
                    if (congigList.IsNotNull() && congigList.Count.IsNotZero())
                    {
                        FRAMEWORK.SearchColumnConfig config = congigList.Find(item => item.ColumnName == propDes.Name);
                        if (config.IsNotNull())
                        {
                            if (config.Hiden)
                            {
                                continue;
                            }
                            caption = config.Caption;
                        }
                    }
                    if (arrayColumn.Contains(propDes.Name, new StringEqualityComparer()))
                    {
                        continue;
                    }
                    if (propDes.IsBrowsable.IsFalse())
                    {
                        continue;
                    }
                    if (propDes.PropertyType == typeof(DateTime))
                    {
                        tempCols.Append("{ 'name': '" + propDes.Name + "', 'index': '" + propDes.Name + "', 'width': 50, searchoptions: {dataInit:datePick, sopt: ['eq','ne','lt','le','gt','ge','in','ni'] }}@ ");
                    }
                    else
                    {
                        tempCols.Append("{ 'name': '" + propDes.Name + "', 'index': '" + propDes.Name + "', 'width': 50, searchoptions: { sopt: ['cn','bw','ew','eq','ne','lt','le','gt','ge','bn','in','ni','en','nc'] }}@ ");
                    }

                    columnsCaption += String.Format("{0},", caption);
                }
                columnsCaption += "]";
                columnsCaption  = columnsCaption.Replace(",]", " | ");

                tempCols.Append("]");

                columnsString.Append(columnsCaption);
                columnsString.Append(tempCols.ToString().Replace("@ ]", ""));

                //Dispose the variable from session
                HttpContext.Current.Session[StaticInfo.SearchColumnConfigSessionVarName] = null;
                HttpContext.Current.Session.Remove(StaticInfo.SearchColumnConfigSessionVarName);

                return(columnsString.ToString());
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }