<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
    <%@page import="com.csc.library.utility.DHMConvert" %>
    <%@page import="java.util.ArrayList" %>
    <%@page import="java.util.Iterator" %>
    <%@page import="java.util.Vector" %>
    <%@page import="java.util.*" %>
    <%@page import="com.csc.library.report.ReportUDF" %>
    <%@page import="javax.servlet.jsp.jstl.sql.Result" %>
    <%@page import="java.io.FileOutputStream" %>
    <%@page import="java.io.OutputStream" %>
    <%@page import="java.io.ByteArrayOutputStream" %>
    <%@page import="java.net.URLDecoder" %>
    <%@page import="java.text.DecimalFormat" %>
    <%@page import="java.net.URLEncoder" %>
    <%@page import="java.util.HashMap" %>
    <%@page import="java.text.SimpleDateFormat" %>
    <%@page import="java.util.Locale" %>
    <%@page import="java.util.Date" %>
    <%@page import="java.util.GregorianCalendar" %>
    <%@page import="com.csc.library.database.DataSet" %>
    <%@page import="com.csc.library.session.InitialInquiry" %>
    <%@page import="com.csc.library.session.InitialRecord" %>
    <%@page import="com.csc.library.session.DbInquiry" %>
    <%@page import="com.csc.library.session.DbRecord" %>
    <%@page import="com.csc.library.entry.HelpEntry" %>
    <%@page import="com.itextpdf.text.*" %>
    <%@page import="com.itextpdf.text.pdf.*" %>
    <%@page import="java.io.ByteArrayOutputStream" %>
    <%@page import="com.csc.library.session.InitialEnvironment" %>
    <%@page import="java.io.File" %>
    <%@page import="org.json.JSONArray" %>
    <%@page import="org.json.JSONObject" %>
    <%@page import="com.csc.library.utilities.*" %>
    <%@ page import="com.csc.library.databean.Simmapplicantwithgson" %>
    <%@ page import="com.csc.library.database.MyHashMap" %>
    <%@ page import="com.csc.library.utilities.gsonmapping.*" %>
    <%-- AddFor Make Chart --%>
    <%@ page import="java.awt.Color" %>
    <%@ page import="java.awt.BasicStroke" %>
    <%@ page import="java.text.NumberFormat" %>
    <%@ page import="java.awt.image.BufferedImage" %>
    <%@ page import="javax.swing.JFrame" %>
    <%@ page import="org.jfree.chart.axis.NumberAxis" %>
    <%@ page import="org.jfree.chart.JFreeChart" %>
    <%@ page import="org.jfree.chart.ChartPanel" %>
    <%@ page import="org.jfree.chart.ChartFactory" %>
    <%@ page import="org.jfree.chart.axis.TickUnitSource" %>
    <%@ page import="org.jfree.chart.labels.StandardCategoryItemLabelGenerator" %>
    <%@ page import="org.jfree.chart.labels.StandardXYItemLabelGenerator" %>
    <%@ page import="org.jfree.chart.labels.CategoryItemLabelGenerator" %>
    <%@ page import="org.jfree.chart.labels.XYItemLabelGenerator" %>
    <%@ page import="org.jfree.chart.plot.XYPlot" %>
    <%@ page import="org.jfree.chart.plot.CategoryPlot" %>
    <%@ page import="org.jfree.chart.plot.PlotOrientation" %>
    <%@ page import="org.jfree.chart.renderer.xy.XYLineAndShapeRenderer" %>
    <%@ page import="org.jfree.chart.renderer.category.LineAndShapeRenderer" %>
    <%@ page import="org.jfree.ui.TextAnchor" %>
    <%@ page import="org.jfree.ui.ApplicationFrame" %>
    <%@ page import="org.jfree.ui.RefineryUtilities" %>
    <%@ page import="org.jfree.ui.RectangleInsets" %>
    <%@ page import="org.jfree.data.xy.DefaultXYDataset" %>
    <%@ page import="org.jfree.data.category.DefaultCategoryDataset" %>
    <%@ page import="org.jfree.data.xy.XYDataset" %>
    <%@ page import="org.jfree.data.xy.XYSeries" %>
    <%@ page import="org.jfree.data.xy.XYSeriesCollection" %> 
    <%@ page import="org.jfree.chart.renderer.xy.AbstractXYItemRenderer" %>
    <%@ page import="org.jfree.chart.renderer.category.StatisticalLineAndShapeRenderer" %>
    <%@ page import="org.jfree.data.statistics.DefaultStatisticalCategoryDataset" %>
    <%@ page import="javax.swing.JPanel" %>

    <jsp:useBean id="ApplicantTest_ITALTHAI" class="com.csc.library.system.Task" scope="page"/>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8"/>
    <title>Report</title>
    </head>
    <body>
  
    <%
    ApplicantTest_ITALTHAI.setChannel(request, response);
    HelpEntry screen = (HelpEntry) ApplicantTest_ITALTHAI.process("HelpEntry", "MAPPLICANTHELP");
    CheckNull chk = new CheckNull();

    String filter = "APPLICANTID = '" + chk.chkNullString(request.getParameter("appid")) + "'";
    //    filter = "1=2";

    screen.setMaxLine(1);
    screen.inq.setFilter(filter);
    screen.process();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();//72
    Document document = new Document(PageSize.A4, 25, 25, 20, 0);// Left,Right,Top,Down
    PdfWriter writer = null;
    float[] sizeColumn = new float[]{};
    writer = PdfWriter.getInstance(document, baos);

    document.open();
    document.addTitle("Document Title");
    
    // Setting Fonts
    BaseFont bfWithFontAWesome = BaseFont.createFont(application.getRealPath("fonts/FontAwesome.otf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    BaseFont bf = BaseFont.createFont(application.getRealPath("fonts/Cordia.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    BaseFont bfHead = BaseFont.createFont(application.getRealPath("fonts/Cordia.ttf"), BaseFont.IDENTITY_H, BaseFont.EMBEDDED, true);
    Font font = new Font(bf, 11);
    Font fontTopic = new Font(bfHead, 13);  
    Font fontHead = new Font(bfHead, 13, Font.BOLD);
    Font fontHeadWhiteColor = new Font(bfHead, 12, Font.BOLD, new BaseColor(255, 255, 255));
    fontHead.setStyle(Font.BOLD);
    Font fontContent = new Font(bfHead, 10);
    Font fontContent01 = new Font(bfHead, 9);
    Font fontBoldContent = new Font(bfHead, 11, Font.BOLD);
    Font fontTitle = new Font(bfHead, 20, Font.BOLD);
    fontTitle.setStyle(Font.BOLD);
    Font fontAwesome = new Font(bfWithFontAWesome, 10);
    //setfonts
    Font font_C18B = new Font(bfHead, 18, Font.BOLD);
    Font font_C16B = new Font(bfHead, 16, Font.BOLD);
    Font font_C13B = new Font(bfHead, 13,Font.BOLD);
    Font font_C13N = new Font(bfHead, 13);
    Font font_C12B = new Font(bfHead, 12,Font.BOLD);
    Font font_C12N = new Font(bfHead, 12);
    Font font_C10N = new Font(bfHead, 10);
    Font font_C08N = new Font(bfHead, 8);
    Font linebreak = new Font(bfHead, 1);
    // set vlign middle
    String[] text2 = new String[2];
    Phrase content = new Phrase(new Chunk("",linebreak));
    Float fontSize = content.getFont().getSize();
    Float capHeight = content.getFont().getBaseFont().getFontDescriptor(BaseFont.CAPHEIGHT, fontSize);

    boolean hasData = false;
    if (screen.getInquiry().recCount() > 0) {
      hasData = true;
      screen.nextRec();
      screen.referLangOn();
      DbInquiry dbinq = null;
      int i = 0;
      
      Simmapplicantwithgson simmapplicantwithgson = (Simmapplicantwithgson) screen.inq.getCurrentDbRecord();
    //----------------------------SETDATA Jobrouter ------------------------------------
      MyHashMap hashmap_jobrouter = new MyHashMap();
      int roundAnswer = 0;
 //    int roundID = 0;
      int roundLoop = 0;
      int jobexpkey =0 ;
      for ( jobexpkey = 0; jobexpkey < 40; jobexpkey++){
        hashmap_jobrouter.put("answer" + jobexpkey , "");
        hashmap_jobrouter.put("id" + jobexpkey , "");
        hashmap_jobrouter.put("value" + jobexpkey , "");
      }

      for (MapplicantJobrouter.JobRouter jobrouter : simmapplicantwithgson.mapplicantJobrouter.jobrouter){
        if(jobrouter.question != null){
          for (MapplicantJobrouter.JobRouter.Question question : jobrouter.question){

            hashmap_jobrouter.put("answer" + roundAnswer, question.ansgroup.answer);  
            if(question.ansgroup.choice != null){
              for (MapplicantJobrouter.JobRouter.Question.AnsGroup.Choice choice : question.ansgroup.choice){
                hashmap_jobrouter.put("id"+roundAnswer + roundLoop ,choice.id);
                hashmap_jobrouter.put("value"+roundAnswer + roundLoop, choice.value);
           //     roundID++; //start 0-39
                roundLoop++; //start 0-3 then loop 39 time
                  if(roundLoop == 4){
                    roundLoop = 0;
                  }
                }  
            }
            roundAnswer++;
          }
        }
      }
  //----------------------------Calulate JobRouter 40 Choice ----------------------------------------
      String DataValue[] = new String[40];
      String ChkValue[] = new String[40];
      int countchoice = 0;
      for(int countNum=0;countNum < 40;countNum++){
        for(int number=0;number < 4;number++){
     //  detail.addCell(getCellData(chk.chkNullString( " id"+hashmap_jobrouter.get("id"+countNum+number).toString(),"xx")+" / va "+chk.chkNullString(hashmap_jobrouter.get("value"+countNum+number).toString(),"xx"), font_C12N, "", "LEFT", "BOTTOM", 1, 1));
          if((hashmap_jobrouter.get("answer"+countNum).toString()).equals(hashmap_jobrouter.get("id"+countNum+number).toString())){
              DataValue[countNum] = hashmap_jobrouter.get("value"+countNum+number).toString();
            }     
            else if((hashmap_jobrouter.get("answer"+countNum).toString()).equals("-1")){
              //ให้มีเพื่อป้องกันไม่ให้เกิด Bug
            DataValue[countNum] = hashmap_jobrouter.get("value"+countNum+number).toString();
            }
          }
      }   
      for(int countNum = 0;countNum < 40;countNum++){
        if(DataValue[countNum].equals("1"))
          { hashmap_jobrouter.putToSum("D",1);}
        else if(DataValue[countNum].equals("2"))
          { hashmap_jobrouter.putToSum("I",1);}
        else if(DataValue[countNum].equals("3"))
          { hashmap_jobrouter.putToSum("S",1);}
        else if(DataValue[countNum].equals("4"))
          { hashmap_jobrouter.putToSum("C",1);}
          else if(DataValue[countNum].equals("-1"))
          {
            hashmap_jobrouter.putToSum("D",0);
            hashmap_jobrouter.putToSum("I",0);
            hashmap_jobrouter.putToSum("S",0);
            hashmap_jobrouter.putToSum("C",0);
          }
      }
      // Add Value Use for Chart
      int DValue = Integer.valueOf(hashmap_jobrouter.get("D").toString());
      int IValue = Integer.valueOf(hashmap_jobrouter.get("I").toString());
      int SValue = Integer.valueOf(hashmap_jobrouter.get("S").toString());
      int KValue = Integer.valueOf(hashmap_jobrouter.get("C").toString());

      //----- Start Chk data answer == "-1" if data = -1 set ALL VALUES IS 0 -----
      for(int countNum = 0;countNum < 40;countNum++){
          ChkValue[countNum] = hashmap_jobrouter.get("answer"+countNum).toString();
      }
      for(int countNum = 0;countNum < 40;countNum++){
        if(ChkValue[countNum].equalsIgnoreCase("-1")){
          DValue = 0;
          IValue = 0;
          SValue = 0;
          KValue = 0;
        }
      }
      //----- End Chk data answer == "-1" if data = -1 set ALL VALUES IS 0 -----
    //----------------------------END Calulate JobRouter 40 Choice ----------------------------------------

    //----------------------------End Jobrouter ----------------------------------------
    try {
      CscCalendar calendar = new CscCalendar();
      GregorianCalendar gc = new GregorianCalendar();
      boolean langthai = screen.getUProfile().get("lang").equalsIgnoreCase("THA");
      String reportname = "", printdate = "", printby = "", refer = "RTA2007";
      String reportname_label = "", printdate_label = "", prdate = "", refer_label = "";
      if (langthai) {
      reportname_label = "รายงาน :";
      reportname = "รายงานข้อมูลพนักงาน";
      printdate_label = "วันที่พิมพ์ :";
      prdate = calendar.getDDMMYYYY();
      printdate = "วัน" + calendar.getLongThiDOW() + "ที่ " + calendar.getDate() + " " + calendar.getThaiLongMonth() + " พ.ศ. " + calendar.getThaiYYYY() + " " + calendar.getHHMM() + " น.";
      printby = screen.getUProfile().get("tfullname");
      refer_label = "อ้างอิง #";
      } else {
      reportname_label = "Report Name :";
      reportname = "Personal Report";
      printdate_label = "Print Date :";
      printby = screen.getUProfile().get("efullname");
      refer_label = "Ref #";
    }
    // --------------- new line -----------------
      sizeColumn = new float[]{100.0f};
      PdfPTable detail = new PdfPTable(1);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(1.0f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);

      String Fname = simmapplicantwithgson.mapplicantPersonal.fname.tha;
      String Lname = simmapplicantwithgson.mapplicantPersonal.lname.tha;
      String prefixid  = simmapplicantwithgson.mapplicantPersonal.prefixid;
      String prefixid2  = "";
      DbInquiry DBprefix = new InitialInquiry(screen.getUProfile()).getDbInquiry("mprefix");
      DBprefix.setFilter("prefixid = '" + prefixid + "'");
      DBprefix.refresh();
      while (DBprefix.next()) {
        prefixid2 = DBprefix.getString("tdesc");
      }

      detail.addCell(getCellData("ผลการทดสอบบุคลิกภาพ DISC", font_C18B, "NO", "CENTER", "MIDDLE", 1, 1));
      detail.addCell(getCellData(prefixid2 +" "+Fname+"  "+Lname, font_C18B, "NO", "CENTER", "MIDDLE", 1, 1));
      setPaddingBottom(0.5f);
      detail.addCell(getCellData(" ", linebreak, "NO", "CENTER", "MIDDLE", 1, 1));
      document.add(detail);

    // --------------- new line -----------------
      sizeColumn = new float[]{100.0f};
      detail = new PdfPTable(1);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      PdfPCell cellDetail;
      setPaddingTop(2.0f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(3.5f);
      //Make a Chart
      int width = 425;
      int height = 200;
      Image img = null;
/*// USE FOR createXYLineChart
      XYDataset dataset = createDataset();
      JFreeChart Jchart = createChart(dataset);
 */
      JFreeChart Jchart = generateBarChart(DValue,IValue,SValue,KValue);
      Jchart.setBackgroundPaint(Color.WHITE);
       //  Jchart.setVisible(true);
      BufferedImage bufferedImage = Jchart.createBufferedImage(width, height);
      Image image = Image.getInstance(writer, bufferedImage, 1.0f);
      image.setAlignment(Element.ALIGN_CENTER);
      document.add(image);
   
      // --------------- new line -----------------
          sizeColumn = new float[] {25.0f,25.0f,25.0f,25.0f}; 
          detail = new PdfPTable(4);
          detail.setWidthPercentage(100);
          detail.setWidths(sizeColumn);
          setPaddingTop(0.5f);
          setPaddingLeft(3.5f);
          setPaddingRight(3.5f);
          setPaddingBottom(0.5f);
      // Loop  check  answer
 /*     for(int countNum=0;countNum < 40;countNum++){
      detail.addCell(getCellData(hashmap_jobrouter.get("answer"+countNum).toString(), font_C10N, "", "LEFT", "BOTTOM", 1, 1));
      }
          detail.addCell(getCellData("======", font_C12N, "", "CENTER", "BOTTOM", 4, 1));

      for(int countNum=0;countNum < 40;countNum++){
          detail.addCell(getCellData(DataValue[countNum], font_C12N, "", "CENTER", "BOTTOM", 1, 1));
      }
 */     document.add(detail);
    // new Line-----------------------------------------------------------------------------
      sizeColumn = new float[] {25.0f,75.0f};
      detail = new PdfPTable(2);
      detail.setWidthPercentage(100);
      detail.setWidths(sizeColumn);
      setPaddingTop(0.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(0.5f);

      
       //Check Score in Style Table//
     /*   detail.addCell(getCellData("D", font_C12N, "", "CENTER", "BOTTOM", 1, 1));
        detail.addCell(getCellData(hashmap_jobrouter.get("D").toString(), font_C12N, "", "CENTER", "BOTTOM", 1, 1));
        detail.addCell(getCellData("I", font_C12N, "", "CENTER", "BOTTOM", 1, 1));
        detail.addCell(getCellData(hashmap_jobrouter.get("I").toString(), font_C12N, "", "CENTER", "BOTTOM", 1, 1));
        detail.addCell(getCellData("S", font_C12N, "", "CENTER", "BOTTOM", 1, 1));
        detail.addCell(getCellData(hashmap_jobrouter.get("S").toString(), font_C12N, "", "CENTER", "BOTTOM", 1, 1));
        detail.addCell(getCellData("C", font_C12N, "", "CENTER", "BOTTOM", 1, 1));
     */   detail.addCell(getCellData(hashmap_jobrouter.get("C").toString(), font_C12N, "", "CENTER", "BOTTOM", 1, 1));
       document.add(detail);
    
      // new Line-----------------------------------------------------------------------------
      sizeColumn = new float[] {25.0f,75.0f};
      detail = new PdfPTable(2);
      detail.setWidthPercentage(77);
      detail.setWidths(sizeColumn);
      setPaddingTop(0.5f);
      setPaddingLeft(3.5f);
      setPaddingRight(3.5f);
      setPaddingBottom(2.5f);

      detail.addCell(getCellData("ประเภท", font_C16B, "", "CENTER", "BOTTOM", 1, 1, true));
      detail.addCell(getCellData("บุคลิกลักษณะ", font_C16B, "", "CENTER", "BOTTOM", 1, 1, true));
      setPaddingBottom(0.5f);
      detail.addCell(getCellData("D", font_C18B, "", "CENTER", "MIDDLE", 1, 10));
    
      Chunk ChuD = new Chunk("สิ่งที่คนสไตล์ D ชอบ",font_C12N);
      ChuD.setUnderline(0.1f, -2f);
      content = new Phrase();
      content.add(ChuD);
      detail.addCell(getCellData2( content, "R_RIGHT", "LEFT", "MIDDLE",  1,  1) );
      detail.addCell(getCellData("- การทำงานอย่างอิสระและมีอำนาจตัดสินใจในงานที่ได้รับมอบหมาย", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("- มุ่งเน้นผลลัพธ์(Result Oriented) สูง", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("- ชอบงานที่ท้าทาย ชอบเสี่ยง กล้าตัดสินใจ งานหรือกิจกรรมที่จะต้องการคนเข้า", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("  ไปลุยแก้ปัญหาหรือจัดการให้เสร็จในภารกิจเฉพาะที่ต้องการให้เห็นผลเร็ว", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("  หรือมีการแข่งขันสูงและมีเป้าหมาย หรือตัวชี้วัดผลสำเร็จที่ชัดเจน", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      ChuD = new Chunk("สิ่งที่คนสไตล์ D ไม่ชอบ",font_C12N);
      ChuD.setUnderline(0.1f, -2f);
      content = new Phrase();
      content.add(ChuD);
      detail.addCell(getCellData2( content, "R_RIGHT", "LEFT", "MIDDLE",  1,  1) );
      detail.addCell(getCellData("- การรู้สึกไม่ได้รับความไว้วางใจตลอดจนการเข้าไปแทรกแซงสิ่งที่เขาได้", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("  ตัดสินใจสั่งการหรือดำเนินการไปแล้วโดยไม่มีเหตุผลที่สมควร", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      setPaddingBottom(5.5f);
      detail.addCell(getCellData("- การทำงานหรือการตัดสินใจที่ล่าช้า, หลายขั้นตอน", font_C12N, "R_RB", "LEFT", "BOTTOM", 1, 1));
      setPaddingBottom(0.5f);
      detail.addCell(getCellData("I", font_C18B, "", "CENTER", "MIDDLE", 1, 7));

      ChuD = new Chunk("สิ่งที่คนสไตล์ I ชอบ",font_C12N);
      ChuD.setUnderline(0.1f, -2f);
      content = new Phrase();
      content.add(ChuD);
      detail.addCell(getCellData2( content, "R_RIGHT", "LEFT", "MIDDLE",  1,  1) );
      detail.addCell(getCellData("- งานที่ต้องพบปะติดต่อผู้คน", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("- งานที่ได้ใช้ความคิดสร้างสรรค์ หรืองานที่ต้องร่วมกันแก้ไขปัญหา", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      ChuD = new Chunk("สิ่งที่คนสไตล์ I ไม่ชอบ",font_C12N);
      ChuD.setUnderline(0.1f, -2f);
      content = new Phrase();
      content.add(ChuD);
      detail.addCell(getCellData2( content, "R_RIGHT", "LEFT", "MIDDLE",  1,  1) );
      detail.addCell(getCellData("- งานที่ต้องทำเป็นประจำ โดยเฉพาะงานที่ไม่ค่อยได้พบปะกับผู้คน หรือมี", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("  กฎระเบียบมากๆ งานที่ต้องเข้าไปเกี่ยวกับความขัดแย้งของผู้คน", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      setPaddingBottom(5.5f);
      detail.addCell(getCellData("- หลีกเลี่ยงงานที่ใช้รายละเอียด", font_C12N, "R_RB", "LEFT", "BOTTOM", 1, 1));
      setPaddingBottom(0.5f);
      detail.addCell(getCellData("S", font_C18B, "", "CENTER", "MIDDLE", 1, 9));

      ChuD = new Chunk("สิ่งที่คนสไตล์ S ชอบ",font_C12N);
      ChuD.setUnderline(0.1f, -2f);
      content = new Phrase();
      content.add(ChuD);
      detail.addCell(getCellData2( content, "R_RIGHT", "LEFT", "MIDDLE",  1,  1) );
      detail.addCell(getCellData("- งานที่เป็นขั้นเป็นตอนชัดเจน, ชอบให้มีเวลาในการทำงานอย่างไม่เร่งรีบ(เพื่อมี", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("  เวลาในการตัดสินใจอย่างรอบคอบ), ชอบทำอะไรที่ไม่เสี่ยง", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("- ไม่ละเมิดกฎเกณฑ์", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("- เป็นผู้รับฟังที่ดี  ให้ความสำคัญกับสัมพันธภาพ", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      ChuD = new Chunk("สิ่งที่คนสไตล์ S ไม่ชอบ",font_C12N);
      ChuD.setUnderline(0.1f, -2f);
      content = new Phrase();
      content.add(ChuD);
      detail.addCell(getCellData2( content, "R_RIGHT", "LEFT", "MIDDLE",  1,  1) );
      detail.addCell(getCellData("- บรรยากาศของความขัดแย้ง", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("- การบีบบังคับให้ตัดสินใจแบบทันทีทันใด, การลัดขั้นตอน หรือการมีกฎเกณฑ์", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      setPaddingBottom(5.5f);
      detail.addCell(getCellData(" ที่คลุมเครือ", font_C12N, "R_RB", "LEFT", "BOTTOM", 1, 1));
      setPaddingBottom(0.5f);
      detail.addCell(getCellData("C", font_C18B, "", "CENTER", "MIDDLE", 1, 11));

      ChuD = new Chunk("สิ่งที่คนสไตล์ C ชอบ",font_C12N);
      ChuD.setUnderline(0.1f, -2f);
      content = new Phrase();
      content.add(ChuD);
      detail.addCell(getCellData2( content, "R_RIGHT", "LEFT", "MIDDLE",  1,  1) );
      detail.addCell(getCellData("- มีความละเอียดรอบคอบสูง,ชอบความเป็นระเบียบเรียบร้อยรวมถึง", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("  ความถูกต้องของข้อมูลที่เชื่อถือและพิสูจน์ได้", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("- มาตรฐานการทำงานสูง (หรือเรียกว่าเป็นพวก Perfectionism)", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      ChuD = new Chunk("สิ่งที่คนสไตล์ C ไม่ชอบ",font_C12N);
      ChuD.setUnderline(0.1f, -2f);
      content = new Phrase();
      content.add(ChuD);
      detail.addCell(getCellData2( content, "R_RIGHT", "LEFT", "MIDDLE",  1,  1) );
      detail.addCell(getCellData("- ความไม่เป็นระเบียบเรียบร้อย แล้วเป็นสไตล์ที่ชอบรับฟังหรือค้นหาข้อเท็จจริง", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("  จากพยานหลักฐาน(หรือพยานวัตถุ) มากกว่าพยานบุคคล ดังนั้นจะอึดอัดใจ", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("  หากไม่มีข้อมูลรายละเอียดรองรับ  เพราะจะทำให้ตัดสินใจไม่ถูก", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("- ไม่ชอบถูกวิพากษ์วิจารณ์ในตัวบุคคลและผลงาน", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      detail.addCell(getCellData("- ไม่ชอบงานที่ถูกเร่งรัดจนไม่มีเวลาตรวจสอบความถูกต้อง", font_C12N, "R_RIGHT", "LEFT", "BOTTOM", 1, 1));
      setPaddingBottom(5.5f);
      detail.addCell(getCellData("- ไม่ชอบเข้าสังคม ไม่ชอบการเป็นจุดเด่น", font_C12N, "R_RB", "LEFT", "BOTTOM", 1, 1));
      document.add(detail);
      // -----------------------------------------------------------------------------

      } catch (Exception e) {
        e.printStackTrace();
      } finally {
        document.close();
      }
    }
 
    if (hasData) {
      OutputStream os = response.getOutputStream();
    // Create a reader
      PdfReader reader = new PdfReader(baos.toByteArray());
    // Create a stamper
      PdfStamper stamper = new PdfStamper(reader, baos);

    // Close the stamper
      stamper.close();
      reader.close();

      response.setHeader("Expires", "0");
      response.setHeader("Cache-Control", "must-revalidate, post-check=0 , pre-check=0");
      response.setHeader("Pragma", "public");

    // setting the content type
      response.setContentType("application/pdf");
    // the contentlength
      response.setContentLength(baos.size());
    // write ByteArrayOutputStream to the ServletOutputStream

      baos.writeTo(os);

      os.flush();
      os.close(); 
    }
    //PdfWriter.getInstance(document, baos);
    %>

    <%!
    Float padding = 0.0f;
    Float paddingtop = 0.0f;
    Float paddingbottom = 0.0f;
    Float paddingleft = 0.0f;
    Float paddingright = 0.0f;
    BaseColor basecolor = new BaseColor(235, 235, 224);

    private PdfPCell getCellData(String text, Font font, String noborder, String horalign, String veralign, int colspan, int rowspan) {
      return getCellData(text, font, noborder, horalign, veralign, colspan, rowspan, false);
    }
   
    //get call data
    private PdfPCell getCellData(String text, Font font, String noborder, String horalign, String veralign, int colspan, int rowspan, boolean bgcolor) {
      PdfPCell cellDetail = new PdfPCell(new Phrase(text, font));

      if (horalign.equalsIgnoreCase("LEFT")) {
        cellDetail.setHorizontalAlignment(Element.ALIGN_LEFT);
      } else if (horalign.equalsIgnoreCase("CENTER")) {
        cellDetail.setHorizontalAlignment(Element.ALIGN_CENTER);
      } else if (horalign.equalsIgnoreCase("RIGHT")) {
        cellDetail.setHorizontalAlignment(Element.ALIGN_RIGHT);
      }

      if (veralign.equalsIgnoreCase("TOP")) {
        cellDetail.setVerticalAlignment(Element.ALIGN_TOP);
      } else if (veralign.equalsIgnoreCase("MIDDLE")) {
        cellDetail.setVerticalAlignment(Element.ALIGN_MIDDLE);
      } else if (veralign.equalsIgnoreCase("BOTTOM")) {
        cellDetail.setVerticalAlignment(Element.ALIGN_BOTTOM);
      }

      if (padding > 0.0f) {
        cellDetail.setPadding(padding);
      }
      if (paddingtop > 0.0f) {
        cellDetail.setPaddingTop(paddingtop);
      }
      if (paddingbottom > 0.0f) {
        cellDetail.setPaddingBottom(paddingbottom);
      }
      if (paddingleft > 0.0f) {
        cellDetail.setPaddingLeft(paddingleft);
      }
      if (paddingright > 0.0f) {
        cellDetail.setPaddingRight(paddingright);
      }
      if (colspan > 0) {
        cellDetail.setColspan(colspan);
      }
      if (rowspan > 0) {
        cellDetail.setRowspan(rowspan);
      }
      if (noborder.equalsIgnoreCase("NO")) {
        cellDetail.setBorder(Rectangle.NO_BORDER);
      } 
      else if(noborder.equalsIgnoreCase("R_RB")){ 
            cellDetail.setBorder(Rectangle.RIGHT | Rectangle.BOTTOM);
      } 
      else if(noborder.equalsIgnoreCase("R_TB")){ 
            cellDetail.setBorder(Rectangle.TOP | Rectangle.BOTTOM);
      } 
      else if(noborder.equalsIgnoreCase("R_BOTTOM")){ 
            cellDetail.setBorder(Rectangle.BOTTOM);
      }
      else if(noborder.equalsIgnoreCase("R_RIGHT")){ 
            cellDetail.setBorder(Rectangle.RIGHT);
      }
      else{

      }
      if (bgcolor) {
        cellDetail.setBackgroundColor(basecolor);
      } 
      return cellDetail;
    }
    //CellDeatail2 Use For Add Chunk(1row 2 Fonts Or Color)
    private PdfPCell getCellData2(Phrase content, String noborder, String horalign, String veralign, int colspan, int rowspan) {
      return getCellData2(content, noborder, horalign, veralign, colspan, rowspan, false);
    }
    private PdfPCell getCellData2(Phrase content, String noborder, String horalign, String veralign, int colspan, int rowspan, boolean bgcolor) {
        PdfPCell cellDetail2 = new PdfPCell(new Phrase(content));
     
      if (horalign.equalsIgnoreCase("LEFT")) {
        cellDetail2.setHorizontalAlignment(Element.ALIGN_LEFT);
      } else if (horalign.equalsIgnoreCase("CENTER")) {
        cellDetail2.setHorizontalAlignment(Element.ALIGN_CENTER);
      } else if (horalign.equalsIgnoreCase("RIGHT")) {
        cellDetail2.setHorizontalAlignment(Element.ALIGN_RIGHT);
      }

      if (veralign.equalsIgnoreCase("TOP")) {
        cellDetail2.setVerticalAlignment(Element.ALIGN_TOP);
      } else if (veralign.equalsIgnoreCase("MIDDLE")) {
        cellDetail2.setVerticalAlignment(Element.ALIGN_MIDDLE);
      } else if (veralign.equalsIgnoreCase("BOTTOM")) {
        cellDetail2.setVerticalAlignment(Element.ALIGN_BOTTOM);
      }

      if (padding > 0.0f) {
        cellDetail2.setPadding(padding);
      }
      if (paddingtop > 0.0f) {
        cellDetail2.setPaddingTop(paddingtop);
      }
      if (paddingbottom > 0.0f) {
        cellDetail2.setPaddingBottom(paddingbottom);
      }
      if (paddingleft > 0.0f) {
        cellDetail2.setPaddingLeft(paddingleft);
      }
      if (paddingright > 0.0f) {
        cellDetail2.setPaddingRight(paddingright);
      }
      if (colspan > 0) {
        cellDetail2.setColspan(colspan);
      }
      if (rowspan > 0) {
        cellDetail2.setRowspan(rowspan);
      }

      if (noborder.equalsIgnoreCase("NO")) {
        cellDetail2.setBorder(Rectangle.NO_BORDER);
      }
      else if(noborder.equalsIgnoreCase("R_RB")){ 
            cellDetail2.setBorder(Rectangle.RIGHT | Rectangle.BOTTOM);
      } 
      else if(noborder.equalsIgnoreCase("R_BOTTOM")){ 
            cellDetail2.setBorder(Rectangle.BOTTOM);
      }
      else if(noborder.equalsIgnoreCase("R_RIGHT")){ 
            cellDetail2.setBorder(Rectangle.RIGHT);
      }
      else{

      }
      if (bgcolor) {
        cellDetail2.setBackgroundColor(basecolor);
      }
     
      return cellDetail2;
    }
    
    private void setPadding(Float padding) {
      this.padding = padding;
    }

    private void setPaddingTop(Float padding) {
      this.paddingtop = padding;
    }

    private void setPaddingBottom(Float padding) {
      this.paddingbottom = padding;
    }

    private void setPaddingLeft(Float padding) {
      this.paddingleft = padding;
    }

    private void setPaddingRight(Float padding) {
      this.paddingright = padding;
    }

    private void setBaseBackgroundColor(int r, int g, int b) {
      this.basecolor = new BaseColor(r, g, b);
    }
   // Add IMAGE IN PART
    private String getImagePath(String type, String subFolder, String imageFileName, String defaultFile) {
      InitialEnvironment inv = new InitialEnvironment("GLOBAL");
      String path = inv.getValue(type)+subFolder;
      if (!new File(path+imageFileName).exists() || imageFileName.equals("")){
        imageFileName = defaultFile;
      }
      return path+imageFileName;
    }

    public static JFreeChart generateBarChart(int DChart,int IChart,int SChart,int CChart) {
    //	DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
      DefaultCategoryDataset dataSet = new DefaultCategoryDataset();
      dataSet.setValue(DChart, "Score", "D");
      dataSet.setValue(IChart, "Score", "I");
      dataSet.setValue(SChart, "Score", "S");
      dataSet.setValue(CChart, "Score", "C");

      JFreeChart chart = ChartFactory.createLineChart(
          "", // chart title
          "", // domain axis label
          "", // range axis label
      dataSet,  // initial series
      PlotOrientation.VERTICAL, // orientation
      false, // include legend
      true,  // tooltips?
      false);  // URLs? 
     
      CategoryPlot plot = (CategoryPlot) chart.getPlot();
      plot.setBackgroundPaint(Color.white);
      plot.setRangeGridlinePaint(Color.lightGray);
    
      // Range Axis Data Y
      NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
      rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
      rangeAxis.setUpperMargin(0.40);  // setUpperMargin
      rangeAxis.setAutoRangeIncludesZero(false); // setAutoRangeIncludesZero
       
      LineAndShapeRenderer renderer;
      renderer= (LineAndShapeRenderer) plot.getRenderer();
      plot.setRenderer(renderer);
      renderer.setBaseItemLabelsVisible(Boolean.TRUE);
      renderer.setBaseItemLabelGenerator((CategoryItemLabelGenerator) new StandardCategoryItemLabelGenerator());//Set Show Score On line
      renderer.setShapesVisible(true);
      renderer.setDrawOutlines(true);
      renderer.setUseFillPaint(true);
      renderer.setPaint(Color.blue);
      renderer.setFillPaint(Color.blue); 
      renderer.setBaseStroke( new BasicStroke( 3 ) );
      renderer.setSeriesStroke( 0, new BasicStroke( 3 ) );
        
    // renderer.setUseOutlinePaint(true);
      return chart;
	  }
    
///////////////////////////////////////////////////////////////////
/* // HOW TO USE  createXYLineChart
    private static XYDataset createDataset() {
    XYSeries series1 = new XYSeries("First");
    series1.add(1.0, 1.0);
    series1.add(2.0, 4.0);
    series1.add(3.0, 3.0);
    series1.add(4.0, 5.0);
    series1.add(5.0, 5.0);
    series1.add(6.0, 7.0);
    series1.add(7.0, 7.0);
    series1.add(8.0, 8.0);
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series1);
    return dataset;
    }
    private static JFreeChart createChart(XYDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(
    "", // chart title
    "", // x axis label
    "", // y axis label
    dataset, // data
    PlotOrientation.VERTICAL,
    false, // include legend
    true, // tooltips
    false // urls
    );
    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);
    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
XYLineAndShapeRenderer renderer =
            new XYLineAndShapeRenderer(true, true);
        plot.setRenderer(renderer);
        renderer.setShapesVisible(true);
        renderer.setShapesFilled(true);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.
    NumberFormat format = NumberFormat.getNumberInstance();
        format.setMaximumFractionDigits(2);
        XYItemLabelGenerator generator =
        new StandardXYItemLabelGenerator(
        StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT,
        format, format);
        renderer.setBaseItemLabelGenerator(generator);
        renderer.setBaseItemLabelsVisible(true);
    return chart;
    }
*/
    %>
    </body>
    </html>