var commonGridObj_invoiceitem; var newInvoiceBookitemCount = 0; String.prototype.trim = function () { return this.replace(/(^\s*)|(\s*$)/g, ""); } function $(id){ return document.getElementById(id); } function createGrid(){ //header var headerArgs_invoiceitem = new Array("","发票号码","是否锁定","是否删除","是否已开出","创建人","创建时间"); //width var widthArgs_invoiceitem = new Array("40","150","70","70","70","120","120"); //column align var colAlignArgs_invoiceitem = new Array("center","center","center","center","center","center","center"); //column sort var colSortArgs_invoiceitem = new Array("na","str","str","str","str","str","str"); //column type var colTypeArgs_invoiceitem = new Array("ch","ed","ch","ch","ch","ro","ro"); commonGridObj_invoiceitem = new TGridCommon("mygrid_container_invoiceitem","form1",headerArgs_invoiceitem,widthArgs_invoiceitem,colAlignArgs_invoiceitem,colSortArgs_invoiceitem,colTypeArgs_invoiceitem); commonGridObj_invoiceitem.setResponseUrl("InvoiceBookGridSource.aspx"); var bookID = $("h_bookid").value; commonGridObj_invoiceitem.setRequest("InvoiceBookGridSource.aspx?handle=itemlist&show_page=15&cur_page=1&bookid="+bookID+"&uid="+commonGridObj_invoiceitem.newGuid()); commonGridObj_invoiceitem.setSourceType("json"); commonGridObj_invoiceitem.setSkin("xp"); commonGridObj_invoiceitem.setImageUrl("../images/"); commonGridObj_invoiceitem.initGrid(); commonGridObj_invoiceitem.bind(); commonGridObj_invoiceitem.getGridObj().enableEditEvents(true, false, true); commonGridObj_invoiceitem.getGridObj().enableKeyboardSupport(true); commonGridObj_invoiceitem.initPageByGID("itemlist","&bookid="+bookID); // commonGridObj_invoiceitem.getGridObj().attachEvent("onEditCell",function(stage,rId,cInd,nValue,oValue){ // if(stage == 0){ // if(cInd != 0){ // return false; // }else{ // return true; // } // } // }); // commonGridObj_invoiceitem.onEditEvent = function(){ // commonGridObj_invoicebooks.getGridObj().attachEvent("onEditCell",function(stage,rId,cInd,nValue,oValue){ // if(stage == 0){ // if(cInd != 0){ // return false; // }else{ // return true; // } // } // }); // } } //添加新发票 function addInvoiceBookitem(){ //权限检查 //添加新行 var newId = newGuid(); //获取插入新纪录位置 var rowCount = commonGridObj_invoiceitem.getGridObj().getRowsNum(); commonGridObj_invoiceitem.getGridObj().addRow(newId,[0,"",0,0,0,"",""],rowCount); commonGridObj_invoiceitem.getGridObj().clearSelection(); newInvoiceBookitemCount++; } //post数据 function postEnterInvoiceBookitem(){ var myForm = document.getElementById("form1"); myForm.submit() ; } //获取GUID function newGuid() { var guid = ""; for (var i = 1; i <= 32; i++){ var n = Math.floor(Math.random()*16.0).toString(16); guid += n; if((i==8)||(i==12)||(i==16)||(i==20)) guid += "-"; } return guid.toUpperCase(); } //生成/保存发票册 function createInvoice(){ var _name = $("txt_name").value.trim(); if(_name == ""){ alert("发票系统名称不能为空"); return; } var _description = $("txt_description").value.trim(); if(_description == ""){ alert("发票中文名称不能为空"); return; } var _type = $("sel_type").value.trim(); if(_type == ""){ alert("发票类型不能为空"); return; } var _code = $("txt_code").value.trim(); if(_code == ""){ alert("发票代码号不能为空"); return; } var _start = $("txt_startnum").value.trim(); if(_start == ""){ alert("发票起始号码不能为空"); return; } var _end = $("txt_endnum").value.trim(); if(_end == ""){ alert("发票结束号码不能为空"); return; } var _total = $("txt_total").value.trim(); if (_total == "") { alert("发票总数量不能为空"); return; } if(validateInvoiceNum() == 1){ if(window.confirm("确定要生成")){ var _gid=newGuid(); var _name = $("txt_name").value; var _description = $("txt_description").value; var _creator = $("h_userid").value var _code = $("txt_code").value; var _start = $("txt_startnum").value; var _end = $("txt_endnum").value; var _total = $("txt_total").value; var _islock = $("ck_lock").checked; var _isdelete = $("ck_delete").checked; var _comp = $("sel_company").value; var _type = $("sel_type").value; var postJson = ""; //begin postJson +="{"; postJson += "["; postJson += "\"gid\":\""+_gid+"\","; postJson += "\"name\":\""+_name+"\","; postJson += "\"desp\":\""+_description+"\","; postJson += "\"creator\":\""+_creator+"\","; postJson += "\"code\":\""+_code+"\","; postJson += "\"start\":\""+_start+"\","; postJson += "\"end\":\""+_end+"\","; postJson += "\"total\":\""+_total+"\","; postJson += "\"islock\":"+_islock+","; postJson += "\"isdelete\":"+_isdelete+","; postJson += "\"comp\":\""+_comp+"\","; postJson += "\"type\":\""+_type+"\""; postJson += "]"; postJson +="}"; var url = ""; url = "InvoiceBookGridSource.aspx?handle=createinvoice&post=" + escape(postJson) + "&bookid=" + $("h_bookid").value + "&uid=" + commonGridObj_invoiceitem.newGuid(); var loader = dhtmlxAjax.getSync(url); var cacheTotal = ""; var cacheTotalObj = null; var cacheVal = loader.xmlDoc.responseText; if(cacheVal.trim().length > 1){ cacheTotalObj = eval('(' + cacheVal + ')'); if(cacheTotalObj.result.length > 0){ if(cacheTotalObj.result[0].result == 1){ $("btn_create").disable = 1; $("h_bookid").value = cacheTotalObj.result[0].bookid; window.parent.opener.location.href = window.parent.opener.location.href; createGrid(); }else{ switch(cacheTotalObj.result[0].result){ case -3: alert("发票代码号重复,请重新输入"); break; case -4: alert("发票明细号码添加重复,请重新输入"); break; case -5: break; } } } } }else{ //createGrid(); } } } //校验发票起始和结束值 function validateInvoiceNum(){ var result = ""; var validate = 0; var startVal = $("txt_startnum").value; var endVal = $("txt_endnum").value; var totalVal = $("txt_total").value; var status = 0; if(startVal != ""){ if(endVal != ""){ //异步执行操作 var url = "InvoiceBookGridSource.aspx?handle=validinvoice&startnum="+startVal+"&endnum="+endVal+"&uid="+commonGridObj_invoiceitem.newGuid(); var loader = dhtmlxAjax.getSync(url); var postStatus = loader.xmlDoc.responseText; status = parseInt(postStatus); }else if(totalVal != ""){ //异步执行操作 var url = "InvoiceBookGridSource.aspx?handle=validinvoice&startnum="+startVal+"&endnum="+endVal+"&totalnum="+totalVal+"&uid="+commonGridObj_invoiceitem.newGuid(); var loader = dhtmlxAjax.getSync(url); var postStatus = loader.xmlDoc.responseText; status = parseInt(postStatus); }else if(endVal == "" && totalVal == ""){ validate = -1; result = "未填写发票结束号码和发票总数,生成发票时请填写发票结束号码或者发票总数"; } }else{ validate = -1; result = "起始值不能为空"; } switch(status){ case 1: result = ""; validate = 1; break; case -1: result = "发票号码长度错误"; validate = -1; break; case -2: result = "发票结束号码不能小于等于发票起始号码"; validate = -1; break; case -3: result = "发票总数与起始结束号码不相符"; validate = -1; break; case -4: result = "发票起始和结束间值超过发票册最大发票数值"; validate = -1; break; } if(validate < 0){ alert(result); } return validate; } function refreshList(){ createGrid(); } //全选框 function checkall(){ var checkStatus = $("ck_all").checked; if(checkStatus == 1){ var iCount = commonGridObj_invoiceitem.getGridObj().getRowsNum(); for(var i=0;i < iCount;i++){ commonGridObj_invoiceitem.getGridObj().cellByIndex(i,0).setValue(1); } }else{ var iCount = commonGridObj_invoiceitem.getGridObj().getRowsNum(); for(var i=0;i < iCount;i++){ commonGridObj_invoiceitem.getGridObj().cellByIndex(i,0).setValue(0); } } } function cancelInvoice() { } function updateInvoice() { }