using System.Windows.Forms;
using DevExpress.Data.Controls;
using DevExpress.Utils;
using DevExpress.XtraCharts;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
namespace TestProject
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
#region 그리드 뷰를 설정한다.
InitializeView(this.gridView, true, false, true, false, false);
AddColumn(this.gridView, "Country" , "국가", 100, HorzAlignment.Near, false, null , null );
AddColumn(this.gridView, "Category", "분야", 100, HorzAlignment.Near, false, null , null );
AddColumn(this.gridView, "Amount" , "금액", 100, HorzAlignment.Far , false, FormatType.Numeric, "#,##0");
this.gridControl.DataSource = Revenue.GetList(1000);
this.gridView.BestFitColumns();
#endregion
#region 차트 컨트롤을 설정한다.
this.chartControl.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Right;
this.chartControl.Legend.AlignmentVertical = LegendAlignmentVertical.Top;
this.chartControl.SeriesTemplate.CrosshairLabelPattern = "{S}: {V:C2}";
this.chartControl.SeriesTemplate.SeriesPointsSorting = SortingMode.Ascending;
this.chartControl.SeriesTemplate.SeriesPointsSortingKey = SeriesPointKey.Argument;
this.chartControl.SeriesTemplate.SeriesDataMember = "Category";
this.chartControl.SeriesTemplate.ArgumentDataMember = "Country";
this.chartControl.SeriesTemplate.SummaryFunction = "SUM([Amount])";
chartControl.SeriesTemplate.ValueDataMembers.AddRange("Amount");
(this.chartControl.Diagram as XYDiagram).AxisY.Label.TextPattern = "{V:C0}";
this.chartControl.DataSource = new ControlRowSource()
{
Control = this.gridView,
ControlRows = ControlRows.Selected
};
#endregion
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 뷰 초기화 하기 - InitializeView(gridView, multiSelect, allowFilter, allowSort, allowCellMerge, editable)
/// <summary>
/// 뷰 초기화 하기
/// </summary>
/// <param name="gridView">그리드 뷰</param>
/// <param name="multiSelect">멀티 선택 여부</param>
/// <param name="allowFilter">필터 허용 여부</param>
/// <param name="allowSort">정렬 허용 여부</param>
/// <param name="allowCellMerge">셀 병합 사용 여부</param>
/// <param name="editable">편집 허용 여부</param>
private void InitializeView(GridView gridView, bool multiSelect, bool allowFilter, bool allowSort, bool allowCellMerge, bool editable)
{
gridView.OptionsDetail.EnableMasterViewMode = false;
gridView.OptionsSelection.MultiSelect = multiSelect;
gridView.OptionsSelection.MultiSelectMode = GridMultiSelectMode.RowSelect;
gridView.FocusRectStyle = DrawFocusRectStyle.None;
// 그룹 패널
gridView.OptionsView.ShowGroupPanel = false;
// 행
gridView.IndicatorWidth = 30;
gridView.OptionsView.ShowIndicator = true;
gridView.OptionsView.EnableAppearanceEvenRow = false;
gridView.OptionsView.EnableAppearanceOddRow = false;
gridView.OptionsBehavior.KeepFocusedRowOnUpdate = false;
gridView.OptionsNavigation.AutoFocusNewRow = true;
// 컬럼
gridView.OptionsBehavior.AutoPopulateColumns = false;
gridView.OptionsView.ShowColumnHeaders = true;
gridView.OptionsView.ColumnAutoWidth = false;
gridView.OptionsMenu.EnableColumnMenu = false;
gridView.OptionsNavigation.EnterMoveNextColumn = true;
gridView.OptionsCustomization.AllowColumnMoving = false;
gridView.OptionsCustomization.AllowColumnResizing = true;
gridView.OptionsCustomization.AllowFilter = allowFilter;
gridView.OptionsCustomization.AllowSort = allowSort;
// 셀
gridView.OptionsView.ShowButtonMode = ShowButtonModeEnum.ShowForFocusedCell;
gridView.OptionsView.AllowCellMerge = allowCellMerge;
gridView.OptionsBehavior.EditorShowMode = EditorShowMode.Default;
gridView.OptionsBehavior.Editable = editable;
gridView.OptionsSelection.EnableAppearanceFocusedCell = editable;
gridView.OptionsSelection.InvertSelection = false;
gridView.OptionsHint.ShowCellHints = false;
gridView.OptionsClipboard.CopyColumnHeaders = DefaultBoolean.True;
}
#endregion
#region 컬럼 추가하기 - AddColumn(gridView, columnName, caption, columnWidth, hAlignment, allowEdit, displayFormatType, displayFormatString)
/// <summary>
/// 컬럼 추가하기
/// </summary>
/// <param name="gridView">그리드 뷰</param>
/// <param name="columnName">컬럼명</param>
/// <param name="caption">제목</param>
/// <param name="columnWidth">컬럼 너비</param>
/// <param name="hAlignment">수평 정렬</param>
/// <param name="allowEdit">편집 허용 여부</param>
/// <param name="displayFormatType">디스플레이 포맷 타입</param>
/// <param name="displayFormatString">디스플레이 포맷 문자열</param>
/// <returns>그리드 컬럼</returns>
private GridColumn AddColumn
(
GridView gridView,
string columnName,
string caption,
int columnWidth,
HorzAlignment hAlignment,
bool allowEdit,
FormatType? displayFormatType,
string displayFormatString
)
{
GridColumn column = gridView.Columns.AddVisible(columnName, caption);
column.Name = columnName;
column.Width = columnWidth;
column.AppearanceHeader.Options.UseTextOptions = true;
column.AppearanceHeader.TextOptions.HAlignment = HorzAlignment.Center;
column.AppearanceHeader.TextOptions.VAlignment = VertAlignment.Center;
column.AppearanceCell.Options.UseTextOptions = true;
column.AppearanceCell.TextOptions.HAlignment = hAlignment;
column.AppearanceCell.TextOptions.VAlignment = VertAlignment.Center;
column.OptionsColumn.AllowEdit = allowEdit;
if(displayFormatType.HasValue)
{
column.DisplayFormat.FormatType = displayFormatType.Value;
column.DisplayFormat.FormatString = displayFormatString;
}
return column;
}
#endregion
}
}