protected void btnSend_Click(object sender, EventArgs e)
    {
        // Validate date/time
        if (dtpMailout.SelectedDateTime == DateTimeHelper.ZERO_TIME)
        {
            ShowError(GetString("newsletterissue_send.invaliddatetime"));
            return;
        }

        IssueInfo winner        = (IssueInfo)EditedObject;
        int       parentIssueId = winner.IssueVariantOfIssueID;

        // Get A/B test info
        ABTestInfo abi = ABTestInfoProvider.GetABTestInfoForIssue(parentIssueId);

        if (abi != null)
        {
            IssueInfo issue = IssueInfoProvider.GetIssueInfo(parentIssueId);

            // Check if winner was selected and sent
            if (abi.TestWinnerIssueID != 0)
            {
                if ((issue.IssueStatus == IssueStatusEnum.Finished) || (issue.IssueStatus == IssueStatusEnum.Sending))
                {
                    // Winner was already sent
                    CloseDialogAndRefreshParent();
                    return;
                }
            }

            // Update A/B test info and winner selection task (if exist)
            abi.TestWinnerOption = ABTestWinnerSelectionEnum.Manual;
            NewsletterTasksManager.EnsureWinnerSelectionTask(abi, issue, false, DateTime.Now);

            abi.TestSelectWinnerAfter = 0;
            abi.TestWinnerSelected    = DateTime.Now;
            abi.TestWinnerIssueID     = winner.IssueID;
            ABTestInfoProvider.SetABTestInfo(abi);

            if ((issue != null) && (winner != null))
            {
                // Copy data from winner to parent
                IssueHelper.CopyIssueProperties(winner, issue, "issuesubject;issuetext;issuetemplateid;issueshowinnewsletterarchive;issuesendername;issuesenderemail");
                IssueInfoProvider.SetIssueInfo(issue);

                // Remove previous scheduled task of this issue
                NewsletterTasksManager.DeleteMailoutTask(issue.IssueGUID, issue.IssueSiteID);

                DateTime    mailoutTime = dtpMailout.SelectedDateTime;
                IssueSender issueSender = new IssueSender(IssueInfoProvider.GetIssueInfo(parentIssueId));
                issueSender.Send(mailoutTime);
            }
        }

        // Close dialog and refresh parent page
        CloseDialogAndRefreshParent();
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        // Validate date/time
        if (dtpMailout.SelectedDateTime == DateTimeHelper.ZERO_TIME)
        {
            ShowError(GetString("newsletterissue_send.invaliddatetime"));
            return;
        }

        IssueInfo winner = (IssueInfo)EditedObject;
        int parentIssueId = winner.IssueVariantOfIssueID;

        // Get A/B test info
        ABTestInfo abi = ABTestInfoProvider.GetABTestInfoForIssue(parentIssueId);
        if (abi != null)
        {
            IssueInfo issue = IssueInfoProvider.GetIssueInfo(parentIssueId);

            // Check if winner was selected and sent
            if (abi.TestWinnerIssueID != 0)
            {
                if ((issue.IssueStatus == IssueStatusEnum.Finished) || (issue.IssueStatus == IssueStatusEnum.Sending))
                {
                    // Winner was already sent
                    CloseDialogAndRefreshParent();
                    return;
                }
            }

            // Update A/B test info and winner selection task (if exist)
            abi.TestWinnerOption = ABTestWinnerSelectionEnum.Manual;
            NewsletterTasksManager.EnsureWinnerSelectionTask(abi, issue, false, DateTime.Now);

            abi.TestSelectWinnerAfter = 0;
            abi.TestWinnerSelected = DateTime.Now;
            abi.TestWinnerIssueID = winner.IssueID;
            ABTestInfoProvider.SetABTestInfo(abi);

            if ((issue != null) && (winner != null))
            {
                // Copy data from winner to parent
                IssueHelper.CopyIssueProperties(winner, issue, "issuesubject;issuetext;issuetemplateid;issueshowinnewsletterarchive;issuesendername;issuesenderemail");
                IssueInfoProvider.SetIssueInfo(issue);

                // Remove previous scheduled task of this issue
                NewsletterTasksManager.DeleteMailoutTask(issue.IssueGUID, issue.IssueSiteID);

                DateTime mailoutTime = dtpMailout.SelectedDateTime;
                IssueSender issueSender = new IssueSender(IssueInfoProvider.GetIssueInfo(parentIssueId));
                issueSender.Send(mailoutTime);
            }
        }

        // Close dialog and refresh parent page
        CloseDialogAndRefreshParent();
    }
    /// <summary>
    /// Removes all scheduled tasks for the given issue.
    /// </summary>
    /// <param name="when">DateTime when to send</param>
    private void RemovePreviousTaskAndSendIssue(DateTime when)
    {
        IssueInfo issue = IssueInfoProvider.GetIssueInfo(IssueID);

        if (issue != null)
        {
            // Remove all previously scheduled tasks (if any)
            NewsletterTasksManager.DeleteMailoutTask(issue.IssueGUID, issue.IssueSiteID);
            // Schedule new task for new mailout time
            IssueSender issueSender = new IssueSender(issue);
            issueSender.Send(when);
        }
    }
    /// <summary>
    /// Sends issue to testing email addresses.
    /// </summary>
    /// <returns>True when everything went ok</returns>
    private bool SendDraft()
    {
        string draftEmails = txtSendDraft.Text.Trim();

        if (String.IsNullOrEmpty(draftEmails))
        {
            ErrorMessage = GetString("newsletter.recipientsmissing");
        }
        else if (!ValidationHelper.AreEmails(draftEmails))
        {
            ErrorMessage = GetString("newsletter.wrongemailformat");
        }
        else
        {
            IssueSender sender = new IssueSender(IssueInfoProvider.GetIssueInfo(IssueID));
            sender.SendAsync(draftEmails);
        }

        return(String.IsNullOrEmpty(ErrorMessage));
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        // Check field for emptyness
        if (string.IsNullOrEmpty(txtSendDraft.Text) || (txtSendDraft.Text.Trim().Length == 0))
        {
            ShowError(GetString("newsletter.recipientsmissing"));
        }
        // Check e-mail address validity
        else if (!ValidationHelper.AreEmails(txtSendDraft.Text.Trim()))
        {
            ShowError(GetString("newsletter.wrongemailformat"));
        }
        else
        {
            IssueSender issueSender = new IssueSender((IssueInfo)EditedObject);
            issueSender.SendAsync(txtSendDraft.Text.Trim());

            // Close the dialog
            ScriptHelper.RegisterStartupScript(this, GetType(), "ClosePage", "if (CloseDialog) { CloseDialog(); }", true);
        }
    }
    protected void btnSend_Click(object sender, EventArgs e)
    {
        // Check field for emptyness
        if (string.IsNullOrEmpty(txtSendDraft.Text) || (txtSendDraft.Text.Trim().Length == 0))
        {
            ShowError(GetString("newsletter.recipientsmissing"));
        }
        // Check e-mail address validity
        else if (!ValidationHelper.AreEmails(txtSendDraft.Text.Trim()))
        {
            ShowError(GetString("newsletter.wrongemailformat"));
        }
        else
        {
            IssueSender issueSender = new IssueSender((IssueInfo)EditedObject);
            issueSender.SendAsync(txtSendDraft.Text.Trim());

            // Close the dialog
            ScriptHelper.RegisterStartupScript(this, GetType(), "ClosePage", "if (CloseDialog) { CloseDialog(); }", true);
        }
    }
    /// <summary>
    /// Sends issue to testing email addresses.
    /// </summary>
    /// <returns>True when everything went ok</returns>
    private bool SendDraft()
    {
        string draftEmails = txtSendDraft.Text.Trim();

        if (String.IsNullOrEmpty(draftEmails))
        {
            ErrorMessage = GetString("newsletter.recipientsmissing");
        }
        else if (!ValidationHelper.AreEmails(draftEmails))
        {
            ErrorMessage = GetString("newsletter.wrongemailformat");
        }
        else
        {
            IssueSender sender = new IssueSender(IssueInfoProvider.GetIssueInfo(IssueID));
            sender.SendAsync(draftEmails);
        }

        return String.IsNullOrEmpty(ErrorMessage);
    }
 /// <summary>
 /// Removes all scheduled tasks for the given issue.
 /// </summary>
 /// <param name="when">DateTime when to send</param>
 private void RemovePreviousTaskAndSendIssue(DateTime when)
 {
     IssueInfo issue = IssueInfoProvider.GetIssueInfo(IssueID);
     if (issue != null)
     {
         // Remove all previously scheduled tasks (if any)
         NewsletterTasksManager.DeleteMailoutTask(issue.IssueGUID, issue.IssueSiteID);
         // Schedule new task for new mailout time
         IssueSender issueSender = new IssueSender(issue);
         issueSender.Send(when);
     }
 }