<%@ Page Language="C#" Inherits="TopWinCMS.BLL.PageFactory.Pages.ClientPublicPage" %><%@ Register Src="Header.ascx" TagName="Header" TagPrefix="uc1" %><%@ Register Src="SearchBar.ascx" TagName="SearchBar" TagPrefix="uc2" %><%@ Register Src="Left.ascx" TagName="Left" TagPrefix="uc3" %><%@ Import Namespace="System" %><%@ Import Namespace="System.Web" %><%@ Import Namespace="System.Web.UI.WebControls" %><%@ Import Namespace="System.Collections.Generic" %><%@ Import Namespace="TopWinCMS.BLL" %><%@ Import Namespace="TopWinCMS.Model" %><%@ Import Namespace="TopWinCMS.Common" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>订单</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link href="/Shop/css.css" rel="stylesheet" type="text/css" /><script language="javascript" type="text/javascript" src="/JS/TopWinCMS.js"></script><script language="javascript" type="text/javascript" src="/JS/Ajax/Ajax.js"></script><script language="javascript" type="text/javascript" src="/JS/Ajax/MemberLoginBar.js"></script><script language="javascript" type="text/javascript" src="/JS/Ajax/Shop.js"></script><script language="javascript" type="text/javascript" src="/JS/Ajax/GetVote.js"></script><script language="javascript" type="text/javascript">        function In() {
            for (var i = 1; i < <%=R_List.Items.Count +1 %>; i++) {
                if(document.getElementById("LB_Price_" + i)){
                var itemPrice = document.getElementById("LB_Price_" + i).innerHTML;
                var itemQuantity = document.getElementById("TB_Quantity_" + i).innerHTML;
                total(i, itemPrice, itemQuantity);
                }
            }
        }
        function total(Index,Price, Quantity) {
 
            var itemPrice = document.getElementById("LB_Price_" + Index).innerHTML;
            var itemQuantity = document.getElementById("TB_Quantity_" + Index).innerHTML;
 
            document.getElementById("LB_Total_" + Index).innerHTML = itemPrice * itemQuantity;
        }
    </script><script runat="server">
        private void Page_Load(object sender, System.EventArgs e)
        {
            MemberRightsCheck.LoginedCheck();
            if (!IsPostBack)
            {
                BT_Back.OnClientClick = string.Format("window.location='/Shop/ShoppingCart.aspx?ModelID={0}&CartGUID={1}'; return false;", Request.QueryString["ModelID"], Request.QueryString["CartGUID"]);
                BindList();


            }
        }


        private void BindList()
        {
            if (Request["GoodsID"] != null)
            {
                new Public_Shop(int.Parse(Request["ModelID"])).BindList(R_List, int.Parse(Request["GoodsID"]));
            }

            string CartGUID = Request.QueryString["CartGUID"];
            if (string.IsNullOrEmpty(CartGUID) == false)
            {
                new BLL_ShoppingCart().BindList(R_List, CartGUID);
            }

            new BLL_DeliveryMethod().BindList(RBL_DeliveryMethod);

            new BLL_PaymentMethod().BindList(RBL_PaymentMethod);

            Model_Member m = new BLL_Member().Member_EditLoad(MemberLoginInfo.MemberID);
            if (m != null)
            {
                TB_ContacterName.Text = m.TrueName;
                TB_Address.Text = m.Address;
                //TB_ZipCode.Text = m.;
                TB_Mobile.Text = m.Mobile;
                TB_Phone.Text = m.Phone;
                TB_Email.Text = m.eMail;
            }

            if (R_List.Items.Count == 0)
            {
                BT_OK.Enabled = false;
            }
        }
        protected void BT_OK_Click(object sender, System.EventArgs e)
        {
            Model_Orders model = new Model_Orders();
            model.ModelID = int.Parse(Request["ModelID"]);
            model.UserName = MemberLoginInfo.UserName;
            model.MoneyTotal = 0;
            model.MoneyReceived = 0;
            model.NeedInvoice = int.Parse(RBL_NeedInvoice.SelectedValue);
            model.Invoiced = 0;
            model.Remark = Server.HtmlEncode(TB_Remark.Text.Trim());
            model.ContacterName = Server.HtmlEncode(TB_ContacterName.Text.Trim());
            model.Address = Server.HtmlEncode(TB_Address.Text.Trim());
            model.ZipCode = Server.HtmlEncode(TB_ZipCode.Text.Trim());
            model.Mobile = Server.HtmlEncode(TB_Mobile.Text.Trim());
            model.Phone = Server.HtmlEncode(TB_Phone.Text.Trim());
            model.Email = Server.HtmlEncode(TB_Email.Text.Trim());
            model.InvoiceContent = Server.HtmlEncode(TB_InvoiceContent.Text.Trim());

            try
            {
                model.PaymentType = int.Parse(RBL_PaymentMethod.SelectedValue);
                model.DeliverType = int.Parse(RBL_DeliveryMethod.SelectedValue);
            }
            catch
            {
                MsgBox.Alert("提交订单出错。", UpdatePanel1);
                return;
            }


            string strErr = null;
            if (Request["CartGUID"] != null)
            {
                new BLL_Orders().Add(model, Request["CartGUID"], ref strErr);
            }
            else
            {
                new BLL_Orders().Add(model, int.Parse(Request["GoodsID"]), ref strErr);
            }

            if (string.IsNullOrEmpty(strErr) == false)
            {

                MsgBox.Alert(strErr, UpdatePanel1);
            }
            else
            {
                MsgBox.Alert("订单提交成功!", "/Member/MyOrders.aspx", UpdatePanel1);
            }
        }
    </script></head><body onload="In();"><form id="form1" runat="server"><table width="980" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td><uc1:Header ID="Header1" runat="server" /><table width="1002
      " border="0" cellpadding="0" cellspacing="0"><tr><td height="68" colspan="2" valign="top" background="images/Shop/top_nav.gif"><uc2:SearchBar ID="SearchBar1" runat="server" /></td></tr></table></td></tr><tr><td height="5"></td></tr><tr><td><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td valign="top"><div style="margin-bottom: 15px; clear: both"></div><div class="mainDiv" style="margin-left: 10px"><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:UpdatePanel runat="server" ID="UpdatePanel1"><ContentTemplate><fieldset><legend>商品</legend><asp:Repeater ID="R_List" runat="server"><HeaderTemplate><table cellspacing="0" rules="all" border="1" style="width: 99%; border-collapse: collapse;
                                                        margin-left: auto; margin-right: auto; margin-top: 6px; margin-bottom: 6px;"><tr style="color: White; background-color: Black; font-size: 12px; font-weight: bold;
                                                            height: 24px;"><th align="center" scope="col">                                                                商品名称
                                                            </th><th scope="col">                                                                价格
                                                            </th><th scope="col">                                                                价格(折扣后)
                                                            </th><th scope="col">                                                                数量
                                                            </th><th scope="col">                                                                小计
                                                            </th></tr></HeaderTemplate><ItemTemplate><tr style="height: 24px;"><td><a href="/ShopShow-<%# Eval("GoodsID") %>.htm" target="_blank"><%# Eval("GoodsName") %></a></td><td align="right" style="width: 180px;"><%#  DataBinder.Eval(Container.DataItem, "PriceMember","{0:##.00}")%></td><td align="right" style="width: 80px;"><span id="LB_Price_<%# Container.ItemIndex+1%>"><%#  DataBinder.Eval(Container.DataItem, "PriceMember_Cuted","{0:##.00}")%></span></td><td align="right" style="width: 80px;"><span id="TB_Quantity_<%# Container.ItemIndex+1%>"><%# Eval("Quantity") %></span></td><td align="right" style="width: 80px;"><span id="LB_Total_<%# Container.ItemIndex+1%>">0</span></td></tr></ItemTemplate><FooterTemplate></table></FooterTemplate></asp:Repeater></fieldset><br /><fieldset><legend>收货人信息</legend><table cellspacing="0" cellpadding="4" width="98%" align="center"><tbody><tr><td>                                                            收货地点：
                                                        </td><td colspan="3" height="16"><asp:TextBox ID="TB_Address" runat="server" Width="290px"></asp:TextBox><span style="color: Red;">*</span></td></tr><tr><td>                                                            收货人姓名：
                                                        </td><td><asp:TextBox ID="TB_ContacterName" runat="server"></asp:TextBox><span style="color: Red;">*</span></td><td>                                                            Email：
                                                        </td><td><asp:TextBox ID="TB_Email" runat="server"></asp:TextBox></td></tr><tr><td>                                                            收货人电话：
                                                        </td><td><asp:TextBox ID="TB_Phone" runat="server"></asp:TextBox><span style="color: Red;">*</span></td><td>                                                            收货人邮编：
                                                        </td><td><asp:TextBox ID="TB_ZipCode" runat="server"></asp:TextBox></td></tr><tr><td>                                                            收货人手机：
                                                        </td><td><asp:TextBox ID="TB_Mobile" runat="server"></asp:TextBox><span style="color: Red;">*</span></td><td>                                                            &nbsp;
                                                        </td><td>                                                            &nbsp;
                                                        </td></tr></tbody></table></fieldset><br /><fieldset><legend>配送信息</legend><asp:RadioButtonList ID="RBL_DeliveryMethod" runat="server"></asp:RadioButtonList></fieldset><br /><fieldset><legend>支付方式</legend><asp:RadioButtonList ID="RBL_PaymentMethod" runat="server"></asp:RadioButtonList></fieldset><br /><fieldset><legend>其他</legend><table cellspacing="0" cellpadding="4" width="98%" align="center"><tbody><tr><td>                                                            是否需要发票：
                                                        </td><td colspan="3" height="16"><asp:RadioButtonList ID="RBL_NeedInvoice" runat="server" RepeatDirection="Horizontal"><asp:ListItem Selected="True" Value="0">不需要</asp:ListItem><asp:ListItem Value="1">需要</asp:ListItem></asp:RadioButtonList></td></tr><tr><td>                                                            发票说明：
                                                        </td><td colspan="3"><asp:TextBox ID="TB_InvoiceContent" runat="server" Width="290px"></asp:TextBox></td></tr><tr><td>                                                            &nbsp;
                                                        </td><td>                                                            &nbsp;
                                                        </td><td>                                                            &nbsp;
                                                        </td><td>                                                            &nbsp;
                                                        </td></tr><tr><td>                                                            订单备注：
                                                        </td><td colspan="3"><asp:TextBox ID="TB_Remark" runat="server" Height="120px" TextMode="MultiLine" Width="650px"></asp:TextBox></td></tr></tbody></table></fieldset><br /><div style="width: 80%; margin-left: auto; margin-right: auto; text-align: center"><asp:Button ID="BT_OK" runat="server" CssClass="btn" OnClick="BT_OK_Click" Text="生成订单" />                                            &nbsp;&nbsp;&nbsp;&nbsp;
                                            <asp:Button ID="BT_Back" runat="server" CssClass="btn" Text="返回购物车" /></div><br /></ContentTemplate></asp:UpdatePanel></div></td></tr></table></td></tr><tr><td>                &nbsp;
            </td></tr></table><script language="javascript" type="text/javascript">      //Ajax显示购物车界面
                ShowShopingCart(<%=Request["ModelID"] %>);
    </script></form></body></html>