private void GvProdList_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == colBtnEdit.Index) { DataGridViewRow row = this.gvProdList.Rows[e.RowIndex]; FrmProduct frmProduct = new FrmProduct(); frmProduct.isNew = false; frmProduct.dsCategoriesCurrencies = (DataSetProducts)this.dsCategoriesCurrencies.Copy(); frmProduct.ProductCode = row.Cells[colProductCode.Index].Value.ToString(); this.Hide(); frmProduct.ShowDialog(); if (frmProduct.dataSaved) { GetProductList(); } frmProduct.Dispose(); this.Show(); } else if (e.ColumnIndex == colBtnDelete.Index) { DialogResult result = MessageBox.Show("Are you sure to delete?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result != DialogResult.Yes) { return; } DataGridViewRow row = this.gvProdList.Rows[e.RowIndex]; String productcode = row.Cells[colProductCode.Index].Value.ToString(); String cmdQuery = @"DELETE FROM PRODUCTS WHERE PRODUCT_CODE=:PRODUCT_CODE"; CdbcConnection con = UtilCommon.getConnection(); CdbcCommand cmd = new CdbcCommand(cmdQuery, con); CdbcParameter para = new CdbcParameter(":PRODUCT_CODE", CdbcOracleDbType.Varchar2); para.Value = productcode; cmd.Parameters.Add(para); try { cmd.ExecuteNonQuery(); GetProductList(); } catch (Exception Ex) { MessageBox.Show(Ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) ; } } }
private void BtnNew_Click(object sender, EventArgs e) { this.Hide(); FrmProduct frmProduct = new FrmProduct(); frmProduct.isNew = true; frmProduct.dsCategoriesCurrencies = (DataSetProducts)this.dsCategoriesCurrencies.Copy(); frmProduct.ShowDialog(); if (frmProduct.dataSaved) { GetProductList(); } frmProduct.Dispose(); this.Show(); }