$.import( "sap.hana.democontent.epm.services" , "messages" ); var MESSAGES = $.sap.hana.democontent.epm.services.messages; function performMultiply(){ var body = '' ; var num1 = $.request.parameters.get( 'num1' ); var num2 = $.request.parameters.get( 'num2' ); var answer; answer = num1 * num2; body = answer.toString(); $.response.setBody(body); $.response.status = $.net.http.OK; } function downloadExcel() { var body = '' ; try { var query ='SELECT TOP 25000 \"PurchaseOrderId\", \"PartnerId\", \"CompanyName\", \"CreatedByLoginName\", \"CreatedAt\", \"GrossAmount\" ' + 'FROM \"sap.hana.democontent.epm.data::purchaseOrderHeaderExt\" order by \"PurchaseOrderId\"' ; $.trace.debug(query); var conn = $.db.getConnection(); var pstmt = conn.prepareStatement(query); var rs = pstmt.executeQuery(); body = MESSAGES.getMessage( 'SEPM_POWRK' , '002' ) + "\t " + // PurchaseOrder ID MESSAGES.getMessage('SEPM_POWRK', '003') + " \t " + // Partner ID MESSAGES.getMessage('SEPM_POWRK', '001') + " \t " + // Company Name MESSAGES.getMessage('SEPM_POWRK', '004') + " \t " + // Employee Responsible MESSAGES.getMessage('SEPM_POWRK', '005') + " \t " + // Created At MESSAGES.getMessage('SEPM_POWRK', '006') + " \n "; // Gross Amount while (rs.next()) { body += rs.getNString(1) + " \t " + rs.getNString(2) + " \t " + rs.getNString(3) + " \t " + rs.getNString(4) + " \t " + rs.getDate(5) + " \t " + rs.getDecimal(6) + " \n "; } } catch (e) { $.response.status = $.net.http.INTERNAL_SERVER_ERROR; $.response.setBody(e.message); return; } $.response.setBody(body); $.response.contentType = 'application/vnd.ms-excel; charset=utf-16le'; $.response.headers.set('Content-Disposition', 'attachment; filename=Excel.xls'); $.response.headers.set('access-control-allow-origin', '*'); $.response.status = $.net.http.OK; } var aCmd = $.request.parameters.get('cmd'); switch (aCmd) { case " multiply ": performMultiply(); break; case " Excel": downloadExcel(); break ; default : $.response.status = $.net.http.INTERNAL_SERVER_ERROR; $.response.setBody(MESSAGES.getMessage( 'SEPM_ADMIN' , '002' , aCmd)); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | sap.ui.jsview( "sapui5.xsjstest" , { getControllerName : function () { return "sapui5.xsjstest" ; }, createContent : function (oController) { var multiplyPanel = new sap.ui.commons.Panel().setText("XS Service Test - Multiplication" ); multiplyPanel.setAreaDesign sap.ui.commons.enums.AreaDesign.Fill); multiplyPanel.setBorderDesign sap.ui.commons.enums.BorderDesign.Box); var layoutNew = new sap.ui.commons.layout.MatrixLayout({width:"auto" }); multiplyPanel.addContent(layoutNew); var oVal1 = new sap.ui.commons.TextField( "val1" ,{tooltip: "Value #1" , editable: true }); var oVal2 = new sap.ui.commons.TextField( "val2" ,{tooltip: "Value #2" , editable: true }); var oResult = new sap.ui.commons.TextView( "result" ,{tooltip: "Results" }); var oEqual = new sap.ui.commons.TextView( "equal" ,{tooltip: "Equals" , text: " = " }); var oMult = new sap.ui.commons.TextView( "mult" ,{tooltip: "Multiply by" , text: " * " }); //Attach a controller event handler to Value 1 Input Field oVal1.attachEvent( "liveChange" , function (oEvent){ oController.onLiveChangeV1(oEvent,oVal2); }); //Attach a controller event handler to Value 2 Input Field oVal2.attachEvent( "liveChange" , function (oEvent){ oController.onLiveChangeV2(oEvent,oVal1); }); layoutNew.createRow(oVal1, oMult, oVal2, oEqual, oResult ); return multiplyPanel; } }); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | onLiveChangeV1: function (oEvent,oVal2){ //To-Do: Insert Service Call to XSJS Service var aUrl = '../../../services/Example1.xsjs?cmd=multiply' + '&num1=' +escape(oEvent.getParameters().liveValue)+ '&num2=' +escape(oVal2.getValue()); jQuery.ajax({ url: aUrl, method: 'GET' , dataType: 'json' , success: this .onCompleteMultiply, error: this .onErrorCall }); }, onLiveChangeV2: function (oEvent,oVal1){ //To-Do: Insert Service Call to XSJS Service var aUrl = '../../../services/Example1.xsjs?cmd=multiply' + '&num1=' +escape(oVal1.getValue())+ '&num2=' +escape(oEvent.getParameters().liveValue); jQuery.ajax({ url: aUrl, method: 'GET' , dataType: 'json' , success: this .onCompleteMultiply, error: this .onErrorCall }); }, onCompleteMultiply: function (myTxt){ var oResult = sap.ui.getCore().byId( "result" ); if (myTxt==undefined){ oResult.setText(0); } else { jQuery.sap.require( "sap.ui.core.format.NumberFormat" ); var oNumberFormat = sap.ui.core.format.NumberFormat.getIntegerInstance({ maxFractionDigits: 12, minFractionDigits: 0, groupingEnabled: true }); oResult.setText(oNumberFormat.format(myTxt)); } }, onErrorCall: function (jqXHR, textStatus, errorThrown){ sap.ui.commons.MessageBox.show(jqXHR.responseText, "ERROR" , "Service Call Error" ); return ; } |
欢迎光临 168大数据 (http://www.bi168.cn/) | Powered by Discuz! X3.2 |