示例#1
0
        protected void product_grid_OnPageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            product_grid.PageIndex = e.NewPageIndex;

            TelevisionDbDataContext context = new TelevisionDbDataContext();

            List <Product> queryAsList = (List <Product>)Cache["Product_Query"];

            if (queryAsList == null)
            {
                // cache miss ($$$)
                var pSource = (from Products in context.Products
                               select Products);

                List <Product> pList = pSource.ToList();

                product_grid.DataSource = pSource;
                product_grid.DataBind();

                Cache.Insert("Product_Query", pList, null, DateTime.UtcNow.AddMinutes(10), Cache.NoSlidingExpiration);
            }
            else
            {
                // cache hit

                product_grid.DataSource = Cache["Product_Query"];
                product_grid.DataBind();
            }

            // HERE: bar is initialized either way
        }
示例#2
0
        public static bool ReSeedData(out string error)
        {
            // LINQ-to-SQL data context. Automatically created with .dbml
            TelevisionDbDataContext context = new TelevisionDbDataContext();

            try
            {
                // delete all existing rows (DELETE FROM Defects).
                context.Products.DeleteAllOnSubmit(context.Products);
                // insert each Defect from the sample data
                foreach (Product d in data)
                {
                    context.Products.InsertOnSubmit(d);
                }
                // commit
                context.SubmitChanges();
                error = "";
                return(true);
            }
            catch (Exception e)
            {
                // return message from thrown exception
                error = e.Message;
                return(false);
            }
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            //Reset All Values Inside Dictionary

            Dictionary <string, int> televisions = new Dictionary <string, int>();
            TelevisionDbDataContext  context     = new TelevisionDbDataContext();

            var query = (from p in context.Products
                         select p.Name).ToList();

            List <string> names = new List <string>();

            names = query;

            for (int i = 0; i < names.Count; i++)
            {
                televisions.Add(names[i].Trim(), 0);
            }

            txtQuantWant.Enabled = true;
            txtQuantWant.Text    = "";
            lblquant.Text        = string.Format("{0:0}", televisions[theProduct.Name] + 3);
            lblHowMuch.Text      = ("You currently have " + televisions[theProduct.Name]);

            Session["cart"] = televisions;
        }
示例#4
0
        protected void btn_purchase_Click(object sender, EventArgs e)
        {
            TelevisionDbDataContext context = new TelevisionDbDataContext();
            Dictionary<string, int> televisions = (Dictionary<string, int>)Session["cart"];

            
            using (TransactionScope cartTrans = new TransactionScope())
            {
                try
                {
                    //Updating the Database
                    foreach (var key in televisions.Keys)
                    {
                        int value = televisions[key];

                        //Checking to See if Quantity in cart is greater than 0
                        if (value > 0)
                        {

                            var query = from p in context.Products
                                        where p.Name == key
                                        select p;
                            theProduct = query.Single();

                            theProduct.Quantity = theProduct.Quantity - televisions[key];
                            context.SubmitChanges();

                        }
                    }
                    var nameList = (from p in context.Products
                                    select p.Name).ToList();

                    List<string> names = new List<string>();
                    names = nameList;

                    televisions = new Dictionary<string, int>();

                    for (int i = 0; i < names.Count; i++)
                    {
                        televisions.Add(names[i].Trim(), 0);
                    }

                    Session["cart"] = televisions;

                    Response.Redirect("~/ThankYou.aspx",false);

                    cartTrans.Complete();
                }
                catch (Exception E)
                {
                    cartTrans.Dispose();
                    Response.Redirect("~/ErrorPage.aspx?err=" + E.Message);
                }
            }
        }
示例#5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            TelevisionDbDataContext context = new TelevisionDbDataContext();
            List <string>           names   = null;


            List <Product> queryAsList = (List <Product>)Cache["Product_Query"];

            if (queryAsList == null)
            {
                // cache miss ($$$)
                var pSource = (from Products in context.Products
                               select Products);

                var query = (from p in context.Products
                             select p.Name).ToList();

                names = query;

                List <Product> pList = pSource.ToList();

                product_grid.DataSource = pSource;
                product_grid.DataBind();

                Cache.Insert("Product_Query", pList, null, DateTime.UtcNow.AddMinutes(10), Cache.NoSlidingExpiration);
            }
            else
            {
                // cache hit

                product_grid.DataSource = Cache["Product_Query"];
                product_grid.DataBind();
            }

            /*
             * if (!IsPostBack)
             * {
             *  //Place all products in the drop down menu
             *  for (int i = 0; i < names.Count; i++)
             *  {
             *      ddlTvChoice.Items.Add(names[i].Trim());
             *  }
             * }
             * */
        }
示例#6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            TelevisionDbDataContext context = new TelevisionDbDataContext();
            Dictionary<string, int> televisions = (Dictionary<string, int>)Session["cart"];

            decimal subTotal = 0;

            List<CartItem> cartList = new List<CartItem>();

            foreach (var key in televisions.Keys)
            {
               int value = televisions[key];

                //Checking to See if Quantity is greater than 0
                if (value > 0)
                {
                    var query = from p in context.Products
                                where p.Name == key
                                select p;
                    theProduct = query.Single();

                    blList.Items.Add(key + " (" + value + " @" + theProduct.Price + " ): $" + (theProduct.Price * value));
                    subTotal += (decimal)(theProduct.Price * value);


                    CartItem cartitems = new CartItem(theProduct.Name, (decimal)theProduct.Price, (decimal)(theProduct.Price * value), value);
                    cartList.Add(cartitems);
                }
            }

            gv_cart.DataSource = cartList;
            gv_cart.DataBind();

            decimal gst = (decimal)(0.05) * subTotal;
            decimal pst = (decimal)(0.1) * subTotal;

            lblSubTot.Text = string.Format("{0:C}", subTotal);
            lblGst.Text = string.Format("{0:C}", gst);
            lblPst.Text = string.Format("{0:C}", pst);
            lblTot.Text = string.Format("{0:C}", gst + pst + subTotal);   
            
        }
示例#7
0
        void Session_Start(object sender, EventArgs e)
        {
            //Getting all Names from database to List
            TelevisionDbDataContext context = new TelevisionDbDataContext();
            var query = (from p in context.Products
                         select p.Name).ToList();

            List <string> names = new List <string>();

            names = query;

            Dictionary <string, int> televisions = new Dictionary <string, int>();

            for (int i = 0; i < names.Count; i++)
            {
                televisions.Add(names[i].Trim(), 0);
            }

            Session["cart"] = televisions;
        }
示例#8
0
        public string DecriptionUrl(string theName)
        {
            string description;

            TelevisionDbDataContext context = new TelevisionDbDataContext();
            Product pdescription            = (Product)Cache["Product_Description"];

            var query = from p in context.Products
                        where p.Name == theName
                        select p;

            theProduct = query.Single();

            var pathToFile = Server.MapPath(theProduct.Description);

            description  = File.ReadAllText(pathToFile);
            description  = description.Substring(0, 50);
            description += "...";
            return(description);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //Getting all products with requested image
            string choice = Request.QueryString["img"];

            TelevisionDbDataContext context = new TelevisionDbDataContext();
            Product currentProduct          = (Product)Cache["Description_Query"];

            if (currentProduct == null || currentProduct.Name != choice)
            {
                // cache miss ($$$)
                var query = from p in context.Products
                            where p.Name == choice
                            select p;
                theProduct = query.Single();

                Cache.Insert("Description_Query", theProduct, null, DateTime.UtcNow.AddMinutes(1), Cache.NoSlidingExpiration);
            }
            else
            {
                // cache hit
                theProduct = (Product)Cache["Description_Query"];
            }

            //Keeping the same Quantity Through Session
            Dictionary <string, int> televisions = (Dictionary <string, int>)Session["cart"];

            //Enable User to Keep Using Based On Stock
            if (televisions[choice] == theProduct.Quantity)
            {
                txtQuantWant.Text    = "Out of Stock";
                txtQuantWant.Enabled = false;
            }

            //Setting the Basics
            televisions = setBasics(televisions);
            setImage();
        }