editoper.js
资源名称:minierp.rar [点击查看]
上传用户:yantgcom
上传日期:2013-07-19
资源大小:478k
文件大小:10k
源码类别:
MySQL数据库
开发平台:
PHP
- var prodList=getObj("productList");
- var listTableStart="<table width='100%' border='1' cellspacing='0' cellpadding='0' class='formBorder'>";
- if (document.all)
- var browser_ie=true
- else if (document.layers)
- var browser_nn4=true
- else if (document.layers || (!document.all && document.getElementById))
- var browser_nn6=true
- function addRow() { //新增行数
- //adding new row
- rowCnt++;
- if (rowCnt%2==0)
- var newRow="<tr id=row"+rowCnt+" class='evenListRow'>"
- else
- var newRow="<tr id=row"+rowCnt+" class='oddListRow'>"
- newRow+="<tr id='row"+rowCnt+"'> "
- newRow+="<td >"+rowCnt+"<input type='hidden' id='auto"+rowCnt+"' name='auto"+rowCnt+"' value='0'></td>"
- newRow+="<td ><input class='button' type='button' onClick='productPickList(this)' value='..'><input type='text' id='x_SHD01"+rowCnt+"' name='x_SHD01"+rowCnt+"' value='' size='5'><input name='pshd02"+rowCnt+"' type='text' id='pshd02"+rowCnt+"' size='30' value=''></td>"
- newRow+="<td ><input name='pshd06"+rowCnt+"' type='text' id='pshd06"+rowCnt+"' size='2' value=''></td>"
- newRow+="<td ><input name='pshd03"+rowCnt+"' type='text' id='pshd03"+rowCnt+"' size='10' value='1' onBlur='calcTotal(this)'></td>"
- newRow+="<td ><input name='pshd04"+rowCnt+"' type='text' id='pshd04"+rowCnt+"' size='8' value='' onBlur='calcTotal(this)'></td>"
- newRow+="<td ><input name='pshd05"+rowCnt+"' type='text' id='pshd05"+rowCnt+"' size='8' value=''></td>"
- //newRow+="<td ><input name='x_SHD07"+rowCnt+"' type='text' id='x_SHD07"+rowCnt+"' size='10' value=''></td>"
- newRow+="<td ><input name='x_SHD09"+rowCnt+"' type='text' id='x_SHD09"+rowCnt+"' size='10' value=''>"
- newRow+="<input type='hidden' id='hdnRowStatus"+rowCnt+"' name='hdnRowStatus"+rowCnt+"' value='1'></td>"
- newRow+="</tr>"
- //alert(newRow)
- var prodListBody=getProdListBody()
- if (browser_nn4 || browser_nn6) {
- var product=new Array(rowCnt-1)
- var qty=new Array(rowCnt-1)
- var listPrice=new Array(rowCnt-1)
- var productId=new Array(rowCnt-1)
- var total=new Array(rowCnt-1)
- var rowStatus=new Array(rowCnt-1)
- //alert(rowCnt);
- for (var i=1,k=0;i<=rowCnt-1;i++,k++) {
- product[k]=getObj("pshd02"+i).value
- qty[k]=getObj("pshd06"+i).value
- listPrice[k]=getObj("pshd03"+i).value
- total[k]=getObj("pshd04"+i).value
- productId[k]=getObj("x_SHD01"+i).value
- rowStatus[k]=getObj("hdnRowStatus"+i).value
- }
- }
- prodList.innerHTML=listTableStart+prodListBody.innerHTML+newRow+"</table>"
- if (browser_nn4 || browser_nn6) {
- for (var i=1,k=0;i<=rowCnt-1;i++,k++) {
- getObj("pshd02"+i).value=product[k]
- getObj("pshd06"+i).value=qty[k]
- getObj("pshd03"+i).value=listPrice[k]
- getObj("pshd04"+i).value=total[k]
- getObj("x_SHD01"+i).value=productId[k]
- getObj("hdnRowStatus"+i).value=rowStatus[k]
- }
- }
- }
- function getProdListBody() {
- if (browser_ie) {
- var prodListBody=getObj("productList").children[0].children[0]
- } else if (browser_nn4 || browser_nn6) {
- if (getObj("productList").childNodes.item(0).tagName=="TABLE") {
- var prodListBody=getObj("productList").childNodes.item(0).childNodes.item(0)
- } else {
- var prodListBody=getObj("productList").childNodes.item(1).childNodes.item(1)
- }
- }
- return prodListBody;
- }
- function getObj(n,d) {
- var p,i,x;
- if(!d)
- d=document;
- if((p=n.indexOf("?"))>0&&parent.frames.length) {
- d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
- }
- if(!(x=d[n])&&d.all)
- x=d.all[n];
- for(i=0;!x&&i<d.forms.length;i++)
- x=d.forms[i][n];
- for(i=0;!x&&d.layers&&i<d.layers.length;i++)
- x=getObj(n,d.layers[i].document);
- if(!x && d.getElementById)
- x=d.getElementById(n);
- return x;
- }
- function calcTotal(currObj) {
- var trObj=currObj.parentNode.parentNode
- var rowId=parseInt(trObj.id.substr(trObj.id.indexOf("w")+1,trObj.id.length))
- //alert(currObj.value)
- //alert(rowId)
- var total=eval(getObj("pshd03"+rowId).value*getObj("pshd04"+rowId).value) / 1000
- //alert(total)
- //getObj("total"+rowId).innerHTML=getObj("hdnTotal"+rowId).value=roundValue(total.toString())
- getObj("pshd05"+rowId).value=getObj("pshd05"+rowId).value=roundValue(total.toString())
- calcGrandTotal()
- }
- function calcGrandTotal() {
- var subTotal=0,grandTotal=0;
- for (var i=1;i<=rowCnt;i++) {
- if (getObj("pshd05"+i).value=="")
- getObj("pshd05"+i).value=0
- if (!isNaN(getObj("pshd05"+i).value))
- subTotal+=parseFloat(getObj("pshd05"+i).value)
- }
- getObj("SubTotal").value=roundValue(subTotal.toString())
- getObj("RmbTotal").value=convertCurrency(subTotal)
- }
- function roundValue(val) {
- if (val.indexOf(".")<0) {
- val+=".00"
- } else {
- var dec=val.substring(val.indexOf(".")+1,val.length)
- if (dec.length>2)
- val=val.substring(0,val.indexOf("."))+"."+dec.substring(0,2)
- else if (dec.length==1)
- val=val+"0"
- }
- return val;
- }
- function settotalnoofrows() {
- document.EditView.totalProductCount.value = rowCnt;
- }
- function validate() {
- if(!formValidate())
- return false
- if(!FindDuplicate())
- return false;
- if(rowCnt == 0)
- {
- alert('No product is selected. Select atleast one Product');
- return false;
- }
- for (var i=1;i<=rowCnt;i++) {
- if (!emptyCheck("pshd02"+i,"Product","text")) return false
- if (!emptyCheck("pshd03"+i,"Qty","text")) return false
- if (!numValidate("pshd03"+i,"Qty","any")) return false
- if (!numConstComp("pshd03"+i,"Qty","GE","1")) return false
- if (!emptyCheck("pshd04"+i,"List Price","text")) return false
- if (!numValidate("pshd04"+i,"List Price","any")) return false }
- //if (getObj("txtTax").value.replace(/^s+/g, '').replace(/s+$/g, '').length>0)
- // if (!numValidate("txtTax","Tax","any")) return false
- // if (getObj("txtAdjustment").value.replace(/^s+/g, '').replace(/s+$/g, '').length>0)
- // if (!numValidate("txtAdjustment","Adjustment","any")) return false
- return true
- }
- function formValidate() { //检查数据正确性
- return true
- }
- function FindDuplicate(){ //检查 重复的产品
- return true;
- var product_id = new Array(rowCnt-1);
- var product_name = new Array(rowCnt-1);
- product_id[1] = getObj("hdnProductId"+1).value;
- product_name[1] = getObj("txtProduct"+1).value;
- for (var i=1;i<=rowCnt;i++)
- {
- for(var j=i+1;j<=rowCnt;j++)
- {
- if(i == 1)
- {
- product_id[j] = getObj("hdnProductId"+j).value;
- }
- if(product_id[i] == product_id[j])
- {
- alert("You have selected < "+getObj("txtProduct"+j).value+" > more than once in line items "+i+" & "+j+".n Please select it once and change the Qty");
- return false;
- }
- }
- }
- return true;
- }
- function emptyCheck(fldName,fldLabel, fldType) {
- var currObj=getObj(fldName)
- if (fldType=="text") {
- if (currObj.value.replace(/^s+/g, '').replace(/s+$/g, '').length==0) {
- alert(fldLabel+" cannot be empty")
- currObj.focus()
- return false
- }
- else
- return true
- } else {
- if (currObj.value == "" ) {
- alert(fldLabel+" cannot be none")
- return false
- } else return true
- }
- }
- function numValidate(fldName,fldLabel,format,neg) {
- var val=getObj(fldName).value.replace(/^s+/g, '').replace(/s+$/g, '')
- if (format!="any") {
- if (isNaN(val)) {
- var invalid=true
- } else {
- var format=format.split(",")
- var splitval=val.split(".")
- if (neg==true) {
- if (splitval[0].indexOf("-")>=0) {
- if (splitval[0].length-1>format[0])
- invalid=true
- } else {
- if (splitval[0].length>format[0])
- invalid=true
- }
- } else {
- if (val<0)
- invalid=true
- else if (splitval[0].length>format[0])
- invalid=true
- }
- if (splitval[1])
- if (splitval[1].length>format[1])
- invalid=true
- }
- if (invalid==true) {
- alert("Invalid "+fldLabel)
- getObj(fldName).focus()
- return false
- } else return true
- } else {
- var splitval=val.split(".")
- if(splitval[0]>2147483647)
- {
- alert( fldLabel + " exceeds the maximum limit ");
- return false;
- }
- if (neg==true)
- var re=/^(-|)d+(.dd*)*$/
- else
- var re=/^d+(.dd*)*$/
- }
- if (!re.test(val)) {
- alert("Invalid "+fldLabel)
- getObj(fldName).focus()
- return false
- } else return true
- }
- function numConstComp(fldName,fldLabel,type,constval) {
- var val=parseFloat(getObj(fldName).value.replace(/^s+/g, '').replace(/s+$/g, ''))
- constval=parseFloat(constval)
- var ret=true
- switch (type) {
- case "L" : if (val>=constval) {
- alert(fldLabel+" should be less than "+constval)
- ret=false
- }
- break;
- case "LE" : if (val>constval) {
- alert(fldLabel+" should be less than or equal to "+constval)
- ret=false
- }
- break;
- case "E" : if (val!=constval) {
- alert(fldLabel+" should be equal to "+constval)
- ret=false
- }
- break;
- case "NE" : if (val==constval) {
- alert(fldLabel+" should not be equal to "+constval)
- ret=false
- }
- break;
- case "G" : if (val<=constval) {
- alert(fldLabel+" should be greater than "+constval)
- ret=false
- }
- break;
- case "GE" : if (val<constval) {
- alert(fldLabel+" should be greater than or equal to "+constval)
- ret=false
- }
- break;
- }
- if (ret==false) {
- getObj(fldName).focus()
- return false
- } else return true;
- }