/// <summary> /// Add a new note to our display /// </summary> /// <param name="Note">The note to be handled</param> private void NoteAdded(MM_Note Note) { if (InvokeRequired) { Invoke(new SafeNoteHandler(NoteAdded), Note); } else { ListViewItem NewItem = lvNotes.Items.Add(Note.ID.ToString(), "*", ""); NewItem.SubItems.Add(Note.CreatedOn.ToString()); MM_Element AssociatedElement; if (MM_Repository.TEIDs.TryGetValue(Note.AssociatedElement, out AssociatedElement)) { NewItem.SubItems.Add(AssociatedElement.Name); NewItem.SubItems.Add(AssociatedElement.ElemType.Name); } else { NewItem.SubItems.Add("?"); NewItem.SubItems.Add("?"); } NewItem.SubItems.Add(Note.Author); NewItem.SubItems.Add(Note.Note); NewItem.Tag = Note; } }
/// <summary> /// Handle the clicking on an item, by marking it as "acknowledged" or seen. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lvNotes_SelectedIndexChanged(object sender, EventArgs e) { if (lvNotes.SelectedItems.Count == 1) { MM_Note Note = lvNotes.SelectedItems[0].Tag as MM_Note; Note.Acknowledged = true; lvNotes.SelectedItems[0].Text = ""; } }
/// <summary> /// Remove a note from the display /// </summary> /// <param name="Note">The note to be handled</param> private void NoteRemoved(MM_Note Note) { if (InvokeRequired) { Invoke(new SafeNoteHandler(NoteRemoved), Note); } else { lvNotes.Items.RemoveByKey(Note.ID.ToString()); } }
private void lvNotes_MouseDoubleClick(object sender, MouseEventArgs e) { ListViewHitTestInfo ht = lvNotes.HitTest(e.Location); if (ht != null) { MM_Note Note = (ht.Item.Tag as MM_Note); Note.Acknowledged = true; ht.Item.Text = ""; MessageBox.Show(Note.Note, Note.Author + " on " + Note.CreatedOn, MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// Create a new note, and if selected, upload it. /// </summary> /// <param name="NoteElement">The element about which the note is being written</param> public static void CreateNote(MM_Element NoteElement) { using (MM_Note_Writer NewNote = new MM_Note_Writer(NoteElement)) if (NewNote.ShowDialog() == DialogResult.OK) { MM_Note OutNote = NewNote.CreatedNote; if (MM_Server_Interface.Client != null) { OutNote.ID = MM_Server_Interface.Client.UploadNote(OutNote); } Data_Integration.HandleNoteEntry(OutNote); } }
/// <summary> /// Handle the modification of a note /// </summary> /// <param name="Note">The note to be handled</param> private void NoteModified(MM_Note Note) { if (InvokeRequired) { Invoke(new SafeNoteHandler(NoteModified), Note); } else { ListViewItem FoundItem = lvNotes.Items[Note.ID.ToString()]; FoundItem.SubItems[0].Text = "*"; FoundItem.SubItems[1].Text = Note.CreatedOn.ToString(); MM_Element AssociatedElement = MM_Repository.TEIDs[Note.AssociatedElement]; FoundItem.SubItems[2].Text = AssociatedElement.ElemType.Name; FoundItem.SubItems[3].Text = Note.Author; FoundItem.SubItems[4].Text = Note.Note; } }
/// <summary> /// Upload a note, and return the new ID /// </summary> /// <param name="Note"></param> /// <returns></returns> public int UploadNote(MM_Note Note) { User.LastCommand = DateTime.Now; if (MM_Database_Connector.oConn == null || MM_Database_Connector.oConn.State != System.Data.ConnectionState.Open) { return(new Random().Next()); } using (DbCommand oCmd = MM_Database_Connector.CreateCommand(Settings.Default.DatabaseNoteInsertCommand, MM_Database_Connector.oConn)) { oCmd.Prepare(); MM_Database_Connector.AddParameter(oCmd, "CreatedOn", Note.CreatedOn); MM_Database_Connector.AddParameter(oCmd, "Author", Note.Author); MM_Database_Connector.AddParameter(oCmd, "Note", Note.Note); MM_Database_Connector.AddParameter(oCmd, "AssociatedElement", Note.AssociatedElement); MM_Database_Connector.AddParameter(oCmd, "Acknowledged", Note.Acknowledged); DbParameter Param = MM_Database_Connector.AddParameter(oCmd, "ID", null); Param.Direction = System.Data.ParameterDirection.Output; Param.DbType = System.Data.DbType.Int32; oCmd.ExecuteNonQuery(); return(Convert.ToInt32(oCmd.Parameters["ID"].Value)); } }