WebPrint.java
资源名称:OA.rar [点击查看]
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:23k
源码类别:
OA系统
开发平台:
Java
- /**
- 公司:北京方成科技发展有限公司
- 作者:梅勇
- 日期:2001.08.24
- */
- import java.io.*;
- import java.text.*;
- import java.util.*;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import java.sql.*;
- import explato.database.*;
- import sun.io.ByteToCharConverter;
- import org.xml.sax.* ;
- import org.apache.xerces.dom.TextImpl;
- import org.w3c.dom.Attr;
- import org.w3c.dom.Document;
- import org.w3c.dom.NamedNodeMap;
- import org.w3c.dom.Node;
- import org.w3c.dom.NodeList;
- import dom.DOMParserWrapper;
- import dom.wrappers.DOMParser;
- public class WebPrint extends HttpServlet {
- private String strXml="";
- private ResultSet rs = null;
- private ResultSet rs1 = null;
- private Connection con = null;
- private ConnectionManager cm=null;
- private Document document=null;
- public void doPost(HttpServletRequest req,
- HttpServletResponse res)
- throws IOException, ServletException
- {
- //设置演示版,
- long Time1=1026000000+10454400;
- long curTime=0;
- curTime=System.currentTimeMillis();
- curTime=curTime/1000;
- //每天的时间为 86400
- if(curTime>Time1){
- System.out.println("演示版已到期,系统将不正常!");
- return ;
- }
- //------------------
- res.setContentType("text/html;charset=UTF-8");
- PrintWriter out = res.getWriter();
- try {
- ServletContext application = getServletContext();
- //ConnectionManager cm= (ConnectionManager)application.getAttribute("fcConPoolManager");
- cm=(ConnectionManager)application.getAttribute ( "fcConPoolManager" );
- //demo是配置文件中逻辑数据库的名字,同时也是连接池的名字
- // String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
- // String sConnStr = "jdbc:odbc:ereport";
- // Class.forName(sDBDriver);
- // con = DriverManager.getConnection(sConnStr,"sa","");
- con = cm.getConnection( "demo" ); //或者 con = cm.getConnection( "demo", 30000 ); //30000是不能马上取到连接时的等待时间(以毫秒计)
- //-----------------------
- /*
- Statement stmt = con.createStatement();
- //rs = stmt.executeQuery("SELECT * FROM test");
- con.setAutoCommit(false);
- stmt.executeUpdate("insert into test values('aaa','adfsdfsd')");
- int tran1=stmt.getUpdateCount();
- if (tran1>0){
- con.commit();
- }else{
- con.rollback();
- }
- // out.println("tran1="+tran1);
- /*String tt;
- while (rs.next()) {
- tt = rs.getString("fstr1");
- out.print("<LI>" + rs.getString("fstr2") + "</LI>");
- out.print("<pre>" + tt + "</pre>");
- }
- rs.close();*/
- //----------------------
- } catch (Exception e){
- //out.println("读表发生错误");
- }
- finally {
- if( con != null ){
- cm.freeConnection( "demo", con );
- }
- }
- //-------------------------------------------------------
- //strKey为?后的值
- String strKey=new String(req.getQueryString());
- //计算前台SEND来的XML串 存入strXml中
- BufferedReader in = req.getReader();
- String line = null;
- strXml="";
- while ((line = in.readLine()) != null) {
- strXml=strXml+line;
- }
- //parse XML串
- try {
- DOMParserWrapper parser =
- (DOMParserWrapper)Class.forName("dom.wrappers.DOMParser").newInstance();
- document = parser.parseXml(strXml);
- }
- catch (Exception e) {
- }
- //--------------------------------------------------------
- //用一个CASE语句来处理各种方法
- if (strKey.equals("fc_insert")) out.print(fc_insert());
- if (strKey.equals("fc_insert1")) out.print(fc_insert1()); //新增主子表
- if (strKey.equals("fc_update1")) out.print(fc_update1()); //新增主子表
- if (strKey.equals("fc_select")) out.print(fc_select());
- if (strKey.equals("fc_FieldToTable")) out.print(fc_FieldToTable());
- if (strKey.equals("twors")) out.print(twors());//两个结果集的测试
- if (strKey.equals("sqltoxml")) out.print(sqltoxml());//两个结果集的测试
- if (strKey.equals("dsnSetSession"))
- {
- Node root = document.getChildNodes().item(0);
- String strName=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- String strValue="";
- try {
- //当此节点值为空时
- strValue=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- }
- catch (Exception e) { }
- HttpSession session = req.getSession(true);
- session.setAttribute(strName, strValue);
- out.print("");
- }
- if (strKey.equals("dsnGetSession"))
- {
- Node root = document.getChildNodes().item(0);
- String strName=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- HttpSession session = req.getSession(true);
- String strSR=session.getAttribute(strName).toString();;
- out.print(strSR);
- }
- if (strKey.equals("loadprint")) {
- String strX="function%20detachPage%28%29%7B%20htmlToptmp%3DhtmlTop%3B%20htmlBottomtmp%3DhtmlBottom%3B%20var%20iStart%3D0%3B%20var%20iEnd%3D0%3B%20var%20lngEndLine%3Dt.rows.length-tabCauda%3B%20var%20colwidthXML%3DLoadUserData%28%22setcolwidth%22%2C%22ReportColWidth%22+ReportName%29%3B%20effectiveWidth%3DparseInt%28repWidth-tabLeft-tabRight%29%3B%20var%20oXML1%3Dnew%20ActiveXObject%28%22Microsoft.XMLDOM%22%29%3B%20oXML1.async%3D%22false%22%3B%20oXML1.loadXML%28%22%3Croot%3E%22%20+colwidthXML+%22%3C/root%3E%22%29%3B%20sumcol%3D0%3B%20var%20compressRate%3D1%3B%20if%28prnSet.compressWidth%3D%3D1%29%20%7B%20for%20%28var%20j%3D0%3Bj%3CMaxCols%3Bj++%29%7B%20if%20%28oXML1.documentElement.childNodes.item%28j%29.getAttribute%28%22colSelect%22%29%3D%3D%22block%22%29%7B%20sumcol%3Dsumcol+parseInt%28oXML1.documentElement.childNodes.item%28j%29.getAttribute%28%22colWidth%22%29%29%3B%20%7D%20%7D%20compressRate%3DeffectiveWidth/%28sumcol+MaxCols%29%3B%20if%28compressRate%3E%3D1%20%29%20%7B%20compressRate%3D1%3B%20%7D%20compressColWidth%28compressRate%29%3B%20%7D%20var%20hcompressRate%3D1%3B%20var%20t_outerHTMLbak%3Dt.outerHTML%20%3B%20if%28prnSet.compressHeight%3D%3D1%29%20%7B%20cur1%3D0%3B%20for%20%28var%20i%3DtabHead%3Bi%3ClngEndLine%3Bi++%29%20%7B%20cur1%3Dcur1+parseInt%28t.rows%28i%29.offsetHeight%29%3B%20%7D%20hcompressRate%3D%28repHeight-tabBottom-tabTop-PageHeadHeight-PageCaudaHeight-heightTop-heightBottom%29/%28cur1+lngEndLine-tabHead%29%3B%20if%28hcompressRate%3E%3D1%20%29%20%7B%20hcompressRate%3D1%3B%20%7D%20compressRowHeight%28hcompressRate%2CtabHead%2ClngEndLine%29%3B%20%7D%20if%20%28prnSet.compressFont%21%3D1%29%20%7B%20var%20compressFont%3D0%3B%20if%28hcompressRate%3CcompressRate%29%20%7B%20compressFont%3DhcompressRate%3B%20%7D%20else%20%7B%20compressFont%3DcompressRate%3B%20%7D%20if%28compressFont%3C1%29%7B%20t.style.fontSize%3DparseFloat%28t.style.fontSize%29*compressFont%3B%20%7D%20%7D%20setAutoturnRow%28%29%3B%20cur1%3D0%3B%20var%20sOtherPage%3D%22%22%3B%20for%20%28var%20i%3DtabHead%3Bi%3ClngEndLine%3Bi++%29%20%7B%20cur1%3Dcur1+parseInt%28t.rows%28i%29.offsetHeight%29%3B%20sOtherPage%3Dt.rows%28i%29.getAttribute%28%22otherpage%22%29%3B%20if%20%28sOtherPage%3D%3D%221%22%20%7C%7C%20cur1%3E%3DrepHeight-tabBottom-tabTop-PageHeadHeight-PageCaudaHeight-heightTop-heightBottom%7C%7C%20i%3D%3DlngEndLine-1%29%7B%20if%20%28sOtherPage%3D%3D%221%22%20%7C%7C%20cur1%3D%3DrepHeight-tabBottom-tabTop-PageHeadHeight-PageCaudaHeight-heightTop-heightBottom%29%20%7B%20cur1%3D0%3B%20%7D%20else%20%7B%20cur1%3DparseInt%28t.rows%28i%29.offsetHeight%29%3B%20%7D%20sumcol%3D0%3B%20var%20bFind%3Dfalse%3B%20iStart%3D0%3B%20iEnd%3D0%3B%20if%20%28sOtherPage%3D%3D%221%22%20%7C%7C%20i%3D%3DlngEndLine-1%29%7B%20perPageHTML%3DperPageHTML+t.rows%28i%29.outerHTML%20%3B%20%7D%20for%20%28var%20j%3D0%3Bj%3CMaxCols%3Bj++%29%7B%20if%20%28oXML1.documentElement.childNodes.item%28j%29.getAttribute%28%22colSelect%22%29%3D%3D%22block%22%29%7B%20sumcol%3Dsumcol+parseInt%28oXML1.documentElement.childNodes.item%28j%29.getAttribute%28%22colWidth%22%29%29*compressRate%3B%20%7D%20if%20%28sumcol%3E%3DeffectiveWidth%20%7C%7C%20j%3D%3DMaxCols-1%29%7B%20if%20%28sumcol%3C%3DeffectiveWidth%29%7B%20iEnd%3Dj%3B%20sumcol%3D0%3B%20%7D%20else%20%7B%20iEnd%3Dj-1%3B%20sumcol%3DparseInt%28oXML1.documentElement.childNodes.item%28j%29.getAttribute%28%22colWidth%22%29%29*compressRate%3B%20%7D%20var%20s1%3DHideCol%28strCol%2CiStart%2CiEnd%29%3B%20bFind%3Dtrue%3B%20PageDataAdd%28Pages%29%3B%20arrPage%5BPages%5D%3DhtmlTop+htmlBottom+tabstyle+s1%3B%20arrPage%5BPages%5D%3DarrPage%5BPages%5D+PageHeadHTML%3B%20arrPage%5BPages%5D%3DarrPage%5BPages%5D+perPageHTML+PageCaudaHTML+%22%3C/Table%3E%22%20+%22%3Cimg%20%3E%22%3B%20if%20%28i%3D%3DlngEndLine-1%29%7B%20if%28cur1%3ErepHeight-tabBottom-tabTop-PageHeadHeight-PageCaudaHeight-heightTop-heightBottom%29%7B%20PageDataAdd%28Pages+1%29%3B%20arrPage%5BPages+1%5D%3DhtmlTop+htmlBottom+tabstyle+s1%3B%20arrPage%5BPages+1%5D%3DarrPage%5BPages+1%5D+PageHeadHTML+PageCaudaHTML+%22%3C/Table%3E%22+%22%3Cimg%20%3E%22%3B%20biglabel.innerHTML%3Dbiglabel.innerHTML%20+%22%3Cdiv%20class%3DpreviewDiv%20%3E%u6B63%u5728%u8BA1%u7B97...%3C/DIV%3E%22%3B%20Pages%3DPages+1%3B%20%7D%20%7D%20biglabel.innerHTML%3Dbiglabel.innerHTML%20+%22%3Cdiv%20class%3DpreviewDiv%20%3E%u6B63%u5728%u8BA1%u7B97...%3C/DIV%3E%22%3B%20Pages%3DPages+1%3B%20if%20%28%28j%3D%3DMaxCols-1%20%29%20%26%26%20%28iEnd%3D%3Dj-1%29%20%29%7B%20var%20s1%3DHideCol%28strCol%2CMaxCols-1%2CMaxCols-1%29%3B%20bFind%3Dtrue%3B%20PageDataAdd%28Pages%29%3B%20arrPage%5BPages%5D%3DhtmlTop+htmlBottom+tabstyle+s1%3B%20arrPage%5BPages%5D%3DarrPage%5BPages%5D+PageHeadHTML%3B%20arrPage%5BPages%5D%3DarrPage%5BPages%5D+perPageHTML+PageCaudaHTML+%22%3C/Table%3E%22+%22%3Cimg%20%3E%22%3B%20if%20%28i%3D%3DlngEndLine-1%29%7B%20if%28cur1%3ErepHeight-tabBottom-tabTop-PageHeadHeight-PageCaudaHeight-heightTop-heightBottom%29%7B%20PageDataAdd%28Pages+1%29%3B%20arrPage%5BPages+1%5D%3DhtmlTop+htmlBottom+tabstyle+s1%20%3B%20arrPage%5BPages+1%5D%3DarrPage%5BPages+1%5D+PageHeadHTML+PageCaudaHTML+%22%3C/Table%3E%22+%22%3Cimg%20%3E%22%3B%20biglabel.innerHTML%3Dbiglabel.innerHTML%20+%22%3Cdiv%20class%3DpreviewDiv%20%3E%u6B63%u5728%u8BA1%u7B97...%3C/DIV%3E%22%3B%20Pages%3DPages+1%3B%20%7D%20%7D%20biglabel.innerHTML%3Dbiglabel.innerHTML%20+%22%3Cdiv%20class%3DpreviewDiv%20%3E%u6B63%u5728%u8BA1%u7B97...%3C/DIV%3E%22%3B%20Pages%3DPages+1%3B%20%7D%20iStart%3DiEnd+1%3B%20%7D%20%7D%20perPageHTML%3D%22%22%3B%20%7D%20if%28sOtherPage%21%3D%221%22%29%20perPageHTML%3DperPageHTML+t.rows%28i%29.outerHTML%20%3B%20%7D%20mdblRate%3D1%3B%20htmlTop%3D%22%22%3B%20htmlBottom%3D%22%22%3B%20t.outerHTML%3Dt_outerHTMLbak%3B%20t.style.display%3D%22none%22%3B%20for%28var%20i%3D0%3Bi%3CPages%3Bi++%29%7B%20arrPage%5Bi%5D%3Dfc_RepStr%28arrPage%5Bi%5D%2C%22%28P%29%22%2CPages+%22%22%29%3B%20%7D%20%7D%20%20";
- out.println(strX);
- }
- }
- //下面是自定义的方法
- //--------------------------------------
- //两个结果集的示例,第一个用连接池打开,第二个用一般方式打开
- private String twors() {
- // Node root = document.getChildNodes().item(0);
- // String sField=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- // String sTable=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- String strSql="select flngVoucherID,fstrVoucherTypeName from Voucher" ;
- String sTmp="";
- try {
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(strSql);
- while (rs.next()) {
- String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
- String sConnStr = "jdbc:odbc:ereport";
- Class.forName(sDBDriver);
- Connection con1 = DriverManager.getConnection(sConnStr,"sa","");
- String sT=rs.getString(1);
- Statement stmt1 = con1.createStatement();
- rs1 = stmt1.executeQuery("select fstrAccountName from voucherdetail Where flngVoucherId="+sT);
- while (rs1.next()) {
- System.out.println("科目:"+rs1.getString(1));
- }
- }
- }
- catch (Exception e){
- sTmp=e.getMessage() ;
- }
- return sTmp;
- }
- //--------------------------------------
- private String fc_FieldToTable() {
- Node root = document.getChildNodes().item(0);
- String sField=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- String sTable=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- String strSql="select "+sField+" From "+sTable ;
- String sTmp="";
- try {
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(strSql);
- }
- catch (Exception e){
- sTmp=e.getMessage() ;
- }
- return sTmp;
- }
- //--------------------------------------
- private String fc_select() {
- Node root = document.getChildNodes().item(0);
- String strSql=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- String strPageNo=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- int iPageNo=Integer.parseInt(strPageNo,10);//页号
- String strPageSize=root.getChildNodes().item(2).getChildNodes().item(0).getNodeValue();
- int iPageSize=Integer.parseInt(strPageSize,10);//页尺寸
- strSql=fcTrans(strSql);
- //System.out.println(strSql);
- String strX = "<root>";
- String sTmp = "";
- int iField=1;
- int iCount=1;
- int i=1;
- try {
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(strSql);
- ResultSetMetaData rsmd=rs.getMetaData();
- while (rs.next()) {
- //每页30行
- if (i>(iPageNo-1)*iPageSize && i<=iPageNo*iPageSize) {
- strX = strX + "<record>";
- iCount=rsmd.getColumnCount();
- for (iField = 1 ; iField<=iCount ;iField++ )
- {
- //当有NULL字段名时,表示此则无需给值.用fcnull标记名区分.
- String colName=rsmd.getColumnName(iField);
- if (colName==null) {
- strX = strX + "<fcnull></fcnull>" ;
- }
- else {
- String sT=rs.getString(iField);
- if (sT==null) sT="";
- strX = strX + "<fc>" + sT +"</fc>" ;
- }
- }
- strX = strX + "</record>";
- }
- i = i + 1;
- }
- i=i-1;
- if (i>0) {
- strX = strX + "<pages>"+i+"</pages>";
- }
- strX = strX + "</root>";
- rs.close();
- }
- catch (Exception e){
- sTmp=e.getMessage() ;
- System.out.println(sTmp);
- }
- return strX ;
- }
- //--------------------------------------
- private String fc_insert() {
- Node root = document.getChildNodes().item(0);
- String strSql=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- strSql=fcTrans(strSql);
- String sTmp = "";
- // CallableStatement cstmt=null;
- try {
- Statement stmt = con.createStatement();
- // stmt.executeQuery(strSql);
- stmt.executeUpdate(strSql);
- /*
- cstmt=con.prepareCall("{call sp_getID(?)}");
- cstmt.registerOutParameter(1,java.sql.Types.INTEGER,1);
- cstmt.executeUpdate();
- sTmp="<dsnID>"+ cstmt.getInt(1)+"</dsnID>";
- */
- }
- catch (Exception e){
- sTmp=e.getMessage() ;
- }
- return sTmp ;
- }
- //--------------------------------------
- private String fc_insert1() {
- //凭证增加
- Node root = document.getChildNodes().item(0);
- String sTmp = "";
- CallableStatement cstmt=null;
- try {
- Statement stmt = con.createStatement();
- int i;
- //System.out.println(root.getChildNodes().getLength());
- String strSql=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- strSql=fcTrans(strSql);
- stmt.executeUpdate(strSql);
- String sID="1"; //存主表新生成的ID
- try {
- //SQL Server 的存储过程,用于计算自动ID
- cstmt=con.prepareCall("{call sp_getID(?)}");
- cstmt.registerOutParameter(1,java.sql.Types.INTEGER,1);
- cstmt.executeUpdate();
- sID=""+cstmt.getInt(1);
- }
- catch (Exception e1){
- try {
- //计算MS Access数据库的主表ID
- String sDBDriver = "sun.jdbc.odbc.JdbcOdbcDriver";
- String sConnStr = "jdbc:odbc:webprint";
- Class.forName(sDBDriver);
- Connection con1 = DriverManager.getConnection(sConnStr,"sa","");
- Statement stmt1 = con1.createStatement();
- rs1 = stmt1.executeQuery("select max(flngSendOutID) From SendOut");
- if (rs1.next()) {
- sID=rs1.getString(1);
- }
- }
- catch (Exception e2){
- }
- }
- //追加子表内容
- for(i=1;i<root.getChildNodes().getLength();i++) {
- strSql=root.getChildNodes().item(i).getChildNodes().item(0).getNodeValue();
- strSql=fcTrans(strSql);
- strSql=strSql+sID+" )";
- stmt.executeUpdate(strSql);
- }
- }
- catch (Exception e){
- System.out.println(e.getMessage()) ;
- }
- return sTmp ;
- }
- //--------------------------------------
- private String fc_update1() {
- //凭证修改
- Node root = document.getChildNodes().item(0);
- String sTmp = "";
- String strSql="";
- try {
- Statement stmt = con.createStatement();
- int i;
- for(i=0;i<root.getChildNodes().getLength();i++) {
- strSql=root.getChildNodes().item(i).getChildNodes().item(0).getNodeValue();
- strSql=fcTrans(strSql);
- stmt.executeUpdate(strSql);
- }
- }
- catch (Exception e){
- System.out.println(e.getMessage()) ;
- }
- return sTmp ;
- }
- //--------------------------------------
- private String SqlToField(String strSql) {
- //用一个SQL语句返回一个字段的第一个记录值
- String strR = "";
- try {
- Statement stmt = con.createStatement();
- rs = stmt.executeQuery(strSql);
- if (rs.next()) {
- strR = rs.getString(1) ;
- }
- rs.close();
- stmt.close();
- }
- catch (Exception e){
- //out.println("读表发生错误");
- }
- return strR;
- }
- //--------------------------------------
- //通用函数
- private String rTrim(String str){
- String rstr = str;
- if(str == null)
- {
- rstr = "";
- }
- else
- {
- if(str.length() == 0) rstr = "";
- if(str.length() > 0)
- {
- for(int i = str.length() ; i > 0 ; i--)
- {
- if(str.substring(i-1,i).equals(" "))
- rstr = rstr.substring(0,i-1);
- else break;
- }
- }
- }
- return rstr;
- }
- //--------------------------------------------
- private String XmlOut(ResultSet oRs , String sRowEntityName,long EntFormat )
- {
- String sSet="";
- try {
- //oRs.first();
- while (oRs.next())
- {
- sSet = sSet + RecordToXMLEntity(oRs, sRowEntityName, EntFormat) ;
- }
- }
- catch (Exception e)
- {
- return e.getMessage();
- }
- return sSet ;
- }
- private String RecordToXMLEntity(ResultSet oRs , String EntityName,long EntFormat)
- {
- String sEty ="";
- int iField=1;
- int iCount=1;
- try {
- ResultSetMetaData rsmd=oRs.getMetaData();
- iCount=rsmd.getColumnCount();
- if (EntFormat==1)
- {
- //属性
- sEty = "<" + EntityName ;
- for (iField = 1 ; iField<=iCount ;iField++ )
- {
- sEty = sEty + " " + rsmd.getColumnName(iField) +"='" + oRs.getString(iField) +"'" ;
- }
- sEty = sEty + "/>" + "n";
- }
- else
- {
- //节点
- sEty = "<" + EntityName +">" +"n" ;
- for (iField = 1 ; iField<=iCount ; iField++)
- {
- sEty = sEty +"<" + rsmd.getColumnName(iField) +">" + oRs.getString(iField) +"</" + rsmd.getColumnName(iField) +">";
- }
- sEty = sEty +"n" +"</" + EntityName +">" +"n";
- }
- }
- catch (Exception e)
- {
- }
- return sEty;
- }
- //-----------------------------------------------------
- private Attr[] sortAttributes(NamedNodeMap attrs) {
- int len = (attrs != null) ? attrs.getLength() : 0;
- Attr array[] = new Attr[len];
- for ( int i = 0; i < len; i++ ) {
- array[i] = (Attr)attrs.item(i);
- }
- for ( int i = 0; i < len - 1; i++ ) {
- String name = array[i].getNodeName();
- int index = i;
- for ( int j = i + 1; j < len; j++ ) {
- String curName = array[j].getNodeName();
- if ( curName.compareTo(name) < 0 ) {
- name = curName;
- index = j;
- }
- }
- if ( index != i ) {
- Attr temp = array[i];
- array[i] = array[index];
- array[index] = temp;
- }
- }
- return(array);
- } // sortAttributes(NamedNodeMap):Attr[]
- private String fcTrans(String sSource)
- {
- //
- //XML节点中的汉字经8859_1==>UTF-8转换后用System.out.println输出正常
- String unicodesR ="";
- try {
- byte [] by = sSource.getBytes("8859_1"); //GB2312
- unicodesR = new String(by,"UTF-8");
- }
- catch (Exception e)
- {
- }
- //System.out.println(unicodesR);
- return unicodesR;
- ///
- }
- //--------------------------------------------
- //WebCode中用
- private String sqltoxml()
- {
- Node root=document.getChildNodes().item(0);
- String strpage=root.getChildNodes().item(0).getChildNodes().item(0).getNodeValue();
- String strsql=root.getChildNodes().item(1).getChildNodes().item(0).getNodeValue();
- strsql=fcTrans(strsql);
- String strsearch=root.getChildNodes().item(2).getChildNodes().item(0).getNodeValue();
- String strrownum=root.getChildNodes().item(3).getChildNodes().item(0).getNodeValue();
- String showcheckbox=root.getChildNodes().item(4).getChildNodes().item(0).getNodeValue();
- String blnempty=root.getChildNodes().item(5).getChildNodes().item(0).getNodeValue();
- //加空行
- showcheckbox=showcheckbox.toUpperCase();
- int intpage=Integer.parseInt(strpage);//开始页
- int intrownum=Integer.parseInt(strrownum);//页尺寸
- String strX="";
- try {
- //建立数据库连接
- Statement stmt = con.createStatement();
- //执行查询建立结果集
- //-----------------
- //System.out.print(strsearch);
- int i=1;
- if (strsearch.compareTo("###")!=0){
- rs = stmt.executeQuery(strsql);
- boolean bfind=false;
- while(rs.next()){
- String searchone=rs.getString(1);
- //out.print(searchone);
- if (searchone.equals(strsearch)){
- bfind=true;
- break;
- }
- i=i+1;
- }
- rs.close();
- if (bfind==true){
- if (i<=intrownum){
- intpage=1;
- }
- else {
- if (i%intrownum>0){
- intpage=i/intrownum+1;
- }
- else {
- intpage=i/intrownum;
- }
- }
- }
- //自动定位到当前选择所在值的页
- }
- //out.print("intpage="+intpage);
- //-----------------
- // System.out.print(intpage);
- rs = stmt.executeQuery(strsql);
- ResultSetMetaData rsmd=rs.getMetaData();
- strX="<root>";
- String sLabel="";
- int k=0;
- int thisrow=0;
- int pagenumber=0;//总页数
- int iFind=0; //控制在开始处插入一个空白行
- while (rs.next()) {
- if (blnempty.equals("true") && iFind==0) {
- //插入一个空白行
- strX=strX+"<tr height='16'>";
- for (i=1;i<=rsmd.getColumnCount();i++) {
- strX = strX + "<td></td>";
- }
- strX=strX+"</tr>";
- iFind=1;
- }
- if (k>=(intpage-1)*intrownum && k<(intpage)*intrownum){
- strX = strX + "<tr>";
- for (i=1;i<=rsmd.getColumnCount();i++) {
- sLabel=rsmd.getColumnLabel(i);
- //System.out.println(rsmd.getColumnTypeName(i));
- String sT=rs.getString(i);
- if (sT==null) sT="";
- strX = strX + "<td>" + sT + "</td>";
- }
- if (showcheckbox.equals("TRUE"))
- strX = strX + "<td width='30'><input type='checkbox'></input></td>"+"</tr>";
- else
- strX = strX + "</tr>";
- }
- k=k+1;
- }
- if (k%intrownum>0)
- pagenumber=k/intrownum+1;
- else
- pagenumber=k/intrownum;
- strX=strX+"<pagenumber>"+pagenumber+"</pagenumber><intpage>"+intpage+"</intpage></root>";
- } catch (Exception e){
- strX=e.getMessage();
- }
- return strX;
- }
- }