using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
///CategoryClass 的摘要说明
/// </summary>
public class CategoryClass
{
	
    /// <summary>
    /// 返回Category信息
    /// </summary>
    /// <returns>DataSet</returns>
    public DataSet CategoryAll()
    {
        DataSet ds = new DataSet();
        SqlConnection con = ConSql.ConnectionSql();
        SqlDataAdapter sdr = new SqlDataAdapter();
        sdr.SelectCommand = new SqlCommand();   //创建数据适配集的SelectCommand对象
        sdr.SelectCommand.CommandText = "select * from Category";
        sdr.SelectCommand.Connection = con; //直接调用数据库连接对象
        sdr.Fill(ds, "CategoryTable");  //填充数据集ds，表名为CategoryTable
        return ds;  //返回数据集
    }

    /// <summary>
    /// 按商品类别ID查找商品类别信息
    /// </summary>
    /// <param name="categoryId"></param>
    /// <returns></returns>
    public DataSet CategoryByCid(int categoryId)
    {
        DataSet ds = new DataSet();
        SqlConnection con = ConSql.ConnectionSql();
        SqlDataAdapter sdr = new SqlDataAdapter();
        sdr.SelectCommand = new SqlCommand();   //创建数据适配集的SelectCommand对象
        sdr.SelectCommand.CommandText = "select * from Category where categoryId=@categoryId ";
        sdr.SelectCommand.Parameters.Add("@categoryId", SqlDbType.Int).Value = categoryId;
        sdr.SelectCommand.Connection = con; //直接调用数据库连接对象
        sdr.Fill(ds, "CategoryByCidTable");  //填充数据集ds，表名为CategoryByCidTable
        return ds;  //返回数据集
    }

    /// <summary>
    /// 删除商品类别
    /// </summary>
    /// <param name="categoryId"></param>
    public string DeleteCategory(int categoryId)
    {
        string message = "";
        SqlConnection con = ConSql.ConnectionSql();
        SqlCommand cmd = new SqlCommand();                           //创建SqlCommand对象
        cmd.Connection = con;
        cmd.CommandText = "delete from category where categoryId=@categoryId ";//修改记录SQL语句
        cmd.Parameters.Add("@categoryId", SqlDbType.Int).Value = categoryId;
        try
        {
            con.Open();            //打开数据库
            if (cmd.ExecuteNonQuery() > 0)              //执行SQL语句
            {
                message = "删除成功";
            }
            else
            {
                message = "删除失败";
            }
        }
        catch
        {
            message = "数据库出错";
        }
        finally
        {
            con.Close();      //关闭数据库
        }
        return message;
    }
    
    
    
   
}
