166 lines
5.1 KiB
C#
166 lines
5.1 KiB
C#
|
using FineUIPro.Web.common;
|
|||
|
using Model;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Web;
|
|||
|
using System.Web.UI;
|
|||
|
using System.Web.UI.WebControls;
|
|||
|
|
|||
|
namespace FineUIPro.Web.Email_Send
|
|||
|
{
|
|||
|
public partial class Email_Send_Edit : PageBase
|
|||
|
{
|
|||
|
#region 加载
|
|||
|
protected void Page_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (!IsPostBack)
|
|||
|
{
|
|||
|
//加载菜单树
|
|||
|
this.InitMenuTree();
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 初始化系统菜单树
|
|||
|
/// <summary>
|
|||
|
/// 加载菜单树:动态加载
|
|||
|
/// </summary>
|
|||
|
private void InitMenuTree()
|
|||
|
{
|
|||
|
this.tvMenu.Nodes.Clear();
|
|||
|
TreeNode rootNode = new TreeNode();//定义根节点
|
|||
|
rootNode.Text = "所有人";
|
|||
|
rootNode.NodeID = "0";
|
|||
|
rootNode.Expanded = true;
|
|||
|
rootNode.EnableCheckEvent = true;
|
|||
|
rootNode.EnableCheckBox = true;
|
|||
|
this.tvMenu.Nodes.Add(rootNode);
|
|||
|
this.GetNodes(rootNode.Nodes, rootNode.NodeID);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 遍历节点方法(系统功能)
|
|||
|
/// <summary>
|
|||
|
/// 遍历节点方法
|
|||
|
/// </summary>
|
|||
|
/// <param name="nodes">节点集合</param>
|
|||
|
/// <param name="parentId">父节点</param>
|
|||
|
private void GetNodes(TreeNodeCollection nodes, string parentId)
|
|||
|
{
|
|||
|
List<Model.Sys_User> sysUserMenu = null;
|
|||
|
|
|||
|
sysUserMenu = (from x in BLL.Funs.DB.Sys_User where x.Account != "gly" orderby x.UserName select x).ToList();
|
|||
|
|
|||
|
foreach (var q in sysUserMenu)
|
|||
|
{
|
|||
|
TreeNode newNode = new TreeNode();
|
|||
|
newNode.Text = (q.UserName + "(" + q.Email + ")").ToString();
|
|||
|
newNode.NodeID = q.UserId;
|
|||
|
newNode.CommandName = q.Email;
|
|||
|
//newNode.NavigateUrl = q.Email;
|
|||
|
newNode.EnableCheckEvent = true;
|
|||
|
newNode.EnableCheckBox = true;
|
|||
|
newNode.Selectable = true;
|
|||
|
nodes.Add(newNode);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region 全选、全不选
|
|||
|
/// <summary>
|
|||
|
/// 全选、全不选
|
|||
|
/// </summary>
|
|||
|
/// <param name="sender"></param>
|
|||
|
/// <param name="e"></param>
|
|||
|
protected void tvMenu_NodeCheck(object sender, FineUIPro.TreeCheckEventArgs e)
|
|||
|
{
|
|||
|
if (e.Checked)
|
|||
|
{
|
|||
|
this.tvMenu.CheckAllNodes(e.Node.Nodes);
|
|||
|
SetCheckParentNode(e.Node);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
this.tvMenu.UncheckAllNodes(e.Node.Nodes);
|
|||
|
}
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 选中父节点
|
|||
|
/// </summary>
|
|||
|
/// <param name="node"></param>
|
|||
|
private void SetCheckParentNode(TreeNode node)
|
|||
|
{
|
|||
|
if (node.ParentNode != null && node.ParentNode.NodeID != "0")
|
|||
|
{
|
|||
|
node.ParentNode.Checked = true;
|
|||
|
if (node.ParentNode.ParentNode.NodeID != "0")
|
|||
|
{
|
|||
|
SetCheckParentNode(node.ParentNode);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
protected void btnSave_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
//string mailFrom = MailHelper.MailServerFrom;
|
|||
|
var pop = MailHelper.getEmailPop();
|
|||
|
if (pop == null)
|
|||
|
{
|
|||
|
ShowNotify("未配置邮件服务器", MessageBoxIcon.Error);
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
string mailFrom = pop.EmailYx;
|
|||
|
|
|||
|
string[] mailTo = null;
|
|||
|
string mailSubject = string.Empty;
|
|||
|
string mailBody = string.Empty;
|
|||
|
string mailAttch = string.Empty;
|
|||
|
string mailCode = string.Empty;
|
|||
|
string mailPriority = string.Empty;
|
|||
|
string[] mailCC = null;
|
|||
|
string resultMessage = "";
|
|||
|
List<string> namelist = new List<string>();
|
|||
|
|
|||
|
foreach (TreeNode tn in this.tvMenu.GetCheckedNodes())
|
|||
|
{
|
|||
|
if (tn.NodeID != "0")
|
|||
|
{
|
|||
|
namelist.Add(tn.CommandName);
|
|||
|
}
|
|||
|
}
|
|||
|
if (namelist.Count == 0)
|
|||
|
{
|
|||
|
ShowNotify("请至少选择一项用户进行发送!", MessageBoxIcon.Warning);
|
|||
|
return;
|
|||
|
}
|
|||
|
mailTo = namelist.ToList().ToArray();
|
|||
|
mailSubject = this.txtSendTitle.Text.Trim();
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
string templetpath = txtSendContent.Text.Trim();
|
|||
|
mailBody = templetpath;
|
|||
|
|
|||
|
bool f = MailHelper.SendNetMail(pop, mailFrom, mailTo, mailSubject, mailBody, mailAttch, mailCode, mailPriority, mailCC, out resultMessage);
|
|||
|
if (f == true)
|
|||
|
{
|
|||
|
ShowNotify("发送成功!", MessageBoxIcon.Success);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
ShowNotify(resultMessage, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
ShowNotify(ex.Message, MessageBoxIcon.Success);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
}
|