Ejemplo n.º 1
0
        private void Button1_Click(object sender, System.EventArgs e)
        {
            OTC.Web.Promotion.OTCPromotion p = new OTC.Web.Promotion.OTCPromotion(Convert.ToInt32(this.ddPromotions.SelectedValue));
            OTCProduct pd  = new OTCProduct(Convert.ToInt32(this.lstProducts.SelectedValue));
            OTCShoppingCart c = new OTCShoppingCart(this.m_page.ShoppingCartId);
            OTCShoppingCartItem i = new OTCShoppingCartItem();
            i.ProductID = pd.ProductId;
            i.ProductPrice = pd.Price;
            i.ItemCount = 1;
            c.AddCartItem(i);
            c.ApplyPromotion(this.ddPromotions.SelectedItem.Text,c.ShoppingCartID);
            c = null;
            c = new OTCShoppingCart(this.m_page.ShoppingCartId);
            this.txtProductPrice.Text = c.CartTotal.ToString("c");
            Response.Write(this.m_page.ShoppingCartId);
            p.AddPromotionUsage(1,999999);

            /*
            OTCProduct pd  = new OTCProduct(Convert.ToInt32(this.lstProducts.SelectedValue));
            if(p.DiscountAmount > 0)
            {
                string displayPrice = Convert.ToDouble(pd.Price - p.DiscountAmount).ToString("c");
                this.txtProductPrice.Text = pd.Price.ToString("c");
                this.txtPromotionPrice.Text = displayPrice;
            }

            if(p.DiscountPercentage > 0)
            {
                string displayPrice = Convert.ToDouble(pd.Price - (pd.Price * p.DiscountPercentage)).ToString("c");
                this.txtProductPrice.Text = pd.Price.ToString("c");
                this.txtPromotionPrice.Text = displayPrice;
            }
            */
        }
Ejemplo n.º 2
0
        protected void btnCheckout_Click(object sender, System.EventArgs e)
        {
            if(!(doValidate()))
                return;

            int sessionOrderId = Convert.ToInt32(Session["SID"]);
            ITC itc = new ITC();
            OTCShoppingCart cart	= new OTCShoppingCart(this.m_shoppingCartId);

            string promotionKey = Request.Form["promotion"].Length > 0 ? Request.Form["promotion"] : "";
            if (promotionKey.Length > 0)
            {
                //If we have a promotion, apply here & the next instance will recognize it. We could
                //have a function that would reload the shopping cart? This is much easier for the sake of time.
                cart.ApplyPromotion(promotionKey, this.m_shoppingCartId);
            }

            //BG - Added swap product sku for international and canadian
            string shippingType = String.Empty;
            if (isInternationalAutoShip()) shippingType = "International";
            else if (isCanadianAutoShip()) shippingType = "Canadian";

            if (!String.IsNullOrEmpty(shippingType))
            {
                foreach (var item in cart.CartItems) swapProduct(shippingType, item.ProductID);
            }

            //refresh cart
            cart = new OTCShoppingCart(this.m_shoppingCartId);

            OTCSalesOrder order		= new OTCSalesOrder();
            order.ShoppingCartId    = cart.ShoppingCartID;
            order.OTCPromotionId    = cart.OTCPromotionId;
            order.Address			= this.txtAddress.Text;
            order.City				= this.txtCity.Text;
            order.Country           = this.ddCountry.SelectedItem.Text;
            order.EmailAddress		= this.txtEmailAddress.Text;
            order.FirstName			= this.txtFirstName.Text;
            order.LastName			= this.txtLastName.Text;
            order.Phone             = this.txtPhone.Text;
            order.OrderCost			= cart.CartTotal;
            order.SalesTax          = this.m_salesTax;
            order.OTCSiteId			= itc.SiteId;
            order.ShippingAddress	= this.txtShippingAddress.Text;
            order.ShippingCity		= this.txtShippingCity.Text;
            order.ShippingCost		= getShippingCost(this.ddShippingMethods.SelectedItem.Value);
            order.ShippingFirstName = this.txtShippingFirstName.Text;
            order.ShippingLastName	= this.txtShippingLastName.Text;
            //order.ShippingState		= this.txtShippingStateProvince.Text;
            order.ShippingState     = this.getShippingStateOrProvince();
            order.ShippingZip		= this.txtShippingZipPostalCode.Text; //bug fix
            //order.State				= this.ddState.SelectedIndex > 0 ? this.ddState.SelectedItem.Text : "";
            order.State             = this.getBillingStateOrProvince();
            order.ShippingPhone     = this.txtShippingPhone.Text;
            order.Zip				= this.txtZipPostalCode.Text;
            order.ShippingCountryId = Convert.ToInt32(this.ddShippingCountry.SelectedValue);
            order.ShippingCountry   = this.ddShippingCountry.SelectedItem.Text;
            order.ShippingMethod    = this.ddShippingMethods.SelectedItem.Text;
            order.ShippingEmailAddress = this.txtShippingEmailAddress.Text;
            order.Comments			= this.txtComments.Value.Length > 0 ? this.txtComments.Value : "";
            int id = order.Add();
            OTCCreditCard cc        = new OTCCreditCard();
            cc.OTCSalesOrderId      = order.OTCSalesOrderId;
            cc.OTCSiteMemberId      = order.OTCSiteMemberId;
            cc.CardNumber           = this.txtCardNumber.Text;
            cc.CardType             = this.ddCCType.SelectedValue;
            cc.ExpirationMonth      = this.ddMonth.SelectedValue;
            cc.ExpirationYear       = this.ddYear.SelectedValue;
            cc.IISSessionId         = Session.SessionID;
            cc.Add();

            if(Convert.ToBoolean(Session["WantsMemberShip"]))
            {
                OTCPromotion.AddMemberPromotion(order.OTCSiteMemberId,1);
            }

            //if(this.txtComments.Value.Length > 0)
            //{
            //	OTCContact contact = new OTCContact();
            //	contact.SiteId = 7;
            //	contact.EmailAddress = this.txtEmailAddress.Text;
            //	contact.FirstName = this.txtFirstName.Text;
            //	contact.LastName = this.txtLastName.Text;
            //	contact.Comment1 = this.txtComments.Value;
            //	contact.Add();
            //}

            try
            {
                string sql = "";
                this.m_db.Open();
                string howDidYouHear = Request.Form["txtHowDidYouHear"];

                if(howDidYouHear.Length > 0)
                {
                    sql = "spInsertOTCSiteMemberQuestionAnswerAffiliation "
                        + "@OTCSiteMemberId = " + order.OTCSiteMemberId + ","
                        + "@OTCSiteMemberQuestionId = 1,"
                        + "@OTCSiteMemberAnswerID = 1,"
                        + "@AnswerText = " + OTCDatabase.SqlFormat(howDidYouHear)
                        ;
                    this.m_db.SendSQLUpdate(sql);
                }

                foreach(string s in Request.Form.ToString().Split('&')){
                    if(s.IndexOf("mq_") > -1){
                        int questionId = Convert.ToInt32(s.Split('=')[0].Replace("mq_",""));
                        int answerId   = Convert.ToInt32(s.Split('=')[1]);
                        sql = "spInsertOTCSiteMemberQuestionAnswerAffiliation "
                            + "@OTCSiteMemberId = " + order.OTCSiteMemberId + ","
                            + "@OTCSiteMemberQuestionId = " + questionId + ","
                            + "@OTCSiteMemberAnswerID = " + answerId
                            ;
                        this.m_db.SendSQLUpdate(sql);
                    }
                }

                sql = "spUpdateCartAbandonmentOrderID @sessionId = " + OTCDatabase.SqlFormat(Session.SessionID);
                sql += ",@cartId = " + cart.ShoppingCartID;
                sql += ",@OrderId = " + order.OTCSalesOrderId;
                this.m_db.SendSQLUpdate(sql);

                this.m_db.ReleaseConnection();
            }

            catch(Exception ex) {/*do nothing*/}
            OTCEncryption crypt = new OTCEncryption(7);
            cart = new OTCShoppingCart(Session.SessionID);
            Session["shoppingCartId"]   = cart.AddNew();

            Session["SID"] = 0;

            if (Page.IsValid)
            {
                Session["SessionID"] = Session.SessionID;
                Response.Redirect("../order/creditcardpost.aspx?OID=" + id.ToString() + "&_ga=" + Request.QueryString["_ga"] + "&site=" + Request.QueryString["site"]);

            }
        }