예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
 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);
     }
 }
예제 #4
0
        private void BuildHtmlTable()
        {
            var nagsTable = DonationNags.GetAllData();

            // possible modes: normal (Empty), "Edit", "Insert"
            var editMode          = GetMsgTypeFromId(NagEditMode.Value);
            var editMessageNumber = GetMsgNoFromId(NagEditMode.Value);

            var htmlTable = InitializeNagsTable();

            foreach (var nagsRow in nagsTable)
            {
                BuildOneNagsDataRow(editMode, editMessageNumber, htmlTable, nagsRow);
            }

            if (editMode != "Edit")
            {
                BuildInsertRow(editMode, htmlTable);
            }
        }
예제 #5
0
        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);
            }
        }