using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
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;

/// <summary>
/// DbManager 的摘要说明
/// </summary>
public class DbManager
{
    private static string strConn = "Server=localhost\\SQLEXPRESS;Database=bbs;Integrated Security=True";
    private static SqlConnection conn;
    public DbManager()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    public static SqlCommand getCommand()
    {
        openConnection();
        SqlCommand comm = new SqlCommand();
        comm.Connection = conn;
        return comm;
    }
    public static SqlCommand getCommand(string sql)
    {
        openConnection();
        SqlCommand comm = new SqlCommand(sql, conn);
        return comm;
    }
    public static DataSet getDataSet(string sql, string dbName)
    {
        openConnection();
        DataSet myDataSet = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(sql, conn);
        da.Fill(myDataSet, dbName);
        return myDataSet;
    }
    public static SqlDataReader getReader(string sql)
    {
        SqlCommand myComm = getCommand(sql);
        return myComm.ExecuteReader();
    }
    public static int getNonQuery(string sql)
    {
        SqlCommand comm = getCommand();
        comm.CommandText = sql;
        return comm.ExecuteNonQuery();
    }
    public static void closeConnection()
    {
        if(conn.State==ConnectionState.Open)
            conn.Close();
    }
    public static void openConnection()
    {
        if (conn == null)
            conn = new SqlConnection(strConn);
        if (conn.State == ConnectionState.Closed)
            conn.Open();
    }

}
