Exemple #1
0
        //Checkout Button (only visible if gridview has data)
        protected void btnCheckout_Click(object sender, EventArgs e)
        {
            shoppingCart = (ArrayList)Session["ShoppingCart"];
            JavaScriptSerializer js  = new JavaScriptSerializer();
            APICalls             api = new APICalls();
            SPCaller             spc = new SPCaller();

            Customer c = new Customer();

            c.Email      = Session["Username"].ToString();
            c.CustomerID = spc.GetCustomerIDByEmail(c.Email);

            //Adding each product into the database
            foreach (Product p in shoppingCart)
            {
                //String jsonCheckout = js.Serialize(p);
                try
                {
                    bool data = api.RecordPurchase(url, p.ID.ToString(), p.Quantity, "1", "0", DateTime.Now.ToString(), DateTime.Now.TimeOfDay.ToString(), c);
                    if (data == true)
                    {
                        Response.Redirect("Confirmation.aspx", false);
                    }
                    else
                    {
                        lblMessage.Text = "A problem occurred while checking out.";
                    }
                }
                catch (Exception ex)
                {
                    lblMessage.Text = "Error: " + ex.Message;
                }
            }
        }
Exemple #2
0
        protected void Session_End(object sender, EventArgs e)
        {
            if (Session["ShoppingCart"] != null)
            {
                ArrayList cart = (ArrayList)Session["ShoppingCart"];

                BinaryFormatter serializer = new BinaryFormatter();
                MemoryStream    memStream  = new MemoryStream();
                serializer.Serialize(memStream, cart);

                byte[] cartBytes = memStream.ToArray();

                SPCaller   spc        = new SPCaller();
                DBConnect  objDB      = new DBConnect();
                SqlCommand objCommand = new SqlCommand();
                objCommand.CommandType = CommandType.StoredProcedure;
                objCommand.CommandText = "TP_StoreCart";

                int custID = spc.GetCustomerIDByEmail(Session["Username"].ToString());

                objCommand.Parameters.AddWithValue("@CustomerID", custID);
                objCommand.Parameters.AddWithValue("@Cart", cartBytes);
                objDB.DoUpdateUsingCmdObj(objCommand);
            }

            if (Session["WishList"] != null)
            {
                ArrayList wishList = (ArrayList)Session["WishList"];

                BinaryFormatter serializer = new BinaryFormatter();
                MemoryStream    memStream  = new MemoryStream();
                serializer.Serialize(memStream, wishList);

                byte[] wlBytes = memStream.ToArray();

                SPCaller   spc        = new SPCaller();
                DBConnect  objDB      = new DBConnect();
                SqlCommand objCommand = new SqlCommand();
                objCommand.CommandType = CommandType.StoredProcedure;
                objCommand.CommandText = "TP_StoreWishList";

                int custID = spc.GetCustomerIDByEmail(Session["Username"].ToString());

                objCommand.Parameters.AddWithValue("@CustomerID", custID);
                objCommand.Parameters.AddWithValue("@WishList", wlBytes);
                objDB.DoUpdateUsingCmdObj(objCommand);
            }
        }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["Username"] == null)
                {
                    Response.Redirect("Login.aspx");
                    return;
                }

                string email = Session["Username"].ToString();
                customerID             = spc.GetCustomerIDByEmail(email);
                ddlMonth.SelectedValue = currMonth;
                ddlYear.SelectedValue  = currYear;
            }
        }
Exemple #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Username"] == null)
            {
                Response.Redirect("Login.aspx");
                return;
            }
            else
            {
                string username = Session["Username"].ToString();
                customerID = spc.GetCustomerIDByEmail(username);

                if (!IsPostBack)
                {
                    myDS = spc.GetCCByCustomerID(customerID);
                    if (myDS.Tables[0].Rows.Count > 0)
                    {
                        for (int i = 0; i < myDS.Tables[0].Rows.Count; i++)
                        {
                            ddlCard.Items.Add(myDS.Tables[0].Rows[i][1].ToString());
                        }

                        int cardID = int.Parse(ddlCard.SelectedValue);
                        myDS = spc.GetCCInfoByCardID(cardID);

                        if (myDS.Tables[0].Rows.Count > 0)
                        {
                            txtCardNumber.Text = myDS.Tables[0].Rows[0][0].ToString();
                            string   expiration    = myDS.Tables[0].Rows[0][1].ToString();
                            string[] arrExpiration = expiration.Split('/');

                            ddlMonth.SelectedValue = arrExpiration[0].Trim();
                            ddlYear.SelectedValue  = arrExpiration[1].Trim();
                        }
                    }
                }
            }
        }
Exemple #5
0
        protected void btnEmpty_Click(object sender, EventArgs e)
        {
            gvCart.DataSource = new DataTable();
            gvCart.DataBind();

            Session.Remove("WishList");
            Response.Redirect("EmptyWishList.aspx", false);

            DBConnect  objDB      = new DBConnect();
            SPCaller   spc        = new SPCaller();
            SqlCommand objCommand = new SqlCommand();

            objCommand.CommandType = CommandType.StoredProcedure;
            objCommand.CommandText = "TP_EmptyWishList";

            int custID = spc.GetCustomerIDByEmail(Session["Username"].ToString());

            objCommand.Parameters.AddWithValue("@CustomerID", custID);
            objCommand.Parameters.Add("@New", SqlDbType.VarBinary, -1);
            objCommand.Parameters["@New"].Value = DBNull.Value;

            objDB.DoUpdateUsingCmdObj(objCommand);
        }
Exemple #6
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string username;
            string password;

            username = txtEmail.Text;
            password = txtPassword.Text;

            DBConnect db = new DBConnect();
            DataSet   ds = new DataSet();

            SqlCommand objcommand = new SqlCommand();

            //if dropdown selection is Customer
            if (ddlLoginType.Text == "Customer")
            {
                objcommand.CommandType = CommandType.StoredProcedure;
                objcommand.CommandText = "TP_CustomerLogin";
                objcommand.Parameters.AddWithValue("@username", username);
                objcommand.Parameters.AddWithValue("@password", password);

                ds = db.GetDataSetUsingCmdObj(objcommand);

                if (ds.Tables[0].Rows.Count == 0)
                {
                    lblLoginErrorMessage.Text = "Incorrect username or password";
                }
                else
                {
                    if (chkbxRememberMe.Checked == true)
                    {
                        Response.Cookies["Username"].Value   = txtEmail.Text;
                        Response.Cookies["Password"].Value   = txtPassword.Text;
                        Response.Cookies["Username"].Expires = DateTime.Now.AddDays(15);
                        Response.Cookies["Password"].Expires = DateTime.Now.AddDays(15);
                    }
                    else
                    {
                        Response.Cookies["Username"].Expires = DateTime.Now.AddDays(-1);
                        Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);
                    }

                    Session["AccountType"] = 0;
                    Session["Username"]    = username;
                    Session["Password"]    = password;

                    //check if customer already has cart in db
                    SPCaller   spc        = new SPCaller();
                    DBConnect  objDB      = new DBConnect();
                    SqlCommand objCommand = new SqlCommand();
                    objCommand.CommandType = CommandType.StoredProcedure;
                    objCommand.CommandText = "TP_GetCart";

                    int custID = spc.GetCustomerIDByEmail(Session["Username"].ToString());
                    objCommand.Parameters.AddWithValue("@CustomerID", custID);

                    DataSet myDS = objDB.GetDataSetUsingCmdObj(objCommand);
                    if (myDS.Tables[0].Rows[0][0] != System.DBNull.Value)
                    {
                        byte[]          cartBytes    = (byte[])myDS.Tables[0].Rows[0][0];
                        BinaryFormatter deserializer = new BinaryFormatter();
                        MemoryStream    ms           = new MemoryStream(cartBytes);

                        ArrayList shoppingCart = (ArrayList)deserializer.Deserialize(ms);
                        Session["ShoppingCart"] = shoppingCart;
                    }

                    objCommand             = new SqlCommand();
                    objCommand.CommandType = CommandType.StoredProcedure;
                    objCommand.CommandText = "TP_GetWishList";
                    objCommand.Parameters.AddWithValue("@CustomerID", custID);

                    myDS = objDB.GetDataSetUsingCmdObj(objCommand);
                    if (myDS.Tables[0].Rows[0][0] != System.DBNull.Value)
                    {
                        byte[]          wlBytes      = (byte[])myDS.Tables[0].Rows[0][0];
                        BinaryFormatter deserializer = new BinaryFormatter();
                        MemoryStream    ms           = new MemoryStream(wlBytes);

                        ArrayList wishList = (ArrayList)deserializer.Deserialize(ms);
                        Session["WishList"] = wishList;
                    }
                    Response.Redirect("CustomerHome.aspx");
                }
            }
            //if dropdown selection is Merchant
            if (ddlLoginType.Text == "Merchant")
            {
                objcommand.CommandType = CommandType.StoredProcedure;
                objcommand.CommandText = "TP_MerchantLogin";
                objcommand.Parameters.AddWithValue("@username", username);
                objcommand.Parameters.AddWithValue("@password", password);

                ds = db.GetDataSetUsingCmdObj(objcommand);

                if (ds.Tables[0].Rows.Count == 0)
                {
                    lblLoginErrorMessage.Text = "Incorrect username or password";
                }
                else
                {
                    if (chkbxRememberMe.Checked == true)
                    {
                        Response.Cookies["Username"].Value   = txtEmail.Text;
                        Response.Cookies["Password"].Value   = txtPassword.Text;
                        Response.Cookies["Username"].Expires = DateTime.Now.AddDays(15);
                        Response.Cookies["Password"].Expires = DateTime.Now.AddDays(15);
                    }
                    else
                    {
                        Response.Cookies["Username"].Expires = DateTime.Now.AddDays(-1);
                        Response.Cookies["Password"].Expires = DateTime.Now.AddDays(-1);
                    }

                    Session["AccountType"] = 1;
                    Session["Username"]    = username;
                    Session["Password"]    = password;
                    Response.Redirect("MerchantHome.aspx", false);
                }
            }
        }