// METHOD TO FILTER THE PRODUCT BY THE PRICE PROVIDED private void button8_Click(object sender, EventArgs e) { decimal.TryParse(textBox5.Text, out decimal d); try { if (textBox5.Text != "") { if (d > 0 && decimal.TryParse(textBox5.Text, out decimal _)) { // Method to filter the product list by the price inputted this.dataGridView1.DataSource = ResProd.FilterProductByPrice(d); textBox5.Text = ""; } } else { // Method to populate back the product list by its offset this.dataGridView1.DataSource = ResProd.GetAllProductByOffSet(Offset, Span); textBox5.Text = ""; } } catch (Exception ex) { MessageBox.Show("Invalid Details"); } }
// METHOD TO ADD PRODUCT private void button1_Click(object sender, EventArgs e) { decimal.TryParse(textBox2.Text, out decimal d); try { if (textBox1.Text != "" && textBox2.Text != "") { if (d > 0 && decimal.TryParse(textBox2.Text, out decimal _)) { // Method to add to the Product table ResProd.AddProduct(textBox1.Text, d); // Method to Populate the Data Grid View this.dataGridView1.DataSource = ResProd.GetAllProductByOffSet(Offset, Span); MessageBox.Show("Product Added Successfully"); } else { MessageBox.Show("Enter a Positive Value"); } } } catch (Exception ex) { MessageBox.Show("Fill all the Boxes available"); } // Change the text to empty string textBox1.Text = ""; textBox2.Text = ""; }
// METHOD TO EDIT AND UPDATE PRODUCT private void button2_Click(object sender, EventArgs e) { decimal.TryParse(textBox3.Text, out decimal d); try { if (textBox3.Text != "" && textBox4.Text != "") { if (d > 0 && decimal.TryParse(textBox3.Text, out decimal _)) { // Method to edit to the Product table ResProd.EditProduct(ID, textBox4.Text, d); // Method to Populate the Data Grid View this.dataGridView1.DataSource = ResProd.GetAllProductByOffSet(Offset, Span); MessageBox.Show("Product Updated Successfully"); } else { MessageBox.Show("Invalid Details"); } } } catch (Exception ex) { MessageBox.Show("Fill all the Boxes Available"); } // Change the Text Box Data textBox3.Text = ""; textBox4.Text = ""; }
// METHOD TO PERFORM WHEN THE FORM LOAD private void ShoppingCartUI_Load(object sender, EventArgs e) { // Open the connection Conn.OpenConnection(); ResProd.GetAllProduct(); this.dataGridView1.DataSource = ResProd.GetAllProductByOffSet(Offset, Span); this.dataGridView2.DataSource = ResCart.GetAllCart(); // Close the connection Conn.CloseConnection(); }
// METHOD TO GO PREVIOUS OF PRODUCTLIST private void button6_Click(object sender, EventArgs e) { try { Offset -= 5; this.dataGridView1.DataSource = ResProd.GetAllProductByOffSet(Offset, Span); } catch (Exception) { Offset += 5; } }
// METHOD TO GO NEXT OF PRODUCTLIST private void button7_Click(object sender, EventArgs e) { Offset += 5; var list = ResProd.GetAllProductByOffSet(Offset, Span); if (list.Count == 0) { Offset -= 5; list = ResProd.GetAllProductByOffSet(Offset, Span); } this.dataGridView1.DataSource = list; }
// METHOD TO REMOVE FROM PRODUCT private void button3_Click(object sender, EventArgs e) { if (ID > 0) { // Method to remove from the Product table ResProd.RemoveProduct(ID); // Method to Populate the Data Grid View this.dataGridView1.DataSource = ResProd.GetAllProductByOffSet(Offset, Span); this.dataGridView2.DataSource = ResCart.GetAllCart(); MessageBox.Show("Product Deleted Successfully"); } else { MessageBox.Show("Invalid Details"); } }
// METHOD TO FILTER THE PRODUCT BY THE NAME PROVIDED private void button9_Click(object sender, EventArgs e) { try { if (textBox5.Text != "") { // Method to filter the product list by the name inputted this.dataGridView1.DataSource = ResProd.FilterProductByProductName(textBox5.Text); textBox5.Text = ""; } else { // Method to populate back the product list by its offset this.dataGridView1.DataSource = ResProd.GetAllProductByOffSet(Offset, Span); textBox5.Text = ""; } } catch (Exception ex) { MessageBox.Show("Invalid Details "); } }
// METHOD TO REFRESH THE PRODUCT DATAGRIDVIEW private void button10_Click(object sender, EventArgs e) { this.dataGridView1.DataSource = ResProd.GetAllProductByOffSet(Offset, Span); }