コード例 #1
0
        private void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "XML files (*.xml)|*.xml";
            DialogResult dr = ofd.ShowDialog(this);
            if (dr == DialogResult.OK)
            {
                // Now we need to verify the xml data.
                Stream file = ofd.OpenFile();
                ChapterInfo[] chapters = ParseXMLChapterInfo(file);
                file.Close();

                if (chapters.Length == 0)
                {
                    // If the file is not valid...
                    // Display error message.
                    MessageBox.Show(this, "There were no valid chapter found in the selected file.");
                    return;
                }
                else
                {
                    // If the file is good...
                    // Are there any chapters currently in the window?
                    if (chapterCount != 0)
                    {
                        // Yes, ask user if they would like to save.
                        string result = PromptDialog.Show(
                            "Data Exists",
                            "Data is already populated in the table. What would you like to do?",
                            new string[] { "Discard", "Save", "Merge", "Cancel" });
                        if (result == "Cancel")
                        {
                            return;
                        }
                        if (result == "Save")
                        {
                            if (SaveCurrentChapters() == false)
                                return;
                            ClearAllChapters();
                        }
                        if (result == "Merge")
                        {
                            MergeDialog dlg = new MergeDialog(chapters[0].Title != "", chapters[0].StartTime != "" || chapters[0].Duration != "", chapters[0].UID != "");
                            DialogResult res = dlg.ShowDialog();
                            if (res == DialogResult.Cancel)
                            {
                                return;
                            }
                            else
                            {
                                // Get the current chapter info data.
                                ChapterInfo[] currentChapters = GetCurrentChapters();
                                int numChapters = Math.Max(currentChapters.Length, chapters.Length);
                                ChapterInfo[] newChapters = new ChapterInfo[numChapters];

                                // Find out what needs to be merged...
                                for (int i = 0; i < numChapters; i++)
                                {
                                    if (i < currentChapters.Length)
                                    {
                                        newChapters[i] = new ChapterInfo(currentChapters[i].Title, currentChapters[i].StartTime, currentChapters[i].Duration, currentChapters[i].UID);
                                    }
                                    else
                                    {
                                        newChapters[i] = new ChapterInfo(chapters[i].Title, chapters[i].StartTime, chapters[i].Duration, chapters[i].UID);
                                    }

                                    if (i < chapters.Length)
                                    {
                                        if (dlg.UseTimeStamps == true)
                                        {
                                            newChapters[i].StartTime = chapters[i].StartTime;
                                            newChapters[i].Duration = chapters[i].Duration;
                                        }
                                        if (dlg.UseTitles == true)
                                        {
                                            newChapters[i].Title = chapters[i].Title;
                                        }
                                        if (dlg.UseUIDs == true)
                                        {
                                            newChapters[i].UID = chapters[i].UID;
                                        }
                                    }
                                }

                                ClearAllChapters();
                                AddChapters(newChapters);
                                return;
                            }
                        }
                        if (result == "Discard")
                        {
                            // Clear all chapters from the window.
                            ClearAllChapters();
                        }
                    }

                    // Load the chapters from the new file into the display window.
                    AddChapters(chapters);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Handles data from a drag and drop operation. It is
        /// expected that this will be chapter information from
        /// Barnes & Noble.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_DragDrop(object sender, DragEventArgs e)
        {
            string data = (string)e.Data.GetData(typeof(string));
            ChapterInfo[] chapters = ParseDragDropData(data);
            this.Activate();

            if (chapters != null && chapters.Length == 0)
            {
                // If the file is not valid...
                // Display error message
                MessageBox.Show(this, "There were no valid chapter found.");
                return;
            }
            else
            {
                // If the file is good...
                // Are there any chapters currently in the window?
                if (chapterCount != 0)
                {
                    // Yes, ask user if they would like to save.
                    string result = PromptDialog.Show(
                            "Data Exists",
                            "Data is already populated in the table. What would you like to do?",
                            new string[] { "Discard", "Save", "Merge", "Cancel" });
                    if (result == "Cancel")
                    {
                        return;
                    }
                    if (result == "Save")
                    {
                        if (SaveCurrentChapters() == false)
                            return;
                        ClearAllChapters();
                    }
                    if (result == "Merge")
                    {
                        MergeDialog dlg = new MergeDialog(chapters[0].Title != "", chapters[0].StartTime!="" || chapters[0].Duration != "", chapters[0].UID != "");
                        DialogResult res = dlg.ShowDialog();
                        if (res == DialogResult.Cancel)
                        {
                            return;
                        }
                        else
                        {
                            // Get the current chapter info data.
                            ChapterInfo[] currentChapters = GetCurrentChapters();
                            int numChapters = Math.Max(currentChapters.Length, chapters.Length);
                            ChapterInfo[] newChapters = new ChapterInfo[numChapters];

                            // Find out what needs to be merged...
                            for (int i = 0; i < numChapters; i++)
                            {
                                if (i < currentChapters.Length)
                                {
                                    newChapters[i] = new ChapterInfo(currentChapters[i].Title, currentChapters[i].StartTime, currentChapters[i].Duration, currentChapters[i].UID);
                                }
                                else
                                {
                                    newChapters[i] = new ChapterInfo(chapters[i].Title, chapters[i].StartTime, chapters[i].Duration, chapters[i].UID);
                                }

                                if (i < chapters.Length)
                                {
                                    if (dlg.UseTimeStamps == true)
                                    {
                                        newChapters[i].StartTime = chapters[i].StartTime;
                                        newChapters[i].Duration = chapters[i].Duration;
                                    }
                                    if (dlg.UseTitles == true)
                                    {
                                        newChapters[i].Title = chapters[i].Title;
                                    }
                                    if (dlg.UseUIDs == true)
                                    {
                                        newChapters[i].UID = chapters[i].UID;
                                    }
                                }
                            }

                            ClearAllChapters();
                            AddChapters(newChapters);
                            return;
                        }
                    }
                    if (result == "Discard")
                    {
                        // Clear all chapters from the window.
                        ClearAllChapters();
                    }
                }

                // Load the chapters from the new file into the display window.
                AddChapters(chapters);
            }
        }