private void button2_Click(object sender, EventArgs e) { ProductEntity pe = new ProductEntity(); if (productcode == true) { if (!pe.ProductExistsByCode(txt_product_code.Text)) { MessageBox.Show("Product Code Does Not Exist"); return; } else { pe = pe.FindProductByCode(txt_product_code.Text); if (pe == null) { MessageBox.Show("Product Code Does Not Exist !!"); return; } } } else { //Check If Product Combo Box Has Item Selected if (combo_product_name.SelectedIndex == 0) { MessageBox.Show("Please Select Product"); return; } else { pe = pe.FindProductByCode(combo_product_name.SelectedValue.ToString()); if (pe == null) { MessageBox.Show("Product Code Does Not Exist !!"); return; } } } string[] rows = new string[]{pe.id,pe.code,pe.name,pe.price,pe.specifications}; dataGridView1.Rows.Add(rows); lb_grand_total.Text = Convert.ToString(Convert.ToInt32(lb_grand_total.Text) + Convert.ToInt32(pe.price)); itemsadded = true; //Check ComboBpx Item For Product //if Product Name Is selected //Add Product To Table //UpdateGrandTotal() //else //Check the Product Exist in Database //if Exist //Add Product Row To Table //UpdateGrandTotal() //else //Wrong Product Code Nad Notify User }
private void btnadd_Click(object sender, EventArgs e) { ProductEntity p = new ProductEntity(); //Check All Fields Are not empty if(!FieldsEmpty()) { MessageBox.Show("Fill All the Fields Properly."); return; } //Check Product does Not Exists Already if(p.ProductExistsByCode(txtcode.Text)) { MessageBox.Show("Product Code Already In Use."); return; } //Check Price does not contain alphabetical characters if (!checkOnlyNumbers(txtprice.Text)) { MessageBox.Show("Amount Field Can Only Contain Only"); return; } //Get Date string date=DateTime.Today.ToString(); //Add Product //Check For Any Insertion Errors //If Error //Notify User //Else //Clear All Fields ProductEntity product = new ProductEntity(txtcode.Text,txtname.Text,txtprice.Text,txtspecfication.Text); if (product.CreateProduct()) { MessageBox.Show("New Product Created."); ClearFields(); } else { MessageBox.Show("Problem In Inserting Product."); } }
private void LoadProducts() { ProductEntity product=new ProductEntity(); dr = product.FindAllProducts(); dt.Load(dr); DataRow datadr = dt.NewRow(); datadr["productname"] = "Select Product"; dt.Rows.InsertAt(datadr,0); combo_product.DisplayMember = "productname"; combo_product.ValueMember = "id"; combo_product.DataSource = dt; dr.Close(); }