Exemplo n.º 1
0
 /// <summary>
 /// This event is called by Search button to search for a
 /// spelling and enter the text fields with the information found
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btSearch_Click(object sender, EventArgs e)
 {
     //check to see if the text field is not empty
     if (!String.IsNullOrEmpty(tbSearchSpelling.Text))
     {
         Word       checkWordObj  = new Word();
         SearchWord searchWordObj = new SearchWord();
         checkWordObj = searchWordObj.checkWord(WordList, tbSearchSpelling.Text);
         if (!(checkWordObj == null))
         {
             tbSpelling.Text       = checkWordObj.Spelling;
             tbMeaning.Text        = checkWordObj.Meaning;
             tbSampleSentence.Text = checkWordObj.SampleSentence;
         }
         //if the word is already present then alert a message
         else
         {
             MessageBox.Show("Word searched is not on list", "Word Not Found");
             ClearFields();
         }
     }
     else
     {
         MessageBox.Show("Search Field is empty", "Please enter the word to search");
         ClearFields();
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// This event is called by Search button to search for a
 /// spelling and enter the text fields with the information found
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void btSearch_Click(object sender, EventArgs e)
 {
     EditSpelling = string.Empty;
     //check to see if the text field is not empty
     if (!String.IsNullOrEmpty(tbSearchSpelling.Text))
     {
         Word       checkWordObj  = new Word();
         SearchWord searchWordObj = new SearchWord();
         checkWordObj = searchWordObj.checkWord(WordList, tbSearchSpelling.Text);
         if (!(checkWordObj == null))
         {
             tbSpelling.Text       = checkWordObj.Spelling;
             tbMeaning.Text        = checkWordObj.Meaning;
             tbSampleSentence.Text = checkWordObj.SampleSentence;
             EditSpelling          = checkWordObj.Spelling;
         }
         //if the word is already present then alert a message
         else
         {
             ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Failed", "alert('Word searched is not on list,Word Not Found')", true);
             ClearFields();
         }
     }
     else
     {
         ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Failed", "alert('Search Field is empty,Please enter the word to search')", true);
         ClearFields();
     }
 }
Exemplo n.º 3
0
    /// <summary>
    /// This event is invoked when save button is clicked
    /// It adds the words into text file only if the word doesnt exists
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btSave_Click(object sender, EventArgs e)
    {
        Word       checkWordObj  = new Word();
        SearchWord searchWordObj = new SearchWord();

        checkWordObj = searchWordObj.checkWord(WordList, tbSpelling.Text);
        if (String.IsNullOrEmpty(tbSpelling.Text) || String.IsNullOrEmpty(tbMeaning.Text) || String.IsNullOrEmpty(tbSampleSentence.Text))
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Failed", "alert('Please enter value in all fields.')", true);
        }
        //if the fields are not empty,stores into text file
        else
        {
            //Check for word if it already exists
            if (!(checkWordObj == null))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Failed", "alert('The word is already existing.Please Enter an other word')", true);
                return;
            }
            else
            {
                using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["WordsDBConnStr"].ConnectionString))
                {
                    conn.Open();
                    //Insert into the table with current contents
                    string     queryText = "insert into \"all-word-table\" values(@SpellingTxt, @MeaningTxt, @ExampleTxt, @TimeCreatedTxt,@TimeUpdatedTxt)";
                    SqlCommand cmd       = new SqlCommand(queryText, conn);
                    cmd.Parameters.AddWithValue("@SpellingTxt", tbSpelling.Text);
                    cmd.Parameters.AddWithValue("@MeaningTxt", tbMeaning.Text);
                    cmd.Parameters.AddWithValue("@ExampleTxt", tbSampleSentence.Text);
                    cmd.Parameters.AddWithValue("@TimeCreatedTxt", DateTime.Now);
                    cmd.Parameters.AddWithValue("@TimeUpdatedTxt", DBNull.Value);

                    int rows = cmd.ExecuteNonQuery();
                    if (rows > 0)
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Success", "alert('Word has been Added Successfully')", true);
                        dgvCompleteGridView.DataBind();
                    }
                    else
                    {
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Failed", "alert('Word has not been added.')", true);
                    }
                }
            }

            //LoadData();
        }
        ClearFields();
    }
Exemplo n.º 4
0
        /// <summary>
        /// This event is invoked when save button is clicked
        /// It adds the words into text file only if the word doesnt exists
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btSave_Click(object sender, EventArgs e)
        {
            Word       checkWordObj  = new Word();
            SearchWord searchWordObj = new SearchWord();

            checkWordObj = searchWordObj.checkWord(WordList, tbSpelling.Text);//calls the method in the library to check the word
            //see if the text fields are not empty and alert the user to enter all the fields
            if (String.IsNullOrEmpty(tbSpelling.Text) || String.IsNullOrEmpty(tbMeaning.Text) || String.IsNullOrEmpty(tbSampleSentence.Text))
            {
                MessageBox.Show("Please enter value in all fields.", "Error in adding word");
            }
            //if the fields are not empty,stores into text file
            else
            {
                //checks if the word is already present in the text file
                if (!(checkWordObj == null))
                {
                    MessageBox.Show("The word is already existing.Please Enter an other word");
                    return;
                }
                //if it is new word,adds into text file by writing it
                //creates a instance of writer in write mode
                StreamWriter writer = new StreamWriter(wordsFile, true);

                string line = string.Concat(tbSpelling.Text, "*", tbMeaning.Text, "*",
                                            tbSampleSentence.Text);
                //append the word to file
                try
                {
                    writer.WriteLine(line);
                    writer.Close();
                    LoadData();//update datagridview with new word
                }
                //let the user know what went wrong in appending the line
                catch (Exception ex)
                {
                    MessageBox.Show("There is some error caught. Err: " + ex.Message);
                }
            }
            ClearFields();//reset the fields
        }
Exemplo n.º 5
0
        /// <summary>
        /// This event is invoked when save button is clicked
        /// It adds the words into text file only if the word doesnt exists
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btSave_Click(object sender, EventArgs e)
        {
            Word       checkWordObj  = new Word();
            SearchWord searchWordObj = new SearchWord();

            checkWordObj = searchWordObj.checkWord(WordList, tbSpelling.Text);
            if (String.IsNullOrEmpty(tbSpelling.Text) || String.IsNullOrEmpty(tbMeaning.Text) || String.IsNullOrEmpty(tbSampleSentence.Text))
            {
                MessageBox.Show("Please enter value in all fields.", "Error in adding word");
            }
            //if the fields are not empty,stores into text file
            else
            {
                //MessageBox to confirm addition
                DialogResult dr = MessageBox.Show("Do you want to add this word to database?", "Word Addition", MessageBoxButtons.YesNo);
                //if the user wants to save the add ,add it to database
                if (dr == System.Windows.Forms.DialogResult.Yes)
                {
                    try
                    {
                        //Check for word if it already exists
                        if (!(checkWordObj == null))
                        {
                            MessageBox.Show("The word is already existing.Please Enter an other word");
                            return;
                        }
                        else
                        {
                            using (SqlConnection conn = new SqlConnection(connString))
                            {
                                conn.Open();
                                //Insert into the table with current contents
                                string     queryText = "insert into \"all-word-table\" values(@SpellingTxt, @MeaningTxt, @ExampleTxt, @TimeCreatedTxt,@TimeUpdatedTxt)";
                                SqlCommand cmd       = new SqlCommand(queryText, conn);
                                cmd.Parameters.AddWithValue("@SpellingTxt", tbSpelling.Text);
                                cmd.Parameters.AddWithValue("@MeaningTxt", tbMeaning.Text);
                                cmd.Parameters.AddWithValue("@ExampleTxt", tbSampleSentence.Text);
                                cmd.Parameters.AddWithValue("@TimeCreatedTxt", DateTime.Now);
                                cmd.Parameters.AddWithValue("@TimeUpdatedTxt", DBNull.Value);

                                int rows = cmd.ExecuteNonQuery();
                                if (rows > 0)
                                {
                                    MessageBox.Show("Word has been added successfully.", "Success");
                                }
                                else
                                {
                                    MessageBox.Show("Word has not been added.", "Fail");
                                }
                            }
                        }

                        LoadData();
                    }

                    // If Inner Exception occurs, the message for tht exception is displyed
                    // else normal exception is displayed.
                    catch (Exception ex)
                    {
                        MessageBox.Show("There is some error caught. Err: " + ex.Message);
                    }
                }
            }
            ClearFields();
        }