[Devexpress] Dashboard Grid Maker

2020. 2. 17. 17:53Development/Winform

/* DashboardGridMaker*/
abstract class DashboardGridMaker

 

/* Entity */
private readonly BandedGridView _gridView;
protected abstract string GetDemandPartyFieldName();
protected abstract void CreateGridColumns();
protected abstract BandedGridColumn[] GetColumns();
protected abstract void CreateGridBands();
protected abstract GridBand[] GetTopBands();

 

/* 생성자 */
protected DashboardGridMaker(SBandedGridView gridView)
{
    _gridView = gridView;

    _gridView.Bands.Clear();
    _gridView.Columns.Clear();
}

public void SetGridBandColumns()
{
    CreateGridColumns();
    _gridView.Columns.AddRange(GetColumns());

    CreateGridBands();
    _gridView.Bands.AddRange(GetTopBands());
}

/* Summary Column */
protected BandedGridColumn CreateSummaryColumn(
    string caption, string fieldName, int width, RepositoryItem repoItemLink)
{
    var col = CreateColumn(caption, fieldName, width, repoItemLink);
    col.Summary.AddRange(new DevExpress.XtraGrid.GridSummaryItem[] {
new DevExpress.XtraGrid.GridColumnSummaryItem(DevExpress.Data.SummaryItemType.Sum)});

    return col;
}
/* Create Column */
protected BandedGridColumn CreateColumn(string caption, string fieldName, int width, RepositoryItem repoItemLink)
{
    var col = new BandedGridColumn();
    col.AppearanceCell.Font = new Font("Tahoma", 12F, FontStyle.Regular, GraphicsUnit.Pixel);
    col.AppearanceCell.Options.UseFont = true;
    col.AppearanceCell.Options.UseTextOptions = true;
    col.AppearanceCell.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
    col.AppearanceHeader.Font = new Font("Tahoma", 12F, FontStyle.Regular, GraphicsUnit.Pixel);
    col.AppearanceHeader.Options.UseFont = true;
    col.AppearanceHeader.Options.UseTextOptions = true;
    col.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
    col.Caption = caption;
    col.ColumnEdit = repoItemLink;
    col.FieldName = fieldName;
    col.OptionsColumn.AllowEdit = false;
    col.OptionsColumn.ReadOnly = true;
    col.OptionsFilter.AutoFilterCondition = DevExpress.XtraGrid.Columns.AutoFilterCondition.Contains;
    col.Visible = true;
    col.Width = width;

    return col;
}
/* Create Band */
protected GridBand CreateBand(string caption, bool bold = true)
{
    var band = new GridBand();
    band.AppearanceHeader.Font = new Font(
"Tahoma", 
12F, 
bold ? FontStyle.Bold : FontStyle.Regular,
GraphicsUnit.Pixel);
    band.AppearanceHeader.Options.UseFont = true;
    band.AppearanceHeader.Options.UseTextOptions = true;
    band.AppearanceHeader.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center;
    band.Caption = caption;
    band.VisibleIndex = 0;

    return band;
}
/* Create Band */
protected GridBand CreateBand(string caption, int width)
{
    var band = CreateBand(caption);
    band.Width = width;

    return band;
}
/* Create Child Band */
protected GridBand CreateChildBand(GridBand parentBand, string caption, bool bold = true)
{
    var band = CreateBand(caption, bold);
    parentBand.Children.Add(band);

    return band;
}

/* Evnet*/
 public void GridView_CustomDrawFooter(RowObjectCustomDrawEventArgs e)
{
    var brush = e.Cache.GetSolidBrush(Color.LightGoldenrodYellow);
    e.Graphics.FillRectangle(brush, e.Bounds);
    ControlPaint.DrawBorder(e.Graphics, e.Bounds,
Color.Empty, 0, ButtonBorderStyle.None,
Color.LightGray, 1, ButtonBorderStyle.Solid,
Color.Empty, 0, ButtonBorderStyle.None,
Color.Empty, 0, ButtonBorderStyle.None);
    e.Handled = true;
}
public virtual void GridView_CustomDrawFooterCell(object sender, FooterCellCustomDrawEventArgs e)
{
    ControlPaint.DrawBorder(e.Graphics, e.Bounds, Color.Transparent, ButtonBorderStyle.Solid);

    e.Appearance.DrawString(e.Cache, e.Info.DisplayText, e.Bounds);
    e.Handled = true;
}


 public void GridView_Click(object sender, EventArgs e, ItemListControlBase listControl)
{
    var gridView = sender as GridView;
    if (gridView == null) return;

    var hi = gridView.CalcHitInfo(((MouseEventArgs)e).Location);
    if (hi.HitTest != GridHitTest.RowCell && hi.HitTest != GridHitTest.Footer) return;
    if (hi.Column == null) return;

    if (hi.HitTest == GridHitTest.Footer)
listControl.GridView.ActiveFilterString = "[컬럼명]=[컬럼명]";
    else
listControl.GridView.ActiveFilterString = string.Format(
    "[컬럼명]='{0}'",
    gridView.GetRowCellValue(gridView.FocusedRowHandle, "컬럼명"));    
}


 private DashboardGridMaker _dashboardGridMaker;  
/* 그리드 초기화 하고 Call */
InitializeSettings()

bandedGVDashboard.OptionsView.ColumnAutoWidth = true;
    bandedGVDashboard.FooterPanelHeight = 15;
    bandedGVDashboard.OptionsView.ShowFooter = true;
    bandedGVDashboard.OptionsView.ShowGroupPanel = false;
    bandedGVDashboard.OptionsView.ShowIndicator = false;
    bandedGVDashboard.OptionsView.ShowColumnHeaders = false;
    bandedGVDashboard.Appearance.FooterPanel.Options.UseBackColor = true;
    bandedGVDashboard.Appearance.FooterPanel.Options.UseTextOptions = true;
    bandedGVDashboard.Appearance.FooterPanel.TextOptions.HAlignment = HorzAlignment.Center;
    bandedGVDashboard.Appearance.FooterPanel.Font = new Font("Tahoma", 9F, FontStyle.Underline);
    bandedGVDashboard.Appearance.FooterPanel.ForeColor = Color.SteelBlue;
    bandedGVDashboard.Appearance.Row.Font = new Font("Tahoma", 9F, FontStyle.Underline);
    bandedGVDashboard.Appearance.Row.ForeColor = Color.Blue;
    bandedGVDashboard.Appearance.Row.Options.UseFont = true;
    bandedGVDashboard.Appearance.Row.Options.UseForeColor = true;
    bandedGVDashboard.CustomDrawFooterCell += bandedGVDashboard_CustomDrawFooterCell;
    bandedGVDashboard.CustomDrawFooter += bandedGVDashboard_CustomDrawFooter;
    bandedGVDashboard.Click += bandedGVDashboard_Click;
BindDashboard();
}

#region Dashboard 관련 Methods



private void bandedGVDashboard_Click(object sender, EventArgs e)
{
    _dashboardGridMaker.GridView_Click(sender, e, itemListControl);
}

private void bandedGVDashboard_CustomDrawFooter(
    object sender, RowObjectCustomDrawEventArgs e)
{
    _dashboardGridMaker.GridView_CustomDrawFooter(e);
}

private void bandedGVDashboard_CustomDrawFooterCell(object sender, FooterCellCustomDrawEventArgs e)
{
    _dashboardGridMaker.GridView_CustomDrawFooterCell(sender, e);
}

/// 화면 테스트용 메소드임
private void lblDashboard_Click(object sender, EventArgs e)
{
    // Alt 키를 누르고 클릭했을 경우만 실행
    if (ModifierKeys != Keys.Alt) return;

    var form1 = new FileControlTestForm();
    form1.Show(this);
}

#endregion

public void BindDashboard(bool filterMyTask = false)
{
 _dashboardGridMaker = new DashboardGridMaker(bandedDashboard);
  _dashboardGridMaker.SetGridBandColumns();
 
}