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.OleDb;
using System.Collections.Generic;
/// <summary>
/// DB 的摘要说明
/// </summary>
public class DB
{
	public DB()
	{
	    
	}

    private OleDbConnection getcon()
    {
        try
        {
            string connStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|microsoftDLLImport.dll;Persist Security Info=True;Jet OLEDB:Database Password=@#$sa%%$#@; mode=share exclusive;";
            //以独占方式打开 有密码的数据库 www.5has.com 
            OleDbConnection conn = new OleDbConnection(connStr);
            return conn;
        }
        catch (Exception ex)
        {
            throw new Exception("数据库连接错误！" + ex.Message);
        }
    }


    #region 查询维汉部分
    public string GetUy2Ch(string word)
    {
        OleDbConnection con = null;
        try
        {
            con = getcon();
            if (con == null)
            {
                throw new Exception("Con is Null");
            }
            if (con.State != ConnectionState.Open)
            {
                con.Open();
            }
            ///开始查找
            ///
            string sql = "Select  * From [uyhan] where [uy]  like'"+word.Trim()+"'";
            OleDbDataAdapter adp = new OleDbDataAdapter(sql,con);
            DataTable dt = new DataTable();
            adp.Fill(dt);
            if (dt.Rows.Count == 0)
            {
                con.Close();
                throw new Exception("مۇناسىۋەرلىك سۆز تېپىلمىدى...");
            }
            else
            {
                con.Close();
                return dt.Rows[0]["han"].ToString();
            }
        }
        catch (Exception ex)
        {
            if (con != null)
            con.Close();
            throw new Exception(ex.Message);
        }
    }
    #endregion

    #region 查询汉维部分
    public string GetCh2Uy(string word)
    {
        OleDbConnection con = null;
        try
        {
            con = getcon();
            if (con == null)
            {
                throw new Exception("Con is Null");
            }
            if (con.State != ConnectionState.Open)
            {
                con.Open();
            }
            ///开始查找
            ///
            string sql = "Select  * From [hanuy] where [han]  like'" + word.Trim() + "'";
            OleDbDataAdapter adp = new OleDbDataAdapter(sql,con);
            DataTable dt = new DataTable();
            adp.Fill(dt);
            if (dt.Rows.Count == 0)
            {
                con.Close();
                throw new Exception("مۇناسىۋەرلىك سۆز تېپىلمىدى...");
            }
            else
            {
                con.Close();
                return dt.Rows[0]["uy"].ToString();
            }
        }
        catch (Exception ex)
        {
            if(con!=null)
            con.Close();
            throw new Exception(ex.Message);
        }
    }
    #endregion


}
