// 선택 합계 구하기(옵션)
        protected void SelectedTotal(object sender, EventArgs e)
        {
            // 그리드뷰의 아이템 개수만큼 반복
            for (int i = 0; i < ctlShoppingCartList.Rows.Count; i++)
            {
                // 선택 체크박스 값 가져오기
                if (((CheckBox)ctlShoppingCartList.Rows[i].FindControl("Select")).Checked)
                {
                    // 수량에 대한 SubTotal
                    quantitySelectedTotal += Convert.ToInt32(((TextBox)ctlShoppingCartList.Rows[i].FindControl("Quantity")).Text);
                    // 가격에 대한 SubTotal
                    priceSelectedTotal += Convert.ToInt32(ctlShoppingCartList.Rows[i].Cells[5].Text.Replace(",", String.Empty));
                    // 소계에 대한 SubTotal
                    extendedSelectedAmountTotal += Convert.ToInt32(ctlShoppingCartList.Rows[i].Cells[6].Text.Replace(",", ""));
                }
            }//end for
            this.lblQuantitySelectedTotal.Text       = quantitySelectedTotal.ToString();
            this.lblPriceSelectedTotal.Text          = priceSelectedTotal.ToString();
            this.lblExtendedSelectedAmountTotal.Text = extendedSelectedAmountTotal.ToString();
            // 총합
            // 쇼핑카트 인스턴스 생성
            ShoppingCartDB cart = new ShoppingCartDB();
            // 고유 키 값 생성
            string cartId = cart.GetShoppingCartId();

            // 총합
            lblTotal.Text = String.Format("{0:###,###}", cart.GetTotal(cartId));
        }
Exemplo n.º 2
0
        protected void btnLogin_Click(object sender, System.EventArgs e)
        {
            // 오래된 쇼핑카트 아이디 저장
            ShoppingCartDB shoppingCart = new ShoppingCartDB();
            string         tempCartID   = shoppingCart.GetShoppingCartId();

            // 로그인 정보가 맞는지 확인
            CustomersDB accountSystem = new CustomersDB();
            // 로그인이 정상적으로 진행되면 고객번호 : 1번 고객, 2번 고객
            string customerId = accountSystem.Login(txtUserID.Text, Security.Encrypt(txtPassword.Text));

            if (customerId != null)
            {
                // 현재 쇼핑카트 정보를 고객 정보로 마이그레이트
                shoppingCart.MigrateCart(tempCartID, customerId);

                // 고객의 모든 정보 값 반환
                CustomerDetails customerDetails = accountSystem.GetCustomerDetails(customerId);

                // 고객의 이름을 쿠키에 저장
                // Response.Cookies["Shopping_CustomerName"].Value = customerDetails.CustomerName;
                HttpCookie customerName = new HttpCookie("Shopping_CustomerName", Server.UrlEncode(customerDetails.CustomerName));
                customerName.HttpOnly = true;
                Response.Cookies.Add(customerName);

                // 고객의 이이디를 쿠키에 저장
                Response.Cookies["Shopping_UserID"].Value = customerDetails.UserID;

                // 고객 이름 저장 체크박스 확인
                if (chkRememberLogin.Checked == true)
                {
                    // 앞으로 한달간 저장
                    Response.Cookies["Shopping_CustomerName"].Expires = DateTime.Now.AddMonths(1);
                }

                // 원래 요청했었던 페이지로 이동
                if (Request.ServerVariables["SCRIPT_NAME"].ToLower().EndsWith("checklogin.aspx"))
                {
                    System.Web.Security.FormsAuthentication.SetAuthCookie(customerId, chkRememberLogin.Checked); // 인증값 부여
                    Response.Redirect("CheckOut.aspx");                                                          // 현재 페이지가 로그인 체크 페이지면 주문서 페이지로 이동
                }
                else
                {
                    // 따로 지정하지 않았으면 기본값으로 ~/Default.aspx로 이동
                    System.Web.Security.FormsAuthentication.RedirectFromLoginPage(customerId, chkRememberLogin.Checked);
                }
            }
            else
            {
                lblError.Text = "로그인에 실패했습니다. 다시 로그인하세요.";
            }
        }
        /// <summary>
        /// 쇼핑카트 내용 업데이트
        /// </summary>
        private void UpdateShoppingCartDatabase()
        {
            // 쇼핑카트 객체 생성
            ShoppingCartDB cart = new ShoppingCartDB();

            // 고유 키 값 반환
            string cartId = cart.GetShoppingCartId();

            // 그리드뷰의 아이템 개수만큼 반복
            for (int i = 0; i < ctlShoppingCartList.Rows.Count; i++)
            {
                // 수량 텍스트박스 값 가져오기
                TextBox quantityTxt = (TextBox)ctlShoppingCartList.Rows[i].FindControl("Quantity");

                // 삭제 체크박스 값 가져오기
                CheckBox remove = (CheckBox)ctlShoppingCartList.Rows[i].FindControl("Remove");

                int quantity;
                try
                {
                    // 수량 값 가져오기
                    quantity = Int32.Parse(quantityTxt.Text);

                    // 원래 바인딩될 때의 수량과 현재 텍스트박스의 수량이 틀리고, 삭제 체크박스가 선택되어 있다면...
                    if (quantity != (int)ctlShoppingCartList.DataKeys[i].Value || remove.Checked == true)
                    {
                        // 해당 상품코드값 가져오기
                        Label lblProductID = (Label)ctlShoppingCartList.Rows[i].FindControl("ProductID");

                        // 수량이 0이거나 삭제가 체크되었다면, 삭제 로직 실행
                        if (quantity == 0 || remove.Checked == true)
                        {
                            cart.RemoveItem(cartId, Int32.Parse(lblProductID.Text));
                        }
                        else // 그렇지 않으면 업데이트 로직 실행
                        {
                            cart.UpdateItem(cartId, Int32.Parse(lblProductID.Text), quantity);
                        }
                    }
                }
                catch
                {
                    lblErrorMessage.Text = "고객님께서 입력하신 자료가 잘못되었습니다.";
                }
            } // end for
        }
        // 주문 버튼
        protected void btnCheckOut_Click(object sender, System.EventArgs e)
        {
            // 쇼핑카트 업데이트
            UpdateShoppingCartDatabase();

            ShoppingCartDB cart   = new ShoppingCartDB();
            string         cartId = cart.GetShoppingCartId();

            // 장바구니 검사
            if (cart.GetItemCount(cartId) != 0)
            {
                Response.Redirect("CheckLogin.aspx");//주문 페이지로 이동
            }
            else
            {
                lblErrorMessage.Text = "장바구니가 비어있습니다.";
            }
        }
        /// <summary>
        /// 쇼핑카트 리스트
        /// 현재 접속자에 대한 장바구니 리스트를 출력
        /// </summary>
        private void PopulateShoppingCartList()
        {
            // 쇼핑카트 인스턴스 생성
            ShoppingCartDB cart = new ShoppingCartDB();
            // 고유 키 값 생성
            string cartId = cart.GetShoppingCartId();

            // 현재 사용자에 해당하는 상품이 없다면... 아이템 카운트가 0이라면..
            if (cart.GetItemCount(cartId) == 0)
            {
                this.MultiView1.ActiveViewIndex = 1;
                lblErrorMessage.Text            = "장바구니가 비어있습니다.";
            }
            else
            {
                this.MultiView1.ActiveViewIndex = 0;
                // 바인딩
                ctlShoppingCartList.DataSource = cart.GetItems(cartId);
                ctlShoppingCartList.DataBind();

                // 총합 : 정수 3자리마다 콤마 찍기 : String.Format("{0:###,###}", 정수형데이터);
                lblTotal.Text = String.Format("{0:###,###}", cart.GetTotal(cartId));
            }
        }
Exemplo n.º 6
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            // 장바구니 담는 기본 수량은 1로 초기화
            int intQuantity = 1;

            // 만약에 넘겨져 온 수량값이 있다면 해당 값으로 초기화
            if (Request["Quantity"] != null)
            {
                intQuantity = Int32.Parse(Request["Quantity"]);
            }

            // 넘겨져 온 상품코드가 있다면, 해당 상품코드를 장바구니 테이블에 추가
            if (Request.Params["ProductID"] != null)
            {
                // 쇼핑카트 클래스 인스턴스 생성
                ShoppingCartDB cart = new ShoppingCartDB();

                // 고유 키값 생성 : GUID값(접속자의 유일한 값)
                // 회원로그인했을 경우에는 cartId에 CustomerID가 저장
                String cartId = cart.GetShoppingCartId();
                // String cartId = Session.SessionID; // 고전 방식

                // 장바구니 담기
                cart.AddItem(cartId, Int32.Parse(Request.Params["ProductID"]), intQuantity);
            }

            if (Request["State"] == null) // 장바구니 담기
            {
                // 장바구니 테이블로 이동
                Response.Redirect("~/ShoppingCart.aspx");
            }
            else // 즉시구매
            {
                Response.Redirect("CheckLogin.aspx"); // 주문 페이지로 이동
            }
        }
Exemplo n.º 7
0
        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     = "<hr />당신이 주문하신 주문번호는 : " + orderId + "입니다.<br />";
                    lblMessage.Text    += "<a href='Default.aspx'>홈으로 가기</a><hr />";
                    cmdCheckOut.Visible = false;// 구매 버튼 숨기기
                }
            }

            // 메일전송 : 주문 내역을 메일 또는 SMS로 보내주는 코드는 이 부분에 위치
            // System.Web.Mail.SmtpMail.Send("*****@*****.**", this.txtEmailAddress.Text, "주문이 완료되었습니다.", "주문번호 : " + orderId + ", 주문비밀번호 : " + this.txtOrdersPassword.Text);
        }
Exemplo n.º 8
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            // 체크박스 컨트롤에 자바스크립트 이벤트 적용
            this.chkDelivery.Attributes["onclick"] = "return CopyForm();";

            // 현재 사용자의 쇼핑카트 아이디 가져오기 : 회원 또는 비회원
            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;
            }
        }
Exemplo n.º 9
0
        // 회원 가입 버튼
        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 != "")
            {
                // 회원가입 후 바로 로그인 처리 : 1, 2, 3
                System.Web.Security.FormsAuthentication.SetAuthCookie(customerId, false);

                shoppingCart.MigrateCart(tempCartId, customerId);
                // 현재 접속자의 이름은 따로 쿠키에 저장
                //Response.Cookies["Shopping_CustomerName"].Value = Server.HtmlEncode(this.txtCustomerName.Text); // 홍길동
                HttpCookie customerName = new HttpCookie("Shopping_CustomerName", Server.UrlEncode(txtCustomerName.Text));
                customerName.HttpOnly = true;
                Response.Cookies.Add(customerName);
            }
            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");
        }