[C#] 컨테이너 번호 체크 함수

C#으로 구현한 컨테이너 번호 정합성(Validation) 체크 메소드

/// <summary>
/// 컨테이너 번호 체크(Container Number Check)
/// </summary>
/// <param name="sContNo">컨테이너번호(Container Number)</param>
/// <returns>true:적합, false:부적합</returns>
private  bool cisCont_Chk(string sContNo)
{
    if (sContNo.Equals(""))
        return false;

    int nChk = 0;
    int nBcd = 0;
    int nHap = 0;

    string sChk = "";

    sContNo = sContNo.Trim();

    for (int i = 0; i < sContNo.Length; i++)
    {
        nBcd *= 2;

        if (nBcd == 0)
            nBcd = 1;

        sChk = sContNo.Substring(i, 1);  

        switch (sChk)
        {
            case "A": nChk = 10; break;
            case "B": nChk = 12; break;
            case "C": nChk = 13; break;
            case "D": nChk = 14; break;
            case "E": nChk = 15; break;
            case "F": nChk = 16; break;
            case "G": nChk = 17; break;
            case "H": nChk = 18; break;
            case "I": nChk = 19; break;
            case "J": nChk = 20; break;
            case "K": nChk = 21; break;
            case "L": nChk = 23; break;
            case "M": nChk = 24; break;
            case "N": nChk = 25; break;
            case "O": nChk = 26; break;
            case "P": nChk = 27; break;
            case "Q": nChk = 28; break;
            case "R": nChk = 29; break;
            case "S": nChk = 30; break;
            case "T": nChk = 31; break;
            case "U": nChk = 32; break;
            case "V": nChk = 34; break;
            case "W": nChk = 35; break;
            case "X": nChk = 36; break;
            case "Y": nChk = 37; break;
            case "Z": nChk = 38; break;
            default: nChk =  0; break;
        }

        nChk *= nBcd;
        nHap += nChk;
    }

    nChk = nHap / 11;
    nChk *= 11;
    nChk = nHap - nChk;

    if (nChk == 10)
        nChk = 0;



    if (Convert.ToInt16(sContNo.Substring(sContNo.Length - 1, 1)) == nChk)
        return true;
    else
        return false;
}

댓글 남기기