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;

public partial class manage_Manageliuyan : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Loginjudge();
        if (!Page.IsPostBack)
        {
            Showliuyan();
        }

    }
    private void Showliuyan()
    {
        INews shownews = new Mynews();
        DataSet ds = shownews.DsGetinfo("SELECT * FROM Leaveword ORDER BY Createdate DESC");
        LiuyanGridView.DataSource = ds.Tables["aa"].DefaultView;
        LiuyanGridView.DataBind();
    }
    protected string Myleaveword(string sContent)
    {
        string str = sContent;
        if (str.Length > 30)
        {
            str=str.Substring(0,30) + "..";
        }
        return str;
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        foreach (GridViewRow row in LiuyanGridView.Rows)
        {
            CheckBox cbox = (CheckBox)row.FindControl("chkBox");
            if (cbox != null)
            {
                if (CheckBox1.Checked == true)
                {
                    cbox.Checked = true;
                }
                else
                {
                    cbox.Checked = false;
                }
            }
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        INews shownews = new Mynews();
        foreach (GridViewRow row in LiuyanGridView.Rows)
        {
            CheckBox cbox = (CheckBox)row.FindControl("chkBox");
            if (cbox != null)
            {
                if (cbox.Checked == true)
                {
                    int nLeavewordID=Int32.Parse(LiuyanGridView.DataKeys[row.RowIndex].Value.ToString());
                    shownews.Executeinfo("DELETE FROM Leaveword WHERE LeavewordID=" + nLeavewordID);
                }
            }
        }
        Showliuyan();
    }
    private void Loginjudge()
    {
        if (Session["Login"] == null)
        {
            Response.Redirect("Error.aspx");
        }
        else
        {
            if (Session["Login"] != "pass")
            {
                Response.Redirect("Error.aspx");
            }

        }
    }
}
