.net下用c# 编写成语字典查询工具

呵呵,以前弄的一个成语字典数据库.最近用C#写了个查询工具.

界面:

 

源代码如下:

 

// http://blog.csdn.net/greenerycn
// 请遵守署名非商业的CC版权.

using  System;
using  System.Collections.Generic;
using  System.ComponentModel;
using  System.Data;
using  System.Drawing;
using  System.Text;
using  System.Windows.Forms;
using  System.Data.OleDb;

namespace  CyDict
{
    
public partial class Form1 : Form
    
{
        
public Form1()
        
{
            InitializeComponent();
        }


        
private void Form1_Load(object sender, EventArgs e)
        
{


            
this.reportViewer1.RefreshReport();
        }


        
private void button1_Click(object sender, EventArgs e)
        
{
           
//连接数据库
            string con_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=cy.mdb";
          
//sql语句
            string sql_str = "SELECT * FROM [cy] WHERE ([成语]=@cy_name)";
            OleDbConnection db_conn 
= new OleDbConnection(con_str);
            db_conn.Open();
            OleDbCommand cm
=new OleDbCommand (sql_str,db_conn);
            cm.Parameters.Add(
new OleDbParameter("@cy_name",OleDbType.Variant,4));
            cm.Parameters[
"@cy_name"].Value=txt_input.Text.Trim();
           
//查询数据库
            OleDbDataReader reader=cm.ExecuteReader();
            
if (reader.Read())
            
{
                
string[] result = new string[9];
                result[
0= "成语: " + reader["成语"].ToString();
                result[
2= "解释: " + reader["解释"].ToString();
                result[
1= "拼音: " + reader["拼音"].ToString();
                result[
3= "近义: " + reader["近义"].ToString();
                result[
4= "反义: " + reader["反义"].ToString();
                result[
5= "出处: " + reader["出处"].ToString();
                result[
7= "示例: " + reader["示例"].ToString();
                result[
6= "典故: " + reader["典故"].ToString();
                txt_Result.Lines 
= result;
            }

            
else
            
{
                txt_Result.Text 
= "无此成语,本词典收录数据6000条!";
            }

           
//不要忘了关闭.
            reader.Close();
            db_conn.Close();

        }


    }

}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
namespace CYBrowse { #region DateFileHeadStruct /// <summary> /// Defines head struct to read the date file. /// </summary> public struct TagIdiomLibraryHead { public string idiomFlag; //6 byte public int idiomLength; //4 byte public int idiomCount; //3 byte public int[] idiomPositon; //3 byte } #endregion DateFileHeadStruct #region ListViewColumnNameEnum enum ListViewColumnName { ColumnIdiom = 0,//成语 ColumnCode = 1,//拼音简码 ColumnRecordNumber = 2//编号 }; #endregion ListViewColumnNameEnum /// <summary> /// Defines the idiom dictionary main form. /// </summary> public partial class IdiomDictionary : Form { /// <summary> /// The max length of an idiom. /// </summary> const int idiomMaxLength = 36; public const string helpFileName = @"\ReadMe.txt"; /// <summary> /// Declares the idiom dictionary set. /// </summary> public IdiomDictionarySet idiomDictionarySet; /// <summary> /// The index table constructed by the first word in each idiom. /// </summary> public char[] firstWordConstructedIndexTable; /// <summary> /// Represents the index table's count. /// </summary> public int firstWordConstructedIndexTableCount; #region Constructor public IdiomDictionary() { idiomDictionarySet = new IdiomDictionarySet(); InitializeComponent(); } #endregion Constructor /// <summary> /// Invokes this method when IdiomDictionary Form loads. /// </summary> private void IdiomDictionaryLoad(object sender, EventArgs e) { idiomDictionarySet.SetIdiomLibraryBuffer(); firstWordConstructedIndexTable = new char[idiomDictionarySet.idiomLibraryHead.idiomCount]; firstWordConstructedIndexTableCount = 0; listView.Columns.Add("成语",180); listView.Columns.Add("拼音简码", 80); listView.Columns.Add("编号", 60); listView.Sorting = SortOrder.Ascending; listView.BeginUpdate(); for (int i = 0; i < idiomDictionarySet.idiomLibraryHead.idiomCount; i++) { ListViewItem listViewItem= new ListViewItem(); idiomDictionarySet.Move(i); listViewItem.SubItems.Clear(); listViewItem.SubItems[0].Text = (string)idiomDictionarySet.m_CM.Clone(); listViewItem.SubItems.Add(idiomDictionarySet.m_PYCODE); listViewItem.Tag = i; listView.Items.Add(listViewItem); } comboBoxFirst.BeginUpdate(); for (int i = 0; i < idiomDictionarySet.idiomLibraryHead.idiomCount; i++) { listView.Items[i].SubItems.Add((i + 1).ToString()); char ch = listView.Items[i].SubItems[0].Text[0]; if (firstWordConstructedIndexTableCount == 0 || firstWordConstructedIndexTable[firstWordConstructedIndexTableCount - 1] != ch) { firstWordConstructedIndexTable[firstWordConstructedIndexTableCount] = ch; comboBoxFirst.Items.Add(ch); firstWordConstructedIndexTableCount++; } }

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值