Exemplo n.º 1
0
    protected void OnSelectedIndexChanged(object sender, EventArgs e)
    {
        int CustID = Convert.ToInt16(Session["CustomerID"]);

        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            //-----------------------------------------------------------
            DropDownList ddlPageSize = (DropDownList)sender;
            RepeaterItem item        = ddlPageSize.NamingContainer as RepeaterItem;
            string       a           = Convert.ToString(ddlPageSize.SelectedValue);

            int    index = item.ItemIndex;
            string id    = ((Label)(Repeater12.Items[index].FindControl("lblHiddenCartID"))).Text;
            int    bb    = Convert.ToInt16(id);
            int    cc    = Convert.ToInt16(a);
            //-----------------------------------------------------------


            var users = context.Carts.Where(x => (x.CustomerID == CustID) && (x.CartID == bb));

            foreach (var user in users)
            {
                // change the properties
                user.Quantity = cc;
            }
            //System.Diagnostics.Debug.WriteLine("gggggggggddddgggggggggggg{0}   {1}", users);
            // EF will pick up those changes and save back to the database.
            context.SaveChanges();
        }
    }
Exemplo n.º 2
0
    protected void btnClothesNext_Click(object sender, EventArgs e)
    {
        //Enable prev button if it's disabled.
        if (btnClothesPrev.Enabled == false)
        {
            btnClothesPrev.Enabled = true;
        }
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            List <Product> clothes = context.Products.Where(p => p.CategoryID == 3).ToList();
            int            i       = (int)ViewState["rowClothes"];

            //Get the next row
            i++;
            try
            {
                lblClothesPrice.Text              = clothes[i].ProductPrice.ToString();
                lnkClothesTitle.Text              = clothes[i].ProductName;
                lnkClothesTitle.NavigateUrl       = "product.aspx?ProductID=" + clothes[i].ProductID;
                lnkImageLinkToClothes.NavigateUrl = lnkClothesTitle.NavigateUrl;
                imgProductClothes.ImageUrl        = clothes[i].ProductImageURL;
                lnkClothesOrder.NavigateUrl       = lnkClothesTitle.NavigateUrl;
            }
            catch (ArgumentOutOfRangeException ex)
            {
                //There aren't anymore rows so, disable further action.
                btnClothesNext.Enabled = false;
                i--;
            }

            //Updating viewstate for next use.
            ViewState["rowClothes"] = i;
        }
    }
Exemplo n.º 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["CustomerID"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            if (!IsPostBack)
            {
                using (eCommerceDBEntities context = new eCommerceDBEntities())
                {
                    //Getting user info based on session variable
                    int      id   = (int)Session["CustomerID"];
                    Customer cust = context.Customers.Where(i => i.CustomerID == id).FirstOrDefault();

                    //Setting page title.
                    Page.Title = "Profile | " + cust.CustomerName;

                    //Setting values from DB
                    txtName.Text            = cust.CustomerName;
                    txtUserName.Text        = cust.UserName;
                    txtContact.Text         = cust.ContactNumber;
                    ddlGender.SelectedValue = cust.sex;
                    txtEmail.Text           = cust.email;
                    txtAddress.Text         = cust.Address;
                }
            }
        }
    }
Exemplo n.º 4
0
    protected void btnPrev_Click(object sender, EventArgs e)
    {
        //Enable next button if it's disabled.
        if (btnNext.Enabled == false)
        {
            btnNext.Enabled = true;
        }
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            List <Product> pr = context.Products.Where(p => p.CategoryID == 1).ToList();

            int i = (int)ViewState["rowMobile"];
            //Get the next rowMobile
            i--;
            try
            {
                lblPrice.Text               = pr[i].ProductPrice.ToString();
                lnkProductTitle.Text        = pr[i].ProductName;
                lnkProductTitle.NavigateUrl = "product.aspx?ProductID=" + pr[i].ProductID;
                lnkImageLinkTo.NavigateUrl  = lnkProductTitle.NavigateUrl;
                imgProduct.ImageUrl         = pr[i].ProductImageURL;
                lnkOrder.NavigateUrl        = lnkProductTitle.NavigateUrl;
            }
            catch (ArgumentOutOfRangeException ex)
            {
                //There aren't anymore rowMobiles so, disable further action.
                btnPrev.Enabled = false;
                i++;
            }

            //Updating viewstate for next use.
            ViewState["rowMobile"] = i;
        }
    }
Exemplo n.º 5
0
    protected void lnkRemoveItem_Click(object sender, EventArgs e)
    {
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            //Get the reference of the clicked button.
            LinkButton button = (sender as LinkButton);
            //Get the Repeater Item reference
            RepeaterItem item = button.NamingContainer as RepeaterItem;

            //Get the repeater item index
            int    index = item.ItemIndex;
            string id    = ((Label)(Repeater12.Items[index].FindControl("lblHiddenCartID"))).Text;
            string id3   = ((DropDownList)(Repeater12.Items[index].FindControl("ddlQuantity"))).SelectedValue;

            int  cartid = Convert.ToInt16(id);
            Cart cr     = context.Carts.Where(i => i.CartID == cartid).FirstOrDefault();

            context.Carts.DeleteObject(cr);
            context.SaveChanges();

            string notifyTitle  = "One item removed";
            string message      = "One item was removed from your cart!";
            string notification = string.Format("?notifyTitle={0}&notificationDescription={1}", notifyTitle, message);

            Response.Redirect("~/order.aspx" + notification);
        }
    }
Exemplo n.º 6
0
    protected void btnPasswordRecover_Click(object sender, EventArgs e)
    {
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            Customer cust = context.Customers.Where(i => i.email == txtEmail.Text).FirstOrDefault();
            if (cust == null)
            {
                string title      = "User ID not found";
                string message    = "No user found with the given email ID. Please provide the email ID you signed up with.";
                string jsFunction = string.Format("showNotification('{0}','{1}')", title, message);
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "notify", jsFunction, true);
            }
            else
            {
                string      email    = cust.email;
                string      password = cust.Password;
                MailMessage mail     = new MailMessage("*****@*****.**", email);
                mail.Subject    = "Password for your eCommerce ID";
                mail.Body       = "Your password for eCommerce is : " + password;
                mail.IsBodyHtml = false;

                SmtpClient smp = new SmtpClient();
                //smp.Send(mail);

                string title      = "Password sent!";
                string message    = "Your password has been sent to " + email;
                string jsFunction = string.Format("showNotification('{0}','{1}')", title, message);
                ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "notify", jsFunction, true);
            }
        }
    }
Exemplo n.º 7
0
    protected void btnPost_Click(object sender, EventArgs e)
    {
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            if (Session["CustomerID"] != null)
            {
                int CustID = Convert.ToInt16(Session["CustomerID"].ToString());
                int ProdID = Convert.ToInt16(Request.QueryString["ProductID"]);

                Review rv = new Review()
                {
                    ReviewTitle       = txtReviewTitle.Text,
                    ReviewDescription = txtReviewDetail.Text,
                    CustomerID        = CustID,
                    ProductID         = ProdID,
                    Rating            = Convert.ToInt16(ddlRatings.SelectedValue),
                    ReviewDate        = DateTime.Now
                };

                context.Reviews.AddObject(rv);
                context.SaveChanges();

                string notifyTitle  = "Review added";
                string message      = "Your review has been posted on the product page. Thanks for helping others.";
                string notification = string.Format("?notifyTitle={0}&notificationDescription={1}", notifyTitle, message);

                Response.Redirect("~/product.aspx?ProductID=" + ViewState["prodid"].ToString() + "&" + notification);
            }
        }
    }
Exemplo n.º 8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //Get the lookup string form URL
            string lookup   = Request.QueryString["product"];
            string category = Request.QueryString["category"];

            Page.Title = "Search: " + lookup;

            //Keeping the lookup string in searchbar for ease of use
            ((TextBox)this.Page.Master.FindControl("txtSearch")).Text = lookup;

            using (eCommerceDBEntities context = new eCommerceDBEntities())
            {
                //Running %like query on 2 fields to get best results from DB
                List <Product> pr = context.Products.Where(i => i.ProductName.Contains(lookup) ||
                                                           i.ProductDescription.Contains(lookup)
                                                           ).ToList();

                var lq = (from p in context.Products
                          join c in context.Categories
                          on p.CategoryID equals c.CategoryID
                          where (string.IsNullOrEmpty(category) ? true : c.CategoryName == category) &&
                          (string.IsNullOrEmpty(lookup)? true : p.ProductName.Contains(lookup) || p.ProductDescription.Contains(lookup))
                          select p).ToList();

                Repeater1.DataSource = lq;
                Repeater1.DataBind();
            }
        }
    }
Exemplo n.º 9
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        try
        {
            //Save the file on server's folder kepping the original filename
            flImageUpload.SaveAs(Server.MapPath(@"~\Site_data\product_images\" + flImageUpload.FileName));

            Product pr = new Product
            {
                ProductName        = txtName.Text,
                ProductDescription = txtDescription.Text,
                ProductPrice       = Convert.ToDecimal(txtPrice.Text),
                ProductImageURL    = @"~\Site_data\product_images\" + flImageUpload.FileName,
                Discount           = Convert.ToInt16(string.IsNullOrEmpty(txtDiscount.Text) ? "0" : txtDiscount.Text),
                CategoryID         = Convert.ToInt16(ddlCategory.SelectedValue)
            };

            using (eCommerceDBEntities context = new eCommerceDBEntities())
            {
                context.Products.AddObject(pr);
                context.SaveChanges();
            }

            lblStatus.Text           = "Product successfully uploaded.";
            lblStatus.ForeColor      = System.Drawing.Color.Green;
            hlAddFeature.NavigateUrl = "~/Admin/addFeatures.aspx?ProductID=" + pr.ProductID;
        }
        catch (System.IO.DirectoryNotFoundException ex)
        {
            lblStatus.ForeColor = System.Drawing.Color.Red;
            lblStatus.Text      = "Select an image first";
        }
    }
Exemplo n.º 10
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //---------------------------------------------------

        if (Session["CustomerID"] == null)
        {
            string redirectToURL = "~/order.aspx";
            Response.Redirect("~/login.aspx?redirect=" + redirectToURL);
        }

        if (!IsPostBack)
        {
            //Get logged in id
            int CustID = Convert.ToInt16(Session["CustomerID"]);
            using (eCommerceDBEntities context = new eCommerceDBEntities())
            {
                if (Request.QueryString["addToCart"] != null)
                {
                    int ProdID = Convert.ToInt16(Request.QueryString["addToCart"]);

                    //Check if product is already in cart
                    Cart cr = context.Carts.Where(i => i.ProductID == ProdID).FirstOrDefault();
                    //If not in the DB add it.
                    if (cr == null)
                    {
                        context.Carts.AddObject(new Cart
                        {
                            CustomerID = CustID,
                            ProductID  = ProdID,
                            Quantity   = 1
                        });
                        context.SaveChanges();
                    }
                }

                var cart = (from c in context.Carts
                            join p in context.Products
                            on c.ProductID equals p.ProductID
                            where c.CustomerID == CustID
                            select new { p.ProductName, p.ProductPrice, p.ProductImageURL, c.CartID });
                Repeater12.DataSource = cart;
                Repeater12.DataBind();

                Boolean isCartEmpty = context.Carts.Where(i => i.CustomerID == CustID).FirstOrDefault() == null;
                //If cart is empty. No ID label means, no cart item
                if (isCartEmpty)
                {
                    Wizard1.Visible    = false;
                    lblMessage.Visible = true;
                }
            }
        }
    }
Exemplo n.º 11
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //Populating Mobile category
            //Instantiating the entity class to access DB tables
            using (eCommerceDBEntities context = new eCommerceDBEntities())
            {
                //Query the DB for products which are mobile i.e. CategoryID == 1
                List <Product> pr = context.Products.Where(i => i.CategoryID == 1).ToList();

                //At first launch, fill fields with first rowMobile i.e. pr[0]
                lblPrice.Text               = pr[0].ProductPrice.ToString();
                lnkProductTitle.Text        = pr[0].ProductName;
                lnkProductTitle.NavigateUrl = "product.aspx?ProductID=" + pr[0].ProductID;
                lnkImageLinkTo.NavigateUrl  = lnkProductTitle.NavigateUrl;
                imgProduct.ImageUrl         = pr[0].ProductImageURL;
                lnkOrder.NavigateUrl        = lnkProductTitle.NavigateUrl;

                //Store returned rowMobile in viewstate for it to persist, to be used later.
                ViewState["rowMobile"] = 0;

                //Populating Books category
                //Query the DB for products which are books i.e. CategoryID == 4
                List <Product> books = context.Products.Where(i => i.CategoryID == 4).ToList();
                //At first launch, fill fields with first row i.e. pr[0]
                lblBookPrice.Text              = books[0].ProductPrice.ToString();
                lnkBookTitle.Text              = books[0].ProductName;
                lnkBookTitle.NavigateUrl       = "product.aspx?ProductID=" + books[0].ProductID;
                lnkImageLinkToBook.NavigateUrl = lnkBookTitle.NavigateUrl;
                imgProductBook.ImageUrl        = books[0].ProductImageURL;
                lnkBookOrder.NavigateUrl       = lnkBookTitle.NavigateUrl;

                //Store returned rowBook in viewstate for it to persist, to be used later.
                ViewState["rowBooks"] = 0;

                //Populating Clothes category
                //Query the DB for products which are clothes i.e. CategoryID == 3
                List <Product> clothes = context.Products.Where(i => i.CategoryID == 3).ToList();
                //At first launch, fill fields with first row i.e. pr[0]
                lblClothesPrice.Text              = clothes[0].ProductPrice.ToString();
                lnkClothesTitle.Text              = clothes[0].ProductName;
                lnkClothesTitle.NavigateUrl       = "product.aspx?ProductID=" + clothes[0].ProductID;
                lnkImageLinkToClothes.NavigateUrl = lnkClothesTitle.NavigateUrl;
                imgProductClothes.ImageUrl        = clothes[0].ProductImageURL;
                lnkClothesOrder.NavigateUrl       = lnkClothesTitle.NavigateUrl;

                //Store returned rowBook in viewstate for it to persist, to be used later.
                ViewState["rowClothes"] = 0;
            }
        }
    }
Exemplo n.º 12
0
    protected void btnChange_Click(object sender, EventArgs e)
    {
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            //Getting user info based on session variable
            int      id   = (int)Session["CustomerID"];
            Customer cust = context.Customers.Where(i => i.CustomerID == id).FirstOrDefault();

            cust.Password = txtPassword.Text;
            context.SaveChanges();
        }
        lblError.Visible = true;
        lblError.Text    = "Password successfully updated";
    }
Exemplo n.º 13
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         using (eCommerceDBEntities context = new eCommerceDBEntities())
         {
             List <Category> ct = context.Categories.ToList();
             ddlCategory.DataSource     = ct;
             ddlCategory.DataTextField  = "CategoryName";
             ddlCategory.DataValueField = "CategoryID";
             ddlCategory.DataBind();
         }
     }
 }
Exemplo n.º 14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int id = Convert.ToInt16(Request.QueryString["ProductID"]);
            ViewState["prodid"] = id;
            using (eCommerceDBEntities context = new eCommerceDBEntities())
            {
                if (Session["CustomerID"] == null)
                {
                    Panel1.Enabled = false;
                }
                Product pr = context.Products.Where(i => i.ProductID == id).FirstOrDefault();
                lblName.Text             = pr.ProductName;
                lblPrice.Text           += pr.ProductPrice.ToString();
                lblDescription.Text      = pr.ProductDescription;
                imgProductImage.ImageUrl = pr.ProductImageURL;

                //Setting page title
                Page.Title = pr.ProductName;

                //Joing feature tables to show data on datagrid
                var lq = (from f in context.Features
                          join mf in context.MetaFeatures
                          on f.MetaFeatureID equals mf.MetaFeatureID
                          where f.ProductID == id
                          select new { Feature = mf.FeatureName, Description = f.FeatureDescription }).ToList();

                GridView1.DataSource = lq;
                GridView1.DataBind();

                //Populating reviews
                var review = (from r in context.Reviews
                              where r.ProductID == id
                              join c in context.Customers
                              on r.CustomerID equals c.CustomerID
                              select new {
                    r.ReviewDate,
                    r.ReviewTitle,
                    r.ReviewDescription,
                    r.Rating,
                    c.CustomerName
                });
                Repeater1.DataSource = review;
                Repeater1.DataBind();
            }
        }
    }
Exemplo n.º 15
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            Customer cust = context.Customers.Where(i => i.UserName == txtUserName.Text).FirstOrDefault();

            cust.CustomerName  = txtName.Text;
            cust.email         = txtEmail.Text;
            cust.ContactNumber = txtContact.Text;
            cust.Address       = txtAddress.Text;
            cust.Password      = txtPassword.Text;
            cust.sex           = ddlGender.SelectedValue;
            cust.UserType      = ddlUserType.SelectedValue;

            context.SaveChanges();
        }
    }
Exemplo n.º 16
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            txtProductID.Text = Request.QueryString["ProductID"];

            //Fill the list from table
            using (eCommerceDBEntities context = new eCommerceDBEntities())
            {
                List <MetaFeature> mf = context.MetaFeatures.ToList();
                ddlFeatureName.DataSource     = mf;
                ddlFeatureName.DataTextField  = "FeatureName";
                ddlFeatureName.DataValueField = "MetaFeatureID";
                ddlFeatureName.DataBind();
            }
        }
    }
Exemplo n.º 17
0
    private void addAmount()
    {
        int CustomerID = Convert.ToInt16(Session["CustomerID"].ToString());

        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            var cart = (from c in context.Carts
                        join p in context.Products
                        on c.ProductID equals p.ProductID
                        where c.CustomerID == CustomerID
                        select new { p.ProductPrice, c.Quantity });
            decimal amt = 0;
            foreach (var i in cart)
            {
                amt += (i.ProductPrice * i.Quantity);
            }
            txtAmount.Text = amt.ToString();
        }
    }
Exemplo n.º 18
0
    protected void Page_Load(object sender, EventArgs e)
    {
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            var lq = (from o in context.Orders
                      join p in context.Products
                      on o.ProductID equals p.ProductID
                      select new {
                o.OrderID,
                o.DateOrdered,
                p.ProductName,
                p.ProductPrice,
                p.Discount,
            });

            GridView1.DataSource = lq;
            GridView1.DataBind();
        }
    }
Exemplo n.º 19
0
    protected void btnPay_Click(object sender, EventArgs e)
    {
        DropDownList ctr = (DropDownList)Master.FindControl("ddlQuantity");

        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            int custID = Convert.ToInt16(Session["CustomerID"]);
            if (string.IsNullOrEmpty(txtAmount.Text))
            {
                lblStatus.Text      = "Please select mode of payment Debit/Credit card";
                lblStatus.ForeColor = System.Drawing.Color.Red;
            }
            else
            {
                List <Cart> cart = context.Carts.Where(i => i.CustomerID == custID).ToList();

                foreach (var i in cart)
                {
                    //Fill order table
                    context.Orders.AddObject(new Order
                    {
                        CustomerID  = custID,
                        ProductID   = i.ProductID,
                        DateOrdered = DateTime.Now
                    });

                    //Product is bought so, empty the cart.
                    //context.Carts.DeleteObject(i);
                }
                context.SaveChanges();

                lblStatus.Text      = "Your order has been placed. Happy shopping!";
                lblStatus.ForeColor = System.Drawing.Color.Green;

                string notifyTitle  = "Payment Successful!";
                string message      = "The order has been placed. You will receive your shipment sonn.";
                string notification = string.Format("?notifyTitle={0}&notificationDescription={1}", notifyTitle, message);

                // Response.Redirect("~/order.aspx" + notification);
            }
        }
    }
Exemplo n.º 20
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            //Getting user info based on session variable
            int      id   = (int)Session["CustomerID"];
            Customer cust = context.Customers.Where(i => i.CustomerID == id).FirstOrDefault();

            cust.CustomerName  = txtName.Text;
            cust.sex           = ddlGender.SelectedValue;
            cust.UserName      = txtUserName.Text;
            cust.Address       = txtAddress.Text;
            cust.email         = txtEmail.Text;
            cust.ContactNumber = txtContact.Text;

            context.SaveChanges();
        }
        lblError.Visible = true;
        lblError.Text    = "Details successfully updated";
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            if (Session["CustomerID"] != null)
            {
                //Getting user info based on session variable
                int      id   = (int)Session["CustomerID"];
                Customer cust = context.Customers.Where(i => i.CustomerID == id).FirstOrDefault();

                if (cust.UserType == "admin")
                {
                    Panel1.Visible = true;
                }
            }
            else
            {
                Response.Redirect("~/Home.aspx");
            }
        }
    }
Exemplo n.º 22
0
    protected void btnSignup_Click(object sender, EventArgs e)
    {
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            //New user object created from the information in the webform.
            Customer newUser = new Customer()
            {
                CustomerName  = txtName.Text,
                sex           = ddlGender.SelectedValue,
                UserName      = txtUserName.Text,
                Password      = txtPassword.Text,
                Address       = txtAddress.Text,
                email         = txtEmail.Text,
                ContactNumber = txtContact.Text,
                UserType      = "customer"
            };

            //Lookup if a user with the given username or email already exists in DB.
            Customer cust = context.Customers.Where(i => i.UserName == newUser.UserName ||
                                                    i.email == newUser.email).FirstOrDefault();

            //If user is found, show error, else add new user.
            if (cust != null)
            {
                lblError.Text    = "A user with that Email ID or UserName already exists.";
                lblError.Visible = true;
            }
            else
            {
                //Add new user to the customers' context
                context.Customers.AddObject(newUser);
                //Save new user in the database.
                context.SaveChanges();

                //Send user to loginpage
                Response.Redirect("login.aspx");
            }
        }
    }
Exemplo n.º 23
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            //Check if there's any user who has the given username and password
            Customer cust = context.Customers.Where(i => i.UserName == txtUserName.Text &&
                                                    i.Password == txtPassword.Text).FirstOrDefault();

            if (cust == null)
            {
                //User not found
                lblError.Text    = "Wrong username or password";
                lblError.Visible = true;
            }
            else
            {
                //Create a session for user
                Session["CustomerID"] = cust.CustomerID;

                string notifyTitle  = "Welcome!";
                string message      = "You have been successfully logged in. Happy shopping!";
                string notification = string.Format("?notifyTitle={0}&notificationDescription={1}", notifyTitle, message);

                //If user is requesting a redirect.
                string redirectToURL = Request.QueryString["redirect"];
                if (string.IsNullOrEmpty(redirectToURL))
                {
                    Response.Redirect("~/home.aspx" + notification);
                }
                else
                {
                    Response.Redirect(redirectToURL);
                }
            }
        }
    }
Exemplo n.º 24
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["notifyTitle"] != null || Request.QueryString["notificationDescription"] != null)
        {
            string title      = Request.QueryString["notifyTitle"];
            string message    = Request.QueryString["notificationDescription"];
            string jsFunction = string.Format("showNotification('{0}','{1}')", title, message);
            ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "notify", jsFunction, true);
        }

        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            //Check if some user is logged in.
            if (Session["CustomerID"] != null)
            {
                //Getting user info based on session variable
                int      id   = (int)Session["CustomerID"];
                Customer cust = context.Customers.Where(i => i.CustomerID == id).FirstOrDefault();
                //Change the links
                lnkLogInLogOut.Text        = "Logout";
                lnkLogInLogOut.PostBackUrl = "logout.aspx";

                lnkSignUpProfile.Text        = "Welcome: " + cust.CustomerName;
                lnkSignUpProfile.PostBackUrl = "~/profile.aspx?CustomerID=" + cust.CustomerID;


                //Update Cart count
                var cart = (from c in context.Carts
                            join p in context.Products
                            on c.ProductID equals p.ProductID
                            where c.CustomerID == id
                            select new { p.ProductName, p.ProductPrice, p.ProductImageURL });
                lblCartCount.Text = cart.Count().ToString();
            }
        }
    }
Exemplo n.º 25
0
    protected void btnLoad_Click(object sender, EventArgs e)
    {
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            Customer cust = context.Customers.Where(i => i.UserName.Contains(txtUserName.Text)).FirstOrDefault();

            txtName.Enabled     = true;
            txtEmail.Enabled    = true;
            txtContact.Enabled  = true;
            txtAddress.Enabled  = true;
            ddlGender.Enabled   = true;
            txtPassword.Enabled = true;
            ddlUserType.Enabled = true;

            txtUserName.Text          = cust.UserName;
            txtName.Text              = cust.CustomerName;
            txtEmail.Text             = cust.email;
            txtContact.Text           = cust.ContactNumber;
            txtAddress.Text           = cust.Address;
            txtPassword.Text          = cust.Password;
            ddlGender.SelectedValue   = cust.sex;
            ddlUserType.SelectedValue = cust.UserType;
        }
    }
Exemplo n.º 26
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            if (rdoChooseFeature.SelectedValue == "1")
            {
                Feature fr = new Feature()
                {
                    MetaFeatureID      = Convert.ToInt16(ddlFeatureName.SelectedValue),
                    ProductID          = Convert.ToInt16(txtProductID.Text),
                    FeatureDescription = txtBoxFeatureValue.Text
                };
                context.Features.AddObject(fr);
            }
            else if (rdoChooseFeature.SelectedValue == "2")
            {
                //Show error on empty textbox
                if (string.IsNullOrEmpty(txtFeatureName.Text))
                {
                    lblStatus.ForeColor = System.Drawing.Color.Red;
                    lblStatus.Text      = "Please add a feature name.";
                }
                else
                {
                    //Check if the feature already exists
                    MetaFeature mr = context.MetaFeatures.Where(i => i.FeatureName == txtFeatureName.Text).FirstOrDefault();
                    int         id;
                    //If not found, create new row
                    if (mr == null)
                    {
                        MetaFeature mfr = new MetaFeature()
                        {
                            FeatureName = txtFeatureName.Text
                        };

                        context.MetaFeatures.AddObject(mfr);
                        context.SaveChanges();
                        //get the ID which is just created
                        id = mfr.MetaFeatureID;

                        Feature fr = new Feature()
                        {
                            MetaFeatureID      = id,
                            ProductID          = Convert.ToInt16(txtProductID.Text),
                            FeatureDescription = txtBoxFeatureValue.Text
                        };
                        context.Features.AddObject(fr);
                    }
                    //if found, update row.
                    else
                    {
                        id = mr.MetaFeatureID;
                        Feature fUpdate = context.Features.Where(i => i.MetaFeatureID == id).FirstOrDefault();
                        fUpdate.FeatureDescription = txtBoxFeatureValue.Text;
                    }
                }
            }
            context.SaveChanges();
            lblStatus.ForeColor = System.Drawing.Color.Green;
            lblStatus.Text      = "Feature added successfully. You can add more!";
        }
    }
Exemplo n.º 27
0
    protected void GenerateInvoicePDF(object sender, EventArgs e)
    {
        //Dummy data for Invoice (Bill).
        string companyName = "Mobile Mart";
        int    orderNo     = 2303;
        int    CustID      = Convert.ToInt16(Session["CustomerID"]);
        string CustID2     = Convert.ToString(Session["CustomerID"]);

        // eCommerceDBEntities context = new eCommerceDBEntities();

        using (eCommerceDBEntities context = new eCommerceDBEntities())
        {
            //-----------------------------------------------------------

            int CustomerID = Convert.ToInt16(Session["CustomerID"].ToString());

            var cart = (from c in context.Carts
                        join p in context.Products
                        on c.ProductID equals p.ProductID


                        where c.CustomerID == CustomerID
                        select new { p.ProductPrice, c.Quantity, p.ProductName, c.CartID });


            var customer = (from cust in context.Customers
                            where cust.CustomerID == CustomerID
                            select new { cust.CustomerName });



            //000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

            DataTable dt = new DataTable();



            decimal amt          = 0;
            string  orderId      = "";
            string  customerName = "";
            foreach (var i in cart)
            {
                amt    += (i.ProductPrice * i.Quantity);
                orderId = Convert.ToString(i.CartID);
            }
            foreach (var i in customer)
            {
                customerName = Convert.ToString(i.CustomerName);
            }

            //oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
            using (StringWriter sw = new StringWriter())
            {
                using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                {
                    StringBuilder sb = new StringBuilder();

                    //Generate Invoice (Bill) Header.
                    sb.Append("<table width='100%' cellspacing='0' cellpadding='2'>");
                    sb.Append("<tr><td align='center' style='background-color: #18B5F0' colspan = '2'><b>INVOICE</b></td></tr>");
                    sb.Append("<tr><td colspan = '2'></td></tr>");
                    sb.Append("<tr><td><b>Invoice No: </b>");
                    sb.Append(orderId);
                    sb.Append("</td><td align = 'right'><b>Date: </b>");
                    sb.Append(DateTime.Now);
                    sb.Append(" </td></tr>");
                    sb.Append("<tr><td colspan = '2'><b>Company Name: </b>");
                    sb.Append(companyName);
                    sb.Append("</td></tr>");
                    sb.Append("<tr><td colspan = '2'><b>Customer Name: </b>");
                    sb.Append(customerName);
                    sb.Append("</td></tr>");
                    sb.Append("</table>");
                    sb.Append("<br />");

                    //Generate Invoice (Bill) Items Grid.
                    sb.Append("<table border = '1'>");
                    sb.Append("<tr>");

                    sb.Append("<th style = 'background-color: #D20B0C;color:#ffffff'>");
                    sb.Append("Product Name");
                    sb.Append("</th>");
                    sb.Append("<th style = 'background-color: #D20B0C;color:#ffffff'>");
                    sb.Append("Quantity");
                    sb.Append("</th>");
                    sb.Append("<th style = 'background-color: #D20B0C;color:#ffffff'>");
                    sb.Append("Product Price");
                    sb.Append("</th>");

                    sb.Append("</tr>");
                    foreach (var i in cart)
                    {
                        sb.Append("<tr>");

                        sb.Append("<td>");
                        sb.Append(i.ProductName);
                        sb.Append("</td>");
                        sb.Append("<td>");
                        sb.Append(i.Quantity);
                        sb.Append("</td>");
                        sb.Append("<td>");
                        sb.Append(i.ProductPrice);
                        sb.Append("</td>");

                        sb.Append("</tr>");
                    }
                    sb.Append("<tr><td align = 'right' colspan = '");
                    sb.Append(3 - 1);
                    sb.Append("'>Total</td>");
                    sb.Append("<td>");
                    sb.Append(amt.ToString());
                    sb.Append("</td>");
                    sb.Append("</tr></table>");

                    //Export HTML String as PDF.
                    StringReader sr         = new StringReader(sb.ToString());
                    Document     pdfDoc     = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                    HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);
                    PdfWriter    writer     = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                    pdfDoc.Open();
                    htmlparser.Parse(sr);
                    pdfDoc.Close();
                    Response.ContentType = "application/pdf";
                    Response.AddHeader("content-disposition", "attachment;filename=Invoice_" + orderNo + ".pdf");
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.Write(pdfDoc);

                    // ====================================================================================
                    int         custID = Convert.ToInt16(Session["CustomerID"]);
                    List <Cart> cart2  = context.Carts.Where(ii => ii.CustomerID == custID).ToList();
                    foreach (var i in cart2)
                    {
                        context.Carts.DeleteObject(i);
                    }

                    context.SaveChanges();
                    Response.End();
                }
            }
        }

        //=================================================================================
        Response.Redirect("~/order.aspx");
    }