protected void regBtn_Click(object sender, EventArgs e)
        {
            var db = new DataLinqDataContext();

            dynamic users = from a in db.Users
                            select a;

            var user      = username.Value;
            var password1 = Secrecy.Secrecy.HashPassword(pass1.Value);
            var password2 = Secrecy.Secrecy.HashPassword(pass2.Value);

            bool isReg = false;

            foreach (User u in users)
            {
                if (u.Username == user)
                {
                    alertReg.InnerHtml = "<strong>Oh snap!</strong> Username already exists.";
                    isReg = true;
                    if (u.Email == email.Value)
                    {
                        alertReg.InnerHtml = "<strong>Oh snap!</strong> Email already exists.";
                        isReg = true;
                    }
                }
            }
            if (password1 != password2)
            {
                alertReg.InnerHtml = "<strong>Oh snap!</strong> Passwords do not match";
            }
            if (isReg == false)
            {
                User regUser = new User
                {
                    Username       = user,
                    Password       = password1,
                    UserType       = "User",
                    FirstName      = firstname.Value,
                    Surname        = lastname.Value,
                    Email          = email.Value,
                    AddressLine1   = add1.Value,
                    AddressLine2   = add2.Value,
                    ZipCode        = zip.Value,
                    DateRegistered = DateTime.Now.Date
                };
                db.Users.InsertOnSubmit(regUser);
                try
                {
                    db.SubmitChanges();
                    Session["AuthLevel"] = "User";
                    Session["Username"]  = user;
                    Response.Redirect("index.aspx");
                }
                catch (Exception ex)
                {
                    ex.GetBaseException();
                }
            }
        }
        protected void savebtn_Click(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session["Username"] != null)
            {
                String sessionuname = (String)HttpContext.Current.Session["Username"];
                var    db           = new DataLinqDataContext();
                User   userd        = (from g in db.Users
                                       where sessionuname.Equals(g.Username)
                                       select g).FirstOrDefault();

                if (!(fname.Value.Equals("")))
                {
                    userd.FirstName = fname.Value;
                }
                if (!(lname.Value.Equals("")))
                {
                    userd.Surname = lname.Value;
                }
                if (!(email.Value.Equals("")))
                {
                    userd.Email = email.Value;
                }
                if (!(location1.Value.Equals("")))
                {
                    userd.AddressLine1 = location1.Value;
                }
                if (!(location2.Value.Equals("")))
                {
                    userd.AddressLine2 = location2.Value;
                }
                if (!(zipcode.Value.Equals("")))
                {
                    userd.ZipCode = zipcode.Value;
                }

                if (Secrecy.Secrecy.HashPassword(oldPassword.Value).Equals(userd.Password))
                {
                    if (!(pass1.Value.Equals("")))
                    {
                        if (pass1.Value.Equals(pass2.Value))
                        {
                            userd.Password   = Secrecy.Secrecy.HashPassword(pass1.Value);
                            result.InnerText = "Password Changed";
                        }
                    }
                }
                try
                {
                    db.SubmitChanges();
                }
                catch (Exception exep) { exep.GetBaseException(); }
                Response.Redirect("UserHomePage.aspx");
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var db = new DataLinqDataContext();

            var cart = (from Cart c in db.Carts
                        where c.Product_Id.Equals(Request.QueryString["ProductId"])
                        select c).FirstOrDefault();

            db.Carts.DeleteOnSubmit(cart);

            db.SubmitChanges();

            Response.Redirect("Wishlist.aspx");
        }
Ejemplo n.º 4
0
        protected void removeBtn_Click(object sender, EventArgs e)
        {
            var db = new DataLinqDataContext();

            int id = int.Parse(deleteId.Value);

            var deleteP = (from p in db.Products
                           where p.Product_Id == id
                           select p).FirstOrDefault();

            deleteP.Product_IsActive = false;
            db.SubmitChanges();
            Response.Redirect("AdminHomePage.aspx");
        }
Ejemplo n.º 5
0
        protected void btnupdate_Click(object sender, EventArgs e)
        {
            ProductID = Convert.ToInt32(Request.QueryString["ProductId"]);
            if (ProductID == 0)
            {
                Response.Redirect("ControlSpecials.aspx", false);
            }
            else
            {
                var     db        = new DataLinqDataContext();
                string  todisplay = "<p> Updating of price of product </p>";
                Product Pro       = (from p in db.Products
                                     where p.Product_Id.Equals(ProductID)
                                     select p).FirstOrDefault();

                int newpercent = Convert.ToInt32(newper.Value);
                Pro.Product_SpclPercantage = newpercent;
                int newcostdiff = Convert.ToInt32(Pro.Product_Price * (newpercent / 100));
                int totalcost   = Convert.ToInt32(Pro.Product_Price - newcostdiff);

                //if (Cbspecial.Checked==true)
                //{
                //    Debug.WriteLine("Checked");
                //    Pro.Product_IsSpecial = true;
                //}
                //else if (Cbspecial.Checked == false)
                //{
                //    Pro.Product_IsSpecial = false;
                //}

                if (newpercent == 0)
                {
                    Pro.Product_IsSpecial = false;
                }
                else
                {
                    Pro.Product_IsSpecial = true;
                }
                try
                {
                    db.SubmitChanges();
                }
                catch (Exception exep) { exep.GetBaseException(); }

                todisplay           = todisplay + "New Price:R " + totalcost;
                singlepro.InnerHtml = todisplay;
                Response.Redirect("ControlSpecials.aspx", false);
            }
        }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var db = new DataLinqDataContext();


            var wishlist = (from Wishlist w in db.Wishlists
                            where w.Product_Id.Equals(Request.QueryString["ProductId"])
                            select w).FirstOrDefault();

            var newCart = new Cart
            {
                Quantity   = 1,
                Product_Id = wishlist.Product_Id,
                Username   = Convert.ToString(Session["Username"])
            };

            db.Carts.InsertOnSubmit(newCart);
            db.SubmitChanges();

            db.Wishlists.DeleteOnSubmit(wishlist);
            db.SubmitChanges();

            Response.Redirect("Wishlist.aspx");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var db = new DataLinqDataContext();

            var cart = (from Cart c in db.Carts
                        where c.Product_Id.Equals(Request.QueryString["ProductId"])
                        select c).FirstOrDefault();

            var product = (from Product p in db.Products
                           where p.Product_Id.Equals(cart.Product_Id)
                           select p).FirstOrDefault();

            if (cart.Quantity != 1)
            {
                cart.Quantity -= 1;
            }
            db.SubmitChanges();
            Response.Redirect("Wishlist.aspx");
        }
Ejemplo n.º 8
0
        protected void editBtn_Click(object sender, EventArgs e)
        {
            var db = new DataLinqDataContext();

            int productID = int.Parse(prodId.Value);
            var prodd     = (from Product a in db.Products
                             where a.Product_Id.Equals(productID)
                             select a).FirstOrDefault();
            var    thingtochange = edit.Value;
            string value         = prodEdit1.Value;

            if (thingtochange.Equals("editName"))
            {
                prodd.Product_Name = value;
            }
            if (thingtochange.Equals("editPrice"))
            {
                prodd.Product_Price = Convert.ToDecimal(value);
            }
            if (thingtochange.Equals("editDesc"))
            {
                prodd.Product_Description = value;
            }
            if (thingtochange.Equals("editType"))
            {
                prodd.Product_Type = value;
            }
            if (thingtochange.Equals("editImg"))
            {
                prodd.Product_Img = value;
            }
            if (thingtochange.Equals("editOH"))
            {
                prodd.Product_OnHand = int.Parse(value);
            }
            if (thingtochange.Equals("editBrand"))
            {
                prodd.Product_Brand = value;
            }
            db.SubmitChanges();
        }
Ejemplo n.º 9
0
        protected void addProd_Click(object sender, EventArgs e)
        {
            var     db       = new DataLinqDataContext();
            dynamic products = from a in db.Products
                               select a;
            bool isReg = false;

            if (isReg == false)
            {
                Product newProd = new Product
                {
                    Product_Name           = prodName.Value,
                    Product_Price          = Convert.ToDecimal(prodPrice.Value),
                    Product_Description    = prodDesc.Value,
                    Product_Type           = prodType.Value,
                    Product_Img            = prodImg.Value,
                    Product_OnHand         = int.Parse(prodOnHand.Value),
                    Product_Brand          = prodBrand.Value,
                    Product_DateAdded      = DateTime.Now,
                    Product_IsActive       = true,
                    Product_IsSpecial      = false,
                    Product_NumSold        = 0,
                    Product_SpclPercantage = 0
                };
                db.Products.InsertOnSubmit(newProd);
                try
                {
                    db.SubmitChanges();
                    Response.Redirect("AdminHomePage.aspx");
                }
                catch (Exception ex)
                {
                    ex.GetBaseException();
                    addResponse.InnerHtml = "<div class=alert alert-danger><strong>Warning!</strong> An error occurred, please try again.</div>";
                }
            }
        }
Ejemplo n.º 10
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            var db = new DataLinqDataContext();

            var Product = (from product in db.Products
                           where (product.Product_Id).Equals(prdctID)
                           select product).FirstOrDefault();

            if (!((txtNwPrdctNm.Text).Trim()).Equals(""))
            {
                Product.Product_Name = txtNwPrdctNm.Text;
            }
            if (!((txtNwPrdctPrc.Text).Trim()).Equals(""))
            {
                Product.Product_Price = Convert.ToDecimal(txtNwPrdctPrc.Text);
            }
            if (!((txtNwDesrp.InnerText).Trim()).Equals(""))
            {
                Product.Product_Description = txtNwDesrp.InnerText;
            }
            if (!((txtNwPrdctTyp.Text).Trim()).Equals(""))
            {
                Product.Product_Type = txtNwPrdctTyp.Text;
            }
            if (!((txtNwPrdctSldNum.Text).Trim()).Equals(""))
            {
                Product.Product_NumSold = Convert.ToInt32(txtNwPrdctSldNum.Text);
            }
            if (!((txtnwPrdctHnd.Text).Trim()).Equals(""))
            {
                Product.Product_OnHand = Convert.ToInt32(txtnwPrdctHnd.Text);
            }

            if (txtNwPrctSpcl.Checked == true)
            {
                Product.Product_IsSpecial = true;
            }
            else
            {
                Product.Product_IsSpecial = false;
            }

            if (!((txtNwPrdctSpclPerc.Text).Trim()).Equals(""))
            {
                Product.Product_SpclPercantage = (float)Convert.ToDouble(txtNwPrdctSpclPerc.Text);
            }

            if (!((txtNwPrdctBrnd.Text).Trim()).Equals(""))
            {
                Product.Product_Brand = txtNwPrdctBrnd.Text;
            }

            if (txtNwPrdctActv.Checked == true)
            {
                Product.Product_IsActive = true;
            }
            else
            {
                Product.Product_IsActive = true;
            }
            try
            {
                db.SubmitChanges();
            }catch (Exception ex)
            {
                ex.GetBaseException();
            }
        }
Ejemplo n.º 11
0
        protected void final_Click(object sender, EventArgs e)
        {
            var db  = new DataLinqDataContext();
            var cpu = (from Product b in db.Products
                       where b.Product_Id.Equals(Request.QueryString["cpu"])
                       select b).FirstOrDefault();
            Cart aa = new Cart
            {
                Product_Id = cpu.Product_Id,
                Quantity   = 1,
                Username   = Convert.ToString(Session["Username"])
            };

            db.Carts.InsertOnSubmit(aa);
            db.SubmitChanges();
            var mobo = (from Product c in db.Products
                        where c.Product_Id.Equals(Request.QueryString["mobo"])
                        select c).FirstOrDefault();
            Cart bb = new Cart
            {
                Product_Id = mobo.Product_Id,
                Quantity   = 1,
                Username   = Convert.ToString(Session["Username"])
            };

            db.Carts.InsertOnSubmit(bb);
            db.SubmitChanges();
            var cool = (from Product d in db.Products
                        where d.Product_Id.Equals(Request.QueryString["cool"])
                        select d).FirstOrDefault();
            Cart cc = new Cart
            {
                Product_Id = cool.Product_Id,
                Quantity   = 1,
                Username   = Convert.ToString(Session["Username"])
            };

            db.Carts.InsertOnSubmit(cc);
            db.SubmitChanges();
            var gpu = (from Product f in db.Products
                       where f.Product_Id.Equals(Request.QueryString["gpu"])
                       select f).FirstOrDefault();
            Cart dd = new Cart
            {
                Product_Id = gpu.Product_Id,
                Quantity   = 1,
                Username   = Convert.ToString(Session["Username"])
            };

            db.Carts.InsertOnSubmit(dd);
            db.SubmitChanges();
            var mem = (from Product g in db.Products
                       where g.Product_Id.Equals(Request.QueryString["mem"])
                       select g).FirstOrDefault();
            Cart ff = new Cart
            {
                Product_Id = mem.Product_Id,
                Quantity   = 1,
                Username   = Convert.ToString(Session["Username"])
            };

            db.Carts.InsertOnSubmit(ff);
            db.SubmitChanges();
            var hard = (from Product h in db.Products
                        where h.Product_Id.Equals(Request.QueryString["hard"])
                        select h).FirstOrDefault();
            Cart gg = new Cart
            {
                Product_Id = hard.Product_Id,
                Quantity   = 1,
                Username   = Convert.ToString(Session["Username"])
            };

            db.Carts.InsertOnSubmit(gg);
            db.SubmitChanges();
            var psu = (from Product i in db.Products
                       where i.Product_Id.Equals(Request.QueryString["psu"])
                       select i).FirstOrDefault();
            Cart pp = new Cart
            {
                Product_Id = psu.Product_Id,
                Quantity   = 1,
                Username   = Convert.ToString(Session["Username"])
            };

            db.Carts.InsertOnSubmit(pp);
            db.SubmitChanges();
            var casee = (from Product j in db.Products
                         where j.Product_Id.Equals(Request.QueryString["case"])
                         select j).FirstOrDefault();
            Cart hh = new Cart
            {
                Product_Id = casee.Product_Id,
                Quantity   = 1,
                Username   = Convert.ToString(Session["Username"])
            };

            db.Carts.InsertOnSubmit(hh);
            db.SubmitChanges();
            Response.Redirect("Index.aspx");
        }
Ejemplo n.º 12
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var db = new DataLinqDataContext();

            //...........................................................................................Product Category List
            string divCategoryDisplay = "";

            dynamic ProductList = from product in db.Products
                                  group product by product.Product_Type into productTypeLst
                                  select productTypeLst.Key;

            divCategoryDisplay += " <li class='closed'><a href='CategoryPage.aspx?Category=AllSpecial'>View All Special Products</a></li>";
            foreach (string prdctType in ProductList)
            {
                divCategoryDisplay += " <li class=closed><a href=CategoryPage.aspx?Category=" + prdctType + ">" + prdctType + "</a>";

                //dynamic ProductItmLst = (from item in db.Products
                //                         where (item.Product_Type.Equals(prdctType)) || (item.Product_IsSpecial == true)
                //                         select item).Take(3);

                dynamic ProductItmLst = (from item in db.Products
                                         where (item.Product_Type.Equals(prdctType) &&
                                                (item.Product_IsActive == true))
                                         select item).Take(3);

                divCategoryDisplay += "<ul>";
                divCategoryDisplay += "<li><a href='CategoryPage.aspx?CategorySpcl=" + prdctType + "'>View All " + prdctType + " Specials</a></li>";
                foreach (Product prdctItm in ProductItmLst)
                {
                    //divCategoryDisplay += "<li><a href=#>" + prdctItm.Product_Name + "</a></li>";
                    divCategoryDisplay += "<li><a href='ProductPage.aspx?ProductId=" + prdctItm.Product_Id + "'>" + prdctItm.Product_Name + "</a></li>";
                }
                divCategoryDisplay += "<li><a href='CategoryPage.aspx?Category=" + prdctType + "'>View All</a></li>";
                divCategoryDisplay += "</ul>";
                divCategoryDisplay += "</li>";
            }

            ulCategoryList.InnerHtml = divCategoryDisplay;

            //..............................................................................Populate Recent Products

            dynamic RecentProductList = (from product in db.Products
                                         where (product.Product_IsActive == true)
                                         orderby product.Product_DateAdded descending
                                         select product).Take(3);

            string strDisplayRcnt = "";

            strDisplayRcnt += "<h6 class='widget-title border-left mb-20'>recent products</h6>";
            foreach (Product prdct in RecentProductList)
            {
                strDisplayRcnt += " <div class='product-item'>";
                strDisplayRcnt += " <div class='product-img'>";
                strDisplayRcnt += " <a href='ProductPage.aspx?ProductId=" + prdct.Product_Id + "'>";
                strDisplayRcnt += " <img src='" + prdct.Product_Img + "' alt='' width=90 height=80/>";
                strDisplayRcnt += " </a>";
                strDisplayRcnt += " </div>";
                strDisplayRcnt += " <div class='product-info'>";
                strDisplayRcnt += " <h6 class='product-title'>";
                strDisplayRcnt += " <a href='ProductPage.aspx?ProductId=" + prdct.Product_Id + "'>" + prdct.Product_Name + "</a>";
                strDisplayRcnt += " </h6>";
                strDisplayRcnt += " <h3 class='pro-price'>R" + String.Format("{0:0.00}", prdct.Product_Price) + "</h3>";
                strDisplayRcnt += " </div>";
                strDisplayRcnt += " </div>";
            }

            WidgetProduct.InnerHtml = strDisplayRcnt;

            //.............................................................................Show Details of Selected Product
            if (Request.QueryString["ProductId"] != null)
            {
                //PrdctID = Convert.ToInt32(Request.QueryString["ProductId"]);
                if (!PrdctID.Equals(Convert.ToInt32(Request.QueryString["ProductId"])))
                {
                    PrdctID  = Convert.ToInt32(Request.QueryString["ProductId"]);
                    PrdctQty = 1;
                }

                //..................................................................Selected Product Specifications

                var Product = (from product in db.Products
                               where (product.Product_Id).Equals(Request.QueryString["ProductId"])
                               select product).FirstOrDefault();

                PrdctNmBrnd.InnerHtml = "<h3 class='text-black-1'>" + Product.Product_Name + "</h3>" + " <h6 class='brand-name-2'>" + Product.Product_Brand + "</h6>";

                description.InnerHtml = "<p>" + Product.Product_Description + "</p>";

                ProductImg.InnerHtml = "<img id='zoom_03' src='" + Product.Product_Img + "' data-zoom-image='" + Product.Product_Img + "' alt=''>";

                string DspPrc = "";
                if (Product.Product_IsSpecial == true)
                {
                    decimal prc1 = (Product.Product_Price) - ((Product.Product_Price) * Convert.ToDecimal(Product.Product_SpclPercantage / 100));
                    DspPrc += "<h5>Old Price</h5>";
                    DspPrc += "<s>" + String.Format("{0:0.00}", Product.Product_Price) + "</s>";
                    DspPrc += "<h5>Special Price</h5>";
                    DspPrc += "<h6><mark>" + String.Format("{0:0.00}", prc1) + "</mark></h6>";
                }
                else
                {
                    DspPrc += "<h5>Price</h5>";
                    DspPrc += "<h6><mark>" + String.Format("{0:0.00}", Product.Product_Price) + "</mark></h6>";
                }
                PriceDsp.InnerHtml = DspPrc;

                string strBtnActnDsply = "";

                strBtnActnDsply += "<ul class='action-button'>";

                strBtnActnDsply += "<li>";
                strBtnActnDsply += "<a href='ProductPage.aspx?AddToWshLst=" + (Request.QueryString["ProductId"]) + "' title='Wishlist' tabindex='0'><i class='zmdi zmdi-favorite'></i></a>";
                strBtnActnDsply += "</li>";

                strBtnActnDsply += "<li>";
                strBtnActnDsply += "<a href='ProductPage.aspx?AddToShpCrt=" + (Request.QueryString["ProductId"]) + "' title='Add to cart' tabindex='0'><i class='zmdi zmdi-shopping-cart-plus'></i></a>";
                strBtnActnDsply += "</li>";

                if ((HttpContext.Current.Session["AuthLevel"] != null) && (HttpContext.Current.Session["AuthLevel"].Equals("Admin")))
                {
                    strBtnActnDsply += "<li>";
                    strBtnActnDsply += "<a href='EditProductPage.aspx?EdtPrdctID=" + (Request.QueryString["ProductId"]) + "' title='Edit Product' tabindex='0'><i class='zmdi zmdi zmdi-edit'></i></a>";
                    strBtnActnDsply += "</li>";
                }

                strBtnActnDsply += "</ul>";

                btnAction.InnerHtml = strBtnActnDsply;



                //.............................................................................Related Product Images


                var RelatedProduct = (from product in db.Products
                                      where (product.Product_Id).Equals(Request.QueryString["ProductId"])
                                      select product).FirstOrDefault();

                dynamic RelatedPrdctLst = (from product in db.Products
                                           where (product.Product_Type).Equals(RelatedProduct.Product_Type) &&
                                           (!(product.Product_Id).Equals(RelatedProduct.Product_Id)) &&
                                           (product.Product_IsActive == true)
                                           select product).Take(3);

                string strDisplay = "";
                foreach (Product prdct in RelatedPrdctLst)
                {
                    strDisplay += " <div class='col-xs-12'>";
                    strDisplay += " <div class='product-item'>";
                    strDisplay += " <div class='product-img'>";
                    strDisplay += " <a href=ProductPage.aspx?ProductId=" + prdct.Product_Id + ">";
                    strDisplay += " <img src=" + prdct.Product_Img + " height=300 width=270 alt=/>";
                    strDisplay += " </a>";
                    strDisplay += " </div>";
                    strDisplay += " <div class='product-info'>";
                    strDisplay += " <h6 class='product-title'>";
                    strDisplay += " <a href=ProductPage.aspx?ProductId=" + prdct.Product_Id + " >" + prdct.Product_Name + "</a>";
                    strDisplay += " </h6>";
                    //strDisplay += " <div class='pro-rating'>";
                    //strDisplay += " <a href=#><i class='zmdi zmdi-star'></i></a>";
                    //strDisplay += " <a href=#><i class='zmdi zmdi-star'></i></a>";
                    //strDisplay += " <a href=#><i class='zmdi zmdi-star'></i></a>";
                    //strDisplay += " <a href=#><i class='zmdi zmdi-star-half'></i></a>";
                    //strDisplay += " <a href=#><i class='zmdi zmdi-star-outline'></i></a>";
                    //strDisplay += " </div>";
                    strDisplay += " <h3 class='pro-price'>R" + String.Format("{0:0.00}", prdct.Product_Price) + "</h3>";
                    strDisplay += " <ul class='action-button'>";

                    strDisplay += " <li>";
                    strDisplay += " <a href='ProductPage.aspx?AddToWshLst=" + prdct.Product_Id + "' title=Wishlist><i class='zmdi zmdi-favorite'></i></a>";
                    strDisplay += " </li>";

                    //strDisplay += " <li>";
                    //strDisplay += " <a href=# data-toggle=modal data-target=#productModal title=Quickview><i class='zmdi zmdi-zoom-in'></i></a>";
                    //strDisplay += " </li>";

                    //strDisplay += " <li>";
                    //strDisplay += " <a href=# title=Compare><i class='zmdi zmdi-refresh'></i></a>";
                    //strDisplay += " </li>";

                    strDisplay += " <li>";
                    strDisplay += " <a href='ProductPage.aspx?AddToShpCrt=" + prdct.Product_Id + "' title=Add to cart><i class='zmdi zmdi-shopping-cart-plus'></i></a>";
                    strDisplay += " </li>";

                    strDisplay += " </ul>";
                    strDisplay += " </div>";
                    strDisplay += " </div>";
                    strDisplay += " </div>";
                } //...........................................end of foreach
                RelatedPrdct.InnerHtml = strDisplay;
            }     //.................................................................end of if

            //.......................................................add to wishlist of the user
            else if (Request.QueryString["AddToWshLst"] != null)
            {
                if (!PrdctID.Equals(Convert.ToInt32(Request.QueryString["AddToWshLst"])))
                {
                    PrdctID  = Convert.ToInt32(Request.QueryString["AddToWshLst"]);
                    PrdctQty = 1;
                }

                if (HttpContext.Current.Session["Username"] != null)
                {
                    var chkWshLst = (from wishlst in db.Wishlists
                                     where ((wishlst.Username).Equals(HttpContext.Current.Session["Username"])) &&
                                     ((wishlst.Product_Id).Equals(Request.QueryString["AddToShpCrt"]))
                                     select wishlst).FirstOrDefault();

                    if (chkWshLst == null)
                    {
                        var AddToWshList = new Wishlist
                        {
                            Username   = Convert.ToString(HttpContext.Current.Session["Username"]),
                            Product_Id = Convert.ToInt32(Request.QueryString["AddToWshLst"]),
                        };
                        db.Wishlists.InsertOnSubmit(AddToWshList);

                        try
                        {
                            db.SubmitChanges();
                            Response.Redirect("CategoryPage.aspx");
                        }
                        catch (Exception ex)
                        {
                            ex.GetBaseException();
                        }
                    }
                }
                else
                {
                    Session["AddListItm"] = Request.QueryString["AddToWshLst"];
                    Response.Redirect("Login.aspx");
                }
            }//...............................................................end of else if

            //...........................................................Adding to shopping cart
            else if (Request.QueryString["AddToShpCrt"] != null)
            {
                if (!PrdctID.Equals(Convert.ToInt32(Request.QueryString["AddToShpCrt"])))
                {
                    PrdctID  = Convert.ToInt32(Request.QueryString["AddToShpCrt"]);
                    PrdctQty = 1;
                }

                if (HttpContext.Current.Session["Username"] != null)
                {
                    //.................................................check if item exist in cart
                    var ChckCart = (from cart in db.Carts
                                    where ((cart.Product_Id).Equals(Request.QueryString["AddToShpCrt"])) &&
                                    ((cart.Username).Equals(HttpContext.Current.Session["Username"]))
                                    select cart).FirstOrDefault();

                    if (ChckCart != null)
                    {
                        int RlQty = ChckCart.Quantity;
                        RlQty = RlQty + PrdctQty;


                        int getPrdct = (from product in db.Products
                                        where (product.Product_Id.Equals(Request.QueryString["AddToShpCrt"]))
                                        select product.Product_OnHand).FirstOrDefault();
                        if (ChckCart.Quantity < getPrdct)
                        {
                            ChckCart.Quantity = RlQty;
                            try
                            {
                                db.SubmitChanges();
                            }
                            catch (Exception ex)
                            {
                                ex.GetBaseException();
                            }
                        }
                    }
                    else
                    {
                        //.................................................adding to cart table
                        Debug.WriteLine(PrdctQty);
                        var AddToCart = new Cart
                        {
                            Product_Id = Convert.ToInt32(Request.QueryString["AddToShpCrt"]),
                            Quantity   = PrdctQty,
                            Username   = Convert.ToString(HttpContext.Current.Session["Username"]),
                        };
                        db.Carts.InsertOnSubmit(AddToCart);
                        try
                        {
                            db.SubmitChanges();
                            //Response.Redirect("CategoryPage.aspx");
                        }
                        catch (Exception ex)
                        {
                            ex.GetBaseException();
                        }
                    }

                    //.............................................deleting item from wishlist if exists
                    var CheckWshLst = (from wishlst in db.Wishlists
                                       where ((wishlst.Username).Equals(HttpContext.Current.Session["Username"])) &&
                                       ((wishlst.Product_Id).Equals(Request.QueryString["AddToShpCrt"]))
                                       select wishlst).FirstOrDefault();

                    if (CheckWshLst != null)
                    {
                        db.Wishlists.DeleteOnSubmit(CheckWshLst);
                        try
                        {
                            db.SubmitChanges();
                        }catch (Exception ex)
                        {
                            ex.GetBaseException();
                        }
                    }

                    Response.Redirect("CategoryPage.aspx");
                }
                else
                {
                    Session["AddListItm"] = Request.QueryString["AddToShpCrt"];
                    Response.Redirect("Login.aspx");
                }
            }//................................................................end of else if

            //.................................................................Removing from Shopping cart
            else if (Request.QueryString["DelFrmShpCrt"] != null)
            {
                var DelFromShopCart = (from cart in db.Carts
                                       where ((cart.Username).Equals(HttpContext.Current.Session["Username"])) &&
                                       ((cart.Product_Id).Equals(Request.QueryString["DelFrmShpCrt"]))
                                       select cart).FirstOrDefault();

                db.Carts.DeleteOnSubmit(DelFromShopCart);
                try
                {
                    db.SubmitChanges();
                    Response.Redirect("CategoryPage.aspx");
                }catch (Exception ex)
                {
                    ex.GetBaseException();
                }
            }
        }//.......................................................................................end of pageload
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (numOfProducts > 0)
            {
                var city    = txtCity.Value.Trim();
                var country = txtCountry.Value.Trim();
                var address = txtAddress.Value.Trim();

                liCountry.InnerText = country;
                liCity.InnerText    = city;
                liAddress.InnerText = address;

                var db = new DataLinqDataContext();

                var newInvoice = new Invoice
                {
                    Invoice_Date  = DateTime.Now,
                    Username      = Convert.ToString(Session["username"]),
                    Invoice_Total = totalSubCart
                };

                db.Invoices.InsertOnSubmit(newInvoice);
                db.SubmitChanges();

                liAddress.InnerText = address;

                var cart = from Cart c in db.Carts
                           where c.Username.Equals(Session["username"])
                           select c;

                foreach (Cart c in cart)
                {
                    var product = (from Product p in db.Products
                                   where p.Product_Id.Equals(c.Product_Id)
                                   select p).FirstOrDefault();

                    var newItem = new Item
                    {
                        Invoice_Id        = newInvoice.Invoice_Id,
                        Product_Id        = c.Product_Id,
                        Item_Qty          = c.Quantity,
                        Item_SellingPrice = product.Product_Price
                    };

                    db.Items.InsertOnSubmit(newItem);
                    db.SubmitChanges();

                    db.Carts.DeleteOnSubmit(c);
                    db.SubmitChanges();


                    product.Product_OnHand -= c.Quantity;
                    db.SubmitChanges();
                }

                displayOrderNo1.InnerText = Convert.ToString(newInvoice.Invoice_Id);

                // Response.Redirect("Wishlist.aspx#order-complete");
                //  liPhone = phone;

                //preferences.Attributes.Remove("class");
                //preferences.Attributes.Add("class", "tab-pane");
                //cpuBut.Attributes.Add("class", "active");
                //cpu.Attributes.Remove("class");
                //cpu.Attributes.Add("class", "tab-pane active");
            }
        }