Пример #1
0
        public void updateNotes()
        {
            totalNotes   = DB_Data.GetTotalNotes(Properties.Settings.Default.UserID);
            notesPerPage = 100; // This is because we will show only 100 notes for page.
            actualPage   = 1;

            // If we get less notes than the max notes.
            if (totalNotes < notesPerPage)
            {
                // Max pages set to 1.
                maxPages = 1;

                // Blocking those buttons so the user cannot go forward/back.
                buttonPAGE_BACK.Enabled = false;
                buttonPAGE_NEXT.Enabled = false;
            }
            else
            {
                // Max pages set to the value + 1, just to avoid problems with the data showed.
                maxPages = (totalNotes / notesPerPage) + 1;
            }

            // Showing the notes.
            showNotesByPage(1);
        }
Пример #2
0
        public void udpateSecondaryDataGridView()
        {
            DataSet ds_aux = DB_Data.GetAllNotes(Properties.Settings.Default.UserID);

            dt_aux = ds_aux.Tables[0];
            datagridviewNOTES_SECONDARY.DataSource = dt_aux;
        }
Пример #3
0
        private void buttonRESTORE_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("¿Do you want to restore those notes?", "Restoring notes",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    foreach (DataGridViewRow row in datagridview_NOTES.Rows)
                    {
                        if (Convert.ToBoolean(row.Cells["Select"].Value))
                        {
                            int noteID = Convert.ToInt32(row.Cells["ID"].Value);

                            if (DB_Data.RestoreNote(noteID) != 1)
                            {
                                MessageBox.Show("This note cannot be restored.", "Notes", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                    }

                    updateNotes();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
Пример #4
0
        private void buttonDELETE_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Do you want to mark as non-favorite notes?", "Deleting notes",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    foreach (DataGridViewRow row in datagridview_NOTES.Rows)
                    {
                        if (Convert.ToBoolean(row.Cells["Select"].Value))
                        {
                            int noteID = Convert.ToInt32(row.Cells["ID"].Value);

                            if (DB_Data.NotFavoriteAnymore(noteID) != 1)
                            {
                                MessageBox.Show("This note cannot be deleted.", "Notes", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                    }

                    showFavoriteNotesByPage(1);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
Пример #5
0
        public void updateData()
        {
            int id = Properties.Settings.Default.UserID;

            labelNOTES_TOTALCREATED.Text = Convert.ToString(DB_Data.GetTotalNotes(id));
            labelNOTES_FAVORITES.Text    = Convert.ToString(DB_Data.GetTotalFavoriteNotes(id));
            labelNOTES_DELETED.Text      = Convert.ToString(DB_Data.GetTotalDeletedNotes(id));
            labelNOTES_USERSCREATED.Text = Convert.ToString(DB_Data.GetTotalUsersCreated());
        }
Пример #6
0
        private void buttonMODIFY_Click(object sender, EventArgs e)
        {
            // If we have more than 0 rows in the datagridview
            if (datagridview_NOTES.Rows.Count > 0)
            {
                int checkboxClicked = 0;

                Note selectedNote = new Note();

                // Looping the datagridview.
                foreach (DataGridViewRow row in datagridview_NOTES.Rows)
                {
                    // If there's a checkbox selected from the column "Select"
                    if (Convert.ToBoolean(row.Cells["Select"].Value))
                    {
                        checkboxClicked++;

                        // If there's more than one checkbox clicked, we end the task.
                        if (checkboxClicked > 1)
                        {
                            MessageBox.Show("You cannot choose more than one note to modify",
                                            "Notes", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            break;
                        }

                        // Pick every object data from the datagridview.
                        selectedNote.Id          = Convert.ToInt32(row.Cells["ID"].Value);
                        selectedNote.Title       = Convert.ToString(row.Cells["Title"].Value);
                        selectedNote.Category    = Convert.ToString(row.Cells["Category"].Value);
                        selectedNote.Description = Convert.ToString(row.Cells["NoteDescription"].Value);
                        selectedNote.Importance  = Convert.ToString(row.Cells["Importance"].Value);
                        selectedNote.DateCreated = Convert.ToDateTime(row.Cells["DateCreated"].Value);
                    }
                }

                // If there's just one checkbox clicked, we proceed.
                if (checkboxClicked == 1)
                {
                    // See if the note selected is favourite or not.
                    if (DB_Data.IsFavorite(selectedNote.Id))
                    {
                        selectedNote.Favorite = 1;
                    }
                    else
                    {
                        selectedNote.Favorite = 0;
                    }

                    // This will help me to know when the user wants to modify a note.
                    ModifyNotes.setNote(selectedNote);

                    // We open the form to modify the note.
                    OpenForm <FormCreateNotes>();
                }
            }
        }
Пример #7
0
        public void showNotesByPage(int pageNumber)
        {
            // Obtain data + show it in the datagridview.
            DataSet ds = DB_Data.LoadNotesByPage(Properties.Settings.Default.UserID, pageNumber);

            dt = ds.Tables[0];
            datagridview_NOTES.DataSource = dt;

            // If the page we sent is 1, set everything to 1, to avoid bugs.
            if (pageNumber == 1)
            {
                actualPage = 1;
                textboxACTUAL_PAGE.Text  = "1";
                textoPAGINA_TOTALES.Text = "/ " + maxPages;
            }
        }
Пример #8
0
        private void buttonDELETE_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Do you want to delete those notes?", "Deleting notes",
                                    MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    foreach (DataGridViewRow row in datagridview_NOTES.Rows)
                    {
                        if (Convert.ToBoolean(row.Cells["Select"].Value))
                        {
                            int noteID = Convert.ToInt32(row.Cells["ID"].Value);

                            if (DB_Data.DeleteNote(noteID) != 1)
                            {
                                MessageBox.Show("This note cannot be deleted.", "Notes", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                        }
                    }

                    // Refresh the datagridview if the form is open.
                    if (Application.OpenForms["FormSeeDeletedNotes"] != null)
                    {
                        (Application.OpenForms["FormSeeDeletedNotes"] as FormSeeDeletedNotes).updateNotes();
                    }

                    // Refresh the datagridview if the form is open.
                    if (Application.OpenForms["FormSeeFavoriteNotes"] != null)
                    {
                        (Application.OpenForms["FormSeeFavoriteNotes"] as FormSeeFavoriteNotes).showFavoriteNotesByPage(1);
                    }

                    showNotesByPage(1);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + ex.StackTrace);
            }
        }
Пример #9
0
        private void buttonLOGINREGISTER_Click(object sender, EventArgs e)
        {
            string user     = textboxUSER.Text.Trim();
            string password = textboxPASS.Text.Trim();

            if (user != "" && password != "")
            {
                if (buttonLOGINREGISTER.Text == "Register") // Register
                {
                    // If the user exists.
                    if (DB_Data.UserExists(user))
                    {
                        MessageBox.Show("The user is already taken.", "Register", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (password.Length < 3) // If the password have less than 3 characters.
                    {
                        MessageBox.Show("The password is too weak.", "Register", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else // Everything is OK.
                    {
                        // Register the user in the database.
                        DB_Data.CreateUser(user, password);

                        resetThings(true);

                        MessageBox.Show("User registered!", "Register", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else // Login
                {
                    // If the user exists.
                    if (DB_Data.UserExists(user))
                    {
                        // If the user and password match.
                        if (DB_Data.VerifyLogin(user, password))
                        {
                            // With this we save the UserID because we need to have easy access to that ID (creation of notes or
                            // another things).
                            Properties.Settings.Default.UserID = DB_Data.BringUserID(user);
                            Properties.Settings.Default.Save();

                            // Show the main form.
                            FormMain form = new FormMain();
                            form.Show();
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show("User/Password invalid.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    else
                    {
                        MessageBox.Show("The user doesn't exists.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                MessageBox.Show("User or Password empty.", "Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #10
0
        private void buttonSAVE_Click(object sender, EventArgs e)
        {
            Note note = new Note();

            note.Title       = textboxTITLE.Text;
            note.Category    = textboxCATEGORY.Text;
            note.Description = textboxDESCRIPTION.Text;

            switch (comboboxIMPORTANCE.SelectedIndex)
            {
            case 0:
                note.Importance = "Low";
                break;

            case 1:
                note.Importance = "Medium";
                break;

            default:
                note.Importance = "High";
                break;
            }

            if (switchFAVOURITE.Value)
            {
                note.Favorite = 1;
            }
            else
            {
                note.Favorite = 0;
            }

            // If the user is modifying the note...
            if (ModifyNotes.modifyNote)
            {
                note.Id = Convert.ToInt32(textboxID.Text);

                // Sending data to modify the note.
                DB_Data.ModifyNote(note);

                // Send the message to the user.
                MessageBox.Show("Note modified!", "Modify note", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                // Sending data to create the note.
                DB_Data.CreateNote(Properties.Settings.Default.UserID, note);

                // Send the message to the user.
                MessageBox.Show("Note added!", "Create note", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            // Refreshing the datagridview.
            if (Application.OpenForms["FormSeeNotes"] != null)
            {
                (Application.OpenForms["FormSeeNotes"] as FormSeeNotes).updateNotes();
            }

            // Reset every possible thing to avoid bugs.
            resetText();

            ModifyNotes.modifyNote = false;
            ModifyNotes.resetNotes();

            // Hiding the form.
            this.Hide();
        }