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

using System.Data.SqlClient;

/// <summary>
/// DataBaseConnection 的摘要说明
/// </summary>
public class DataBaseConnection
{
    private SqlConnection sqlConn;
    private SqlCommand sqlCmd;

	public DataBaseConnection()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}

    public void Open(string sqlConStr)
    {
        this.sqlConn = new SqlConnection(sqlConStr);
        if (this.sqlConn.State == ConnectionState.Closed)
        {
            this.sqlConn.Open();
        }
    }

    public void Close()
    {
        this.sqlConn.Close();
    }

    private bool IsExists(string insertTxt)
    {
        this.sqlCmd = new SqlCommand(insertTxt, this.sqlConn);
        if (this.sqlCmd.ExecuteScalar() != null)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    public int Insert(string insertTxt)
    {
        this.sqlCmd = new SqlCommand(insertTxt, this.sqlConn);
        return this.sqlCmd.ExecuteNonQuery();
    }

    public bool CheckData(string table, string where, string what)
    {
        string insertTxt = "SELECT " + where + " FROM " + table + " WHERE " + where + " = " + "'" + what + "'";
        return this.IsExists(insertTxt);
    }
}
