/// <summary> /// Fires a given event and passes it with the correct arguments to the registered event handlers. It returns the <see cref="CollectionEventArgs"/> structure it created and that the event handlers might have modified. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="handler">The event to fire.</param> /// <param name="record">The record the collection belongs to.</param> /// <param name="collection">The collection to pass to the event handlers.</param> /// <returns>A new instance of the <see cref="CollectionEventArgs"/> class that has been passed to every event handler and might have been modified.</returns> public static CollectionEventArgs Fire(Control sender, CollectionEventHandler handler, IEditableDbRecord record, PropertyInfo collection) { var args = new CollectionEventArgs(record, collection); if (handler == null) return args; handler(sender, args); return args; }
/// <summary> /// Fires a given event and passes it with the correct arguments to the registered event handlers. It returns the <see cref="RecordEventArgs"/> structure it created and that the event handlers might have modified. /// </summary> /// <param name="sender">The sender of the event.</param> /// <param name="handler">The event to fire.</param> /// <param name="record">The record to pass to the event handlers (may be null).</param> /// <returns>A new instance of the <see cref="RecordEventArgs"/> class that has been passed to every event handler and might have been modified.</returns> public static RecordEventArgs Fire(Control sender, RecordEventHandler handler, IEditableDbRecord record) { var args = new RecordEventArgs() { Record = record, Continue = true }; if (handler == null) return args; handler(sender, args); return args; }
/// <summary>Initializes the form's basic properties. Call this before showing the form.</summary> /// <param name="Owner">Window that is the owner of the form that is shown.</param> /// <param name="Name">Name to use for the edit window (think user preferences = FormData).</param> /// <param name="Title">Text to show in the form's title bar and a caption label.</param> /// <param name="Records">The base records from which a user may select a record for editing.</param> /// <param name="RecordType">The type of the DbRecord subclass to show the form for.</param> /// <param name="SelectedRecord">Record to be selected when showing the form for the first time.</param> protected virtual void InitializeForm(IWin32Window Owner, String Name, String Title, Type RecordType, List<IEditableDbRecord> Records, IEditableDbRecord SelectedRecord) { // Important for FormData.LoadFormData and FormData.SaveFormData this.Name = Name; this.Text = Title; this.HeaderText = Title; this.Records = Records; this.RecordType = RecordType; this.SelectedRecord = SelectedRecord; if (Owner == null) this.ShowInTaskbar = true; }
/// <summary> /// Shows a form that allows a user to select a record. /// </summary> /// <param name="Owner">Window that is the owner of the form that is shown</param> /// <param name="Name">Name to use for the edit window (think user preferences = FormData).</param> /// <param name="Title">Text to show in the form's title bar and a caption label.</param> /// <param name="Records">The base records from which a user may select a record for editing.</param> /// <param name="RecordType">The type of the DbRecord subclass to show the form for.</param> /// <param name="SelectedRecord">Record to be selected when showing the form for the first time.</param> public static IEditableDbRecord SelectRecord(IWin32Window Owner, String Name, String Title, Type RecordType, List<IEditableDbRecord> Records, IEditableDbRecord SelectedRecord) { using (var form = new DbRecordSelectorForm()) { form.InitializeForm(Owner, Name, Title, RecordType, Records, SelectedRecord); if (form.ShowDialog(Owner) == DialogResult.OK) return form.SelectedRecord; else return null; } }
private void List_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e) { var record = (e.Item == null ? null : (IEditableDbRecord)e.Item.Tag); SelectedRecord = (e.IsSelected ? record : null); LastSelection = SelectedRecord; }
/// <summary> /// Adds the given record the the left list view. /// </summary> /// <param name="Record"></param> /// <returns></returns> ListViewItem AddRecordToListView(IEditableDbRecord Record) { ListViewItem item = new ListViewItem(); item.Text = Record.Name; item.Tag = Record; return List.Items.Add(item); }
/// <summary> /// Deletes a record from the database and removes it from the list of shown records. /// </summary> /// <param name="Record">The record to delete.</param> protected virtual bool DeleteRecord(IEditableDbRecord Record) { var args = RecordEvent.Fire(this, DeletingRecord, Record); if (!args.Continue) return false; if (Record.Delete()) { Records.Remove(Record); RecordEvent.Fire(this, DeletedRecord, Record); return true; } else { return false; } }
/// <summary> /// Select a record in the left list view. /// </summary> /// <param name="Record">The record to be selected.</param> /// <param name="EnsureVisibility">Make the list view item associated with the record visible?</param> /// <param name="EditAfterSelect">Start editing the record's name after selecting it?</param> void SelectRecord(IEditableDbRecord Record, Boolean EnsureVisibility, Boolean EditAfterSelect) { if (List.Items.Count <= 0) return; foreach (ListViewItem item in List.Items) { if ((IEditableDbRecord)item.Tag != Record) continue; SelectRecord(item, EnsureVisibility, EditAfterSelect); break; } }
/// <summary> /// Creates a new instance of the <see cref="CollectionEventArgs"/> class and initializes it with the given values. /// </summary> /// <param name="record">Reference to the record that owns the collection.</param> /// <param name="collection">Reference to the property of the record that represents the collection.</param> public CollectionEventArgs(IEditableDbRecord record, PropertyInfo collection) { this.Record = record; this.Collection = collection; }
/// <summary> /// Constructor. /// </summary> /// <param name="record">The record the collection belongs to.</param> /// <param name="property">The property of the record that represents the collections.</param> public RecordCollectionTreeNode(IEditableDbRecord record, PropertyInfo property) { this.Record = record; this.Property = property; }
/// <summary> /// Constructor. /// </summary> /// <param name="record">The record the new node should be associated with.</param> public RecordTreeNode(IEditableDbRecord record) { this.Record = record; }
/// <summary> /// Updates the tree view with changes made to a record. /// </summary> /// <param name="record">The record that has changed.</param> public virtual void RecordChanged(IEditableDbRecord record) { var key = record.Name; if (String.IsNullOrEmpty(key)) return; // Find the node of the record. var nodes = Tree.Nodes.Find(key, true); if (nodes.Length <= 0) return; // Walk through all nodes that matched the key we looked for. for (int i = 0; i < nodes.Length; i++) { var node = (RecordTreeNode)nodes[i]; // Update nodes whose record matches the one that has been changed. if (node.Record != record) continue; node.RecordChanged(); } }