2012년 2월 10일 금요일
..:: Learn » 쇼핑몰 프로젝트 » [5] 주문관리 » 22. 주문서 페이지 ::..
최소화(Minimize)CheckOut.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="CheckOut.ascx.cs" Inherits="CheckOutControl" %>

<script language="Javascript" type="text/javascript">
// 우편번호 검색 페이지 오픈
function OpenGetZipCode(Zip, Address)
{
  window.open('./GetZipCode.aspx?Zip=' + Zip + '&Address=' + Address,'','width=400,height=300,scrollbars=yes');
  return false; // 서버컨트롤이 포스트백이 일어나지 않도록
}

//[!] 폼을 동기화 하기 : 이전 자료를 임시 보관하는 기능 포함
//[1] 이름과 체크박스만 처리
var name = ""; // 이름
var dname = ""; // 수취인 이름
//[2] 배송지 정보에 복사된 정보 임시 보관
function InitValue()
{
    name = document.getElementById( // 서버 컨트롤의 ClientID로 가져오기
        '<%= txtCustomerName.ClientID %>').value;
    dname = document.getElementById( // 실제로 렌더링된 클라이언트아이디로 가져오기
        "ctl00_ContentPlaceHolder1_CheckOut1_txtDeliveryCustomerName").value;
}
//[3] 폼을 동기화 시키기
function CopyForm()
{
    if (document.getElementById('<%= chkDelivery.ClientID %>').checked) // 체크되었다면, 폼을 동기화
    {
        InitValue(); // 이전에 작성된 자료를 임시 보관
        document.getElementById('<%= txtDeliveryCustomerName.ClientID %>').value = name;
    }
    else // 그렇지 않으면, 배송지 정보 클리어
    {
        document.getElementById('<%= txtDeliveryCustomerName.ClientID %>').value = dname; // 
    }   
}
</script>

<h3>
    주문서작성 및 결제방법선택</h3>
<asp:Label ID="lblMessage" runat="server">
주문하는 상품과 결제 금액이 정확한지를 확인해 주십시오.<br />
구매자의 정보와 배송지의 정보를 정확하게 작성해 주십시오.
</asp:Label>
<hr />
<table cellspacing="0" cellpadding="0" width="550" border="0">
    <tr valign="top">
        <td style="height: 179px">
            <strong>주문 상세 내역(Products+ShoppingCart 테이블에서 가져옴)</strong>&nbsp;<br />
            <asp:DataGrid ID="ctlCheckOutList" Width="100%" BorderColor="#CCCCCC" CellPadding="3"
                Font-Size="8pt" AutoGenerateColumns="False" runat="server" BorderStyle="None"
                BorderWidth="1px" BackColor="White" Font-Names="Verdana">
                <FooterStyle ForeColor="#000066" CssClass="cartlistfooter" BackColor="White"></FooterStyle>
                <SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#669999"></SelectedItemStyle>
                <AlternatingItemStyle CssClass="CartListItemAlt"></AlternatingItemStyle>
                <ItemStyle ForeColor="#000066" CssClass="CartListItem"></ItemStyle>
                <HeaderStyle Font-Bold="True" ForeColor="White" CssClass="CartListHead" BackColor="#006699">
                </HeaderStyle>
                <Columns>
                    <asp:BoundColumn DataField="ModelName" HeaderText="상품명"></asp:BoundColumn>
                    <asp:BoundColumn DataField="ModelNumber" HeaderText="모델번호"></asp:BoundColumn>
                    <asp:BoundColumn DataField="Quantity" HeaderText="수량"></asp:BoundColumn>
                    <asp:BoundColumn DataField="SellPrice" HeaderText="가격" DataFormatString="{0:###,###}">
                    </asp:BoundColumn>
                    <asp:BoundColumn DataField="ExtendedAmount" HeaderText="소계" DataFormatString="{0:###,###}">
                    </asp:BoundColumn>
                </Columns>
                <PagerStyle HorizontalAlign="Left" ForeColor="#000066" BackColor="White" Mode="NumericPages">
                </PagerStyle>
            </asp:DataGrid>
            <br />
            <b>총합: </b>
            <asp:Label ID="lblTotal" runat="server" />원
            <asp:Label ID="lblDelivery" runat="server" Font-Italic="True" ForeColor="Silver"
                Text="(배송비 2500원 포함된 가격임)" Visible="False"></asp:Label>&nbsp;
        </td>
    </tr>
</table>
<hr />
<table id="Table1" cellspacing="0" cellpadding="0" width="550" border="0">
    <tr valign="top">
        <td>
            <p>
                <strong>주문자 정보 입력(Customers 테이블 사용)</strong></p>
            <p>
                성명 :
                <asp:TextBox ID="txtCustomerName" runat="server"></asp:TextBox><br />
                전화번호 :
                <asp:TextBox ID="txtPhone1" runat="server" Width="56px">02</asp:TextBox>-
                <asp:TextBox ID="txtPhone2" runat="server" Width="48px">123</asp:TextBox>-
                <asp:TextBox ID="txtPhone3" runat="server" Width="56px">1234</asp:TextBox>&nbsp;<br />
                휴대폰 :
                <asp:TextBox ID="txtMobile1" runat="server" Width="48px">010</asp:TextBox>-
                <asp:TextBox ID="txtMobile2" runat="server" Width="48px">123</asp:TextBox>-
                <asp:TextBox ID="txtMobile3" runat="server" Width="48px">1234</asp:TextBox><br />
                우편번호 :
                <asp:TextBox ID="txtZip" runat="server" Width="80px" ReadOnly="True">111-111</asp:TextBox>

                <script language="Javascript" type="text/javascript">
                function GetCheckOutZipCode()
                {
                    window.open("GetZipCode.aspx?Zip=<%= txtZip.ClientID %>","GetCheckOutZipCode","width=470,height=300,scrollbars=yes");
                }
                </script>

                <input type="button" value="우편번호 검색" onclick="OpenGetZipCode('<%= txtZip.ClientID %>','<%= txtAddress.ClientID %>');" />
                <br />
                주소 :
                <asp:TextBox ID="txtAddress" runat="server" Width="320px" ReadOnly="True">서울</asp:TextBox><br />
                상세주소 :
                <asp:TextBox ID="txtAddressDetail" runat="server" Width="288px">우리집</asp:TextBox><br />
                주민등록번호 :
                <asp:TextBox ID="txtSsn1" runat="server" Width="72px">111111</asp:TextBox>-
                <asp:TextBox ID="txtSsn2" runat="server" Width="72px">2222222</asp:TextBox><br />
                이메일 :
                <asp:TextBox ID="txtEmailAddress" runat="server">a@a.com</asp:TextBox><br />
                <asp:Panel ID="MemberDivisionPanel" runat="server">
                    회원으로&nbsp;주문하시면 마일리지가 적립됩니다.
                    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="Register.aspx">회원가입</asp:HyperLink><br />
                    주문비밀번호 :
                    <asp:TextBox ID="txtOrdersPassword" runat="server">1234</asp:TextBox>(비회원 주문시 주문
                    확인시 필요)</asp:Panel>
            </p>
        </td>
    </tr>
</table>
<hr />
<asp:CheckBox ID="chkDelivery" runat="server" AutoPostBack="True"
    OnCheckedChanged="chkDelivery_CheckedChanged">
</asp:CheckBox>배송지 주소가 위 내용과 동일하면 클릭해주세요.
<hr />
<table id="Table2" cellspacing="0" cellpadding="0" width="550" border="0">
    <tr valign="top">
        <td width="100%">
            <strong>배송지 정보 입력(Delivery 테이블 사용)</strong>
            <br />
            성명 :
            <asp:TextBox ID="txtDeliveryCustomerName" runat="server"></asp:TextBox><br />
            전화번호 :
            <asp:TextBox ID="txtDeliveryTelePhone1" runat="server" Width="56px">02</asp:TextBox>-
            <asp:TextBox ID="txtDeliveryTelePhone2" runat="server" Width="48px">321</asp:TextBox>-
            <asp:TextBox ID="txtDeliveryTelePhone3" runat="server" Width="56px">4321</asp:TextBox>&nbsp;<br />
            휴대폰 :
            <asp:TextBox ID="txtDeliveryMobilePhone1" runat="server" Width="48px">010</asp:TextBox>-
            <asp:TextBox ID="txtDeliveryMobilePhone2" runat="server" Width="48px">321</asp:TextBox>-
            <asp:TextBox ID="txtDeliveryMobilePhone3" runat="server" Width="48px">4321</asp:TextBox><br />
            우편번호 :
            <asp:TextBox ID="txtDeliveryZipCode" runat="server" Width="80px" ReadOnly="True">222-222</asp:TextBox>
            <input type="button" value="우편번호 검색" onclick="OpenGetZipCode('<%= txtDeliveryZipCode.ClientID %>','<%= txtDeliveryAddress.ClientID %>');" />
            <br />
            주소 :
            <asp:TextBox ID="txtDeliveryAddress" runat="server" Width="320px" ReadOnly="True">세울</asp:TextBox><br />
            상세주소 :
            <asp:TextBox ID="txtDeliveryAddressDetail" runat="server" Width="288px">너네집</asp:TextBox>
        </td>
    </tr>
</table>
<hr />
<table id="Table3" cellspacing="0" cellpadding="0" width="550" border="0">
    <tr valign="top">
        <td width="100%">
            <strong>기타 정보 입력(Message 테이블 사용)</strong><br />
            남길 메모 :
            <asp:TextBox ID="txtMessage" runat="server" Width="392px">신속/정확하게 가져다 주세요.</asp:TextBox>
        </td>
    </tr>
</table>
<hr />
<table id="Table4" cellspacing="0" cellpadding="0" width="550" border="0">
    <tr valign="top">
        <td width="100%">
            <strong>결제 방법 선택(Orders 테이블 사용)</strong><br />
            <asp:RadioButtonList ID="lstPayment" runat="server" RepeatDirection="Horizontal">
                <asp:ListItem Value="온라인입금 결제" Selected="True">온라인입금 결제</asp:ListItem>
                <asp:ListItem Value="신용카드 결제">신용카드 결제</asp:ListItem>
            </asp:RadioButtonList>
        </td>
    </tr>
</table>
<hr />
<asp:Button ID="cmdCheckOut" runat="server" Text="결제하기" OnClick="cmdCheckOut_Click">
</asp:Button>

최소화(Minimize)CheckOut.ascx.cs

using System;
using System.Web.UI;

public partial class CheckOutControl : System.Web.UI.UserControl
{
    #region Event Handlers
    protected void Page_Load(object sender, System.EventArgs e)
    {
        // 현재 사용자의 쇼핑카트 아이디 가져오기 : 회원 또는 비회원
        ShoppingCartDB cart = new ShoppingCartDB();
        String cartId = cart.GetShoppingCartId();

        // 현재 접속자의 장바구니 내용 읽어오기 : ASP.NET1.X 버전과 호환 테스트 위해 데이터그리드 사용하였음
        ctlCheckOutList.DataSource = cart.GetItems(cartId);
        ctlCheckOutList.DataBind();

        // 총합 출력하기 : 만약에 3만원 이상 구매시 배송료(2500원) 미포함
        //lblTotal.Text =
        //  String.Format("{0:###,###}", cart.GetTotal(cartId));
        int intTotal = cart.GetTotal(cartId);
        if (intTotal >= 30000)
        {
            lblTotal.Text = String.Format("{0:###,###}", intTotal);
        }
        else
        {
            this.lblDelivery.Visible = true;
            lblTotal.Text = String.Format("{0:###,###}", intTotal + 2500);
        }

        // 회원/비회원에 따른 폼 모양 정의
        if (Page.User.Identity.IsAuthenticated)
        {
            // 고객 정보 읽어오기
            string customerId = Page.User.Identity.Name.ToString();
            CustomersDB customerDB = new CustomersDB();
            CustomerDetails customerDetails = customerDB.GetCustomerDetails(customerId);

            // 고객 정보 바인딩
            // 주문자 정보 입력
            this.txtCustomerName.Text = customerDetails.CustomerName;
            this.txtPhone1.Text = customerDetails.Phone1;
            this.txtPhone2.Text = customerDetails.Phone2;
            this.txtPhone3.Text = customerDetails.Phone3;
            this.txtMobile1.Text = customerDetails.Mobile1;
            this.txtMobile2.Text = customerDetails.Mobile2;
            this.txtMobile3.Text = customerDetails.Mobile3;
            this.txtZip.Text = customerDetails.Zip;
            this.txtAddress.Text = customerDetails.Address;
            this.txtAddressDetail.Text = customerDetails.AddressDetail;
            this.txtSsn1.Text = customerDetails.Ssn1;
            this.txtSsn2.Text = customerDetails.Ssn2;
            this.txtEmailAddress.Text = customerDetails.EmailAddress;
            this.MemberDivisionPanel.Visible = false;
            // 배송지 정보 입력
            this.txtDeliveryCustomerName.Text = customerDetails.CustomerName;
            this.txtDeliveryTelePhone1.Text = customerDetails.Phone1;
            this.txtDeliveryTelePhone2.Text = customerDetails.Phone2;
            this.txtDeliveryTelePhone3.Text = customerDetails.Phone3;
            this.txtDeliveryMobilePhone1.Text = customerDetails.Mobile1;
            this.txtDeliveryMobilePhone2.Text = customerDetails.Mobile2;
            this.txtDeliveryMobilePhone3.Text = customerDetails.Mobile3;
            this.txtDeliveryZipCode.Text = customerDetails.Zip;
            this.txtDeliveryAddress.Text = customerDetails.Address;
            this.txtDeliveryAddressDetail.Text = customerDetails.AddressDetail;
        }
        else
        {
            this.MemberDivisionPanel.Visible = true;
        }
    }

    protected void cmdCheckOut_Click(object sender, System.EventArgs e)
    {
        // 쇼핑카트 클래스 인스턴스 생성
        ShoppingCartDB cart = new ShoppingCartDB();

        // 쇼핑카트 아아디 가져오기 : 회원
        string cartId = cart.GetShoppingCartId();

        // 주문번호 : 회원이든 비회원이든 주문번호는 생성(비회원이면, 주문정보 확인시 사용)
        int orderId = 0;

        // 회원/비회원에 따른 폼 모양 정의
        if (Page.User.Identity.IsAuthenticated)
        {
            // 고객코드 가져오기
            string customerId = Page.User.Identity.Name;

            // 주문 정보 클래스 사용
            OrderDetails orderDetails = new OrderDetails();
            orderDetails.CustomerID = customerId;
            // 배송비 포함 여부 : 3만원 이상
            orderDetails.TotalPrice = (cart.GetTotal(cartId) >= 30000) ? cart.GetTotal(cartId) : cart.GetTotal(cartId) + 2500;
            orderDetails.OrderStatus = "신규주문";
            orderDetails.Payment = this.lstPayment.SelectedValue;
            // 배송비 포함 여부 : 3만원 이상
            orderDetails.PaymentPrice = (cart.GetTotal(cartId) >= 30000) ? cart.GetTotal(cartId) : cart.GetTotal(cartId) + 2500;
            orderDetails.PaymentInfo = "미입금";
            orderDetails.DeliveryInfo = 1;//일단 회원...
            orderDetails.DeliveryStatus = "미배송";
            orderDetails.OrderIP = Request.UserHostAddress;
            orderDetails.Password = "";
            orderDetails.CartID = cartId;
            orderDetails.Message = this.txtMessage.Text;
            //
            orderDetails.CustomerName = this.txtCustomerName.Text;
            orderDetails.TelePhone =
                String.Format("{0}-{1}-{2}"
                , this.txtDeliveryTelePhone1.Text
                , this.txtDeliveryTelePhone2.Text
                , this.txtDeliveryTelePhone3.Text);
            orderDetails.MobilePhone =
                String.Format("{0}-{1}-{2}"
                , this.txtDeliveryMobilePhone1.Text
                , this.txtDeliveryMobilePhone2.Text
                , this.txtDeliveryMobilePhone3.Text);
            orderDetails.ZipCode = this.txtDeliveryZipCode.Text;
            orderDetails.Address = this.txtDeliveryAddress.Text;
            orderDetails.AddressDetail = this.txtDeliveryAddressDetail.Text;

            // 고객이면서 장바구니에 구매 상품이 담겨져 있다면,
            if ((cartId != null) && (customerId != null))
            {
                // 주문 클래스 인스턴스 생성
                OrdersDB ordersDatabase = new OrdersDB();
                // 주문 실행
                orderId = ordersDatabase.PlaceOrder(orderDetails);
                // 주문 완료 표시
                lblMessage.Text = "당신이 주문하신 주문번호는 : " + orderId + "입니다.";
                cmdCheckOut.Visible = false;// 구매 버튼 숨기기
            }
        }
        else // 비회원 주문 처리
        {
            // 고객 클래스 인스턴스 생성
            CustomersDB accountSystem = new CustomersDB();
            CustomerDetails customerDetails = new CustomerDetails();

            customerDetails.CustomerName = this.txtCustomerName.Text;
            customerDetails.Phone1 = this.txtPhone1.Text;
            customerDetails.Phone2 = this.txtPhone2.Text;
            customerDetails.Phone3 = this.txtPhone2.Text;
            customerDetails.Mobile1 = this.txtMobile1.Text;
            customerDetails.Mobile2 = this.txtMobile2.Text;
            customerDetails.Mobile3 = this.txtMobile3.Text;
            customerDetails.Zip = this.txtZip.Text;
            customerDetails.Address = this.txtAddress.Text;
            customerDetails.AddressDetail = this.txtAddressDetail.Text;
            customerDetails.Ssn1 = this.txtSsn1.Text;
            customerDetails.Ssn2 = this.txtSsn2.Text;
            customerDetails.EmailAddress = this.txtEmailAddress.Text;
            customerDetails.MemberDivision = 0;//비회원

            // 고객 정보 저장 및 고객 코드 반환
            string customerId = accountSystem.AddNonCustomer(customerDetails);

            // 주문 정보 클래스 사용
            OrderDetails orderDetails = new OrderDetails();
            orderDetails.CustomerID = customerId;
            orderDetails.TotalPrice = (cart.GetTotal(cartId) >= 30000) ? cart.GetTotal(cartId) : (cart.GetTotal(cartId) + 2500);
            orderDetails.OrderStatus = "신규주문";
            orderDetails.Payment = this.lstPayment.SelectedValue;
            orderDetails.PaymentPrice = (cart.GetTotal(cartId) >= 30000) ? cart.GetTotal(cartId) : (cart.GetTotal(cartId) + 2500);
            orderDetails.PaymentInfo = "미입금";
            orderDetails.DeliveryInfo = 0;// 비회원...
            orderDetails.DeliveryStatus = "미배송";
            orderDetails.OrderIP = Request.UserHostAddress;
            orderDetails.Password = this.txtOrdersPassword.Text;
            orderDetails.CartID = cartId;
            orderDetails.Message = this.txtMessage.Text;
            //
            orderDetails.CustomerName = this.txtCustomerName.Text;
            orderDetails.TelePhone =
                String.Format("{0}-{1}-{2}"
                , this.txtDeliveryTelePhone1.Text
                , this.txtDeliveryTelePhone2.Text
                , this.txtDeliveryTelePhone3.Text);
            orderDetails.MobilePhone =
                String.Format("{0}-{1}-{2}"
                , this.txtDeliveryMobilePhone1.Text
                , this.txtDeliveryMobilePhone2.Text
                , this.txtDeliveryMobilePhone3.Text);
            orderDetails.ZipCode = this.txtDeliveryZipCode.Text;
            orderDetails.Address = this.txtDeliveryAddress.Text;
            orderDetails.AddressDetail = this.txtDeliveryAddressDetail.Text;

            // 비회원이면서 장바구니에 구매 상품이 담겨져 있다면,
            if ((cartId != null) && (customerId != null))
            {
                // 주문 클래스 인스턴스 생성
                OrdersDB ordersDatabase = new OrdersDB();
                // 주문 실행
                orderId = ordersDatabase.PlaceOrder(orderDetails);
                // 주문 완료 표시
                lblMessage.Text = "당신이 주문하신 주문번호는 : " + orderId + "입니다.<br />";
                lblMessage.Text += "<a href='Default.aspx'>홈으로 가기</a>";
                cmdCheckOut.Visible = false;// 구매 버튼 숨기기
            }
        }

        // 메일전송
        //   System.Web.Mail.SmtpMail.Send(
        //    "admin@aaa.com"
        //    , this.txtEmailAddress.Text
        //    ,"주문이 완료되었습니다.","주문번호 : " + orderId
        //    + ", 주문비밀번호 : " + this.txtOrdersPassword.Text
        //   );
    }

    protected void chkDelivery_CheckedChanged(object sender, System.EventArgs e)
    {
        if (this.chkDelivery.Checked)//동일하다면...
        {
            this.txtDeliveryCustomerName.Text = this.txtCustomerName.Text;
            this.txtDeliveryTelePhone1.Text = this.txtPhone1.Text;
            this.txtDeliveryTelePhone2.Text = this.txtPhone2.Text;
            this.txtDeliveryTelePhone3.Text = this.txtPhone3.Text;
            this.txtDeliveryMobilePhone1.Text = this.txtMobile1.Text;
            this.txtDeliveryMobilePhone2.Text = this.txtMobile2.Text;
            this.txtDeliveryMobilePhone3.Text = this.txtMobile3.Text;
            this.txtDeliveryZipCode.Text = this.txtZip.Text;
            this.txtDeliveryAddress.Text = this.txtAddress.Text;
            this.txtDeliveryAddressDetail.Text = this.txtAddressDetail.Text;
        }
        else
        {
            this.txtDeliveryCustomerName.Text = "";
            this.txtDeliveryTelePhone1.Text = "";
            this.txtDeliveryTelePhone2.Text = "";
            this.txtDeliveryTelePhone3.Text = "";
            this.txtDeliveryMobilePhone1.Text = "";
            this.txtDeliveryMobilePhone2.Text = "";
            this.txtDeliveryMobilePhone3.Text = "";
            this.txtDeliveryZipCode.Text = "";
            this.txtDeliveryAddress.Text = "";
            this.txtDeliveryAddressDetail.Text = "";
        }
    }

    protected void btnZipCode_Click(object sender, System.EventArgs e)
    {
        string strJs = @"
   <script language='javascript'>
   window.open('./GetCheckOutZipCode.aspx','','width=400,height=300,scrollbars=yes');
   </script>
  ";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "GetZipCode", strJs);
    }

    protected void btnDeliveryZipCode_Click(object sender, System.EventArgs e)
    {
        string strJs = @"
   <script language='javascript'>
   window.open('./GetDeliveryZipCode.aspx','','width=400,height=300,scrollbars=yes');
   </script>
  ";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "GetZipCode", strJs);
    }
    #endregion
}

Copyright 2000-2011 by DotNetKorea all right reserved.   사용약관  개인정보취급방침