﻿// JScript 文件
function GetDecode_onclick(url)
{   
    var theCode = $get("TextTraceCode").value;
    if( theCode =="" || theCode ==null || (theCode.trim().length != 20 && theCode.trim().length != 18))
    {
        alert("产品追溯码必须是18或20位，请您仔细核对！")
        return;
    }
    
    var contextObj = 
    {
        Pcode:theCode,
        theUrl:url
    };
    WebServiceDecode.Getdecode(theCode,getdecodeOnSucceeded, getdecodeOnFailed,contextObj);
}

function GetDecode_onclickIndex(url)
{   
    var theCode = $get("CodeInput").value;
    if( theCode =="" || theCode ==null || (theCode.trim().length != 20 && theCode.trim().length != 18))
    {
        alert("产品追溯码必须是18或20位，请您仔细核对！")
        return;
    }
    
    var contextObj = 
    {
        Pcode:theCode,
        theUrl:url
    };
    WebServiceDecode.Getdecode(theCode,getdecodeOnSucceeded, getdecodeOnFailed,contextObj);
}

function getdecodeOnSucceeded(result,context)
{
    var type = result.Type;
    var code = result.Code;

    if( context.theUrl == 1)
    {
        if(type =='TypeError' || code =='CodeError')
        {
             window.location.href = 'Trace/ErrorCode.aspx?code='+context.Pcode;
            return;
        }
        else if(type =='NoUpload')
        {
            window.location.href = 'Trace/Product.aspx?code='+context.Pcode+'&ProductId='+code;
            return;
        }
        switch(type)
        {
            case '0':
                window.location.href='Trace/VegetableTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break; 
            case '4':
                window.location.href='Trace/FreezeFishTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break; 
            case '15':
                window.location.href='Trace/PorkedTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break;                 
            case '8':
                window.location.href='Trace/VFishTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break;           
            case '10':
                window.location.href='Trace/OldVegetableTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break;      
            case '14':
                window.location.href='Trace/OldVegetableTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break;                                                                            
//            case '99':
//                 window.location.href='Trace/MarketTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
//                break; 
           default:
                break;
        }
     
     }   
       
    if( context.theUrl == 2)
    {
        if(type =='TypeError' || code =='CodeError')
        {
             window.location.href = 'ErrorCode.aspx?code='+context.Pcode;
            return;
        }
        else if(type =='NoUpload')
        {
            window.location.href = 'Product.aspx?code='+context.Pcode+'&ProductId='+code;
            return;
        }        
        switch(type)
        {
            case '0':
                window.location.href='VegetableTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break; 
            case '4':
                window.location.href='FreezeFishTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break; 
            case '15':
                window.location.href='PorkedTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break;                   
            case '8':
                window.location.href='VFishTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break;              
            case '10':
                window.location.href='OldVegetableTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break;      
            case '14':
                window.location.href='OldVegetableTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break;                            
//            case '99':
//                 window.location.href='MarketTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
//                break; 
           default:
                break;
        }        
    }
}

function getdecodeOnFailed()
{
    alert("Error");
}