본문 바로가기
반복코드

저장시 밸리데이션처리 관련 반복 소스 제거

by 캡틴노랑이 2015. 7. 29.
반응형

각 상황별 밸리데이션 코드 상황에 맞게 수정하여 사용. 


//Combo 밸리데이션
protected bool ComboValidation(DevExpress.Xpf.Editors.ComboBoxEdit combo, string name)
{
    if (combo.SelectedIndex < 1)
    {       
        MsgCodeHelper.ShowDialog("CM0050", name);
        return false;
    }
    return true;
}
//Text 밸리데이션
protected bool TextBoxValidation(DevExpress.Xpf.Editors.TextEdit textBox, string name)
{
    if (textBox.Text == "")
    {
        MsgCodeHelper.ShowDialog("CM0060", name);
        return false;
    }
    return true;
}
//DT 밸리데이션
protected bool DateEditValidation(DevExpress.Xpf.Editors.DateEdit dtEdit, string name)
{
    if (dtEdit.Text == "")
    {        
        MsgCodeHelper.ShowDialog("CM0060", name);
        return false;
    }
    return true;
}
 
//호출
//저장 밸리데이션
protected bool SaveValidation()
{
    if (!TextBoxValidation(btxtWorkPlace, "test1"))
        return false;
    if (!ComboValidation(cmbInstallPlace, "tes2t"))
        return false;
    if (!ComboValidation(cmbEquip, "tes3t"))
        return false;
    if (!TextBoxValidation(txtPanelName, "test4"))
        return false;
    if (!ComboValidation(cmbType, "test5"))
        return false;
    return true;
}
// If 2 conditions are same, ouput message.
public static bool IsConditionCheck(bool condition1, bool condition2, string message)
{
    if (condition1.Equals(condition2))
    {   
        MessageBox.Show(message);
        return true;
    }
    return false;
}

//호출 예제
if (IsConditionCheck(!strValue.Equals("03"), false, this, "출력 메세지"))
                return;



// DevExpress 벨리데이션
public static bool IsValid(this BaseEdit control, Control owner, string message)
{
    if (control.EditValue == null || control.EditValue.ToString().Equals(""))
    {
        control.Focus();
        MessageBox.Show(message);
        return true;
    }
    return false;
}
반응형

'반복코드' 카테고리의 다른 글

DevExpress 공통성 반복 코드  (0) 2016.05.10

댓글