2012년 2월 10일 금요일
..:: Learn » 쇼핑몰 프로젝트 » [3] 회원관리 » 01. 회원 가입 ::..
최소화(Minimize)Register.ascx

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

<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; // 서버컨트롤이 포스트백이 일어나지 않도록
}

// 아이디 중복 검사 페이지 오픈
function OpenCheckID()
{
  window.open('./CheckID.aspx?txtUserID=<%= txtUserID.ClientID %>','','width=400,height=200');
  return false;
}
</script>

<table border="0" cellpadding="5" width="100%">
    <tr>
        <td>
            <h3>
                회원가입</h3>
            <font face="굴림"><font style="font-size: 9pt; color: #ff0000">회원 가입 - 다음 필드들을 채워주세요.
            </font>
                <hr width="100%" size="1">
                <font color="#ff0000">
                    <br />
                </font>
                <table id="Table1" style="border-collapse: collapse" bordercolor="black" cellspacing="0"
                    rules="none" width="575" align="center" bgcolor="white">
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                <font color="#ff0000">*</font>아이디 :
                            </p>
                        </td>
                        <td width="475">
                            <asp:TextBox ID="txtUserID" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                MaxLength="10" Width="150px" BorderColor="InactiveCaptionText"></asp:TextBox><font
                                    face="굴림">&nbsp;
                                    <asp:Button ID="btnCheckID" runat="server" BorderWidth="1px" BorderStyle="Groove"
                                        Width="122px" BorderColor="InactiveCaptionText" Text="아이디 중복 확인" CausesValidation="False"
                                        OnClick="btnCheckID_Click"
                                        OnClientClick="return OpenCheckID();return false;"></asp:Button></font>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                <font color="#ff0000">*</font>비밀번호 :
                            </p>
                        </td>
                        <td width="475">
                            <asp:TextBox ID="txtPassword" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                MaxLength="10" Width="150px" BorderColor="InactiveCaptionText" TextMode="Password"></asp:TextBox><font
                                    face="굴림">&nbsp; 비밀번호 확인 :
                                    <asp:TextBox ID="txtPasswordConfirm" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                        MaxLength="10" Width="150px" BorderColor="InactiveCaptionText" TextMode="Password"></asp:TextBox></font><font
                                            face="굴림">&nbsp;</font>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                <font color="#ff0000">*</font>이 &nbsp;름 :
                            </p>
                        </td>
                        <td width="475">
                            <asp:TextBox ID="txtCustomerName" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                MaxLength="10" Width="150px" BorderColor="InactiveCaptionText"></asp:TextBox><font
                                    face="굴림">&nbsp;</font>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                이메일 :
                            </p>
                        </td>
                        <td width="475">
                            <asp:TextBox ID="txtEmailAddress" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                Width="150px" BorderColor="InactiveCaptionText"></asp:TextBox><font face="굴림">&nbsp;
                                    <asp:CheckBox ID="chkMailing" runat="server" Text="메일링 가입"></asp:CheckBox></font>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                <font color="#ff0000">*</font>주민번호 :
                            </p>
                        </td>
                        <td width="475">
                            <asp:TextBox ID="txtSsn1" runat="server" BorderWidth="1px" BorderStyle="Solid" MaxLength="10"
                                Width="120px" BorderColor="InactiveCaptionText"></asp:TextBox>-
                            <asp:TextBox ID="txtSsn2" runat="server" BorderWidth="1px" BorderStyle="Solid" MaxLength="10"
                                Width="120px" BorderColor="InactiveCaptionText"></asp:TextBox><font face="굴림">&nbsp;
                                    <asp:Button ID="btnSsn" runat="server" BorderWidth="1px"
                                BorderStyle="Groove" Width="122px"
                                        BorderColor="InactiveCaptionText" Text="주민번호 중복 확인" CausesValidation="False"
                                        OnClick="btnSsn_Click" Visible="False"></asp:Button></font>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                전화번호 :
                            </p>
                        </td>
                        <td width="475">
                            <asp:TextBox ID="txtPhone1" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                MaxLength="10" Width="50px" BorderColor="InactiveCaptionText"></asp:TextBox>-
                            <asp:TextBox ID="txtPhone2" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                MaxLength="10" Width="50px" BorderColor="InactiveCaptionText"></asp:TextBox>-
                            <asp:TextBox ID="txtPhone3" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                MaxLength="10" Width="50px" BorderColor="InactiveCaptionText"></asp:TextBox><font
                                    face="굴림">&nbsp;</font>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                휴대폰 :
                            </p>
                        </td>
                        <td width="475">
                            <asp:TextBox ID="txtMobile1" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                MaxLength="10" Width="50px" BorderColor="InactiveCaptionText"></asp:TextBox>-
                            <asp:TextBox ID="txtMobile2" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                MaxLength="10" Width="50px" BorderColor="InactiveCaptionText"></asp:TextBox>-
                            <asp:TextBox ID="txtMobile3" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                MaxLength="10" Width="50px" BorderColor="InactiveCaptionText"></asp:TextBox><font
                                    face="굴림">&nbsp;</font>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                <font color="#ff0000">*</font>우편번호 :
                            </p>
                        </td>
                        <td width="475">
                            <asp:TextBox ID="txtZip" runat="server" BorderWidth="1px" BorderStyle="Solid" MaxLength="10"
                                Width="150px" BorderColor="InactiveCaptionText"></asp:TextBox>
                            <input type="button" value="우편번호 검색"
                                onclick="OpenGetZipCode('<%= txtZip.ClientID %>','<%= txtAddress.ClientID %>');" />                               
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                <font color="#ff0000">*</font> 집주소 :
                            </p>
                        </td>
                        <td width="475">
                            <asp:TextBox ID="txtAddress" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                Width="90%" BorderColor="InactiveCaptionText"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                나머지 주소&nbsp;:
                            </p>
                        </td>
                        <td width="475">
                            <asp:TextBox ID="txtAddressDetail" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                Width="240px" BorderColor="InactiveCaptionText"></asp:TextBox><font face="굴림">&nbsp;</font>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                생년월일 :
                            </p>
                        </td>
                        <td width="475">
                            <font face="굴림">
                                <asp:TextBox ID="txtBirthYear" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                    MaxLength="10" Width="50px" BorderColor="InactiveCaptionText"></asp:TextBox>년
                                <asp:TextBox ID="txtBirthMonth" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                    MaxLength="10" Width="50px" BorderColor="InactiveCaptionText"></asp:TextBox>월
                                <asp:TextBox ID="txtBirthDay" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                    MaxLength="10" Width="50px" BorderColor="InactiveCaptionText"></asp:TextBox>일&nbsp;
                                <asp:RadioButtonList ID="lstBirthStatus" runat="server" Width="144px" RepeatDirection="Horizontal"
                                    RepeatLayout="Flow">
                                    <asp:ListItem Value="양">양력</asp:ListItem>
                                    <asp:ListItem Value="음">음력</asp:ListItem>
                                </asp:RadioButtonList>
                            </font>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                직 업 :
                            </p>
                        </td>
                        <td width="475">
                            <font face="굴림">
                                <asp:DropDownList ID="lstJob" runat="server">
                                    <asp:ListItem Value="직업선택" Selected="True">직업선택</asp:ListItem>
                                    <asp:ListItem Value="회사원">회사원</asp:ListItem>
                                    <asp:ListItem Value="백수">백수</asp:ListItem>
                                </asp:DropDownList>
                                &nbsp;
                                </font>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                홈페이지 :
                            </p>
                        </td>
                        <td width="475">
                            <font face="굴림">
                                <asp:TextBox ID="txtHomepage" runat="server" BorderWidth="1px" BorderStyle="Solid"
                                    Width="192px" BorderColor="InactiveCaptionText"></asp:TextBox>&nbsp;</font>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                취 미 :
                            </p>
                        </td>
                        <td width="475">
                            <font face="굴림">
                                <asp:TextBox ID="txtHobby" runat="server" BorderWidth="1px" BorderStyle="Solid" MaxLength="10"
                                    Width="104px" BorderColor="InactiveCaptionText"></asp:TextBox>&nbsp;</font>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef">
                            <p align="right">
                                결 혼 :
                            </p>
                        </td>
                        <td width="475">
                            <font face="굴림">
                                <asp:RadioButtonList ID="lstWedding" runat="server" Width="144px" RepeatDirection="Horizontal"
                                    RepeatLayout="Flow">
                                    <asp:ListItem Value="0" Selected="True">미혼</asp:ListItem>
                                    <asp:ListItem Value="1">기혼</asp:ListItem>
                                </asp:RadioButtonList>
                                &nbsp;</font>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" width="100" bgcolor="#efefef" style="height: 22px">
                            <p align="right">
                                성 별&nbsp;:
                            </p>
                        </td>
                        <td width="475" style="height: 22px">
                            <font face="굴림">
                                <asp:RadioButtonList ID="lstGender" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
                                    <asp:ListItem Value="1" Selected="True">남자</asp:ListItem>
                                    <asp:ListItem Value="2">여자</asp:ListItem>
                                </asp:RadioButtonList>
                            </font>
                        </td>
                    </tr>
                    <tr>
                        <td align="center" bgcolor="#efefef">
                            <p align="right">
                                소 개 :
                            </p>
                        </td>
                        <td>
                            <asp:TextBox ID="txtIntro" runat="server" BorderWidth="1px" BorderStyle="Solid" Width="90%"
                                BorderColor="InactiveCaptionText" TextMode="MultiLine" Rows="10" Height="64px"></asp:TextBox>
                        </td>
                    </tr>
                </table>
                <p>
                </p>
                <p align="center">
                    <a href="list.aspx"></a>
                </p>
                <p align="center">
                    <asp:Button ID="btnRegister" runat="server" BorderWidth="1px" BorderStyle="Groove"
                        Width="80px" BorderColor="InactiveCaptionText" Text="회원가입" OnClick="btnRegister_Click">
                    </asp:Button><font face="굴림">&nbsp;</font><font face="굴림">&nbsp;</font><asp:Button
                        ID="btnDefault" runat="server" BorderWidth="1px" BorderStyle="Groove" Width="80px"
                        BorderColor="InactiveCaptionText" Text="취소" CausesValidation="False" OnClick="btnDefault_Click">
                    </asp:Button></p>
                <p align="center">
                    <asp:Label ID="lblDisplay" runat="server" ForeColor="Red"></asp:Label></p>
                <p align="center">
                    <asp:RequiredFieldValidator ID="valUserID" runat="server" ErrorMessage="아이디를 입력하세요."
                        ControlToValidate="txtUserID" Display="None"></asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="valPassword" runat="server" ErrorMessage="비밀번호를 입력하세요."
                        ControlToValidate="txtPassword" Display="None"></asp:RequiredFieldValidator>
                    <asp:CompareValidator ID="valPasswordConfirm" runat="server" ErrorMessage="비밀번호를 확인하세요."
                        ControlToValidate="txtPassword" Display="None" ControlToCompare="txtPasswordConfirm"></asp:CompareValidator>
                    <asp:RequiredFieldValidator ID="valCustomerName" runat="server" ErrorMessage="이름을 입력하세요."
                        ControlToValidate="txtCustomerName" Display="None"></asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="valSsn1" runat="server" ErrorMessage="주민등록번호 앞자리를 입력하세요."
                        ControlToValidate="txtSsn1" Display="None"></asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="valSsn2" runat="server" ErrorMessage="주민등록번호 뒷자리를 입력하세요."
                        ControlToValidate="txtSsn2" Display="None"></asp:RequiredFieldValidator>
                            <font face="굴림">
                                <asp:RequiredFieldValidator ID="valJob" runat="server" ControlToValidate="lstJob"
                                    ErrorMessage="직업을 선택해 주세요." InitialValue="직업선택" Display="None"></asp:RequiredFieldValidator></font>
                        </p>
                <p align="center">
                    <asp:ValidationSummary ID="valSummary" runat="server" ShowSummary="False" ShowMessageBox="True"
                        DisplayMode="List"></asp:ValidationSummary>
                </p>
                <p>
                    <font face="굴림"></font>&nbsp;</p>
            </font>
        </td>
    </tr>
</table>

최소화(Minimize)Register.ascx.cs

using System;
using System.Configuration;
using System.Data;
using System.Web.UI;
using System.Data.SqlClient;

public partial class RegisterControl : System.Web.UI.UserControl
{
    #region Event Handlers
    protected void Page_Load(object sender, System.EventArgs e)
    {
        // 여기에 사용자 코드를 배치하여 페이지를 초기화합니다.
    }

    // 회원 가입 버튼
    protected void btnRegister_Click(object sender, System.EventArgs e)
    {
        // 쇼핑 카드 업데이트
        ShoppingCartDB shoppingCart = new ShoppingCartDB();
        String tempCartId = shoppingCart.GetShoppingCartId();

        // 고객 클래스 인스턴스 생성
        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.EmailAddress = this.txtEmailAddress.Text;
        customerDetails.MemberDivision = 1;
        //
        customerDetails.UserID = this.txtUserID.Text;
        customerDetails.Password = Security.Encrypt(txtPassword.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.BirthYear = this.txtBirthYear.Text;
        customerDetails.BirthMonth = this.txtBirthMonth.Text;
        customerDetails.BirthDay = this.txtBirthDay.Text;
        customerDetails.BirthStatus = this.lstBirthStatus.SelectedValue;
        customerDetails.Gender = Convert.ToInt32(this.lstGender.SelectedValue);
        customerDetails.Job = this.lstJob.SelectedValue;
        customerDetails.Wedding = Convert.ToInt32(this.lstWedding.SelectedValue);
        customerDetails.Hobby = this.txtHobby.Text;
        customerDetails.Homepage = this.txtHomepage.Text;
        customerDetails.Intro = this.txtIntro.Text;
        customerDetails.Mailing = (this.chkMailing.Checked) ? 1 : 0;
        customerDetails.Mileage = 0;

        // 고객 정보 입력
        string customerId = accountSystem.AddCustomer(customerDetails);

        if (customerId != "")
        {
            System.Web.Security.FormsAuthentication.SetAuthCookie(customerId, false);

            shoppingCart.MigrateCart(tempCartId, customerId);

            Response.Cookies["Shopping_CustomerName"].Value =
                Server.HtmlEncode(this.txtCustomerName.Text);
        }
        else
        {
            lblDisplay.Text = "Registration failed:&nbsp; That email address is already registered.<br /><img align=left height=1 width=92 src=images/1x1.gif>";
        }

        string strJs = @"
   <script language='javascript'>
   window.alert('회원가입을 축하드립니다.');
   location.href='Default.aspx';
   </script>
  ";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "js", strJs);

        //Response.Redirect("Default.aspx");
    }

    // 주민 번호 찾기 버튼
    protected void btnSsn_Click(object sender, System.EventArgs e)
    {
        SqlConnection objCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        objCon.Open();

        SqlCommand objCmd = new SqlCommand();
        objCmd.Connection = objCon;
        objCmd.CommandText = "Select Ssn1 From Customers Where Ssn1 = '" + this.txtSsn1.Text + "' And Ssn2 = '" + this.txtSsn2.Text + "'";
        objCmd.CommandType = CommandType.Text;
        string strMsg = String.Empty;
        SqlDataReader objDr = objCmd.ExecuteReader();
        if (objDr.Read())
        {
            strMsg = "이미 등록된 주민번호입니다.";
        }
        else
        {
            strMsg = "사용할 수 있는 주민번호입니다.";
        }
        objDr.Close(); objCon.Close();

        string strJs = "<script>";
        strJs += "alert('" + strMsg + "');";
        strJs += "</script>";
        Page.ClientScript.RegisterStartupScript(this.GetType(), "aaa", strJs);//앞
    }

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

    // 아이디 중복 확인 버튼
    protected void btnCheckID_Click(object sender, System.EventArgs e)
    {
        string strJs = @"
   <script language='javascript'>
   window.open('./CheckID.aspx','','width=400,height=200');
   </script>
  ";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "checkID", strJs);
    }

    // 취소 버튼
    protected void btnDefault_Click(object sender, System.EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
    #endregion
}

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