using System;
using System.Data;
using System.Data.SqlClient;
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;

public partial class RevertCard : System.Web.UI.Page
{
    DataOperate sqlBind = new DataOperate();
    SqlConnection sqlcon=new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
    protected void Page_Load(object sender, EventArgs e)
    {
        dlBind();
        string idStr = Page.Request.QueryString["CardID"];
        sqlcon.Open();
        string sqlstrbind = "select * from tb_Card where CardID='" + idStr + "'";
        SqlCommand sqlcom = new SqlCommand(sqlstrbind, sqlcon);
        SqlDataReader tmpReader = sqlcom.ExecuteReader();
        if (tmpReader.Read())
        {
            labCardTitle.Text = "帖子标题：" + tmpReader["CardName"].ToString();
            labCardID.Text = tmpReader["CardID"].ToString();
            labCardDate.Text = "发帖日期：" + tmpReader["CardDate"].ToString();
            labCardContent.Text = tmpReader["CardContent"].ToString();
        }
        sqlcon.Close();
    }
    protected void btnRevert_Click(object sender, EventArgs e)
    {
        string sqlstr = "insert into tb_RevertCard (CardID,RevertCardContent)"
           + " values ('" + labCardID.Text + "','" + txtRevertContent.Text + "')";
        sqlBind.DataCom(sqlstr);
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Index.aspx");
    }
    public void dlBind()
    {
        string idStr = Page.Request.QueryString["CardID"];
        int curpage = Convert.ToInt32(this.labPage.Text);
        PagedDataSource ps = new PagedDataSource();
        sqlcon.Open();
        string sqlstr = "select * from CardInfo_View where CardID='" + idStr + "'";
        SqlDataAdapter MyAdapter = new SqlDataAdapter(sqlstr, sqlcon);
        DataSet ds = new DataSet();
        MyAdapter.Fill(ds, "tb_Card");
        sqlcon.Close();
        ps.DataSource = ds.Tables["tb_Card"].DefaultView;
        ps.AllowPaging = true; //是否可以分页
        ps.PageSize = 2; //显示的数量
        ps.CurrentPageIndex = curpage - 1; //取得当前页的页码
        this.lnkbtnUp.Enabled = true;
        this.lnkbtnNext.Enabled = true;
        this.lnkbtnBack.Enabled = true;
        this.lnkbtnOne.Enabled = true;
        if (curpage == 1)
        {
            this.lnkbtnOne.Enabled = false;//不显示第一页按钮
            this.lnkbtnUp.Enabled = false;//不显示上一页按钮
        }
        if (curpage == ps.PageCount)
        {
            this.lnkbtnNext.Enabled = false;//不显示下一页
            this.lnkbtnBack.Enabled = false;//不显示最后一页
        }
        this.labBackPage.Text = Convert.ToString(ps.PageCount);
        this.dlRevertCard.DataSource = ps;
        this.dlRevertCard.DataKeyField = "CardID";
        this.dlRevertCard.DataBind();
    }
    protected void lnkbtnOne_Click(object sender, EventArgs e)
    {
        this.labPage.Text = "1";
        this.dlBind();
    }
    protected void lnkbtnUp_Click(object sender, EventArgs e)
    {
        this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) - 1);
        this.dlBind();
    }
    protected void lnkbtnNext_Click(object sender, EventArgs e)
    {
        this.labPage.Text = Convert.ToString(Convert.ToInt32(this.labPage.Text) + 1);
        this.dlBind();
    }
    protected void lnkbtnBack_Click(object sender, EventArgs e)
    {
        this.labPage.Text = this.labBackPage.Text;
        this.dlBind();
    }
}
