private void AddButton_Click(object sender, EventArgs e) { // Adds a new message to the database try { var newMsgNo = GetMsgNoFromForm(); CheckForDuplicateMsgNo(newMsgNo); var nextMsgNo = GetNextMsgFromForm(); var messageText = GetMsgTextFromForm(); if (NagFeedback.ValidationErrorCount != 0) { return; } var table = new DonationNagsTable(); table.AddRow(newMsgNo, null, messageText, nextMsgNo); DonationNags.UpdateTable(table); var feedback = $"MsgNo {newMsgNo} was successfully added"; NagFeedback.AddInfo(feedback); CommonCacheInvalidation.ScheduleInvalidateNagsAll(); NagEditMode.Value = Empty; BuildHtmlTable(); } catch (Exception ex) { NagFeedback.AddError("The operation failed due to an unexpected error."); NagFeedback.HandleException(ex); } }
private void CancelButton_Click(object sender, EventArgs e) { // Handles cancellations -- not much to do try { NagFeedback.AddInfo("The operation was cancelled"); NagEditMode.Value = Empty; BuildHtmlTable(); } catch (Exception ex) { NagFeedback.AddError("The operation failed due to an unexpected error."); NagFeedback.HandleException(ex); } }
private void DeleteButton_Click(object sender, EventArgs e) { try { Debug.Assert(sender is Control, "sender is Control"); var msgNo = GetMsgNoFromId(((Control)sender).ID); DonationNags.DeleteByMessageNumber(msgNo); var feedback = $"MsgNo {msgNo} was successfully deleted"; NagFeedback.AddInfo(feedback); CommonCacheInvalidation.ScheduleInvalidateNagsAll(); NagEditMode.Value = Empty; BuildHtmlTable(); } catch (Exception ex) { NagFeedback.AddError("The operation failed due to an unexpected error."); NagFeedback.HandleException(ex); } }
private void UpdateButton_Click(object sender, EventArgs e) { try { // Get the existing record Debug.Assert(sender is Control, "sender is Control"); var msgNo = GetMsgNoFromId(((Control)sender).ID); var table = DonationNags.GetDataByMessageNumber(msgNo); var newMsgNo = GetMsgNoFromForm(); if (newMsgNo != msgNo) { CheckForDuplicateMsgNo(newMsgNo); } var nextMsgNo = GetNextMsgFromForm(); var messageText = GetMsgTextFromForm(); if (NagFeedback.ValidationErrorCount != 0) { return; } table[0].MessageNumber = newMsgNo; table[0].NextMessageNumber = nextMsgNo; table[0].MessageText = messageText; DonationNags.UpdateTable(table); var feedback = newMsgNo != msgNo ? $"MsgNo {msgNo} was successfully updated and its MsgNo changed to {newMsgNo}" : $"MsgNo {msgNo} was successfully updated"; NagFeedback.AddInfo(feedback); CommonCacheInvalidation.ScheduleInvalidateNagsAll(); NagEditMode.Value = Empty; BuildHtmlTable(); } catch (Exception ex) { NagFeedback.AddError("The operation failed due to an unexpected error."); NagFeedback.HandleException(ex); } }