<%@ Page Title="" Language="C#" MasterPageFile="~/eosWinkartWeb/eosWinkartWeb.Master"
    AutoEventWireup="true" CodeBehind="AddEspecificExtraWork.aspx.cs" Inherits="WebKart.eosWinkartWeb.AddEspecificExtraWork" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<%@ Register TagPrefix="cc1" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit, Version=3.0.20820.16598, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link rel="shortcut icon" href="../App_Themes/eosMainThem/icons/flag_blue.ico" />
    <script src="../Scripts/jquery-1.9.1.min.js" type="text/javascript"></script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <telerik:RadCodeBlock ID="RadCodeBlock" runat="server">
        <script type="text/javascript">
            $(document).ready(function () {
                var totalAmount = 0;
                $(".txtAmount").each(function () {
                    var d = $(this).val();
                    if ($(this).is(':visible')) {
                        totalAmount = totalAmount + HoureMinToMin(d);
                    }

                });
                $(".lblAmount").each(function () {
                    var d = $(this).text();
                    if ($(this).is(':visible')) {
                        totalAmount = totalAmount + HoureMinToMin(d);
                    }
                });

                if ($("span[id$='sumExtraWork']").length > 0) {
                    $("span[id$='sumExtraWork']").get(0).innerHTML = "مجموع اضافه کارهای ویژه : " + MinToHoureMin(totalAmount, 4);
                }
                $(".txtAmount").change(function () {
                    var sumOfExtraWork = $("#SumOfExtraWork").val();
                    var totalAmount = 0;
                    $(".txtAmount").each(function () {
                        var d = $(this).val();
                        if ($(this).is(':visible')) {
                            totalAmount = totalAmount + HoureMinToMin(d);
                        }
                    });
                    $(".lblAmount").each(function () {
                        var d = $(this).text();
                        if ($(this).is(':visible')) {
                            totalAmount = totalAmount + HoureMinToMin(d);
                        }
                    });
                    if (totalAmount > sumOfExtraWork) {
                        $("#lblError").text(" سقف اضافه کار ویژه اختصاص یافته به قسمت انتخاب شده " + MinToHoureMin(sumOfExtraWork, 4));
                    } else {
                        $("#lblError").text("");
                    }
                    if ($("span[id$='sumExtraWork']").length > 0) {
                        $("span[id$='sumExtraWork']").get(0).innerHTML = "مجموع اضافه کارهای ویژه : " + MinToHoureMin(totalAmount, 4);
                    }
                });
            });

            function CheckSunOfExtrawork() {
                var totalAmount = 0;
                $(".txtAmount").each(function () {
                    var d = $(this).val();
                    if ($(this).is(':visible')) {
                        totalAmount = totalAmount + HoureMinToMin(d);
                    }
                });
                $(".lblAmount").each(function () {
                    var d = $(this).text();
                    if ($(this).is(':visible')) {
                        totalAmount = totalAmount + HoureMinToMin(d);
                    }
                });
                var sumOfExtraWork = $("#SumOfExtraWork").val();
                if (totalAmount > sumOfExtraWork) {
                    $("#lblError").text(" سقف اضافه کار ویژه اختصاص یافته به قسمت انتخاب شده " + MinToHoureMin(sumOfExtraWork, 4) + " است ");
                    return false;
                } else {
                    $("#lblError").text("");
                    return true;
                }
            }

            function MinToHoureMin(input, hourLength) {
                hourLength = hourLength || 3;
                var hour = Math.floor(input / 60);
                var min = input % 60;
                var result = String("000" + hour).slice(-hourLength) + ":" + String("00" + min).slice(-2);
                return result;
            }

            function HoureMinToMin(input) {
                var arr = input.split(":");
                var hour = arr[0] === "" ? 0 : arr[0];
                var min = arr[1] === "" ? 0 : arr[1];
                var result = Math.round(hour) * 60 + Math.round(min);
                return result;
            };
        </script>
    </telerik:RadCodeBlock>
    <table width="100%">
        <tr>
            <td align="right" colspan="2">
                <asp:HiddenField runat="server" ClientIDMode="Static" ID="SumOfExtraWork" Value="" />
                <asp:Image ID="Image1" runat="server" SkinID="imgAddspesificExtra" />
            </td>
        </tr>
        <tr>
            <td class="CenterTD" colspan="2">
                <asp:Label ID="lblError" runat="server" ForeColor="Red" ClientIDMode="Static" EnableViewState="False"></asp:Label>
                <br />
                <br />
            </td>
        </tr>
        <tr>
            <td class="RightTD">
                <asp:DropDownList ID="ddlSections" runat="server" Width="205px" Height="20px" DataTextField="Name"
                    DataValueField="Code" Font-Names="Tahoma" Font-Size="10pt" Skin="Vista" AutoPostBack="true"
                    OnSelectedIndexChanged="ddlSections_SelectedIndexChanged">
                </asp:DropDownList>
            </td>
            <td class="LeftTD" valign="top">قسمت:
            </td>
        </tr>
        <tr>
            <td align="right" style="direction: rtl">
                <asp:DropDownList runat="server" Width="100px" Height="22px" ID="ddlPeriods" OnSelectedIndexChanged="ddlPeriods_SelectedIndexChanged"
                    AutoPostBack="true">
                    <asp:ListItem>1</asp:ListItem>
                    <asp:ListItem>2</asp:ListItem>
                    <asp:ListItem>3</asp:ListItem>
                    <asp:ListItem>4</asp:ListItem>
                    <asp:ListItem>5</asp:ListItem>
                    <asp:ListItem>6</asp:ListItem>
                    <asp:ListItem>7</asp:ListItem>
                    <asp:ListItem>8</asp:ListItem>
                    <asp:ListItem>9</asp:ListItem>
                    <asp:ListItem>10</asp:ListItem>
                    <asp:ListItem>11</asp:ListItem>
                    <asp:ListItem>12</asp:ListItem>
                </asp:DropDownList>
                <asp:Button runat="server" ID="btnSave" Text="ذخیره" OnClick="SaveClick" SkinID="btnOrange"
                    OnClientClick="return CheckSunOfExtrawork();" />
            </td>
            <td class="LeftTD" valign="top">ماه یا دوره:
            </td>
        </tr>
        <tr>
            <td class="RightTD">
                <asp:Label ID="lblMaxExtraWork" runat="server" SkinID="LblBrown" ClientIDMode="Static"
                    EnableViewState="False"></asp:Label>
                <asp:Label ID="Label1" runat="server" SkinID="LblBrown" ClientIDMode="Static" EnableViewState="False"> </asp:Label>
            </td>
            <td class="LeftTD" valign="top">سقف اضافه کار :
            </td>
        </tr>
        <tr>
            <td class="CenterTD" colspan="3">
                <hr style="size: 1px; color: Yellow; width: 600px">
            </td>
        </tr>
        <tr>
            <td class="CenterTD" colspan="2">
                <telerik:RadGrid runat="server" ID="grdEspecificExtraWork" Skin="WebBlue" AutoGenerateColumns="False"
                    GridLines="None" GroupingEnabled="False" OnSortCommand="grdEspecificExtraWork_SortCommand">
                    <MasterTableView NoDetailRecordsText="" DataKeyNames="PAGENO" ShowFooter="true" NoMasterRecordsText="اطلاعاتی برای نمایش موجود نمی باشد">
                        <SortExpressions>
                            <telerik:GridSortExpression FieldName="perno" SortOrder="Ascending" />
                        </SortExpressions>
                        <Columns>
                            <telerik:GridTemplateColumn DataField="Amount" HeaderText="اضافه کار ویژه"
                                UniqueName="Amount">
                                <ItemTemplate>
                                    <asp:TextBox Width="50px" ID="txtAmount" runat="server" Text='<%# Eval("Amount") %>'
                                        CssClass="txtAmount" Visible='<%# Convert.ToInt32(Eval("Status")) == 0 || Convert.ToInt32(Eval("Status")) == 2 %>'></asp:TextBox>
                                    <asp:Label Width="50px" ID="lblAmount" runat="server" Text='<%# Eval("Amount") %>'
                                        CssClass="lblAmount" Visible='<%# Convert.ToInt32(Eval("Status")) != 0 && Convert.ToInt32(Eval("Status")) != 2 %>'></asp:Label>
                                    <cc1:MaskedEditExtender ID="MaskedEditExtender" runat="server" AutoComplete="false"
                                        Mask="999:99" MaskType="Time" TargetControlID="txtAmount">
                                        <%--                                    <cc1:MaskedEditExtender ID="MaskedEditExtender" runat="server" AutoComplete="false"
                                        Mask="99999" MaskType="Number" TargetControlID="txtAmount">--%>
                                    </cc1:MaskedEditExtender>
                                </ItemTemplate>
                                <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                                <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                                <FooterTemplate>
                                    <asp:Label ID="sumExtraWork" runat="server" Text=" مجموع اضافه کارهای ویژه :  0000:00 "></asp:Label>
                                </FooterTemplate>
                            </telerik:GridTemplateColumn>
                            <telerik:GridBoundColumn DataField="Status" HeaderText="وضعیت" HeaderTooltip="وضعیت"
                                UniqueName="Status" Visible="false" AllowSorting="False">
                                <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                                <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="StatusType" HeaderText="وضعیت" HeaderTooltip="وضعیت"
                                UniqueName="StatusType" AllowSorting="true">
                                <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                                <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="SectionName" HeaderText="قسمت" HeaderTooltip="قسمت"
                                UniqueName="SectionName" Visible="True" AllowSorting="False">
                                <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                                <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Section" HeaderText="قسمت" HeaderTooltip="قسمت"
                                UniqueName="Section" Visible="false" AllowSorting="False">
                                <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                                <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="personName" HeaderText="ن خ و نام" HeaderTooltip="نام و نام خانوادگی"
                                UniqueName="personName" AllowSorting="true">
                                <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                                <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="perno" HeaderText="شماره پرسنلی" UniqueName="perno"
                                AllowSorting="true">
                                <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                                <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PAGENO" HeaderText="ش.ب" UniqueName="PAGENO"
                                Display="false" AllowSorting="False">
                                <HeaderStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                                <ItemStyle Font-Names="Tahoma" Font-Size="10pt" HorizontalAlign="Center" />
                            </telerik:GridBoundColumn>
                        </Columns>
                    </MasterTableView>
                    <ClientSettings EnableRowHoverStyle="true" AllowAutoScrollOnDragDrop="False">
                        <Selecting EnableDragToSelectRows="False" AllowRowSelect="True" />
                    </ClientSettings>
                </telerik:RadGrid>
            </td>
        </tr>
    </table>
</asp:Content>
