private void btnSave_Click(object sender, EventArgs e) { try { if (MessageBox.Show("Are you sure want to save this Product?", "Save Product", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string bid = ""; string cid = ""; cn.Open(); cm = new SQLiteCommand("SELECT id from tblBrand WHERE brand like '" + cboBrand.Text + "'", cn); dr = cm.ExecuteReader(); dr.Read(); if (dr.HasRows) { bid = dr[0].ToString(); } dr.Close(); cn.Close(); cn.Open(); cm = new SQLiteCommand("SELECT id from tblCategory WHERE category like '" + cboCategory.Text + "'", cn); dr = cm.ExecuteReader(); dr.Read(); if (dr.HasRows) { cid = dr[0].ToString(); } dr.Close(); cn.Close(); cn.Open(); cm = new SQLiteCommand("INSERT INTO tblProduct (pcode, barcode, pdesc, bid, cid, price) VALUES(@pcode, @barcode, @pdesc, @bid, @cid, @price)", cn); cm.Parameters.AddWithValue("@pcode", txtPcode.Text); cm.Parameters.AddWithValue("@barcode", txtBarcode.Text); cm.Parameters.AddWithValue("@pdesc", txtPdesc.Text); cm.Parameters.AddWithValue("@bid", bid); cm.Parameters.AddWithValue("@cid", cid); cm.Parameters.AddWithValue("@price", txtPrice.Text); cm.ExecuteNonQuery(); cn.Close(); MessageBox.Show("Product has been successfully saved."); Clear(); flist.LoadRecords(); } } catch (Exception ex) { cn.Close(); MessageBox.Show(ex.Message); } }
private void btnProduct_Click(object sender, System.EventArgs e) { frmProductList frm = new frmProductList(); frm.TopLevel = false; panel4.Controls.Add(frm); frm.BringToFront(); frm.LoadRecords(); frm.Show(); frm.txtSearch.Focus(); }