Ejemplo n.º 1
0
        private void grvData_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            string colName = grvData.Columns[e.ColumnIndex].Name;

            if (colName == "Edit")
            {
                frmBrand Brand = new frmBrand(this);
                Brand.lblId.Text        = grvData[1, e.RowIndex].Value.ToString();
                Brand.txtBrandName.Text = grvData[2, e.RowIndex].Value.ToString();
                Brand.ShowDialog();
            }
            else if (colName == "Delete")
            {
                var confirmResult = MessageBox.Show("Are you sure to delete this item ??",
                                                    "Confirm Delete!!",
                                                    MessageBoxButtons.YesNo);
                if (confirmResult == DialogResult.Yes)
                {
                    // If 'Yes', do something here.
                    using (SqlConnection sqlConnection = new SqlConnection(DBConnection.MyConnection()))
                    {
                        sqlConnection.Open();
                        SqlCommand sqlCommand = new SqlCommand("delete from tblBrand where id like '" + grvData[1, e.RowIndex].Value.ToString() + "' ", sqlConnection);
                        sqlCommand.ExecuteNonQuery();
                        sqlConnection.Close();
                        MessageBox.Show("Record deleted Succesfully", _msgHeader, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LoadData();
                    }
                }
                else
                {
                    // If 'No', do something here.
                }
            }
        }
Ejemplo n.º 2
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     try
     {
         frmBrand frmBrand = new frmBrand(this);
         frmBrand.ShowDialog();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, _msgHeader, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }