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 string GetMsgTextFromForm() { var tbMessageText = Master.FindMainContentControl(TextBoxMessageTextId) as TextBox; return(NagFeedback.ValidateRequired(tbMessageText, "Message text", out _)); }
private int GetMsgNoFromForm() { var tbMessageNumber = Master.FindMainContentControl(TextBoxMessageNumberId) as TextBox; return(NagFeedback.ValidateInt(tbMessageNumber, out _, "MsgNo", 1)); }
private int?GetNextMsgFromForm() { var tbNextMessageNumber = Master.FindMainContentControl(TextBoxNextMessageNumberId) as TextBox; var nextMsgNo = NagFeedback.ValidateIntOptional( tbNextMessageNumber, out _, "NextMsg", 0, 1); return(nextMsgNo == 0 ? (int?)null : nextMsgNo); }
private void CheckForDuplicateMsgNo(int msgNo) { if (!DonationNags.MessageNumberExists(msgNo)) { return; } var tbMessageNumber = Master.FindMainContentControl(TextBoxMessageNumberId) as TextBox; NagFeedback.PostValidationError( tbMessageNumber, "MsgNo {0} already exists", msgNo); }
private void InsertButton_Click(object sender, EventArgs e) { // This method initiates an insert operation. // The AddButton_Click method actually does the add. try { NagEditMode.Value = "Insert"; BuildHtmlTable(); } catch (Exception ex) { NagFeedback.AddError("The operation failed due to an unexpected error."); NagFeedback.HandleException(ex); } }
private void EditButton_Click(object sender, EventArgs e) { try { Debug.Assert(sender is Control, "sender is Control"); var msgNo = GetMsgNoFromId(((Control)sender).ID); NagEditMode.Value = "Edit" + msgNo.ToString(CultureInfo.InvariantCulture); 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); } }