2012년 2월 10일 금요일
..:: Learn » 쇼핑몰 프로젝트 » [4] 상품관리 » 15. 상품 상세 보기 ::..
최소화(Minimize)ProductDetails.ascx

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ProductDetails.ascx.cs"
    Inherits="ProductDetailsControl" %>
<%@ Register Src="/website/portals/0/AlsoBought.ascx" TagName="AlsoBought" TagPrefix="uc2" %>
<%@ Register Src="/website/portals/0/ReviewList.ascx" TagName="ReviewList" TagPrefix="uc1" %>

<script language="javascript" type="text/javascript">
function ShowImage(ProductImage)
{
  window.open("ShowImages.aspx?ProductImage=" + ProductImage, "show", "width=400,height=430");
}
</script>

<table border="0" style="width: 100%">
    <tr>
        <td>
            <h1>
                상품 상세 보기</h1>
        </td>
    </tr>
</table>
<br />
<table border="0" cellpadding="5" style="width: 100%">
    <tr>
        <td>
        </td>
        <td>
        </td>
        <td>
        </td>
    </tr>
    <tr>
        <td rowspan="7">
            <asp:ImageButton ID="imgProductImage" runat="server" Height="200px" Width="200px"
                OnClick="btnViewImage_Click" />
            <br />
            <asp:Button ID="btnViewImage" runat="server" Text="큰 이미지 보기" Width="198px" OnClick="btnViewImage_Click" />
        </td>
        <td>
            모델번호 :
        </td>
        <td>
            <asp:Label ID="lblModelNumber" runat="server"></asp:Label>
        </td>
    </tr>
    <tr>
        <td>
            제조회사 :
        </td>
        <td>
            <asp:Label ID="lblCompany" runat="server"></asp:Label>
        </td>
    </tr>
    <tr>
        <td>
            상품명 :
        </td>
        <td>
            <asp:Label ID="lblModelName" runat="server"></asp:Label>
        </td>
    </tr>
    <tr>
        <td>
            판매가격 :
        </td>
        <td>
            <asp:Label ID="lblSellPrice" runat="server"></asp:Label>
        </td>
    </tr>
    <tr>
        <td>
            재고수량 :
        </td>
        <td>
            <asp:Label ID="lblProductCount" runat="server"></asp:Label>
        </td>
    </tr>
    <tr>
        <td>
            구매수량 :
        </td>
        <td>
            <asp:TextBox ID="txtQuantity" runat="server" Width="51px">1</asp:TextBox>개
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <asp:Button ID="btnAddToCart" runat="server" Text="장바구니 담기" OnClick="btnAddToCart_Click"
                ValidationGroup="ProductDetails" />
        </td>
    </tr>
    <tr>
        <td colspan="3">
            <uc2:AlsoBought ID="AlsoBought1" runat="server" />
        </td>
    </tr>
    <tr>
        <td colspan="3" style="height: 120px">
            <br />
            <h3>
                상품 상세 설명</h3>
            <hr />
            <asp:Label ID="lblDescription" runat="server" Width="100%"></asp:Label>
            <hr />
        </td>
    </tr>
</table>
<br />
<uc1:ReviewList ID="ReviewList1" runat="server" />
<br />
<br />
<asp:RequiredFieldValidator ID="valQuantity" runat="server" ControlToValidate="txtQuantity"
    Display="None" ErrorMessage="구매수량을 입력하세요." ValidationGroup="ProductDetails" SetFocusOnError="True"></asp:RequiredFieldValidator>
<br />
<asp:RangeValidator ID="valQuantiyRange" runat="server" ControlToValidate="txtQuantity"
    Display="None" ErrorMessage="구매수량은 1개부터 1000개까지 입니다." MaximumValue="1000" MinimumValue="1"
    Type="Integer" ValidationGroup="ProductDetails" SetFocusOnError="True"></asp:RangeValidator>
<br />
<asp:ValidationSummary ID="valSummary" runat="server" ShowMessageBox="True" ShowSummary="False"
    ValidationGroup="ProductDetails" />

최소화(Minimize)ProductDetails.ascx.cs

using System;
using System.Web.UI;

public partial class ProductDetailsControl : System.Web.UI.UserControl
{
    #region Event Handlers
    protected void Page_Load(object sender, System.EventArgs e)
    {
        // ProductList.aspx에서 넘겨져 온 값 받기
        int ProductID = Convert.ToInt32(Request["ProductID"]);

        // 인스턴스 생성
        ProductsDB products = new ProductsDB();
        ProductDetails productDetails =
            products.GetProductDetails(ProductID);//반환(Factory Method)

        // 바인딩
        this.lblModelNumber.Text = productDetails.ModelNumber;
        this.lblModelName.Text = productDetails.ModelName;
        this.lblSellPrice.Text =
            Convert.ToString(productDetails.SellPrice);
        this.lblCompany.Text = productDetails.Company;
        this.lblDescription.Text = // 탭 및 개행문자 처리
            RedPlus.Library.Board.ConvertToHtml(productDetails.Description);
        this.lblProductCount.Text =
            Convert.ToString(productDetails.ProductCount);
        this.imgProductImage.ImageUrl =
            "ProductImages/" + productDetails.ProductImage;
        ViewState["ProductImage"] =
            productDetails.ProductImage;//뷰스테이트

        //Cache["ProductImage"] =
        // productDetails.ProductImage;//캐시
        //[1] 리뷰 클래스에게 상품번호 전달
        ReviewList1.ProductID = ProductID;//
    }

    // 장바구니 담기
    protected void btnAddToCart_Click(object sender, System.EventArgs e)
    {
        string strUrl = String.Format(
            "AddToCart.aspx?ProductID={0}&Quantity={1}"
                , Request["ProductID"], this.txtQuantity.Text);
        Response.Redirect(strUrl);//상품코드와 수량을 가지고 전송
    }

    // 큰 이미지 보기
    protected void btnViewImage_Click(object sender, System.EventArgs e)
    {
        string strJs = @"
    <script language='JavaScript'>
    window.open('ShowImage.aspx?ProductImage="
            + ViewState["ProductImage"]
            + @"','','width=400,height=430');
    </script>
   ";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "openImg", strJs);
    }
    #endregion
}

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