/* * CREATED: C. Stanhope MAR 13 2018 * MODIFIED: C. Stanhope MAR 21 2018 * - added ResetSearchFilters() method call * - added validation * MODIFIED: C. Stanhope APR 5 2018 * - new word trims whitespace * MODIFIED: C. Stanhope APR 6 2018 * - added try-catch for database access * * AddAccessCodeButton_Click() * Triggered when "AddAccessCodeButton" is clicked and is used to add an access code to the database. * * PARAMETERS: * object sender - references the object that raised the Page_Load event * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty) * * RETURNS: * void * * ODEV METHOD CALLS: * ValidateAccessCodeWord() * AccessCodeController.AddAccessCode() * MessageUserControl.ShowSuccessMessage() * ClearPage() * ResetSearchFilters() * MessageUserControl.ShowInfoMessage() * MessageUserControl.ShowErrorMessage() */ protected void AddAccessCodeButton_Click(object sender, EventArgs e) { string newWord = AddAccessCodeTB.Text.ToLower().Trim(); if (newWord.Length > 0) { if (ValidateAccessCodeWord(newWord)) { AccessCodeDTO newAccessCode = new AccessCodeDTO(); newAccessCode.accesscodeword = newWord; newAccessCode.activeyn = true; // defaults to active try { accessCodeController.AddAccessCode(newAccessCode); MessageUserControl.ShowSuccessMessage("New access code '" + newWord + "' added"); ClearPage(); ResetSearchFilters(); } catch (Exception ex) { MessageUserControl.ShowErrorMessage("Adding access code failed. Please try again. If error persists, please contact your administrator.", ex); } } else // invalid code word { MessageUserControl.ShowInfoMessage("The access code '" + newWord + "' is not valid. Please ensure the access code is between 6 and 8 letters (no numbers or symbols are permitted)."); } } else // no word entered { MessageUserControl.ShowInfoMessage("No access code word was entered. Please enter a word between 6 and 8 letters (no numbers or symbols are permitted)."); } }
/* * CREATED: C. Stanhope MAR 13 2018 * * AddAccessCodeButton_Click() * Triggered when "AddAccessCodeButton" is clicked and is used to add an access code to the database. * * PARAMETERS: * object sender - references the object that raised the Page_Load event * EventArgs e - optional class that may be passed that inherits from EventArgs (usually empty) * * RETURNS: * void * * METHOD CALLS: * AccessCodeController.AddAccessCode() * MessageUserControl.ShowSuccessMessage() */ protected void AddAccessCodeButton_Click(object sender, EventArgs e) { AccessCodeDTO newAccessCode = new AccessCodeDTO(); newAccessCode.accesscodeword = AddAccessCodeTB.Text; newAccessCode.activeyn = true; // defaults to active accessCodeController.AddAccessCode(newAccessCode); MessageUserControl.ShowSuccessMessage("New access code added!"); ClearPage(); }