Esempio n. 1
0
        protected void Submit_Click(object sender, EventArgs e)
        {
            /*
             * Searches the user table for a matching user name and password
             * Populates the user object and saves it in the Session
             * Creates a shopping cart object and saves it in the Session
             * If user is ADMIN, enable Admin link on Master page
             */
            UserAcct     user = new UserAcct();
            ShoppingCart cart = new ShoppingCart();
            DataView     dv;

            dv = (DataView)sqldsSubmit.Select(DataSourceSelectArguments.Empty);

            try
            {
                user.UserID     = (int)dv.Table.Rows[0][0];
                user.Name       = (string)dv.Table.Rows[0][1];
                user.Role       = (string)dv.Table.Rows[0][2];
                user.Email      = (string)dv.Table.Rows[0][3];
                Session["User"] = user;
                Session["Cart"] = cart;
                Master.enableLogout();
                if (user.Role == "admin")
                {
                    Master.enableAdmin();
                }
                Response.Redirect("products.aspx");
            }
            catch
            {
                Label3.Text = "Invalid Login, please try again!";
            }
        }
Esempio n. 2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            int UserID  = 0;
            int TransID = getTransID();

            //get user object from session and save userid to be used later when saving transaction information to db
            UserAcct user = new UserAcct();

            user = (UserAcct)Session["User"];

            if (user == null)
            {
                Response.Redirect("login.aspx");
            }
            else
            {
                UserID = user.UserID;
            }

            //get shopping cart from Session, redirect to products page if it is empty
            ShoppingCart sc = new ShoppingCart();

            sc = (ShoppingCart)Session["Cart"];

            if (sc == null)
            {
                Response.Redirect("products.aspx");
            }
            else
            {
                //if there are items in the shopping cart
                if (sc.cartCount() > 0)
                {
                    foreach (CartItem ci in sc.getList())
                    {
                        //populate insert parameters with product data, userID and transactionID
                        SqlDataSource1.InsertParameters.Add("UserID", UserID.ToString());
                        SqlDataSource1.InsertParameters.Add("ProdID", ci.ID.ToString());
                        SqlDataSource1.InsertParameters.Add("Date", DateTime.Now.ToString());
                        SqlDataSource1.InsertParameters.Add("ProdPrice", ci.Price.ToString());
                        SqlDataSource1.InsertParameters.Add("Quanity", ci.QTY.ToString());
                        SqlDataSource1.InsertParameters.Add("TransID", TransID.ToString());
                        SqlDataSource1.Insert();
                        //clear insertparameters array so that that parameters can be added for next item onlist
                        SqlDataSource1.InsertParameters.Clear();
                    }
                }
            }
        }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            /*
             * Loads the user object from the session variable, makes sure that it exists, calls
             * LoginStatus method on Master page to display current login status
             */

            UserAcct user = new UserAcct();

            user = (UserAcct)Session["User"];

            if (user == null)
            {
                //Requires <%@ MasterType  virtualPath="~/Site1.master"%> directive in Login.aspx
                Master.LoginStatus();
            }
            else
            {
                Master.LoginStatus();
            }
        }
Esempio n. 4
0
        public void LoginStatus()
        {
            //Verifies the User object exists and updates labels with user name and status
            UserAcct user = new UserAcct();

            user = (UserAcct)Session["User"];

            if (user == null)
            {
                lblLoginStatus.Text = "" + "NOT Logged In";
            }
            else
            {
                lblLoginStatus.Text = user.Name + ": " + "Logged In";
                hlLogout.Visible    = true;
                //if User is Admin, ebable the ADMIN link
                if (user.Role == "admin")
                {
                    hlAdmin.Visible = true;
                }
            }
        }