Пример #1
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>();
                }
            }
        }
Пример #2
0
        private void buttonCANCEL_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("¿Are you sure you want to discard the note?", "Exit", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                resetText();

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

                this.Hide();
            }
        }
Пример #3
0
        private void modifyTheNote()
        {
            Note note = new Note();

            note = ModifyNotes.getNote();

            textboxID.Text          = Convert.ToString(note.Id);
            textboxTITLE.Text       = note.Title;
            textboxCATEGORY.Text    = note.Category;
            textboxDESCRIPTION.Text = note.Description;
            textboxDATE.Text        = Convert.ToString(note.DateCreated);

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

            case "Medium":
                comboboxIMPORTANCE.SelectedIndex = 1;
                break;

            default:
                comboboxIMPORTANCE.SelectedIndex = 2;
                break;
            }

            if (note.Favorite == 1)
            {
                switchFAVOURITE.Value = true;
            }
            else
            {
                switchFAVOURITE.Value = false;
            }
        }
Пример #4
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();
        }