<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="cmp_batchList.ascx.cs" Inherits="NKC_WF.WebUserControls.cmp_batchList" %>
<%@ Register Src="~/WebUserControls/cmp_batchDetail.ascx" TagPrefix="uc1" TagName="cmp_batchDetail" %>
<%@ Register Src="~/WebUserControls/cmp_numRow.ascx" TagPrefix="uc1" TagName="cmp_numRow" %>

<asp:UpdatePanel ID="updPanelDetail" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <div class="row">
            <div class="col-12 border border-info table-info rounded py-2 mb-1" runat="server" id="divDetail">
                <uc1:cmp_batchDetail runat="server" ID="cmp_batchDetail" />
                <asp:HiddenField runat="server" ID="hfLastSelRow" />
            </div>
            <div class="col-12 px-0">
                <div class="row">
                    <div class="col-4">
                        <b class="text-uppercase"><%: traduci("CallList") %></b>
                    </div>
                    <div class="col-8 text-right small">
                        <span>
                            <asp:CheckBox runat="server" ID="chkShowSplit" CssClass="custom-control-input2" AutoPostBack="true" OnCheckedChanged="chkShowSplit_CheckedChanged" />
                            <%: traduci("ShowSplitBatch") %>
                        </span>
                        <%: traduci("FilterStatus") %>
                        <asp:DropDownList runat="server" ID="ddlStatus" AutoPostBack="true" OnSelectedIndexChanged="ddlStatus_SelectedIndexChanged">
                            <asp:ListItem Selected="True" Text="-- Show All --" Value="-1"></asp:ListItem>
                            <asp:ListItem Text="Imported" Value="0"></asp:ListItem>
                            <asp:ListItem Text="Estimating Requested" Value="1"></asp:ListItem>
                            <asp:ListItem Text="Estimating Completed" Value="2"></asp:ListItem>
                            <asp:ListItem Text="Nesting Requested" Value="3"></asp:ListItem>
                            <asp:ListItem Text="Nesting Completed" Value="4"></asp:ListItem>
                            <%--<asp:ListItem Text="Nesting Approved" Value="5"></asp:ListItem>--%>
                            <asp:ListItem Text="Nesting Discarded" Value="6"></asp:ListItem>
                            <asp:ListItem Text="Errors Present" Value="7"></asp:ListItem>
                            <asp:ListItem Text="Validation UNKNOWN" Value="8"></asp:ListItem>
                            <asp:ListItem Text="Parts INVALID" Value="9"></asp:ListItem>
                            <asp:ListItem Text="Parts OK" Value="10"></asp:ListItem>
                        </asp:DropDownList>
                        &nbsp;
        <uc1:cmp_numRow runat="server" ID="cmp_numRow" numRow="10" />
                    </div>
                </div>
            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="updPanelGrView" runat="server">
    <ContentTemplate>
        <div class="row">
            <div class="col-12 textCondens px-0">
                <asp:GridView ID="grView" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="BatchID" DataSourceID="ods" CssClass="table table-sm table-striped" AllowSorting="True" OnSelectedIndexChanged="grView_SelectedIndexChanged" OnPageIndexChanged="grView_PageIndexChanged">
                    <HeaderStyle CssClass="default" />
                    <PagerStyle CssClass="active GridPager" />
                    <PagerSettings Mode="NumericFirstLast" />
                    <SelectedRowStyle CssClass="table-info" />
                    <EmptyDataTemplate>
                        <%: traduci("NoRecord") %>
                    </EmptyDataTemplate>
                    <Columns>
                        <asp:TemplateField ShowHeader="False">
                            <HeaderTemplate>
                                <div class="text-center">
                                    <asp:LinkButton ID="lbtReset" runat="server" OnClick="lbtReset_Click" CssClass="btn btn-sm btn-primary" Visible="true" ToolTip="Reset"><i class="fa fa-refresh"></i></asp:LinkButton>
                                </div>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <div class="text-center">
                                    <asp:LinkButton ID="lbRedoEval" runat="server" CausesValidation="False" CommandName="Cancel" CommandArgument='<%# Eval("Takt") %>' CssClass="btn btn-sm btn-info" Visible='<%# listMode== NKC_SDK.BatchListMode.PartsEval %>' ToolTip="Re-Validate single ITEM" OnClick="lbRedoEval_Click" OnClientClick='return confirm("ITEM Re-Validation requested. Are you sure to proceed?")'><i class="fa fa-check-circle-o" aria-hidden="true"></i></asp:LinkButton>
                                    <asp:LinkButton ID="lbSelect" runat="server" CausesValidation="False" CommandName="Select" CommandArgument="" CssClass="btn btn-sm btn-primary" Visible='<%# listMode== NKC_SDK.BatchListMode.Standard %>'><i class="fa fa-search" aria-hidden="true"></i></asp:LinkButton>
                                </div>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="#" InsertVisible="False" SortExpression="Takt">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblBatchType" ToolTip='<%# tooltipByType(Eval("BatchType")) %>'>
                                <span style="font-size: 1.3em;"><i class='<%# cssIconByType(Eval("BatchType")) %>'></i></span>&nbsp;&nbsp;<b><%# Eval("Takt") %></b></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Status" SortExpression="Status">
                            <ItemTemplate>
                                <div class="d-flex">
                                    <div class="px-2 flex-grow-1">
                                        <asp:Label ID="lblStatus" runat="server" CssClass='<%# cssByStatus(Eval("Status"))  %>'><%# BStatus(Eval("Status")) %></asp:Label>
                                        <i class="fa fa-spinner fa-spin" aria-hidden="true" runat="server" visible='<%# Eval("Status").ToString()=="1" || Eval("Status").ToString()=="3" %>'></i>
                                    </div>
                                    <div class="px-2 text-right">
                                        <asp:HyperLink runat="server" ID="hlSheetPreview" Target="_blank" NavigateUrl='<%# $"../site/BatchPreview?BatchId={Eval("BatchID")}" %>' Visible='<%# isPreviewVisible(Eval("Status")) && hasPreviewByType(Eval("BatchType")) %>' ToolTip="Show Batch preview" CssClass="btn btn-sm btn-info"><i class="fa fa-object-group" aria-hidden="true"></i></asp:HyperLink>
                                        <asp:HyperLink runat="server" ID="hlPlannerReports" Target="_blank" NavigateUrl='<%# $"../site/PlannerReports?BatchId={Eval("BatchID")}&MaxHour=4" %>' Visible='<%# isPreviewVisible(Eval("Status")) && hasPreviewByType(Eval("BatchType")) %>' ToolTip="Show Unload Preview" CssClass="btn btn-sm btn-dark"><i class="fa fa-bar-chart" aria-hidden="true"></i></asp:HyperLink>
                                    </div>
                                </div>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Errors" SortExpression="Errors">
                            <ItemTemplate>
                                <asp:HyperLink runat="server" ID="hlShowErr" NavigateUrl='<%# $"../site/ErrorsLog?PUID=B.{Eval("BatchID")}" %>' CssClass="text-warning" Visible='<%# Eval("NumErrPre").ToString()!="0" %>' Target="_blank" ToolTip="Show errors"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> <%# $"{Eval("Errors")} (tot: {Eval("NumErrPre")} err)" %></asp:HyperLink>
                                <asp:HyperLink runat="server" ID="HyperLink1" NavigateUrl='<%# $"../site/ErrorsLog?PUID={Eval("EnvNum")}" %>' CssClass="text-danger" Visible='<%# Eval("NumErr").ToString()!="0" %>' Target="_blank" ToolTip="Show errors"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i> <%# $"{Eval("Errors")} (tot: {Eval("NumErr")} err)" %></asp:HyperLink>
                            </ItemTemplate>
                            <ItemStyle CssClass="text-right" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="TotalTime" HeaderText="Estimated Time" SortExpression="TotalTime" DataFormatString="{0:N2} min" ItemStyle-CssClass="text-right">
                            <ItemStyle CssClass="text-right"></ItemStyle>
                        </asp:BoundField>

                        <asp:TemplateField ShowHeader="False">
                            <HeaderTemplate>
                                <div class="text-center">
                                    <asp:LinkButton ID="lbtEnableDel" runat="server" CssClass="btn btn-sm btn-danger" Visible='<%# listMode== NKC_SDK.BatchListMode.Standard && !deleteEnabled %>' ToolTip="Enable Delete ALL" OnClick="lbtEnableDel_Click"><i class="fa fa-eraser"></i></asp:LinkButton>
                                    <asp:LinkButton ID="lbtDisableDel" runat="server" CssClass="btn btn-sm btn-success" Visible='<%# listMode== NKC_SDK.BatchListMode.Standard && deleteEnabled %>' ToolTip="Disable Delete ALL" OnClick="lbtDisableDel_Click"><i class="fa fa-eraser"></i></asp:LinkButton>
                                </div>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <div class="text-center">
                                    <asp:LinkButton ID="lbtDelete" runat="server" CausesValidation="False" CommandName="Delete" CommandArgument="" CssClass="btn btn-sm btn-danger" Visible='<%# (listMode== NKC_SDK.BatchListMode.Standard && (Eval("Status").ToString() == "0" || Eval("Status").ToString() == "6" || Eval("Status").ToString() == "7")) || deleteEnabled %>' OnClientClick='return confirm("Record deletion requested. Proceed?")'><i class="fa fa-trash" aria-hidden="true"></i></asp:LinkButton>
                                </div>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                <asp:HiddenField ID="hfDeleteEnabled" runat="server" />
                <asp:ObjectDataSource ID="ods" runat="server" OldValuesParameterFormatString="original_{0}" SelectMethod="getByStatus" TypeName="AppData.DS_AppTableAdapters.BatchListTableAdapter" DeleteMethod="deleteTree" FilterExpression="Status <> 5">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="ddlStatus" DefaultValue="-1" Name="Status" PropertyName="SelectedValue" Type="Int32" />
                        <asp:SessionParameter Name="SearchVal" SessionField="valoreSearch" Type="String" DefaultValue="" />
                        <asp:ControlParameter ControlID="chkShowSplit" DefaultValue="false" Name="ShowSplit" PropertyName="Checked" Type="Boolean" />
                        <asp:ControlParameter ControlID="hfPartValid" DefaultValue="0" Name="PartValid" PropertyName="Value" Type="Int32" />
                    </SelectParameters>
                    <DeleteParameters>
                        <asp:Parameter Name="Original_BatchID" Type="Int32" />
                        <asp:Parameter Name="ForceDelete" Type="Int32" DefaultValue="1" />
                    </DeleteParameters>
                </asp:ObjectDataSource>
                <asp:HiddenField runat="server" ID="hfPartValid" />
            </div>
            <asp:Timer ID="Timer1" runat="server" Interval="3000" OnTick="Timer1_Tick"></asp:Timer>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>