[  ◎ Data Validation 종류 1  (물 회사) ]     

1. dataset 컬럼 및  체크 값

    - expr : 컬럼에 검사방법에 대한 사항을 입력


2. source

function fn_OnLoadInit()

{

      gfn_SetGridValidation(dsGridValidation, divDataArea.grdEvalList, dsTerm);  // 3. Grid validation 사용시 index를 사용

}

 

function fn_SaveValidate()

{

    // 1. 수정여부 검사

    if (gfn_CheckDsModified(dsEvalList) == false) return false;

    ...

    // 9. 검사

    if (gfn_ValidateGrid(dsGridValidation, divDataArea.grdEvalList) == false) return false;

    

    return true;

}

 

3. 참고

   1.  gfn_SetGridValidation 을 사용했던 이유는   gfn_ValidateGrid()함수가 grid의 index를 이용해서 했기 때문에

        차후 개발시 gfn_ValidateGrid()함수에서 컬럼값으로 처리하는 방법으로 수정 필요

 

 

/**

 * 프로그램 ID   : lib_validation.xjs

 * 프로그램명    : 필수값 검증 함수

 * 프로그램 설명 : 업무에서 공통으로 사용하는 필수값 검증 함수 정의

 * 작성자        : tobesoft

 * 작성일        : 2012.01.16

 *

 * =============================================================================

 * 변경이력    수정자    내    용

 * =============================================================================

 * 2012.01.16  tobesoft  최초작성

 *

 */

 

/******************************************************************************/

/**   Include                                                                 */

/******************************************************************************/

include "lib::lib_string.xjs";

include "lib::lib_date.xjs";

 

/******************************************************************************

 * ★ Function명 : gfn_Validate

 * ★ 설명       : 다건 필수값 검증 함수 - Dataset에 검증정보 포함

 *                 검증할 Row의 범위 지정시 pnStartRow, pnEndRow 지정

 * ★ Parameter  : 1. poDataset : 필수값 검증 데이타를 가지고 있는 Dataset

 *                 2. pnStartRow : 필수값 검증 Start Row

 *                 3. pnEndRow : 필수값 검증 End Row

 * ★ Return     : 없음

 ******************************************************************************/

function gfn_Validate(poDataset, pnStartRow, pnEndRow)

{

    if (gfn_IsNull(pnStartRow)) pnStartRow = 0;

    if (gfn_IsNull(pnEndRow)) {

        pnEndRow = poDataset.rowcount;

    } else {

        pnEndRow = pnEndRow + 1;

    }

    

    for (var nRow = pnStartRow; nRow < pnEndRow; nRow++) {

        var sPath = poDataset.getColumn(nRow, "path");

        var sComp = poDataset.getColumn(nRow, "component");

        var sTermCode = poDataset.getColumn(nRow, "termCode");

        var sExpr = poDataset.getColumn(nRow, "expr");

        var oComp;

        

        if (gfn_IsNull(sPath))

            oComp = eval(sComp);

        else

            oComp = eval(sPath + "." + sComp);

        

        if (!gfn_IsNull(oComp)) {

            var bReturn = gfn_CheckValidData(gfn_GetLabel(sTermCode), sExpr, oComp.value);

            

            if (!bReturn) {

                if (sExpr.indexOf("function") == -1) {

                    oComp.setFocus();

                }

                return false;

            }

        }

    }

    

    return true;

}

 

/******************************************************************************

 * ★ Function명 : gfn_ValidateGrid

 * ★ 설명       : Grid 필수값 검증 함수 - Dataset에 검증정보 포함

 * ★ Parameter  : 1. poDataset : 필수값 검증정보를 가지고 있는 Dataset

 *                 2. poGrid : 필수값 검증할 Grid

 *                 3. pbCheckOnly : check한 Row만 대상으로 함(check Row의 colId는 "_chk"로 되어있어야 함)

 * ★ Return     : 없음

 ******************************************************************************/

function gfn_ValidateGrid(poDataset, poGrid, pbCheckOnly)

{

    if (gfn_IsNull(pbCheckOnly)) pbCheckOnly = false;

    

    var oBindDataset = eval(poGrid.binddataset);

    

    for (var nRow = 0; nRow < oBindDataset.rowcount; nRow++) {

        if (pbCheckOnly) {

            if (oBindDataset.getColumn(nRow, "_chk") != "1") {

                continue;

            }

        }

        

        for (var i = 0; i < poDataset.rowcount; i++) {

            var sTermCode = poDataset.getColumn(i, "termCode");

            var nIndex = poDataset.getColumn(i, "index");

            var sValue = poGrid.getCellValue(nRow, nIndex);

            var sExpr = poDataset.getColumn(i, "expr");

            

            var bReturn = gfn_CheckValidData(gfn_GetLabel(sTermCode), sExpr, sValue);

            

            if (!bReturn) {

                oBindDataset.rowposition = nRow;

                poGrid.setCellPos(nIndex);

                poGrid.showEditor(true);

                

                return false;

            }

        }

    }

    

    return true;

}

 

/******************************************************************************

 * ★ Function명 : gfn_CheckData

 * ★ 설명       : 필수값 검증 함수 및 gfn_Alert 호출

 * ★ Parameter  : 1. psTitle : 필수값 검증 대상 Title

 *                 2. psExpr : 필수값 검증 Expression

 *                 3. psValue : 필수값

 * ★ Return     : 없음

 ******************************************************************************/

function gfn_CheckValidData(psTitle, psExpr, psValue)

{

    if (gfn_IsNull(psTitle) || gfn_IsNull(psExpr)) {

        gfn_Alert("WRN00037", gfn_GetLabel("param"));

        return false;

    }

    

    var bReturn = true;

    var aExpr = psExpr.split(";");

    

    for (var i = 0; i < aExpr.length; i++) {

        if (!gfn_IsNull(aExpr[i])) {

            var aParam = aExpr[i].split("=");

            

            switch(aParam[0]) {

                case "required": //WRN00038/{0}은(는) 필수 입력 항목입니다.

                    if (gfn_IsNull(psValue)) {

                        bReturn = false;

                        gfn_Alert("WRN00038", psTitle);

                    } else { //checkbox 무조건 Check 해야 할때,required=true

                        if (aParam[1] == "true" && (psValue+"") != aParam[1]) {

                            bReturn = false;

                            gfn_Alert("WRN00038", psTitle);

                        }

                    }

                    break;

                case "length": //WRN00039/{0}은(는) {1}자리입니다.

                    if (!gfn_IsNull(psValue)) {

                        if (psValue.trim().length != parseInt(aParam[1])) {

                            bReturn = false;

                            gfn_Alert("WRN00039", [psTitle, aParam[1]]);

                        }

                    }

                    break;

                case "maxlength": //WRN00040/{0}의 최대 길이는 {1}자리입니다.

                    if (!gfn_IsNull(psValue)) {

                        if (gfn_GetLengthB(psValue) > parseInt(aParam[1])) {

                            bReturn = false;

                            gfn_Alert("WRN00040", [psTitle, aParam[1]]);

                        }

                    }

                    break;

                case "minlength": //WRN00041/{0}의 최소 길이는 {1}자리입니다.

                    if (!gfn_IsNull(psValue)) {

                        if (gfn_GetLengthB(psValue) < parseInt(aParam[1])) {

                            bReturn = false;

                            gfn_Alert("WRN00041", [psTitle, aParam[1]]);

                        }

                    }

                    break;

                case "min": //WRN00042/{0}값의 최소값은 {1}입니다.

                    if (parseFloat(psValue) < parseFloat(aParam[1])) {

                        bReturn = false;

                        gfn_Alert("WRN00042", [psTitle, aParam[1]]);

                    }

                    break;

                case "max": //WRN00043/{0}값의 최대값은 {1}입니다.

                    if (parseFloat(psValue) > parseFloat(aParam[1])) {

                        bReturn = false;

                        gfn_Alert("WRN00043", [psTitle, aParam[1]]);

                    }

                    break;

                case "digit": //WRN00044/{0}은(는) 숫자 입력 항목입니다.

                    if (!gfn_IsNull(psValue)) {

                        if (!gfn_IsNumber(psValue)) {

                            bReturn = false;

                            gfn_Alert("WRN00044", psTitle);

                        }

                    }

                    break;

                case "date": //WRN00046/{0}은(는) 날짜 입력 항목입니다.

                    if (!gfn_IsNull(psValue)) {

                        if (!gfn_IsDate(psValue)) {

                            bReturn = false;

                            gfn_Alert("WRN00046", psTitle);

                        }

                    }

                    break;

                case "dateym": //WRN00047/{0}은(는) 년월 입력 항목입니다.

                    if (!gfn_IsNull(psValue)) {

                        if (!gfn_IsDate(psValue + "01")) {

                            bReturn = false;

                            gfn_Alert("WRN00047", psTitle);

                        }

                    }

                    break;

                case "range": //WRN00051/{0}은(는) {1}사이의 값입니다.

                    if (!gfn_IsNull(psValue)) {

                        var aRange = aParam[1].split(",");

                        if (parseInt(psValue) < parseInt(aRange[0]) || parseInt(psValue) > parseInt(aRange[1])) {

                            bReturn = false;

                            gfn_Alert("WRN00051", [psTitle, aRange[0] + " ~ " + aRange[1]]);

                        }

                    }

                    break;

                case "code" : //WRN00051/{0}은(는) {1}사이의 값입니다.

                    if (!gfn_IsNull(psValue)) {

                        var aRange = aParam[1].split(",");

                        for (var i = 0; i < aRange.length; i++) {

                            if (psValue == aRange[i]) {

                                return true;

                            }

                        }

                        

                        bReturn = false;

                        gfn_Alert("WRN00051", [psTitle, aRange]);

                    }

                    break;

                case "declimit": //WRN00052/{0}길이는 소수점 {1}자리로 구성되어야 합니다.

                    if (!gfn_IsNull(psValue)) {

                        var nExistDot = psValue.indexOf(".");

                        if (nExistDot == -1) {

                            bReturn = false;

                            gfn_Alert("WRN00052", [psTitle, aParam[1]]);

                        } else {

                            var nDecLength = psValue.substr(nExistDot + 1, psValue.trim().length);

                            if (nDecLength.length != parseInt(aParam[1])) {

                                bReturn = false;

                                gfn_Alert("WRN00052", [psTitle, aParam[1]]);

                            }

                        }

                    }

                    break;

                case "function": //함수로 검증

                    bReturn = eval(aParam[1]);

                    break;

            }

        }

        

        if (!bReturn) break;

    }

    

    return bReturn;

}

 

/******************************************************************************

 * ★ Function명 : gfn_ValidateOnlyOne

 * ★ 설명       : 단건 필수값 검증 함수

 * ★ Parameter  : 1. poObject : 필수값 검증할 Object

 *                 2. psTermCode : Title로 보여줄 용어코드

 *                 3. psExpr : 필수값 검증 Expression

 * ★ Return     : 없음

 ******************************************************************************/

function gfn_ValidateOnlyOne(poObject, psTermCode, psExpr)

{

    var bReturn = gfn_CheckValidData(gfn_GetLabel(psTermCode), psExpr, poObject.value);

    

    if (!bReturn) {

        if (psExpr.indexOf("function") == -1) {

            poObject.setFocus();

        }

        return false;

    }

    

    return true;

}

Posted by 농부지기