Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package source;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.PrintStream;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- import java.text.SimpleDateFormat;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.Properties;
- import javax.print.attribute.HashPrintRequestAttributeSet;
- import javax.print.attribute.HashPrintServiceAttributeSet;
- import javax.print.attribute.PrintRequestAttributeSet;
- import javax.print.attribute.PrintServiceAttributeSet;
- import net.sf.jasperreports.engine.JRException;
- import net.sf.jasperreports.engine.JRExporterParameter;
- import net.sf.jasperreports.engine.export.JRPrintServiceExporter;
- import net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter;
- import net.sf.jasperreports.view.JasperViewer;
- public class JasperClientReport
- {
- String printer;
- String reportName;
- net.sf.jasperreports.engine.JasperReport jasperReport;
- net.sf.jasperreports.engine.JasperPrint jasperPrint;
- String printInPrinter;
- /* 28 */ Properties prop = new Properties();
- /* 29 */ PropertyOption propertyOption = new PropertyOption();
- public JasperClientReport(String reportName) throws JRException
- {
- /* 33 */ this.reportName = reportName;
- /* 34 */ this.jasperReport = net.sf.jasperreports.engine.JasperCompileManager.compileReport("reports/" + reportName + ".jrxml");
- }
- private void fillParams(Map<String, Object> params) throws JRException
- {
- /* 39 */ this.jasperPrint = net.sf.jasperreports.engine.JasperFillManager.fillReport(this.jasperReport, params, new net.sf.jasperreports.engine.JREmptyDataSource());
- /* 40 */ net.sf.jasperreports.engine.util.JRSaver.saveObject(this.jasperPrint, "reports/" + this.reportName + ".jrprint");
- }
- public void printPreview() {
- JasperViewer.viewReport(this.jasperPrint, true);
- }
- public void print(String printerName, Boolean displayPrintDialog) throws JRException
- {
- PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
- PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();
- printServiceAttributeSet.add(new javax.print.attribute.standard.PrinterName(printerName, null));
- JRPrintServiceExporter exporter = new JRPrintServiceExporter();
- exporter.setParameter(JRExporterParameter.INPUT_FILE_NAME, "reports/" + this.reportName + ".jrprint");
- exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);
- exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet);
- exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);
- exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, displayPrintDialog);
- exporter.exportReport();
- }
- void prepare(String description, String itemCode, String itemPackNr, String numberOfPackages, String packageUid, String producer) throws JRException, IOException {
- numberOfPackages = ("0".equals(numberOfPackages) | "".equals(numberOfPackages)) ? "1" : numberOfPackages;
- this.prop.load(new FileInputStream("config.properties"));
- this.printer = this.prop.getProperty("printer");
- this.printInPrinter = this.prop.getProperty("printInPrinter");
- System.out.println(printer);
- JasperClientReport jasperClientReport = new JasperClientReport("prod_label_1");
- Map<String, Object> params = new HashMap();
- params.put("pItemDesc", description);
- params.put("pArticleNo", itemCode);
- params.put("pPackageNo", itemPackNr + "/" + numberOfPackages);
- params.put("pBatchNo", packageUid);
- params.put("pVendor", producer);
- jasperClientReport.fillParams(params);
- if (!"true".equals(this.printInPrinter)) {
- jasperClientReport.printPreview();
- } else {
- jasperClientReport.print(this.printer, Boolean.FALSE);
- }
- }
- void prepareNew(String description, String itemCode, String itemPackNr, String numberOfPackages, String packageUid, String itemBarcode, String itemWeight, String itemDescription, String newItemCode) throws JRException, IOException {
- JasperClientReport jasperClientReport = new JasperClientReport("prod_label_1_new");
- Map<String, Object> params = new HashMap();
- params.put("pItemDesc", description);
- params.put("pArticleNo", itemCode);
- params.put("pPackageNo", itemPackNr + "/" + numberOfPackages);
- params.put("pBatchNo", packageUid);
- params.put("pItemBarcode", itemBarcode);
- params.put("pWeight", itemWeight);
- params.put("pItemDescription", itemDescription);
- params.put("pTotalColli", numberOfPackages);
- params.put("pNewItemCode", newItemCode);
- jasperClientReport.fillParams(params);
- this.prop.load(new FileInputStream("config.properties"));
- this.printer = this.prop.getProperty("printer");
- this.printInPrinter = this.prop.getProperty("printInPrinter");
- if (!"true".equals(this.printInPrinter)) {
- jasperClientReport.printPreview();
- } else {
- jasperClientReport.print(this.printer, Boolean.FALSE);
- }
- }
- void prepareAdditional(String gates, String shipToName, String address, String postNo, String city, String orderNo, String orderConfirmNo, String MRK, String barcode, String customerItemNo, String customerItemDescription) throws JRException, IOException {
- JasperClientReport jasperClientReport = new JasperClientReport("additionalLabel");
- System.out.println("Gates = " + gates + " ShipToName = " + shipToName + " address = " + address + " postNo = " + postNo + " city = " + city + " orderNo = " + orderNo + " orderConfirmNo = " + orderConfirmNo + " MRK = " + MRK + " barkode = " + barcode + " customerItemNo = " + customerItemNo + " customerItemDescription = " + customerItemDescription );
- SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- Map<String, Object> params = new HashMap<String, Object>();
- params.put("pName", shipToName);
- params.put("pAdress", address);
- params.put("pPostNo", postNo);
- params.put("pCity", city);
- params.put("pOrderNo", orderNo);
- params.put("pConfirmNo", orderConfirmNo);
- params.put("pMrk", MRK);
- params.put("customerItemNo", customerItemNo);
- params.put("customerItemDescription", customerItemDescription);
- if (barcode.length() != 1)
- {
- params.put("pBar", barcode);
- }
- params.put("pDate", ft.format(new Date()));
- jasperClientReport.fillParams(params);
- this.printer = this.propertyOption.getConfigValueFromProperties(gates + "GatesPrinter");
- // this.printer = this.propertyOption.getConfigValueFromProperties("R17GatesPrinter=Canon MF5900 Series UFRII LT");
- jasperClientReport.print(this.printer, Boolean.FALSE);
- }
- void prepareLutz(String description, String itemCode, String itemPackNr, String numberOfPackages, String packageUid, String itemBarcode, String itemWeight, String itemHeight, String itemWidth, String itemSize, String itemLenght, String customArtNr) throws JRException, IOException {
- JasperClientReport jasperClientReport = new JasperClientReport("prod_label_lutz");
- Map<String, Object> params = new HashMap();
- params.put("pItemDesc", description);
- params.put("pArticleNo", itemCode);
- params.put("pPackageNo", itemPackNr + "/" + numberOfPackages);
- params.put("pBatchNo", packageUid);
- params.put("pItemBarcode", itemBarcode);
- params.put("pWeight", itemWeight);
- params.put("pLenght", itemLenght);
- params.put("pHeight", itemHeight);
- params.put("pWidth", itemWidth);
- params.put("pSize", itemSize);
- params.put("pTotalColli", numberOfPackages);
- params.put("pCustomArtNr", customArtNr);
- jasperClientReport.fillParams(params);
- this.prop.load(new FileInputStream("config.properties"));
- this.printer = this.prop.getProperty("printer");
- this.printInPrinter = this.prop.getProperty("printInPrinter");
- if (!"true".equals(this.printInPrinter)) {
- jasperClientReport.printPreview();
- }
- else {
- jasperClientReport.print(this.printer, Boolean.FALSE);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement