⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dict.cs

📁 用中文Wordnet开发的一个智能搜索引擎
💻 CS
字号:
///////////////////////////////////////////////////////
//                                                   //                                     
//      宁夏大学   张冬 康彩      2006.6             //    
//                                                   //
//      LGPL  许可发行    Email: zd4004@163.com      //
//                                                   //
//     部分资料来自互联网 鉴定来源较困难             //
//     如有不妥之处请立刻联系我们                    //
///////////////////////////////////////////////////////

using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Drawing;

namespace WindowsDCITClientX
{
	public partial class dict : Form
	{

		 public delegate void Mylabel2(string text);
     	 public delegate void MylistBox2(string text);
		 public delegate void MylistBox3(string text);
     	 public delegate void MytextBoxM(string text);
     	 public delegate void MyClistBox2(string text);
		 public delegate void MyClistBox3(string text);
    	 public delegate void MylistBox1(string text);


		private const int WM_NCHITTEST = 0x84;
		private const int HTCLIENT = 0x1;
		private const int HTCAPTION = 0x2;

		//服务的地址参数
		public  string serviceIP = "";

		//服务说明
		public string serviceReadme = "";

		public string server = "";

		protected override void WndProc(ref Message m)
		{
			switch (m.Msg)
			{
				case WM_NCHITTEST:
					base.WndProc(ref m);
					if ((int)m.Result == HTCLIENT)
						m.Result = (IntPtr)HTCAPTION;
					return;
					break;
			}
			base.WndProc(ref m);
		} 


		 public void ClistBox2(string text)
         {
            listBox2.Items.Clear() ;

         }

		 public void ApplistBox1(string text)
         {
            listBox1.Items.Add (text);
         }

	     public void ClistBox3(string text)
         {
           listBox3.Items.Clear();
         }


		 public void Applabel2(string text)
         {
            label2.Text = text;
         }

		 public void ApplistBox2(string text)
         {
            listBox2.Items.Add (text);
         }

	     public void ApplistBox3(string text)
         {
           listBox3.Items.Add (text);
         }

		 public void ApptextBoxM(string text)
         {
            textBoxM.Text = text;
         }






		public dict()
		{
			InitializeComponent();
		}

		private void dict_Load(object sender, EventArgs e)
		{


			
		}

		public void SysDataSet()
		{

			//资源节点参数
			textBox2.Text = serviceReadme;
			textBox3.Text = serviceIP;

		}

		private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
		{
			
		}

		public bool SetSerIP(string mSerIP)
		{

			textBox2.Text = mSerIP;

			return true;
		}

		private void button1_Click(object sender, EventArgs e)
		{
			server = serviceIP;
			//server = textBox2.Text.ToString();

			Thread T1 = new Thread(new ThreadStart(ConnectM));


			T1.Start();

			//ConnectM();
			//timer1.Interval = 100;
			//timer1.Enabled = true;
			

		}



		public void ConnectM()
		{

			
			String message;

			//server = "202.201.128.55";

			message = textBox1.Text + (char)13 + (char)10;

			//Thread.Sleep(10);

			try
			{
				// Create a TcpClient.
				// Note, for this client to work you need to have a TcpServer 
				// connected to the same address as specified by the server, port
				// combination.
				Int32 port = 6060;
				TcpClient client = new TcpClient(server, port);


				Encoding gbx=System.Text.Encoding.GetEncoding("gb2312"); 

				// Translate the passed message into ASCII and store it as a Byte array.
				//Byte[] data = System.Text.Encoding.ASCII.GetBytes(message);
				Byte[] data = gbx.GetBytes(message);
				
//object[] bytes=gb.Encoding.GetBytes ("好"); 




				// Get a client stream for reading and writing.
				//  Stream stream = client.GetStream();

				NetworkStream stream = client.GetStream();
				
				//label2.Text = "Search...";
				// Send the message to the connected TcpServer. 
				stream.Write(data, 0, data.Length);

				//Console.WriteLine("Sent: {0}", message);

				// Receive the TcpServer.response.

				// Buffer to store the response bytes.
				data = new Byte[1024];

				// String to store the response ASCII representation.
				String responseData = String.Empty;

				// Read the first batch of the TcpServer response bytes.
				Int32 bytes = stream.Read(data, 0, data.Length);

				Encoding gb = System.Text.Encoding.GetEncoding("gb2312");
                
				//label2.Text = "GET  OK";
				
				responseData = gb.GetString(data, 0, bytes);
				//responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
				//Console.WriteLine("Received: {0}", responseData);
				//textBoxM.Text   = responseData;
				//showIt
				// Close everything.

			

				stream.Close();
				client.Close();

				if (responseData.IndexOf("<OneBack>") > 0)
				{
					string[] myTmppo = responseData.Split((char)9);
					textBoxM.Invoke(new MytextBoxM(ApptextBoxM), new Object[] { myTmppo[1] });

				}
				else
				{

					showItMC(responseData);
				}




			}
			catch (ArgumentNullException e)
			{
				
				//Console.WriteLine("ArgumentNullException: {0}", e);
				//label2.Text = "Close";
			}
			catch (SocketException e)
			{
				
				//Console.WriteLine("SocketException: {0}", e);
				//label2.Text = "Close";
			}

			//Console.WriteLine("\n Press Enter to continue...");
			//Console.Read();
			
		}

		private void label2_Click(object sender, EventArgs e)
		{

		}

		private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (listBox3.Text != ""  &&  listBox3.Text!=textBox1.Text ) 
			{

				textBox1.Text = listBox3.Text;
			

				Thread T1 = new Thread(new ThreadStart(ConnectM));
				T1.Start();

	
			}
		}

	
		
		private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
		{
			if (listBox1.Text != "" && listBox1.Text != textBox1.Text)
			{
				textBox1.Text = listBox1.Text;


				Thread T1 = new Thread(new ThreadStart(ConnectM));
				T1.Start();


			}
		
		
		
		}
	
	
	private void showItMC(String Data)
		{



			if (Data != "NXU_AGL_NULL")
			{


				String[] Tmp = Data.Split((char)9);
				if (Tmp[14] == "EN|CN")
				{
					//textBoxM.Text = Tmp[9];
                      textBoxM.Invoke(new MytextBoxM(ApptextBoxM),new Object[] {Tmp[9]});

					String[] TmpWord = Tmp[4].Split('|');

					//listBox2.Items.Clear();
                    listBox2.Invoke (new MyClistBox2(ClistBox2),new Object[] {"A"});


					foreach (string i in TmpWord)
					{
						if (i.ToString().Length > 0)
						{
							listBox2.Invoke (new MylistBox2(ApplistBox2),new Object[]{i.ToString()});
							//listBox2.Items.Add(i.ToString());
						}

					}

					String[] TmpPnt = Tmp[7].Split('|');

					//listBox3.Items.Clear();
					listBox3.Invoke (new MyClistBox3(ClistBox3),new Object[] {"A"});


					foreach (string i in TmpPnt)
					{
						if (i.ToString().Length > 0)
						{
							String[] TmpZH = i.ToString().Split(' ');
						//	listBox3.Items.Add(TmpZH[1]);
								listBox3.Invoke (new MylistBox3(ApplistBox3),new Object[]{TmpZH[1]});
						

						}

					}
				}
				else
				{
					// textBoxM.Text = Tmp[10];
					 textBoxM.Invoke(new MytextBoxM(ApptextBoxM),new Object[] {Tmp[10]});

					String[] TmpWord = Tmp[4].Split('|');

					//listBox2.Items.Clear();
                    listBox2.Invoke (new MyClistBox2(ClistBox2),new Object[] {"A"});
					foreach (string i in TmpWord)
					{
						if (i.ToString().Length > 0)
						{
							//listBox2.Items.Add(i.ToString());
								listBox2.Invoke (new MylistBox2(ApplistBox2),new Object[]{i.ToString()});
						

						}

					}

					String[] TmpPnt = Tmp[12].Split('|');

					//listBox3.Items.Clear();
                   	listBox3.Invoke (new MyClistBox3(ClistBox3),new Object[] {"A"});

					foreach (string i in TmpPnt)
					{
						if (i.ToString().Length > 0)
						{
							String[] TmpZH = i.ToString().Split(' ');
							//listBox3.Items.Add(TmpZH[1]);
								listBox3.Invoke (new MylistBox3(ApplistBox3),new Object[]{TmpZH[1]});
						

						}

					}
				}

			

				for (int i = 0; i < listBox1.Items.Count ; i++)
				{
					if (listBox1.Items[i].ToString() == textBox1.Text) { goto HAVEIT; }
				
				}
               // listBox1.Items.Add(textBox1.Text);
				listBox1.Invoke(new MylistBox2(ApplistBox1), new Object[] { textBox1.Text });
						
			HAVEIT: ;

				

			}
			else 
			{
				label2.Invoke (new Mylabel2(Applabel2),new Object[]{"NO Find"});
				//label2.Text = "NO Find";
			}
		}

		private void pictureBox1_Click(object sender, EventArgs e)
		{

		}

		#region Captures mouse to move the window to new location

		// points to hold the current position
		// and the new position for the form and the mouse
		System.Drawing.Point  MouseCurrrnetPos, MouseNewPos, formPos, formNewPos;
		bool mouseDown = false;

		private void MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			// when the mouse is down we must activate
			// a flag to say that the left button is down
			// and then store the current position
			// of the mouse and the form and we will 
			// use these posotions to calculate the offset
			// that must be added to the loaction
			if (e.Button == MouseButtons.Left)
			{
				mouseDown = true;
				MouseCurrrnetPos = Control.MousePosition;
				formPos = this.Location;
			}
		}

		private void MouseUp(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (e.Button == MouseButtons.Left)
				mouseDown = false;
		}

		private void Mclick(object sender, System.Windows.Forms.MouseEventArgs e)
		{

			this.Text = "AAA";

		}

		private void MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
		{
			if (mouseDown == true)
			{
				// get the position of the mouse in the screen
				MouseNewPos = Control.MousePosition;

				formNewPos.X = MouseNewPos.X - MouseCurrrnetPos.X + formPos.X;
				formNewPos.Y = MouseNewPos.Y - MouseCurrrnetPos.Y + formPos.Y;

				Location = formNewPos;
				formPos = formNewPos;
				MouseCurrrnetPos = MouseNewPos;
			}

		}

		#endregion

		private void IconMlabel8_Click(object sender, EventArgs e)
		{

		}
	
	
	
	
	}





}


	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -