コード例 #1
0
ファイル: Form1.cs プロジェクト: lehongdanh99/Project-HCMUTE
 private void btnSearch_Click(object sender, EventArgs e)
 {
     if (!File.Exists("D:\\Tudien.txt"))
     {
         MessageBox.Show("Error", "Không tìm thấy file nguồn");
         this.Close();
     }
     else
     {
         String       Line;
         StreamReader sr = new StreamReader("D:\\Tudien.txt");
         Line = sr.ReadLine();
         while (Line != null)
         {
             string[] words = Line.Split(':');       //Slpit tách chuổi thành 2 chuổi nhỏ bới dấu hai chấm
             node = tree.Insert(node, words[0], words[1]);
             Line = sr.ReadLine();
         }
         root = node;
         sr.Close();
     }
     if (tree.Seacrch(root, textBox1.Text) != null)
     {
         txtNghiaTu.Text = tree.Seacrch(root, textBox1.Text);
         tree.Destroy(root);
     }
     else
     {
         MessageBox.Show("Không có từ này! Bạn có thể thêm từ ^^");
         txtNghiaTu.Text = "";
     }
 }
コード例 #2
0
ファイル: Form3.cs プロジェクト: lehongdanh99/Project-HCMUTE
        private void Testbtn_Click(object sender, EventArgs e)
        {
            if (tree.Seacrch(root, DelBox.Text.ToString()) == null || DelBox.Text.ToString() == null)
            {
                MessageBox.Show("Khong co tu nay trong tu dien! ");
                Reset();
            }
            else
            {
                string       line = "";                                 // Variable used to store data from file.txt
                StreamReader sr   = new StreamReader("D:\\Tudien.txt"); // Reads the data from the file.txt file
                while (!sr.EndOfStream)                                 // Allows for data in Text file to be separated by comma delimiter
                {
                    line += sr.ReadLine() + ":";

                    string[] parts = line.Split(':').ToArray();

                    node = tree.Insert(node, parts[0], parts[1]);
                    line = "";

                    if (DelBox.Text == parts[0]) // Adds data to correct rows in table by counting the columns
                    {
                        DataGV.Rows.Clear();
                        DataGV.Rows.Add(parts[0], parts[1]);
                    }
                }
                sr.Close();
            }
        }
コード例 #3
0
ファイル: Struct.cs プロジェクト: lehongdanh99/Project-HCMUTE
 public void Traverse(NODE tree)
 {
     if (tree != null)
     {
         Traverse(tree.Left);
         Insert(tree, tree.Word, tree.Mean);
         Traverse(tree.Right);
     }
 }
コード例 #4
0
ファイル: Struct.cs プロジェクト: lehongdanh99/Project-HCMUTE
 public void Traverse(NODE tree)
 {
     if (tree != null)
     {
         Traverse(tree.Left);
         StreamWriter sw = new StreamWriter("D:\\Tudien.txt", true);
         //Write a line of text
         sw.WriteLine(tree.Word.ToString() + ":" + tree.Mean.ToString());
         sw.Close();
         Traverse(tree.Right);
     }
 }
コード例 #5
0
ファイル: Struct.cs プロジェクト: lehongdanh99/Project-HCMUTE
 public void Replace(NODE p, NODE q)
 {
     if (q.Left != null)
     {
         Replace(p, q.Left);
     }
     else
     {
         p.Word = q.Word;
         p.Mean = q.Mean;
         p      = q;
         q      = p.Right;
     }
 }
コード例 #6
0
ファイル: Struct.cs プロジェクト: lehongdanh99/Project-HCMUTE
 public void searchTowNode(NODE p, NODE q)
 {
     if (q.Left != null)
     {
         searchTowNode(p, q.Left);
     }
     else
     {
         p.Word = q.Word;
         p.Mean = q.Mean;
         p      = q;
         q      = p.Right;
     }
 }
コード例 #7
0
ファイル: Form1.cs プロジェクト: lehongdanh99/Project-HCMUTE
        private void Form1_Load(object sender, EventArgs e)
        {
            String       Line;
            StreamReader sr = new StreamReader("D:\\Tudien.txt");

            Line = sr.ReadLine();
            while (Line != null)
            {
                string[] words = Line.Split(':');       //Slpit tách chuổi thành 2 chuổi nhỏ bới dấu hai chấm
                node = tree.Insert(node, words[0], words[1]);
                Line = sr.ReadLine();
            }
            root = node;
            sr.Close();
        }
コード例 #8
0
ファイル: Form3.cs プロジェクト: lehongdanh99/Project-HCMUTE
        private void btnDelete_Click(object sender, EventArgs e)
        {
            string       line = "";                                 // Variable used to store data from file.txt
            StreamReader sr   = new StreamReader("D:\\Tudien.txt"); // Reads the data from the file.txt file

            while (!sr.EndOfStream)                                 // Allows for data in Text file to be separated by comma delimiter
            {
                line += sr.ReadLine() + ":";


                string[] parts = line.Split(':').ToArray();

                node = tree.Insert(node, parts[0], parts[1]);

                line = "";

                if (DelBox.Text == parts[0]) // Adds data to correct rows in table by counting the columns
                {
                    DataGV.Rows.Clear();
                    DataGV.Rows.Add(parts[0], parts[1]);
                }
            }
            sr.Close();
            DialogResult del = MessageBox.Show("Ban co muon xoa: ", "Thong bao", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (del == DialogResult.Yes)
            {
                if (tree.Seacrch(root, DelBox.Text.ToString().ToLower()) == null)
                {
                    MessageBox.Show("Khong co tu nay trong tu dien! ");
                }
                else
                {
                    string Filepath = @"D:\Tudien.txt";
                    System.IO.File.WriteAllText(Filepath, "");
                    tree.Del(ref root, DelBox.Text);
                    tree.Traverse(root);
                    MessageBox.Show("Xoa Thanh Cong! ");
                }
                Reset();
                System.GC.Collect();
            }
            else
            {
                return;
            }
        }
コード例 #9
0
ファイル: Struct.cs プロジェクト: lehongdanh99/Project-HCMUTE
 public string Seacrch(NODE root, string FindWord)                   //gọi đệ quy hàm search
 {
     if (root != null)
     {
         if (string.Compare(root.Word.ToLower(), FindWord.ToLower()) == 0)           //giống nhau: trả ra cái nghĩa
         {
             return(root.Mean);
         }
         else if (string.Compare(root.Word.ToLower(), FindWord.ToLower()) == 1)          //Word>word thì từ cần tìm chạy về phía bên trái
         {
             return(Seacrch(root.Left, FindWord));
         }
         else if (string.Compare(root.Word.ToLower(), FindWord.ToLower()) == -1)
         {
             return(Seacrch(root.Right, FindWord));
         }
     }
     return(null);
 }
コード例 #10
0
ファイル: Struct.cs プロジェクト: lehongdanh99/Project-HCMUTE
        public NODE Insert(NODE root, string word, string mean)
        {
            if (root == null)
            {
                root      = new NODE();
                root.Word = word;
                root.Mean = mean;
            }
            //compare dùng để so sánh hai từ bằng giá trị ASCII

            else if (string.Compare(root.Word, word) == 1)      // ==1 là Word>word
            {
                root.Left = Insert(root.Left, word, mean);      //từ nhỏ hơn sẽ đi về phía bên trái của cây
            }
            else if (string.Compare(root.Word, word) == -1)     // ==-1 là Word<word
            {
                root.Right = Insert(root.Right, word, mean);    //từ nhỏ hơn sẽ đi về phía bên phải của cây
            }
            return(root);
        }
コード例 #11
0
        private void btn_Click(object sender, EventArgs e)
        {
            if (MeanBox.Text == "" || WordBox.Text == "")
            {
                MessageBox.Show("Bạn chưa nhập đủ nghĩa và từ! ", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                String       Line;
                StreamReader sr = new StreamReader("D:\\Tudien.txt");
                Line = sr.ReadLine();
                while (Line != null)
                {
                    string[] words = Line.Split(':');       //Slpit tách chuổi thành 2 chuổi nhỏ bới dấu hai chấm
                                                            //node = tree.Insert(ref node, words[0], words[1]);
                    node = tree.Insert(node, words[0], words[1]);
                    Line = sr.ReadLine();
                }
                root = node;
                sr.Close();

                string fword = WordBox.Text.ToString();
                if (tree.Seacrch(node, fword) != null)
                {
                    MessageBox.Show("Từ đã có trong từ điển! ");
                }
                else
                {
                    //Pass the filepath and filename to the StreamWriter Constructor
                    StreamWriter sw = new StreamWriter("D:\\Tudien.txt", true);

                    //Write a line of text
                    sw.WriteLine(WordBox.Text + ":" + MeanBox.Text);
                    sw.Close();
                    MessageBox.Show("Them Thanh Cong! ");
                    System.GC.Collect();
                }
            }
        }
コード例 #12
0
ファイル: Struct.cs プロジェクト: lehongdanh99/Project-HCMUTE
        public bool Del(ref NODE root, string DelWord)
        {
            if (root == null)
            {
                return(false);
            }
            if (string.Compare(root.Word.ToLower(), DelWord.ToLower()) == 1)
            {
                return(Del(ref root.Left, DelWord));
            }

            if (string.Compare(root.Word.ToLower(), DelWord.ToLower()) == -1)
            {
                return(Del(ref root.Right, DelWord));
            }

            NODE p = root;

            if (root.Left == null)
            {
                root = root.Right;
            }
            else
            {
                if (root.Right == null)
                {
                    root = root.Left;
                }
                else
                {
                    Replace(p, root.Right);
                }
            }

            p = null;
            return(true);
        }
コード例 #13
0
ファイル: Form3.cs プロジェクト: lehongdanh99/Project-HCMUTE
        public void ReadFile()
        {
            /* int count = 0; */                                    // Varialble used to perform count of columns before moving to next row in table.
            string       line = "";                                 // Variable used to store data from file.txt
            StreamReader sr   = new StreamReader("D:\\Tudien.txt"); // Reads the data from the file.txt file

            while (!sr.EndOfStream)                                 // Allows for data in Text file to be separated by comma delimiter
            {
                line += sr.ReadLine() + ":";
                //count++;

                //if (count >= 2) // Adds data to correct rows in table by counting the columns
                //{
                string[] parts = line.Split(':').ToArray();
                DataGV.Rows.Add(parts[0], parts[1]);
                node = tree.Insert(node, parts[0], parts[1]);
                //count = 0;
                line = "";
                //}
            }
            root = node;
            sr.Close();
            int totalWidth = 0;

            //Auto Resize the columns to fit the data
            foreach (DataGridViewColumn column in DataGV.Columns)
            {
                DataGV.Columns[column.Index].AutoSizeMode = DataGridViewAutoSizeColumnMode.DisplayedCells;
                int widthCol = DataGV.Columns[column.Index].Width;
                DataGV.Columns[column.Index].AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
                DataGV.Columns[column.Index].Width        = widthCol;
                totalWidth = totalWidth + widthCol;
            }
            //the selector on the left of the DataGridView is about 45 in width
            DataGV.Width = totalWidth + 120;
        }
コード例 #14
0
ファイル: Struct.cs プロジェクト: lehongdanh99/Project-HCMUTE
 public void Destroy(NODE root)
 {
     Destroy(root.Left);
     Destroy(root.Right);
     root = null;
 }