Beispiel #1
0
        //this event lets the user edit notes.
        private void Edit_Button_Click(object sender, EventArgs e)
        {
            //check for something selected.
            if (dataGridView1.SelectedRows.Count > 0)
            {
                //go through table.
                foreach (DataRow dr in NoteTable.Rows)
                {
                    //TODO: edit tags as well.
                    if (dataGridView1.SelectedRows[0].Cells[0].Value.ToString() == dr[0].ToString())
                    {
                        DateTime timenow = DateTime.Now;
                        DataRow newRow = NoteTable.NewRow();
                        dr["Title"] = Title_TextBox.Text;
                        dr["TextBody"] = Text_TextBox.Text;
                        dr["TimeUpdated"] = timenow;

                        int count = 0;

                        //New tagsplit object
                        TagSplit TS = new TagSplit();
                        List<string> TL = TS.tagger(Tags_TextBox.Text);
                        //remove all the tags related
                        //go through tags table

                        foreach (DataRow idrow in IdTable.Rows)
                        {
                            //if the note ids match
                            if (IdTable.Rows[count][0].ToString() == dataGridView1.SelectedRows[0].Cells[0].Value.ToString())
                            {

                                //TagsTable.Rows[(int)IdTable.Rows[count][1]].Delete();
                                for (int i = TagsTable.Rows.Count - 1; i >= 0; i--)
                                {
                                    if (TagsTable.Rows[i].RowState != DataRowState.Deleted &&(int)IdTable.Rows[count][1] == (int)TagsTable.Rows[i][0])
                                    {
                                        TagsTable.Rows[i].Delete();
                                        deleted++;
                                    }
                                }
                                IdTable.Rows[count].Delete();
                            }
                            count++;
                        }

                        int noteid = (int)dataGridView1.SelectedRows[0].Cells[0].Value;
                        con_delete();
                        con_update();
                        refreshGrid();

                        //add all the tags back.
                        int tag_row = TagsTable.Rows.Count;
                        //checks for null values in tags table because previous tags were deleted.
                        while (TagsTable.Rows[tag_row - 1][0] == DBNull.Value)
                        { tag_row--; }
                        tag_row = Convert.ToInt32(TagsTable.Rows[tag_row - 1][0]);

                        foreach (string tag in TL)
                        {
                            DataRow tagRow = TagsTable.NewRow();
                            tagRow["Tag"] = tag;
                            TagsTable.Rows.Add(tagRow);
                            DataRow idRow = IdTable.NewRow();
                            idRow["NoteID"] = noteid;
                            //this is currently incorrect and does not point to the correct tag.

                            idRow["TagID"] = tag_row+1+deleted;
                            IdTable.Rows.Add(idRow);
                            tag_row++;
                        }
                        clearTextBoxes();
                        con_update();
                        refreshGrid();
                        MessageBox.Show("Note Edited", "Changed");
                        break;
                    }
                }
            }
            else
                //if nothing is selected, tell user.
                MessageBox.Show("please select note to be edited.", "no selection.");
        }
Beispiel #2
0
 //Gives the user a message for the Show Tags Button, and also creating a message box for what's typed in the TextBox
 private void ShowTags_Button_Click(object sender, EventArgs e)
 {
     TagSplit tg = new TagSplit();
     if (Tags_TextBox.Text == "")
     {
         //Displays a message if nothing is entered.
         MessageBox.Show("Please enter tags seperated by : \n ex. Tags:Tag:Note", "Tags Error");
     }
     else
     {
         //Declares a string and assigns it to the string returned by the class library.
         List<string> inTags = tg.tagger(Tags_TextBox.Text);
         string tagList ="";
         //Displays the tags, each of them on a different line.
         foreach (string ele in inTags)
         {
             tagList += ele + "\n";
         }
         MessageBox.Show(tagList, "Tags");
     }
 }
Beispiel #3
0
        private void changeNote()
        {
            if (Tags_TextBox.Text == "" || Title_TextBox.Text == "" || Text_TextBox.Text == "")
            {
                //Displays a message if nothing is entered.

                if (Title_TextBox.Text == "")
                    MessageBox.Show("Please enter a title for your note.", "No Title");
                if (Tags_TextBox.Text == "")
                    MessageBox.Show("Please enter tags seperated by : \n ex. Tags:Tag:Note", "Tags Error");
                if (Text_TextBox.Text == "")
                    MessageBox.Show("Please the body of your text.", "No Body");
            }
            else
            {
                DialogResult doubleCheckBox = MessageBox.Show("Would you like to save this new note, or nah?", "Just to double check", MessageBoxButtons.YesNo);
                if (doubleCheckBox == DialogResult.Yes)
                {
                    //New tagsplit object
                    TagSplit TS = new TagSplit();
                    DateTime timenow = DateTime.Now;

                    //Send the tags to the tagslitter
                    List<string> tagList = TS.tagger(Tags_TextBox.Text);

                    //Make a new note object
                    NoteItem NI = new NoteItem(Text_TextBox.Text, Title_TextBox.Text, tagList);

                    //database magic
                    DataRow newRow = NoteTable.NewRow();
                    newRow["Title"] = Title_TextBox.Text;
                    newRow["TextBody"] = Text_TextBox.Text;
                    newRow["TimeUpdated"] = timenow;
                    newRow["TimeCreated"] = timenow;
                    NoteTable.Rows.Add(newRow);

                    int tag_row = TagsTable.Rows.Count;
                    //checks for null values in tags table because previous tags were deleted.
                    while (TagsTable.Rows[tag_row - 1][0] == DBNull.Value)
                    { tag_row--; }
                    tag_row = Convert.ToInt32(TagsTable.Rows[tag_row - 1][0]);

                    int note_row = NoteTable.Rows.Count;
                    //checks for null values in tags table because previous tags were deleted.
                    while (NoteTable.Rows[note_row - 1][0] == DBNull.Value)
                    { note_row--; }
                    note_row = Convert.ToInt32(NoteTable.Rows[note_row - 1][0]);

                    foreach(string tag in tagList )
                    {
                        DataRow tagRow = TagsTable.NewRow();
                        tagRow["Tag"] = tag;
                        TagsTable.Rows.Add(tagRow);
                        DataRow idRow = IdTable.NewRow();
                        //note id is wrong, need to check for null values.
                        idRow["NoteID"] = note_row + 1;

                        idRow["TagID"] = tag_row + 1;
                        IdTable.Rows.Add(idRow);
                        tag_row++;
                    }

                    //Show the user that the note was added.
                    MessageBox.Show("Note added", "New Note");

                    //Update the data grid.
                    con_update();
                    refreshGrid();
                    //dataGridView1.Update();
                    //dataGridView1.Refresh();
                }
                else
                    MessageBox.Show("The new note was not saved");
            }
        }