<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true"
    CodeBehind="Conversion_rate.aspx.cs" Inherits="HRMS.GL.Conversion_Rate.Conversion_rate" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:ScriptManager ID="scriptManager" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel runat="server" ID="upMain" UpdateMode="Conditional" ChildrenAsTriggers="true">
        <ContentTemplate>
         <script type="text/javascript">
             function clearTextBox() {
                 var elements = document.getElementsByTagName("input");
                 for (var ii = 0; ii < elements.length; ii++) {
                     if (elements[ii].type == "text") {
                         elements[ii].value = "";

                     }
                     document.getElementById('<%=hid_rate.ClientID %>').value = "";
                 }
             }
    </script>


            <div class="main-panel">
                <div class="row">
                    <div class="col-md-12">
                        <section class="panel">
                    <header class="panel-heading" style="padding-bottom:30px">
                           <span class="label label-primary">Conversion Rate</span>
                    
                        <div class="pull-right">
                            <asp:button text="Save" CssClass="btn btn-info" Width="100px" ID="btn_save" runat="server"  ValidationGroup="save"
                                onclick="btn_save_Click" />
                            <asp:button text="Back" CssClass="btn btn-info" ID="btn_cancel" 
                                runat="server" onclick="btn_cancel_Click" Visible="false" />

                                 <input type="button" value="Clear" class="btn btn-info" onclick="clearTextBox()" />
                        </div>
                    </header>
                    <div class="panel-body">
                         <div class="span6">
                                <div id="divmessage" runat="server" visible="false" class="alert alert-info alert-dismissable">
                                    <asp:label text="" ID="lbl_msg" CssClass="msg" runat="server"></asp:label>
                                </div>
                            </div>

                            <div class="span6">
                                <div id="diverrmessage" runat="server" visible="false" class="alert alert-info alert-dismissable">
                                    <asp:label text="" id="lbl_err_msg" CssClass="msg" runat="server"></asp:label>
                                </div>
                            </div>

                            <div class="row">
                                <label class="control-label col-md-2" runat="server">From Currency</label>
                                <div class="col-md-2">
                                    <asp:HiddenField runat="server" ID="hid_rate" />
                                    <asp:DropDownList CssClass="form-control select2" ID="ddl_from" onchange="return GetSelectedTextValue()"
                                        runat="server"></asp:DropDownList>
                                    <%--<asp:TextBox CssClass="form-control" ID="txt_from" runat="server" 
                                        ontextchanged="txt_from_TextChanged1" AutoPostBack="true"></asp:TextBox>--%>
                                    <%--<asp:RequiredFieldValidator SetFocusOnError="true" ValidationGroup="save" runat="server" id="req_from" controltovalidate="txt_from" errormessage="From Currency Required!" />--%>
                                </div>

                                 <label id="Label1" class="control-label col-md-2" runat="server">To Currency</label>
                                <div class="col-md-2">
                                <asp:DropDownList CssClass="form-control select2" ID="ddl_to" runat="server" onchange="return GetSelectedTextValue()"></asp:DropDownList>
                                   <%-- <asp:TextBox CssClass="form-control" ID="txt_to" runat="server" 
                                        ontextchanged="txt_to_TextChanged" AutoPostBack="true"></asp:TextBox>--%>
                                    <%--<asp:RequiredFieldValidator SetFocusOnError="true" ValidationGroup="save" runat="server" id="req_to" controltovalidate="txt_to" errormessage="To Currency Required!" />--%>
                                </div>

                                <label id="Label3" class="control-label col-md-1" runat="server">Type</label>
                                <div class="col-md-2">
                                <asp:DropDownList CssClass="form-control select2" ID="ddl_type" runat="server"></asp:DropDownList>
                                </div>

                            </div>

                            <div class="row" style="padding-top:10px">
                               <label id="lbl_frm" class="control-label col-md-2" runat="server"></label>
                                <div class="col-md-2">
                                    <asp:TextBox CssClass="form-control" ID="txt_show_convo_rate" runat="server"  onchange="calculate()"></asp:TextBox>
                                    <asp:RequiredFieldValidator SetFocusOnError="true" ValidationGroup="save" runat="server" id="req_show_convo_rate" controltovalidate="txt_show_convo_rate" errormessage="Conversion Rate Required!" />
                                </div>

                                 <label id="lbl_to" class="control-label col-md-2" runat="server"></label>
                                <div class="col-md-2">
                                    <asp:TextBox CssClass="form-control" ID="txt_show_inv_convo_rate" runat="server" ></asp:TextBox>
                                    <asp:RequiredFieldValidator SetFocusOnError="true" ValidationGroup="save" runat="server" id="req_show_inv_convo_rate" controltovalidate="txt_show_inv_convo_rate" errormessage="Conversion Rate Required!" />

                                </div>
                            </div>

                            <div class="row" style="padding-top:10px"   >
                                  <label id="Label2" class="control-label col-md-2" runat="server">From Date</label>
                                <div class="col-md-2">
                                    <asp:TextBox CssClass="form-control form_datetime" ID="txt_from_date" runat="server"></asp:TextBox>
                                </div>

                                <label id="Label4" class="control-label col-md-2" runat="server">To Date</label>
                                <div class="col-md-2">
                                    <asp:TextBox CssClass="form-control form_datetime" ID="txt_to_date" runat="server"></asp:TextBox>
                                </div>
                            </div>

                            <br />

                             <button id="btn_popup" type="button" data-target="#conv_rate" data-toggle="modal" runat="server" class="btn btn-white col-md-offset-10">Entry By Date Range</button>


                             <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" 
                             CssClass="display" CellPadding="0" Border="0" 
                             onrowcommand="GridView1_RowCommand">
                            <Columns>
                                <asp:BoundField DataField="Conversion_rate_id" HeaderText="ID" />
                                <asp:BoundField DataField="FROM_CURRENCY" HeaderText="From" />
                                <asp:BoundField DataField="TO_CURRENCY" HeaderText="To" />
                                <asp:BoundField DataField="CONVERSION_DATE" HeaderText="Date" />
                                <asp:BoundField DataField="CONVERSION_TYPE" HeaderText="Type ID" />
                                <asp:BoundField DataField="user_conversion_type" HeaderText="Type" />
                                
                                <asp:BoundField DataField="show_inverse_conversion_rate" HeaderText="From" />
                                <asp:BoundField DataField="show_conversion_rate" HeaderText="To" />

                                    <asp:TemplateField HeaderText="Action" ItemStyle-Width="6%">
                                        <ItemTemplate>
                                            <asp:LinkButton ID="linkedit" CausesValidation="false" runat="server" CommandName="gEdit"><i class="fa fa-pencil" style="font-size:20px !important"></i></asp:LinkButton>
                                            <asp:LinkButton ID="linkdelete" CausesValidation="false" runat="server" OnClientClick="return confirm('Are you sure to delete?')" CommandName="gDelete" Visible="false"><i class="fa fa-trash" style="font-size:20px !important"></i></asp:LinkButton>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                            </Columns>
                                 <FooterStyle CssClass="footerStyle" />
                                 <HeaderStyle CssClass="headerStyle" />
                                 <RowStyle CssClass="rowStyle" />
                        </asp:GridView>
                         <script src="/ThemeScrips/Datatables/media/js/jquery.js" type="text/javascript"></script>
                             <script src="/ThemeScrips/Datatables/media/js/jquery.datatables.min.js" type="text/javascript"></script>
                             <script src="/ThemeScrips/Datatables/media/js/jquery.Datatables.js" type="text/javascript"></script>
                             <script src="/ThemeScrips/Datatables/media/js/GridviewFix.js" type="text/javascript"></script>
                             <script type="text/javascript">
                                 $("#ContentPlaceHolder1_GridView1").GridviewFix().dataTable();
                            </script>

                           
                             <div class="modal fade" id="conv_rate" role="dialog">
                               <div class="modal-dialog modal-dialog-center" >
                                <div class="modal-content">
                                  <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                                    <h4 class="modal-title">Conversion Rate By Date Range:</h4>
                                  </div>
                                  <div class="modal-body">
                                       <div class="row">
                                        <label id="Label6" class="control-label col-md-3" runat="server">From</label>
                                            <div class="col-md-3">
                                                <asp:DropDownList Width="120px" CssClass="form-control select2" ID="ddl_d_frm" onchange="return GetSelectedTextValue_InPopUp()"
                                        runat="server"></asp:DropDownList>
                                            </div>

                                        <label id="Label7" class="control-label col-md-3" runat="server">To</label>
                                            <div class="col-md-3">
                                                <asp:DropDownList Width="120px" CssClass="form-control select2" ID="ddl_d_to" onchange="return GetSelectedTextValue_InPopUp()"
                                        runat="server"></asp:DropDownList>
                                            </div>
                                        </div>

                                        <div class="row" style="padding-top:10px">
                                             <label id="lbl_d_frm" class="control-label col-md-3" runat="server"></label>
                                                <div class="col-md-3">
                                                    <asp:TextBox CssClass="form-control" ID="txt_d_frm" runat="server" onchange="calculate_In_PopUp()"></asp:TextBox>
                                                </div>

                                             <label id="lbl_d_to" class="control-label col-md-3" runat="server"></label>
                                                <div class="col-md-3">
                                                    <asp:TextBox CssClass="form-control" ID="txt_d_to" runat="server" onchange="calculate_In_PopUp()"></asp:TextBox>
                                                </div>
                                         </div>


                                          <div class="row" style="padding-top:10px">
                                             <label id="Label8" class="control-label col-md-3" runat="server">From Date</label>
                                                <div class="col-md-3">
                                                    <asp:TextBox CssClass="form-control form_datetime" ID="txt_d_frmdate" runat="server"></asp:TextBox>
                                                </div>

                                             <label id="Label9" class="control-label col-md-3" runat="server">To Date</label>
                                                <div class="col-md-3">
                                                    <asp:TextBox CssClass="form-control form_datetime" ID="txt_d_todate" runat="server"></asp:TextBox>
                                                </div>
                                         </div>

                                         <div class="row" style="padding-top:10px">
                                             <label id="Label10" class="control-label col-md-3" runat="server">Type</label>
                                                <div class="col-md-3">
                                                 <asp:DropDownList CssClass="form-control" ID="ddl_d_type" runat="server"></asp:DropDownList>
                                                </div>
                                         </div>


                                          
                                </div>

                                  <div class="modal-footer">
                                  <asp:Button ID="btn_save_datewise" runat="server" CssClass="btn btn-default" Text="Save & Close" OnClick="btn_save_datewise_Click"></asp:Button>
                                  </div>
                               </div>
                            </div>
                    </div>
                </section>
                    </div>
                </div>
            </div>
            </div>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="RowCommand" />
        </Triggers>
    </asp:UpdatePanel>

            <%--Get Text From Dropdown to Label in Form--%>
            <script type="text/javascript">
                function GetSelectedTextValue() {

                    var ddl_frm = document.getElementById("<%=ddl_from.ClientID %>");
                    var ddl_to = document.getElementById("<%=ddl_to.ClientID %>");
                    var selectedText_frm = ddl_frm.options[ddl_frm.selectedIndex].innerHTML;
                    var selectedText_to = ddl_to.options[ddl_to.selectedIndex].innerHTML;
                    var label_frm = document.getElementById("<%=lbl_frm.ClientID %>");
                    var label_to = document.getElementById("<%=lbl_to.ClientID %>");
                    if (selectedText_frm != '') {
                        label_frm.innerHTML = selectedText_frm;
                    }

                    if (selectedText_to != '---- Select ----') {
                        label_frm.innerHTML = selectedText_frm + " to " + selectedText_to;
                        label_to.innerHTML = selectedText_to + " to " + selectedText_frm;
                    }

                    return false;
                }
            </script>

       <%--Get Text From Dropdown to Label in PopUp Window--%>
            <script type="text/javascript">
                function GetSelectedTextValue_InPopUp() {

                    var ddl_d_frm = document.getElementById("<%=ddl_d_frm.ClientID %>");
                    var ddl_d_to = document.getElementById("<%=ddl_d_to.ClientID %>");
                    var selectedText_d_frm = ddl_d_frm.options[ddl_d_frm.selectedIndex].innerHTML;
                    var selectedText_d_to = ddl_d_to.options[ddl_d_to.selectedIndex].innerHTML;
                    var label_d_frm = document.getElementById("<%=lbl_d_frm.ClientID %>");
                    var label_d_to = document.getElementById("<%=lbl_d_to.ClientID %>");
                    if (selectedText_d_frm != '') {
                        label_d_frm.innerHTML = selectedText_d_frm;
                    }

                    if (selectedText_d_to != '---- Select ----') {
                        label_d_frm.innerHTML = selectedText_d_frm + " to " + selectedText_d_to;
                        label_d_to.innerHTML = selectedText_d_to + " to " + selectedText_d_frm;
                    }

                    return false;
                }
            </script>

        <%--Conversion Rate in Form--%>
            <script type="text/javascript" language="javascript">
                function calculate() {
                    var first = document.getElementById("<%=txt_show_convo_rate.ClientID %>");
                    //var sec = document.getElementById("<%=txt_show_inv_convo_rate.ClientID %>");
                    var rate = parseFloat(1 / first.value);
                    var round = rate.toFixed(3);
                    document.getElementById("<%=txt_show_inv_convo_rate.ClientID %>").value = round;

                }

            </script>

        <%--Conversion Rate in PopUp Window--%>
        <script type="text/javascript" language="javascript">
            function calculate_In_PopUp() {
                var first_d = document.getElementById("<%=txt_d_frm.ClientID %>");
                //var sec = document.getElementById("<%=txt_show_inv_convo_rate.ClientID %>");
                var rate_d = parseFloat(1 / first_d.value);
                var round_d = rate_d.toFixed(3);
                document.getElementById("<%=txt_d_to.ClientID %>").value = round_d;

            }


            function Comma(Num) { //function to add commas to textboxes
                Num += '';
                Num = Num.replace(',', ''); Num = Num.replace(',', ''); Num = Num.replace(',', '');
                Num = Num.replace(',', ''); Num = Num.replace(',', ''); Num = Num.replace(',', '');
                x = Num.split('.');
                x1 = x[0];
                x2 = x.length > 1 ? '.' + x[1] : '';
                var rgx = /(\d+)(\d{3})/;
                while (rgx.test(x1))
                    x1 = x1.replace(rgx, '$1' + ',' + '$2');
                return x1 + x2;
            }
    

            </script>

            <script src="../../ThemeScrips/jquery.min.js"></script>
    <link href="../../ThemeScrips/select2.min.css" rel="stylesheet" />
    <script src="../../ThemeScrips/select2.min.js"></script>
    <script>
        $('.select2').select2();
    </script>
</asp:Content>
