using BLL; using System; using System.Collections.Generic; using System.Linq; namespace FineUIPro.Web.SendEmail { public partial class SendEmailTemplate : PageBase { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string emailId = Request.Params["id"]; if (!string.IsNullOrEmpty(emailId)) { Model.SendEmailTemplate sends = new Model.SendEmailTemplate(); sends = Funs.DB.SendEmailTemplate.Where(p => p.EmailId == emailId).FirstOrDefault(); //this.ddlMailNotifier.SelectedValue = sends.EmailNotifier.Trim(); this.txtTemplateName.Text = sends.EmailName.ToString(); this.txtTemplateCondition.Text = sends.EailTiaoJian.ToString(); this.txtContent.Text = sends.EmailContext.ToString(); //ddlMailNotifier.Enabled = false; if (sends.EmailUserYN.HasValue) { rblAutoPostBack.SelectedValue = sends.EmailUserYN.ToString(); } } if (rblAutoPostBack.SelectedValue == "0") { ddlSendUserName.Hidden = true; ddlccUserName.Hidden = true; } else if (rblAutoPostBack.SelectedValue == "1")//选择人 { //发送人 var people1 = (from x in Funs.DB.Email_ToPeople select x).Where(o => o.EmtempID == emailId && o.EMPeopleType == "0").ToList(); 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 = (from x in Funs.DB.Email_ToPeople select x).Where(o => o.EmtempID == emailId && o.EMPeopleType == "1").ToList(); 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; } } } 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; } else if (rblAutoPostBack.SelectedValue == "1") { ddlSendUserName.Hidden = false; ddlccUserName.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.SendEmailTemplate temp = new Model.SendEmailTemplate(); temp.EmailId = Guid.NewGuid().ToString(); //temp.EmailTitle = txtTemplateName.Text.Trim(); temp.EmailType = 0; temp.EmailName = txtTemplateName.Text.Trim(); temp.EailTiaoJian = txtTemplateCondition.Text.Trim(); temp.EmailContext = this.txtContent.Text; temp.EmailUserYN = Convert.ToInt32(rblAutoPostBack.SelectedValue); List stlist = new List(); 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 = "0"; tep.EmuaerEmailAddress = item.Email.ToString(); 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 = "1"; tep.EmuaerEmailAddress = item.Email.ToString(); tplist.Add(tep); } } temp.CreateName = this.CurrUser.UserName; temp.CreateTime = DateTime.Now; BLL.SendEmail.SendEmailTemplateService.AddSendEmail(temp, tplist); BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Add SendEmailTemplate!"); } else { Model.SendEmailTemplate temp = BLL.SendEmail.SendEmailTemplateService.GetSendEmailTemplate(emailId); temp.EmailId = emailId; temp.EailTiaoJian = txtTemplateCondition.Text.Trim(); temp.EmailName = 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 = "0"; tep.EmuserName = item.UserName.ToString(); tep.EmuaerEmailAddress = item.Email.ToString(); 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.ToString(); tep.EmuserName = item.UserName.ToString(); tep.EMPeopleType = "1"; tep.EmuaerEmailAddress = item.Email.ToString(); tplist.Add(tep); } } BLL.SendEmail.SendEmailTemplateService.UpdateSendEmail(temp, tplist); BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Update SendEmailTemplate!"); } ShowNotify("Save Successfully!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } else { if (string.IsNullOrEmpty(emailId)) { Model.SendEmailTemplate temp = new Model.SendEmailTemplate(); temp.EmailId = emailId; temp.EmailType = 0; temp.EmailName = txtTemplateName.Text.Trim(); temp.EailTiaoJian = txtTemplateCondition.Text.Trim(); temp.EmailContext = this.txtContent.Text; temp.EmailUserYN = Convert.ToInt32(rblAutoPostBack.SelectedValue); temp.CreateName = this.CurrUser.UserName; temp.CreateTime = DateTime.Now; BLL.SendEmail.SendEmailTemplateService.AddSendEmail(temp, null); BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Add SendEmailTemplate!"); #region 不用 //List stlist = new List(); //stlist = BLL.SendEmail.SendEmailTemplateService.GetEmailNotifierList(temp.EmailNotifier); //if (stlist == null || stlist.Count == 0) //{ // temp.CreateName = this.CurrUser.UserName; // temp.CreateTime = DateTime.Now; // BLL.SendEmail.SendEmailTemplateService.AddSendEmail(temp, null); // BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Add SendEmailTemplate!"); //} //else //{ // foreach (var item in stlist) // { // item.EmailType = 1; // Model.SendEmailTemplate sendtp = new Model.SendEmailTemplate(); // sendtp = item; // BLL.SendEmail.SendEmailTemplateService.UpdateSendEmail(sendtp,null); // } // temp.CreateName = this.CurrUser.UserName; // temp.CreateTime = DateTime.Now; // BLL.SendEmail.SendEmailTemplateService.AddSendEmail(temp,null); // BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Add SendEmailTemplate!"); //} #endregion } else { Model.SendEmailTemplate temp = BLL.SendEmail.SendEmailTemplateService.GetSendEmailTemplate(emailId); temp.EmailId = emailId; temp.EmailType = 0; temp.EmailName = txtTemplateName.Text.Trim(); temp.EailTiaoJian = txtTemplateCondition.Text.Trim(); temp.EmailContext = this.txtContent.Text; temp.EmailUserYN = Convert.ToInt32(rblAutoPostBack.SelectedValue); temp.UpdateName = this.CurrUser.UserName; temp.UpdateTime = DateTime.Now; BLL.SendEmail.SendEmailTemplateService.UpdateSendEmail(temp,null); BLL.Sys_LogService.AddLog(this.CurrUser.UserId, "Update SendEmailTemplate!"); } ShowNotify("Save Successfully!", MessageBoxIcon.Success); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } } }