using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.OleDb;
using System.Text;
using System.Windows.Forms;
using System.Collections;
namespace ICD_search
{
public partial class UserControl1 : UserControl
{
private OleDbCommand Cmd;
private OleDbDataReader Dr;
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Environment.CurrentDirectory + "\\icd-full.mdb";
private OleDbConnection Conn;
public UserControl1()
{
InitializeComponent();
}
private void UserControl1_Load(object sender, EventArgs e)
{
Conn = new OleDbConnection(strConn);
this.Conn.Open();
Cmd = Conn.CreateCommand();
Cmd.CommandText = "select * from icdcode where icdcode like '___'";
Dr = Cmd.ExecuteReader();
while (Dr.Read())
{
treeView1.Nodes.Add(Dr.GetString(1) + Dr.GetString(2));
}
Dr.Close();
//从数据库中读取数据,通过递归生成树。
}
private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (textBox1.Text.Length == 3)//暂时只显示二级结点
{
if (e.Node.Nodes.Count == 0 && e.Node.Level != 2)//是否展开树节点的判断
{
string Sxuanzhong = treeView1.SelectedNode.Text.ToString().Substring(0, 3);
Cmd.CommandText = "select * from icdcode where icdcode like '" + Sxuanzhong + "._'";
Dr = Cmd.ExecuteReader();
while (Dr.Read())
{
e.Node.Nodes.Add(Dr.GetString(1) + Dr.GetString(2));
}
Dr.Close();
}
}
else
{
if (e.Node.Nodes.Count == 0&&e.Node.Level != 2)//显示三级结点
{
string Sxuanzhong = treeView1.SelectedNode.Text.ToString().Substring(0, 5);
Cmd.CommandText = "select * from icdcode where icdcode like '" + Sxuanzhong + "%'";
Dr = Cmd.ExecuteReader();
while (Dr.Read())
{
e.Node.Nodes.Add(Dr.GetString(1) + Dr.GetString(2));
}
Dr.Close();
}
}
}
void jiansuotestbox1()
{
int intlengthString = treeView1.SelectedNode.Text.ToString().Length;
string Sxuanzhong=treeView1.SelectedNode.Text.ToString();
char[] Cshuzu = Sxuanzhong.ToCharArray();
byte[] myArrayByte = System.Text.Encoding.ASCII.GetBytes(Cshuzu);
for (int i = 0; i < Sxuanzhong.Length; i++)
{
if ((48 <= myArrayByte[i] && myArrayByte[i] <= 57) || (65 <= myArrayByte[i] && myArrayByte[i] <= 90) || myArrayByte[i] == 46 || myArrayByte[i] == 43)
textBox1.Text += Cshuzu[i].ToString();
}
}
void jiansuotestbox2()
{
int intlengthString = treeView1.SelectedNode.Text.ToString().Length;
string Sxuanzhong = treeView1.SelectedNode.Text.ToString();
char[] Cshuzu = Sxuanzhong.ToCharArray();
byte[] myArrayByte = System.Text.Encoding.ASCII.GetBytes(Cshuzu);
for (int i = 0; i < Sxuanzhong.Length; i++)
{
if (!((48 <= myArrayByte[i] && myArrayByte[i] <= 57) || (65 <= myArrayByte[i] && myArrayByte[i] <= 90) || myArrayByte[i] == 46 || myArrayByte[i] == 43))
textBox2.Text += Cshuzu[i].ToString();
}
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
textBox1.Clear();
jiansuotestbox1();
textBox2.Clear();
jiansuotestbox2();
}
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
}
}
}