ReadMail.aspx.cs
上传用户:jdb8708888
上传日期:2013-05-29
资源大小:19971k
文件大小:7k
源码类别:

WEB源码(ASP,PHP,...)

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Web;
  7. using System.Web.SessionState;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12. using UDS.Components;
  13. namespace UDS.SubModule.UnitiveDocument.Mail
  14. {
  15. /// <summary>
  16. /// ReadMail 的摘要说明。
  17. /// </summary>
  18. public class ReadMail : System.Web.UI.Page
  19. {
  20. public static string MailID;
  21. protected HttpCookie UserCookie;
  22. protected static string CurrentPageIndex="",FolderType="";
  23. protected System.Web.UI.WebControls.Label lblSenderName;
  24. protected System.Web.UI.WebControls.Label lblReceiverStr;
  25. protected System.Web.UI.WebControls.Label lblCcToAddr;
  26. protected System.Web.UI.WebControls.Label lblBccToAddr;
  27. protected System.Web.UI.WebControls.Label lblProjectName;
  28. protected System.Web.UI.WebControls.Label lblSubject;
  29. protected System.Web.UI.WebControls.Label lblSendDate;
  30. protected System.Web.UI.WebControls.Label lblBody;
  31. protected System.Web.UI.WebControls.Label lblAttachFile;
  32. protected System.Web.UI.WebControls.Button btnDelete;
  33. private void Page_Load(object sender, System.EventArgs e)
  34. {
  35. UserCookie = Request.Cookies["Username"];
  36. CurrentPageIndex = Request.QueryString["CurrentPageIndex"]!=null?Request.QueryString["CurrentPageIndex"]:"";
  37. string Action = Request.QueryString["Action"]!=null?Request.QueryString["Action"]:"";
  38. string RMailID = Request.QueryString["MailID"]!=null?Request.QueryString["MailID"]:"";
  39. string ClassID =  Request.QueryString["ClassID"]!=null?Request.QueryString["ClassID"]:"";
  40. if (Request.QueryString["FolderType"] !=null)
  41. {
  42. FolderType = Request.QueryString["FolderType"].ToString();
  43. }
  44. if(Action=="3")
  45. {
  46. MailIncoming(RMailID,ClassID);
  47. }
  48. if(!Page.IsPostBack)
  49. {
  50. MailID = Request.QueryString["MailID"];
  51. ShowBodyDetail();
  52. this.btnDelete .Attributes["onclick"]= "javascript:return confirm('您确认要删除此邮件吗?');";
  53. }
  54. }
  55. #region 邮件归档
  56. public void MailIncoming(string MailID,string ClassID)
  57. {
  58. if(MailID!=""&&ClassID!="")
  59. {
  60. try
  61. {
  62. String Username = Request.Cookies["Username"].Value.ToString();
  63. MailClass mailclass = new MailClass();
  64. SqlDataReader dataReader = null; 
  65. ProjectClass pjt = new ProjectClass();
  66. DocBody docbody = new DocBody();
  67. DocumentClass doc = new DocumentClass();
  68. dataReader = mailclass.GetMailCompleteInfoDbreader(MailID);
  69. if(dataReader.Read())
  70. {
  71. int cstRightToApproveDocument = 2;
  72. docbody.DocTitle = dataReader["MailSubject"].ToString();
  73. docbody.DocContent = dataReader["MailBody"].ToString();;
  74. docbody.DocAddedBy = dataReader["MailSender"].ToString();;
  75. docbody.DocClassID = Int32.Parse(ClassID);
  76. docbody.DocAddedDate        = DateTime.Now.ToString();
  77. docbody.DocApprover = (pjt.GetAccessPermission(Int32.Parse(ClassID),Username,cstRightToApproveDocument))?Username:"";
  78. docbody.DocApproveDate = (pjt.GetAccessPermission(Int32.Parse(ClassID),Username,cstRightToApproveDocument))?DateTime.Now.ToString():"";
  79. docbody.DocApproved         = (docbody.DocApprover =="")?0:1;
  80. docbody.DocAttribute        = 0;
  81. docbody.DocType = 0;
  82. }
  83. dataReader.Close();
  84. string DocID = doc.AddDocBody(docbody);
  85. dataReader = mailclass.GetMailAttInfoDbreader(MailID);
  86. while(dataReader.Read())
  87. {
  88. DocAttachFile docatt = new DocAttachFile();
  89. docatt.FileAttribute  = 0;
  90. docatt.FileSize       = Int32.Parse(dataReader["FileSize"].ToString());
  91. docatt.FileName       = dataReader["FileName"].ToString();
  92. docatt.FileAuthor     = Username;
  93. docatt.FileCatlog     = "文档";
  94. docatt.FileVisualPath = "Mail"+dataReader["FileVisualPath"].ToString();
  95. docatt.FileAddedDate  = DateTime.Now.ToString();
  96. docatt.DocID          = Int32.Parse(DocID);
  97. doc.AddAttach(docatt,Int32.Parse(DocID));
  98. }
  99. dataReader = null;
  100. pjt    = null;
  101. docbody    = null;
  102. Response.Write("<script language=javascript>alert('归档成功!');</script>");
  103. }
  104. catch(Exception oe)
  105. {
  106. UDS.Components.Error.Log(oe.ToString());
  107. Server.Transfer("../Error.aspx");
  108. }
  109. }
  110. }
  111. #endregion
  112. #region 使用DataReader显示邮件内容
  113. protected void ShowBodyDetail()
  114. {
  115. MailClass mailclass = new MailClass();
  116. SqlDataReader dataReader = null; 
  117. try
  118. {
  119.  dataReader = mailclass.GetMailCompleteInfoDbreader(MailID);
  120. }
  121. catch
  122. {
  123. Server.Transfer("../../Error.aspx");
  124. }
  125. if(dataReader.Read())
  126. {
  127. this.lblSenderName.Text = dataReader["MailSender"].ToString();
  128. this.lblCcToAddr.Text   = UDS.Components.Staff.GetRealNameStrByUsernameStr(dataReader["MailCcToAddr"].ToString(),0);
  129. // 判断是否显示密抄人信息给本用户
  130. string[] RecvAr = System.Text.RegularExpressions.Regex.Split(dataReader["MailBccToAddr"].ToString() ,",");
  131. for(int i=0;i<RecvAr.Length-1;i++)
  132. { //判断密抄人中是否包含自己
  133. if( RecvAr[i].ToString()==UserCookie.Value.ToString())
  134. {
  135. //this.lblBccToAddr.Text = UserCookie.Value.ToString();
  136. this.lblBccToAddr.Text = UDS.Components .Staff.GetRealNameByUsername(UserCookie.Value.ToString());
  137. }
  138. }
  139. this.lblSubject.Text    = dataReader["MailSubject"].ToString();
  140. this.lblBody.Text       = dataReader["MailBody"].ToString();
  141. this.lblSendDate.Text   = dataReader["MailSendDate"].ToString();
  142. this.lblReceiverStr .Text = UDS.Components.Staff.GetRealNameStrByUsernameStr(dataReader["MailReceiverStr"].ToString(),0);
  143. this.lblProjectName .Text = dataReader["classname"].ToString();
  144. }
  145. dataReader.Close();
  146. // 开始读取附件信息
  147. try
  148. {
  149. dataReader = mailclass.GetMailAttInfoDbreader(MailID);
  150. }
  151. catch
  152. {
  153. Server.Transfer("../../Error.aspx");
  154. }
  155. while(dataReader.Read())
  156. {
  157. lblAttachFile.Text += "&nbsp;<a href='Download.aspx?destFileName="+Server.UrlEncode(dataReader[2].ToString())+"'>"+dataReader[0].ToString()+"("+dataReader[1].ToString()+" Byte)</a><br>";
  158. }
  159. dataReader.Close();
  160. mailclass = null;
  161. }
  162. #endregion
  163. #region Web Form Designer generated code
  164. override protected void OnInit(EventArgs e)
  165. {
  166. //
  167. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  168. //
  169. InitializeComponent();
  170. base.OnInit(e);
  171. }
  172. /// <summary>
  173. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  174. /// 此方法的内容。
  175. /// </summary>
  176. private void InitializeComponent()
  177. {    
  178. this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
  179. this.Load += new System.EventHandler(this.Page_Load);
  180. }
  181. #endregion
  182. private void btnDelete_Click(object sender, System.EventArgs e)
  183. {
  184. MailClass mail   = new MailClass();
  185. string sql   = " MailID="+MailID.ToString();
  186. if(FolderType!="3"?mail.MailDelete(sql,0):mail.MailDelete(sql,1))
  187. {
  188. Response.Write("<script language=javascript>alert('邮件删除成功!');window.location='Index.aspx?FolderType="+FolderType+"';</script>");
  189. }
  190. else
  191. {
  192. Server.Transfer("../../Error.aspx");
  193. }
  194. mail=null;
  195. }
  196. }
  197. }