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

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.SM
  14. {
  15. /// <summary>
  16. /// MsgManage 的摘要说明。
  17. /// </summary>
  18. public class MsgManage : System.Web.UI.Page
  19. {
  20. protected System.Web.UI.WebControls.Label lblSender;
  21. protected System.Web.UI.WebControls.Label lblContent;
  22. protected System.Web.UI.WebControls.TextBox txtContent;
  23. protected System.Web.UI.WebControls.Button btnReply;
  24. protected System.Web.UI.WebControls.Button btnNext;
  25. protected System.Web.UI.WebControls.TextBox txtMsgID;
  26. protected System.Web.UI.WebControls.Button btnRead;
  27. protected System.Web.UI.WebControls.TextBox txtRealName;
  28. protected System.Web.UI.WebControls.TextBox txtSender;
  29. protected System.Web.UI.WebControls.Label lblShortCut;
  30. protected System.Web.UI.WebControls.Label lblInstruction;
  31. protected System.Web.UI.WebControls.Button btnHistory;
  32. private void Page_Load(object sender, System.EventArgs e)
  33. {
  34. if(!Page.IsPostBack)
  35. {
  36. string Username = Request.Cookies["Username"].Value.ToString();
  37. ReadMsg(Username);
  38. CheckNextMsg(Username);
  39. this.btnReply.CommandArgument="view";
  40. this.btnHistory.Attributes["onclick"] = "javascript: mytop=screen.availHeight-330-175;myleft=0;var newhiswin=window.open('../SM/MsgHistory.aspx?Sender="+Username+"&Receiver="+this.txtSender.Text+"','show','height=170,width=350,status=0,toolbar=no,menubar=no,location=no,scrollbars=yes,top='+mytop+',left='+myleft+',resizable=yes');newhiswin.focus();";
  41. }
  42. }
  43. private void CheckNextMsg(string Username)
  44. {
  45. SMS sm = new SMS();
  46. int count = 0;
  47. try
  48. {
  49. count = sm.GetNewMsgCount(Username);
  50. if(count>=2)
  51. {
  52. this.btnNext.Enabled = true;
  53. }
  54. else
  55. {
  56. this.btnNext.Enabled = false;
  57. }
  58. }
  59. catch
  60. {
  61. Server.Transfer("../Error.aspx");
  62. }
  63. }
  64. private void ReadMsg(string Username)
  65. {
  66. this.txtSender.Enabled = false;
  67. this.txtRealName.Enabled = false;
  68. this.txtContent.Enabled = false;
  69. this.btnReply.Enabled = true;
  70. this.btnHistory .Enabled = true;
  71. SMS sm = new SMS();
  72. SqlDataReader dataReader = null; 
  73. try
  74. {
  75. dataReader = sm.GetNewLocalMsg(Username);
  76. if(dataReader.Read())
  77. {
  78. this.txtSender.Text  = dataReader["Sender"].ToString();
  79. this.txtRealName.Text = UDS.Components.Staff.GetRealNameByUsername(this.txtSender.Text);
  80. this.txtContent.Text = dataReader["Content"].ToString();
  81. this.txtMsgID.Text   = dataReader["ID"].ToString();
  82.   }
  83. }
  84. catch
  85. {
  86. Server.Transfer("../Error.aspx");
  87. }
  88. }
  89. #region Web Form Designer generated code
  90. override protected void OnInit(EventArgs e)
  91. {
  92. //
  93. // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
  94. //
  95. InitializeComponent();
  96. base.OnInit(e);
  97. }
  98. /// <summary>
  99. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  100. /// 此方法的内容。
  101. /// </summary>
  102. private void InitializeComponent()
  103. {    
  104. this.btnReply.Click += new System.EventHandler(this.btnReply_Click);
  105. this.btnNext.Click += new System.EventHandler(this.btnNext_Click);
  106. this.btnRead.Click += new System.EventHandler(this.btnRead_Click);
  107. this.Load += new System.EventHandler(this.Page_Load);
  108. }
  109. #endregion
  110. private void btnRead_Click(object sender, System.EventArgs e)
  111. {
  112. SMS sm = new SMS();
  113. string Username = Request.Cookies["Username"].Value.ToString();
  114. try
  115. {
  116. sm.ReadMsg(this.txtMsgID.Text.ToString(),Username);
  117. Response.Write("<script language=javascript>window.opener.location.reload();window.close();</script>");
  118. }
  119. catch(Exception ex)
  120. {
  121. UDS.Components.Error.Log(ex.ToString());
  122. Server.Transfer("../Error.aspx");
  123. }
  124. }
  125. private void btnNext_Click(object sender, System.EventArgs e)
  126. {
  127. SMS sm = new SMS();
  128. string Username = Request.Cookies["Username"].Value.ToString();
  129. try
  130. {
  131. sm.ReadMsg(this.txtMsgID.Text.ToString(),Username);
  132. Response.Redirect("MsgManage.aspx");
  133. }
  134. catch
  135. {
  136. Server.Transfer("../Error.aspx");
  137. }
  138. }
  139. private void btnReply_Click(object sender, System.EventArgs e)
  140. {
  141. string Username = Request.Cookies["Username"].Value.ToString();
  142. this.lblInstruction.Text = "回复消息";
  143. SMS sm = new SMS();
  144. #region 更新记录的已读状态
  145. try
  146. {
  147. sm.ReadMsg(this.txtMsgID.Text.ToString(),Username);
  148. }
  149. catch
  150. {
  151. Server.Transfer("../Error.aspx");
  152. }
  153. #endregion
  154. if(this.btnReply.CommandArgument=="view") //查看消息状态
  155. {
  156. btnReply.Text = "发送";
  157. btnReply.CommandArgument = "reply";
  158. btnRead.Visible = false;
  159. btnNext.Visible = false;
  160. lblSender.Text = "接收者";
  161. txtSender.Enabled = true;
  162. txtContent.Enabled = true;
  163. txtContent.Text = "";
  164. this.lblShortCut.Text = "按Ctrl+回车键 发送消息 ";
  165. }
  166. else //发送消息状态
  167. { //sender文本框变为receiver
  168. int Code = sm.SendMsg(Username,this.txtSender.Text,this.txtContent.Text,1,DateTime.Now,"",0,0);
  169. if(Code==1)
  170. Response.Write("<script language=javascript>alert('回复成功');window.opener.location.reload();window.close();</script>");
  171. else
  172. Response.Write("<script language=javascript>alert('回复失败');window.opener.location.reload();window.close();</script>");
  173. }
  174. }
  175. }
  176. }