⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 checkout.aspx.cs

📁 一个很好的网上购物系统!进行了新的修改具有很多的功能!
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Checkout : System.Web.UI.Page
{
    double cartSubTotal = 0;
    void Page_Load(object sender, EventArgs e)
    {

        //this page MUST be protected by SSL!
        string thisUrl=Request.Url.AbsoluteUri;
        //if (!thisUrl.StartsWith("https")) {
            //redirect to a secure URL
            //Response.Redirect(SiteConfiguration.SecureURL + "/checkout.aspx");
        //}

        trContinue.Visible = SiteConfiguration.UseDirectPay;
        pnlDirectPay.Visible = SiteConfiguration.UseDirectPay;
        tblExpress.Visible = !SiteConfiguration.UsePayPalPaymentsStandard;
        
        if (!Page.IsPostBack)
        {
            
            //check the config file to make sure they need to login
            if (SiteConfiguration.RequireLogin == "checkout")
            {
                //if they are not logged in, then send them to the login page
                if (!User.Identity.IsAuthenticated)
                {
                    Response.Redirect("login.aspx?ReturnUrl=checkout.aspx");
                }
            }

            //load the profile
            this.LoadProfile();
            BindOrder();
        }

    }
    void BindOrder() {

        ShoppingCart cart = ShoppingCartManager.GetCart();
        cartSubTotal = cart.SubTotal;
        dgBasket.DataSource = cart.Items;
        dgBasket.DataBind();


    }
    string GetUserEmail() {
        //get the user's data
        MembershipUser thisUser = Membership.GetUser(User.Identity.Name);
        return thisUser.Email;

    }
    void LoadProfile() {

        txtShipFirst.Text = Profile.Commerce.ShipFirst;
        txtShipLast.Text = Profile.Commerce.ShipLast;
        txtShipCity.Text = Profile.Commerce.ShipCity;
        txtShipZip.Text = Profile.Commerce.ShipZip;
        txtShipPhone.Text = Profile.Commerce.ShipPhone;
        txtShipAddress2.Text = Profile.Commerce.ShipAddress2;
        txtShipAddress.Text = Profile.Commerce.ShipAddress1;
        txtShipEmail.Text = GetUserEmail();
        LocationSelector1.LoadDrops(Profile.Commerce.ShipState, Profile.Commerce.ShipCountry);

    }
    void SetProfile() {
        Profile.Commerce.ShipFirst = txtShipFirst.Text;
        Profile.Commerce.ShipLast = txtShipLast.Text;
        Profile.Commerce.ShipAddress1 = txtShipAddress.Text;
        Profile.Commerce.ShipAddress2 = txtShipAddress2.Text;
        Profile.Commerce.ShipCity = txtShipCity.Text;
        Profile.Commerce.ShipState = LocationSelector1.GetSelectedState();
        Profile.Commerce.ShipCountry = LocationSelector1.GetSelectedCountry(); ;
        Profile.Commerce.ShipPhone = txtShipPhone.Text;
        Profile.Commerce.ShipZip = txtShipZip.Text;
        Profile.Save();
    }

    protected void imgPayPal_Click(object sender, ImageClickEventArgs e) {
        SetExpressOrder();
    }
    void SetExpressOrder() {
        //use the API to get the SetCheckout response.
        //Then, redirect to PayPal
        ShoppingCart cart = ShoppingCartManager.GetCart();

        Commerce.PayPal.APIWrapper wrapper = new Commerce.PayPal.APIWrapper(
            SiteConfiguration.PayPalAPIAccountName, SiteConfiguration.PayPalAPIAccountPassword,
            SiteConfiguration.PayPalAPICertificationPath, SiteConfiguration.PayPalAPICertificationPassword);
        string sEmail = GetUserEmail();

        try {
            string baseURL = Request.Url.AbsoluteUri.Replace("checkout.aspx", "");
            string successURL = baseURL + "checkoutconfirm.aspx";
            string cancelURL = Request.Url.AbsoluteUri;

            string ppToken = wrapper.SetExpressCheckout(sEmail, cart.SubTotal,
               successURL, cancelURL);
            string sUrl = "https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + ppToken;
            if (SiteConfiguration.UseSandbox) {
                sUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=" + ppToken;
            }
                
            Response.Redirect(sUrl);
        } catch (Exception x) {
            pnlError.Visible = true;
            lblError.Text = x.Message;
        }
    }
    void ShowMessage(string sMessage) {
        pnlError.Visible = true;
        lblError.Text = sMessage;
    }

    protected void btnContinue_Click(object sender, EventArgs e) {
        //save up the shipping info
        SetProfile();
        string nextUrl = "billing.aspx";
        if (SiteConfiguration.UsePayPalPaymentsStandard)
        {
            nextUrl = "checkoutconfirm.aspx?st=1";
        }
        Response.Redirect(nextUrl);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -