• 大小: 296KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-26
  • 语言: C#
  • 标签: C#  拼音  模糊查询  简码  

资源简介

C#实现拼音模糊查询,可只输入一个字母就可查询出完整的字段

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using NPinyin;

namespace pingyin
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        List list = new List();
        List listPinyin = new List();
        List listHanZi= new List();

        Dictionary dictionaryJianMa = new Dictionary();
        Dictionary dictionaryQuanPing = new Dictionary();
        Dictionary dictionaryHanZi= new Dictionary();

        private void Form1_Load(object sender EventArgs e)
        {
            using (SqlConnection sqlcon = new SqlConnection(“Data Source=192.168.1.121;Initial Catalog=BPMEF_TEST;uid=sa;pwd=bfeit“))
            {
                string strSQL = @“select title from Sys_Dics“;

                SqlCommand vCommand = new SqlCommand(strSQL sqlcon);
                SqlDataAdapter vDa = new SqlDataAdapter(vCommand);
                DataSet vDs = new DataSet();
                vDa.Fill(vDs);
               
               foreach (DataRow dr in vDs.Tables[0].Rows)
               {
                   listHanZi.Add(dr[0].ToString());
               }

               Encoding gb2312 = Encoding.GetEncoding(“GB2312“);

               foreach (string str in listHanZi)
                {
                    string py = Pinyin.GetInitials(str gb2312);

                    if (!listPinyin.Contains(py))
                    {
                        listPinyin.Add(py);

                        dictionaryJianMa.Add(py str);

                        dictionaryQuanPing.Add(Pinyin.GetPinyin(str).Replace(“ “““) str);
                    } 
                    
                }


               
            }
           
           
        }

        private void txtCustomer_TextChanged(object sender EventArgs e)
        {
           

        }

        private void button1_Click(object sender EventArgs e)
        {
            
        }

        private void textBox1_TextChanged(object sender EventArgs e)
        {
            list.Clear();
            if (textBox1.Text.Length==0)
            {
                list.Clear();
                listBox1.Items.Clear();
                return;
            }
            listBox1.Visible = false;
            var queryJM = (from c in dictionaryJianMa where c.Key.Contains(textBox1.Text.ToUpper()) select c).ToList();
            var queryQP = (from c in dictionaryQuanPing where c.Key.Contains(textBox1.Text) select c).ToList();
            var queryHZ = (from c in listHanZi where c.Contains(textBox1.Text) select c).ToList();

            if (queryJM.C

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      68608  2012-07-24 11:11  pingyin\NPinyin.dll

     文件      68608  2012-07-24 11:11  pingyin\pingyin\bin\Debug\NPinyin.dll

     文件      12800  2013-12-31 17:04  pingyin\pingyin\bin\Debug\pingyin.exe

     文件      26112  2013-12-31 17:04  pingyin\pingyin\bin\Debug\pingyin.pdb

     文件      11600  2013-12-31 17:04  pingyin\pingyin\bin\Debug\pingyin.vshost.exe

     文件        490  2010-03-17 22:39  pingyin\pingyin\bin\Debug\pingyin.vshost.exe.manifest

     文件       5308  2013-12-31 17:04  pingyin\pingyin\Form1.cs

     文件       3541  2013-12-31 16:41  pingyin\pingyin\Form1.Designer.cs

     文件       5817  2013-12-31 16:41  pingyin\pingyin\Form1.resx

     文件       2152  2013-12-31 15:21  pingyin\pingyin\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6354  2013-12-31 17:04  pingyin\pingyin\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        252  2013-12-31 16:41  pingyin\pingyin\obj\x86\Debug\GenerateResource.read.1.tlog

     文件        602  2013-12-31 16:41  pingyin\pingyin\obj\x86\Debug\GenerateResource.write.1.tlog

     文件        971  2013-12-31 17:04  pingyin\pingyin\obj\x86\Debug\pingyin.csproj.FileListAbsolute.txt

     文件      12800  2013-12-31 17:04  pingyin\pingyin\obj\x86\Debug\pingyin.exe

     文件        180  2013-12-31 16:41  pingyin\pingyin\obj\x86\Debug\pingyin.Form1.resources

     文件      26112  2013-12-31 17:04  pingyin\pingyin\obj\x86\Debug\pingyin.pdb

     文件        180  2013-12-31 15:43  pingyin\pingyin\obj\x86\Debug\pingyin.Properties.Resources.resources

     文件       9226  2013-12-31 15:43  pingyin\pingyin\obj\x86\Debug\ResolveAssemblyReference.cache

     文件       3769  2013-12-31 15:43  pingyin\pingyin\pingyin.csproj

     文件        488  2013-12-31 15:21  pingyin\pingyin\Program.cs

     文件       1370  2013-12-31 15:21  pingyin\pingyin\Properties\AssemblyInfo.cs

     文件       2864  2013-12-31 15:21  pingyin\pingyin\Properties\Resources.Designer.cs

     文件       5612  2013-12-31 15:21  pingyin\pingyin\Properties\Resources.resx

     文件       1092  2013-12-31 15:21  pingyin\pingyin\Properties\Settings.Designer.cs

     文件        249  2013-12-31 15:21  pingyin\pingyin\Properties\Settings.settings

     文件        863  2013-12-31 15:21  pingyin\pingyin.sln

    ..A..H.     22528  2013-12-31 17:04  pingyin\pingyin.suo

     目录          0  2013-12-31 15:21  pingyin\pingyin\obj\x86\Debug\TempPE

     目录          0  2013-12-31 17:04  pingyin\pingyin\obj\x86\Debug

............此处省略10个文件信息

评论

共有 条评论