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();
            }
        }
        internal static ValidationCriterion GetValidationCriterion(GridColumnInfo columnInfo, IControlManager cm)
        {
            ValidationCriterion cri1 = null;

            if (!string.IsNullOrEmpty(columnInfo.ValidRegularExpression))
            {
                cri1 = new MyRegularExpressionCriterion(columnInfo.GridColumnName,
                                                        Xceed.Validation.ValidationLevel.Manual,
                                                        new System.Text.RegularExpressions.Regex(columnInfo.ValidRegularExpression, System.Text.RegularExpressions.RegexOptions.Singleline),
                                                        false, true, new Xceed.Validation.CustomValidationMessages());
                cri1.CustomValidationMessages.RegularExpression = columnInfo.ValidErrorMessage;
            }
            ValidationCriterion cri2 = null;

            if (!string.IsNullOrEmpty(columnInfo.ValidScript))
            {
                cri2 = new ScriptCriterion(columnInfo.GridColumnName,
                                           Xceed.Validation.ValidationLevel.Manual,
                                           columnInfo.ValidScript, new Dictionary <string, object> {
                    { "cm", cm }
                },
                                           false, true, new Xceed.Validation.CustomValidationMessages());
                cri2.CustomValidationMessages.RegularExpression = columnInfo.ValidErrorMessage;
            }

            ValidationCriterion cri3 = null;

            if (Authority.AuthorizeByRule(columnInfo.NotNull))
            {
                cri3 = new RequiredFieldCriterion(columnInfo.GridColumnName,
                                                  Xceed.Validation.ValidationLevel.Manual, GridColumnInfoHelper.CreateType(columnInfo),
                                                  false, true, new Xceed.Validation.CustomValidationMessages());
            }
            var ret = TryAndValidations(TryAndValidations(cri1, cri2), cri3);

            if (ret != null)
            {
                ret.Name = columnInfo.GridColumnName;
            }
            return(ret);
        }
        void m_insertionRow_EditBegun(object sender, EventArgs e)
        {
            IList <GridColumnInfo> gridColumnInfos = ADInfoBll.Instance.GetGridColumnInfos(m_grid.GridName);

            try
            {
                foreach (GridColumnInfo info in gridColumnInfos)
                {
                    if (!string.IsNullOrEmpty(info.DataControlDefaultValue))
                    {
                        object defaultValue = ControlFactory.GetControlDefaultValueByUser(info.DataControlDefaultValue);
                        if (defaultValue != null)
                        {
                            m_insertionRow.Cells[info.GridColumnName].Value = Feng.Utils.ConvertHelper.ChangeType(defaultValue, GridColumnInfoHelper.CreateType(info));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionProcess.ProcessWithNotify(ex);
            }
        }
示例#4
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]);
            }
        }
示例#5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dataSource"></param>
        /// <param name="dataMember"></param>
        /// <param name="hereLevel"></param>
        protected void SetDataRows(object dataSource, string dataMember, int hereLevel)
        {
            try
            {
                this.DisplayManager.BeginBatchOperation();

                this.DataRows.Clear();

                System.Collections.Generic.Dictionary <string, Xceed.Grid.DataRow> masterRows =
                    new System.Collections.Generic.Dictionary <string, Xceed.Grid.DataRow>();

                DataTable dt = dataSource as DataTable;
                if (dt == null)
                {
                    IEnumerable list = dataSource as IEnumerable;
                    if (list != null)
                    {
                        foreach (object entity in list)
                        {
                            for (int i = 0; i <= hereLevel; ++i)
                            {
                                Xceed.Grid.DataRow gridRow = null;

                                if (i < hereLevel || i == 0)
                                {
                                    if (!masterRows.ContainsKey(GetListValue(entity, m_levelParents[i]).ToString()))
                                    {
                                        if (i == 0)
                                        {
                                            gridRow = this.DataRows.AddNew();
                                            masterRows[GetListValue(entity, m_levelParents[i]).ToString()] = gridRow;
                                        }
                                        else
                                        {
                                            gridRow = masterRows[GetListValue(entity, m_levelParents[i - 1]).ToString()].DetailGrids[0].DataRows.AddNew();
                                        }
                                    }
                                    else
                                    {
                                        gridRow = masterRows[GetListValue(entity, m_levelParents[i]).ToString()];
                                    }
                                }
                                else
                                {
                                    gridRow = masterRows[GetListValue(entity, m_levelParents[i - 1]).ToString()].DetailGrids[0].DataRows.AddNew();
                                }
                                gridRow.EndEdit();

                                gridRow.Tag = entity;
                                foreach (string columnName in m_gridColumnNames[i])
                                {
                                    GridColumnInfo info = m_infos[columnName];

                                    switch (info.GridColumnType)
                                    {
                                    case GridColumnType.Normal:
                                        if (gridRow.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName))
                                        {
                                            gridRow.Cells[info.GridColumnName].Value = EntityScript.GetPropertyValue(entity, info.Navigator, info.PropertyName);
                                        }
                                        break;

                                    case GridColumnType.WarningColumn:
                                        gridRow.Cells[info.GridColumnName].Value = (gridRow.Cells[info.GridColumnName].ParentColumn as WarningColumn).Calculate(entity);
                                        break;

                                    case GridColumnType.StatColumn:
                                    case GridColumnType.ExpressionColumn:
                                    case GridColumnType.ImageColumn:
                                    case GridColumnType.SplitColumn:
                                    case GridColumnType.CheckColumn:
                                    case GridColumnType.NoColumn:
                                        break;

                                    default:
                                        throw new NotSupportedException("invalid GridColumnType of " + info.GridColumnType);
                                    }
                                    //
                                    //gridRow.Cells[columnName].Value = GetListValue(entity, columnName);
                                }
                                gridRow.EndEdit();
                            }
                        }
                    }

                    Dictionary <Xceed.Grid.DataRow, bool> m_processdRows = new Dictionary <Xceed.Grid.DataRow, bool>();
                    foreach (object entity in list)
                    {
                        for (int i = 0; i < hereLevel; ++i)
                        {
                            Xceed.Grid.DataRow gridRow = masterRows[GetListValue(entity, m_levelParents[i]).ToString()];
                            if (!m_processdRows.ContainsKey(gridRow))
                            {
                                m_processdRows[gridRow] = true;
                            }
                            else
                            {
                                continue;
                            }
                            foreach (string columnName in m_gridColumnNames[i])
                            {
                                GridColumnInfo info = m_infos[columnName];
                                switch (info.GridColumnType)
                                {
                                case GridColumnType.StatColumn:
                                {
                                    if (gridRow.DetailGrids.Count == 0)
                                    {
                                        throw new ArgumentException("stateColumn should has detailgrids.");
                                    }
                                    gridRow.Cells[info.GridColumnName].Value = Feng.Utils.ConvertHelper.ChangeType(
                                        MySummaryRow.GetSummaryResult(gridRow.DetailGrids[0].GetSortedDataRows(true), info.PropertyName), gridRow.Cells[info.GridColumnName].ParentColumn.DataType);
                                }
                                break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    foreach (System.Data.DataRow dataRow in dt.Rows)
                    {
                        for (int i = 0; i <= hereLevel; ++i)
                        {
                            Xceed.Grid.DataRow gridRow = null;

                            if (i < hereLevel || i == 0)
                            {
                                if (!masterRows.ContainsKey(dataRow[m_levelParents[i]].ToString()))
                                {
                                    if (i == 0)
                                    {
                                        gridRow = this.DataRows.AddNew();

                                        masterRows[dataRow[m_levelParents[i]].ToString()] = gridRow;
                                    }
                                    else
                                    {
                                        gridRow = masterRows[dataRow[m_levelParents[i - 1]].ToString()].DetailGrids[0].DataRows.AddNew();
                                    }
                                }
                                else
                                {
                                    gridRow = masterRows[dataRow[m_levelParents[i]].ToString()];
                                }
                            }
                            else
                            {
                                gridRow = masterRows[dataRow[m_levelParents[i - 1]].ToString()].DetailGrids[0].DataRows.AddNew();
                            }

                            // 如果在下方EndEdit,DetailGrid可能不会生成,不知原因
                            gridRow.EndEdit();

                            gridRow.Tag = dataRow;
                            foreach (string columnName in m_gridColumnNames[i])
                            {
                                GridColumnInfo info = m_infos[columnName];

                                switch (info.GridColumnType)
                                {
                                case GridColumnType.Normal:
                                {
                                    if (!dt.Columns.Contains(columnName))
                                    {
                                        continue;
                                    }
                                    if (gridRow.Cells[info.GridColumnName] != null && !string.IsNullOrEmpty(info.PropertyName))
                                    {
                                        gridRow.Cells[info.GridColumnName].Value = (dataRow[columnName] == System.DBNull.Value ?
                                                                                    null : Feng.Utils.ConvertHelper.TryIntToEnum(dataRow[columnName], GridColumnInfoHelper.CreateType(m_infos[columnName])));
                                    }
                                }
                                break;

                                case GridColumnType.WarningColumn:
                                    throw new NotSupportedException("warning column is not supported in datarow.");

                                case GridColumnType.StatColumn:
                                case GridColumnType.ExpressionColumn:
                                case GridColumnType.ImageColumn:
                                case GridColumnType.SplitColumn:
                                case GridColumnType.CheckColumn:
                                case GridColumnType.NoColumn:
                                    break;

                                default:
                                    throw new NotSupportedException("invalid GridColumnType of " + info.GridColumnType);
                                }
                            }
                            gridRow.EndEdit();
                        }
                    }

                    Dictionary <Xceed.Grid.DataRow, bool> m_processdRows = new Dictionary <Xceed.Grid.DataRow, bool>();
                    foreach (System.Data.DataRow dataRow in dt.Rows)
                    {
                        for (int i = 0; i < hereLevel; ++i)
                        {
                            Xceed.Grid.DataRow gridRow = masterRows[dataRow[m_levelParents[i]].ToString()];
                            if (!m_processdRows.ContainsKey(gridRow))
                            {
                                m_processdRows[gridRow] = true;
                            }
                            else
                            {
                                continue;
                            }
                            foreach (string columnName in m_gridColumnNames[i])
                            {
                                GridColumnInfo info = m_infos[columnName];
                                switch (info.GridColumnType)
                                {
                                case GridColumnType.StatColumn:
                                {
                                    if (gridRow.DetailGrids.Count == 0)
                                    {
                                        throw new ArgumentException("stateColumn should has detailgrids.");
                                    }

                                    gridRow.Cells[info.GridColumnName].Value = Feng.Utils.ConvertHelper.ChangeType(
                                        MySummaryRow.GetSummaryResult(gridRow.DetailGrids[0].GetSortedDataRows(true), info.PropertyName), gridRow.Cells[info.GridColumnName].ParentColumn.DataType);
                                }
                                break;
                                }
                            }
                        }
                    }
                }

                this.AfterLoadData();
            }
            finally
            {
                this.DisplayManager.EndBatchOperation();
                this.DisplayManager.OnPositionChanged(System.EventArgs.Empty);
            }
        }
示例#6
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();
        }