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_BigProductCategory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["WtoRightName"] == null)
        {
            Response.Redirect("~/SYSADMIN/main/error.aspx?err=非法登陆!或系统超时，请刷新后重新登录");
        }
        this.databind2();
      
     }

 public void databind2()
    { 
    string isdo = Request.QueryString["do"].ToString().Trim();
    string LBid=Request.QueryString["id"].ToString().Trim();
    SqlConnection conn = CDatabase.wtoconn();
        conn.Open();
    this.Panel1.Visible = false;

  
     
     switch (isdo)
        {
          case "edit":
                this.title.Text="修改类名";
                this.Panel1.Visible = true;
                SqlCommand cmd = new SqlCommand("select * from BigProductAttribute where id=" + LBid, conn);
                SqlDataReader sdr = cmd.ExecuteReader();
                sdr.Read();
                this.LB.Text = sdr.GetString(1);
                this.sort.Text =Convert.ToString(sdr.GetInt32(2));
                sdr.Close();
                conn.Close();

                break;
 
            case "Del"://删除大类

                SqlCommand smlbcount = new SqlCommand("select count(*) from SmallProductAttribute where BigAttributeId=" + LBid, conn);
                int count = Convert.ToInt32(smlbcount.ExecuteScalar().ToString());

                if (count > 0)
                {
                    Response.Redirect("/sysadmin/main/errorlei.aspx?err=存在子类,不能删除!&backurl=/sysadmin/products/ProductAttribute.aspx");
                }
                else
                {
                    SqlCommand cmdDel = new SqlCommand("delete BigProductAttribute where id=" + LBid, conn);
                    cmdDel.ExecuteNonQuery();
                    Response.Redirect("ProductAttribute.aspx");
                }
                

                
                break;        
          }
      }


    //修改大类并返回
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        string LBid2 = Request.QueryString["id"].ToString().Trim();
        string LB = Request["LB"].ToString().Trim();
        int Sort =Convert.ToInt32(Request["sort"].ToString().Trim());
        
        SqlConnection conn = CDatabase.wtoconn();


        conn.Open();
        Response.Write(LBid2+LB+Sort);
        SqlCommand cmd2 = new SqlCommand("update BigProductAttribute  set BigAttribute='" + LB + "',Sort=" + Sort + " where id=" + LBid2, conn);
        cmd2.ExecuteNonQuery();
        conn.Close();
        Response.Redirect("ProductAttribute.aspx");
        
    }


}
