📄 sendnewsletter.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Mail;
using Wrox.WebModules.Accounts.Business;
namespace Wrox.WebModules.MailingLists.Web
{
/// <summary>
/// Summary description for SendNewsletter.
/// </summary>
public class SendNewsletter : Wrox.ThePhile.Web.PhilePage
{
protected System.Web.UI.WebControls.Button Send;
protected System.Web.UI.WebControls.Button Preview;
protected System.Web.UI.WebControls.Table TableMailBody;
protected System.Web.UI.WebControls.Table TableMailSettings;
protected System.Web.UI.WebControls.TextBox Subject;
protected System.Web.UI.WebControls.DropDownList PriorityDropDown;
protected System.Web.UI.WebControls.DropDownList FormatDropDown;
protected System.Web.UI.WebControls.TextBox Body;
protected System.Web.UI.WebControls.DropDownList ListsDropDown;
protected System.Web.UI.WebControls.CheckBox ArchiveNewsletter;
protected System.Web.UI.WebControls.Label MsgPreview;
protected void Page_Load(object sender, EventArgs e)
{
// check if the current user is allowed to send out a newsletter
if (!Context.User.Identity.IsAuthenticated ||
!((SitePrincipal)Context.User).HasPermission((int)MailingListsPermissions.SendNewsletter))
{
// if not, redirect to the Login page
Response.Redirect("/ThePhile/Modules/Users/Login.aspx?ShowError=true", true);
}
// get the ListID param from QueryString
string listID = Request.Params["ListID"];
if (!Page.IsPostBack)
{
// load all the lists name in the DropDown control
ListsDropDown.DataSource = Business.List.GetLists().Tables[0].DefaultView;
// retrieve the subject and signature settings, and set as values for the textboxes
Configuration.ModuleSettings settings = Configuration.ModuleConfig.GetSettings();
Subject.Text = settings.NewsSubject;
Body.Text = settings.Signature;
Page.DataBind();
// select the DropDown element according to the ListID value in the QueryString
if (listID!=null)
{
ListsDropDown.SelectedIndex = ListsDropDown.Items.IndexOf(
ListsDropDown.Items.FindByValue(listID));
}
}
}
protected void Preview_Click(object sender, EventArgs e)
{
string msgText = Body.Text;
int listID = int.Parse(ListsDropDown.SelectedItem.Value);
// replace the list's and settings special tags with their values
msgText = Business.Helper.ProcessListTags(msgText, listID);
msgText = Business.Helper.ProcessSettingsTags(msgText);
// encode the body if the format is not HTML
if (FormatDropDown.SelectedIndex==0)
{
msgText = HttpUtility.HtmlEncode(msgText);
// replace the new lines with <br>, to show the new lines in the Label
msgText = msgText.Replace("\n", "<br>");
// remove carriage returns
msgText = msgText.Replace("\r", "");
}
// show the body in the preview label
MsgPreview.Text = msgText;
MsgPreview.Visible = true;
}
protected void Send_Click(object sender, EventArgs e)
{
Server.ScriptTimeout = 3600;
// send the newsletter and eventually save it to the DB
int numSent;
Business.List list = new Business.List(int.Parse(ListsDropDown.SelectedItem.Value));
list.SendNewsletter(Subject.Text, Body.Text, (FormatDropDown.SelectedIndex==1),
(MailPriority)PriorityDropDown.SelectedIndex, ArchiveNewsletter.Checked, out numSent);
// show the number of sent mails
MsgPreview.Text = string.Format("<b>{0} mail(s) have been sent</b>", numSent);
// if the newsletter has been archived, say this
if (ArchiveNewsletter.Checked)
MsgPreview.Text += "<br><b>The newsletter has been archived</b>";
MsgPreview.Visible = true;
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
base.OnInit(e);
InitializeComponent();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -