add_articleto.aspx.cs
资源名称:论坛源码.rar [点击查看]
上传用户:scene123
上传日期:2010-02-19
资源大小:3311k
文件大小:5k
源码类别:
.net编程
开发平台:
C#
- 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.Data.OleDb;
- using System.Text;
- using System.Configuration;
- using System.Web.Security;
- using System.Security.Cryptography;
- using System.IO;
- namespace kuangren
- {
- /// <summary>
- /// add_articleto 的摘要说明。
- /// </summary>
- public class add_articleto : System.Web.UI.Page
- {
- protected int intRunTime;
- protected DateTime dtStartTime = DateTime.Now;
- protected System.Data.OleDb.OleDbCommand cmd;
- protected System.Data.OleDb.OleDbCommand cmd4;
- protected System.Data.OleDb.OleDbCommand cmd5;
- protected System.Data.OleDb.OleDbConnection conn;
- protected string OleDbSqlforum;
- protected string OleDbuser;
- public DataSet dsPending;
- public DataSet dsPending3;
- public string sql;
- public string sql3;
- protected int lastid;
- public int userjudge2;
- public int userjudge3;
- public int sum1;
- public int sum2;
- public int sum3;
- public int sum4;
- public int sum5;
- private void Page_Load(object sender, System.EventArgs e)
- {
- if (Request.Cookies["jusername"]==null)
- {
- Response.Redirect("logine.aspx");
- }
- string str=""+Request.Form["subject"]+"";
- string str1=""+Request.Form["content"]+"";
- userjudge2=System.Text.Encoding.Default.GetByteCount(str);
- userjudge3=System.Text.Encoding.Default.GetByteCount(str1);
- if (userjudge2>50||userjudge2==0||userjudge3>16240||userjudge3==0)
- {
- Response.Redirect("announcerror.aspx");
- }
- OleDbConnection con;
- string OleDbsql;
- OleDbCommand cmd;
- StringBuilder sb=new StringBuilder();
- ArrayList values=new ArrayList();
- 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}')");
- values.Add(Request.Form["subject"]);
- values.Add(Request.Form["content"]);
- values.Add(Request.Form["f3_face"]);
- values.Add(Request.Form["f3_name"]);
- values.Add(Request.UserHostAddress);
- values.Add(Convert.ToInt32(Request.Form["f3_sy"]));
- if(Request.Form["f3_html"]!="")
- values.Add(0);
- else
- values.Add(1);
- OleDbsql=String.Format(sb.ToString(),values.ToArray());
- con=new OleDbConnection(ConfigurationSettings.AppSettings["cnFriends.ConnectionString"]);
- cmd=new OleDbCommand(OleDbsql,con);
- sql="SELECT top 1 f3_id from forum_3 order by f3_id desc";
- dsPending=new DataSet();
- OleDbDataAdapter adWord=new OleDbDataAdapter(sql,con);
- adWord.Fill(dsPending,"forum_3");
- lastid=(Convert.ToInt32(dsPending.Tables[0].Rows[0]["f3_id"])+1);
- 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"]+"";
- cmd4=new OleDbCommand(OleDbSqlforum,con);
- 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"]+"'";
- cmd5=new OleDbCommand(OleDbuser,con);
- con.Open();
- bool doredirect=true;
- try
- {
- cmd.ExecuteNonQuery();
- cmd4.ExecuteNonQuery();
- cmd5.ExecuteNonQuery();
- }
- catch
- {
- doredirect=false;
- }
- finally
- {
- con.Close();
- }
- if(doredirect)
- {
- }
- else
- {
- Response.Redirect("index.aspx");
- }
- //定义发帖统计
- 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";
- dsPending3=new DataSet();
- OleDbDataAdapter adWord3=new OleDbDataAdapter(sql3,con);
- adWord3.Fill(dsPending3,"forum_2");
- Page.DataBind();
- sum1=Convert.ToInt32(dsPending3.Tables[0].Rows[0]["sum1"]);
- sum2=Convert.ToInt32(dsPending3.Tables[0].Rows[0]["sum2"]);
- sum3=Convert.ToInt32(dsPending3.Tables[0].Rows[0]["sum3"])+1;
- sum4=Convert.ToInt32(dsPending3.Tables[0].Rows[0]["sum4"]);
- sum5=sum1+sum2;
- //结束
- //写文件
- using (StreamWriter sw = new StreamWriter(Server.MapPath("Writerfile1.aspx"),false,System.Text.Encoding.GetEncoding("gb2312")))
- {
- // Add some text to the file.
- sw.Write("<table width='100%' border='0' cellspacing='0' cellpadding='0'>");
- sw.WriteLine("<tr> ");
- sw.WriteLine("<td width='50%'>今日发贴:<font color=#ff0000><b>"+sum3+"</b></font> 篇</td>");
- sw.Write("<td width='50%'>主题总数:<b>"+sum1+"</b> 篇 </td>");
- sw.Write("</tr>");
- sw.Write("<tr>");
- sw.Write("<td width='50%'>昨日发贴:<b>"+sum4+"</b> 篇 </td>");
- sw.Write("<td width='50%'>帖子总数:<b>"+sum5+"</b> 篇 </td>");
- sw.Write("</tr>");
- sw.Write("</table>");
- sw.Close();
- }
- //结束
- con.Close();
- }
- #region Web 窗体设计器生成的代码
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
- //
- InitializeComponent();
- base.OnInit(e);
- }
- /// <summary>
- /// 设计器支持所需的方法 - 不要使用代码编辑器修改
- /// 此方法的内容。
- /// </summary>
- private void InitializeComponent()
- {
- this.Load += new System.EventHandler(this.Page_Load);
- }
- #endregion
- }
- }