private void deleteSingleToolStripMenuItem_Click(object sender, EventArgs e) { if (singlesListView.SelectedItems.Count == 1) { MusicSingle single = (MusicSingle)singlesListView.SelectedItems[0].Tag; removeSingleInModel(single); OnActivated(EventArgs.Empty); } }
public void removeSingle(MusicSingle single) { int idx = singlesList.FindIndex(s => s.Title == single.Title && s.Author == single.Author && s.TrackDate == single.TrackDate); if (idx != -1) { singlesList.RemoveAt(idx); } onDeleted(new MyEventArgs(single, isNewer(single), false)); }
private ListViewItem getItem(MusicSingle single) { foreach (ListViewItem item in singlesListView.Items) { if (ReferenceEquals(single, item.Tag)) { return(item); } } return(null); }
public void editSingle(MusicSingle single, String title, String author, DateTime trackDate, MusicStyle style) { single.Title = title; single.Author = author; DateTime oldDate = single.TrackDate; single.TrackDate = trackDate; single.Style = style; bool changedGeneration = isChangedGeneration(oldDate, trackDate); onEdited(new MyEventArgs(single, isNewer(single), changedGeneration)); }
// Methods for updating appropriate form private void addedSingle(object sender, MyEventArgs e) { MusicSingle lastSingle = model.getLastSingle(); if (allCheckBox.Checked || (newerCheckBox.Checked && lastSingle.TrackDate.Year >= 2000) || (olderCheckBox.Checked && lastSingle.TrackDate.Year < 2000)) { ListViewItem item = new ListViewItem(); item.Tag = model.getLastSingle(); updateItem(item); singlesListView.Items.Add(item); } }
//To update item in ListView private void updateItem(ListViewItem item) { MusicSingle single = (MusicSingle)item.Tag; // 5 due to zeroColumn while (item.SubItems.Count < 5) { item.SubItems.Add(new ListViewItem.ListViewSubItem()); } item.SubItems[1].Text = single.Title; item.SubItems[2].Text = single.Author; item.SubItems[3].Text = single.TrackDate.ToShortDateString(); item.SubItems[4].Text = single.Style.ToString(); }
private void editSingleToolStripMenuItem_Click(object sender, EventArgs e) { if (singlesListView.SelectedItems.Count == 1) { MusicSingle single = (MusicSingle)singlesListView.SelectedItems[0].Tag; AddEditForm dialogForm = new AddEditForm(single); if (dialogForm.ShowDialog() == DialogResult.OK) { editSingleInModel(single, dialogForm.SingleTitle, dialogForm.SingleAuthor, dialogForm.SingleTrackDate, dialogForm.SingleStyle); OnActivated(EventArgs.Empty); } } }
private void deletedSingle(object sender, MyEventArgs e) { MusicSingle single = e.getSingle(); bool isNewer = e.getNewer(); if (allCheckBox.Checked || (newerCheckBox.Checked && isNewer) || (olderCheckBox.Checked && !isNewer)) { if (single != null) { ListViewItem item = getItem(single); getItem(single).Remove(); } } }
private void editedSingle(object sender, MyEventArgs e) { MusicSingle single = e.getSingle(); bool isNewerSingle = e.getNewer(); bool isChangedGeneration = e.getChangedGeneration(); if (allCheckBox.Checked) { updateItem(getItem(single)); } else { if ((newerCheckBox.Checked && isNewerSingle) || (olderCheckBox.Checked && !isNewerSingle)) { if (isChangedGeneration) { ListViewItem item = new ListViewItem(); item.Tag = single; updateItem(item); singlesListView.Items.Add(item); } else { updateItem(getItem(single)); } } else { if (isChangedGeneration) { if ((newerCheckBox.Checked && !isNewerSingle) || (olderCheckBox.Checked && isNewerSingle)) { ListViewItem item = getItem(single); item.Remove(); } } } } }
public AddEditForm(MusicSingle single) { this.single = single; this.Load += new System.EventHandler(addEditForm_Load); InitializeComponent(); }
protected void editSingleInModel(MusicSingle single, String singleTitle, String singleAuthor, DateTime singleTrackDate, MusicStyle singleStyle) { model.editSingle(single, singleTitle, singleAuthor, singleTrackDate, singleStyle); }
public MyEventArgs(MusicSingle single) { this.single = single; }
private static bool isNewer(MusicSingle single) { return(single.TrackDate.Year >= 2000); }
public void addSingle(MusicSingle single) { singlesList.Add(single); onAdded(new MyEventArgs()); }
protected void removeSingleInModel(MusicSingle single) { model.removeSingle(single); }
public MyEventArgs(MusicSingle single, bool newer, bool changedGeneration) { this.single = single; this.newer = newer; this.changedGeneration = changedGeneration; }
protected void addSingleToModel(String singleTitle, String singleAuthor, DateTime singleTrackDate, MusicStyle singleStyle) { MusicSingle newSingle = new MusicSingle(singleTitle, singleAuthor, singleTrackDate, singleStyle); model.addSingle(newSingle); }