示例#1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["CloseDialogCodes"] != null) // 如果有LoanID
        {
            CloseDialogCodes = Request.QueryString["CloseDialogCodes"].ToString();
        }

        if (Request.QueryString["TemplEmailId"] != null) // 如果有LoanID
        {
            string sTemplEmailId = Request.QueryString["TemplEmailId"];

            if (PageCommon.IsID(sTemplEmailId) == false)
            {
                PageCommon.WriteJsEnd(this, sErrorMsg, CloseDialogCodes);
            }

            TemplEmailId = Convert.ToInt32(sTemplEmailId);
        }

        Token = Request.QueryString["token"] != null ? Request.QueryString["token"].ToString() : "";
        isListTemplEmailAttach = Request.QueryString["isListTemplEmailAttach"] != null?Convert.ToBoolean(Request.QueryString["isListTemplEmailAttach"]) : false;

        if (!IsPostBack)
        {
            if (isListTemplEmailAttach)
            {
                LPWeb.BLL.Template_Email_Attachments bllTempEmailAttach = new Template_Email_Attachments();

                var           ds = bllTempEmailAttach.GetListWithOutFileImage(" Enabled =1 AND TemplEmailId = " + TemplEmailId);
                StringBuilder sb = new StringBuilder();

                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        sb.Append("<option value='s" + dr["TemplAttachId"].ToString() + "' >" + dr["Name"].ToString() + "." + dr["FileType"].ToString() + "</option>");
                    }
                }

                Default_lbxAttachments = sb.ToString();
            }
        }



        ///判定是不是 在执行发送
        if (Request.Form["hidIsSend"] != null)
        {
            sLocalTime = Request.Form["hfLocalTime"].ToString().Trim();
            //Attachment

            #region Attachments
            if (Request.Files.Count > 0)
            {
                foreach (var key in Request.Files.AllKeys)
                {
                    var file = Request.Files[key];

                    if (file.ContentLength > 0 && !string.IsNullOrEmpty(file.FileName))
                    {
                        if (file.ContentLength > 1024 * 1024 * 20)
                        {
                            ErrorMsg("The file you tried to upload has exceeded the allowed limit, 20MB.");
                            Response.End();
                        }

                        byte[] bytes = new byte[file.InputStream.Length];
                        file.InputStream.Read(bytes, 0, bytes.Length);
                        file.InputStream.Seek(0, SeekOrigin.Begin);

                        FileInfo info = new FileInfo(file.FileName);

                        Attachments.Add(info.Name, bytes);
                    }
                }
            }
            #endregion

            if (Attachments.Count == 0)
            {
                ErrorMsg("Attachments / Note is empty.");
                Response.End();
            }


            #region Save file

            try
            {
                LPWeb.BLL.Email_AttachmentsTemp bllEmailAttachTemp = new Email_AttachmentsTemp();
                foreach (var item in Attachments)
                {
                    LPWeb.Model.Email_AttachmentsTemp model = new LPWeb.Model.Email_AttachmentsTemp();

                    model.Token     = Token;
                    model.Name      = item.Key.ToString().Substring(0, item.Key.ToString().LastIndexOf('.'));
                    model.FileType  = item.Key.ToString().Substring(item.Key.ToString().LastIndexOf('.') + 1);
                    model.FileImage = item.Value;

                    bllEmailAttachTemp.Add(model);
                }

                ErrorMsg(true, "");
            }
            catch (Exception ex)
            {
                ErrorMsg(ex.Message.Replace("\"", "").Replace("\\n", ""));
            }

            #endregion


            Response.End();
        }
    }
示例#2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["TemplEmailId"] == null)
        {
            return;
        }
        TemplEmailId = Convert.ToInt32(Request.QueryString["TemplEmailId"]);

        op       = Request.QueryString["op"] == null ? "list" : Request.QueryString["op"].ToString();
        AttachId = Request.QueryString["AttachId"] == null ? "" : Request.QueryString["AttachId"].ToString();
        Token    = Request.QueryString["Token"] == null ? "" : Request.QueryString["Token"].ToString();



        LPWeb.BLL.Email_AttachmentsTemp bllEmailAttachTemp = new Email_AttachmentsTemp();
        switch (op)
        {
        case "list":

            rpAttachmentsList.DataSource = bllEmailAttachTemp.GetList(TemplEmailId, Token);       //blltmpemalAttach.GetListWithOutFileImage("TemplEmailId = " + TemplEmailId + " and Enabled =1");
            rpAttachmentsList.DataBind();

            break;

        case "Remove":
            if (string.IsNullOrEmpty(AttachId))
            {
                Response.Clear();
                Response.Write("1");
                Response.End();
                return;
            }

            var idlist = AttachId.Split(',').ToList();
            foreach (string idstr in idlist)
            {
                try
                {
                    if (idstr.ToLower().StartsWith("s"))
                    {
                        int id = Convert.ToInt32(idstr.Replace("s", ""));
                        bllEmailAttachTemp.Add(
                            new LPWeb.Model.Email_AttachmentsTemp {
                            Token = Token, TemplAttachId = id
                        }
                            );
                    }
                    if (idstr.ToLower().StartsWith("c"))
                    {
                        int id = Convert.ToInt32(idstr.Replace("c", ""));
                        bllEmailAttachTemp.Delete(id);
                    }
                }
                catch { }
            }



            Response.Clear();
            Response.Write("1");
            Response.End();
            break;
        }
    }