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_SendTemplate_Edit : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindEmailParamsDropDownList(); string emailId = Request.Params["id"]; if (!string.IsNullOrEmpty(emailId)) { Model.Email_SendTemplate sends = new Model.Email_SendTemplate(); sends = BLL.Email_Send.Email_SendTemplateService.GetEmail_SendTemplate(emailId); this.rblAutoPostBack.SelectedValue = sends.EmailUserYN.ToString(); this.ddlEmailParamsID.SelectedValue = sends.EmailParamsID.Trim(); this.txtTemplateName.Text = sends.EmailTitle.ToString(); this.txtTemplateCondition.Text = sends.EailTiaoJian.ToString(); this.txtContent.Text = sends.EmailContext.ToString(); } if (rblAutoPostBack.SelectedValue == "0") { ddlSendUserName.Hidden = true; ddlccUserName.Hidden = true; ddlSendRole.Hidden = true; ddlccRole.Hidden = true; } else if (rblAutoPostBack.SelectedValue == "1")//选择人 { //发送人 var people1 = BLL.Email_Send.Email_ToPeopleService.GetSenderTopeopleList(emailId); if (people1.Count == 0 || people1 == null) { } else { this.ddlSendUserName.Values = people1.Select(o => o.EmuserID).ToArray(); this.ddlSendUserName.Texts = people1.Select(o => o.EmuserName).ToArray(); } //抄送人 var people2 = BLL.Email_Send.Email_ToPeopleService.GetCCTopeopleList(emailId); if (people2.Count == 0 || people2 == null) { } else { this.ddlccUserName.Values = people2.Select(o => o.EmuserID).ToArray(); this.ddlccUserName.Texts = people2.Select(o => o.EmuserName).ToArray(); } ddlSendUserName.Hidden = false; ddlccUserName.Hidden = false; ddlSendRole.Hidden = true; ddlccRole.Hidden = true; } else if (rblAutoPostBack.SelectedValue == "2")//选择角色 { //发送人 var people1 = BLL.Email_Send.Email_ToPeopleService.GetSenderTopeopleList(emailId); if (people1.Count == 0 || people1 == null) { } else { this.ddlSendRole.Values = people1.Select(o => o.EmuserID).ToArray(); this.ddlSendRole.Texts = people1.Select(o => o.EmuserName).ToArray(); } //抄送人 var people2 = BLL.Email_Send.Email_ToPeopleService.GetCCTopeopleList(emailId); if (people2.Count == 0 || people2 == null) { } else { this.ddlccRole.Values = people2.Select(o => o.EmuserID).ToArray(); this.ddlccRole.Texts = people2.Select(o => o.EmuserName).ToArray(); } ddlSendUserName.Hidden = true; ddlccUserName.Hidden = true; ddlSendRole.Hidden = false; ddlccRole.Hidden = false; } } } #region 下拉加载 private void BindEmailParamsDropDownList() { List email_Params = new List(); email_Params = BLL.Email_Send.Email_ParamsService.GetEmail_ParamsList(); ddlEmailParamsID.DataTextField = "MailClassName"; ddlEmailParamsID.DataValueField = "MailClassID"; ddlEmailParamsID.DataSource = email_Params; ddlEmailParamsID.DataBind(); ddlEmailParamsID.Items.Insert(0, new ListItem("", "")); } #endregion protected void rblAutoPostBack_SelectedIndexChanged(object sender, EventArgs e) { //ShowNotify("列表三选中项的值:" + rblAutoPostBack.SelectedValue); if (rblAutoPostBack.SelectedValue == "0") { ddlccUserName.Value = string.Empty; ddlccUserName.Hidden = true; ddlSendUserName.Value = string.Empty; ddlSendUserName.Hidden = true; ddlccRole.Value = string.Empty; ddlccRole.Hidden = true; ddlSendRole.Value = string.Empty; ddlSendRole.Hidden = true; } else if (rblAutoPostBack.SelectedValue == "1") { ddlSendUserName.Hidden = false; ddlccUserName.Hidden = false; ddlSendRole.Hidden = true; ddlccRole.Hidden = true; } else if (rblAutoPostBack.SelectedValue == "2") { ddlSendUserName.Hidden = true; ddlccUserName.Hidden = true; ddlSendRole.Hidden = false; ddlccRole.Hidden = false; } } protected void btnSave_Click(object sender, EventArgs e) { string emailId = Request.Params["id"]; if (rblAutoPostBack.SelectedValue == "1") { //发送人id 集合 List SenduserList = new List(); if (!string.IsNullOrEmpty(this.ddlSendUserName.Value)) { string[] toUserId = this.ddlSendUserName.Values; List usList = BLL.Sys_UserService.GetUserList(); foreach (var item in toUserId) { string itemstr = item.Trim(); Model.Sys_User syuser = new Model.Sys_User(); syuser = usList.Where(o => o.UserId == itemstr).FirstOrDefault(); SenduserList.Add(syuser); } } //抄送人集合 List CCuserList = new List(); if (!string.IsNullOrEmpty(this.ddlccUserName.Value)) { string[] toUserId = this.ddlccUserName.Values; List usList = BLL.Sys_UserService.GetUserList(); foreach (var item in toUserId) { string itemstr = item.Trim(); Model.Sys_User syuser = new Model.Sys_User(); syuser = usList.Where(o => o.UserId == itemstr).FirstOrDefault(); CCuserList.Add(syuser); } } List tplist = null; if (string.IsNullOrEmpty(emailId)) { Model.Email_SendTemplate temp = new Model.Email_SendTemplate(); temp.EmailParamsID = ddlEmailParamsID.SelectedValue.ToString(); temp.EmailId = Guid.NewGuid().ToString(); temp.EmailTitle = txtTemplateName.Text.Trim(); temp.EailTiaoJian = txtTemplateCondition.Text.Trim(); temp.EmailContext = this.txtContent.Text; temp.EmailUserYN = Convert.ToInt32(rblAutoPostBack.SelectedValue); List stlist = new List(); stlist = BLL.Email_Send.Email_SendTemplateService.GetEmailNotifierList(temp.EmailParamsID); if (stlist == null || stlist.Count == 0) { tplist = new List(); //发送人 if (SenduserList != null || SenduserList.Count != 0) { foreach (var item in SenduserList) { Model.Email_ToPeople tep = new Model.Email_ToPeople(); tep.EmID = Guid.NewGuid().ToString(); tep.EmtempID = temp.EmailId; tep.EmuserID = item.UserId.ToString(); tep.EmuserName = item.UserName.ToString(); tep.EMPeopleType = BLL.Const.SenderType; tep.EmuaerEmailAddress = item.Email; tplist.Add(tep); } } //抄送人保存 if (CCuserList != null || CCuserList.Count != 0) { foreach (var item in CCuserList) { Model.Email_ToPeople tep = new Model.Email_ToPeople(); tep.EmID = Guid.NewGuid().ToString(); tep.EmtempID = temp.EmailId; tep.EmuserID = item.UserId.ToString(); tep.EmuserName = item.UserName.ToString(); tep.EMPeopleType = BLL.Const.CCType; tep.EmuaerEmailAddress = item.Email; tplist.Add(tep); } } temp.CreateName = this.CurrUser.UserName; temp.CreateTime = DateTime.Now; BLL.Email_Send.Email_SendTemplateService.Add(temp, tplist); //BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Add SendEmailTemplate!"); } else { ShowNotify("不能重复创建!", MessageBoxIcon.Error); return; } } else { Model.Email_SendTemplate temp = BLL.Email_Send.Email_SendTemplateService.GetEmail_SendTemplate(emailId); temp.EmailId = emailId; temp.EmailParamsID = ddlEmailParamsID.SelectedValue.ToString(); temp.EailTiaoJian = txtTemplateCondition.Text.Trim(); temp.EmailTitle = this.txtTemplateName.Text.Trim(); temp.EmailContext = this.txtContent.Text; temp.EmailUserYN = Convert.ToInt32(rblAutoPostBack.SelectedValue); temp.UpdateName = this.CurrUser.UserName; temp.UpdateTime = DateTime.Now; tplist = new List(); if (SenduserList != null || SenduserList.Count != 0) { foreach (var item in SenduserList) { Model.Email_ToPeople tep = new Model.Email_ToPeople(); tep.EmID = Guid.NewGuid().ToString(); tep.EmtempID = emailId; tep.EmuserID = item.UserId.ToString(); tep.EMPeopleType = BLL.Const.SenderType; tep.EmuserName = item.UserName; tep.EmuaerEmailAddress = item.Email; tplist.Add(tep); } } //抄送人保存 if (CCuserList.Count != 0 || CCuserList != null) { foreach (var item in CCuserList) { Model.Email_ToPeople tep = new Model.Email_ToPeople(); tep.EmID = Guid.NewGuid().ToString(); tep.EmtempID = temp.EmailId; tep.EmuserID = item.UserId; tep.EmuserName = item.UserName; tep.EMPeopleType = BLL.Const.CCType; tep.EmuaerEmailAddress = item.Email; tplist.Add(tep); } } BLL.Email_Send.Email_SendTemplateService.Update(temp, tplist); // BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Update SendEmailTemplate!"); } } else if (rblAutoPostBack.SelectedValue == "2") { //发送人id 集合 List SenduserList = new List(); if (!string.IsNullOrEmpty(this.ddlSendRole.Value)) { string[] toRoleId = this.ddlSendRole.Values; List usRoleList = BLL.Sys_RoleService.GetRoleList(); foreach (var item in toRoleId) { string itemstr = item.Trim(); Model.Sys_Role syuser = new Model.Sys_Role(); syuser = usRoleList.Where(o => o.RoleId == itemstr).FirstOrDefault(); SenduserList.Add(syuser); } } //抄送人集合 List CCuserList = new List(); if (!string.IsNullOrEmpty(this.ddlccRole.Value)) { string[] toUserId = this.ddlccRole.Values; List usList = BLL.Sys_RoleService.GetRoleList(); foreach (var item in toUserId) { string itemstr = item.Trim(); Model.Sys_Role syuser = new Model.Sys_Role(); syuser = usList.Where(o => o.RoleId == itemstr).FirstOrDefault(); CCuserList.Add(syuser); } } List tplist = null; if (string.IsNullOrEmpty(emailId)) { Model.Email_SendTemplate temp = new Model.Email_SendTemplate(); temp.EmailParamsID = ddlEmailParamsID.SelectedValue.ToString(); temp.EmailId = Guid.NewGuid().ToString(); temp.EmailTitle = txtTemplateName.Text.Trim(); temp.EailTiaoJian = txtTemplateCondition.Text.Trim(); temp.EmailContext = this.txtContent.Text; temp.EmailUserYN = Convert.ToInt32(rblAutoPostBack.SelectedValue); List stlist = new List(); stlist = BLL.Email_Send.Email_SendTemplateService.GetEmailNotifierList(temp.EmailParamsID); if (stlist == null || stlist.Count == 0) { tplist = new List(); //发送人 if (SenduserList != null || SenduserList.Count != 0) { foreach (var item in SenduserList) { Model.Email_ToPeople tep = new Model.Email_ToPeople(); tep.EmID = Guid.NewGuid().ToString(); tep.EmtempID = temp.EmailId; tep.EmuserID = item.RoleId.ToString(); tep.EmuserName = item.RoleName.ToString(); tep.EMPeopleType = BLL.Const.SenderType; tep.EmuaerEmailAddress = string.Empty; tplist.Add(tep); } } //抄送人保存 if (CCuserList != null || CCuserList.Count != 0) { foreach (var item in CCuserList) { Model.Email_ToPeople tep = new Model.Email_ToPeople(); tep.EmID = Guid.NewGuid().ToString(); tep.EmtempID = temp.EmailId; tep.EmuserID = item.RoleId.ToString(); tep.EmuserName = item.RoleName.ToString(); tep.EMPeopleType = BLL.Const.CCType; tep.EmuaerEmailAddress = string.Empty; tplist.Add(tep); } } temp.CreateName = this.CurrUser.UserName; temp.CreateTime = DateTime.Now; BLL.Email_Send.Email_SendTemplateService.Add(temp, tplist); // BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Add SendEmailTemplate!"); } else { ShowNotify("不能重复创建", MessageBoxIcon.Error); return; } } else { Model.Email_SendTemplate temp = BLL.Email_Send.Email_SendTemplateService.GetEmail_SendTemplate(emailId); temp.EmailId = emailId; temp.EmailParamsID = ddlEmailParamsID.SelectedValue.ToString(); temp.EailTiaoJian = txtTemplateCondition.Text.Trim(); temp.EmailTitle = this.txtTemplateName.Text.Trim(); temp.EmailContext = this.txtContent.Text; temp.EmailUserYN = Convert.ToInt32(rblAutoPostBack.SelectedValue); temp.UpdateName = this.CurrUser.UserName; temp.UpdateTime = DateTime.Now; tplist = new List(); if (SenduserList != null || SenduserList.Count != 0) { foreach (var item in SenduserList) { Model.Email_ToPeople tep = new Model.Email_ToPeople(); tep.EmID = Guid.NewGuid().ToString(); tep.EmtempID = emailId; tep.EmuserID = item.RoleId.ToString(); tep.EMPeopleType = BLL.Const.SenderType; tep.EmuserName = item.RoleName.ToString(); tep.EmuaerEmailAddress = string.Empty; tplist.Add(tep); } } //抄送人保存 if (CCuserList.Count != 0 || CCuserList != null) { foreach (var item in CCuserList) { Model.Email_ToPeople tep = new Model.Email_ToPeople(); tep.EmID = Guid.NewGuid().ToString(); tep.EmtempID = temp.EmailId; tep.EmuserID = item.RoleId.ToString(); tep.EmuserName = item.RoleName.ToString(); tep.EMPeopleType = BLL.Const.CCType; tep.EmuaerEmailAddress = string.Empty; tplist.Add(tep); } } BLL.Email_Send.Email_SendTemplateService.Update(temp, tplist); //BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Update SendEmailTemplate!"); } } else { List tplist = null; if (string.IsNullOrEmpty(emailId)) { Model.Email_SendTemplate temp = BLL.Email_Send.Email_SendTemplateService.GetEmail_SendTemplate(emailId); if (temp == null) { temp = new Model.Email_SendTemplate(); temp.EmailId = Guid.NewGuid().ToString(); } else { temp.EmailId = emailId; } temp.EmailParamsID = ddlEmailParamsID.SelectedValue.ToString(); temp.EailTiaoJian = txtTemplateCondition.Text.Trim(); temp.EmailTitle = this.txtTemplateName.Text.Trim(); temp.EmailContext = this.txtContent.Text; temp.EmailUserYN = Convert.ToInt32(rblAutoPostBack.SelectedValue); temp.UpdateName = this.CurrUser.UserName; temp.UpdateTime = DateTime.Now; BLL.Email_Send.Email_SendTemplateService.Add(temp, tplist); //BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Add SendEmailTemplate!"); } else { Model.Email_SendTemplate temp = BLL.Email_Send.Email_SendTemplateService.GetEmail_SendTemplate(emailId); if (temp == null) { temp = new Model.Email_SendTemplate(); temp.EmailId = Guid.NewGuid().ToString(); } else { temp.EmailId = emailId; } temp.EmailParamsID = ddlEmailParamsID.SelectedValue.ToString(); temp.EailTiaoJian = txtTemplateCondition.Text.Trim(); temp.EmailTitle = this.txtTemplateName.Text.Trim(); temp.EmailContext = this.txtContent.Text; temp.EmailUserYN = Convert.ToInt32(rblAutoPostBack.SelectedValue); temp.UpdateName = this.CurrUser.UserName; temp.UpdateTime = DateTime.Now; BLL.Email_Send.Email_SendTemplateService.Update(temp, tplist); //BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Update SendEmailTemplate!"); } } ShowNotify("保存成功!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } }