Tuesday, January 26, 2010

Dicts.cs

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 Spaces;
using System.Text.RegularExpressions;

///
/// Dicts 的摘要说明
///

public class Dicts
{
public Dicts()
{

}
public static bool IsCN(string strIn)
{
return Regex.IsMatch(strIn, "[\u4E00 - \u9FA0]+ ");
}


const string CacheEntityKey="dict_entity_hashtable";
public static string KeyToValue(string key)
{
CacheEntity dict = new CacheEntity(CacheEntityKey);
return dict[key];
}
public static void AddValue(string key, string value)
{
CacheEntity dict = new CacheEntity(CacheEntityKey);
dict.Add(key, value);

}
///
/// 获取格言
///

///
///
public static string GetMaxim(string Source)
{
string str = Utils.SqlInput(Source);
string key = string.Format("en_Maxim_{0}",str);
string outValue = KeyToValue(key);
if (!string.IsNullOrEmpty(outValue))
return outValue;

string strSQL = "SELECT top 1 detaile FROM [en_maxim] WHERE (detaile LIKE '%" + str + "%')";

try
{
outValue = SpacesDataProvider.Instance().ExecuteScalar(strSQL).ToString();
AddValue(key, outValue);
return outValue;
}
catch
{
return "";
}
}
public static DataView GetEnWord(string Source)
{
string str = Utils.SqlInput(Source);

string key=string.Format("en_enword_{0}",str);
DataView dv=IFCache.Get(key) as DataView;
if (dv == null)
{
string strSQL = "select top 3 * from en_dictEC where source='" +str + "'";
dv = SpacesDataProvider.Instance().GetDataView(strSQL);
IFCache.Insert(key, dv, 6000);
}
return dv;
}

public static DataView GetCnWord(string Source)
{

string str = Utils.SqlInput(Source);

string key = string.Format("en_cnword_{0}", str);
DataView dv = IFCache.Get(key) as DataView;
if (dv == null)
{
string strSQL = "select top 3 * from en_dictCE where source='" + str + "'";
dv = SpacesDataProvider.Instance().GetDataView(strSQL);
IFCache.Insert(key, dv, 6000);
}
return dv;
}





public static DataRow GetSentsCE(string Scan, string Source)
{
string str = Utils.SqlInput(Source);

string key = string.Format("en_SentsCE_{0}", str);

DataRow dr = IFCache.Get(key) as DataRow;
if (dr == null)
{
string strSQL = "SELECT top 1 * FROM en_SentsCE WHERE (" + Scan + " LIKE '%" + str + "%')";
dr = SpacesDataProvider.Instance().GetDataRow(strSQL);
if (dr == null)
dr = new DataTable().NewRow();
IFCache.Max(key, dr);
}
return dr;
}



public static string GetSentence(string Source)
{
string str = Utils.SqlInput(Source);
string key = string.Format("en_n1000_{0}", str);
string outValue = KeyToValue(key);
if (!string.IsNullOrEmpty(outValue))
return outValue;

string strSQL = "SELECT top 1 detaile FROM en_n1000 WHERE (detaile LIKE '%" + str + "%')";

try
{
outValue = SpacesDataProvider.Instance().ExecuteScalar(strSQL).ToString();
AddValue(key, outValue);
return outValue;
}
catch
{
return "";
}
}






}

No comments:

Post a Comment