Example #1
0
        private void bunifuThinButton21_Click(object sender, EventArgs e)
        {
            customemessage c;

            catlist.Items.Clear();

            if (filename.Text.Trim() == "")
            {
                c = new customemessage("Empty Field!!");
                c.ShowDialog();
                return;
            }
            string      name = filename.Text.Trim();
            XmlDocument doc  = new XmlDocument();

            doc.Load("User.xml");
            XmlNodeList list  = doc.GetElementsByTagName("File");
            string      s     = "";
            bool        check = false;

            for (int i = 0; i < list.Count; i++)
            {
                XmlNodeList child = list[i].ChildNodes;
                if (child[0].InnerText == name)
                {
                    check = true;
                    for (int j = 0; j < child.Count - 2; j++)
                    {
                        s += child[j + 2].InnerText + ",";
                    }
                    s = s.Remove(s.Length - 1, 1);
                }
            }
            if (!check)
            {
                c = new customemessage("File not Found!!");
                c.ShowDialog();
            }
            string[] word = s.Split(',');

            for (int i = 0; i < word.Length; i++)
            {
                catlist.Items.Add(word[i]);
            }
        }
        private void bunifuThinButton21_Click(object sender, EventArgs e)
        {
            customemessage x, c, p;

            if (catname.Text.Trim() == "" || keywords.Text.Trim() == "")
            {
                c = new customemessage("Empty Field!!");
                c.ShowDialog();
                return;
            }



            string name = catname.Text.Trim();

            string[] a = new string[keywords.Lines.Length];
            for (int i = 0; i < keywords.Lines.Length; i++)
            {
                a[i] = keywords.Lines[i].ToString();
            }


            if (!File.Exists("Categories.xml"))
            {
                XmlWriter wr = XmlWriter.Create("Categories.xml");
                wr.WriteStartDocument();

                wr.WriteStartElement("Table");

                wr.WriteStartElement("Categories");



                wr.WriteStartElement("Name");
                wr.WriteString(name);
                wr.WriteEndElement();


                for (int i = 0; i < keywords.Lines.Length; i++)
                {
                    if (a[i].Trim() == "")
                    {
                        continue;
                    }
                    wr.WriteStartElement("Keywords");
                    wr.WriteString(a[i]);
                    wr.WriteEndElement();
                }
                wr.WriteEndElement();
                wr.WriteEndElement();



                wr.WriteEndDocument();
                wr.Close();
            }
            else
            {
                XmlDocument doc0 = new XmlDocument();
                doc0.Load("Categories.xml");
                XmlNodeList list = doc0.GetElementsByTagName("Categories");
                for (int i = 0; i < list.Count; i++)
                {
                    XmlNodeList child0 = list[i].ChildNodes;
                    if (catname.Text.Trim() == child0[0].InnerText)
                    {
                        p = new customemessage("Category Is Exist ");
                        p.Show();
                        return;
                    }
                }

                XmlDocument doc  = new XmlDocument();
                XmlElement  cate = doc.CreateElement("Categories");

                XmlElement node = doc.CreateElement("Name");
                node.InnerText = name;
                cate.AppendChild(node);



                for (int i = 0; i < keywords.Lines.Length; i++)
                {
                    if (a[i].Trim() == "")
                    {
                        continue;
                    }
                    node           = doc.CreateElement("Keywords");
                    node.InnerText = a[i];
                    cate.AppendChild(node);
                }

                doc.Load("Categories.xml");
                XmlElement root = doc.DocumentElement;
                root.AppendChild(cate);

                doc.Save("Categories.xml");
            }


            x = new customemessage("Category Added Successfully!");
            x.ShowDialog();

            keywords.Clear();
            catname.Text = "";
            catname.Focus();
        }
Example #3
0
        private void bunifuThinButton21_Click(object sender, EventArgs e)
        {
            customemessage y, c, p;

            if (filename.Text.Trim() == "" || catname.Text.Trim() == "" || content.Text.Trim() == "")
            {
                c = new customemessage("Empty Field!!");
                c.ShowDialog();
                return;
            }



            FileStream   fs = new FileStream(filename.Text.ToString().Trim() + ".txt", FileMode.Append);
            StreamWriter sw = new StreamWriter(fs);
            string       s;

            //sw.Write(content.Text);
            for (int i = 0; i < content.Lines.Length; i++)
            {
                s = content.Lines[i];
                sw.WriteLine(s);
            }
            sw.Close();
            string name = filename.Text;

            string[] arr = new string[catname.CheckedItems.Count];
            for (int j = 0; j < catname.CheckedItems.Count; j++)
            {
                arr[j] = catname.CheckedItems[j].ToString();
            }
            string path = "C:\\" + Environment.UserName.ToString() + "\\Projects\\Files Project\\FileSearchEngine\\FileSearchEngine\\bin\\Debug\\" + filename.Text + ".txt";

            if (arr.Length == 0)
            {
                customemessage cm = new customemessage("Empty Field!!");
                cm.ShowDialog();
                return;
            }


            if (!File.Exists("User.xml"))
            {
                XmlWriter wr = XmlWriter.Create("User.xml");
                wr.WriteStartDocument();

                wr.WriteStartElement("Table");

                wr.WriteStartElement("File");

                wr.WriteStartElement("FileName");
                wr.WriteString(name);
                wr.WriteEndElement();

                wr.WriteStartElement("Path");
                wr.WriteString(path);
                wr.WriteEndElement();

                for (int x = 0; x < arr.Length; x++)
                {
                    wr.WriteStartElement("CategoryName");
                    wr.WriteString(arr[x]);
                    wr.WriteEndElement();
                }



                wr.WriteEndElement();
                wr.WriteEndElement();



                wr.WriteEndDocument();
                wr.Close();
            }
            else
            {
                XmlDocument doc0 = new XmlDocument();
                doc0.Load("User.xml");
                XmlNodeList list = doc0.GetElementsByTagName("File");
                for (int i = 0; i < list.Count; i++)
                {
                    XmlNodeList child0 = list[i].ChildNodes;
                    if (filename.Text.Trim() == child0[0].InnerText)
                    {
                        p = new customemessage("File Name Is Exist ");
                        p.Show();
                        return;
                    }
                }
                XmlDocument doc  = new XmlDocument();
                XmlElement  cate = doc.CreateElement("File");
                XmlElement  node = doc.CreateElement("FileName");

                node.InnerText = name;
                cate.AppendChild(node);

                node           = doc.CreateElement("Path");
                node.InnerText = path;



                cate.AppendChild(node);

                for (int x = 0; x < arr.Length; x++)
                {
                    node = doc.CreateElement("CategoryName");

                    node.InnerText = arr[x];
                    cate.AppendChild(node);
                }


                doc.Load("User.xml");
                XmlElement root = doc.DocumentElement;
                root.AppendChild(cate);

                doc.Save("User.xml");
            }


            XmlDocument doc2 = new XmlDocument();

            doc2.Load("Categories.xml");
            XmlNodeList nl = doc2.GetElementsByTagName("Categories");



            for (int i = 0; i < nl.Count; i++)
            {
                XmlNodeList child  = nl[i].ChildNodes;
                bool        bolean = false;
                for (int w = 0; w < arr.Length; w++)
                {
                    if (arr[w] == child[0].InnerText.ToString())
                    {
                        bolean = true;
                    }
                }


                //MessageBox.Show(child.Count.ToString());
                for (int x = 1; x < child.Count; x++)
                {
                    if (!bolean)
                    {
                        continue;
                    }
                    //MessageBox.Show(filename.Text.ToString());
                    string       file = filename.Text.ToString() + ".txt";
                    FileStream   f = new FileStream(file, FileMode.Open);
                    StreamReader sr = new StreamReader(f);
                    int          counter = 0, line = 1;
                    List <int>   existingLine = new List <int>();

                    while (sr.Peek() != -1)
                    {
                        string   sx    = sr.ReadLine();
                        string[] words = sx.Split(' ');
                        bool     q     = false;
                        //if (sx.Contains(child[x].InnerText.ToString()))
                        for (int w = 0; w < words.Length; w++)
                        {
                            if (words[w] == child[x].InnerText.ToString())
                            {
                                counter++;
                                q = true;
                            }
                        }
                        if (q)
                        {
                            existingLine.Add(line);
                        }
                        line++;
                    }
                    //MessageBox.Show(counter.ToString() + " ");

                    if (counter > 0)
                    {
                        if (!File.Exists("HistoryLog.xml"))
                        {
                            XmlWriter wr = XmlWriter.Create("HistoryLog.xml");
                            wr.WriteStartDocument();
                            wr.WriteStartElement("Table");
                            wr.WriteStartElement("Log");

                            wr.WriteStartElement("CategoryName");
                            wr.WriteString(child[0].InnerText.ToString());
                            wr.WriteEndElement();

                            wr.WriteStartElement("KeywordName");
                            wr.WriteString(child[x].InnerText.ToString());
                            wr.WriteEndElement();

                            wr.WriteStartElement("FileName");
                            wr.WriteString(filename.Text.ToString());
                            wr.WriteEndElement();

                            for (int q = 0; q < existingLine.Count; q++)
                            {
                                wr.WriteStartElement("LineNumber");
                                wr.WriteString(existingLine[q].ToString());
                                wr.WriteEndElement();
                            }

                            wr.WriteStartElement("Counter");
                            wr.WriteString(counter.ToString());
                            wr.WriteEndElement();

                            wr.WriteEndElement();
                            wr.WriteEndElement();
                            wr.WriteEndDocument();
                            wr.Close();
                        }
                        else
                        {
                            XmlDocument doc  = new XmlDocument();
                            XmlElement  cate = doc.CreateElement("Log");
                            XmlElement  node = doc.CreateElement("CategoryName");

                            node.InnerText = child[0].InnerText.ToString();
                            cate.AppendChild(node);


                            node           = doc.CreateElement("KeywordName");
                            node.InnerText = child[x].InnerText.ToString();
                            cate.AppendChild(node);


                            node           = doc.CreateElement("FileName");
                            node.InnerText = filename.Text.ToString();
                            cate.AppendChild(node);

                            for (int q = 0; q < existingLine.Count; q++)
                            {
                                node           = doc.CreateElement("LineNumber");
                                node.InnerText = existingLine[q].ToString();
                                cate.AppendChild(node);
                            }

                            node           = doc.CreateElement("Counter");
                            node.InnerText = counter.ToString();
                            cate.AppendChild(node);


                            doc.Load("HistoryLog.xml");
                            XmlElement root = doc.DocumentElement;
                            root.AppendChild(cate);

                            doc.Save("HistoryLog.xml");
                        }
                    }

                    sr.Close();
                }
            }



            y = new customemessage("File Added Successfully!");
            y.ShowDialog();
            filename.Text = "";
            filename.Focus();
            content.Text = "";
            for (int z = 0; z < catname.Items.Count; z++)
            {
                catname.SetItemChecked(z, false);
            }
        }