/// Author: Joe Audette
/// Created: 2007-06-16
/// Last Modified: 2007-06-26
///
/// The use and distribution terms for this software are covered by the
/// Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
/// which can be found in the file CPL.TXT at the root of this distribution.
/// By using this software in any fashion, you are agreeing to be bound by
/// the terms of this license.
///
/// You must not remove this notice, or any other, from this software.
using System;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using mojoPortal.Business;
using mojoPortal.Web;
using Resources;
using SiteOffice.Business.ExternalMail;
namespace SiteOffice.ExternalMail{
public partial class PopAccountEditor : UserControl
{
protected SiteUser siteUser;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Load += new EventHandler(Page_Load);
this.btnSaveEmailAccount.Click += new EventHandler(btnSaveEmailAccount_Click);
this.ddEmailAccounts.SelectedIndexChanged += new EventHandler(ddEmailAccounts_SelectedIndexChanged);
}
protected void Page_Load(object sender, EventArgs e)
{
LoadSettings();
PopulateLabels();
if (!Page.IsPostBack)
{
BindEmailAccountList();
}
}
private void BindEmailAccountList()
{
if (siteUser != null)
{
// TODO: remove try catch, after implemented in all dbs
try
{
using (IDataReader reader = UserEmailAccount.GetUserEmailAccountByUser(siteUser.UserGuid))
{
ddEmailAccounts.DataSource = reader;
ddEmailAccounts.DataBind();
}
}
catch { }
}
ListItem listItem = new ListItem();
listItem.Value = String.Empty;
listItem.Text = ExternalMailResources.NewEmailAccountLabel;
ddEmailAccounts.Items.Insert(0, listItem);
}
void ddEmailAccounts_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList dd = (DropDownList)sender;
if (dd.SelectedValue.Length == 36)
{
BindEmailAccount(new Guid(dd.SelectedValue));
}
else
{
BindEmailAccount(Guid.Empty);
}
}
private void BindEmailAccount(Guid accountId)
{
if (accountId == Guid.Empty)
{
txtAccountTitle.Text = String.Empty;
txtUserPassword.Text = String.Empty;
txtPopPort.Text = "110";
txtPopServer.Text = String.Empty;
txtSMTPPort.Text = "25";
txtSMTPServer.Text = String.Empty;
txtPopUserName.Text = String.Empty;
txtPopUserEmail.Text = String.Empty;
chkUseSSL.Checked = true;
}
else
{
// TODO: remove try catch, after implemented in all dbs
try
{
UserEmailAccount userEmailAccount = new UserEmailAccount(accountId);
if (userEmailAccount != null)
{
txtAccountTitle.Text = userEmailAccount.AccountName;
txtUserPassword.Text = userEmailAccount.Password;
txtPopPort.Text = userEmailAccount.Pop3Port.ToString();
txtPopServer.Text = userEmailAccount.Pop3Server;
txtSMTPPort.Text = userEmailAccount.SmtpPort.ToString();
txtSMTPServer.Text = userEmailAccount.SmtpServer;
txtPopUserName.Text = userEmailAccount.UserName;
txtPopUserEmail.Text = userEmailAccount.Email;
chkUseSSL.Checked = userEmailAccount.UseSsl;
}
}
catch { }
}
}
void btnSaveEmailAccount_Click(object sender, EventArgs e)
{
if (siteUser == null)
{
siteUser = SiteUtils.GetCurrentSiteUser();
}
if (siteUser != null)
{
// TODO: remove try catch, after implemented in all dbs
try
{
UserEmailAccount userEmailAccount;
if (ddEmailAccounts.SelectedValue.Length == 36)
{
userEmailAccount = new UserEmailAccount(new Guid(ddEmailAccounts.SelectedValue));
}
else
{
userEmailAccount = new UserEmailAccount();
userEmailAccount.UserGuid = siteUser.UserGuid;
}
userEmailAccount.AccountName = txtAccountTitle.Text;
userEmailAccount.Password = txtUserPassword.Text;
userEmailAccount.Pop3Port = int.Parse(txtPopPort.Text);
userEmailAccount.Pop3Server = txtPopServer.Text;
userEmailAccount.SmtpPort = int.Parse(txtSMTPPort.Text);
userEmailAccount.SmtpServer = txtSMTPServer.Text;
userEmailAccount.UserName = txtPopUserName.Text;
userEmailAccount.Email = txtPopUserEmail.Text;
userEmailAccount.UseSsl = chkUseSSL.Checked;
userEmailAccount.Save();
}
catch { }
}
BindEmailAccountList();
}
private void PopulateLabels()
{
btnSaveEmailAccount.Text = ExternalMailResources.ExtrnalMailSaveButton;
}
private void LoadSettings()
{
siteUser = SiteUtils.GetCurrentSiteUser();
}
}
}
|