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_Manageorder : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Loginjudge();
        if (!Page.IsPostBack)
        {
            Bindorder();
        }
    }
    //绑定订单控件
    private void Bindorder()
    {
        DataSet ds = Getorders();
        OrderGridView.DataSource = ds.Tables["aa"].DefaultView;
        OrderGridView.DataBind();
    }
    //删除数据按ID
    private void DeleteorderByID(int nOrderID)
    {
        INews shownews = new Mynews();
        shownews.Executeinfo("DELETE FROM Myorder WHERE OrderID=" + nOrderID);
       
    }
    //打开订单数据库
    public DataSet Getorders()
    {
        INews shownews = new Mynews();
        DataSet ds = shownews.DsGetinfo("SELECT OrderID,Title,Content,Lxr,Lxdh,Lxdw,Createdate FROM Myorder ORDER BY Createdate DESC");
        
        return ds;
    }
    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
    {
        foreach (GridViewRow row in OrderGridView.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)
    {
        foreach(GridViewRow row in OrderGridView.Rows)
        {
            CheckBox cbox = (CheckBox)row.FindControl("chkBox");
            if (cbox.Checked == true)
            {
                DeleteorderByID(Int32.Parse(OrderGridView.DataKeys[row.RowIndex].Value.ToString()));
            }
        }
        Bindorder();
    }
    protected void OrderGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        OrderGridView.PageIndex = e.NewPageIndex;
        Bindorder();
    }
    private void Loginjudge()
    {
        if (Session["Login"] == null)
        {
            Response.Redirect("Error.aspx");
        }
        else
        {
            if (Session["Login"] != "pass")
            {
                Response.Redirect("Error.aspx");
            }

        }
    }
}
