PopSetup.aspx.cs
上传用户:cha0314
上传日期:2014-03-02
资源大小:12522k
文件大小:11k
源码类别:

C#编程

开发平台:

C#

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Web;
  8. using System.Web.SessionState;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using System.Web.UI.HtmlControls;
  12. using UDS.Components;
  13. namespace UDS.SubModule.UnitiveDocument.Mail.External
  14. {
  15. /// <summary>
  16. /// PopSetup 的摘要说明。
  17. /// </summary>
  18. public class PopSetup : System.Web.UI.Page
  19. {
  20. protected System.Web.UI.WebControls.TextBox txtTimeOut1;
  21. protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator6;
  22. protected System.Web.UI.WebControls.TextBox txtPort1;
  23. protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator9;
  24. protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator4;
  25. protected System.Web.UI.WebControls.TextBox txtPort2;
  26. protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator8;
  27. protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator5;
  28. protected System.Web.UI.WebControls.TextBox txtPort3;
  29. protected System.Web.UI.WebControls.TextBox txtTimeOut2;
  30. protected System.Web.UI.WebControls.TextBox txtTimeOut3;
  31. protected System.Web.UI.WebControls.Button btnOK;
  32. protected System.Web.UI.WebControls.Button btnCancel;
  33. protected System.Web.UI.WebControls.Button btnTest1;
  34. protected System.Web.UI.WebControls.Button btnTest2;
  35. protected System.Web.UI.WebControls.Button btnTest3;
  36. protected System.Web.UI.WebControls.TextBox txtTitle1;
  37. protected System.Web.UI.WebControls.TextBox txtPopSvrName1;
  38. protected System.Web.UI.WebControls.TextBox txtPopUserName1;
  39. protected System.Web.UI.WebControls.TextBox txtPopPwd1;
  40. protected System.Web.UI.WebControls.TextBox txtTitle2;
  41. protected System.Web.UI.WebControls.TextBox txtEmail2;
  42. protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator2;
  43. protected System.Web.UI.WebControls.TextBox txtEmail1;
  44. protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
  45. protected System.Web.UI.WebControls.TextBox txtPopSvrName2;
  46. protected System.Web.UI.WebControls.TextBox txtPopUserName2;
  47. protected System.Web.UI.WebControls.TextBox txtPopPwd2;
  48. protected System.Web.UI.WebControls.TextBox txtTitle3;
  49. protected System.Web.UI.WebControls.TextBox txtEmail3;
  50. protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator3;
  51. protected System.Web.UI.WebControls.TextBox txtPopSvrName3;
  52. protected System.Web.UI.WebControls.TextBox txtPopUserName3;
  53. protected System.Web.UI.WebControls.TextBox txtPopPwd3;
  54. protected System.Web.UI.WebControls.CheckBox chkDelSvrMsg1;
  55. protected System.Web.UI.WebControls.CheckBox chkDownNew1;
  56. protected System.Web.UI.WebControls.CheckBox chkDelSvrMsg2;
  57. protected System.Web.UI.WebControls.CheckBox chkDownNew2;
  58. protected System.Web.UI.WebControls.CheckBox chkDelSvrMsg3;
  59. protected System.Web.UI.WebControls.CheckBox chkDownNew3;
  60. protected System.Web.UI.WebControls.Label lblResultRep1;
  61. protected System.Web.UI.WebControls.Label lblResultRep2;
  62. protected System.Web.UI.WebControls.Label lblResultRep3;
  63. protected System.Web.UI.WebControls.Label lblPwdShow1;
  64. protected System.Web.UI.WebControls.Label lblPwdShow2;
  65. protected System.Web.UI.WebControls.Label lblPwdShow3;
  66. protected System.Web.UI.HtmlControls.HtmlInputHidden lblPwd1;
  67. protected System.Web.UI.HtmlControls.HtmlInputHidden lblPwd2;
  68. protected System.Web.UI.HtmlControls.HtmlInputHidden lblPwd3;
  69. protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator7;
  70. private void Page_Load(object sender, System.EventArgs e)
  71. {
  72. if(!Page.IsPostBack)
  73. {
  74. BindData();
  75. }
  76. }
  77. #region Web 窗体设计器生成的代码
  78. override protected void OnInit(EventArgs e)
  79. {
  80. //
  81. // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
  82. //
  83. InitializeComponent();
  84. base.OnInit(e);
  85. }
  86. /// <summary>
  87. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  88. /// 此方法的内容。
  89. /// </summary>
  90. private void InitializeComponent()
  91. {    
  92. this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
  93. this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
  94. this.btnTest1.Click += new System.EventHandler(this.btnTest1_Click);
  95. this.btnTest2.Click += new System.EventHandler(this.btnTest2_Click);
  96. this.btnTest3.Click += new System.EventHandler(this.btnTest3_Click);
  97. this.Load += new System.EventHandler(this.Page_Load);
  98. }
  99. #endregion
  100. private void BindData()
  101. {
  102. MailClass mail = new MailClass();
  103. string Username = Request.Cookies["Username"].Value.ToString();
  104. SqlDataReader dataReader = null; 
  105. try
  106. {
  107. dataReader = mail.ExtGetSetting(Username,1);
  108. if(dataReader.Read())
  109. {
  110. this.txtTitle1 .Text = dataReader["Title"].ToString();
  111. this.txtEmail1 .Text = dataReader["Email"].ToString();
  112. this.txtPopSvrName1 .Text   = dataReader["PopServer"].ToString();
  113. this.txtPopUserName1 .Text  = dataReader["PopUsername"].ToString();
  114. this.lblPwdShow1.Visible    = true;
  115. this.lblPwd1.Value = dataReader["PopPassword"].ToString();
  116. this.txtTimeOut1 .Text = dataReader["TimeOut"].ToString();
  117. this.txtPort1.Text = dataReader["PopPort"].ToString();
  118. this.chkDelSvrMsg1 .Checked = dataReader["IsDelAfterRead"].ToString()=="True"?true:false;
  119. this.chkDownNew1 .Checked   = dataReader["IsReceiveNew"].ToString()=="True"?true:false;
  120. }
  121. dataReader.Close();
  122. dataReader = mail.ExtGetSetting(Username,2);
  123. if(dataReader.Read())
  124. {
  125. this.txtTitle2 .Text = dataReader["Title"].ToString();
  126. this.txtEmail2 .Text = dataReader["Email"].ToString();
  127. this.txtPopSvrName2 .Text   = dataReader["PopServer"].ToString();
  128. this.txtPopUserName2 .Text  = dataReader["PopUsername"].ToString();
  129. this.lblPwdShow2.Visible    = true;
  130. this.lblPwd2.Value = dataReader["PopPassword"].ToString();
  131. this.txtTimeOut2 .Text = dataReader["TimeOut"].ToString();
  132. this.txtPort2.Text = dataReader["PopPort"].ToString();
  133. this.chkDelSvrMsg2 .Checked = dataReader["IsDelAfterRead"].ToString()=="True"?true:false;
  134. this.chkDownNew2 .Checked   = dataReader["IsReceiveNew"].ToString()=="True"?true:false;
  135. }
  136. dataReader = null;
  137. dataReader = mail.ExtGetSetting(Username,3);
  138. if(dataReader.Read())
  139. {
  140. this.txtTitle3 .Text = dataReader["Title"].ToString();
  141. this.txtEmail3 .Text = dataReader["Email"].ToString();
  142. this.txtPopSvrName3 .Text   = dataReader["PopServer"].ToString();
  143. this.txtPopUserName3 .Text  = dataReader["PopUsername"].ToString();
  144. this.lblPwdShow3.Visible    = true;
  145. this.lblPwd3.Value = dataReader["PopPassword"].ToString();
  146. this.txtTimeOut3 .Text = dataReader["TimeOut"].ToString();
  147. this.txtPort3.Text = dataReader["PopPort"].ToString();
  148. this.chkDelSvrMsg3 .Checked = dataReader["IsDelAfterRead"].ToString()=="True"?true:false;
  149. this.chkDownNew3 .Checked   = dataReader["IsReceiveNew"].ToString()=="True"?true:false;
  150. }
  151. dataReader = null;
  152. }
  153. catch(Exception ex)
  154. {
  155. dataReader.Close();
  156. UDS.Components.Error .Log(ex.ToString());
  157. Server.Transfer("../../../Error.aspx");
  158. }
  159. }
  160. private void btnOK_Click(object sender, System.EventArgs e)
  161. {
  162. this.SaveSetting();
  163. Response.Redirect("PopSetup.aspx");
  164. }
  165. private void SaveSetting()
  166. {
  167. MailClass mail   = new MailClass();
  168. string Username = Request.Cookies["Username"].Value.ToString();
  169. try
  170. {
  171. if(mail.ExtClearSettings(Username))
  172. {
  173. mail.ExtSaveSetting(Username,this.txtTitle1.Text,this.txtEmail1 .Text,true,"","","","21",this.txtPopSvrName1.Text,this.txtPopUserName1.Text,(this.txtPopPwd1.Text!="")?this.txtPopPwd1.Text:this.lblPwd1.Value,Int32.Parse(this.txtPort1.Text),this.chkDelSvrMsg1.Checked,this.chkDownNew1.Checked,Int32.Parse(this.txtTimeOut1.Text),1);
  174. mail.ExtSaveSetting(Username,this.txtTitle2.Text,this.txtEmail2 .Text,true,"","","","21",this.txtPopSvrName2.Text,this.txtPopUserName2.Text,(this.txtPopPwd2.Text!="")?this.txtPopPwd2.Text:this.lblPwd2.Value,Int32.Parse(this.txtPort2.Text),this.chkDelSvrMsg2.Checked,this.chkDownNew2.Checked,Int32.Parse(this.txtTimeOut2.Text),2);
  175. mail.ExtSaveSetting(Username,this.txtTitle3.Text,this.txtEmail3. Text,true,"","","","21",this.txtPopSvrName3.Text,this.txtPopUserName3.Text,(this.txtPopPwd3.Text!="")?this.txtPopPwd3.Text:this.lblPwd3.Value,Int32.Parse(this.txtPort3.Text),this.chkDelSvrMsg3.Checked,this.chkDownNew3.Checked,Int32.Parse(this.txtTimeOut3.Text),3);
  176. }
  177. else
  178. {
  179. Server.Transfer("../../../Error.aspx");
  180. }
  181. }
  182. catch(Exception ex)
  183. {
  184. UDS.Components.Error .Log(ex.ToString());
  185. Server.Transfer("../../../Error.aspx");
  186. }
  187. mail=null;
  188. }
  189. private void TestPopConn(string PopServer,string Uname,string Pwd,string Port,int OrderID)
  190. {
  191. int Count;
  192. jmail.Message Msg=new jmail.Message();
  193. jmail.POP3 jpop = new jmail.POP3();
  194. try
  195. {
  196. jpop.Connect(Uname,Pwd,PopServer,Int32.Parse(Port));
  197. Count = jpop.Count;
  198. switch (OrderID) 
  199. {
  200. case 1:
  201. this.lblResultRep1.Visible = true;
  202. this.lblResultRep1.Text = "测试成功,共有 "+Count.ToString()+" 封邮件";
  203. break;
  204. case 2:
  205. this.lblResultRep2 .Visible = true;
  206. this.lblResultRep2.Text = "测试成功,共有 "+Count.ToString()+" 封邮件";
  207. break;
  208. case 3:
  209. this.lblResultRep3 .Visible = true;
  210. this.lblResultRep3.Text = "测试成功,共有 "+Count.ToString()+" 封邮件";
  211. break;
  212. default:
  213. break;
  214. }
  215. jpop.Disconnect();
  216. }
  217. catch(Exception e)
  218. {
  219. switch (OrderID) 
  220. {
  221. case 1:
  222. this.lblResultRep1.Visible = true;
  223. this.lblResultRep1.Text = "未能连接到所指定的[接收邮件服务器],或输入了错误的[用户名]或[密码]!";
  224. break;
  225. case 2:
  226. this.lblResultRep2 .Visible = true;
  227. this.lblResultRep2.Text = "未能连接到所指定的[接收邮件服务器],或输入了错误的[用户名]或[密码]!";
  228. break;
  229. case 3:
  230. this.lblResultRep3 .Visible = true;
  231. this.lblResultRep3.Text = "未能连接到所指定的[接收邮件服务器],或输入了错误的[用户名]或[密码]!";
  232. break;
  233. default:
  234. break;
  235. }
  236. }
  237. }
  238. private void btnTest1_Click(object sender, System.EventArgs e)
  239. {
  240. this.SaveSetting();
  241. this.TestPopConn(this.txtPopSvrName1.Text,this.txtPopUserName1.Text,(this.txtPopPwd1.Text!="")?this.txtPopPwd1.Text:this.lblPwd1.Value,this.txtPort1.Text,1);
  242. }
  243. private void btnTest2_Click(object sender, System.EventArgs e)
  244. {
  245. this.SaveSetting();
  246. this.TestPopConn(this.txtPopSvrName2.Text,this.txtPopUserName2.Text,(this.txtPopPwd2.Text!="")?this.txtPopPwd2.Text:this.lblPwd2.Value,this.txtPort2.Text,2);
  247. }
  248. private void btnTest3_Click(object sender, System.EventArgs e)
  249. {
  250. this.SaveSetting();
  251. this.TestPopConn(this.txtPopSvrName3.Text,this.txtPopUserName3.Text,(this.txtPopPwd3.Text!="")?this.txtPopPwd3.Text:this.lblPwd3.Value,this.txtPort3.Text,3);
  252. }
  253. private void btnCancel_Click(object sender, System.EventArgs e)
  254. {
  255. Response.Redirect("SetupNavi.aspx");
  256. }
  257. }
  258. }