첨부 소스 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170
using System;

using DevExpress.XtraEditors.DXErrorProvider;

/// <summary>
/// 작업
/// </summary>
public class Task : IDXDataErrorInfo
{
    //////////////////////////////////////////////////////////////////////////////////////////////////// Property
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    #region 작업명 - TaskName

    /// <summary>
    /// 작업명
    /// </summary>
    public string TaskName { get; set; }

    #endregion

    #region 시작 일자 - StartDate

    /// <summary>
    /// 시작 일자
    /// </summary>
    public DateTime StartDate { get; set; }

    #endregion

    #region 종료 일자 - EndDate

    /// <summary>
    /// 종료 일자
    /// </summary>
    public DateTime EndDate { get; set; }

    #endregion

    //////////////////////////////////////////////////////////////////////////////////////////////////// Method
    ////////////////////////////////////////////////////////////////////////////////////////// Public

    // IDXDataErrorInfo
    #region 에러 구하기 - GetError(errorInfo)

    /// <summary>
    /// 에러 구하기
    /// </summary>
    /// <param name="errorInfo">ErrorInfo 객체</param>
    public void GetError(ErrorInfo errorInfo)
    {
        if(StartDate > EndDate)
        {
            SetErrorInfo(pErrorInfo, "Either StartDate or EndDate should be corrected.", ErrorType.Critical);
        }
    }

    #endregion

    // IDXDataErrorInfo
    #region 속성 에러 구하기 - GetPropertyError(propertyName, errorInfo)

    /// <summary>
    /// 속성 에러 구하기
    /// </summary>
    /// <param name="propertyName">속성명</param>
    /// <param name="errorInfo">ErrorInfo 객체</param>
    public void GetPropertyError(string propertyName, ErrorInfo errorInfo)
    {
        switch(propertyName)
        {
            case "StartDate" :

                if(StartDate > EndDate)
                {
                    SetErrorInfo(errorInfo, "StartDate must be less than EndDate", ErrorType.Critical);
                }

                break;

            case "EndDate" :

                if(StartDate > EndDate)
                {
                    SetErrorInfo(errorInfo, "EndDate must be greater than StartDate", ErrorType.Critical);
                }

                break;

            case "TaskName" :

                if(IsStringEmpty(TaskName))
                {
                    SetErrorInfo(errorInfo, "Task name hasn't been entered", ErrorType.Information);
                }

                break;
        }
    }

    #endregion

    ////////////////////////////////////////////////////////////////////////////////////////// Private

    #region ErrorInfo 객체 설정하기 - SetErrorInfo(errorInfo, errorMessage, errorType)

    /// <summary>
    /// ErrorInfo 객체 설정하기
    /// </summary>
    /// <param name="errorInfo">ErrorInfo 객체</param>
    /// <param name="errorMessage">에러 메시지</param>
    /// <param name="errorType">에러 타입</param>
    private void SetErrorInfo(ErrorInfo errorInfo, string errorMessage, ErrorType errorType)
    {
        errorInfo.ErrorText = errorMessage;
        errorInfo.ErrorType = errorType;
    }

    #endregion

    #region 빈 문자열 여부 조사하기 - IsStringEmpty(source)

    /// <summary>
    /// 빈 문자열 여부 조사하기
    /// </summary>
    /// <param name="source">소스 문자열</param>
    /// <returns>빈 문자열 여부</returns>
    private bool IsStringEmpty(string source)
    {
        return (source != null && source.Trim().Length == 0);
    }

    #endregion
}
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요