var mygrid_recv; var page_count = 5; var column_count; var jsonTopCtnObj; var changeCount = 0; //两端去空格函数 String.prototype.trim = function() { return this.replace(/(^\s*)|(\s*$)/g, ""); } function $(id){ return document.getElementById(id); } function doInitRecvGrid() { if($("hd_comboBLTYPE").value!="整箱") { document.getElementById('divadd').style.display = "none"; //document.getElementById('divsave').style.display = "none"; document.getElementById('divrefresh').style.display = "none"; document.getElementById('divdel').style.display = "none"; document.getElementById('divrollback').style.display = "none"; } // mygrid_recv = new dhtmlXGridObject('mygrid_container_recv'); mygrid_recv.setImagePath("../images/"); mygrid_recv.setSkin("xp"); mygrid_recv.setHeader("箱型,箱量,箱号,封号,件数,包装类型,箱内货重,箱皮重,尺码,备注"); mygrid_recv.setInitWidths("60,40,90,50,50,80,80,80,80,70"); mygrid_recv.setColAlign("center,left,left,left,left,left,left,left,left,left"); mygrid_recv.setColSorting("str,str,str,str,str,str,str,str,str,str"); mygrid_recv.setColTypes("co,ed,ed,ed,ed,co,ed,ed,ed,ed"); var BSNO = $("dvOrderNumVal").value.trim(); var urlVal = "SeaExportInfoGridSource.aspx?read=exist&showcount=1&BSNO="+BSNO+"&val="+newGuid(); var loader = dhtmlxAjax.getSync(urlVal); var loadVal = loader.xmlDoc.responseText; loader = null; if(parseInt(loadVal) == 1) { mygrid_recv.loadXML("SeaExportInfoGridSource.aspx?read=init&showcount=1&BSNO="+BSNO); setTimeout(function(){ ReShowLabel(mygrid_recv); },200); } mygrid_recv.init(); mygrid_recv.enableEditEvents(true,false,true); mygrid_recv.enableMultiselect(true); mygrid_recv.enableKeyboardSupport(true); var pushVal = ""; var pressRecord = ""; var pressRowIndex = -1; var pressCellIndex = -1; var pressCount = 0; var isExchange = false; var shiftCount = 0; var isDelete = 0; var flagFilter = 0; var flagTab = 0; var flagEnter = 0; var flagDelete = 0; //手动编写Grid控件编辑事件,由于免费控件没有提供完整的编辑判断功能,现特此做更改 mygrid_recv.attachEvent("onEditCell", function(stage, rId, cInd, nValue, oValue) { var newCheckValue = false; //初始化状态 if (stage == 0) { var selectedId = mygrid_recv.getSelectedRowId(); var rowIndex = mygrid_recv.getRowIndex(selectedId); var oldVal = mygrid_recv.cellByIndex(rowIndex, 0).getValue().trim(); return true; } if (stage == 1) { return true; } //如果编辑结束 if (stage == 2) { //获取当前RowID var selectedId = mygrid_recv.getSelectedRowId(); //获取当前RowIndex var rowIndex = mygrid_recv.getRowIndex(selectedId); //获取当前CellIndex(ind) var ind = mygrid_recv.getSelectedCellIndex(); //触发操作事件前获取单元值 var oldVal = mygrid_recv.cellByIndex(rowIndex, ind).getValue(); if (ind == 0) { oldVal = oldVal.toUpperCase(); var loader = dhtmlxAjax.getSync("../FeeCodes/TopCtnAdapter.aspx?ctn=" + oldVal + "&val=" + newGuid()); oldVal = loader.xmlDoc.responseText; //将value写入cell(触发 stage2) mygrid_recv.cellByIndex(rowIndex, ind).setValue(oldVal); } else if (ind == 5) { oldVal = oldVal.toUpperCase(); //comboKINDPKGS.loadXML("../FeeCodes/TCodePackageAdapter.aspx?mask=0&pos=0"); var loader = dhtmlxAjax.getSync("../FeeCodes/TopCtnAdapter.aspx?kindpkgs=" + oldVal + "&val=" + newGuid()); oldVal = loader.xmlDoc.responseText; //将value写入cell(触发 stage2) mygrid_recv.cellByIndex(rowIndex, ind).setValue(oldVal); } else if (ind == 6 || ind == 7 || ind == 8)//键盘输入浮点数字 { if (oldVal.trim() != "") { var bl = isFloat(oldVal); if (!bl) { alert("重量或尺码格式出错!"); return false; } } } else if (ind == 1 || ind == 4)//键盘输入整数 { if (oldVal.trim() != "") { var bl = isInt(oldVal); if (!bl) { alert("箱量或件数格式出错!"); return false; } } } return true; } }); //键盘操作事件 mygrid_recv.attachEvent("onKeyPress", function(code,cFlag,sFlag) { //onKeyPress begin //获取当前RowID var selectedId = mygrid_recv.getSelectedRowId(); //获取当前RowIndex var rowIndex = mygrid_recv.getRowIndex(selectedId); //获取当前CellIndex(ind) var ind = mygrid_recv.getSelectedCellIndex(); //触发操作事件前获取单元值 var oldVal = mygrid_recv.cellByIndex(rowIndex,ind).getValue(); //获取编辑单元 var txtEdit; //Tab键 if(code == 9) { var colCount = mygrid_recv.getColumnsNum(); var rowCount = mygrid_recv.getRowsNum(); if(ind < colCount) { isExchange = false; pressRecord = ""; pressRowIndex = -1; pressCellIndex = -1; mygrid_recv.editStop(true); mygrid_recv.cellByIndex(rowIndex,ind).setLabel(oldVal); var cInd = ind; var rId = selectedId; mygrid_recv.selectCell(rowIndex,ind+1,true,true); mygrid_recv.editCell(); if(ind == colCount - 1) { if(rowIndex < rowCount) { mygrid_recv.editStop(true); mygrid_recv.clearSelection(); mygrid_recv.selectCell(rowIndex+1,0,true,true); mygrid_recv.editCell(); } else { return; } } } } else if(code == 40)//向下方向键 { var rowCount = mygrid_recv.getRowsNum(); mygrid_recv.clearSelection(); mygrid_recv.editStop(); if(rowIndex == (rowCount - 1)) { addRecvRow(); } else { mygrid_recv.selectCell(rowIndex+1,0,true,true); mygrid_recv.editCell(); } } else if(code == 38)//向上箭头 { if(rowIndex > 0) { mygrid_recv.clearSelection(); mygrid_recv.editStop(); mygrid_recv.selectCell(rowIndex-1,0,true,true); mygrid_recv.editCell(); } } else { if(ind == 0 || ind == 5) { for(i = 0; i < document.all.length; i++) { if(document.all(i).tagName == "TEXTAREA") { txtEdit = document.all(i); break; } } if(code>=65&&code<=90) {//如果是输入英文字符 if(ind == 0) { //获取键盘输入字符 var pressVal = String.fromCharCode(code); var start=0; var end=0; if(document.selection){ var range = document.selection.createRange(); if(range.parentElement().className == txtEdit.className){ var range_all = document.body.createTextRange(); range_all.moveToElementText(txtEdit); for (start=0; range_all.compareEndPoints("StartToStart", range) < 0; start++){ range_all.moveStart('character', 1); } for (var i = 0; i <= start; i ++){ if (txtEdit.value.charAt(i) == '\n') start++; } var range_all = document.body.createTextRange(); range_all.moveToElementText(txtEdit); for (end = 0; range_all.compareEndPoints('StartToEnd', range) < 0; end ++) range_all.moveStart('character', 1); for (var i = 0; i <= end; i ++){ if (txtEdit.value.charAt(i) == '\n') end ++; } } } //如果是当前检索位置 if(rowIndex == pressRowIndex && ind == pressCellIndex){ //未选中多个字符 if(start == end){ if(start != pressRecord.length){ if(start != 0){ var firstVal = pressRecord.substring(0,start - 1); var endVal = pressRecord.substring(start + 1,txtEdit.value.length - 1); pressRecord = firstVal+pressVal+endVal; } }else{ pressRecord = pressRecord+pressVal; } } //选中多个字符 if(start != end){ var firstVal = pressRecord.substring(0,start); var endVal = pressRecord.substring(end - 1,txtEdit.value.length - 1); pressRecord = firstVal+pressVal+endVal; } }else{ pressRecord = pressVal; pressRowIndex = rowIndex; pressCellIndex = ind; } //获取combo下拉列表 var combo = mygrid_recv.getCustomCombo(selectedId,ind); var comboArg = combo.getKeys(); var count = 0; //开始遍历检索 //如果检索成功 状态pressCount=1 如果不成功应为pressCount=2 for(var i = 0;i 0) { var newId = newGuid(); //获取插入新纪录位置 var rowCount = mygrid_recv.getRowsNum(); mygrid_recv.addRow(newId,["","",""],rowCount); mygrid_recv.clearSelection(); var rId = mygrid_recv.getRowId(rowCount-1); //重新加载FRT var combo_frt; combo_frt = mygrid_recv.getCustomCombo(rId, 0); setComboByArray(mygrid_recv, combo_frt, newId, 0); // combo_frt = mygrid_recv.getCustomCombo(rId, 5); setComboByArray(mygrid_recv, combo_frt, newId, 5) //; mygrid_recv.editStop(true); mygrid_recv.selectCell(mygrid_recv.getRowIndex(newId),0,true,true); mygrid_recv.editCell(); } else { var BSNO = $("dvOrderNumVal").value.trim(); mygrid_recv.loadXML("SeaExportInfoGridSource.aspx?read=add&showcount=1&BSNO="+BSNO); } } function deleteRecvRow() { mygrid_recv.editStop(); var selRowID = mygrid_recv.getSelectedRowId(); var selGroup = new Array(); if(selRowID.indexOf(",") > 0) { selGroup = selRowID.split(","); } else { if(selRowID != null) { selGroup.push(selRowID); } } //查看是否有被选中的费用项 if(selGroup.length > 0) { if(selGroup.length > 1) { var delCount = 0; if(window.confirm("您确定要将所选数据删除吗?")) { var dg=new dialog(); dg.html=""; dg.width=200; dg.height=100; dg.title="标题"; dg.show(); while(delCount < selGroup.length) { var rowIndex = mygrid_recv.getRowIndex(selGroup[delCount]); var TopCtnName = mygrid_recv.cellByIndex(rowIndex,0).getValue(); var cusName = mygrid_recv.cellByIndex(rowIndex,1).getValue(); //var urlVal = "TopCtnService.aspx?gid="+selGroup[delCount]+"&handle=delete"+"&no="+newGuid(); var urlVal = "SeaExportInfoGridSource.aspx?read=delete&CTN_ID="+selGroup[delCount]; var loader = dhtmlxAjax.getSync(urlVal); var loadVal = loader.xmlDoc.responseText; if(loadVal > 0 ) { mygrid_recv.deleteRow(selGroup[delCount]); } else { mygrid_recv.deleteSelectedRows(); } delCount++; } dg.close(); } } else { var delCount = 0; while(delCount < selGroup.length){ var rowIndex = mygrid_recv.getRowIndex(selGroup[delCount]); var TopCtnName = mygrid_recv.cellByIndex(rowIndex,0).getValue(); var cusName = mygrid_recv.cellByIndex(rowIndex,1).getValue(); if(window.confirm("您确定要将数据("+TopCtnName+")删除吗?")){ var dg=new dialog(); dg.html=""; dg.width=200; dg.height=100; dg.title="标题"; dg.show(); //var urlVal = "TopCtnService.aspx?gid="+selGroup[delCount]+"&handle=delete"+"&no="+newGuid(); var urlVal = "SeaExportInfoGridSource.aspx?read=delete&CTN_ID="+selGroup[delCount]; var loader = dhtmlxAjax.getSync(urlVal); var loadVal = loader.xmlDoc.responseText; if(loadVal > 0 ) { mygrid_recv.deleteRow(selGroup[delCount]); dg.close(); //alert("删除成功"); } else { mygrid_recv.deleteSelectedRows(); dg.close(); } } delCount++; } } } else { alert("未选中要操作的费用项"); } } function saveRecvChange() { mygrid_recv.editStop(); var strError=""; var strError2=""; var strError3=""; var BSNO = $("dvOrderNumVal").value.trim(); jsonTopCtnObj = "{\"$type\":\"DSWeb.Models.JsonTopCtnGroupEntity, DSWeb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\",\"JsonTopCtnEntities\":["; column_count = mygrid_recv.getColumnsNum(); var tempJson = ""; var rowCount = mygrid_recv.getRowsNum(); for(var i = 0;i < rowCount;i++){ //获取RowID tempJson = ""; var rId = mygrid_recv.getRowId(i); tempJson += "\"$type\":\"DSWeb.Models.JsonTopCtnEntity, DSWeb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\","; tempJson += "\"TopCtn1\":\""+rId+"\",";//gid strError=""; for(var j=0;j < column_count;j++){ var cell = mygrid_recv.cellById(rId,j); var value = ""; //value = cell.cell.innerText; // .getValue(); value = cell.cell.textContent || cell.cell.innerText; if((j+2)==2) { if(value.trim() == "") { value = ""; strError="集装箱列表中有箱型为空的数据,不能保存集装箱信息!" continue; //value = "null"; } } else if((j+2)==3) { if(value.trim() == "") { value = "1"; strError="集装箱列表中有箱量为空的数据,不能保存集装箱信息!" continue; } else { var nb = IsNum(value.trim()); if(nb) { if(Number(value.trim())<1) { value = "1"; strError="集装箱列表中有箱量小于1的数据,不能保存集装箱信息!" continue; } } else { value = "1"; strError="集装箱列表中箱量数据格式错误,不能保存集装箱信息!" continue; } } } else if((j+2)==4) { if(value.trim() != "") { var svl = value.trim().length; if(svl==11) { var s13=value.trim().substr(0,3); var re = new RegExp("^[A-Za-z]+$"); if (!re.test(s13)) { strError="集装箱列表中箱号为“"+value.trim()+"”的数据,格式错误,请按照正确的箱号格式录入!" continue; } // var s4=value.trim().substr(3,1).toUpperCase(); if(s4.trim()!="U") { strError="集装箱列表中箱号为“"+value.trim()+"”的数据,格式错误,请按照正确的箱号格式录入!" continue; } // var s5611=value.trim().substr(4); var bl = IsNum(s5611.trim()); if(!bl) { strError="集装箱列表中箱号为“"+value.trim()+"”的数据,格式错误,请按照正确的箱号格式录入!" continue; } } else { strError="集装箱列表中箱号为“"+value.trim()+"”的数据,格式错误,请按照正确的箱号格式录入!" continue; } value=value.trim().toUpperCase(); } } else if((j+2)==6) { if(value.trim() == "") { value = "0"; } else { var nb = IsNum(value.trim()); if(nb) { if(Number(value.trim())<1) { value = "0"; strError="集装箱列表中有件数小于0的数据,不能保存集装箱信息!" continue; } } else { value = "0"; strError="集装箱列表中件数格式错误,不能保存集装箱信息!" continue; } } } else if((j+2)==8) { if(value.trim() == "") { value = "0"; } else { var nb = IsNum(value.trim()); if(nb) { if(Number(value.trim())<0) { value = "0"; strError="集装箱列表中有箱内货重小于0的数据,不能保存集装箱信息!" continue; } } else { value = "0"; strError="集装箱列表中箱内货重格式错误,不能保存集装箱信息!" continue; } } } else if((j+2)==9) { if(value.trim() == "") { value = "0"; } else { var nb = IsNum(value.trim()); if(nb) { if(Number(value.trim())<0) { value = "0"; strError="集装箱列表中有箱皮重小于0的数据,不能保存集装箱信息!" continue; } } else { value = "0"; strError="集装箱列表中箱皮重格式错误,不能保存集装箱信息!" continue; } } } else if((j+2)==10) { if(value.trim() == "") { value = "0"; } else { var nb = IsNum(value.trim()); if(nb) { if(Number(value.trim())<0) { value = "0"; strError="集装箱列表中有尺码小于1的数据,不能保存集装箱信息!" continue; } } else { value = "0"; strError="集装箱列表中尺码格式错误,不能保存集装箱信息!" continue; } } } else { if(value.trim() == "") { value = ""; //value = "null"; } } tempJson += "\"TopCtn"+(j+2)+"\":\""+value.trim()+"\","; } tempJson += "\"TopCtn12\":\""+BSNO+"\""; tempJson = "{"+tempJson+"}"; // if(strError!="") { strError2=strError; continue; } else { strError3+=","+BSNO } // if(i == rowCount - 1) { jsonTopCtnObj = jsonTopCtnObj+tempJson; } else { jsonTopCtnObj = jsonTopCtnObj+tempJson+","; } } // if(strError2!="") { alert(strError2); strError2=""; var dg=new dialog(); dg.close(); return; } // // if(strError3=="") // { // var dg=new dialog(); // dg.close(); // return; // } jsonTopCtnObj += "]}"; var txt_name = $("recvContainer"); txt_name.value = jsonTopCtnObj; msgBox(); setTimeout(postEnterTopCtn,200); } function doOnRowSelected(rowID,celInd){ alert("Selected row ID is "+rowID+"\nUser clicked cell with index "+celInd); } function getValue(){ var colLabel=mygrid_recv.getColumnLabel(0); alert(colLabel); var colLabel2=mygrid_recv.getColumnLabel(0,1); alert(colLabel2); } //post数据 function postEnterTopCtn(){ var myForm = document.getElementById("form1"); myForm.submit() ; } function findRow(){ var colNum = mygrid.getColumnsNum(); //alert(colNum); var count = mygrid.getRowsNum(); //alert(count); //var combo = mygrid.getCombo(1); //combo.put("abc","abc"); } function initGrid(){ doInitRecvGrid(); //setTimeout(doInitPayGrid,200); //setTimeout(totalDynamicTopCtnGain,700); } //放弃应收费用修改 重新加载页面 function recoverRecvChange() { mygrid_recv.editStop(); var selRowID = mygrid_recv.getSelectedRowId(); //查看是否有被选中的费用项 if(selRowID != null) { var rowIndex = mygrid_recv.getRowIndex(selRowID); var status = mygrid_recv.cellByIndex(rowIndex,0).getValue(); var TopCtnName = mygrid_recv.cellByIndex(rowIndex,1).getValue(); var cusName = mygrid_recv.cellByIndex(rowIndex,2).getValue(); if(window.confirm("您确定放弃当前行的修改吗?")) { var dg=new dialog(); dg.html=""; dg.width=200; dg.height=100; dg.title="标题"; dg.show(); var urlVal = "SeaExportInfoGridSource.aspx?read=recover&CTN_ID="+selRowID+"&val="+newGuid(); var loader = dhtmlxAjax.getSync(urlVal); var loadVal = loader.xmlDoc.responseText; if(!IsNum(loadVal)) { var recvArg = new Array(); recvArg = loadVal.split(","); var selRowIndex = mygrid_recv.getRowIndex(recvArg[0]); var colCount = mygrid_recv.getColumnsNum(); for(var i=0;i=y) return true; return false; } function ConvertToMoney(strObj){ var result = strObj.replace(",",""); return result; } function filterComboCustomerPress(gridObj,rowID,rowIndex,colIndex,filterVal,oldVal){ var combo = gridObj.getCustomCombo(rowID,colIndex); var comboArg = combo.getKeys(); var doCount = 0; for(var i = 0;i 0){ for(var i = 0;i