protected void Button5_Click(object sender, EventArgs e) { ListItem itm = ListBox2.SelectedItem; Label4.Text = " "; KeyValuePair <int, int> r = lst1.SingleOrDefault(x => x.Key == Convert.ToInt32(itm.Value)); //Label3.Text = r.Key.ToString(); ProductService.IproductsClient client = new ProductService.IproductsClient(); ProductService.Product p = client.GetProduct(Convert.ToInt32(itm.Value)); total -= r.Value * p.ProductPrice; Label5.Text = total.ToString(); lst1.Remove(r); Label4.Text = ""; foreach (var element in lst1) { Label4.Text += element; } ListBox2.Items.Remove(ListBox2.SelectedItem); ListBox1.Items.Add(itm); ListBox1.ClearSelection(); }
protected void Button6_Click(object sender, EventArgs e) { ProductService.IproductsClient client = new ProductService.IproductsClient(); ProductService.Bill b = new ProductService.Bill(); b.date = DateTime.Today; b.total = total; int id2 = client.StoreBill(b); string connetionString; SqlConnection cnn; connetionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=ShopDatabase;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"; cnn = new SqlConnection(connetionString); cnn.Open(); foreach (var itm1 in lst1) { int p = client.GetProductPrice(itm1.Key); ProductService.Product p1 = client.GetProduct(itm1.Key); ProductService.Product p2 = new ProductService.Product(); p2.ProductId = p1.ProductId; p2.ProductName = p1.ProductName; p2.ProductPrice = p2.ProductPrice; p2.Description = p1.Description; p2.Quantity = itm1.Value; client.UpdateProductDetails(p2); var sql = "INSERT INTO History(BillNo,Productid,Price,Quantity,Total) VALUES(@billno,@pid,@pprice,@qun,@tot)"; using (var cmd = new SqlCommand(sql, cnn)) { cmd.Parameters.AddWithValue("@billno", id2); cmd.Parameters.AddWithValue("@pid", itm1.Key); cmd.Parameters.AddWithValue("@pprice", p); cmd.Parameters.AddWithValue("@qun", itm1.Value); cmd.Parameters.AddWithValue("@tot", p * itm1.Value); cmd.ExecuteNonQuery(); } } cnn.Close(); Label4.Text = "Wohoo! Purchase is successful!!! and Your Invoice number is:"; Label4.Text += id2.ToString(); total = 0; Label5.Text = total.ToString(); foreach (ListItem itm3 in ListBox2.Items) { ListBox1.Items.Add(itm3); } ListBox2.Items.Clear(); lst1.Clear(); }
protected void Button4_Click(object sender, EventArgs e) { if (!IsPostBack) { //d1 = new KeyValuePair<int, int>[20]; Label3.Text = ""; total = 0; } if (!System.Text.RegularExpressions.Regex.IsMatch(TextBox6.Text, "^[0-9]*$") || TextBox6.Text == "") { Label3.Text = "Please enter valid Quantity!"; Label3.BackColor = System.Drawing.Color.Red; } else { int q = Convert.ToInt32(TextBox6.Text); int id1 = Convert.ToInt32(ListBox1.SelectedItem.Value); if (arr1[id1] < q) { Label3.Text = "Quantity not available as you want!"; Label3.BackColor = System.Drawing.Color.Red; return; } lst1.Add(new KeyValuePair <int, int>(Convert.ToInt32(ListBox1.SelectedItem.Value), Convert.ToInt32(TextBox6.Text))); //list =lst1; ListItem itm = ListBox1.SelectedItem; //Label3.Text = ListBox1.SelectedItem.Value; ListBox1.Items.Remove(ListBox1.SelectedItem); /*itm.Text = ListBox1.SelectedItem.Text; * int p = Convert.ToInt32(ListBox1.SelectedItem.Value); * itm.Value =(p*q).ToString();*/ ProductService.IproductsClient client = new ProductService.IproductsClient(); ProductService.Product p = client.GetProduct(id1); total += q * p.ProductPrice; ListBox2.Items.Add(itm); ListBox2.ClearSelection(); Label3.Text = " "; Label5.Text = total.ToString(); foreach (var element in lst1) { Label3.Text += element; } } }
protected void Button1_Click(object sender, EventArgs e) { ProductService.IproductsClient client = new ProductService.IproductsClient(); Label5.Text = ""; if (TextBox1.Text == "" || !System.Text.RegularExpressions.Regex.IsMatch(TextBox1.Text, "^[0-9]*$")) { Label1.Text = "Please enter valid Product id!"; Label1.BackColor = System.Drawing.Color.Red; } else { int id = Convert.ToInt32(TextBox1.Text); ProductService.Product p = client.GetProduct(id); TextBox2.Text = p.ProductName; TextBox3.Text = p.ProductPrice.ToString(); TextBox4.Text = p.Quantity.ToString(); TextBox5.Text = p.Description; Label1.Text = "Product fetched!"; Label1.BackColor = System.Drawing.Color.Green; } }