private void btnSave_Click(object sender, EventArgs e) { bool Result = DBLayer.CHK_Nukh(txtName.Text); if (CheckField()) { try { if (mode == 1) { if (Result) { MessageBox.Show(txtName.Text + " Already Exist!", "Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { usp_SEL_tblNukhTableAdapter.Insert1(txtName.Text); btnCancel.Enabled = false; btnNew.Enabled = true; btnSave.Enabled = false; btnDelete.Enabled = true; btnEdit.Enabled = true; txtName.ReadOnly = true; usp_SEL_tblNukhTableAdapter.Fill(comDataSet.usp_SEL_tblNukh); mode = 0; DGNukh.Enabled = true; btnClose.Show(); MessageBox.Show("Saved Succesfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else if (mode == 0) { if (Old == txtName.Text) { usp_SEL_tblNukhTableAdapter.Update1(txtName.Text, Old); btnCancel.Enabled = false; btnNew.Enabled = true; btnSave.Enabled = false; btnDelete.Enabled = true; btnEdit.Enabled = true; txtName.ReadOnly = true; usp_SEL_tblNukhTableAdapter.Fill(comDataSet.usp_SEL_tblNukh); mode = 0; btnClose.Show(); DGNukh.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_tblNukhTableAdapter.Update1(txtName.Text, Old); btnCancel.Enabled = false; btnNew.Enabled = true; btnSave.Enabled = false; btnDelete.Enabled = true; btnEdit.Enabled = true; txtName.ReadOnly = true; usp_SEL_tblNukhTableAdapter.Fill(comDataSet.usp_SEL_tblNukh); mode = 0; btnClose.Show(); DGNukh.Enabled = true; MessageBox.Show("Modified Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } AcceptButton = btnNew; } }
private void btnSave_Click(object sender, EventArgs e) { bool Result = DBLayer.CHK_Nukh(txtAid.Text); if (CheckField()) { try { if (mode == 1) { if (Result) { MessageBox.Show(txtAid.Text + " Already Exist!", "Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { tblAidsTableAdapter.NewAid(txtAid.Text); btnCancel.Enabled = false; btnNew.Enabled = true; btnSave.Enabled = false; btnDelete.Enabled = true; btnEdit.Enabled = true; txtAid.ReadOnly = true; tblAidsTableAdapter.Fill(dataset2.tblAids); mode = 0; dgvAid.Enabled = true; btnClose.Show(); MessageBox.Show("Saved Succesfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else if (mode == 0) { if (Old == txtAid.Text) { tblAidsTableAdapter.UpdateAid(txtAid.Text, ID); btnCancel.Enabled = false; btnNew.Enabled = true; btnSave.Enabled = false; btnDelete.Enabled = true; btnEdit.Enabled = true; txtAid.ReadOnly = true; tblAidsTableAdapter.Fill(dataset2.tblAids); mode = 0; btnClose.Show(); dgvAid.Enabled = true; MessageBox.Show("Modified Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (Result) { MessageBox.Show(txtAid.Text + " Already Exist!", "Duplicate", MessageBoxButtons.OK, MessageBoxIcon.Hand); } else { tblAidsTableAdapter.UpdateAid(txtAid.Text, ID); btnCancel.Enabled = false; btnNew.Enabled = true; btnSave.Enabled = false; btnDelete.Enabled = true; btnEdit.Enabled = true; txtAid.ReadOnly = true; tblAidsTableAdapter.Fill(dataset2.tblAids); mode = 0; btnClose.Show(); dgvAid.Enabled = true; MessageBox.Show("Modified Successfully!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } AcceptButton = btnNew; } }