<%@ Page Title="" Language="C#" MasterPageFile="~/Application.Master" AutoEventWireup="true" CodeBehind="Main.aspx.cs" Inherits="ICDAS_3_0_Web_App.Main" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <script lang="javascript" type="text/jscript">

        function getDetails(id) {

            var RecordId = id.split("_");

            debugger;

            $.ajax({
                method: 'POST',
                url: 'Main.aspx/BindTable',
                contentType: 'application/json;charset=utf-8',
                data: '{RecordId:"' + RecordId[1] + '",BranchId:"' + document.getElementById("<%=hdnBranchId.ClientID%>").value + '"}',
                datatype: 'json',
                success: function (data) {
                    var HtmlContent = "";
                    if (data.d.length > 0) {
                        // alert(data.d);
                        debugger;

                        for (var i = 0; i < data.d.length; i++) {
                            HtmlContent += "<tr><td style = 'width:70px'>" + data.d[i].EqDate + "</td><td style = 'width:70px'>" + data.d[i].EqTime + "</td><td style = 'width:200px'>" + data.d[i].EqDesc + "</td></tr>";
                        }
                        HtmlContent = "<tr><th class=\"active\" scope=\"col\" style = 'width:70px'>Log Date</th><th class=\"active\" scope=\"col\" style = 'width:70px'>Log Time</th><th class=\"active\" scope=\"col\" style = 'width:200px'>Alarm Desc.</th></tr>" + HtmlContent;

                        document.getElementById("<%=headEquipmentName.ClientID%>").innerHTML = data.d[0].EqName + " - Alarm Details (Total Alarms: " + data.d.length + ")";

                        $("#dvAlarm").show();
                        $("table").html(HtmlContent);
                        $("#myModal").modal("show");
                    }
                }
                 , error: function (error) {
                     alert('error; ' + eval(error.d));
                 }
            }

            );
        }

        function getRunHours(id) {

            var RecordId = id.split("_");

            debugger;

            $.ajax({
                method: 'POST',
                url: 'Main.aspx/BindRunningHoursTable',
                contentType: 'application/json;charset=utf-8',
                data: '{RecordId:"' + RecordId[1] + '"}',
                datatype: 'json',
                success: function (data) {
                    var HtmlContent = "";
                    if (data.d.length > 0) {
                        for (var i = 0; i < data.d.length; i++) {

                            debugger;

                            if (parseInt(data.d[i].SetRunHours) >= parseInt(data.d[i].RunHours))
                                HtmlContent += "<tr><td style = 'width:200px'>" + data.d[i].ComponentName + "</td><td style = 'width:70px'>" + data.d[i].SetRunHours + "</td><td style = 'width:70px'>" + data.d[i].RunHours + "</td></tr>";
                            else
                                HtmlContent += "<tr><td style = 'width:200px'>" + data.d[i].ComponentName + "</td><td style = 'width:70px'>" + data.d[i].SetRunHours + "</td><td style = 'width:70px;background-color:#e63333;color:white'>" + data.d[i].RunHours + "</td></tr>";
                        }
                        HtmlContent = "<tr><th class=\"active\" scope=\"col\" style = 'width:70px'>Name</th><th class=\"active\"  style = 'width:200px'>Set Hours</th><th class=\"active\" scope=\"col\" style = 'width:200px'>Run Hours</th></tr>" + HtmlContent;

                        document.getElementById("<%=headEquipmentName.ClientID%>").innerHTML = data.d[0].EqName + " - COMPONENT RUNNING HOURS ";

                        $("#dvAlarm").show();
                        $("table").html(HtmlContent);
                        $("#myModal").modal("show");
                    }
                }
            });
        }
    </script>
    <style>
        .panelbody {
            border: 5px solid;
            border-radius: 9px;
            font-weight: bold;
        }
        .row1{
    margin-right: -10px;
    margin-left: -10px;
    display:contents;
    
}
        .panel-heading {
            height: 30px;vertical-align: middle
        }

    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:UpdatePanel ID="upnlwzMain" UpdateMode="Always" runat="server">
        <ContentTemplate>
            <asp:Timer runat="server" ID="tmr" Interval="20000" OnTick="tmr_Tick"></asp:Timer>
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="x_panel">
                        <div class="x_content">
                            <asp:HiddenField runat="server" ID="hdnBranchId" />
                            <asp:HiddenField runat="server" ID="hdnSelectedEquipmentName" />

                            <div class="x_title">
                                <div class="col-lg-6">
                                    <h4>
                                        <asp:Label runat="server">Summary of Equipments</asp:Label></h4>
                                </div>
                                <div class="col-lg-6" style="text-align: right;">
                                    <span>
                                        <asp:ImageButton ID="btnGridView" runat="server" src="Images/grid.png" OnClick="btnGridView_Click" AlternateText="GridView" ToolTip="Grid View" /></span>
                                    <span>
                                        <asp:ImageButton ID="btnListView" runat="server" src="Images/list.png" OnClick="btnListView_Click" AlternateText="ListView" ToolTip="List View" /></span>
                                    <span>
                                        <asp:ImageButton ID="btnRefresh" runat="server" src="Images/refresh-icon1.png" OnClick="btnRefresh_Click" AlternateText="Refresh" ToolTip="Refresh" /></span>
                                </div>
                                <div class="clearfix"></div>
                            </div>

                            <div class="col-lg-12 col-sm-12 col-xs-12">
                                <div class="row" id="dvListView" runat="server" visible="false" style="overflow: auto; position: relative">
                                    <asp:GridView runat="server" ID="grdEquipmentdiagnosis" OnRowCommand="grdEquipmentdiagnosis_RowCommand" OnRowDataBound="grdEquipmentdiagnosis_RowDataBound"
                                        AllowPaging="false" AllowSorting="false" AutoGenerateColumns="False" BackColor="#cdf9e4"
                                        CssClass="table table-bordered dt-responsive nowrap"
                                        ShowHeader="true">
                                        <Columns>
                                            <asp:BoundField DataField="EquipmentMasterId">
                                                <HeaderStyle CssClass="hidden txtalign" BackColor="#52c58e" />
                                                <ItemStyle CssClass="hidden" />
                                            </asp:BoundField>
                                            <asp:BoundField DataField="EquipmentName" HeaderText="Equipment Name" HeaderStyle-CssClass="text-center active">
                                                <HeaderStyle BackColor="#075534" ForeColor="White" />
                                            </asp:BoundField>
                                            <asp:TemplateField HeaderStyle-CssClass="text-center active" ItemStyle-CssClass="text-center">
                                                <HeaderTemplate>Status</HeaderTemplate>
                                                <HeaderStyle BackColor="#075534" ForeColor="White" />
                                                <ItemTemplate>
                                                    <asp:Image ID="imgStatus" runat="server" />
                                                    <asp:Label ID="lblStatus" CssClass="text-right" Style="font-weight: bold; font-size: 13px" runat="server"></asp:Label>
                                                    <asp:HiddenField ID="hdnStatus" Value='<%# Eval("EquipmentOnlineStatus") %>' runat="server" />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderStyle-CssClass="text-center active" ItemStyle-CssClass="text-center">
                                                <HeaderTemplate>Temperature SV</HeaderTemplate>
                                                <HeaderStyle BackColor="#075534" ForeColor="White" />
                                                <ItemTemplate>
                                                    <asp:Label ID="lblTempSV" Text='<%# Eval("TempSetValue") %>' CssClass="text-right" Style="font-weight: bold; font-size: 13px" runat="server"></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderStyle-CssClass="text-center active" ItemStyle-CssClass="text-center">
                                                <HeaderTemplate>Temperature PV</HeaderTemplate>
                                                <HeaderStyle BackColor="#075534" ForeColor="White" />
                                                <ItemTemplate>
                                                    <asp:Label ID="lblTempPV" Text='<%# Eval("TempLastValue") %>' CssClass="text-right" Style="font-weight: bold; font-size: 13px" runat="server"></asp:Label>
                                                    <asp:HiddenField ID="hdnTempLL" Value='<%# Eval("TempratureLowerLimit") %>' runat="server" />
                                                    <asp:HiddenField ID="hdnTempUL" Value='<%# Eval("TempratureUpperLimit") %>' runat="server" />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderStyle-CssClass="text-center active" ItemStyle-CssClass="text-center">
                                                <HeaderTemplate>Humidity SV</HeaderTemplate>
                                                <HeaderStyle BackColor="#075534" ForeColor="White" />
                                                <ItemTemplate>
                                                    <asp:Label ID="lblHumidSV" Text='<%# Eval("HumidSetValue") %>' CssClass="text-right" Style="font-weight: bold; font-size: 13px" runat="server"></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderStyle-CssClass="text-center active" ItemStyle-CssClass="text-center">
                                                <HeaderTemplate>Humidity PV</HeaderTemplate>
                                                <HeaderStyle BackColor="#075534" ForeColor="White" />
                                                <ItemTemplate>
                                                    <asp:Label ID="lblHumidPV" Text='<%# Eval("HumidLastValue") %>' CssClass="text-right" Style="font-weight: bold; font-size: 13px" runat="server"></asp:Label>
                                                    <asp:HiddenField ID="hdnHumiLL" Value='<%# Eval("HumidityLowerLimit") %>' runat="server" />
                                                    <asp:HiddenField ID="hdnHumiUL" Value='<%# Eval("HumidityUpperLimit") %>' runat="server" />
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderStyle-CssClass="text-center active" ItemStyle-CssClass="text-center">
                                                <HeaderTemplate>Pending Alarm</HeaderTemplate>
                                                <HeaderStyle BackColor="#075534" ForeColor="White" />
                                                <ItemTemplate>
                                                    <asp:ImageButton ID="imgAlarm" runat="server" Style="vertical-align: middle" CommandName="GetAlarmDetails" CommandArgument='<%# Container.DataItemIndex %>' />
                                                    <asp:HiddenField ID="hdnAlarm" Value='<%# Eval("ALCount") %>' runat="server" />
                                                    <asp:Label ID="lblAlarm" CssClass="text-right" Style="font-weight: bold; font-size: 13px" runat="server"></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:BoundField DataField="MAXReviewLogDateTime" HeaderText="Pending Review" HeaderStyle-CssClass="text-center active" ItemStyle-CssClass="text-center">
                                                <HeaderStyle BackColor="#075534" ForeColor="White" />
                                            </asp:BoundField>
                                            <asp:TemplateField HeaderStyle-CssClass="text-center active" ItemStyle-CssClass="text-center">
                                                <HeaderTemplate>Running Hours</HeaderTemplate>
                                                <HeaderStyle BackColor="#075534" ForeColor="White" />
                                                <ItemTemplate>
                                                    <asp:HiddenField ID="hdnHealth" Value='<%# Eval("HealthCount") %>' runat="server" />
                                                    <asp:LinkButton runat="server" CssClass="btn btn-group-sm" ID="lnkBtnHealth" CommandName="GetHealthDetails" CommandArgument='<%#  Container.DataItemIndex %>'>LinkButton</asp:LinkButton>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                        </Columns>
                                    </asp:GridView>
                                </div>
                                <div style="overflow-y: auto; overflow-x: hidden;">
                                    <div class="row" id="dvGridview" runat="server" visible="false">
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="modal fade" id="myModal" role="dialog">
                <div class="modal-dialog">
                    <!-- Modal content-->
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal">&times;</button>
                            <h4 class="modal-title" id="headEquipmentName" runat="server"></h4>
                        </div>
                        <div class="modal-body">
                            <div id="dvScroll" runat="server" style="height: 250px; overflow: auto; overflow-x: hidden;">
                                <asp:GridView runat="server" Width="100%" ID="grdAlarmDesc" Visible="false"
                                    AllowPaging="false" AllowSorting="false" AutoGenerateColumns="False" BackColor="#e3f9df"
                                    CssClass="table table-bordered dt-responsive nowrap"
                                    ShowHeader="true">
                                    <Columns>
                                        <asp:BoundField DataField="Log Date" HeaderText="Log Date" HeaderStyle-CssClass="active">
                                            <ItemStyle Width="20%"></ItemStyle>
                                        </asp:BoundField>
                                        <asp:BoundField DataField="Log Time" HeaderText="Log Time" HeaderStyle-CssClass="active">
                                            <ItemStyle Width="20%"></ItemStyle>
                                        </asp:BoundField>
                                        <asp:BoundField DataField="Alarm Description" HeaderText="Alarm Desc." HeaderStyle-CssClass="active">
                                            <ItemStyle Width="60%"></ItemStyle>
                                        </asp:BoundField>
                                    </Columns>
                                </asp:GridView>
                                <asp:GridView runat="server" Width="100%" ID="grdRunningHours" Visible="false"
                                    AllowPaging="false" AllowSorting="false" AutoGenerateColumns="False" BackColor="#e3f9df"
                                    CssClass="table table-bordered dt-responsive nowrap"
                                    ShowHeader="true">
                                    <Columns>
                                        <asp:BoundField DataField="Name" HeaderText="Name" HeaderStyle-CssClass="active">
                                            <ItemStyle Width="50%"></ItemStyle>
                                        </asp:BoundField>
                                        <asp:BoundField DataField="SetRunHours" HeaderText="Set RunHours" HeaderStyle-CssClass="active" ItemStyle-Width="25%" />
                                        <asp:BoundField DataField="RunHours" HeaderText="RunHours" HeaderStyle-CssClass="active">
                                            <ItemStyle Width="25%"></ItemStyle>
                                        </asp:BoundField>
                                    </Columns>
                                </asp:GridView>
                                <div id="dvAlarm" runat="server">
                                    <table id="tblBody" runat="server" class="table table-bordered dt-responsive nowrap" cellspacing="0" rules="all" border="1" style="background-color: #E3F9DF; border-collapse: collapse;">
                                    </table>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default alert-danger" data-dismiss="modal">Close</button>
                        </div>
                    </div>

                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
    <!-- /page content -->
</asp:Content>
