📄 compose.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Configuration;
using System.Data.SqlClient;
using UDS.Components;
namespace UDS.SubModule.UnitiveDocument.Mail
{
/// <summary>
/// Compose 的摘要说明。
/// </summary>
public class Compose : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label lblSendTo;
protected System.Web.UI.WebControls.Label lblSubject;
protected System.Web.UI.WebControls.TextBox txtSubject;
protected System.Web.UI.WebControls.Label lblBody;
protected System.Web.UI.WebControls.TextBox txtBody;
protected System.Web.UI.WebControls.Label lblImportance;
protected System.Web.UI.WebControls.DropDownList listImportance;
protected System.Web.UI.WebControls.Button btnSendMail;
protected System.Web.UI.WebControls.Label lblAttachFile;
protected System.Web.UI.WebControls.Label lblCcTo;
protected System.Web.UI.WebControls.Label lblBccTo;
protected System.Web.UI.HtmlControls.HtmlInputFile filecontrol1;
protected static string Username;
public string ClassID;
public static string MailID;
public string Action;
public string SendTo="",CcTo="",BccTo="",SendToRealName="",CcToRealName="",BccToRealName="";
protected System.Web.UI.WebControls.CheckBoxList cblistAttribute;
protected System.Web.UI.WebControls.Button btnUpload;
protected System.Web.UI.WebControls.ListBox listUp;
protected System.Web.UI.WebControls.Button btnRemove;
protected System.Web.UI.HtmlControls.HtmlInputFile filecontrol2;
protected System.Web.UI.HtmlControls.HtmlInputFile File1;
protected System.Web.UI.HtmlControls.HtmlInputFile File2;
protected System.Web.UI.WebControls.CheckBox cbRemind;
protected ArrayList upattlist = new ArrayList();
private void Page_Load(object sender, System.EventArgs e)
{
ClassID = (Request.QueryString["ClassID"]!=null)?Request.QueryString["ClassID"].ToString():"";
MailID = (Request.QueryString["MailID"]!=null)?Request.QueryString["MailID"].ToString():"";
HttpCookie UserCookie = Request.Cookies["Username"];
Username = UserCookie.Value.ToString();
if(!IsPostBack)
{
Session["upattlist"]=upattlist;
//upattlist.Clear();
// Action=1 回复 Action=2 转发 Action=3 指定收件人的寄信
if (Request.QueryString["Action"]!=null)
{
MailID = (Request.QueryString["MailID"]==null)?"":Request.QueryString["MailID"].ToString();
if(Request.QueryString["Action"]=="1")
ReplySet(); // 进行回复邮件设置
if(Request.QueryString["Action"]=="2")
ForwardSet(); // 进行转发邮件设置
if(Request.QueryString["Action"]=="3")
ReceiverSet(); // 进行发信人设置
}
PopulateListView();
}
}
#region 回复邮件设置
/// <summary>
/// 回复邮件设置
/// </summary>
private void ReplySet()
{
// 读取原邮件内容
MailClass mailclass = new MailClass();
SqlDataReader dataReader = null;
try
{
dataReader = mailclass.GetMailCompleteInfoDbreader(MailID);
}
catch
{
Server.Transfer("../../Error.aspx");
}
if(dataReader.Read())
{
string tmpStr = "<br/>"+dataReader[7].ToString();
tmpStr = tmpStr.Replace("<br/>","\r\n>");
this.txtSubject.Text = "Re:"+dataReader[4].ToString();
SendToRealName = dataReader[1].ToString()+",";
SendTo = dataReader[10].ToString()+",";
this.txtBody.Text = SendToRealName+"你好!\n\n\n\n\n\n\n";
this.txtBody.Text += "======="+dataReader[3].ToString()+"你在来信中写道:"+"=======\n\n";
this.txtBody.Text += tmpStr;
}
dataReader.Close();
mailclass = null;
}
#endregion
#region 转发邮件设置
/// <summary>
/// 转发邮件设置
/// </summary>
private void ForwardSet()
{
// 读取原邮件内容
MailClass mailclass = new MailClass();
SqlDataReader dataReader = null;
try
{
dataReader = mailclass.GetMailCompleteInfoDbreader(MailID);
}
catch
{
Server.Transfer("../../Error.aspx");
}
if(dataReader.Read())
{
string tmpStr = "<br/>"+dataReader[7].ToString();
tmpStr = tmpStr.Replace("<br/>","\r\n>");
this.txtSubject.Text = "Fw::"+dataReader[4].ToString();
this.txtBody.Text = ",你好!\n\n\n\n\n\n\n";
this.txtBody.Text += "=======下面是转发邮件=======\n";
this.txtBody.Text += "原邮件发件人姓名:"+dataReader[1].ToString()+"\n";
this.txtBody.Text += "原邮件发件人代号:"+dataReader[10].ToString()+"\n";
this.txtBody.Text += tmpStr;
}
dataReader.Close();
try
{
dataReader = mailclass.GetMailAttInfoDbreader(MailID);
}
catch
{
Server.Transfer("../../Error.aspx");
}
while(dataReader.Read())
{
UDS.Components.MailAttachFile att = new MailAttachFile();
att.FileAttribute = 0;
att.FileSize = Int32.Parse(dataReader[1].ToString());
att.FileName = dataReader[0].ToString();
att.FileAuthor = Username;
att.FileCatlog = "邮件";
att.FileVisualPath = dataReader[2].ToString();
upattlist.Add(att);
}
BindAttList();
dataReader.Close();
mailclass = null;
}
#endregion
#region 发信人设置
/// <summary>
/// 发信人设置
/// </summary>
private void ReceiverSet()
{
SendToRealName = (Request.QueryString["Name"]==null)?"":Request.QueryString["Name"].ToString()+",";
SendTo = (Request.QueryString["Username"]==null)?"":Request.QueryString["Username"].ToString()+",";
}
#endregion
public string GetClassName()
{
if(ClassID=="0")
return "请选择项目";
else
return UDS.Components .ProjectClass .GetProjectName(Int32.Parse(ClassID));
}
#region 初始化下拉列表框
/// <summary>
/// 对下拉列表进行初始化
/// </summary>
private void PopulateListView()
{
Class cls = new Class();
listImportance.Items.Clear();
listImportance.Items.Add(new ListItem("一般","1"));
listImportance.Items.Add(new ListItem("重要","2"));
listImportance.Items.Add(new ListItem("特别重要","3"));
cblistAttribute.Items.Add(new ListItem("普通邮件","1"));
cblistAttribute.Items.Add(new ListItem("邮件归档","2"));
//cblistAttribute.Items.Add(new ListItem("结案报告","3"));
cblistAttribute.Items[0].Selected=true;
cls = null;
}
#endregion
#region 处理邮件附件上传操作,传回附件数组
/// <summary>
/// 处理上传操作,附件以链接形式存放
/// </summary>
/// <param name="MailReceiverStr"> 用户登陆名字符串,用逗号隔开 </param>
private ArrayList AttUpload(string MailReceiverStr)
{
HtmlForm FrmCompose = (HtmlForm)this.Page.FindControl("Compose");
string[] RecvIdAr = System.Text.RegularExpressions.Regex.Split(MailReceiverStr ,",");
ArrayList listattfile = new ArrayList();
// 存放附件至发件人目录中,随机生成目录名
Random TempNameInt = new Random();
string NewMailDirName = TempNameInt.Next(100000000).ToString();
string FileName = "";
try
{
if(!Directory.Exists(Server.MapPath(".")+"\\AttachFiles\\"+Username))
Directory.CreateDirectory(Server.MapPath(".")+"\\AttachFiles\\"+Username);
Directory.CreateDirectory(Server.MapPath(".")+"\\AttachFiles\\"+Username+"\\"+NewMailDirName);
for (int i=0;i<FrmCompose.Controls.Count;i++)
{
if(FrmCompose.Controls [i].GetType().ToString()=="System.Web.UI.HtmlControls.HtmlInputFile")
{
HtmlInputFile hif = ((HtmlInputFile)(FrmCompose.Controls[i]));
if(hif.PostedFile.FileName.Trim()!="")
{
FileName = System.IO .Path.GetFileName(hif.PostedFile.FileName);
UDS.Components.MailAttachFile att = new MailAttachFile();
// 初始化
att.FileAttribute = 0;
att.FileSize = hif.PostedFile.ContentLength;
att.FileName = FileName;
att.FileAuthor = Username;
att.FileCatlog = "邮件";
att.FileVisualPath = "\\AttachFiles\\"+Username+"\\"+NewMailDirName+"\\"+FileName;
hif.PostedFile.SaveAs(Server.MapPath(".")+"\\AttachFiles\\"+Username+"\\"+NewMailDirName+"\\"+FileName);
listattfile.Add(att);
}
hif=null;
}
}
}
catch(Exception ioex)
{
UDS.Components.Error.Log(ioex.ToString());
Server.Transfer("../../Error.aspx");
}
return listattfile;
}
#endregion
#region 处理除收件人外的表单传递参数 传回MailMainBody类
/// <summary>
/// 发送不包括附件的邮件正文
/// </summary>
private MailMainBody ProcessFormPost()
{
if(this.cblistAttribute.SelectedIndex.ToString()=="-1")
{
Response.Write("<script language=javascript>alert('请选择邮件类型!');history.go(-1);</script>");
Response.End();
}
if(cblistAttribute.Items[1].Selected)
{
if(Request.Form["hdnProjectID"].ToString()=="0")
{
Response.Write("<script language=javascript>alert('请选择归档项目!');history.go(-1);</script>");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -