<%--
    Document   : microFileUploadDownload
    Created on : May 17, 2018, 2:15:10 PM
    Author     : 1004242
--%>
<%@page import="LoginDb.DbHandler"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Handbill File Processing</title>
        <link rel="shortcut icon" href="${pageContext.request.contextPath}/img/favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/TableCSSCode.css" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/styles.css?pacs=<%=((new java.util.Date()).getTime())%>"/>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/ButtonAndText.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/info.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <script src="${pageContext.request.contextPath}/js/Calendar.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="${pageContext.request.contextPath}/jquery-ui-1.10.4.custom/development-bundle/jquery-1.10.2.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="/PacsApplication/chromejs/chrome.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <script type="text/javascript" src="/PacsApplication/js/iFrame_killer.js"></script>
        
    </head>
    <body>
        
        <jsp:include page="MenuHead_Deposit.jsp" flush="true" />
        <%
             String pacsId = (String) session.getAttribute("pacsId");
             
        %>     
        <br>
        <fieldset style="border-color: black; background-image: url('/PacsApplication/img/download.jpg'); border-width: 3px">
            <legend style="padding: 8px; border-radius: 20px; background-color: #006600; color: white">Handbill File Processing</legend>
            <center>
                <div id="SelectDiv">
                    <table>
                        <tr>
                            <td>Select Operation: </td>
                            <td>
                                <select id="FileTypeId" name="FileType" onchange="toggleDiv(1)">
                                    <option value="Def" selected> --Select-- </option>
                                    <option value="Upload" >Upload File</option>
                                    <option value="Download" >Download File</option>
                                </select>
                            </td>
                        </tr>
                    </table>
                </div>
            </center>
            <div id="UploadDiv" style="display:none">
                <form name="MicroFile" id="MicroFileIdUpload" action="" method="post" enctype="multipart/form-data">
                    <center>

                        Select file to upload:
                        <input type="file" name="dataFile" id="fileChooser"/><br/><font color="blue" >*Supported File type: csv</font><br/><br/>
                        <input type="button" value="Upload" id ="FileTypeIdUpload" name="FileType" onclick="sendFileToServer(1)"/>
                        <input type="button" value="Back" id ="BackIdU" name="BackIdUButton" onclick="toggleDiv(3)"/>

                    </center>
                </form>
            </div>

            <div id="DownloadDiv" style="display:none">
                <form name="MicroFile" id="MicroFileIdDownload" action="" method="post" >
                    <center>                     
                        <tr>
                            <td>Select Agent <font color="red" >*</font>:</td><td>
                            <select id="agentId" name="agentId">
                                <option value="" > --Select-- </option>
                                <%
                                        Connection connection = null;
                                        ResultSet rs = null;
                                        Statement statement = null;
                                        connection = DbHandler.getDBConnection();
                                        try {
                                            statement = connection.createStatement();
                                            rs = statement.executeQuery("select agent_id,agent_id || ' : ' || (select login_name from login_details ld where ld.pacs_id = k.pacs_id and ld.login_id = k.agent_id) agent_name from dds_agent_limit k where pacs_id like '%" + pacsId + "%'");
                                            while (rs.next()) {%>
                                            <option value="<%=rs.getString(1)%>" ><%=rs.getString(2)%></option>
                              <%
                                                 }
                                                // statement.close();
                                                // connection.close();
                                             } catch (Exception e) {
                                                System.out.println("Error occurred during processing.");
                                             } finally {
                try {
                    if(statement !=null)
                        statement.close();
                    if (connection != null)
                    connection.close();

            } catch (Exception e) {               
               System.out.println("Error Occurred during connection close.");
            }

            }
                                         %>
                            </select>
                        </td>
                        </tr>
                        <tr><td><br></td></tr>
                        <tr><td><br></td></tr>
                        <tr><td><br></td></tr>
                        <input type="hidden" id="actionId" value="Download" name="actionTag">
                        <input type="button" value="Download" id ="FileTypeIdDownload" name="FileTypeDownload" onclick="sendFileToServer(2)"/>
                        <input type="button" value="Back" id ="BackIdD" name="BackIdDButton" onclick="toggleDiv(2)"/>

                    </center>
                </form>
            </div>
            <div id="errorMessageTag"style="color: #FF0000;">${errorMessage}</div>
        </fieldset>
    </body>
    <script type="text/javascript" src="${pageContext.request.contextPath}/jsController/microFileUploadDownloadController.js"></script>
</html>
