Пример #1
0
    protected void btn1_Click(object sender, EventArgs e)
    {
        Hashtable ht = new Hashtable();

        string[] arr1 = new string[] { "title", "remark" };
        for (int i = 0; i < arr1.Length; i++)
        {
            ht.Add(arr1[i], Util.GetControlValue(this.to1.Parent.FindControl(arr1[i])));
        }
        ht.Add("to1", this.to1.Text);
        ht.Add("time0", DateTime.Now.ToString());
        ht.Add("from1", User.Identity.Name);

        if (ht["title"].ToString().Trim() == "" || ht["remark"].ToString().Trim() == "")
        {
            Util.alert(this.Page, "错误提示,请输入标题或正文");
        }
        else
        {
            ZX_EmailBu email2 = new ZX_EmailBu();
            bool       result = email2.AddMailTwo(ht);

            if (result)
            {
                Response.Redirect("ReceiveMail.aspx", true);
            }
            else
            {
                Util.alert(this.Page, "错误提示:邮件发送失败!");
            }
        }
    }
Пример #2
0
    protected void btn1_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            //如果是转发邮件,需要判断邮件的数量(2008年6月1日)
            //编码:金寿吉 时间:2008年6月1日
            /*----判断上传附件的数量---------*/
            int      MaxFile  = 0;
            int      begin    = 0;
            String[] TranFile = new String[5];
            if (Request.QueryString["inboxid"] != null)
            {
                foreach (RepeaterItem item in this.tranReapeater.Items)
                {
                    CheckBox chk1 = item.FindControl("chkfile") as CheckBox;
                    if (chk1.Checked)
                    {
                        Label lab2 = item.FindControl("labTransFile") as Label;
                        TranFile[begin] = lab2.Text;        //保存转发的附件
                        MaxFile++;
                        begin++;
                    }
                }

                //累计用户上传的附件
                if (MaxFile <= 5)
                {
                    for (int i = 1; i <= 5; i++)
                    {
                        FileUpload file = this.FileUpload1.Parent.FindControl("FileUpload" + i) as FileUpload;
                        if (file != null && file.PostedFile != null && file.PostedFile.FileName != String.Empty)
                        {
                            MaxFile++;
                        }
                    }
                }
            }


            //处理附件上传
            if (MaxFile <= 5)
            {
                Hashtable ht = new Hashtable();
                ht["to1"]    = this.to1.Text;
                ht["title"]  = this.title.Text.Trim();
                ht["remark"] = this.remark.Text;
                ht["time0"]  = DateTime.Now.ToString();
                ht["from1"]  = User.Identity.Name;

                //处理转发的附件
                int hbegin = 1;
                for (int i = 0; i < TranFile.Length; i++)
                {
                    if (TranFile[i] != null && TranFile[i] != String.Empty)
                    {
                        ht["file" + hbegin] = TranFile[i];
                        hbegin++;
                    }
                }


                //处理上传的附件
                if (this.FileUpload1.PostedFile != null)
                {
                    string ExcelName1 = FileUpload1.PostedFile.FileName;
                    string file1      = User.Identity.Name + "_" + Util.GetRandomString(9) + "_" + Path.GetFileName(ExcelName1);
                    if (Path.GetFileName(ExcelName1) != "")
                    {
                        ht["file" + hbegin] = file1;
                        FileUpload1.PostedFile.SaveAs(Server.MapPath(Application["root"] + "/Common/MailFiles/" + file1));
                        hbegin++;
                    }
                }
                if (this.FileUpload2.PostedFile != null)
                {
                    string ExcelName2 = FileUpload2.PostedFile.FileName;
                    string file2      = User.Identity.Name + "_" + Util.GetRandomString(9) + "_" + Path.GetFileName(ExcelName2);
                    if (Path.GetFileName(ExcelName2) != "")
                    {
                        ht["file" + hbegin] = file2;
                        FileUpload2.PostedFile.SaveAs(Server.MapPath(Application["root"] + "/Common/MailFiles/" + file2));
                        hbegin++;
                    }
                }
                if (this.FileUpload3.PostedFile != null)
                {
                    string ExcelName3 = FileUpload3.PostedFile.FileName;
                    string file3      = User.Identity.Name + "_" + Util.GetRandomString(9) + "_" + Path.GetFileName(ExcelName3);
                    if (Path.GetFileName(ExcelName3) != "")
                    {
                        ht["file" + hbegin] = file3;
                        FileUpload3.PostedFile.SaveAs(Server.MapPath(Application["root"] + "/Common/MailFiles/" + file3));
                        hbegin++;
                    }
                }
                if (this.FileUpload4.PostedFile != null)
                {
                    string ExcelName4 = FileUpload4.PostedFile.FileName;
                    string file4      = User.Identity.Name + "_" + Util.GetRandomString(9) + "_" + Path.GetFileName(ExcelName4);
                    if (Path.GetFileName(ExcelName4) != "")
                    {
                        ht["file" + hbegin] = file4;
                        FileUpload4.PostedFile.SaveAs(Server.MapPath(Application["root"] + "/Common/MailFiles/" + file4));
                        hbegin++;
                    }
                }
                if (this.FileUpload5.PostedFile != null)
                {
                    string ExcelName5 = FileUpload5.PostedFile.FileName;
                    string file5      = User.Identity.Name + "_" + Util.GetRandomString(9) + "_" + Path.GetFileName(ExcelName5);
                    if (Path.GetFileName(ExcelName5) != "")
                    {
                        ht["file" + hbegin] = file5;
                        FileUpload5.PostedFile.SaveAs(Server.MapPath(Application["root"] + "/Common/MailFiles/" + file5));
                        hbegin++;
                    }
                }

                //发送邮件操作
                ZX_EmailBu email2 = new ZX_EmailBu();
                bool       result = false;
                result = email2.AddMailTwo(ht);

                if (result)
                {
                    PubComm.ShowInfo("操作提示:邮件发送成功!", Application["root"] + "/Info/SendMail.aspx");
                }
                else
                {
                    Util.alert(this.Page, "错误提示:邮件发送失败!");
                }
            }
            else
            {
                Util.alert(this.Page, "错误提示:上传的附件数量不等超过5个!");
            }
        }
    }