private void CreateGridColumns(IGrid grid)
        {
            try
            {
                grid.BeginInit();

                grid.Columns.Clear();

                foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(grid.GridName))
                {
                    // 有些列是要设置值但不可见的,例如Id
                    //if (!Authority.AuthorizeByRule(info.ColumnVisible))
                    //    continue;

                    switch (info.GridColumnType)
                    {
                    case GridColumnType.Normal:
                    {
                        Xceed.Grid.Column column;
                        if (grid.Columns[info.GridColumnName] != null)
                        {
                            throw new ArgumentException("there have already exist column " + info.GridColumnName);
                        }
                        else
                        {
                            column = new Xceed.Grid.Column(info.GridColumnName, GridColumnInfoHelper.CreateType(info));
                        }

                        UnBoundGridExtention.SetColumnProperties(column, info, grid);

                        GridFactory.CreateCellViewerManager(column, info, this.ControlManager.DisplayManager);

                        bool readOnly = Authority.AuthorizeByRule(info.ReadOnly);
                        if (!readOnly)
                        {
                            GridFactory.CreateCellEditorManager(column, info, this.ControlManager.DisplayManager);
                        }

                        grid.Columns.Add(column);
                    }
                    break;

                    default:
                        break;
                        //default:
                        //    throw new InvalidOperationException("Invalide gridcolumnType of " + info.GridColumnType + " in " + info.Name);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionProcess.ProcessWithNotify(ex);
            }
            finally
            {
                grid.EndInit();
            }
        }
Example #2
0
        /// <summary>
        ///
        /// </summary>
        public override void CreateGrid()
        {
            this.BeginInit();

            m_infos = new Dictionary <string, GridColumnInfo>();
            Dictionary <string, int> levels = new Dictionary <string, int>();
            int cnt = 0;

            foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(this.GridName))
            {
                if (m_infos.ContainsKey(info.GridColumnName))
                {
                    throw new ArgumentException("there have already exist column " + info.GridColumnName);
                }
                m_infos[info.GridColumnName] = info;
                cnt++;
            }
            m_maxLevel = 0;
            int repeatTime = 0;

            while (levels.Count < cnt)
            {
                foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(this.GridName))
                {
                    if (levels.ContainsKey(info.GridColumnName))
                    {
                        continue;
                    }

                    if (string.IsNullOrEmpty(info.ParentPropertyName))
                    {
                        levels[info.GridColumnName] = 0;
                    }
                    else if (levels.ContainsKey(info.ParentPropertyName))
                    {
                        levels[info.GridColumnName] = levels[info.ParentPropertyName] + 1;
                        m_maxLevel = Math.Max(m_maxLevel, levels[info.GridColumnName]);
                    }
                }
                repeatTime++;
                if (repeatTime >= cnt)
                {
                    throw new ArgumentException("there must have some invalide ParentPropertyName!");
                }
            }
            Debug.Assert(m_maxLevel > 0);

            m_levelParents = new string[m_maxLevel];
            foreach (KeyValuePair <string, int> kvp in levels)
            {
                if (kvp.Value == 0)
                {
                    continue;
                }
                m_levelParents[kvp.Value - 1] = m_infos[kvp.Key].ParentPropertyName;
            }

            m_gridColumnNames = new List <string> [m_maxLevel + 1];
            for (int i = 0; i <= m_maxLevel; ++i)
            {
                m_gridColumnNames[i] = new List <string>();
            }
            foreach (KeyValuePair <string, int> kvp in levels)
            {
                if (Array.IndexOf <string>(m_levelParents, kvp.Key) != -1)
                {
                    m_gridColumnNames[kvp.Value].Insert(0, kvp.Key);
                }
                else
                {
                    m_gridColumnNames[kvp.Value].Add(kvp.Key);
                }
            }


            MyDetailGrid[] detailGrid = new MyDetailGrid[m_maxLevel];
            for (int i = 0; i < m_maxLevel; ++i)
            {
                MyDetailGrid detail = new MyDetailGrid();
                detail.Collapsed = true;

                if (i == 0)
                {
                    base.DetailGridTemplates.Add(detail);
                }
                else
                {
                    detailGrid[i - 1].DetailGridTemplates.Add(detail);
                }
                detailGrid[i] = detail;
            }
            this.UpdateDetailGrids();


            foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(this.GridName))
            {
                switch (info.GridColumnType)
                {
                case GridColumnType.NoColumn:
                    break;

                case GridColumnType.CheckColumn:
                    this.AddCheckColumn();
                    break;

                case GridColumnType.StatColumn:
                {
                    Xceed.Grid.Column column = new Xceed.Grid.Column(info.GridColumnName, GridColumnInfoHelper.CreateType(info));
                    column.Visible = Authority.AuthorizeByRule(info.ColumnVisible);
                    if (!column.Visible)
                    {
                        // only for column custom visible
                        column.MaxWidth = 0;
                    }
                    column.Title    = string.IsNullOrEmpty(info.Caption) ? info.PropertyName : info.Caption;
                    column.Tag      = info;
                    column.ReadOnly = true;
                    if (levels[info.GridColumnName] == 0)
                    {
                        this.Columns.Add(column);
                    }
                    else
                    {
                        detailGrid[levels[info.GridColumnName] - 1].Columns.Add(column);
                    }
                }
                break;

                case GridColumnType.ExpressionColumn:
                case GridColumnType.ImageColumn:
                case GridColumnType.SplitColumn:
                    break;

                case GridColumnType.Normal:
                {
                    Xceed.Grid.Column column = new Xceed.Grid.Column(info.GridColumnName, GridColumnInfoHelper.CreateType(info));
                    column.Visible = Authority.AuthorizeByRule(info.ColumnVisible);
                    if (!column.Visible)
                    {
                        // only for column custom visible
                        column.MaxWidth = 0;
                    }
                    column.Title = string.IsNullOrEmpty(info.Caption) ? info.PropertyName : info.Caption;
                    column.Tag   = info;

                    GridFactory.CreateCellViewerManager(column, info, this.DisplayManager);

                    bool readOnly = Authority.AuthorizeByRule(info.ReadOnly);
                    if (readOnly)
                    {
                        column.ReadOnly = readOnly;
                    }
                    else
                    {
                        GridFactory.CreateCellEditorManager(column, info, this.DisplayManager);
                    }

                    if (levels[info.GridColumnName] == 0)
                    {
                        this.Columns.Add(column);
                    }
                    else
                    {
                        detailGrid[levels[info.GridColumnName] - 1].Columns.Add(column);
                    }
                }
                break;

                default:
                    throw new NotSupportedException("Invalid GridColumnType");
                }
            }
            this.UpdateDetailGrids();
            this.EndInit();

            this.CreateSumRow();
            this.CreateGroups();
            this.CreateEvents();

            for (int i = 0; i < m_maxLevel; ++i)
            {
                CreateDetailGridSumRow(detailGrid[i]);
            }

            this.BoundGridHelper.CreateColumnManageRowEvent();
            for (int i = 0; i < m_maxLevel; ++i)
            {
                CreateDetailGridColumnManageRowTips(detailGrid[i]);
            }
        }
Example #3
0
        internal static void CreateUnBoundGrid(this IBoundGrid grid)
        {
            try
            {
                grid.BeginInit();

                grid.Columns.Clear();
                foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(grid.GridName))
                {
                    // 有些列是要设置值但不可见的,例如Id
                    //if (!Authority.AuthorizeByRule(info.ColumnVisible))
                    //    continue;

                    switch (info.GridColumnType)
                    {
                    case GridColumnType.NoColumn:
                        break;

                    case GridColumnType.CheckColumn:
                    {
                        CheckColumn column = grid.AddCheckColumn(info.GridColumnName);
                        SetColumnProperties(column, info, grid);
                    }
                    break;

                    case GridColumnType.Normal:
                    {
                        Xceed.Grid.Column column;
                        if (grid.Columns[info.GridColumnName] != null)
                        {
                            //throw new ArgumentException("there have already exist column " + info.GridColumnName);
                            continue;
                        }
                        else
                        {
                            column = new Xceed.Grid.Column(info.GridColumnName, GridColumnInfoHelper.CreateType(info));
                        }

                        SetColumnProperties(column, info, grid);

                        GridFactory.CreateCellViewerManager(column, info, grid.DisplayManager);
                        bool readOnly = Authority.AuthorizeByRule(info.ReadOnly);
                        if (readOnly)
                        {
                            column.ReadOnly = readOnly;
                        }
                        else
                        {
                            GridFactory.CreateCellEditorManager(column, info, grid.DisplayManager);
                        }

                        grid.Columns.Add(column);
                    }
                    break;

                    case GridColumnType.WarningColumn:
                    {
                        Columns.WarningColumn column = new Columns.WarningColumn(info.GridColumnName, info.PropertyName);
                        grid.Columns.Add(column);
                    }
                    break;

                    case GridColumnType.StatColumn:
                    {
                        Xceed.Grid.Column column = new Xceed.Grid.Column(info.GridColumnName, GridColumnInfoHelper.CreateType(info));
                        SetColumnProperties(column, info, grid);
                        GridFactory.CreateCellViewerManager(column, info, grid.DisplayManager);
                        column.ReadOnly = true;
                        grid.Columns.Add(column);
                    }
                    break;

                    case GridColumnType.ExpressionColumn:
                    {
                        Xceed.Grid.Column column = new Xceed.Grid.Column(info.GridColumnName, GridColumnInfoHelper.CreateType(info));
                        SetColumnProperties(column, info, grid);
                        GridFactory.CreateCellViewerManager(column, info, grid.DisplayManager);
                        bool readOnly = Authority.AuthorizeByRule(info.ReadOnly);
                        if (readOnly)
                        {
                            column.ReadOnly = readOnly;
                        }
                        else
                        {
                            GridFactory.CreateCellEditorManager(column, info, grid.DisplayManager);
                        }
                        grid.Columns.Add(column);
                    }
                    break;

                    case GridColumnType.ImageColumn:
                    {
                        Xceed.Grid.Column column = new Xceed.Grid.Column(info.GridColumnName, typeof(System.Drawing.Image));
                        SetColumnProperties(column, info, grid);
                        column.ReadOnly = true;
                        column.MaxWidth = 72;
                        grid.Columns.Add(column);
                    }
                    break;

                    case GridColumnType.SplitColumn:
                    {
                        Xceed.Grid.Column column = new Xceed.Grid.Column(info.GridColumnName, typeof(string));
                        SetColumnProperties(column, info, grid);
                        column.ReadOnly  = true;
                        column.BackColor = System.Drawing.Color.LightGray;
                        column.Title     = " ";
                        column.MaxWidth  = 5;
                        column.Width     = 5;
                        grid.Columns.Add(column);
                    }
                    break;

                    case GridColumnType.UnboundColumn:
                    {
                        Xceed.Grid.Column column = new Xceed.Grid.Column(info.GridColumnName, GridColumnInfoHelper.CreateType(info));
                        SetColumnProperties(column, info, grid);

                        GridFactory.CreateCellViewerManager(column, info, grid.DisplayManager);
                        bool readOnly = Authority.AuthorizeByRule(info.ReadOnly);
                        if (readOnly)
                        {
                            column.ReadOnly = readOnly;
                        }
                        else
                        {
                            GridFactory.CreateCellEditorManager(column, info, grid.DisplayManager);
                        }

                        grid.Columns.Add(column);
                    }
                    break;

                    case GridColumnType.IndexColumn:
                    {
                        Xceed.Grid.Column column = new Xceed.Grid.Column(info.GridColumnName, typeof(int));
                        SetColumnProperties(column, info, grid);
                        column.ReadOnly = true;

                        grid.Columns.Add(column);
                    }
                    break;

                    default:
                        throw new NotSupportedException("Invalide gridcolumnType of " + info.GridColumnType + " in " + info.Name);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionProcess.ProcessWithNotify(ex);
            }
            finally
            {
                grid.EndInit();
            }

            grid.CreateSumRow();
            grid.CreateGroups();
            grid.CreateEvents();

            grid.BoundGridHelper.CreateColumnManageRowEvent();
            grid.SetColumnManagerRowHorizontalAlignment();
            grid.CreateMultiColumnHeaderColumnManagerRow();
        }
Example #4
0
        /// <summary>
        /// 创建绑定Grid
        /// </summary>
        /// <param name="grid"></param>
        internal static void CreateBoundGrid(this IBoundGrid grid)
        {
            grid.DisplayManager.SetDataBinding(grid.DisplayManager.SearchManager.GetSchema(), string.Empty);

            if (ADInfoBll.Instance.GetGridColumnInfos(grid.GridName).Count > 0)
            {
                try
                {
                    grid.BeginInit();

                    foreach (Xceed.Grid.Column column in grid.Columns)
                    {
                        column.Visible = false;
                    }

                    foreach (GridColumnInfo info in ADInfoBll.Instance.GetGridColumnInfos(grid.GridName))
                    {
                        switch (info.GridColumnType)
                        {
                        case GridColumnType.NoColumn:
                        case GridColumnType.StatColumn:
                        case GridColumnType.WarningColumn:
                        case GridColumnType.CheckColumn:
                            break;

                        case GridColumnType.Normal:
                            Xceed.Grid.Column column = grid.Columns[info.GridColumnName];
                            if (column == null)
                            {
                                throw new ArgumentException("Invalid GridColumnInfo of " + info.GridColumnName);
                            }

                            column.Visible = Authority.AuthorizeByRule(info.ColumnVisible);
                            if (!column.Visible)
                            {
                                // only for column custom visible.
                                // 当重置配置的时候,不会使他显示出来
                                column.MaxWidth = 0;
                            }

                            column.VisibleIndex = info.SeqNo;
                            column.Title        = (string.IsNullOrEmpty(info.Caption) ? info.PropertyName : info.Caption);

                            if (!string.IsNullOrEmpty(info.BackColor))
                            {
                                column.BackColor = System.Drawing.Color.FromName(info.BackColor);
                            }
                            if (!string.IsNullOrEmpty(info.ForeColor))
                            {
                                column.ForeColor = System.Drawing.Color.FromName(info.ForeColor);
                            }
                            if (!string.IsNullOrEmpty(info.FontName) && info.FontSize.HasValue)
                            {
                                column.Font = new System.Drawing.Font(info.FontName, info.FontSize.Value);
                            }

                            column.Tag = info;

                            GridFactory.CreateCellViewerManager(column, info, grid.DisplayManager);

                            bool readOnly = Authority.AuthorizeByRule(info.ReadOnly);
                            if (readOnly)
                            {
                                column.ReadOnly = readOnly;
                            }
                            else
                            {
                                GridFactory.CreateCellEditorManager(column, info, grid.DisplayManager);
                            }
                            break;

                        default:
                            throw new NotSupportedException("Invalide gridcolumnType of " + info.GridColumnType + " in " + info.Name);
                        }
                    }

                    grid.CreateSumRow();
                    grid.CreateGroups();
                    grid.CreateEvents();
                }
                catch (Exception ex)
                {
                    ExceptionProcess.ProcessWithNotify(ex);
                }
                finally
                {
                    grid.EndInit();
                }
            }

            grid.BoundGridHelper.CreateColumnManageRowEvent();
            grid.SetColumnManagerRowHorizontalAlignment();
        }