private void btnUse_Click(object sender, EventArgs e) { if (lviewChapters.SelectedItems.Count == 0) { ChosenChapter = (ChapterDBAccess.ChapterSet)dgViewResults.SelectedRows[0].Cells[2].Value; } else { //User has selected only a few of the chapters of the selected set //Check if he already set a chapter as base if (lviewChapters.SelectedItems[0].SubItems[1].Text != "00:00:00") { //He hasn't (I guess), prompt him DialogResult result = MessageBox.Show("You have selected only a part of the chapters,\r\ndo you want to recalculate their times so the earliest selected is the base (00:00:00)? " + "\r\n\r\nTo preview how it will look, click cancel then right click the chapter you want as base and select \"Use as base\".", "Part selection", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question); if (result == DialogResult.Yes) { //Save all selected indexes int[] selectedIndexes = new int[lviewChapters.SelectedIndices.Count]; lviewChapters.SelectedIndices.CopyTo(selectedIndexes, 0); LoadChapters(ReCalcBase(LoadedChapterSet, lviewChapters.SelectedIndices[0])); //Now selected all the previously selected items foreach(int i in selectedIndexes) { lviewChapters.Items[i].Selected = true; } } else if(result == DialogResult.Cancel) { return; } } ChapterDBAccess.ChapterSet newSet = new ChapterDBAccess.ChapterSet(); foreach(ListViewItem item in lviewChapters.SelectedItems) { newSet.Chapters.Add(new ChapterDBAccess.Chapter(item.Text, TimeSpan.Parse(item.SubItems[1].Text))); } ChosenChapter = newSet; } DialogResult = DialogResult.OK; Close(); }
private void LoadChapters(ChapterDBAccess.ChapterSet chapterSet) { LoadedChapterSet = chapterSet; lviewChapters.Items.Clear(); foreach (ChapterDBAccess.Chapter chapter in chapterSet) { string time = chapter.Time.ToString(); if (chapter.Time.ToString().Length >= 12) { time = time.Remove(12); } lviewChapters.Items.Add(new ListViewItem(new string[] {chapter.Name, time})); } lblSelected.Text = string.Format("You have selected {0} chapters", chapterSet.Chapters.Count); }
private void btnSearch_Click(object sender, EventArgs e) { ChapterDB chapterDB = new ChapterDB(); ChapterDBAccess.ChapterSet result = chapterDB.ShowDialog(txtSearch.Text); if (result != null) { chapterSet = result; } }
/// <summary> /// Creates a chapter set. /// </summary> /// <param name="runtime">The runtime of the movie in seconds.</param> /// <param name="interval">The interval in seconds.</param> /// <returns></returns> public ChapterDBAccess.ChapterSet CreateChapterSet(int runtime, int interval) { ChapterDBAccess.ChapterSet newChapterSet = new ChapterDBAccess.ChapterSet(); ChapterDBAccess.Chapter chapter; decimal count = runtime / interval; int start; int extraval = 0; int[] time = {00, 00, 00}; if (ExtraChapterStart) { chapter = new ChapterDBAccess.Chapter(); chapter.Time = TimeSpan.Parse(time[0] + ":" + time[1] + ":" + time[2]); chapter.Name = CustomChapterName.Replace("%N", "1").Replace("%T", string.Format("{0:00}:{1:00}:{2:00}", (int)chapter.Time.TotalHours, chapter.Time.Minutes, chapter.Time.Seconds)); newChapterSet.Chapters.Add(chapter); extraval = 1; } for (start = 0 + extraval; start <= count; start++) { time[2] += interval; while (time[2] >= 60) { time[2] -= 60; time[1] += 1; } while (time[1] >= 60) { time[1] -= 60; time[0] += 1; } chapter = new ChapterDBAccess.Chapter(); chapter.Time = TimeSpan.Parse(time[0] + ":" + time[1] + ":" + time[2]); chapter.Name = CustomChapterName.Replace("%N", Convert.ToString(start + 1)).Replace("%T", string.Format("{0:00}:{1:00}:{2:00}", (int)chapter.Time.TotalHours, chapter.Time.Minutes, chapter.Time.Seconds)); newChapterSet.Chapters.Add(chapter); } if (ExtraChapterEnd) { int hours = 0; int minutes = 0; int seconds = runtime; while (seconds >= 60) { seconds -= 60; minutes += 1; } while (minutes >= 60) { minutes -= 60; hours += 1; } chapter = new ChapterDBAccess.Chapter(); chapter.Time = TimeSpan.Parse(hours.ToString() + ":" + minutes.ToString() + ":" + seconds.ToString()); chapter.Name = CustomChapterName.Replace("%N", Convert.ToString(start + 1)).Replace("%T", string.Format("{0:00}:{1:00}:{2:00}", (int)chapter.Time.TotalHours, chapter.Time.Minutes, chapter.Time.Seconds)); } return newChapterSet; }
private void txtSearch_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode != Keys.Enter) { return; } e.SuppressKeyPress = true; ChapterDB chapterDB = new ChapterDB(); ChapterDBAccess.ChapterSet result = chapterDB.ShowDialog(txtSearch.Text); if (result != null) { chapterSet = result; } }