■ GridControl 클래스에서 데이터 주석 어트리뷰트를 갖는 데이터 소스를 바인딩하는 방법을 보여준다.
▶ CompanyProductMetadata.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
using System.ComponentModel.DataAnnotations; namespace TestProject { /// <summary> /// 회사 제품 메타 데이터 /// </summary> public class CompanyProductMetadata { //////////////////////////////////////////////////////////////////////////////////////////////////// Field ////////////////////////////////////////////////////////////////////////////////////////// Public #region Field /// <summary> /// 회사명 /// </summary> [Display(ShortName = "Company", Name = "Company Name", AutoGenerateFilter = false)] public object CompanyName; /// <summary> /// 국가 /// </summary> [Display(Order = 2)] public object Country; /// <summary> /// 도시 /// </summary> [Display(Order = 1), Editable(false)] public object City; /// <summary> /// URL /// </summary> [DataType(DataType.Url)] public object URL; /// <summary> /// E 메일 /// </summary> [DataType(DataType.EmailAddress)] public object EMail; /// <summary> /// 전화 /// </summary> [DataType(DataType.PhoneNumber), Required] public object Phone; /// <summary> /// 텍스트 /// </summary> [DataType(DataType.Text), Display(Order = -1)] public object Text; /// <summary> /// 부가 정보 /// </summary> [Display(AutoGenerateField = false, Description = "This column isn't created")] public object AdditionalInfo; /// <summary> /// 패스워드 /// </summary> [DataType(DataType.Password), StringLength(20, MinimumLength = 3)] public object Password; /// <summary> /// 날짜 2 /// </summary> [DisplayFormat(DataFormatString = "MMMM/yyyy"), Display(Name = "Date 2")] public object Date2; /// <summary> /// 판매액 /// </summary> [DisplayFormat(DataFormatString = "#,##0,,M")] public object Sales; /// <summary> /// 이익 /// </summary> [DisplayFormat(DataFormatString = "#,##0,,M")] public object Profit; /// <summary> /// 판매 대 대상 /// </summary> [DisplayFormat(DataFormatString = "p", ApplyFormatInEditMode = true), Display(Name = "Sales vs Target")] public object SalesVsTarget; /// <summary> /// 시장 점유율 /// </summary> [DisplayFormat(DataFormatString = "p0", ApplyFormatInEditMode = false)] public object MarketShare; /// <summary> /// 고객 만족도 /// </summary> [Display(Name = "Cust Satisfaction")] public object CustomersSatisfaction; #endregion } } |
▶ CompanyPublicInfo.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
using System.ComponentModel.DataAnnotations; namespace TestProject { /// <summary> /// 회사 공개 정보 /// </summary> [MetadataType(typeof(CompanyProductMetadata))] public class CompanyPublicInfo { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 회사명 - CompanyName /// <summary> /// 회사명 /// </summary> public string CompanyName { get; set; } #endregion #region 국가 - Country /// <summary> /// 국가 /// </summary> public string Country { get; set; } #endregion #region 도시 - City /// <summary> /// 도시 /// </summary> public string City { get; set; } #endregion #region URL - URL /// <summary> /// URL /// </summary> public string URL { get; set; } #endregion #region E 메일 - EMail /// <summary> /// E 메일 /// </summary> public string EMail { get; set; } #endregion #region 전화 - Phone /// <summary> /// 전화 /// </summary> public string Phone { get; set; } #endregion #region 부가 정보 - AdditionalInfo /// <summary> /// 부가 정보 /// </summary> public string AdditionalInfo { get; set; } #endregion } } |
▶ CompanyPrivateInfo.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
using System; using System.ComponentModel.DataAnnotations; namespace TestProject { /// <summary> /// 회사 사적 정보 /// </summary> [MetadataType(typeof(CompanyProductMetadata))] public class CompanyPrivateInfo { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 패스워드 - Password /// <summary> /// 패스워드 /// </summary> public string Password { get; set; } #endregion #region 날짜 2 - Date2 /// <summary> /// 날짜 2 /// </summary> public DateTime Date2 { get; set; } #endregion #region 판매액 - Sales /// <summary> /// 판매액 /// </summary> public double Sales { get; set; } #endregion #region 이익 - Profit /// <summary> /// 이익 /// </summary> public double Profit { get; set; } #endregion #region 판매 대 대상 - SalesVsTarget /// <summary> /// 판매 대 대상 /// </summary> public double SalesVsTarget { get; set; } #endregion #region 시장 점유율 - MarketShare /// <summary> /// 시장 점유율 /// </summary> public double MarketShare { get; set; } #endregion #region 고객 만족도 - CustomersSatisfaction /// <summary> /// 고객 만족도 /// </summary> public double CustomersSatisfaction { get; set; } #endregion } } |
▶ ProductCategory.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
namespace TestProject { /// <summary> /// 제품 카테고리 /// </summary> public enum ProductCategory { /// <summary> /// 음료 /// </summary> Beverages = 1, /// <summary> /// 과일 /// </summary> Fruit = 2, /// <summary> /// 채소 /// </summary> Vegetables = 3, /// <summary> /// 고기 /// </summary> Meat = 4, /// <summary> /// 양념 /// </summary> Condiments = 5, /// <summary> /// 과자 /// </summary> Confections = 6, /// <summary> /// 유제품 /// </summary> DairyProducts = 7, /// <summary> /// 곡물 /// </summary> GrainsCereals = 8, /// <summary> /// 해산물 /// </summary> Seafood = 9 } } |
▶ Product.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; namespace TestProject { /// <summary> /// 제품 /// </summary> public class Product { //////////////////////////////////////////////////////////////////////////////////////////////////// Property ////////////////////////////////////////////////////////////////////////////////////////// Public #region 단가 - UnitPrice /// <summary> /// 단가 /// </summary> [ReadOnly(true)] public double UnitPrice { get; set; } #endregion #region 카테고리 - Category /// <summary> /// 카테고리 /// </summary> [EnumDataType(typeof(ProductCategory))] public int Category { get; set; } #endregion #region 수량 - Quantity /// <summary> /// 수량 /// </summary> [Display(Description = "The amount of currently available product")] public int Quantity { get; set; } #endregion #region 텍스트 - Text /// <summary> /// 텍스트 /// </summary> [DataType(DataType.Text), Display(Order = -1)] public string Text { get; set; } #endregion #region 멀티 라인 텍스트 - MultilineText /// <summary> /// 멀티 라인 텍스트 /// </summary> [DataType(DataType.MultilineText)] public string MultilineText { get; set; } #endregion #region 통화 - Currency /// <summary> /// 통화 /// </summary> [DataType(DataType.Currency), Range(200, 5000)] public int Currency { get; set; } #endregion #region 날짜 - Date /// <summary> /// 날짜 /// </summary> [DataType(DataType.Date)] public DateTime Date { get; set; } #endregion #region 시간 - Time /// <summary> /// 시간 /// </summary> [DataType(DataType.Time)] public DateTime Time { get; set; } #endregion } } |
▶ MainForm.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
using System; using DevExpress.XtraEditors; using DevExpress.XtraGrid.Views.Grid; namespace TestProject { /// <summary> /// 메인 폼 /// </summary> public partial class MainForm : XtraForm { //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor ////////////////////////////////////////////////////////////////////////////////////////// Public #region 생성자 - MainForm() /// <summary> /// 생성자 /// </summary> public MainForm() { InitializeComponent(); this.gridView.OptionsView.ShowGroupPanel = false; this.gridView.OptionsView.ColumnAutoWidth = false; this.dataTypeBarEditItem.EditValueChanged += dataTypeBarEditItem_EditValueChanged; this.gridControl.DataSourceChanged += gridControl_DataSourceChanged; } #endregion //////////////////////////////////////////////////////////////////////////////////////////////////// Method ////////////////////////////////////////////////////////////////////////////////////////// Private #region 데이터 타입 바 편집 항목 편집 값 변경시 처리하기 - dataTypeBarEditItem_EditValueChanged(sender, e) /// <summary> /// 데이터 타입 바 편집 항목 편집 값 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void dataTypeBarEditItem_EditValueChanged(object sender, EventArgs e) { switch(this.dataTypeBarEditItem.EditValue as string) { case "Company public info" : this.gridControl.DataSource = DataHelper.GetCompanyPublicInfoList(); break; case "Company private info" : this.gridControl.DataSource = DataHelper.GetCompanyPrivateInfoList(); break; case "Product info" : this.gridControl.DataSource = DataHelper.GetProductList(); break; } } #endregion #region 그리드 컨트롤 데이터 소스 변경시 처리하기 - gridControl_DataSourceChanged(sender, e) /// <summary> /// 그리드 컨트롤 데이터 소스 변경시 처리하기 /// </summary> /// <param name="sender">이벤트 발생자</param> /// <param name="e">이벤트 인자</param> private void gridControl_DataSourceChanged(object sender, EventArgs e) { this.gridControl.MainView.PopulateColumns(); (this.gridControl.MainView as GridView).BestFitColumns(); } #endregion } } |