using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using wormstrdo;

public partial class wormadmin_add_dairy : System.Web.UI.Page
{
    SqlConnection one;
    SqlCommand cmd;
    SqlDataReader rs;
    protected void Page_PreInit(object sender, EventArgs e)
   {
       if (Session["superad"] == null || Session["superpw"] == null)
       {
           Response.Redirect("login.aspx");
       }
       else
       {
           Page.Theme = "SkinFile";
       }
   }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            lbtimes.Text = DateTime.Now.ToShortDateString().ToString();
            tbwriter.Text=Session["superad"].ToString();
            tbbit.Text = "0";
            downclass();   //下拉列框日记分类
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string dtitle=tbtitle.Text.Trim();
        string dclass = ddclass.SelectedValue.ToString().Trim();
        string dbriefly = tbbriefly.Text.Trim();
        int dtop = Convert.ToInt16(cbtop.Checked);
        int dbit = Convert.ToInt16(tbbit.Text.Trim());
        string dtimes = lbtimes.Text.Trim();
        string dwriter = tbwriter.Text.Trim();
        //string dcontent = Regex.Replace(FCKeditor1.Value, @" <[\/\!]*?[^ <>]*?>", "");
        //FCKeditor1.HtmlEncodeOutput=false;
        string dcontent = FCKeditor1.Value;
        //字符串过滤
        strreplace str = new strreplace();
        dtitle = str.txtstr(dtitle);
        dbriefly = str.txtstr(dbriefly);
        dwriter = str.txtstr(dwriter);
        dcontent = str.htmlstr(dcontent);
        //End
        try
        {
            one = conn.sqlconn();
            one.Open();
            string sql = "insert into dairy(dclass,dtitle,dbit,dcontent,dtime,dwriter,dBriefly,dtop) values('" + dclass + "','" + dtitle + "'," + dbit + ",'" + dcontent + "','" + dtimes + "','" + dwriter + "','" + dbriefly + "'," + dtop + ")";
            cmd = new SqlCommand(sql, one);
            cmd.ExecuteNonQuery();
            ClientScript.RegisterStartupScript(GetType(), "Message", "<SCRIPT LANGUAGE='javascript'>alert('添加成功!');</script>");
        }
        catch (System.Exception ee)
        {
            Response.Write(ee.Message.ToString());
        }
        finally 
        {
            cmd.Dispose();
            one.Dispose();
            one.Close();
        }
    }

    //下拉列框日记分类
    protected void downclass()
    { 
        try
        {
            one = conn.sqlconn();
            one.Open();
            string sql = "select distinct dclass from classdai";
            cmd = new SqlCommand(sql, one);
            rs = cmd.ExecuteReader();
            while (rs.Read())
            {
                ddclass.Items.Add(new ListItem(rs["dclass"].ToString(), rs["dclass"].ToString()));
            }
        }
        catch (System.Exception ee)
        {
            Response.Write(ee.Message.ToString());
        }
        finally
        {
            rs.Dispose();
            cmd.Dispose();
            one.Dispose();
            one.Close();
        }
    }
}
