Пример #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //---------Master page section
        if (!IsPostBack)
        {
            if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://peptechcorp.com") || HttpContext.Current.Request.Url.ToString().ToLower().Contains("https://peptechcorp.com"))
            {
                HttpContext.Current.Response.Status = "301 Moved Permanently";
                HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("http://peptechcorp.com", "http://www.peptechcorp.com").Replace("https://peptechcorp.com", "https://www.peptechcorp.com"));
            }
            //else
            //{
            //    if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("/creditcard.aspx"))
            //    {
            //        if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://"))
            //            Response.Redirect(Request.Url.ToString().Replace("http://", "https://"));
            //    }
            //    else
            //    {
            //        if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("https://"))
            //            Response.Redirect(Request.Url.ToString().Replace("https://", "http://"));
            //    }
            //}
        }

        Session["UserID"] = Session["SessionID"];

        if (Session["mainuserid"] != null && Session["title"] != null)
        {
            s3.Visible           = false;
            lnkmyaccount.Visible = true;
            lblUser.Text         = "Welcome " + Session["title"].ToString();
            lnkstatus.Text       = "Sign Out";
            hypsignin.Visible    = false;
        }
        else
        {
            s1.Visible     = false;
            s2.Visible     = false;
            hypsignin.Text = "<a href='Login.aspx' class='blueheading' style='font-weight:bold'>Sign In!</a>";
            lnkstatus.Text = "New Account";
        }

        try
        {
            string    SqlStrItem  = "select total from " + customUtility.DBPrefix + "shoppingBagTmp where Userid='" + Session["UserID"] + "' ";
            DataTable dtitemcount = customUtility.GetTableData(SqlStrItem).Tables[0];
            int       itemcount   = dtitemcount.Rows.Count;
            int       i           = 0;
            float     totalitem   = 0;
            int       ss;
            for (i = 0; i < itemcount; i++)
            {
                totalitem += float.Parse(dtitemcount.Rows[i]["Total"].ToString());
            }
            float     chrg   = 0F;
            DataTable dtchrg = customUtility.GetTableData("select shippingcharge from " + customUtility.DBPrefix + "shippingtmp where userid='" + Session["userid"] + "'").Tables[0];
            if (dtchrg.Rows.Count > 0)
            {
                chrg = float.Parse(dtchrg.Rows[0]["shippingcharge"].ToString());
            }


            if (Request.Url.ToString().Contains("CreditCard.aspx"))
            {
                lnkbasket.Visible = true;
                lnkbasket.Text    = "My Cart &nbsp;" + itemcount.ToString() + " items " + "-" + string.Format("{0:C}", totalitem + chrg);
            }
            else
            {
                lnkbasket.Visible = true;
                lnkbasket.Text    = "My Cart &nbsp;" + itemcount.ToString() + " items " + "-" + string.Format("{0:C}", totalitem);
            }
        }
        catch { }

        //--------Credit Card  Section
        if (Session["mainuserid"] == null || Session["mainuserid"] == "")
        {
            Response.Redirect(ConfigurationManager.AppSettings["websitepath1"] + "login.aspx");
        }

        string scriptBlock = "<script type=\"text/javascript\">\n";

        scriptBlock += "var ClientID, CardNumber, CardType, ExpMon, ExpYear, CVVNo;\n";
        scriptBlock += "window.onload = function(){\n";
        // scriptBlock += "ClientID = \"" + ((ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1")).ClientID + "\";\n";
        scriptBlock += "CardNumber = document.getElementById(ClientID + \"_txtCreditCardNumber\");\n";
        scriptBlock += "CardType = document.getElementById(ClientID + \"_cboCardType\");\n";
        scriptBlock += "ExpMon = document.getElementById(ClientID + \"_cboExpMonth\");\n";
        scriptBlock += "ExpYear = document.getElementById(ClientID + \"_cboExpYear\");\n";
        scriptBlock += "CVVNo = document.getElementById(ClientID + \"_txtCSVNumber\");\n";
        scriptBlock += "Terms = document.getElementById(ClientID + \"_chkTerms\");\n";
        scriptBlock += "}</script>";

        if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "CreditCardInit"))
        {
            ClientScript.RegisterClientScriptBlock(this.GetType(), "CreditCardInit", scriptBlock);
        }

        string scriptUrl = "js/creditcard_validation.js";

        if (!ClientScript.IsClientScriptIncludeRegistered(this.GetType(), "CreditCardValidator"))
        {
            ClientScript.RegisterClientScriptInclude(this.GetType(), "CreditCardValidator", scriptUrl);
        }

        if (Session["UserID"] != null)
        {
            if (Session["UserID"].ToString().Length != 0)
            {
                UserId = Session["UserID"].ToString();
            }
        }

        if (!Page.IsPostBack)
        {
            DataTable dtcheck = customUtility.GetTableData("select orderid from " + customUtility.DBPrefix + "order where UserID='" + Session["UserID"].ToString().Replace("'", "''") + "'").Tables[0];
            if (dtcheck.Rows.Count <= 0)
            {
                Response.Redirect(ConfigurationManager.AppSettings["websitepath1"] + "emptyshopbag.aspx");
            }
            if (Session["orderno"] != null)
            {
                hidorderno.Value = Session["orderno"].ToString();
            }

            rblorder.Items.FindByValue("0").Selected = true;
            for (int i = 1; i <= 12; i++)
            {
                cboExpMonth.Items.Add(new ListItem(i.ToString().PadLeft(2, '0'), i.ToString().PadLeft(2, '0')));
            }

            for (int i = DateTime.Today.Year; i <= (DateTime.Today.Year + 20); i++)
            {
                cboExpYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
            }

            Session["shipp"]    = shipp;
            stotal              = shipp;
            ViewState["stotal"] = stotal;
            fillgridview();

            if (Session["mainuserid"] != null || Session["mainuserid"] != "")
            {
                string    strpostatus = "select PurchaseOrderNo from " + customUtility.DBPrefix + "Memberlist where id=" + Session["mainuserid"];
                DataTable dtpostatus  = customUtility.GetTableData(strpostatus).Tables[0];
                if (dtpostatus.Rows.Count > 0)
                {
                    if (dtpostatus.Rows[0]["PurchaseOrderNo"].ToString().ToLower().Equals("true"))
                    {
                        rblorder.Enabled = true;
                    }
                    else
                    {
                        rblorder.Enabled = false;
                    }
                }
            }
        }
    }