<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/ExhibitorMaster.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
        $(function () {
            selectMenu("翻译人员", "");

            setDateSelect();
            CountTotalPrice();
        });

        function Save() {
            var orderStr = "";
            var check = true;
            $("input[type='text'][name^='Num']").each(function () {
                var num = $(this).val().replace(/[^\d]/g, '');
                var price = $(this).attr("price");
                var bDate = $(this).parent().parent().find("td select[id^='BDate']").val();
                var eDate = $(this).parent().parent().find("td select[id^='EDate']").val();

                if ($.trim(num) != "" && $.trim(num) != "0" && regNum.test(num) && regPrice.test(price)) {
                    if (bDate != "" && eDate != "") {
                        if (parseInt(eDate) > parseInt(bDate)) {
                            var day = parseInt(eDate) - parseInt(bDate);
                            var totalPrice = parseInt(num) * parseFloat(price) * day;
                            var id = $(this).attr("name").substring(3);

                            //var bDateStr = $(this).parent().parent().find("td select[id^='BDate']").find('option:selected').text();
                            //var eDateStr = $(this).parent().parent().find("td select[id^='EDate']").find('option:selected').text();
                            var bDateStr = $(this).parent().parent().find("td select[id^='BDate']").find('option:selected').attr("v");
                            var eDateStr = $(this).parent().parent().find("td select[id^='EDate']").find('option:selected').attr("v");
                            orderStr += id + ":" + num + ":" + totalPrice + ":" + bDateStr + ":" + eDateStr + ";";
                        } else {
                            check = false;
                            $(this).parent().parent().find("td select[id^='BDate']").focus();
                            alert("开始工作日期不能小于结束工作日期！");
                            return false;
                        }
                    } else {
                        if (bDate == "") {
                            $(this).parent().parent().find("td select[id^='BDate']").focus();
                            alert("请选择开始工作日期！");
                        } else if (eDate == "") {
                            $(this).parent().parent().find("td select[id^='EDate']").focus();
                            alert("请选择结束工作日期！");
                        }
                        check = false;
                        return false;
                    }
                }
            });

            if (check) {
                $("#OrderStr").val(orderStr);

                MsgTip.show({ ico: 'loading', during: 0, msg: '正在处理请求，请稍等...' });

                $("#f1").submit();
            }
        }

        var regNum = /^\d+$/;
        var regPrice = /^\d+(\.\d+)?$/;
        function CountTotalPrice() {
            $("input[id^='Num']").each(function () {
                $(this).val($(this).val().replace(/[^\d]/g, ''));
                var num = $(this).val();
                var price = $(this).attr("price");
                var bDate = $(this).parent().parent().find("td select[id^='BDate']").val();
                var eDate = $(this).parent().parent().find("td select[id^='EDate']").val();

                var total = 0;
                if (regNum.test(num) && regPrice.test(price) && bDate != "" && eDate != "") {
                    if (parseInt(eDate) > parseInt(bDate)) {
                        var day = parseInt(eDate) - parseInt(bDate);
                        total += parseInt(num) * parseFloat(price) * day;
                    }
                }

                $(this).parent().parent().find("td[total]").html(total);
            });

            var allTotalPrice = 0;
            $("td[total]").each(function () {
                var totalPrice = $(this).html();
                if (regPrice.test(totalPrice)) {
                    allTotalPrice += parseFloat(totalPrice);
                }
            });
            $("td[alltotal]").html(allTotalPrice);
        }

        function setDateSelect() {
            $("select[id^='BDate']").each(function () {
                var value = $(this).parent().find("input[type='hidden'][id^='BDateValue']").val();
                $(this).val(value);
            });
            $("select[id^='EDate']").each(function () {
                var value = $(this).parent().find("input[type='hidden'][id^='EDateValue']").val();
                $(this).val(value);
            });
        }

        function Back() {
            document.location = "<%=FamousFurnitureExpo.Models.Helper.VRoot %>/Exhibitor/ServiceBookInterpreterList";
        }
    </script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
    <div>
        <center>
            <form id="f1" action="" method="post">
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td align="right">
                        <table border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td align="left" style="width:80px;">截止日期：</td>
                                <td align="left" style="width:80px;"><%=ViewData["EndDate"] %></td>
                                <td align="left" style="width:80px;">提交日期：</td>
                                <td align="left" style="width:80px;"><%=ViewData["SubDate"] %></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr><td>&nbsp;</td></tr>
                <tr>
                    <td align="left">
                        <h2>请阅读下文后填写表格</h2>
                            <span>1.最少雇用日期为一天，不足一天者，按一天计算。</span><br />
                            <span>2.请于截止日期前提交所有的申请表格及费用。</span><br />
                       <h2>大会可替参展商安排临时服务人员，提供如下服务：</h2>
                    </td>
                </tr>
                <tr><td>&nbsp;</td></tr>
                <tr>
                    <td align="left">
                        <strong>翻译人员：</strong>
                    </td>
                </tr>
                <tr>
                    <td align="left">
                        <table width="100%" border="0" cellpadding="1" cellspacing="0">
                            <tr>
                                <td class="td01" width="10%" align="left">工作人员</td>
                                <%--<td class="td01" width="10%" align="center">规格</td>--%>
                               <%-- <td class="td01" width="6%" align="center">单位</td>--%>
                                <td class="td01" width="10%" align="center">价格</td>

                                <td class="td01" width="22%" align="center">开始工作日期</td>
                                <td class="td01" width="22%" align="center">结束工作日期</td>

                                <td class="td01" width="10%" align="center">数量</td>
                                <td class="td01" width="10%" align="center">小计</td>
                            </tr>
                        <% 
                            System.Data.DataTable dt = ViewData["DataTable"] as System.Data.DataTable;
                            if (dt.Rows.Count > 0)
                            {
                                List<string> strBDateList = new List<string>();
                                List<string> strEDateList = new List<string>();
                                List<string> strBDateShowList = new List<string>();
                                List<string> strEDateShowList = new List<string>();
                                for (int i = 11; i <= 14; i++)
                                {
                                    strBDateList.Add((new DateTime(2016, 8, i, 9, 0, 0)).ToString());
                                    strEDateList.Add((new DateTime(2016, 8, i, 18, 0, 0)).ToString());
                                    strBDateShowList.Add("2016/8/" + i + " AM");
                                    strEDateShowList.Add("2016/8/" + i + " PM");
                                }
                                foreach (System.Data.DataRow dr in dt.Rows)
                                {
                                    string bValue = "";
                                    string strBDate = dr["OddWorkBDate"].ToString();
                                    if (strBDate != "")
                                    {
                                        strBDate = Convert.ToDateTime(dr["OddWorkBDate"]).ToString();
                                        bValue = strBDateList.IndexOf(strBDate).ToString();
                                    }
                                    string eValue = "";
                                    string strEDate = dr["OddWorkEDate"].ToString();
                                    if (strEDate != "")
                                    {
                                        strEDate = Convert.ToDateTime(dr["OddWorkEDate"]).ToString(); ;
                                        eValue = (strEDateList.IndexOf(strEDate) + 1).ToString();
                                    }
                        %>
                            <tr>
                                <td class="td03" align="center"><%=Server.HtmlEncode(dr["SrjName"].ToString()) %></td>
                                <%--<td class="td03" align="center"><%=Server.HtmlEncode(dr["SrjScale"].ToString()) %></td>--%>
                            <%--    <td class="td03" align="center"><%=Server.HtmlEncode(dr["SrjUnit"].ToString()) %></td>--%>
                                <td class="td03" align="center"><%=Server.HtmlEncode(dr["SrjSalePrice"].ToString()) %></td>
                                <td class="td03" align="center">
                                    <select id="BDate<%=dr["SrjID"] %>" name="BDate<%=dr["SrjID"] %>" onchange="CountTotalPrice()" style="text-align:center; font-size:12px;width:150px">
                                        <option value="">--请选择--</option>
                                    <% 
                                        for (int i = 0; i < strBDateList.Count; i++)
                                        {
                                    %>
                                        <option value="<%=i %>" v="<%=strBDateList[i] %>"><%=strBDateShowList[i] %></option>
                                    <%        
                                        }
                                    %>
                                    </select>
                                    <input type="hidden" id="BDateValue<%=dr["SrjID"] %>" name="BDateValue<%=dr["SrjID"] %>" value="<%=bValue %>" />
                                </td>
                                <td class="td03" align="center">
                                    <select id="EDate<%=dr["SrjID"] %>" name="EDate<%=dr["SrjID"] %>" onchange="CountTotalPrice()" style="text-align:center; font-size:12px;width:150px">
                                        <option value="">--请选择--</option>
                                    <% 
                                        for (int i = 0; i < strEDateList.Count; i++)
                                        {
                                    %>
                                        <option value="<%=(i+1) %>" v="<%=strEDateList[i] %>"><%=strEDateShowList[i] %></option>
                                    <%        
                                        }
                                    %>
                                    </select>
                                    <input type="hidden" id="EDateValue<%=dr["SrjID"] %>" name="EDateValue<%=dr["SrjID"] %>" value="<%=eValue %>" />
                                </td>
                                <td class="td03" align="center">
                                    <input type="text" class="text" id="Num<%=dr["SrjID"] %>" name="Num<%=dr["SrjID"] %>" price="<%=dr["SrjSalePrice"] %>" value="<%=Server.HtmlEncode(dr["OddTotalNum"].ToString()) %>" style="text-align:center; line-height:14px; width:50px; height:14px" onkeyup="CountTotalPrice()" />
                                </td>
                                <td class="td03" align="center" total="total"></td>
                            </tr>
                        <%            
                                }
                        %>
                            <tr>
                                <td class="td03" align="center" colspan="1">费用合计：</td>
                                <td class="td03" align="center" colspan="6" alltotal="alltotal"></td>
                            </tr>
                        <%
                            }
                            else
                            { 
                        %>
                            <tr>
                                <td colspan="7" class="td03" align="center" valign="middle" height="40" width="100%">暂无信息</td>
                            </tr>
                        <%      
                            } 
                        %>
                        </table>
                    </td>
                </tr>
                <tr><td>&nbsp;</td></tr>
                <tr>
                    <td align="right">
                        <table border="0" cellpadding="0" cellspacing="0">
                            <tr>
                                <td><div class="button" onclick="Save()">提交</div></td>
                                <td><div class="button" onclick="Back()">返回</div></td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr><td>&nbsp;</td></tr>
                <tr>
                    <td align="left">
                   
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="hidden" id="OrderStr" name="OrderStr" />
                    </td>
                </tr>
            </table>
            <script type="text/javascript">
                $(function () {
                    var message = $("#Message").val();
                    if (message != "") {
                        showMsg(message);
                    }
                });
            </script>
            <input type="hidden" id="Message" name="Message" value="<%=ViewData["Message"] %>" />
            </form>
        </center>
    </div>
</asp:Content>
