/// <summary> /// 加入DataTable到DetailGrid中 /// </summary> /// <param name="grid"></param> /// <param name="dt"></param> /// <param name="primaryKeyName"></param> /// <param name="setValues"></param> public static void AddDetailDataTableRows(this IGrid grid, System.Data.DataTable dt, string primaryKeyName, SetOtherRowValues setValues) { System.Collections.Generic.Dictionary <string, Xceed.Grid.DataRow> masterRows = new System.Collections.Generic.Dictionary <string, Xceed.Grid.DataRow>(); foreach (Xceed.Grid.DataRow row in grid.DataRows) { if (!masterRows.ContainsKey(row.Cells[primaryKeyName].Value.ToString())) { masterRows[row.Cells[primaryKeyName].Value.ToString()] = row; } } for (int i = 0; i < dt.Rows.Count; ++i) { Xceed.Grid.DataRow row; if (!masterRows.ContainsKey(dt.Rows[i][primaryKeyName].ToString())) { row = grid.AddDataRow(dt.Rows[i]); masterRows[dt.Rows[i][primaryKeyName].ToString()] = row; } MyDetailGrid detailGrid = masterRows[dt.Rows[i][primaryKeyName].ToString()].DetailGrids[0] as MyDetailGrid; row = detailGrid.AddDataRow(dt.Rows[i]); if (setValues != null) { setValues(row); } } }
/// <summary> /// 加入DetailGrid /// </summary> /// <returns></returns> public static MyDetailGrid AddDetailGrid(this IGrid grid, MyDetailGrid detailGrid) { detailGrid.Collapsed = true; grid.DetailGridTemplates.Add(detailGrid); grid.UpdateDetailGrids(); return(detailGrid); }
/// <summary> /// /// </summary> /// <param name="detailGrid"></param> protected void CreateDetailGridSumRow(MyDetailGrid detailGrid) { bool needSum = false; if (!needSum) { foreach (Column column in detailGrid.Columns) { GridColumnInfo info = column.Tag as GridColumnInfo; if (info == null) { continue; } if (string.IsNullOrEmpty(info.StatFunction) || !Authority.AuthorizeByRule(info.ColumnVisible)) { continue; } needSum = true; break; } } if (needSum) { SummaryRow sumRow = detailGrid.AddSummaryRowToFixedFooter(); sumRow.TextFormat = ADInfoBll.Instance.GetGridInfo(detailGrid.GridName).StatTitle; foreach (Column column in detailGrid.Columns) { GridColumnInfo info = column.Tag as GridColumnInfo; if (info == null) { continue; } if (string.IsNullOrEmpty(info.StatFunction) || !Authority.AuthorizeByRule(info.ColumnVisible)) { continue; } MySummaryCell cell = ((MySummaryCell)sumRow.Cells[info.GridColumnName]); cell.StatFunction = BoundGridExtention.GetStatFunction(info.StatFunction); cell.RunningStatGroupLevel = 0; cell.ResultDataType = typeof(string); if (!string.IsNullOrEmpty(info.StatTitle)) { cell.TitleFormat = info.StatTitle; cell.TitlePosition = TitlePosition.PreferablyRight; } } } }
/// <summary> /// CreateDetailGridColumnManageRowTips /// </summary> /// <param name="detailGrid"></param> protected void CreateDetailGridColumnManageRowTips(MyDetailGrid detailGrid) { ColumnManagerRow columnManageRow = detailGrid.GetColumnManageRow(); if (columnManageRow != null) { foreach (Column column in detailGrid.Columns) { columnManageRow.Cells[column.FieldName].MouseEnter += new EventHandler(this.BoundGridHelper.ColumnManageCell_MouseEnter); } } }
private void AddCheckColumnToDetailGrid(MyDetailGrid detailGrid) { foreach (Xceed.Grid.Column column in detailGrid.Columns) { column.ReadOnly = true; } m_checkColumns.Add(detailGrid.AddCheckColumn()); detailGrid.ReadOnly = false; foreach (MyDetailGrid subDetailGrid in detailGrid.DetailGridTemplates) { AddCheckColumnToDetailGrid(subDetailGrid); } }
/// <summary> /// 删除DetailGrid /// </summary> /// <param name="grid"></param> /// <param name="detail"></param> public static void RemoveDetailGrid(this IGrid grid, MyDetailGrid detail) { grid.DetailGridTemplates.Remove(detail); grid.UpdateDetailGrids(); }
/// <summary> /// 加入DetailGrid /// </summary> /// <returns></returns> public static MyDetailGrid AddDetailGrid(this IGrid grid, MyDetailGrid detailGrid) { detailGrid.Collapsed = true; grid.DetailGridTemplates.Add(detailGrid); grid.UpdateDetailGrids(); return detailGrid; }
/// <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]); } }
/// <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]); } }