//执行sql返回数据列表的json
function LogicsTypeCommon_GetJsonPagerListString(txtSql,tableName,pageCount) {
    var result = new StringBuffer();
    var obj = DBReader.selectSql(txtSql, tableName);
    try
    {
        if (obj == null || obj == undefined)
            return '[{"result" :"2","returnval" :"连接数据库失败！"}]';
        var rowCount = parseInt(obj.RecordCount);
        if (rowCount == 0) {
            DBReader.Dispose(obj);
            return '[{"result" :"0","returnval" :"暂时没有结果"}]';
        }
        var fieldsCount = parseInt(obj.Fields.Count);
        result.appendLine('[{"result" :"1","returnval" :"操作成功", "pageIndex":"' + pageCount + '", "recordcount":"' + rowCount + '","table":[');
        obj.MoveFirst();
        for (var i = 0; i < rowCount; i++) {
            if (i != 0){
                result.appendLine(',');
             }
            result.appendLine('{');
            for (n = 0; n < fieldsCount; n++) {
                if (n !== 0){
                    result.appendLine(",");
                 }
                if (obj.Fields(n).Type == 135) {
                    if (obj.Fields(n).Value == "" || obj.Fields(n).Value == null || obj.Fields(n).Value == undefined)
                        result.appendLine('"' + obj.Fields(n).Name.replace(/'"'/g, "'") + '"' + ':""');
                    else {
                        var dt = new Date(obj.Fields(n).Value);               
                        result.appendLine('"' + obj.Fields(n).Name + '"' + ':"' + dt.Format("yyyy-MM-dd") + '"');                        
                    }
                }
                else {
                    if (obj.Fields(n).Value == null)
                    {
                        result.appendLine('"' + obj.Fields(n).Name.replace(/'"'/g, "'") + '"' + ':""');
                    }
                    else
                    {
                        result.appendLine('"' + obj.Fields(n).Name + '"' + ':"' + strToString(obj.Fields(n).Value.toString().replace(/\\/g,"\\\\")) + '"');
                    }
                }
            }
            result.appendLine('}')
            obj.MoveNext();
        }
        result.appendLine(']}]');
        rowCount=null;fieldsCount=null;
    }
    catch(e)
    {
        
    }
    DBReader.Dispose(obj);
    obj=null;    
    CollectGarbage();
    return result.toString();
}


//执行sql返回数据列表的Object
function LogicsTypeCommon_GetJsonTableString(txtSql,tableName) {
    var obj = DBReader.selectSql(txtSql, tableName);
    if (obj == null || obj == undefined)
        return null;
    var rowCount = parseInt(obj.RecordCount);
    if (rowCount == 0) {
        DBReader.Dispose(obj);
        return null;
    }
    return obj;
}



//执行sql返回数据列表的tabTable,不存在分页
function LogicsTypeCommon_GetJsonTable(txtSql,tableName) {
    var obj = DBReader.selectSql(txtSql, tableName);
    if (obj == null || obj == undefined)
        return "";
    var rowCount = parseInt(obj.RecordCount);
    if (rowCount == 0) {
        DBReader.Dispose(obj);
        return "";
    }
    var resultPush=[];
    resultPush.length=0;
    var fieldsCount = parseInt(obj.Fields.Count);
    obj.MoveFirst();
    for (var i = 0; i < rowCount; i++) {
        var itemobj=new Object();
        for (n = 0; n < fieldsCount; n++) {
            if (obj.Fields(n).Type == 135) {
                if (obj.Fields(n).Value == "" || obj.Fields(n).Value == null || obj.Fields(n).Value == undefined)
                    result+='"' + obj.Fields(n).Name.replace(/'"'/g, "'") + '"' + ':"null"';
                else {
                    
                    var fieldName="colindex"+n;
                    var dt = new Date(obj.Fields(n).Value);
                    eval("itemobj."+fieldName+"='"+dt.Format("yyyy-MM-dd")+"'");
                }
            }
            else {
                var fieldName="colindex"+n;
                eval("itemobj."+fieldName+"='"+obj.Fields(n).Value+"'");
            }
        }
        obj.MoveNext();
        
        resultPush.push(itemobj);
    }
    var resultList=resultPush;
    DBReader.Dispose(resultPush);
    DBReader.Dispose(obj);
    resultPush=null;
    return resultList;
}
//过滤特殊字符
function stripscript(s) 
{
    var pattern = new RegExp("[`~!@#$^&*()=|{}':;',\\[\\].<>?~！@#￥……&*（）——|{}【】\"‘；：”“'。，、？]") 
    var rs = ""; 
    for (var i = 0; i < s.length; i++) { 
    rs = rs+s.substr(i, 1).replace(pattern, ''); 
}
    return rs; 
}
//半角转全角
function strToString(changeStr)
{
    changeStr=changeStr.replace(/[(^*\n*)|(^*\r*)]/g,"");
    var reg=new RegExp("[\"\'<>,{}?\+\&]");
    if (reg.test(changeStr))
    {
         if(changeStr.indexOf("\&")!=-1)
         {
            changeStr=changeStr.replace(/\&/g,"＆");
         }
         if(changeStr.indexOf("\+")!=-1)
         {
            changeStr=changeStr.replace(/\+/g,"＋");
         } 
         if(changeStr.indexOf("\'")!=-1)
         {
            changeStr=changeStr.replace(/\'/g,"’");
         }
         if(changeStr.indexOf("<")!=-1)
         {
            changeStr=changeStr.replace(/\</g,"＜");
         }
         if(changeStr.indexOf(">")!=-1)
         {
            changeStr=changeStr.replace(/\>/g,"＞");
         }
         if(changeStr.indexOf("%")!=-1)
         {
            changeStr=changeStr.replace(/\%/g,"％");
         }
         if(changeStr.indexOf("?")!=-1)
         {
            changeStr=changeStr.replace(/\?/g,"？");
         }
         if(changeStr.indexOf("\"")!=-1)
         {
            changeStr=changeStr.replace(/\"/g,"”");
         }
         if(changeStr.indexOf("[")!=-1)
         {
            changeStr=changeStr.replace(/\[/g,"［");
         }
         if(changeStr.indexOf("]")!=-1)
         {
            changeStr=changeStr.replace(/\]/g,"］");
         }
         if(changeStr.indexOf("{")!=-1)
         {
            changeStr=changeStr.replace(/\{/g,"｛");
         }
         if(changeStr.indexOf("}")!=-1)
         {
            changeStr=changeStr.replace(/\}/g,"｝");
         } 
         if(changeStr.indexOf(",")!=-1)
         {
            changeStr=changeStr.replace(/\,/g,"，");
         }
    } 
    return changeStr;
}