<%-- 
    Document   : FarmerDetailsUpdation
    Created on : Oct 10, 2018, 2:39:08 PM
    Author     : 1004242
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="java.sql.SQLException"%>
<%@page import="LoginDb.DbHandler"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.util.Date"%>
<%@page import="DataEntryBean.BatchProcessingBean"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.UUID" %>
<%String uuid = UUID.randomUUID().toString();%>
<% try {
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <title>Farmer Details Updation</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script src="${pageContext.request.contextPath}/js/Calendar.js?pacs=<%=((new java.util.Date()).getTime())%>"></script>
        <link rel="stylesheet" type="text/css" href="/PacsApplication/css/TableCSSCode.css?pacs=<%=((new java.util.Date()).getTime())%>" />
        <link rel="shortcut icon" href="${pageContext.request.contextPath}/img/favicon.ico?pacs=<%=((new java.util.Date()).getTime())%>" type="image/x-icon" />

        <meta name="viewport" content="width=device-width, initial-scale=1">
        <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 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>
      

        <script type="text/javascript">
            function noBack()
            {
                window.history.forward();
            }

            function ShowParent()
            {
                document.forms[0].action="${pageContext.request.contextPath}/FarmerDetailsUpdation.jsp";
                document.forms[0].submit();
            }

            function checkboxTrue(i){

                if(document.getElementById("chckbox"+i).checked == true){

                    var counter = $("#chkboxCounter").val();
                    counter++;
                    $("#chkboxCounter").val(counter);

                }
                else{

                    var counter = $("#chkboxCounter").val();
                    counter--;
                    $("#chkboxCounter").val(counter);
                }
            }

            function submitform(farmerForm){

                //alert(document.getElementById("handle_id").value);

                if(validate()){

                        document.farmerForm.action = '/PacsApplication/FarmerDetailsUpdationServlet';
                        document.farmerForm.submit();
                }
            }

            function validate(){
                var counter = $("#rowCounter").val();
                //var i = 1;
                if(document.getElementById("cifNumber").value == "")
                    {
                            alert("CIF No cannot be empty.");
                            document.getElementById("cifNo").focus();
                            //resetRow(i);
                            return false;
                    }
                for(i=1;i<=counter;i++){
                    re = /^(?=.*\d)\d*(?:\.\d*)?$/;

                    try {
                        if (document.getElementById("manja"+i).value == "")
                        {
                            alert("Manja cannot be empty");
                            document.getElementById("manja"+i).value="";
                            document.getElementById("manja"+i).focus();
                            //resetRow(i);
                            return false;
                        }
                        if (document.getElementById("dgNo"+i).value == "")
                        {
                            alert("DG NO.  cannot be empty");
                            document.getElementById("dgNo"+i).value="";
                            document.getElementById("dgNo"+i).focus();
                            //resetRow(i);
                            return false;
                        }


                        if (document.getElementById("GP"+i).value == "")
                        {
                            alert("GP should be filled");
                            document.getElementById("GP"+i).value="";
                            document.getElementById("GP"+i).focus();
                            //resetRow(i);
                            return false;
                        }
                        if ((document.getElementById("village"+i).value.trim()) == "")
                        {
                            alert("village should be filled.");
                            document.getElementById("village"+i).focus();
                            //resetRow(i);
                            return false;
                        }
                        if(document.getElementById("Khatiyan"+i).value=="" )
                            {
                                alert("Khatiyan cant be empty")
                                document.getElementById("Khatiyan"+i).focus;
                                return false;
                            }
                       if (document.getElementById("area"+i).value == 0)
                        {
                            alert("area cant be empty   or ZERO");
                            document.getElementById("area"+i).focus();
                            //resetRow(i);
                            return false;
                        }
                    }
                    catch(err){

                    }
                }
                return true;
            }

          
           function popup_cifDetails(width, height, cifNumber) {
                if (window.innerWidth) {
                    LeftPosition = (window.innerWidth - width) / 2;
                    TopPosition = ((window.innerHeight - height) / 2) - 20;
                }
                else {
                    LeftPosition = (parseInt(window.screen.width) - width) / 2;
                    TopPosition = ((parseInt(window.screen.height) - height) / 2) - 20;
                }
                attr = 'resizable=yes,scrollbars=yes,width=' + width + ',height=' +
                        height + ',screenX=300,screenY=200,left=' + LeftPosition + ',top=' +
                        TopPosition + '';
                var screenName = "farmerDetailsUpdation.jsp";
                var lovKey = "cifSearch"
                popWin = open('CommonSearchInfoLOVNew.jsp?cifNumber=' + cifNumber + '&screenName=' + screenName + '&lovKey=' + lovKey, 'cifSearch', attr);
                popWin.focus();

            }

            function setVisibility(){
                //document.getElementById("searchBatch").style.visibility='visible';
                $('select#batchOption').change();
            }

            function textChanged(){
                document.getElementById("searched").value="0";
                //alert("IN");
            }
            function showInfoDiv()
            {
               document.getElementById("infoDiv").style.display="block";
            }
            
            // to restrict back button
            history.pushState(null, null, location.href);
            window.addEventListener('popstate', function(event) {
                history.pushState(null, null, location.href);
            });

        </script>

        <%
             int count = 1;
             String error_msg = "";

             Object error = request.getAttribute("message");
             if (error != null) {
                 error_msg = error.toString();
             }

        %>


        <%!
            String blankNull(String s) {
                return (s == null) ? "" : s;
            }

        %>
    </head>
    <body  onload="noBack();">

        <jsp:include page="MenuHead.jsp" flush="true" />
        <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">Farmer Details Updation</legend>

            <%if (!error_msg.equalsIgnoreCase("")) {%>
            <center><div class="info" id="errorMessage"><center><%= error_msg%></center></div></center>
            <% }%>
            <br>

            <form action="" method="post" name="farmerForm" id="farmerForm">

                <div id="create" name="create">
                    <br>
                    <center>
                        <table>
                            <tr><td>Enter CIF Number<font color="red" >*</font>:</td><td><input type="text" name="cifNumber" id="cifNumber" style="text-align:right;" onkeypress='return event.charCode >= 48 && event.charCode <= 57'/>
                                    <input type="button" value="Search" id="Search" onclick="javascript:popup_cifDetails(600, 180, document.farmerForm.cifNumber.value);"/></td></tr>
                            <tr><td> <br></td></tr>

                        </table>
                        
                    </center>

                    <div align="center" id="infoDiv" style="display: none">
                        <table id="batchData" name="batchData" border="2" width="auto" cellspacing="1" cellpadding="1" style="text-align: center ;overflow-y: scroll; font-size: 15px">
                            <thead class="CSSTableGenerator">
                                <tr>
                                    <td></td>
                                    <td>Mauja</td>
                                    <td>Daag Number</td>
                                    <td>GP</td>
                                    <td>Village</td>
                                    <td>Khatiyan</td>
                                    <td>Area( in acres.)</td>
                                </tr>
                            </thead>
                            <tbody>
                                <tr class="tRow">
                                    <td><input type="checkbox" name="chckbox<%=count%>" id="chckbox<%=count%>" onclick="checkboxTrue(<%=count%>);" /></td>
                                    <td><input type="text"  style="width: 120px" name="manja<%=count%>" id="manja<%=count%>" /></td>
                                    <td><input type="text"  style="width: 120px" name="dgNo<%=count%>" id="dgNo<%=count%>" /></td>
                                    <td><input type="text" name="GP<%=count%>" id="GP<%=count%>"/></td>
                                    <td><input type="text" name="village<%=count%>" id="village<%=count%>" /></td>
                                    <td><input type="text" name="Khatiyan<%=count%>" id="Khatiyan<%=count%>" /></td>
                                    <td><input type="number" name="area<%=count%>" id="area<%=count%>" /></td>
                                </tr>
                            </tbody>
                        </table>
                        <br><br><br>
                      
                        <center>
                            <table>
                                <tr>
                                    <%--<td ><input type="button" id="addRow" value="Add Row"/></td>
                                    <td><input type="button" id="deleteRow" value="Delete Row"/></td>--%>
                                    <td><input type="button" value="Submit" onclick="javascript:submitform(farmerForm)"></td>
                                    <td><input type="button" value="Reset" onclick="ShowParent();" /></td>
                                </tr>
                            </table>
                        </center>
                    </div>

                    <input type="hidden" name="rowCounterDeleteCreate" id="rowCounterDeleteCreate" value="<%=count%>">
                    <input type="hidden" name="rowCounter" id="rowCounter" value="<%=count%>">
                    <input type="hidden" name="chkboxCounter" id="chkboxCounter" value="0"/>
                    <input type="hidden" name="all_rowsAdded" id="all_rowsAdded" value="1">
                </div>

                <br>
               
                <input type="hidden" name="handle_id" id="handle_id" value="" />
                <input type="hidden" name="searched" id="searched" />
            </form>


            <br><br>

            <script  type="text/javascript">
                var x=1;
                <%--$("#addRow").click(function () {
                    if(!validate()){
                        alert('Please fillup one row at a time');
                    } else {
                        document.getElementById("searched").value="0";
                        x=x+1;
                        $("#all_rowsAdded").val(x);
                        var counter = $("#rowCounter").val();
                        counter++;
                        $('#batchData tr:last').after('<tr class="tRow">    <td><input type="checkbox" name="chckbox' + x + '" id="chckbox' + x + '" onclick="checkboxTrue(' + x + ');" /></td>       <td><input type="text"  style="width: 120px" name="manja' + x + '"  id="manja' + x + '" /></td>         <td><input type="text"  style="width: 120px" name="dgNo' + x + '"  id="dgNo' + x + '"  /></td>    <td><input type="text" name="GP' + x + '" id="GP' + x + '"/></td>   <td><input type="text" name="village' + x + '" id="village' + x + '" /></td> <td><input type="text" name="Khatiyan' + x + '" id="Khatiyan' + x + '" /></td> <td><input type="number" name="area' + x + '" id="area' + x + '" /></td></tr>');

                        $("#rowCounter").val(counter);
                        counter = $("#rowCounterDeleteCreate").val();
                        counter++;
                        $("#rowCounterDeleteCreate").val(counter);
                    }
                });

                
                $( "#deleteRow" ).click(function() {

                    var len = ($("#batchData tr").length)-1;
                    var counter = $("#rowCounterDeleteCreate").val();
                    var chkboxCounter=$("#chkboxCounter").val();
                    var counterDelete=counter-chkboxCounter;
                    if (counterDelete==0){
                        alert("All rows cannot be deleted");
                    }
                    else{
                        if (len == 0) {
                            alert("All rows can not be deleted");
                            return false;
                        }

                        $('input:checkbox:checked').closest('tr').remove();
                        $("#rowCounterDeleteCreate").val(counterDelete);

                        chkboxCounter=0;
                        $("#chkboxCounter").val(chkboxCounter);
                        calcAmt();
                        if(isNaN(document.getElementById("grandTotal").value)){
                            document.getElementById("grandTotal").value = 0;
                        }
                    }

                });--%>

                function resetRow(i) {
                    document.getElementById("accNo"+i).value = "";
                    document.getElementById("txnAmt"+i).value = "";
                    document.getElementById("txnInd"+i).value = "CR";
                }


            </script>
        </fieldset>
    </body>
</html>
<% 	} catch (Exception e) {
                
            }
%>