Ejemplo n.º 1
0
        /// <summary>
        /// Button handler for remove word button on the dictionary screen. opens
        /// dialog confirmation and removes word from database and dictionary list
        /// if user selects accept.
        /// </summary>
        /// <param name="sender">default arg</param>
        /// <param name="e">default arg</param>
        private void btn_removeWord_Click(object sender, EventArgs e)
        {
            if (gridView_Dictionary.SelectedRows.Count > 1)
            {
                MessageBox.Show("Please select one word at a time");
            }
            else if (gridView_Dictionary.SelectedRows.Count < 1)
            {
                MessageBox.Show("Must select at least one word");
            }
            else
            {
                var id   = gridView_Dictionary.SelectedRows[0].Index;                     //position relative to gridview
                var word = gridView_Dictionary.SelectedRows[0].Cells[0].Value.ToString(); //word selected

                DialogResult dialogResult = MessageBox.Show("Are you sure you want to remove word: " + word + " ?", "Confirm", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    cAccess acc     = new cAccess();
                    bool    success = acc.deleteWordFromDictionary(word);
                    if (success)
                    {
                        updateDictionaryGrid();
                        MessageBox.Show("Word: " + word + " successfully deleted from dictionary", "Removed");
                    }
                    else
                    {
                        MessageBox.Show("Error removing word from dictionary", "Error");
                    }
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Event handler for the Register button. Will attempt to contact database to create an account
 /// </summary>
 /// <param name="sender">required param</param>
 /// <param name="e">event arguements upon button press</param>
 private void btnRegister_Click(object sender, EventArgs e)
 {
     if (txtUsername.Text.Length < 6)
     {
         MessageBox.Show("Username too short.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else if (txtPasswordOne.Text != txtPasswordTwo.Text)
     {
         MessageBox.Show("Password do not match!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else if (txtPasswordOne.Text.Length < 6)
     {
         MessageBox.Show("Password too short.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {   //create account
         cAccess access     = new cAccess();
         string  hashedPass = generateHash(txtPasswordOne.Text.ToString());
         if (access.registerUser(txtUsername.Text.ToString(), hashedPass)) //successful insert
         {
             this.Close();                                                 //return to login form
         }
         else
         {
             MessageBox.Show("Account creation failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
        /// <summary>
        /// Called whenever the accept button is pressed. Finds all rows
        /// in the user's saved stocks screen and saves all stocks with
        /// a checkmark under the user's favorite stocks in the database.
        /// It deletes any stocks on the list with a checkmark removed.
        /// </summary>
        /// <param name="sender">default parameter.</param>
        /// <param name="e">default paramter.</param>
        private void btn_Accept_Click(object sender, EventArgs e)
        {
            //save all stock id's in list
            List <int> checked_stock_ids = new List <int>();

            //will be true if

            foreach (DataGridViewRow r in gridView_SavedStocks.Rows)
            {
                //find all checked stocks to add to db if not already exist
                //if (
                DataGridViewCheckBoxCell cell = r.Cells[0] as DataGridViewCheckBoxCell;

                //Compare to the true value because Value isn't boolean
                if (cell.Value == cell.TrueValue)
                {
                    checked_stock_ids.Add((int)r.Cells[1].Value);               //store all checked IDs
                    if (checked_stock_ids.Count > 20)                           //can't save more than 20 stocks
                    {
                        MessageBox.Show("Cannot save more than 20 stocks, please uncheck some", "Error");
                        return;                         //might change this to return
                    }
                }
            }

            cAccess acc = new cAccess();

            acc.saveNewStocks(checked_stock_ids);             //drop old stocks and save new list.
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Event handler for the Login button. Will validate credentials
        /// input into username & password boxes
        /// </summary>
        /// <param name="sender">required param</param>
        /// <param name="e">event arguements upon button press</param>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            cAccess access = new cAccess();

            string hashedPass = fRegister.generateHash(txtPassword.Text.ToString());

            int login_success = access.validateUser(txtUserName.Text.ToString(), hashedPass);

            if (login_success > 0)
            {
                //save that the user has logged in
                //set dialog result to OK to pop off primary window
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else    //invalid credentials
            {
                MessageBox.Show("Invalid credentials!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Button handler for add word button on the dictionary screen. opens
        /// the word edit dialog and accepts a word and weight and attempts
        /// to insert it in the database
        /// </summary>
        /// <param name="sender">default arg</param>
        /// <param name="e">default arg</param>
        private void btn_addWord_Click(object sender, EventArgs e)
        {
            fEditDictionaryValues add = new fEditDictionaryValues();

            add.Text = "Add word";
            add.ShowDialog();
            if (add.DialogResult == DialogResult.OK)
            {
                cAccess acc = new cAccess();

                if (acc.addWordToDictionary(add.Word, add.Weight))
                {
                    updateDictionaryGrid();
                    MessageBox.Show("Word: " + add.Word + " successfully added!");
                }
                else
                {
                    MessageBox.Show("Word not added to dictionary.");
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Button handler for edit word button on the dictionary screen. Opens
        /// edit dialog allowing the user to modify the word's values.
        /// </summary>
        /// <param name="sender">default arg</param>
        /// <param name="e">default arg</param>
        private void btn_editWord_Click(object sender, EventArgs e)
        {
            if (gridView_Dictionary.SelectedRows.Count > 1)
            {
                MessageBox.Show("Please select one word at a time");
            }
            else if (gridView_Dictionary.SelectedRows.Count < 1)
            {
                MessageBox.Show("Must select at least one word");
            }
            else
            {
                var word   = gridView_Dictionary.SelectedRows[0].Cells[0].Value.ToString();                     //word selected
                var weight = gridView_Dictionary.SelectedRows[0].Cells[1].Value.ToString();

                fEditDictionaryValues edit = new fEditDictionaryValues(word, weight);

                edit.Text = "Edit word";
                edit.ShowDialog();

                if (edit.DialogResult == DialogResult.OK)
                {
                    cAccess acc = new cAccess();

                    if (word != edit.Word)
                    {
                        acc.modifyWordInDictionary(word, edit.Word, edit.Weight);
                    }
                    if (weight != edit.Weight.ToString())
                    {
                        acc.modifyWeightInDictionary(edit.Word, edit.Weight);
                    }
                    updateDictionaryGrid();
                }
            }
        }