protected void Page_Load(object sender, EventArgs e)
 {
     this.ltlUserName.Text = CookieUtilities.GetCookieValue("username");
     using (var context = new MemberContext())
     {
         VelocityEngine ve = new VelocityEngine();
         ve.SetProperty(RuntimeConstants.RESOURCE_LOADER, "file");
         ve.SetProperty(RuntimeConstants.FILE_RESOURCE_LOADER_PATH, Server.MapPath("~/html_template"));
         ve.Init();
         VelocityContext vContext = new VelocityContext();
         var             entities = context.RoleFunctions.Where(a => a.RoleId == RoleId && a.ParentID.EndsWith("_0")).Select(a => a).ToList();
         List <Item>     items    = new List <Item>();
         foreach (var entity in entities)
         {
             var item = new Item();
             item.Name      = entity.Name;
             item.IconClass = entity.IconClass;
             item.Url       = entity.Url;
             item.Items     = context.RoleFunctions.Where(a => a.RoleId == RoleId && a.ParentID.StartsWith(entity.ParentID.Substring(0, 2))).Where(a => a.Name != entity.Name).Select(a => new Item
             {
                 Name = a.Name,
                 Url  = a.Url
             }).ToList <Item>();
             items.Add(item);
         }
         vContext.Put("items", items);
         Template     template = ve.GetTemplate("menu.html");
         StringWriter writer   = new StringWriter();
         template.Merge(vContext, writer);
         MenuString = writer.GetStringBuilder().ToString();
     }
 }
        protected void btnSendEmail_Click(object sender, EventArgs e)
        {
            string      receiver    = this.txtReceiver.Text.Trim();
            string      subject     = this.txtSubject.Text.Trim();
            MailMessage mailMessage = new MailMessage();

            string content = this.hideMailContent.Value;

            mailMessage.From       = "*****@*****.**";
            mailMessage.Subject    = subject;
            mailMessage.IsBodyHtml = true;
            mailMessage.HtmlBody   = content;
            string[] users = receiver.Split(',');
            foreach (string user in users)
            {
                int    startIndex = user.IndexOf('<') + 1;
                int    length     = user.Length;
                string email      = user.Substring(startIndex, length - startIndex - 1);
                mailMessage.To.Add(email);
            }
            //创建附件
            if (Session["tempTable"] != null)
            {
                DataTable table = (DataTable)Session["tempTable"];
                foreach (DataRow row in table.Rows)
                {
                    mailMessage.Attachments.Add(new Attachment(row["FilePath"].ToString()));
                }
            }
            SmtpClient client = AsposeUtilities.GetSmtpClient(this.Request.ApplicationPath);

            try
            {
                client.Send(mailMessage);
                using (var context = new EmailContext())
                {
                    var entity = new SendLog
                    {
                        Sender   = CookieUtilities.GetCookieValue("username"),
                        Receiver = receiver,
                        SendTime = DateTime.Now,
                        SendType = "Email"
                    };
                    context.SendLogs.Add(entity);
                    context.SaveChanges();
                }
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('邮件发送成功')", true);
            }
            catch (Exception ex)
            {
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('邮件发送失败!" + ex.Message + "')", true);
            }
        }
        protected void btnSendWeiXin_Click(object sender, EventArgs e)
        {
            string content = this.txtWeiXinContent.Text;

            try
            {
                int count = 0;
                foreach (RepeaterItem item in this.Repeater3.Items)
                {
                    HtmlInputCheckBox checkBox = (HtmlInputCheckBox)item.FindControl("inlineCheckbox1");
                    if (checkBox.Checked)
                    {
                        count++;
                    }
                }
                if (count == 0)
                {
                    ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('请选择接收用户')", true);
                    return;
                }
                StringBuilder receiverBuilder = new StringBuilder();
                foreach (RepeaterItem item in this.Repeater3.Items)
                {
                    HtmlInputCheckBox checkBox = (HtmlInputCheckBox)item.FindControl("inlineCheckbox1");
                }
                string receiver = receiverBuilder.ToString().TrimEnd(',');
                using (var context = new EmailContext())
                {
                    var entity = new SendLog
                    {
                        Sender   = CookieUtilities.GetCookieValue("username"),
                        Receiver = receiver,
                        SendTime = DateTime.Now,
                        SendType = "WeiXin"
                    };
                    context.SendLogs.Add(entity);
                    context.SaveChanges();
                }
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('微信发送成功')", true);
            }
            catch (Exception)
            {
                ScriptManager.RegisterStartupScript(this.UpdatePanel1, GetType(), "a", "alert('微信发送可能,可能部分用户我发收到微信内容!')", true);
            }
        }