Example #1
0
        public void button2Clicked(object sender, CommandEventArgs e)
        {
            prod product1 = new prod();

            String[] spearator = { "|" };
            int      count     = 4;

            String[] strlist = e.CommandArgument.ToString().Split(spearator, count,
                                                                  StringSplitOptions.RemoveEmptyEntries);


            float  price = float.Parse(strlist[0], System.Globalization.CultureInfo.InvariantCulture);
            string des   = strlist[2];
            string name  = strlist[1];
            string src   = strlist[3];

            product1.base_price = price;
            product1.des        = des;
            product1.name       = name;
            product1.src        = src;


            cart cart_1 = new cart();

            cart_1.poduct = product1;
            cart_1.price  = product1.base_price;


            //create cookie with array and price
            HttpCookie myCookie = Request.Cookies["checkout"];

            if (myCookie == null)
            {
                cart[] carts_list = carts.InitializeArray(1);
                carts_list[0] = cart_1;
                carts cart_class = new carts();
                cart_class.all_items = carts_list;


                string myObjectJson = new JavaScriptSerializer().Serialize(cart_class);
                var    cookie       = new HttpCookie("checkout", myObjectJson)
                {
                    Expires = DateTime.Now.AddYears(1)
                };
                HttpContext.Current.Response.Cookies.Add(cookie);
            }
            else
            {
                HttpCookie cook = HttpContext.Current.Request.Cookies["checkout"];


                carts myObjectJson = new JavaScriptSerializer().Deserialize <carts>(cook.Value);

                cart[] list       = myObjectJson.all_items;
                cart[] carts_list = carts.InitializeArray(list.Length + 1);

                int n = 0;
                while (n < list.Length)
                {
                    carts_list[n] = list[n];
                    n++;
                }
                carts_list[list.Length] = cart_1;
                carts cart_class = new carts();
                cart_class.all_items = carts_list;
                string myObjectJson2 = new JavaScriptSerializer().Serialize(cart_class);
                cook = new HttpCookie("checkout", myObjectJson2)
                {
                    Expires = DateTime.Now.AddYears(1)
                };
                HttpContext.Current.Response.Cookies.Add(cook);
            }
        }
Example #2
0
        //configure
        public void button3Clicked(object sender, EventArgs args)
        {
            cart cart_1 = new cart();

            float price = 0;
            Regex rx    = new Regex(@"(.+)?\$(.+)",
                                    RegexOptions.Compiled | RegexOptions.IgnoreCase);

            string ram = Request.Form["ram"];


            MatchCollection matches = rx.Matches(ram);

            foreach (Match match in matches)
            {
                GroupCollection groups = match.Groups;

                string p    = groups[2].Value;
                string name = groups[1].Value;
                cart_1.ram = name;
                price     += float.Parse(p, System.Globalization.CultureInfo.InvariantCulture);
            }


            string drive = Request.Form["Hard Drive"];


            matches = rx.Matches(drive);

            foreach (Match match in matches)
            {
                GroupCollection groups = match.Groups;

                string p    = groups[2].Value;
                string name = groups[1].Value;
                cart_1.drive = name;
                price       += float.Parse(p, System.Globalization.CultureInfo.InvariantCulture);
            }

            string CPU = Request.Form["CPU"];



            matches = rx.Matches(CPU);

            foreach (Match match in matches)
            {
                GroupCollection groups = match.Groups;

                string p    = groups[2].Value;
                string name = groups[1].Value;
                cart_1.cpu = name;
                price     += float.Parse(p, System.Globalization.CultureInfo.InvariantCulture);
            }
            string monitor = Request.Form["monitor"];

            matches = rx.Matches(monitor);

            foreach (Match match in matches)
            {
                GroupCollection groups = match.Groups;

                string p    = groups[2].Value;
                string name = groups[1].Value;
                cart_1.monitor = name;
                price         += float.Parse(p, System.Globalization.CultureInfo.InvariantCulture);
            }
            string os = Request.Form["os"];

            matches = rx.Matches(os);

            foreach (Match match in matches)
            {
                GroupCollection groups = match.Groups;

                string p    = groups[2].Value;
                string name = groups[1].Value;
                cart_1.os = name;
                price    += float.Parse(p, System.Globalization.CultureInfo.InvariantCulture);
            }

            string sound = Request.Form["sound"];

            matches = rx.Matches(sound);

            foreach (Match match in matches)
            {
                GroupCollection groups = match.Groups;

                string p    = groups[2].Value;
                string name = groups[1].Value;
                cart_1.sound = name;
                price       += float.Parse(p, System.Globalization.CultureInfo.InvariantCulture);
            }
            price         = price + base_price;
            cart_1.price  = price;
            cart_1.poduct = product1;
            string bas = "Added to your cart with a price of $";

            price_spot.InnerText = bas + price.ToString();


            //create cookie with array and price
            HttpCookie myCookie = Request.Cookies["checkout"];

            if (myCookie == null)
            {
                cart[] carts_list = carts.InitializeArray(1);
                carts_list[0] = cart_1;
                carts cart_class = new carts();
                cart_class.all_items = carts_list;


                string myObjectJson = new JavaScriptSerializer().Serialize(cart_class);
                var    cookie       = new HttpCookie("checkout", myObjectJson)
                {
                    Expires = DateTime.Now.AddYears(1)
                };
                HttpContext.Current.Response.Cookies.Add(cookie);
            }
            else
            {
                HttpCookie cook = HttpContext.Current.Request.Cookies["checkout"];


                carts myObjectJson = new JavaScriptSerializer().Deserialize <carts>(cook.Value);

                cart[] list       = myObjectJson.all_items;
                cart[] carts_list = carts.InitializeArray(list.Length + 1);

                int n = 0;
                while (n < list.Length)
                {
                    carts_list[n] = list[n];
                    n++;
                }
                carts_list[list.Length] = cart_1;
                carts cart_class = new carts();
                cart_class.all_items = carts_list;
                string myObjectJson2 = new JavaScriptSerializer().Serialize(cart_class);
                cook = new HttpCookie("checkout", myObjectJson2)
                {
                    Expires = DateTime.Now.AddYears(1)
                };
                HttpContext.Current.Response.Cookies.Add(cook);
            }
        }