(300分)请指教如何实现类似迅雷淘宝那样的拼音检索(c#,asp.net)(200分)

Z

zn41

Unregistered / Unconfirmed
GUEST, unregistred user!
如题,希望能提供源码,谢谢!搞定后另行送分!
 
Y

yinju

Unregistered / Unconfirmed
GUEST, unregistred user!
// 获取指定汉字的拼音索引字母,如:“汉”的索引字母是“H”
function GetPYIndexChar( hzchar:string):char;
begin

case WORD(hzchar[1]) shl 8 + WORD(hzchar[2]) of
$B0A1..$B0C4 : result := 'A';
$B0C5..$B2C0 : result := 'B';
$B2C1..$B4ED : result := 'C';
$B4EE..$B6E9 : result := 'D';
$B6EA..$B7A1 : result := 'E';
$B7A2..$B8C0 : result := 'F';
$B8C1..$B9FD : result := 'G';
$B9FE..$BBF6 : result := 'H';
$BBF7..$BFA5 : result := 'J';
$BFA6..$C0AB : result := 'K';
$C0AC..$C2E7 : result := 'L';
$C2E8..$C4C2 : result := 'M';
$C4C3..$C5B5 : result := 'N';
$C5B6..$C5BD : result := 'O';
$C5BE..$C6D9 : result := 'P';
$C6DA..$C8BA : result := 'Q';
$C8BB..$C8F5 : result := 'R';
$C8F6..$CBF9 : result := 'S';
$CBFA..$CDD9 : result := 'T';
$CDDA..$CEF3 : result := 'W';
$CEF4..$D188 : result := 'X';
$D1B9..$D4D0 : result := 'Y';
$D4D1..$D7F9 : result := 'Z';
else

result := char(0);
end;

end;

300分拿来
 
S

scxujie

Unregistered / Unconfirmed
GUEST, unregistred user!
$CEF4..$D188 : result := 'X';应为
$CEF4..$D1B8 : result := 'X';
呵呵,抄来抄去的也没人改正过来
 
Z

zpj86

Unregistered / Unconfirmed
GUEST, unregistred user!
呵呵,此贴有用,留个记号
 
Z

zn41

Unregistered / Unconfirmed
GUEST, unregistred user!
不是delphi的代码,要asp.net的c#代码,好像要用到ajax技巧吧,麻烦提供个源码,谢谢
 
T

tempting

Unregistered / Unconfirmed
GUEST, unregistred user!
protected void Page_Load(object sender, EventArgs e)
{
conn = new SqlConnection("server=.//Sql2005;database=autodemo;uid=sa;pwd=sa");
}
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{


conn.Open();
string sql = "select address from address where addresspinyin like '" + getPinYin(prefixText)+ "%'";
SqlDataAdapter da = new SqlDataAdapter(sql,conn);
DataSet ds = new DataSet();
da.Fill(ds);
conn.Close();
int i = 0;
string[] temp = new string[ds.Tables[0].Rows.Count];
foreach (DataRow dr in ds.Tables[0].Rows)
{
temp = dr[0].ToString();
i++;
}
return temp;
}
private static string getPinYin(string text)
{
char pinyin;
byte[] array;
System.Text.StringBuilder sb = new System.Text.StringBuilder(text.Length);
foreach (char c in text)
{
pinyin = c;
array = System.Text.Encoding.Default.GetBytes(new char[] { c });
if (array.Length == 2)
{
int i = array[0] * 0x100 + array[1];
if (i < 0xB0A1) pinyin = c;
else
if (i < 0xB0C5) pinyin = 'a';
else
if (i < 0xB2C1) pinyin = 'b';
else
if (i < 0xB4EE) pinyin = 'c';
else
if (i < 0xB6EA) pinyin = 'd';
else
if (i < 0xB7A2) pinyin = 'e';
else
if (i < 0xB8C1) pinyin = 'f';
else
if (i < 0xB9FE) pinyin = 'g';
else
if (i < 0xBBF7) pinyin = 'h';
else
if (i < 0xBFA6) pinyin = 'g';
else
if (i < 0xC0AC) pinyin = 'k';
else
if (i < 0xC2E8) pinyin = 'l';
else
if (i < 0xC4C3) pinyin = 'm';
else
if (i < 0xC5B6) pinyin = 'n';
else
if (i < 0xC5BE) pinyin = 'o';
else
if (i < 0xC6DA) pinyin = 'p';
else
if (i < 0xC8BB) pinyin = 'q';
else
if (i < 0xC8F6) pinyin = 'r';
else
if (i < 0xCBFA) pinyin = 's';
else
if (i < 0xCDDA) pinyin = 't';
else
if (i < 0xCEF4) pinyin = 'w';
else
if (i < 0xD1B9) pinyin = 'x';
else
if (i < 0xD4D1) pinyin = 'y';
else
if (i < 0xD7FA) pinyin = 'z';
}
sb.Append(pinyin);
}
return sb.ToString();
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("server=.//Sql2005;database=autodemo;uid=sa;pwd=sa");
conn.Open();
string sql = "insert into address(address,addresspinyin) values('"+this.TextBox2.Text+"','"+getPinYin(this.TextBox2.Text)+"')";
SqlCommand cmd = new SqlCommand(sql,conn);
cmd.ExecuteNonQuery();
this.TextBox2.Text = "";
conn.Close();
}
 
Z

zn41

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
592
import
I
I
回复
0
查看
594
import
I
顶部