public prod get_prod(string label) { prod p1 = new prod(); string _connectionString = "Server = tcp:comp466.database.windows.net,1433; Initial Catalog = comp466; Persist Security Info = False; User ID = samh@COMP466; Password = test123$$$; MultipleActiveResultSets = False; Encrypt = True; TrustServerCertificate = False; Connection Timeout = 30;"; using (SqlConnection connection = new SqlConnection(_connectionString)) { using (SqlCommand command_comp = new SqlCommand("SELECT * FROM product WHERE name1 = @label", connection)) { command_comp.Parameters.AddWithValue("@label", label); connection.Open(); using (SqlDataReader reader_comp = command_comp.ExecuteReader()) { while (reader_comp.Read()) { p1.name = reader_comp["name1"].ToString(); p1.src = reader_comp["src"].ToString(); p1.des = reader_comp["des"].ToString(); p1.base_price = float.Parse(reader_comp["price"].ToString(), System.Globalization.CultureInfo.InvariantCulture); break; } } } } return(p1); }
public cart compcart(prod product) { cart cart1 = new cart(); prod p1 = new prod(); string _connectionString = "Server = tcp:comp466.database.windows.net,1433; Initial Catalog = comp466; Persist Security Info = False; User ID = samh@COMP466; Password = test123$$$; MultipleActiveResultSets = False; Encrypt = True; TrustServerCertificate = False; Connection Timeout = 30;"; using (SqlConnection connection = new SqlConnection(_connectionString)) { using (SqlCommand command_comp = new SqlCommand("SELECT * FROM product WHERE name1 = @label", connection)) { command_comp.Parameters.AddWithValue("@label", product.name); connection.Open(); using (SqlDataReader reader_comp = command_comp.ExecuteReader()) { while (reader_comp.Read()) { cart1.price = float.Parse(reader_comp["standard_price"].ToString(), System.Globalization.CultureInfo.InvariantCulture); break; } } } } cart1.poduct = product; cart1.ram = "G.SKILL Ripjaws V Series 8GB"; cart1.drive = "WD Blue 1TB"; cart1.cpu = "Intel Core i5-8400"; cart1.monitor = "ASUS VP249HE Eye Care Monitor 23.8"; cart1.os = "Windows 10 Home"; cart1.sound = "Creative Sound Blaster Audigy RX 7.1"; return(cart1); }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); List <string> labels = new List <string>(); string _connectionString = "Server = tcp:comp466.database.windows.net,1433; Initial Catalog = comp466; Persist Security Info = False; User ID = samh@COMP466; Password = test123$$$; MultipleActiveResultSets = False; Encrypt = True; TrustServerCertificate = False; Connection Timeout = 30;"; using (SqlConnection connection = new SqlConnection(_connectionString)) { using (SqlCommand command_comp = new SqlCommand("SELECT name1 FROM product", connection)) { connection.Open(); using (SqlDataReader reader_comp = command_comp.ExecuteReader()) { int i = 0; while (reader_comp.Read() && i <= 4) { labels.Add(reader_comp["name1"].ToString()); i++; } } } } prod p = get_prod(labels[1]); cart cart1 = compcart(p); makcomel(cart1, button5, button1, product1, des1, im1, price1); prod p2 = get_prod(labels[0]); cart cart2 = new cart(); cart2.poduct = p2; cart2.price = 10F; makereg(cart2, button2, product2, des2, im2, price2); prod p3 = get_prod(labels[2]); cart cart3 = compcart(p3); makcomel(cart3, button6, button4, product3, des3, im3, price3); prod p4 = get_prod(labels[3]); cart cart4 = new cart(); cart4.poduct = p4; cart4.price = 59.99F; makereg(cart4, button7, product4, des4, im4, price4); }
public void button5Clicked(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; string myObjectJson3 = new JavaScriptSerializer().Serialize(product1); HttpCookie myCookie = new HttpCookie("prod", myObjectJson3) { Expires = DateTime.Now.AddYears(1) }; HttpContext.Current.Response.Cookies.Add(myCookie); Response.Redirect("product.aspx"); }
public void button4Clicked(object sender, EventArgs e) { string sVal = list1.Items[list1.SelectedIndex].Value; char[] spearator = { '|' }; Int32 count = 3; String[] strlist = sVal.Split(spearator, count, StringSplitOptions.None); string name1 = strlist[0]; int id = Int32.Parse(strlist[1]); string ConnectionString = "Server = tcp:comp466.database.windows.net,1433; Initial Catalog = comp466; Persist Security Info = False; User ID = samh@COMP466; Password = test123$$$; MultipleActiveResultSets = False; Encrypt = True; TrustServerCertificate = False; Connection Timeout = 30;"; using (var sc = new SqlConnection(ConnectionString)) using (var cmd = sc.CreateCommand()) { sc.Open(); cmd.CommandText = "DELETE FROM Orders WHERE oder_id = @word"; cmd.Parameters.AddWithValue("@word", id); cmd.ExecuteNonQuery(); } cart cart_1 = new cart(); float price = 0; Regex rx = new Regex(@"(.+)?\$(.+)", RegexOptions.Compiled | RegexOptions.IgnoreCase); string ram1 = ram.Items[ram.SelectedIndex].Value; MatchCollection matches = rx.Matches(ram1); 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 drive1 = drive.Items[drive.SelectedIndex].Value; matches = rx.Matches(drive1); 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 cpu1 = cpu.Items[cpu.SelectedIndex].Value; matches = rx.Matches(cpu1); 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 monitor1 = monitor.Items[monitor.SelectedIndex].Value; matches = rx.Matches(monitor1); 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 os1 = os.Items[os.SelectedIndex].Value; matches = rx.Matches(os1); 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 sound1 = sound.Items[sound.SelectedIndex].Value; matches = rx.Matches(sound1); 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); } prod product1 = new prod(); float base_price = 0.00F; int prod_id = 0; string _connectionString = "Server = tcp:comp466.database.windows.net,1433; Initial Catalog = comp466; Persist Security Info = False; User ID = samh@COMP466; Password = test123$$$; MultipleActiveResultSets = False; Encrypt = True; TrustServerCertificate = False; Connection Timeout = 30;"; using (SqlConnection connection = new SqlConnection(_connectionString)) { using (SqlCommand command_comp = new SqlCommand("SELECT * FROM product WHERE name1 = @label", connection)) { command_comp.Parameters.AddWithValue("@label", name1); connection.Open(); using (SqlDataReader reader_comp = command_comp.ExecuteReader()) { while (reader_comp.Read()) { base_price = float.Parse(reader_comp["price"].ToString(), System.Globalization.CultureInfo.InvariantCulture); product1.base_price = base_price; product1.des = reader_comp["des"].ToString(); product1.src = reader_comp["src"].ToString(); product1.name = name1; prod_id = System.Convert.ToInt32(reader_comp["prod_id"]); break; } } } price = price + base_price; cart_1.price = price; cart_1.poduct = product1; string bas = "Added to your order with a price of $"; price_spot.InnerText = bas + price.ToString(); HttpCookie myCookie2 = Request.Cookies["user"]; using (SqlConnection connection1 = new SqlConnection(_connectionString)) { String query = "INSERT INTO Orders (username,prod_id,ram, drive, cpu, monitor, os, sound, price, type) VALUES (@username, @id, @ram, @drive, @cpu, @monitor, @os, @sound, @price, 'comp')"; using (SqlCommand command = new SqlCommand(query, connection1)) { command.Parameters.AddWithValue("@id", prod_id); command.Parameters.AddWithValue("@ram", cart_1.ram); command.Parameters.AddWithValue("@username", myCookie2.Value); command.Parameters.AddWithValue("@drive", cart_1.drive); command.Parameters.AddWithValue("@cpu", cart_1.cpu); command.Parameters.AddWithValue("@monitor", cart_1.monitor); command.Parameters.AddWithValue("@os", cart_1.os); command.Parameters.AddWithValue("@sound", cart_1.sound); command.Parameters.AddWithValue("@price", cart_1.price); connection1.Open(); int result = command.ExecuteNonQuery(); } } } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); signForm1.Visible = false; forgot.Visible = false; button7.Visible = false; myForm.Visible = false; signForm1.Visible = false; button13.Visible = false; button7.Visible = false; myForm.Visible = false; signForm1.Visible = false; forgot.Visible = false; button13.Visible = false; button14.Visible = false; button15.Visible = false; HttpCookie myCookie = Request.Cookies["user"]; if (myCookie == null) { display.InnerText = "Please login to view your orders"; myForm.Visible = true; button13.Visible = true; button7.Visible = true; } else { string username = myCookie.Value; string write = ""; button14.Visible = true; button15.Visible = true; using (SqlConnection connection = new SqlConnection(@"Server = tcp:comp466.database.windows.net,1433; Initial Catalog = comp466; Persist Security Info = False; User ID = samh@COMP466; Password = test123$$$; MultipleActiveResultSets = False; Encrypt = True; TrustServerCertificate = False; Connection Timeout = 30;")) { using (SqlCommand command = new SqlCommand("SELECT * FROM Orders WHERE username = @username", connection)) { command.Parameters.AddWithValue("@username", username); connection.Open(); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { string curuse = reader["username"].ToString(); if (curuse == username) { int label = System.Convert.ToInt32(reader["prod_id"]); SqlConnection connection1 = new SqlConnection(@"Server = tcp:comp466.database.windows.net,1433; Initial Catalog = comp466; Persist Security Info = False; User ID = samh@COMP466; Password = test123$$$; MultipleActiveResultSets = False; Encrypt = True; TrustServerCertificate = False; Connection Timeout = 30;"); using (SqlCommand command_comp = new SqlCommand("SELECT * FROM product WHERE prod_id = @label", connection1)) { command_comp.Parameters.AddWithValue("@label", label); connection1.Open(); using (SqlDataReader reader_comp = command_comp.ExecuteReader()) { while (reader_comp.Read()) { prod prod1 = new prod(); cart add = new cart(); prod1.base_price = float.Parse(reader_comp["price"].ToString(), CultureInfo.InvariantCulture.NumberFormat); prod1.name = reader_comp["name1"].ToString(); prod1.src = reader_comp["src"].ToString(); prod1.des = reader_comp["des"].ToString(); add.poduct = prod1; add.ram = reader["ram"].ToString(); add.drive = reader["drive"].ToString(); add.cpu = reader["cpu"].ToString(); add.monitor = reader["monitor"].ToString(); add.os = reader["os"].ToString(); add.sound = reader["sound"].ToString(); add.price = float.Parse(reader["price"].ToString(), CultureInfo.InvariantCulture.NumberFormat); if (reader["type"].ToString() == "reg") { write += "<li><span3><div class='thumbnail'><a><img src ='" + add.poduct.src + "' alt=''/></a><div class='caption'><h5>" + add.poduct.name + "</h5><p>" + add.poduct.des + "</p><p>$" + add.price + "</p><h4 style = 'text-align:center' > </ h4 ></ div ></ div ></span3> </li>"; } else { write += "<li><span3><div class='thumbnail'><a><img src ='" + add.poduct.src + "' alt=''/></a><div class='caption'><h5>" + add.poduct.name + "</h5><p>" + add.poduct.des + "</p><p>Ram: " + add.ram + "</p><p>Hard Drive: " + add.drive + "</p><p>CPU: " + add.cpu + "</p><p>Display: " + add.monitor + "</p><p>OS: " + add.os + "</p><p>Sound Card: " + add.sound + "</p><p>$" + add.price + "</p><h4 style = 'text-align:center' > </ h4 ></ div ></ div ></span3> </li>"; } } } } } } } } } products.InnerHtml = write; } }
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); } }