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 WTOSYSadmin_Products_ProductAttribute : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }
        if (!IsPostBack)
        {
            this.databind();
        }
    }
   public void databind()
    {
        SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
        SqlDataAdapter sdr = new SqlDataAdapter("select * from Brand", conn);
        DataSet ds = new DataSet();
        sdr.Fill(ds, "cu");
        GridView1.DataSource = ds;
        GridView1.DataKeyNames = new string[] { "id" };
        GridView1.DataBind();
        conn.Close();

        if (GridView1.Rows.Count == 0)
        {
            this.mslable.Visible = true;
            this.t1.Visible = false;
        }
        this.Label1.Text = "当前品牌数为<font color='red'><b>" + ds.Tables["cu"].DefaultView.Count + "</b></font>.分为<font color='red'><b>" + this.GridView1.PageCount + "</b></font>页显示.";

    }
   //插入大类
    //protected void LinkButton2_Click(object sender, EventArgs e)
    //{
    //    string LB = Request["LB2"].ToString().Trim();
    //    int Sort = Convert.ToInt32(Request["sort2"].ToString().Trim());
    //    SqlConnection conn = CDatabase.wtoconn();
    //    conn.Open();
    //    SqlCommand cmd2 = new SqlCommand("insert into BigProductAttribute(BigAttribute,Sort) values ('" + LB + "'," + Sort + ")", conn);
    //    cmd2.ExecuteNonQuery();
    //    conn.Close();
    //    Response.Redirect("ProductAttribute.aspx");
    
    // }
     protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
     {
         GridView1.PageIndex = e.NewPageIndex;
         databind();
     }


     protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
     {
         # region 行变色
         int i;
         int g = 0;
         //执行循环，保证每条数据都可以更新
         for (i = 0; i < GridView1.Rows.Count; i++)
         {
             //首先判断是否是数据行
             if (e.Row.RowType == DataControlRowType.DataRow)
             {

                 //当鼠标停留时更改背景色
                 e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
                 //当鼠标移开时还原背景色
                 e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
             }
             g++;
         }
         //如果是绑定数据行 
         if (e.Row.RowType == DataControlRowType.DataRow)
         {
             //鼠标经过时，行背景色变 
             e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E6F5FA'");
             //鼠标移出时，行背景色变 
             e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF'");
         }
         # endregion
         //如果是绑定数据行 
         if (e.Row.RowType == DataControlRowType.DataRow)
         {
             if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
             {
                 ((HyperLink)e.Row.Cells[4].Controls[0]).Attributes.Add("onclick", "javascript:return confirm('你确认要删除吗?')");
             }
         }
     }
     protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
     {

     }
     protected void CheckBox2_CheckedChanged(object sender, EventArgs e)
     {
         for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
         {
             CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
             if (CheckBox2.Checked == true)
             {
                 cbox.Checked = true;
             }
             else
             {
                 cbox.Checked = false;
             }
         }
     }
     protected void LinkButton2_Click(object sender, EventArgs e)
     {
         for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
         {
             CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");

             if (cbox.Checked == true)
             {
                 string sqlstr = "delete from Brand where  id=" + GridView1.DataKeys[i].Value;
                 Doadmin.Execsql(sqlstr);
             }
         }
         this.databind();
     }
     protected void LinkButton1_Click(object sender, EventArgs e)
     {
         CheckBox2.Checked = false;
         for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
         {
             CheckBox cbox = (CheckBox)GridView1.Rows[i].FindControl("CheckBox1");
             cbox.Checked = false;
         }
     }
     protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
     {

     }
 }