private void btnSave_Click(object sender, EventArgs e) { Boolean status = true; try { accountdaybook adb = new accountdaybook(); AccountDayBookCodeDB adbDB = new AccountDayBookCodeDB(); //adb.BookType = cmbBookType.SelectedItem.ToString().Substring(0, cmbBookType.SelectedItem.ToString().IndexOf("-")); adb.BookType = ((Structures.ComboBoxItem)cmbBookType.SelectedItem).HiddenValue; adb.AccountCode = txtAccCode.Text.Substring(0, txtAccCode.Text.IndexOf('-')); adb.status = getStatusCode(cmbBookStatus.SelectedItem.ToString()); System.Windows.Forms.Button btn = sender as System.Windows.Forms.Button; string btnText = btn.Text; btnText = btnSave.Text; if (btnText.Equals("Update")) { if (adbDB.validateACcountDayBookDetail(adb)) { if (adbDB.updateAccountDayBookDetail(adb)) { MessageBox.Show("Book Type updated"); closeAllPanels(); ListAccountDayBookCode(); } else { status = false; MessageBox.Show("Failed to update Book Type"); } } else { status = false; MessageBox.Show("Validation Failed"); } } else if (btnText.Equals("Save")) { if (adbDB.validateACcountDayBookDetail(adb)) { if (adbDB.insertAccountDayBookDetail(adb)) { MessageBox.Show("Book Type added"); closeAllPanels(); ListAccountDayBookCode(); } else { status = false; MessageBox.Show("Failed to insert Book Type"); //return; } } else { status = false; MessageBox.Show(" Validation failed"); } } } catch (Exception ex) { status = false; MessageBox.Show("Failed Adding / Editing User Data"); } if (status) { setButtonVisibility("btnEditPanel"); //activites are same for cancel, forward,approve, reverse and save } }