Sunday, January 19, 2014

page call using script and azax way (Self note)

package SQLQuery.Patient;

import java.io.IOException;
import java.io.OutputStream;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.export.JRCsvExporter;
import net.sf.jasperreports.engine.export.JRHtmlExporter;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.export.JRRtfExporter;
import net.sf.jasperreports.engine.export.JRXlsExporter;

import Database.DatabaseConnection;

import com.allClass.Model.HrvPoliceInfo;
import com.allClass.Model.OpPatientTypeInfo;
import com.allClass.Model.ReasonAppPatientInfo;

public class ReasonAppointmentSql {

    private Connection con = null;
    private Statement st = null;
    private CallableStatement cs = null;
    private ResultSet rs = null;
    private DatabaseConnection dbc = new DatabaseConnection();
    String query = "";

    // Start Patient Trpe
    public List getPatientTypeData() {

        List<OpPatientTypeInfo> patientTypeList = new ArrayList<OpPatientTypeInfo>();
        boolean fg = true;
        con = dbc.connectDB();

        if (con == null) {
            fg = false;
        }

        if (fg) {
            try {

                st = con.createStatement();

                // query = "select type_code,identity_code from op_pattype";
                // Relational table
                query = "select distinct a.type_code type_code, b.identity_code identity_code from op_pattypedtl a, op_pattype b where a.type_code = b.type_code";

                System.out.println(query);

                rs = st.executeQuery(query);

                while (rs.next()) {

                    OpPatientTypeInfo opPatientTypeInfo = new OpPatientTypeInfo();
                    opPatientTypeInfo.setTYPE_CODE(rs.getInt("type_code"));
                    opPatientTypeInfo.setIDENTITY_CODE(rs
                            .getString("identity_code"));

                    patientTypeList.add(opPatientTypeInfo);
                }

            } catch (SQLException sq) {
                sq.printStackTrace();
            } finally {
                try {
                    if (rs != null) {
                        rs.close();
                    }

                    con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        }

        return patientTypeList;
    }

    // End Patient Trpe

    // Start Department
    public List getDepartAppoinData() {

        List<ReasonAppPatientInfo> departAppPatientList = new ArrayList<ReasonAppPatientInfo>();
        boolean fg = true;
        con = dbc.connectDB();

        if (con == null) {
            fg = false;
        }

        if (fg) {
            try {

                st = con.createStatement();

                query = "select dept_no,dept_name from hr_dept";

                System.out.println(query);

                rs = st.executeQuery(query);

                while (rs.next()) {

                    ReasonAppPatientInfo reasonAppPatientInfo = new ReasonAppPatientInfo();
                    reasonAppPatientInfo.setDEPT_NO(rs.getInt("dept_no"));
                    // reasonAppPatientInfo.setDEPT_NO(rs.getString("dept_no"));
                    reasonAppPatientInfo.setDEPT_NAME(rs.getString("dept_name"));

                    departAppPatientList.add(reasonAppPatientInfo);
                }

            } catch (SQLException sq) {
                sq.printStackTrace();
            } finally {
                try {
                    if (rs != null) {
                        rs.close();
                    }

                    con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        }

        return departAppPatientList;
    }

    // End Department

    // Start specialization
    public List getSpecialAppoinData() {

        List<ReasonAppPatientInfo> specialAppPatientList = new ArrayList<ReasonAppPatientInfo>();
        boolean fg = true;
        con = dbc.connectDB();

        if (con == null) {
            fg = false;
        }

        if (fg) {
            try {

                st = con.createStatement();

                query = "select specialization_no,specialization_name from op_consultationspecialization";

                System.out.println(query);

                rs = st.executeQuery(query);

                while (rs.next()) {

                    ReasonAppPatientInfo reasonAppPatientInfo = new ReasonAppPatientInfo();
                    reasonAppPatientInfo.setSPECIALIZATION_NO(rs.getInt("specialization_no"));
                    reasonAppPatientInfo.setSPECIALIZATION_NAME(rs.getString("specialization_name"));

                    specialAppPatientList.add(reasonAppPatientInfo);
                }

            } catch (SQLException sq) {
                sq.printStackTrace();
            } finally {
                try {
                    if (rs != null) {
                        rs.close();
                    }

                    con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        }

        return specialAppPatientList;
    }

    // End specialization

    // Start Medical Officer
    public List getMedicalOfficerAppoinData() {

        List<ReasonAppPatientInfo> medicalOfficerAppPatientList = new ArrayList<ReasonAppPatientInfo>();
        boolean fg = true;
        con = dbc.connectDB();

        if (con == null) {
            fg = false;
        }

        if (fg) {
            try {

                st = con.createStatement();

                query = "select doctor_no,doctor_name from hpms_doctor where specialization_no is null";

                System.out.println(query);

                rs = st.executeQuery(query);

                while (rs.next()) {

                    ReasonAppPatientInfo reasonAppPatientInfo = new ReasonAppPatientInfo();
                    reasonAppPatientInfo.setDOCTOR_NO(rs.getString("doctor_no"));
                    reasonAppPatientInfo.setDOCTOR_NAME(rs.getString("doctor_name"));
                    medicalOfficerAppPatientList.add(reasonAppPatientInfo);
                }

            } catch (SQLException sq) {
                sq.printStackTrace();
            } finally {
                try {
                    if (rs != null) {
                        rs.close();
                    }

                    con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        }

        return medicalOfficerAppPatientList;
    }

    // End Medical Officer

    // Start Consultent
    public List getConsultentAppoinData(String valSpecial_name) {

        List<ReasonAppPatientInfo> consultentAppPatientList = new ArrayList<ReasonAppPatientInfo>();
        boolean fg = true;
        con = dbc.connectDB();

        Statement st1 = null;
        ResultSet rs1 = null;
        if (con == null) {
            fg = false;
        }

        String addCon = "is null";
        if (valSpecial_name != null) {
            addCon = "=" + valSpecial_name;
        }

        if (fg) {
            try {

                st1 = con.createStatement();

                String query1 = "select doctor_no,doctor_name,doc_chember from hpms_doctor where specialization_no "
                        + addCon;

                System.out.println(query1);

                rs1 = st1.executeQuery(query1);

                while (rs1.next()) {

                    ReasonAppPatientInfo reasonAppPatientInfo = new ReasonAppPatientInfo();
                    reasonAppPatientInfo.setDOCTOR_NO(rs1.getString("doctor_no"));
                    reasonAppPatientInfo.setDOCTOR_NAME(rs1.getString("doctor_name"));
                    reasonAppPatientInfo.setDOC_CHEMBER(rs1.getString("doc_chember"));
                    consultentAppPatientList.add(reasonAppPatientInfo);
                }

            } catch (SQLException sq) {
                sq.printStackTrace();
            } finally {
                try {
                    if (rs1 != null) {
                        rs1.close();
                    }

                    con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        }

        return consultentAppPatientList;
    }

    // End Consultent

    // *********************************************************************************
    // public List getRoomNoData(String valRoom_no) //This is use For Return List
    // Return
    public ReasonAppPatientInfo getRoomNoData(String valRoom_no) {  //This is use For Single Row Return
        // List<ReasonAppPatientInfo> consultentAppPatientList = new
        // ArrayList<ReasonAppPatientInfo>();//This is use For List Return

        ReasonAppPatientInfo reasonAppPatientInfo = null; // Initialize situation Global. If use under line instead of this Line then while Loop's initialize Declaration Not mendatory
        // ReasonAppPatientInfo reasonAppPatientInfo = new ReasonAppPatientInfo();
        boolean fg = true;
        con = dbc.connectDB();

        Statement st1 = null;
        ResultSet rs1 = null;
        if (con == null) {
            fg = false;
        }

        /*
         * String addCon1="is null"; if(valRoom_no!=null){
         * addCon1="="+valRoom_no; }
         */

        if (fg) {
            try {

                st1 = con.createStatement();

                String query1 = "select doc_chember from hpms_doctor where  doctor_no = '"
                        + valRoom_no + "'";

                System.out.println(query1);

                rs1 = st1.executeQuery(query1);

                while (rs1.next()) {

                    // ReasonAppPatientInfo reasonAppPatientInfo = new ReasonAppPatientInfo();
                    reasonAppPatientInfo = new ReasonAppPatientInfo(); // Initialize situation as global declaration null( ReasonAppPatientInfo reasonAppPatientInfo=null; )
                    reasonAppPatientInfo.setDOC_CHEMBER(rs1.getString("doc_chember"));
                    // consultentAppPatientList.add(reasonAppPatientInfo);
                }

            } catch (SQLException sq) {
                sq.printStackTrace();
            } finally {
                try {
                    if (rs1 != null) {
                        rs1.close();
                    }

                    con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        }

        // return consultentAppPatientList;
        return reasonAppPatientInfo;
    }

    // *********************************************************************************

    public List getReasonAppoinData() {

        List reasonAppPatientList = new ArrayList<ReasonAppPatientInfo>();
        boolean fg = true;
        con = dbc.connectDB();

        if (con == null) {
            fg = false;
        }

        if (fg) {
            try {

                st = con.createStatement();

                query = "select type_code,type_des from op_apptype";

                System.out.println(query);

                rs = st.executeQuery(query);

                while (rs.next()) {

                    ReasonAppPatientInfo reasonAppPatientInfo = new ReasonAppPatientInfo();
                    reasonAppPatientInfo.setTYPE_CODE(rs.getString("type_code"));
                    reasonAppPatientInfo.setTYPE_DES(rs.getString("type_des"));

                    reasonAppPatientList.add(reasonAppPatientInfo);
                }

            } catch (SQLException sq) {
                sq.printStackTrace();
            } finally {
                try {
                    if (rs != null) {
                        rs.close();
                    }

                    con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        }

        return reasonAppPatientList;
    }

    // *************************** Start This Portion is use for insert value

    public void addPatientA(String reg_noA, String dobA, String statusValA,String patType_idA, String docChember_idA, String consultentA,String reason_consulA, String ch_complainA) {
        String appoint_no;
        int slNo = 0;
        boolean fg = true;
        con = dbc.connectDB();

        if (con == null) {
            fg = false;
        }

        if (fg) {
            //
            try {
               
                // Start new add Shyfuzzaman************
                try {

                    st = con.createStatement();
//String querySl = "select pat_sl as sl from op_appointment where doctor_no='"+consultentA+"' and trunc(appoint_date)=trunc(sysdate) and rownum <2";
                    String querySl = "select pat_sl  from op_appointment where doctor_no='"+consultentA+"' "
                            + "and trunc(appoint_date)=trunc(sysdate) and rownum <2";
                   
                    System.out.println("querySl:"+querySl);
                   
                    ResultSet rs = st.executeQuery(querySl);
                   
                    while (rs.next()) {

                        //slNo = rs.getInt("sl");
                        slNo = rs.getInt("pat_sl");

                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }

                slNo += 1;
              //End new add Shyfuzzaman*****************
                String sql = "call PRC_BUILD_PK(?, ?,?,?,?,?)";

                cs = con.prepareCall(sql);
                cs.setString(1, "USER");
                cs.setString(2, "SEQ_OP_APPOINTMENT");
                cs.setString(3, "P");
                cs.setString(4, "1");
                cs.registerOutParameter(5, java.sql.Types.VARCHAR);
                cs.setString(6, "Y");

                cs.execute();

                appoint_no = cs.getString(5);

                System.out.println(appoint_no);
                st = con.createStatement();

                // query = "insert into
                // op_appointment(REG_NO,FULL_NAME,DOB,GENDER,DOCTOR_NO) values
                // ('"+reg_noA+"','"+police_nameA+"','"+dobA+"','"+statusValA+"','"+consultentA+"')";

                query = "insert into op_appointment(APPOINT_NO,REG_NO,DOB,GENDER,DOCTOR_NO,CONSULT_TYPE_NO,APPOINT_DATE,COMPANY_NO,PAT_TYPE,PAT_SL,DOC_CHEMBER) "
                        + " values ('"
                        + appoint_no
                        + "','"
                        + reg_noA
                        + "',to_date('"
                        + dobA
                        + "','DD/MM/YYYY') , '"
                        + statusValA
                        + "','"
                        + consultentA
                        + "','"
                        + reason_consulA
                        + "',sysdate,'1','"    + patType_idA+ "',"+ slNo+ ",'" + docChember_idA + "')";

                System.out.println("Query" + query);
                st.execute(query);

                // kaniz Upper style follow or this way same
                // st.execute("insert into
                // op_patchiefcomplain(APPOINT_NO,CHIEF_COMPLAIN,COMPANY_NO)
                // values('"+appoint_no+"','"+ch_complainA+"','1')");
                String query2 = "insert into op_patchiefcomplain(APPOINT_NO,CHIEF_COMPLAIN,COMPANY_NO) values('"
                        + appoint_no + "','" + ch_complainA + "','1')";
                System.out.println("Query2" + query2);
                st.execute(query2);

                try {
                    showReport(appoint_no);
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                // Some Note for Self here one exception(Exception e) catch 3
                // exception as like report method 3 parameter OR 3 exception
                // declare different way
            } catch (SQLException sq) {
                sq.printStackTrace();
            } finally {
                try {

                    if (rs != null) {
                        rs.close();
                    }

                    con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        }
        // return NewFaqList;
    }

    // ***************************Backup Start
    /*
     * public void addPatientA(String reg_noA,String dobA,String
     * statusValA,String consultentA,String reason_consulA,String ch_complainA){
     * String appoint_no;
     *
     * boolean fg = true; con = dbc.connectDB();
     *
     * if (con == null) { fg = false; }
     *
     *
     * if (fg) { try {
     *
     *
     * String sql="call PRC_BUILD_PK(?, ?,?,?,?,?)";
     *
     * cs = con.prepareCall(sql); cs.setString(1, "USER"); cs.setString(2,
     * "SEQ_OP_APPOINTMENT"); cs.setString(3, "P"); cs.setString(4, "1");
     * cs.registerOutParameter(5, java.sql.Types.VARCHAR); cs.setString(6, "Y");
     *
     * cs.execute();
     *
     * appoint_no = cs.getString(5);
     *
     * System.out.println(appoint_no); st = con.createStatement();
     *
     * //query = "insert into
     * op_appointment(REG_NO,FULL_NAME,DOB,GENDER,DOCTOR_NO) values
     * ('"+reg_noA+"','"+police_nameA+"','"+dobA+"','"+statusValA+"','"+consultentA+"')";
     *
     *
     * query = "insert into
     * op_appointment(APPOINT_NO,REG_NO,DOB,GENDER,DOCTOR_NO,CONSULT_TYPE_NO,APPOINT_DATE,COMPANY_NO) " + "
     * values ('"+appoint_no+"','"+reg_noA+"',to_date('" + dobA +
     * "','DD/MM/YYYY') ,
     * '"+statusValA+"','"+consultentA+"','"+reason_consulA+"',sysdate,'1')";
     *
     *
     * System.out.println("Query" + query); st.execute(query);
     *
     * //kaniz Upper style follow or this way same //st.execute("insert into
     * op_patchiefcomplain(APPOINT_NO,CHIEF_COMPLAIN,COMPANY_NO)
     * values('"+appoint_no+"','"+ch_complainA+"','1')"); String query2 =
     * "insert into op_patchiefcomplain(APPOINT_NO,CHIEF_COMPLAIN,COMPANY_NO)
     * values('"+appoint_no+"','"+ch_complainA+"','1')";
     * System.out.println("Query2" + query2); st.execute(query2);
     *
     *
     *  } catch (SQLException sq) { sq.printStackTrace(); } finally { try { if
     * (rs != null) { rs.close(); }
     *
     * con.close(); } catch (SQLException ex) { ex.printStackTrace(); } } } //
     * return NewFaqList; }
     */

    // ***************************Backup End
    // *************************** End This Portion is use for insert value

   
   
   
   
   
   
   
   
    //Start Serial Number Azax Page ******************
    public List serialMain(String consultentA){
       
        List<ReasonAppPatientInfo> patientSeqList = new ArrayList<ReasonAppPatientInfo>();
        boolean fg = true;
        con = dbc.connectDB();

        if (con == null) {
            fg = false;
        }

        if (fg) {
            try {

                st = con.createStatement();

               // String query = "select pat_sl as sl,fnc_patientname(reg_no) patname from op_appointment where doctor_no='"+consultentA+"' and trunc(appoint_date)=trunc(sysdate) and rownum <3";
  String query = "select pat_sl,fnc_patientname(reg_no) patname from op_appointment where doctor_no='"+consultentA+"' and trunc(appoint_date)=trunc(sysdate) and rownum <3";


                System.out.println(query);

                rs = st.executeQuery(query);

                while (rs.next()) {

                    ReasonAppPatientInfo reasonAppPatientInfo = new ReasonAppPatientInfo();                   
                    reasonAppPatientInfo.setPAT_SL(rs.getString("pat_sl"));
                    reasonAppPatientInfo.setPAT_NAME(rs.getString("patname"));
                    patientSeqList.add(reasonAppPatientInfo);
                   
                }

            } catch (SQLException sq) {
                sq.printStackTrace();
            } finally {
                try {
                    if (rs != null) {
                        rs.close();
                    }

                    con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        }

        return patientSeqList;
    }
    //End Serial Number Azax Page ******************
   
   
/*public List trackMain(String docChember_idA,String consultentA,String speciality_idA){
       
        List<ReasonAppPatientInfo> patientTrackList = new ArrayList<ReasonAppPatientInfo>();
        //List<ReasonAppPatientInfo> patientTrackList1 = new ArrayList<ReasonAppPatientInfo>();
        boolean fg = true;
        con = dbc.connectDB();

        if (con == null) {
            fg = false;
        }

        if (fg) {
            try {

                st = con.createStatement();

               // String query = "select pat_sl as sl,fnc_patientname(reg_no) patname from op_appointment where doctor_no='"+consultentA+"' and trunc(appoint_date)=trunc(sysdate) and rownum <3";
  String query = "select pat_sl,fnc_patientname(reg_no) patname from op_appointment where doctor_no='"+consultentA+"' and trunc(appoint_date)=trunc(sysdate) and rownum <3";

                System.out.println(query);

                rs = st.executeQuery(query);
               
               
 //String queryTr ="select doc_chember,specialization_no,doctor_name,designation from hpms_doctor where specialization_no='"+speciality_idA+"'";               
               

                while (rs.next()) {

                    ReasonAppPatientInfo reasonAppPatientInfo = new ReasonAppPatientInfo();                   
                    reasonAppPatientInfo.setPAT_SL(rs.getString("pat_sl"));
                    reasonAppPatientInfo.setPAT_NAME(rs.getString("patname"));                   
                    patientTrackList.add(reasonAppPatientInfo);
                   
                }
               
                // String queryTr ="select doc_chember,specialization_no,doctor_name,designation from hpms_doctor where specialization_no='"+speciality_idA+"'";               
                 String queryTr ="select doc_chember,specialization_no,doctor_name,designation from hpms_doctor where doctor_no='"+consultentA+"'";               

                   System.out.println(queryTr);
                   ResultSet rs1= st.executeQuery(queryTr);
               
                   while (rs1.next()) {

                    ReasonAppPatientInfo reasonAppPatientInfo = new ReasonAppPatientInfo();       
                    reasonAppPatientInfo.setDOC_CHEMBER(rs1.getString("doc_chember"));
                    reasonAppPatientInfo.setDOCTOR_NAME(rs1.getString("doctor_name"));
                    reasonAppPatientInfo.setDesignation(rs1.getString("designation"));
                    patientTrackList.add(reasonAppPatientInfo);
                   
                }

            } catch (SQLException sq) {
                sq.printStackTrace();
            } finally {
                try {
                    if (rs != null) {
                        rs.close();
                    }

                    con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        }

        return patientTrackList;
    }
    */
   
    //By owares
    public List trackMain(){   
        List<ReasonAppPatientInfo> patientTrackList = new ArrayList<ReasonAppPatientInfo>();
        //List<ReasonAppPatientInfo> patientTrackList1 = new ArrayList<ReasonAppPatientInfo>();
        boolean fg = true;
        con = dbc.connectDB();

        if (con == null) {
            fg = false;
        }

        if (fg) {
            try {

                st = con.createStatement();

               // String query = "select pat_sl as sl,fnc_patientname(reg_no) patname from op_appointment where doctor_no='"+consultentA+"' and trunc(appoint_date)=trunc(sysdate) and rownum <3";
  //String query = "select pat_sl,fnc_patientname(reg_no) patname from op_appointment where doctor_no='"+consultentA+"' and trunc(appoint_date)=trunc(sysdate)";
               
               
                // String queryTr ="select doc_chember,specialization_no,doctor_name,designation from hpms_doctor where specialization_no='"+speciality_idA+"'";               
                String queryTr ="select doc_chember ,count(APPOINT_NO) as APPOINT_NO from OP_APPOINTMENT where trunc(appoint_date)=trunc(sysdate)group by doc_chember";               

                   System.out.println(queryTr);
                   ResultSet rs1= st.executeQuery(queryTr);
                String chemberN="";
                Integer totalPatient=null;
                   while (rs1.next()) {

                    ReasonAppPatientInfo reasonAppPatientInfo = new ReasonAppPatientInfo();       
                   
                    chemberN=rs1.getString("doc_chember");
                    totalPatient=rs1.getInt("APPOINT_NO");
                    reasonAppPatientInfo.setDOC_CHEMBER(chemberN);
                    reasonAppPatientInfo.setNumber_of_patient(totalPatient);
                    //reasonAppPatientInfo.setNumber_of_patient(rs1.getInt("appoint_no"));
                    //reasonAppPatientInfo.setDOCTOR_NAME(rs1.getString("doctor_name"));
                    //reasonAppPatientInfo.setDesignation(rs1.getString("designation"));
                    patientTrackList.add(reasonAppPatientInfo);
                   
                }
                  
                           
                  
            } catch (SQLException sq) {
                sq.printStackTrace();
            } finally {
                try {
                    if (rs != null) {
                        rs.close();
                    }

                    con.close();
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
            }
        }

        return patientTrackList;
    }
   
    // ###### START THIS PORTION JASPER REPORT ####
    public void showReport(String accID) throws JRException, ServletException,
            IOException {
        Connection connection = null;
        HttpServletResponse response = ServletActionContext.getResponse();
        // HttpServletRequest request=ServletActionContext.getRequest();

        String filename = "reportA2Appointment.jasper";// request.getParameter(“filename�);
        String outputFileName = "reportA2Appointment";
        // String reportType = request.getParameter("reportType");
        String reportType = "pdf";
        // String accID=request.getParameter("accNo");

        Map parameters = new HashMap();

        // All the parameter you want to pass to report write below way..
        parameters.put("p_appoint_no", accID);
        // parameters.put(“userFullName�, userFullName);
        // DatabaseConnection db=new DatabaseConnection();
        connection = dbc.connectDB();

        ServletContext context = ServletActionContext.getServletContext();
        String path = context.getRealPath("/");// .getContextPath();

        JasperPrint jasperPrint = JasperFillManager.fillReport(path + "/Jasper"
                + "/" + filename, parameters, connection);
        System.out.println("Report Created");

        OutputStream ouputStream = response.getOutputStream();

        JRExporter exporter = null;

        if ("pdf".equalsIgnoreCase(reportType)) {

            response.setContentType("application/pdf");
            // If you want show the report in the browser then write
            // “inline�
            response.setHeader("Content-disposition", "inline;filename="
                    + outputFileName + "." + reportType);
            // If you want show the report out of the browser as a .pdf format
            // then write “attachment�
            // response.setHeader(“Content-disposition�,
            // “attachment;filename=�+outputFileName+�.�+reportType);
            exporter = new JRPdfExporter();
            exporter
                    .setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,
                    ouputStream);

        } else if ("rtf".equalsIgnoreCase(reportType)) {

            response.setContentType("application/rtf");
            response.setHeader("Content-disposition", "inline;filename="
                    + outputFileName + "." + reportType);
            exporter = new JRRtfExporter();
            exporter
                    .setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,
                    ouputStream);

        } else if ("html".equalsIgnoreCase(reportType)) {

            exporter = new JRHtmlExporter();
            exporter
                    .setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,
                    ouputStream);

        } else if ("xls".equalsIgnoreCase(reportType)) {

            response.setContentType("application/xls");
            response.setHeader("Content-disposition", "inline;filename="
                    + outputFileName + "." + reportType);
            exporter = new JRXlsExporter();
            exporter
                    .setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,
                    ouputStream);

        } else if ("csv".equalsIgnoreCase(reportType)) {

            response.setContentType("application/xls");
            response.setHeader("Content-disposition", "inline;filename="
                    + outputFileName + "." + reportType);
            exporter = new JRCsvExporter();
            exporter
                    .setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            exporter.setParameter(JRExporterParameter.OUTPUT_STREAM,
                    ouputStream);
        }

        try {
            exporter.exportReport();

        } catch (JRException e) {
            throw new ServletException(e);
        } finally {
            if (ouputStream != null) {
                try {
                    ouputStream.close();
                } catch (IOException ex) {
                }
            }
        }
    }

    // ###### END THIS PORTION JASPER REPORT ####
   
      /* public static void main(String agrs[]){
         ReasonAppointmentSql reasonAppointmentSql=new ReasonAppointmentSql();
         //reasonAppointmentSql.getFaqList();

       }*/

   
   

}

No comments:

Post a Comment