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.OleDb;

/// <summary>
///oper 的摘要说明
/// </summary>
public class oper
{
	public oper()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}
    public static OleDbConnection createconn()
    {
        //access数据库连接
        return new OleDbConnection(ConfigurationManager.AppSettings["acon"]);
    }
    public static DataTable dt(string query)
    {
        //根据查询，返回一个DataTable结果集
        OleDbConnection con = oper.createconn();
        OleDbDataAdapter oda = new OleDbDataAdapter(query, con);
        DataSet ds = new DataSet();
        oda.Fill(ds, "anounce");
        return ds.Tables["anounce"];       
    }
    public static string findstr(string query)
    {
        //返回查询字符串--Execute方式必须显性打开数据库链接
        OleDbConnection con = oper.createconn();
        using (con)
        {
            con.Open();
            OleDbCommand ocmd = new OleDbCommand(query, con);
            return ocmd.ExecuteScalar().ToString();
        }
    }
    public static bool isfind(string acountstr)
    {
        //判断数据项是否存在
        OleDbConnection con = oper.createconn();
        using (con)
        {
            con.Open();
            OleDbCommand ocmd = new OleDbCommand(acountstr, con);
            int count = Convert.ToInt32(ocmd.ExecuteScalar());
            if (count > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
    public static DataRow dr(string query)
    {
        //返回一行记录
        OleDbConnection con = oper.createconn();
        OleDbDataAdapter sda = new OleDbDataAdapter(query, con);
        DataSet ds = new DataSet();
        sda.Fill(ds, "anounce");
        return ds.Tables["anounce"].Rows[0];       
    }
    public static void opertb(string insertstr)
    {
        //用于添加、修改、删除记录
        OleDbConnection con = oper.createconn();
        using (con)
        {
            con.Open();
            OleDbCommand cmd = new OleDbCommand(insertstr, con);
            cmd.ExecuteNonQuery();
        }
    }
    public static string mess(string mess)
    {
        return "<script language='javascript'>alert('" + mess + "');window.location.href=document.URL;</script>";
    }
}
