コード例 #1
0
        // dataGridView
        private void dataGridView_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e)
        {
            EpisodeEntry entry = episodes[e.RowIndex] as EpisodeEntry;

            if (entry == null)
            {
                return;
            }

            e.PaintParts &= ~DataGridViewPaintParts.Background;

            // Determine whether the cell should be painted
            // with the custom background.
            if (entry.GetEntryType() != EpisodeEntry.EntryType.None)
            {
                // Calculate the bounds of the row.
                Rectangle rowBounds = new Rectangle(
                    0,
                    e.RowBounds.Top,
                    dataGridView.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dataGridView.HorizontalScrollingOffset + 1,
                    e.RowBounds.Height);

                // Paint the custom background.
                Color color;
                switch (entry.GetEntryType())
                {
                case EpisodeEntry.EntryType.Green:
                    color = Color.Green;
                    break;

                case EpisodeEntry.EntryType.Red:
                    color = Color.Red;
                    break;

                case EpisodeEntry.EntryType.Yellow:
                    color = Color.Yellow;
                    dataGridView.Rows[e.RowIndex].DefaultCellStyle.SelectionForeColor = Color.Red;
                    break;

                case EpisodeEntry.EntryType.Gray:
                    color = Color.LightGray;
                    break;

                case EpisodeEntry.EntryType.Blue:
                    color = Color.LightBlue;
                    break;

                default:
                    color = Color.Cyan;
                    break;
                }

                e.Graphics.FillRectangle(new SolidBrush(color), rowBounds);
            }
        }
コード例 #2
0
        private void dataGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            EpisodeEntry entry = episodes[e.RowIndex] as EpisodeEntry;

            if (entry == null)
            {
                return;
            }

            // Determine whether the cell should be painted
            // with the custom foreground.
            if ((entry.GetEntryType() != EpisodeEntry.EntryType.None) && !entry.Enabled)
            {
                // Calculate the bounds of the row.
                Rectangle rowBounds = new Rectangle(
                    0,
                    e.RowBounds.Top,
                    dataGridView.Columns.GetColumnsWidth(DataGridViewElementStates.Visible) - dataGridView.HorizontalScrollingOffset + 1,
                    e.RowBounds.Height);

                Color c1 = Color.FromArgb(160, Color.Gray);
                Color c2 = Color.FromArgb(200, Color.Gray);
                Brush br = new HatchBrush(HatchStyle.Weave, c2, c1);
                e.Graphics.FillRectangle(br, rowBounds);
            }
        }
コード例 #3
0
        /// <summary>
        /// Matches the episode names in <paramref name="lines"/> to <see cref="EpisodeEntry"/> objects in <see cref="episodes"/>
        /// </summary>
        /// <param name="lines">The lines to match</param>
        /// <returns><value>false</value> in case <paramref name="lines"/> is <value>null</value> or empty, otherwise true.</returns>
        bool ReadNames(string[] lines)
        {
            int count = 0;

            if ((lines == null) || (lines.Length < 1))
            {
                return(false);
            }

            Regex post = null;

            if (chkPostReplace.Checked)
            {
                try {
                    post = new Regex(txtSearch.Text, chkIgnoreCase.Checked ? RegexOptions.IgnoreCase : RegexOptions.None);
                } catch (ArgumentException ex) {
                    Trace.WriteLine("ArgumentException in ReadNames: Regex constructor");
                    Trace.WriteLine(ex.Message);

                    post = null;
                }
            }

            foreach (string line in lines)
            {
                int    season;
                int    episode;
                string name;

                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                if (count >= episodes.Count)
                {
                    break;
                }

                // Extract season number, episode number and episode name from line
                ExtractEpisodeInformation(line, out season, out episode, out name);

                // No name, continue with next line
                if (string.IsNullOrWhiteSpace(name))
                {
                    continue;
                }

                // Either IMDb or generic syntax matched the line and at least an episode name could be extracted
                // so search for the corresponding EpisodeEntry and save the data

                EpisodeEntry e = null;
                Point        p;

                // Only episode name
                if (season < 0 || episode < 0)
                {
                    // No episode numbers, so take the next element in the list
                    e = (EpisodeEntry)episodes[count];

                    // If the episode information is set in the EpisodEentry object, take that one, otherwise guess
                    p = new Point(
                        e.EpisodeNumber.X,
                        e.EpisodeNumber.Y < 0 ? count : e.EpisodeNumber.Y);
                }                 // Episode name and numbers
                else
                {
                    p = new Point(season, episode);

                    // Find the EpisodeEntry corresponding to the episode number extracted
                    foreach (object o in episodes)
                    {
                        EpisodeEntry tmp = (EpisodeEntry)o;

                        if (tmp.EpisodeNumber == p)
                        {
                            e = tmp;
                            break;
                        }
                    }

                    // Episode not found, continue with next line
                    if (e == null)
                    {
                        continue;
                    }
                }

                if (chkUseFolderName.Checked)
                {
                    e.Series = folderName;
                }
                else
                {
                    e.ResetSeries();
                }

                e.NewNameString = line.Trim();
                e.NewFilename   = EpisodeEntry.FormatFilename(e.Series, p, name, Path.GetExtension(e.OldFilename));

                try {
                    if (post != null)
                    {
                        e.NewFilename = post.Replace(e.NewFilename, txtReplace.Text);
                    }
                } catch (Exception ex) {
                    Trace.WriteLine("Exception (" + ex.GetType() + ") in ReadNames: regex replace.");
                    Trace.WriteLine(ex.Message);
                    Trace.WriteLine(ex.StackTrace);

                    post = null;
                }

                e.Enabled = (e.GetEntryType() != EpisodeEntry.EntryType.Yellow);
                count++;
            }

            UpdateGridView();
            return(count > 0);
        }