Exemplo n.º 1
0
    private void GetList(string keyword)
    {
        string content = "";

        if (!String.IsNullOrEmpty(keyword))
        {
            ResultDataSet Rs  = drugInfo.GetList(keyword);
            ResultDataSet Rs2 = drugInfo.GetList_C(keyword);
            if (Rs.RowCount > 0)
            {
                for (int i = 0; i < Rs.RowCount; i++)
                {
                    content += "<h4><a href=\"SearchDetail.aspx?id=" + Rs[i, "id"] + "\">" + Rs[i, "药品名称"] + "(" + Rs[i, "规格"] + ")-西药</a></h4>" +
                               "<li>适应症:" + Rs[i, "适应症"] + "</li>";
                }
                Label1.Text = Rs.RowCount + "条搜索结果";
            }
            else if (Rs2.RowCount > 0)
            {
                for (int i = 0; i < Rs2.RowCount; i++)
                {
                    content += "<h4><a href=\"SearchDetail.aspx?ids=" + Rs2[i, "ids"] + "\">" + Rs2[i, "药品名称"] + "(" + Rs2[i, "规格"] + ")-中药</a></h4>" +
                               "<li>功效:" + Rs2[i, "功效"] + "</li>" +
                               "<li>应用:" + Rs2[i, "应用"] + "</li>";
                }
                Label1.Text = Rs2.RowCount + "条搜索结果";
            }
            else
            {
                Label1.Text = "暂无相应药品";
            }
            ul.InnerHtml = content;
        }
    }
Exemplo n.º 2
0
    public String[] GetCompleteDepart(string prefixText, int count)
    {
        DrugInfo drugInfo = new DrugInfo();

        ///检测参数是否为空
        if (string.IsNullOrEmpty(prefixText) == true || count <= 0)
        {
            return(null);
        }
        // 如果数组为空
        if (autoCompleteWordList == null)
        {
            //string sql = "select top 10.药品名称 from DrugInfo where 药品名称 like'" + prefixText + "%'";
            //ResultDataSet Rs = new ResultDataSet();
            //db.DB4Obj.GetRs(sql, out Rs);

            ResultDataSet Rs   = drugInfo.GetList(prefixText);
            ResultDataSet Rs2  = drugInfo.GetList_C(prefixText);
            string[]      temp = null;
            if (Rs.RowCount > 0 || Rs2.RowCount > 0)
            {
                DataSet ds  = ((DataSet)Rs);
                DataSet ds2 = ((DataSet)Rs2);
                ds.Merge(ds2);
                //读取数据库的内容
                //OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("Ex18_02.mdb"));
                //conn.Open();
                //OleDbDataAdapter da = new OleDbDataAdapter("select keyName from keyInfo where keyName like'" + prefixText + "%' order by keyName", conn);
                //DataSet ds = new DataSet();
                //da.Fill(ds);
                //读取内容文件的数据到临时数组
                temp = new string[ds.Tables[0].Rows.Count];
                int i = 0;
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    temp[i] = dr["药品名称"].ToString();
                    i++;
                }
                Array.Sort(temp, new CaseInsensitiveComparer());
                //将临时数组的内容赋给返回数组
                autoCompleteWordList = temp;
                //if (conn.State == ConnectionState.Open)
                //    conn.Close();
            }
            //中药
            //ResultDataSet Rs2 = drugInfo.GetList_C(prefixText);
            //string[] temp2 = null;
            //if (Rs2.RowCount > 0)
            //{
            //    DataSet ds2 = ((DataSet)Rs2);
            //    temp2 = new string[ds2.Tables[0].Rows.Count];
            //    int j = 0;
            //    foreach (DataRow dr in ds2.Tables[0].Rows)
            //    {
            //        temp2[j] = dr["药品名称"].ToString();
            //        j++;
            //    }
            //    Array.Sort(temp2, new CaseInsensitiveComparer());
            //}
            //string[] s3 = new string[temp.Length + temp2.Length];
            //Array.Copy(temp, 0, s3, 0, temp.Length);
            //Array.Copy(temp2, 0, s3, temp.Length, temp2.Length);
            //autoCompleteWordList = s3;
        }
        //定位二叉树搜索的起点
        int index = Array.BinarySearch(autoCompleteWordList, prefixText, new CaseInsensitiveComparer());

        if (index < 0)
        { //修正起点
            index = ~index;
        }
        //搜索符合条件的数据
        int matchCount = 0;

        for (matchCount = 0; matchCount < count && matchCount + index < autoCompleteWordList.Length; matchCount++)
        { ///查看开头字符串相同的项
            if (autoCompleteWordList[index + matchCount].StartsWith(prefixText, StringComparison.CurrentCultureIgnoreCase) == false)
            {
                break;
            }
        }
        //处理搜索结果
        string[] matchResultList = new string[matchCount];
        if (matchCount > 0)
        { //复制搜索结果
            Array.Copy(autoCompleteWordList, index, matchResultList, 0, matchCount);
        }
        return(matchResultList);
    }