Basf_TCC11/HJGL/FineUIPro.Web/Email_Send/Email_Send_Edit.aspx.cs

166 lines
5.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}
}
}