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_dairy_revise : System.Web.UI.Page
{
    static int goid;
    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)
        {
            goid = Convert.ToInt16(Request.QueryString["myGridid"]);
            downclass();     //下拉列框日记分类
            readdata(goid);      //读取所要修改的数据
        }
        
    }
    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 = 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 = "update dairy set dtitle='" + dtitle + "',dclass='" + dclass + "',dbriefly='" + dbriefly + "',dtop=" + dtop + ",dbit=" + dbit + ",dtime='" + dtimes + "',dwriter='" + dwriter + "',dcontent='" + dcontent + "' where id=" + goid;
            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();
        }
    }

    //读取原有数据，修改操作
    protected void readdata(int requestval)
    {
       
        try
        {
            one = conn.sqlconn();
            one.Open();
            string sql = "select * from dairy where id="+requestval;
            cmd = new SqlCommand(sql, one);
            rs = cmd.ExecuteReader();
            if (rs.Read())
            {
                int i;
                for (i = 0; i < ddclass.Items.Count;i++ )
                {
                    if (ddclass.Items[i].Value.ToString() == rs["dclass"].ToString())
                    {
                        ddclass.SelectedIndex = i;
                    }
                }
                tbtitle.Text = rs["dtitle"].ToString();
                tbbriefly.Text = rs["dbriefly"].ToString();
                cbtop.Checked = Convert.ToBoolean(rs["dtop"]);
                tbtitle.Text = rs["dtitle"].ToString();
                tbbit.Text =rs["dbit"].ToString();
                stringdo shortime = new stringdo();
                lbtimes.Text = shortime.short_time(rs["dtime"]);
                tbwriter.Text=rs["dwriter"].ToString();
                strreplace str = new strreplace();
                FCKeditor1.Value = str.rehtmlstr(rs["dcontent"].ToString());
            }
        }
        catch { }
        finally
        {
            rs.Dispose();
            cmd.Dispose();
            one.Dispose();
            one.Close();
        }
    }

}
