public.js
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:5k
- var userData
- function SaveUserData(Main,Sub,strContent){
- //存到数据缓存中
- //Main为主key 如"List"
- //Sub 为子key 如"CustomerFlag"
- //strContent 为要存入的内容
- //无返回
- userData.setAttribute(Main+userData.value,strContent)
- userData.save(Sub+userData.value)
- }
- function LoadUserData(Main,Sub){
- //从数据缓存中装入到变量中
- //Main为主key 如"List"
- //Sub 为子key 如"CustomerFlag"
- //返回取出的内容
- userData.load(Sub+userData.value)
- var sTmp=userData.getAttribute(Main+userData.value)
- if (sTmp==null) sTmp=""
- return sTmp
- }
- function ContDec(sValue,sPointNum) {
- var dblValue=parseFloat(sValue)
- if (isNaN(dblValue)) return sValue
- var iPointNum=parseInt(sPointNum)
- if (isNaN(iPointNum)) iPointNum=0
- if (iPointNum>9) iPointNum=9
- var dbl1=Math.round(dblValue*Math.pow(10,iPointNum))/Math.pow(10,iPointNum)
- var s1=dbl1.toString()
- if (s1.indexOf(".") == -1) {
- var s2="000000000000000"
- s1=s1+"."+s2.substring(0,iPointNum)
- }
- if (right(s1,1)==".")
- s1=s1.substring(s1.length-1,s1.length)
- return s1
- }
- function fc_insert(sSql) {
- //执行插入
- var sXml="<No>"+sSql+"</No>"
-
- var retX=SendHttp("http://"+location.host+"/webprint/servlet/WebPrint?fc_insert",sXml)
- return retX
- }
- function fc_insert1(sXml) {
- //执行为一对多表插入
- //参数串先为主表,后为子表,子表的最后字段值主子表关联字段值,在这不用管了(包括后括号也不用管了)。
- var retX=SendHttp("http://"+location.host+"/webprint/servlet/WebPrint?fc_insert1",sXml)
- return retX
- }
- function fc_update1(sXml) {
- //执行为一对多表修改
- //参数串先为主表,后为子表
- var retX=SendHttp("http://"+location.host+"/webprint/servlet/WebPrint?fc_update1",sXml)
- return retX
- }
- function fc_select(sSql,PageNo,PageSize) {
- //执行查询
- //PageNo页码
- //PageSize页尺寸,即一页含多少行
- var sql1=""
- for(var i=0;i<sSql.length;i++) {
- switch (sSql.charAt(i)) {
- case "<" :
- sql1=sql1+"<";
- break;
- case ">" :
- sql1=sql1+">";
- break;
- default:
- sql1=sql1+sSql.charAt(i);
- }
- }
- //替代非法XML字符
- var sXml="<No>"+sql1+"</No>"+"<No1>"+PageNo+"</No1>"+"<No2>"+PageSize+"</No2>"
- var retX=SendHttp("http://"+location.host+"/webprint/servlet/WebPrint?fc_select",sXml)
- return retX
- }
- function isSpace(strMain){
- strComp=strMain
- if (strComp==" " || strComp=="" || strComp==" " || strComp==null || strComp.length==0 ) {
- return true
- }
- else
- {
- return false
- }
- }
- function SendHttp(sAspFile,sSend)
- {
- if (navigator.onLine==false)
- {
- return "你现在处于脱机状态,请联机后再试!"
- }
- var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- xmlhttp.Open("POST", sAspFile, false);
- try
- {
- xmlhttp.Send("<root>"+sSend+"</root>");
- }
- catch (exception)
- {
- alert("服务器忙!")
- }
- try
- {
- var str11=xmlhttp.responseText
- }
- catch (exception)
- {
- if (exception.description=='系统错误: -1072896748。')
- {
- str11=""
- }
-
- }
- return str11
- }
- function curDate() {
- var dDate=new Date()
- var s1=""+dDate.getYear()
- var s2=dDate.getMonth()+1
- if (s2<10)
- s2="0"+s2
- else
- s2=""+s2
-
- var s3=dDate.getDate()
- if (s3<10)
- s3="0"+s3
- else
- s3=""+s3
- return s1+"-"+s2+"-"+s3
- }
- //字符串实用函数
- function getFront(mainStr,searchStr){
- foundOffset=mainStr.indexOf(searchStr)
- if (foundOffset==-1) {
- return null
- }
- return mainStr.substring(0,foundOffset)
- }
- function getEnd(mainStr,searchStr) {
- foundOffset=mainStr.indexOf(searchStr)
- if (foundOffset==-1) {
- return null
- }
- return mainStr.substring(foundOffset+searchStr.length,mainStr.length)
- }
- function replaceString(mainStr,searchStr,replaceStr) {
- //代替字符串
- //mainStr为源串 searchStr为要查找的串 replaceStr为要改为的串
- //返回替换后的串
- var front=getFront(mainStr,searchStr)
- var end=getEnd(mainStr,searchStr)
- if (front!=null && end!=null) {
- return front+replaceStr+end
- }
- return null
- }
- function left(mainStr,lngLen) {
- if (lngLen>0) {
- return mainStr.substring(0,lngLen)
- }
- else
- {
- return null
- }
- }
- function right(mainStr,lngLen) {
- // alert(mainStr.length)
- if (mainStr.length-lngLen>=0 && mainStr.length>=0 && mainStr.length-lngLen<=mainStr.length) {
- return mainStr.substring(mainStr.length-lngLen,mainStr.length)
- }
- else
- {
- return null
- }
- }
- //滤掉左右空格
- function trim(strMain) {
- if (strMain==null) return ""
- var str1=strMain
-
- //去掉回车符
- var ascMain=strMain.charCodeAt(strMain.length-1)
- if (ascMain==32) str1=left(strMain,strMain.length-1)
- if (str1==null) return ""
- for (var i=0;i<=str1.length-1;i++) {
- var mychar=str1.charAt(i);
- if ((mychar!=" ") && (mychar!=" ")) {
- str1=str1.substring(i,str1.length);
- break;
- }
- }
- for (var i=str1.length-1;i>0;i--) {
- var mychar=str1.charAt(i);
- if ((mychar!=" ") && (mychar!=" ")) {
- str1=str1.substring(0,i+1);
- break;
- }
- }
- return str1;
- }
- function fc_RepStr(mainStr,findStr,replaceStr){
- //多次替代
- var iStart=0
- var iEnd=0
- var sRet=""
- while (iStart<mainStr.length) {
- iEnd=mainStr.indexOf(findStr,iStart)
- if (iEnd<0) {
- iEnd=mainStr.length
- sRet=sRet+mainStr.substring(iStart,iEnd)
- }
- else {
- sRet=sRet+mainStr.substring(iStart,iEnd)+replaceStr
- }
- iStart=iEnd+findStr.length
-
- }
- return sRet
- }