<%@ 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='hidden'][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 != "") {
                if (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 {
                    $(this).parent().parent().find("td select[id^='EDate']").focus();
                    alert("请选择结束使用时间！");
                    check = false;
                    return false;
                }
            } else {
                if (eDate != "") {
                    $(this).parent().parent().find("td select[id^='BDate']").focus();
                    alert("请选择开始使用时间！");
                    check = false;
                    return false;
                }
            }
            //}
        });

        if (check) {
            //alert(orderStr);
            $("#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/ServiceBookActivityByDateList";
    }
    </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">
                        在展览会期间举办新闻发布会/产品或服务推介会是您烘托您的展出，推荐您的产品极好的方法。 您可以邀请您自己的目标观众来参加您的会议。
                    </td>
                </tr>
                <tr><td>&nbsp;</td></tr>
                <tr>
                    <td align="left">
                        <strong>会议室的收费如下：</strong>
                    </td>
                </tr>

                <tr>
                    <td>
                        <table border="0" cellpadding="0" cellspacing="0" width="550px">
                            <tr>
                                <td class="td01">会议室编号</td>
                                <td class="td01">面积（m<sup>2</sup>）</td>
                                <td class="td01">容量（人）</td>
                                <td class="td01">价格（RMB/4小时/次）</td>
                            </tr>
                            <tr>
                                <td class="td03">3-11号会议室</td>
                                <td class="td03">120</td>
                                <td class="td03">100</td>
                                <td class="td03">12000</td>
                            </tr>
                            
                        </table>
                    </td>
                </tr>
                <tr><td>&nbsp;</td></tr>

                <tr>
                    <td align="left">
                        注：以上报价包括场地租赁、白板一块、饮水机、话筒2只，扩音设备。 所有与新闻发布会、技术交流会相关的资料请于1个月前以书面形式与主办单位确认，并于确认后7日内支付费用。在确认有关款项已经收到后，主办单位将为您的新闻发布会、技术交流会进行推广。同时，主办单位欢迎参展商自行组织观众。
                    </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="20%" 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="10%" align="center">开始使用时间</td>
                                <td class="td01" width="10%" 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 = 21; i <= 24; i++)
                                {
                                    strBDateList.Add((new DateTime(2014, 8, i, 9, 0, 0)).ToString());
                                    strBDateList.Add((new DateTime(2014, 8, i, 14, 0, 0)).ToString());
                                    
                                    strEDateList.Add((new DateTime(2014, 8, i, 13, 0, 0)).ToString());
                                    strEDateList.Add((new DateTime(2014, 8, i, 18, 0, 0)).ToString());

                                    strBDateShowList.Add("2014/8/" + i + " AM");
                                    strBDateShowList.Add("2014/8/" + i + " PM");

                                    strEDateShowList.Add("2014/8/" + i + " AM");
                                    strEDateShowList.Add("2014/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()) %><input type="hidden" class="text" id="Num<%=dr["SrjID"] %>" name="Num<%=dr["SrjID"] %>" price="<%=dr["SrjSalePrice"] %>" value="1" style="text-align:center; line-height:14px; width:50px; height:14px" onkeyup="CountTotalPrice()" /></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="4" alltotal="alltotal"></td>
                            </tr>
                        <%
                            }
                            else
                            { 
                        %>
                            <tr>
                                <td colspan="5" 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>
                        <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>


