Ejemplo n.º 1
0
        /*
         * Takes input of file path and search terms.
         * Splits search terms into an array, and if include
         * synonyms is checked, fires method for setting
         * terms and synonyms (newSearch varible).
         * Calls SearchDirectory, runs timer while that is running,
         * and outputs time taken to form.
         * Fires the method to populate form with returned
         * data.
         * @param object sender, EventArgs e
         */
        private void Searchbut_Click(object sender, EventArgs e)
        {
            Boolean useDatabase = false; //to handle include synonym checked/not checked.

            if (SelectFolder.Text == "") //error handling for no file path selected
            {
                MessageBox.Show("Please select a file and try again");
            }
            if (SearchTerms.Text == "")//error handling for no search terms entered.
            {
                MessageBox.Show("Please a enter a search term, and try again");
            }

            FilePathOutput.Items.Clear();                          //clears list box.

            if (SearchTerms.Text != "" && SelectFolder.Text != "") //fires if there is a filepath and search term entered.
            {
                numSearch   = numSearch + 1;                       //adds one to variable holding number of searches. Used for average time.
                searchTerms = SearchTerms.Text.Split(',', ' ');    //splits the search terms at space or comma
                for (int i = 0; i < searchTerms.Length; i++)
                {
                    searchTerms[i] = searchTerms[i].ToLower();//sets all entered search terms to lower case, to match the database.
                }
                if (IncludeSynonyms.Checked)
                {
                    DbUtilities dbUtil = new DbUtilities(newWordsFullDataSet);
                    //constructor for DbUtilities, takes in dataset as parameter.
                    //Dataset out of scope in class variables.
                    useDatabase = true;
                    newSearch   = dbUtil.SearchWithDb(searchTerms);
                    //sets newSearch variable to return from SearchWithDb(), (terms and their synonyms)
                    //database based as a parameter so SearchWithDb can access it
                }

                var watch = System.Diagnostics.Stopwatch.StartNew();//starts a new instance of stop watch

                fileUtil.SearchDir(folderPath, useDatabase, searchTerms, newSearch);
                //Searches files and folders, reads contents, then fires the search methods and frequency methods.

                watch.Stop();                                       //stops stop watch.
                long time = watch.ElapsedMilliseconds;              //gets the time in milliseconds
                SearchTime.Text  = time.ToString() + "ms";          //outputs time to form.
                AverageTime.Text = Average(time).ToString() + "ms"; //outputs average time to form.

                fileToForm(useDatabase);                            //populates the listbox, number of files found and frequency textboxes
            }
        }
Ejemplo n.º 2
0
        /*
         * Takes the input from QueryWord textbox, and passes it to QueryWord
         * in DbUtilities, which queries it, then returns a string of
         * the synonyms, to be displayed in QuerySynonym textbox.
         */
        private void QueryEntryBut_Click(object sender, EventArgs e)
        {
            DbUtilities dbUtil = new DbUtilities(newWordsFullDataSet);

            //constructor for DbUtilities, takes in dataset as parameter.
            //Dataset out of scope in class variables.
            if (QueryWord.Text == "")//error handling for no value entered into textbox.
            {
                MessageBox.Show("Please enter a word and try again");
            }
            if (QueryWord.Text != "")             //fires if textbox is not blank.
            {
                string word = QueryWord.Text;     //sets local variable for passing.
                string aStr = dbUtil.Query(word); //Calls Query in DbUtilities.
                                                  //Sets local variable aStr to the return str from Query.
                QuerySynonym.Text = aStr;         //sets the text in the text box to aStr.
            }
        }
Ejemplo n.º 3
0
        /*
         * Takes the input from DeleteWord textbox
         * and passes it to the method DeleteWord
         * in DbUtilities to remove it from the
         * database.
         */
        private void DeleteWordBut_Click(object sender, EventArgs e)
        {
            DbUtilities dbUtil = new DbUtilities(newWordsFullDataSet);

            //constructor for DbUtilities, takes in dataset as parameter.
            //Dataset out of scope in class variables.
            if (DeleteWord.Text == "")//checks to see if the textbox is blank.
            {
                MessageBox.Show("Please enter a word and try again");
            }
            if (DeleteWord.Text != "")            //fires if textbox is not blank.
            {
                String delWord = DeleteWord.Text; //sets variable to be passed.
                dbUtil.DeleteWord(delWord);       //calls DeleteWord method in DbUtilitites.
                //Passes local variable delWord and the database, so it can be accessed.
                DeleteWord.Text = "";             //sets textbox back to blank.
            }
        }
Ejemplo n.º 4
0
        /*
         * Takes the input from UpdateWord and UpdateSynonym textboxes
         * and passes them to the method UpdateWord in DbUtilities
         * class, so that the new synonym can be appended to the end
         * of the synonym list.
         */
        private void UpdateEntryBut_Click(object sender, EventArgs e)
        {
            DbUtilities dbUtil = new DbUtilities(newWordsFullDataSet);

            //constructor for DbUtilities, takes in dataset as parameter.
            //Dataset out of scope in class variables.
            if (UpdateWord.Text == "")//checks to see if UpdateWord textbox is blank
            {
                MessageBox.Show("Please enter a word and try again");
            }
            if (UpdateWord.Text != "")            //fires if textbox is not blank.
            {
                String word = UpdateWord.Text;    //sets local variable to be passed.
                String syn  = UpdateSynonym.Text; //sets local variable to be passed
                dbUtil.UpdateWord(word, syn);     //calls UpdateWord method in DbUtilities.
                                                  //Passes local variables word and syn as parameters. Also passes the database so it can be accessed.
                UpdateSynonym.Text = "";          //sets textbox to blank
                UpdateWord.Text    = "";          //sets textbox to blank.
            }
        }
Ejemplo n.º 5
0
        /*
         * Takes the input from AddWord and AddSynonyms textboxes
         * and passes them to AddWord in DbUtilities to be added
         * to the database.
         */
        private void AddEntryBut_Click(object sender, EventArgs e)
        {
            DbUtilities dbUtil = new DbUtilities(newWordsFullDataSet);

            //constructor for DbUtilities, takes in dataset as parameter.
            //Dataset out of scope in class variables.
            if (AddWord.Text == "")//error checking for blank textbox
            {
                MessageBox.Show("Please enter a word, and try again");
            }
            if (AddWord.Text != "")            //fires is AddWord textbox is not blank.
            {
                String word = AddWord.Text;    //setting variable to be passed
                String syn  = AddSynonym.Text; //setting variable to be passed
                dbUtil.AddWord(word, syn);     //calls method in DbUtilities
                //uses local word and syn, and passes the database, so it can be accessed.
            }
            //resets textboxes to blank.
            AddWord.Text    = "";
            AddSynonym.Text = "";
        }