⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 reportutil.java

📁 此文件为构造报表的主程序
💻 JAVA
字号:
package com.syscom.prjnckm.report.txt;import java.io.*;import java.util.*;import org.apache.commons.net.ftp.*;import com.syscom.frmcommon.util.db.*;import com.syscom.prjnckm.report.cls.*;public class ReportUtil {  private static final String FTP_HOST = "192.168.1.184";  private static final int FTP_PORT = 21;  private static final String FTP_USER = "user";  private static final String FTP_PASS = "user";  private static final boolean DO_FTP = false;  private static final boolean FORCE_TEMP_PATH = true;  private static final String TEMP_PATH = "C:\\PrintBuffer\\";  private static final String DEST_PATH = "";  public static String createTempFilename(String key) {    return createTempFilename(TEMP_PATH, key);  }  public static String createTempFilename(String dir, String key) {    if (FORCE_TEMP_PATH) {      dir = TEMP_PATH;    }    Calendar time = Calendar.getInstance();    StringBuffer str = new StringBuffer();    str.insert(0, (int) (Math.random() * 900 + 100));    str.insert(0, time.get(Calendar.MILLISECOND));    while (str.length() < 6) {      str.insert(0, '0');    }    str.insert(0, time.get(Calendar.SECOND));    while (str.length() < 8) {      str.insert(0, '0');    }    str.insert(0, time.get(Calendar.MINUTE));    while (str.length() < 10) {      str.insert(0, '0');    }    str.insert(0, time.get(Calendar.HOUR));    while (str.length() < 12) {      str.insert(0, '0');    }    str.insert(0, '.');    str.insert(0, key);    if (!dir.endsWith("/") && !dir.endsWith("\\")) {      str.insert(0, "/");    }    str.insert(0, dir);    str.append(".txt");    return str.toString();  }  public static String getTwDateStr(Calendar date) {    StringBuffer str = new StringBuffer();    str.insert(0, date.get(Calendar.DAY_OF_MONTH));    while (str.length() < 2) {      str.insert(0, '0');    }    str.insert(0, "/");    str.insert(0, date.get(Calendar.MONTH) + 1);    while (str.length() < 5) {      str.insert(0, '0');    }    str.insert(0, "/");    str.insert(0, date.get(Calendar.YEAR) - 1911);    while (str.length() < 8) {      str.insert(0, '0');    }    return str.toString();  }  public static String getHeaderStr(String hospitalNo, String jobName,                                    String location) {    try {      CachedRowSet printer = SQL.getDefaultPrinterByJob(hospitalNo, jobName,          location);      if (printer == null || printer.next() == false) {        return null;      }      String printerName = printer.getString("pnt_printer_name");      CachedRowSet report = SQL.getReportByJob(hospitalNo, jobName);      if (report == null || report.next() == false) {        return null;      }      String reportSize = report.getString("rpt_paper_size");      if (reportSize == null || reportSize.trim().equals("")) {        reportSize = "A4";      }      String reportOrientation = report.getString("rpt_paper_orientation");      if ("P".equals(reportOrientation)) {        reportOrientation = "1";      }      else {        reportOrientation = "2";      }      return printerName + ";" + reportSize + ";9;11;" + reportOrientation;    }    catch (Exception ex) {      ex.printStackTrace();      return null;    }  }  public static String getTimeStr(Calendar time) {    StringBuffer str = new StringBuffer();    str.insert(0, time.get(Calendar.SECOND));    while (str.length() < 2) {      str.insert(0, '0');    }    str.insert(0, ":");    str.insert(0, time.get(Calendar.MINUTE));    while (str.length() < 5) {      str.insert(0, '0');    }    str.insert(0, ":");    str.insert(0, time.get(Calendar.HOUR));    while (str.length() < 8) {      str.insert(0, '0');    }    return str.toString();  }  public static String cut(String str, int len) {    int count = 0;    int cutSize = 0;    for (int i = 0; i < str.length() && count < len * 2; i++) {      char ch = str.charAt(i);      if (ch > 255) {        count += 2;      }      else {        count++;      }      cutSize++;    }    if (count > len * 2) {      cutSize--;    }    return str.substring(0, cutSize);  }  public static String[] wrap(String str, int len) {    int count = 0, overCount = 0;    int startIndex = 0, endIndex = 0;    ArrayList strs = new ArrayList();    for (int i = 0; i < str.length(); i++) {      char ch = str.charAt(i);      if (Character.isLetterOrDigit(ch) == false || ch > 255) {        endIndex = i + 1;        overCount = 0;      }      else {        overCount += ch > 255 ? 2 : 1;      }      count += ch > 255 ? 2 : 1;      if (count > len * 2) {        if (endIndex == i + 1) {          endIndex--;        }        strs.add(str.substring(startIndex, endIndex));        startIndex = endIndex;        if (overCount == 0) {          count = 2;        }        else {          count = overCount;        }        System.out.println("A." + overCount);      }      else if (count == len * 2) {        strs.add(str.substring(startIndex, endIndex));        startIndex = endIndex;        count = overCount;        System.out.println("B." + overCount);      }      else if (ch == '\n') {        strs.add(str.substring(startIndex, endIndex - 1));        startIndex = endIndex = i + 1;        count = overCount = 0;        System.out.println("C." + overCount);      }      else if (ch == '\r') {        strs.add(str.substring(startIndex, endIndex - 1));        startIndex = endIndex = ++i + 1;        count = overCount = 0;        System.out.println("D." + overCount);      }    }    if (startIndex < str.length()) {      strs.add(str.substring(startIndex));    }    String[] result = new String[strs.size()];    for (int i = 0; i < strs.size(); i++) {      result[i] = (String) strs.get(i);    }    return result;  }  public static int ftp(String src) {    if (DO_FTP == false) {      return 0;    }    int pos;    String filename;    if ( (pos = src.lastIndexOf("\\")) != -1) {      filename = src.substring(pos + 1);    }    else if ( (pos = src.lastIndexOf("/")) != -1) {      filename = src.substring(pos + 1);    }    else {      filename = src;    }    String dest = DEST_PATH + filename;    FTPClient ftp = new FTPClient();    try {      ftp.connect(FTP_HOST, FTP_PORT);      int reply = ftp.getReplyCode();      if (!FTPReply.isPositiveCompletion(reply)) {        System.out.println("FTP server refused connection.[" + reply + "]");        return -1;      }      else {        if (ftp.login(FTP_USER, FTP_PASS) == false) {          System.out.println("FTP server authentication fail");          return -1;        }      }      ftp.setFileType(FTP.ASCII_FILE_TYPE);      FileInputStream is = new FileInputStream(src);      boolean isdone = false;      while (!isdone) {        reply = ftp.getReplyCode();        if (FTPReply.isNegativePermanent(reply)) {          break;        }        isdone = FTPReply.isPositiveCompletion(ftp.getReplyCode());        if (isdone && ftp.storeUniqueFile(dest, is)) {          System.out.println(" ok !!");        }        try {          Thread.currentThread().sleep(1000);        }        catch (InterruptedException e) {        }      }      return 0;    }    catch (Exception ex) {      ex.printStackTrace();      return -1;    }    finally {      if (ftp.isConnected()) {        try {          ftp.disconnect();        }        catch (IOException e) {        }      }    }  }  public static void main(String[] args) {    ftp("C:\\HelloWorldSwing.java");  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -