<%@ page language="C#" enableeventvalidation="false" masterpagefile="MyShopMasterPage.master" autoeventwireup="true" inherits="Member_Shop_ReceiveAddress, WebApp_deploy" title="收货地址设置" enableviewstate="true" validaterequest="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <script type="text/javascript">
        var ReceiveAddress = new Array();
        function selectDeliver(obj) {

            var url = "Shop_ReceiveAddress.aspx?Action=modify&aid=" + obj;

            window.location.href = url;
        }

        function deleteDeliver(obj) {
            var url = "Shop_ReceiveAddress.aspx?Action=delete&aid=" + obj;
            window.location.href = url;
        }
    </script>
    <div class="pageTitle">
        <span>收货地址设置</span></div>
    <div class="tableHead">
        您好，在这里可以预设您的收货地址，最好设置<asp:Literal runat="server" ID="Addrnum" Text="3" />个。</div>
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="tableHead"
        DataKeyNames="AddressID" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing"
        OnSelectedIndexChanging="GridView1_SelectedIndexChanging">
        <Columns>
            <asp:BoundField DataField="username" HeaderText="姓名" />
            <asp:TemplateField HeaderText="所在地">
                <ItemTemplate>
                    <asp:Literal ID="Province" Text='<%#Eval("Province") %>' runat="server" />
                    <asp:Literal ID="City" Text='<%#Eval("City") %>' runat="server" />
                    <asp:Literal ID="ltrArea" Text='<%#Eval("CMArea") %>' runat="server"></asp:Literal>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Address" HeaderText="详细地址" />
            <asp:BoundField DataField="ConectPhone" HeaderText="电话" />
            <asp:BoundField DataField="MobilePhone" HeaderText="手机" />
            <asp:TemplateField HeaderText="邮政编码">
                <ItemTemplate>
                    <asp:Label ID="lbzipCode" runat="server" Text='<%# Eval("ZipCode") %>'></asp:Label>
                    <asp:HiddenField ID="hdAddressID" runat="server" Value='<%# Eval("AddressID") %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Email" HeaderText="Email地址" />
            <asp:CommandField SelectText="修改" ShowSelectButton="True" />
            <asp:CommandField ShowDeleteButton="True" />
        </Columns>
        <EmptyDataTemplate>
            <table class="tableHeader" style="width: 98%">
                <th>
                    姓名
                </th>
                <th>
                    所在地
                </th>
                <th>
                    详细地址
                </th>
                <th>
                    电话
                </th>
                <th>
                    手机
                </th>
                <th>
                    邮政编码
                </th>
                <th>
                    Email
                </th>
                <th>
                    操作
                </th>
                <tr>
                    <td colspan="8">
                        暂无收货地址！
                    </td>
                </tr>
            </table>
        </EmptyDataTemplate>
    </asp:GridView>
    <div class="clear" style="height: 5px; overflow: hidden;">
    </div>
    <table class="ShopOrderStyle">
        <caption id="deliverName">
            收货详细地址信息</caption>
        <tr>
            <td class="OrderTitle">
                联 系 人：
            </td>
            <td>
                <asp:TextBox ID="TxtUserName" runat="server" CausesValidation="True" Width="155px"
                    Height="16px" MaxLength="50" />
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ForeColor="Red" runat="server"
                    ErrorMessage="不能为空" ControlToValidate="TxtUserName" />
                <asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ControlToValidate="TxtUserName"
                    ErrorMessage="联系人姓名为中文！" ValidationExpression="^[\u4e00-\u9fa5]+$" Display="Dynamic" />
                <asp:HiddenField ID="editAddressID" runat="server" />
            </td>
        </tr>
        <tr>
            <td class="OrderTitle">
                所 在 地：
            </td>
            <td>
                <hl:HoWaveProvinceCity ID="HoWaveProvinceCity1" runat="server" EnableViewState="true" />
            </td>
        </tr>
        <tr class="div_row">
            <td class="OrderTitle">
                详细地址：
            </td>
            <td>
                <asp:TextBox ID="TxtAddress" runat="server" Width="350px" MaxLength="50" />
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ForeColor="Red" runat="server"
                    ControlToValidate="TxtAddress" ErrorMessage="不能为空" />
            </td>
        </tr>
        <tr class="div_row">
            <td class="OrderTitle">
                邮箱地址：
            </td>
            <td>
                <asp:TextBox ID="TxtEmail" runat="server" Height="18px" Width="155px" MaxLength="50" />
                <asp:RegularExpressionValidator ForeColor="Red" ID="RegularExpressionValidator3"
                    runat="server" ControlToValidate="TxtEmail" ErrorMessage="Email地址不正确" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
                    Display="Dynamic" />
            </td>
        </tr>
        <tr class="div_row">
            <td class="OrderTitle">
                邮政编码：
            </td>
            <td>
                <asp:TextBox ID="TxtZipCode" runat="server" Width="155px" MaxLength="6" />
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" ForeColor="Red" runat="server"
                    ControlToValidate="TxtZipCode" ErrorMessage="不能为空" Display="Dynamic" />
                <asp:RegularExpressionValidator ForeColor="Red" ID="RegularExpressionValidator2"
                    runat="server" ControlToValidate="TxtZipCode" ErrorMessage="邮政编码格式不对" ValidationExpression="\d{6}"
                    Display="Dynamic" />
            </td>
        </tr>
        <tr class="div_row">
            <td class="OrderTitle">
                电话号码：
            </td>
            <td>
                <asp:TextBox ID="TxtPhone" runat="server" Width="155px" Height="16px" />
                <asp:RegularExpressionValidator ForeColor="Red" ID="RegularHomeTel" runat="server"
                    ErrorMessage="格式不对！" ControlToValidate="TxtPhone" ValidationExpression="^\d{3,4}-\d{7,8}$"></asp:RegularExpressionValidator>
                格式：(区号-电话-分机)如：020-87512750)
            </td>
        </tr>
        <tr class="div_row">
            <td class="OrderTitle" style="height: 26px">
                手机号码：
            </td>
            <td style="height: 26px">
                <asp:TextBox ID="TxtMoblephone" runat="server" Width="155px" Height="16px" MaxLength="11" />
                <asp:RegularExpressionValidator ForeColor="Red" ID="RegularExpressionValidator1"
                    runat="server" ControlToValidate="TxtMoblephone" ErrorMessage="手机号码不对" ValidationExpression="^(13[0-9]|15[^4]|18[6|8|9])\d{8}$"
                    Display="Dynamic" />
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center;">
                <asp:Button ID="ButAddress" runat="server" OnClientClick="return checkAddressPass();"
                    OnClick="ButAddress_Click" Text="新 增" />
                <asp:Button ID="ButModify" runat="server" OnClientClick="return checkAddressPass();"
                    OnClick="ButModifyAddress_Click" Text="修 改" Visible="false" />
            </td>
        </tr>
    </table>
    <script type="text/javascript">
        //姓名
        function checkContacter_Name() {
            var Contacter_Name = $("#<%=TxtUserName.ClientID %>");
            if (Contacter_Name.val().length == 0) {
                alert("联系人姓名不能为空!");
                Contacter_Name.focus();
                return false;
            }

            var Chinese = /^[\u4E00-\u9FA5]+$/;
            if (!Chinese.test(Contacter_Name.val())) {
                Contacter_Name.focus();
                alert('联系人名字必须为中文！');
                return false;
            }
            return true;
        }
        //省、市、区
        function checkProvince() {
            //获取用户控件中的dropdownlist的选择值 
            var hpc_Province = document.getElementById('<%=HoWaveProvinceCity1.ClientID %>' + "_Province");
            var bojvalueProvince = "";
            for (i = 0; i < hpc_Province.options.length; i++) {
                if (hpc_Province.options[i].selected)
                    bojvalueProvince = hpc_Province.options[i].value;
            }
            if (bojvalueProvince.length == 0) {
                alert("请选择省份！");
                hpc_Province.focus();
                return false;
            }


            //获取用户控件中的dropdownlist的选择值
            var hpc_City = document.getElementById('<%=HoWaveProvinceCity1.ClientID %>' + "_City");
            if (hpc_City.options.length > 0) {
                var bojvalueCity = "";
                for (i = 0; i < hpc_City.options.length; i++) {
                    if (hpc_City.options[i].selected)
                        bojvalueCity = hpc_City.options[i].value;
                }
                if (bojvalueCity.length == 0) {
                    alert("请选择城市！");
                    hpc_City.focus();
                    return false;
                }

                //获取用户控件中的dropdownlist的选择值
                var hpc_ddlArea = document.getElementById('<%=HoWaveProvinceCity1.ClientID %>' + "_ddlArea");
                if (hpc_ddlArea.options.length > 0) {
                    var bojvalueArea = "";
                    if (hpc_ddlArea.options.length >= 2) {
                        if (hpc_ddlArea.options[1].value != "") {
                            for (i = 0; i < hpc_ddlArea.options.length; i++) {
                                if (hpc_ddlArea.options[i].selected) {
                                    bojvalueArea = hpc_ddlArea.options[i].value;
                                }
                            }
                            if (bojvalueArea.length == 0) {
                                alert("请选择县/区！");
                                hpc_ddlArea.focus();
                                return false;
                            }
                        }
                    }
                }
            }
            return true;
        }
        //详细地址
        function checkContacter_Address() {
            var Contacter_Address = $("#<%=TxtAddress.ClientID %>");
            if (Contacter_Address.val().length == 0) {
                alert("详细地址不能为空!");
                Contacter_Address.focus();
                return false;
            }
            return true;
        }

        //联系电话
        function checkContacter_Phone() {
            var homePhone = $("#<%=TxtPhone.ClientID %>"); //电话
            var mobile = $("#<%=TxtMoblephone.ClientID %>"); //手机

            //            var word = /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/; //电话号码格式
            //            var word1 = /\d{11}/; //手机号码格式/^1\d{10}$/;  

            if (mobile.val().length == 0 && homePhone.val().length == 0) {
                alert("电话号码和手机号码至少填写一个!");
                homePhone.focus();
                return false;
            } else {
                //                if (mobile.val().length != 0) {
                //                    if ((word1.test(mobile.val())) == false) {
                //                        alert('手机号码为数字或格式不对！');
                //                        mobile.focus();
                //                        return false;
                //                    }
                //                }
                //                if (homePhone.val().length != 0) {
                //                    if ((word.test(homePhone.val())) == false) {
                //                        alert('电话号码为数字或格式不对！');
                //                        homePhone.focus();
                //                        return false;
                //                    }
                //                }
            }
            return true;
        }

        function checkAddressPass() {
            if (checkProvince() && checkContacter_Phone()) {
                return true;
            } else {
                return false;
            }
        }
    </script>
</asp:Content>
