private void SaveBtn_Click(object sender, EventArgs e) { try { if (MessageBox.Show("Are you sure you want to save this product", "Save Product", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string brandid = ""; string categoryid = ""; // for brand connect.Open(); command = new MySqlCommand("SELECT id FROM brandtbl where brand LIKE '" + BrandCb.Text + "'", connect); DataReader = command.ExecuteReader(); DataReader.Read(); if (DataReader.HasRows) { brandid = DataReader[0].ToString(); } DataReader.Close(); connect.Close(); //for category connect.Open(); command = new MySqlCommand("SELECT id FROM categorytbl WHERE category LIKE '" + CategoryCb.Text + "'", connect); DataReader = command.ExecuteReader(); DataReader.Read(); if (DataReader.HasRows) { categoryid = DataReader[0].ToString(); } DataReader.Close(); connect.Close(); connect.Open(); command = new MySqlCommand("INSERT INTO producttbl (pcode, barcode, pdescription, generic_name, brandid, categoryid, price, expiry, reorder) VALUES (@pcode, @barcode, @pdescription,@generic_name, @brandid, @categoryid, @price, @expiry, @reorder)", connect); command.Parameters.AddWithValue("@pcode", PCodeTb.Text); command.Parameters.AddWithValue("@barcode", Barcodetb.Text); command.Parameters.AddWithValue("@pdescription", DescriptionTb.Text); command.Parameters.AddWithValue("@generic_name", GenericNamextxt.Text); command.Parameters.AddWithValue("@brandid", brandid); command.Parameters.AddWithValue("@categoryid", categoryid); command.Parameters.AddWithValue("@price", Double.Parse(PriceTb.Text)); command.Parameters.AddWithValue("@expiry", dateTimePicker1.Value.ToString("yyyy-MM-dd")); command.Parameters.AddWithValue("@reorder", int.Parse(ReorderTb.Text)); command.ExecuteNonQuery(); connect.Close(); MessageBox.Show("Product has been succeddfully saved!"); Clear(); formlist.LoadRecords(); } } catch (Exception ex) { connect.Close(); MessageBox.Show(ex.Message); } }
private void ManageProductBtn_Click(object sender, EventArgs e) { ProductListForm plf = new ProductListForm(); plf.TopLevel = false; MainPanel.Controls.Add(plf); plf.BringToFront(); plf.LoadRecords(); plf.Show(); }