private void btnSave_Click(object sender, EventArgs e) { bool Result = DBLayer.CHK_Orakh(txtName.Text); if (CheckField()) { try { if (mode == 1) { if (Result) { MessageBox.Show(txtName.Text + " Already Exist!", "Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { usp_SEL_tblOrakhTableAdapter.Insert1(txtName.Text); btnCancel.Enabled = false; btnNew.Enabled = true; btnSave.Enabled = false; btnDelete.Enabled = true; btnEdit.Enabled = true; txtName.ReadOnly = true; usp_SEL_tblOrakhTableAdapter.Fill(comDataSet.usp_SEL_tblOrakh); mode = 0; DGOrakh.Enabled = true; MessageBox.Show("Saved Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else if (mode == 0) { if (Old == txtName.Text) { usp_SEL_tblOrakhTableAdapter.Update1(txtName.Text, Old); btnCancel.Enabled = false; btnNew.Enabled = true; btnSave.Enabled = false; btnDelete.Enabled = true; btnEdit.Enabled = true; txtName.ReadOnly = true; usp_SEL_tblOrakhTableAdapter.Fill(comDataSet.usp_SEL_tblOrakh); mode = 0; DGOrakh.Enabled = true; MessageBox.Show("Modified Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (Result) { MessageBox.Show(txtName.Text + " Already Exist!", "Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { usp_SEL_tblOrakhTableAdapter.Update1(txtName.Text, Old); btnCancel.Enabled = false; btnNew.Enabled = true; btnSave.Enabled = false; btnDelete.Enabled = true; btnEdit.Enabled = true; txtName.ReadOnly = true; usp_SEL_tblOrakhTableAdapter.Fill(comDataSet.usp_SEL_tblOrakh); mode = 0; DGOrakh.Enabled = true; MessageBox.Show("Modified Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } AcceptButton = btnNew; } }