add_articleto.aspx.cs
上传用户:scene123
上传日期:2010-02-19
资源大小:3311k
文件大小:5k
源码类别:

.net编程

开发平台:

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.OleDb;
  12. using System.Text;
  13. using System.Configuration;
  14. using System.Web.Security;
  15. using System.Security.Cryptography;
  16. using System.IO;
  17. namespace kuangren
  18. {
  19. /// <summary>
  20. /// add_articleto 的摘要说明。
  21. /// </summary>
  22. public class add_articleto : System.Web.UI.Page
  23. {
  24. protected int intRunTime;
  25. protected DateTime dtStartTime = DateTime.Now;
  26. protected System.Data.OleDb.OleDbCommand cmd;
  27. protected System.Data.OleDb.OleDbCommand cmd4;
  28. protected System.Data.OleDb.OleDbCommand cmd5;
  29. protected System.Data.OleDb.OleDbConnection conn;
  30. protected string OleDbSqlforum;
  31. protected string OleDbuser;
  32. public    DataSet dsPending;
  33. public    DataSet dsPending3;
  34. public string sql;
  35. public string sql3;
  36.         protected int lastid;
  37. public int userjudge2;
  38. public int userjudge3;
  39. public int sum1;
  40. public int sum2;
  41. public int sum3;
  42. public int sum4;
  43. public int sum5;
  44. private void Page_Load(object sender, System.EventArgs e)
  45. {
  46. if (Request.Cookies["jusername"]==null)
  47. {
  48. Response.Redirect("logine.aspx");
  49. }
  50. string str=""+Request.Form["subject"]+"";
  51. string str1=""+Request.Form["content"]+"";
  52. userjudge2=System.Text.Encoding.Default.GetByteCount(str);
  53. userjudge3=System.Text.Encoding.Default.GetByteCount(str1);
  54. if  (userjudge2>50||userjudge2==0||userjudge3>16240||userjudge3==0)
  55. {
  56. Response.Redirect("announcerror.aspx");
  57. }
  58. OleDbConnection con;
  59. string OleDbsql;
  60. OleDbCommand cmd;
  61. StringBuilder sb=new StringBuilder();
  62. ArrayList values=new ArrayList();
  63. sb.Append("INSERT INTO [forum_3](f3_motif,f3_content,f3_face,f3_name,f3_uip,f3_sy,f3_html)  values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')"); 
  64.             
  65. values.Add(Request.Form["subject"]);
  66. values.Add(Request.Form["content"]); 
  67. values.Add(Request.Form["f3_face"]);
  68. values.Add(Request.Form["f3_name"]);
  69. values.Add(Request.UserHostAddress);
  70. values.Add(Convert.ToInt32(Request.Form["f3_sy"]));
  71. if(Request.Form["f3_html"]!="")
  72. values.Add(0);
  73. else
  74. values.Add(1);
  75. OleDbsql=String.Format(sb.ToString(),values.ToArray());
  76. con=new OleDbConnection(ConfigurationSettings.AppSettings["cnFriends.ConnectionString"]);
  77. cmd=new OleDbCommand(OleDbsql,con);
  78. sql="SELECT top 1 f3_id from forum_3  order by f3_id desc";
  79. dsPending=new DataSet();
  80. OleDbDataAdapter adWord=new OleDbDataAdapter(sql,con);
  81. adWord.Fill(dsPending,"forum_3");
  82. lastid=(Convert.ToInt32(dsPending.Tables[0].Rows[0]["f3_id"])+1);
  83. OleDbSqlforum="update [forum_2] set f2_topicnum=f2_topicnum+1,f2_lastpostuser='"+Request.Cookies["jusername"].Value+"',f2_lastposttime='"+DateTime.Now+"',f2_lasttopic='"+Request.Form["subject"]+"',f2_lastrootid="+lastid+" where f2_id="+Request.Form["f3_sy"]+"";          
  84. cmd4=new OleDbCommand(OleDbSqlforum,con);
  85. OleDbuser="update [userinfo]  SET u_post=u_post+1,u_money=u_money+2,u_fenshu=u_fenshu+2 where u_user='"+Request.Form["f3_name"]+"'";          
  86. cmd5=new OleDbCommand(OleDbuser,con);
  87. con.Open();
  88. bool doredirect=true;
  89. try
  90. {
  91. cmd.ExecuteNonQuery();
  92. cmd4.ExecuteNonQuery();
  93. cmd5.ExecuteNonQuery();
  94. }
  95. catch
  96. {
  97. doredirect=false;
  98. }
  99. finally
  100. {
  101. con.Close();
  102. }
  103. if(doredirect)
  104. {
  105. }
  106. else
  107. {
  108. Response.Redirect("index.aspx");
  109. }
  110. //定义发帖统计
  111. sql3="SELECT sum(f2_topicnum) as  sum1,sum(f2_replynum) as sum2,sum(f2_todaynum) as sum3,sum(f2_yestoday) as sum4  FROM forum_2";
  112. dsPending3=new DataSet();
  113. OleDbDataAdapter adWord3=new OleDbDataAdapter(sql3,con);
  114. adWord3.Fill(dsPending3,"forum_2");
  115. Page.DataBind();
  116. sum1=Convert.ToInt32(dsPending3.Tables[0].Rows[0]["sum1"]);
  117. sum2=Convert.ToInt32(dsPending3.Tables[0].Rows[0]["sum2"]);
  118. sum3=Convert.ToInt32(dsPending3.Tables[0].Rows[0]["sum3"])+1;
  119. sum4=Convert.ToInt32(dsPending3.Tables[0].Rows[0]["sum4"]);
  120. sum5=sum1+sum2;
  121. //结束
  122. //写文件
  123. using (StreamWriter sw = new StreamWriter(Server.MapPath("Writerfile1.aspx"),false,System.Text.Encoding.GetEncoding("gb2312")))
  124. {
  125. // Add some text to the file.
  126. sw.Write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
  127. sw.WriteLine("<tr> ");
  128. sw.WriteLine("<td width='50%'>今日发贴:<font color=#ff0000><b>"+sum3+"</b></font> 篇</td>");
  129. sw.Write("<td width='50%'>主题总数:<b>"+sum1+"</b> 篇 </td>");
  130. sw.Write("</tr>");
  131. sw.Write("<tr>");
  132. sw.Write("<td width='50%'>昨日发贴:<b>"+sum4+"</b> 篇 </td>");
  133. sw.Write("<td width='50%'>帖子总数:<b>"+sum5+"</b> 篇 </td>");  
  134. sw.Write("</tr>");
  135. sw.Write("</table>");
  136. sw.Close();
  137. }
  138. //结束
  139. con.Close();
  140. }
  141. #region Web 窗体设计器生成的代码
  142. override protected void OnInit(EventArgs e)
  143. {
  144. //
  145. // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
  146. //
  147. InitializeComponent();
  148. base.OnInit(e);
  149. }
  150. /// <summary>
  151. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  152. /// 此方法的内容。
  153. /// </summary>
  154. private void InitializeComponent()
  155. {    
  156. this.Load += new System.EventHandler(this.Page_Load);
  157. }
  158. #endregion
  159. }
  160. }