Exemple #1
0
        private void LoadSelectionDetails(int scrollAt = -1)
        {
            if (tvSeries.SelectedNode == null)
            {
                return;                                //why??
            }
            try
            {
                Cursor = Cursors.WaitCursor;
                pSeriesDetailsContainer.SuspendLayout();

                var seShortInfo = (SeriesEpisodesShortInfo)tvSeries.SelectedNode.Tag;

                var opRes = DAL.LoadMTD(seShortInfo.Id, seShortInfo.IsEpisode);

                if (!opRes.Success)
                {
                    MsgBox.Show(string.Format("The following error occurred while loading the file details:{0}{0}{1}", Environment.NewLine, opRes.CustomErrorMessage),
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (seShortInfo.IsSeason || seShortInfo.IsSeries)
                {
                    //when moving focus from EpisodeDetail to SeasonDetail, the "ucEpisodeDetails" must be removed
                    var prevInstance = pSeriesDetailsContainer.Controls.Find("ucEpisodeDetails", false);
                    if (prevInstance.Any())
                    {
                        pSeriesDetailsContainer.Controls.Remove(prevInstance[0]);
                    }

                    //attempting to reuse the "ucEditSeriesBaseInfo" user control
                    prevInstance = pSeriesDetailsContainer.Controls.Find("ucEditSeriesBaseInfo", false);

                    if (prevInstance.Any())
                    {
                        ((ucEditSeriesBaseInfo)prevInstance[0]).RefreshControls();
                    }
                    else
                    {
                        pSeriesDetailsContainer.Controls.Add(new ucEditSeriesBaseInfo(false)
                        {
                            Dock = DockStyle.Top
                        });
                    }

                    prevInstance = pSeriesDetailsContainer.Controls.Find("ucSeriesEpisodes", false);

                    //attempting to reuse the "ucSeriesEpisodes" user control
                    if (prevInstance.Any())
                    {
                        ((ucSeriesEpisodes)prevInstance[0]).LoadControls(seShortInfo);
                    }
                    else
                    {
                        if (!_isFiltered)
                        {
                            var ucSeriesEpisodes = new ucSeriesEpisodes(seShortInfo, this)
                            {
                                Dock = DockStyle.Top
                            };
                            pSeriesDetailsContainer.Controls.Add(ucSeriesEpisodes);
                            ucSeriesEpisodes.BringToFront();
                        }
                    }

                    _prevSelectedSeriesId = seShortInfo.Id;
                }
                else
                {
                    //when moving focus from SeasonDetail to EpisodeDetail, the "ucSeriesEpisodes" must be removed
                    var prevInstance = pSeriesDetailsContainer.Controls.Find("ucSeriesEpisodes", false);
                    if (prevInstance.Any())
                    {
                        pSeriesDetailsContainer.Controls.Remove(prevInstance[0]);
                    }

                    //attempting to reuse the "ucEditSeriesBaseInfo" user control
                    prevInstance = pSeriesDetailsContainer.Controls.Find("ucEditSeriesBaseInfo", false);
                    if (prevInstance.Any())
                    {
                        pSeriesDetailsContainer.Controls.Remove(prevInstance[0]);
                    }


                    var seriesNode = tvSeries.AllNodes.FirstOrDefault(x => ((SeriesEpisodesShortInfo)x.Tag).Id == seShortInfo.SeriesId && ((SeriesEpisodesShortInfo)x.Tag).IsSeries);
                    var seriesName = seriesNode == null
                        ? "unknown !!!"
                        : ((SeriesEpisodesShortInfo)seriesNode.Tag).FileName;

                    prevInstance = pSeriesDetailsContainer.Controls.Find("ucEpisodeDetails", false);
                    if (prevInstance.Any())
                    {
                        ((ucEpisodeDetails)prevInstance[0]).LoadControls(seShortInfo.Id, null, seriesName);
                    }
                    else
                    {
                        var ucEpisodeDetails = new ucEpisodeDetails(seShortInfo.Id, _prevSelectedSeriesId, seriesName)
                        {
                            Dock = DockStyle.Top
                        };
                        pSeriesDetailsContainer.Controls.Add(ucEpisodeDetails);
                        ucEpisodeDetails.BringToFront();
                    }
                }
            }
            finally
            {
                if (scrollAt > -1)
                {
                    pSeriesDetailsContainer.VerticalScroll.Value = scrollAt;
                }

                pSeriesDetailsContainer.ResumeLayout();
                Cursor = Cursors.Default;
            }
        }
        private void LoadSelectionDetails(int scrollAt = -1)
        {
            if (tvCollections.SelectedNode == null)
            {
                return;                                     //why??
            }
            try
            {
                Cursor = Cursors.WaitCursor;
                DrawingControl.SuspendDrawing(pCollectionElementDetailsContainer);

                var seShortInfo      = (SeriesEpisodesShortInfo)tvCollections.SelectedNode.Tag;
                var isElementSeleted = tvCollections.SelectedNode.Level == 2;

                btnImportElements.Enabled = !isElementSeleted;
                btnLoadPoster.Enabled     =
                    (!isElementSeleted /*&& (CollectionsSiteSectionType)seShortInfo.SectionType == CollectionsSiteSectionType.SeriesType*/) ||
                    (isElementSeleted && (CollectionsSiteSectionType)seShortInfo.SectionType == CollectionsSiteSectionType.MovieType);
                btnRefreshElementData.Enabled = isElementSeleted;
                btnDeleteElement.Enabled      = isElementSeleted; //the collection is deleted by action in the main form toolbar


                btnAddMovieToCollection.Enabled = (CollectionsSiteSectionType)seShortInfo.SectionType == CollectionsSiteSectionType.MovieType;

                if (!isElementSeleted) //collection level
                {
                    ////when moving focus from ElementDetail to CollectionDetail, the "ucCollectionElements" must be removed
                    //var prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucCollectionElements", false);
                    //if (prevInstance.Any())
                    //    pCollectionElementDetailsContainer.Controls.Remove(prevInstance[0]);

                    //attempting to reuse the "ucCollectionInfo" user control
                    var prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucCollectionInfo", false);

                    if (seShortInfo.Poster == null /*&& (CollectionsSiteSectionType)seShortInfo.SectionType == CollectionsSiteSectionType.SeriesType*/)
                    {
                        seShortInfo.Poster = DAL.GetPoster(seShortInfo.Id);
                    }

                    if (prevInstance.Any())
                    {
                        ((ucCollectionInfo)prevInstance[0]).RefreshControls(seShortInfo);
                    }
                    else
                    {
                        if (pCollectionElementDetailsContainer.Controls.Count > 0)
                        {
                            pCollectionElementDetailsContainer.Controls.Clear();
                        }

                        var baseInfoControl = new ucCollectionInfo()
                        {
                            Dock = DockStyle.Top
                        };
                        baseInfoControl.ParentEl = pCollectionElementDetailsContainer;
                        baseInfoControl.RefreshControls(seShortInfo);

                        pCollectionElementDetailsContainer.Controls.Add(baseInfoControl);
                    }

                    prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucCollectionElements", false);

                    //attempting to reuse the "ucSeriesEpisodes" user control
                    if (prevInstance.Any())
                    {
                        ((ucCollectionElements)prevInstance[0]).LoadControls(seShortInfo);
                        pCollectionElementDetailsContainer.Invalidate();
                    }
                    else
                    {
                        if (!_isFiltered)
                        {
                            var ucCollectionElements = new ucCollectionElements(seShortInfo, this)
                            {
                                Dock = DockStyle.Top
                            };
                            pCollectionElementDetailsContainer.Controls.Add(ucCollectionElements);
                            ucCollectionElements.BringToFront();
                        }
                    }

                    _prevSelectedSeriesId = seShortInfo.Id;
                }
                else
                {
                    var opRes = DAL.LoadMTD(seShortInfo.Id, true);

                    if (!opRes.Success)
                    {
                        MsgBox.Show(string.Format("The following error occurred while loading the file details:{0}{0}{1}", Environment.NewLine, opRes.CustomErrorMessage),
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    var prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucCollectionElements", false);
                    if (prevInstance.Any())
                    {
                        pCollectionElementDetailsContainer.Controls.Clear();
                    }

                    switch ((CollectionsSiteSectionType)seShortInfo.SectionType)
                    {
                    case CollectionsSiteSectionType.MovieType:

                        prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucEpisodeDetails", false);
                        if (prevInstance.Any())
                        {
                            pCollectionElementDetailsContainer.Controls.Remove(prevInstance[0]);
                        }

                        prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucMovieInfo", false);

                        if (prevInstance.Any())
                        {
                            ((ucMovieInfo)prevInstance[0]).RefreshControls(DAL.CurrentMTD);
                        }
                        else
                        {
                            var ucMovieInfo = new ucMovieInfo(false)
                            {
                                Dock = DockStyle.Top
                            };
                            ucMovieInfo.RefreshControls(DAL.CurrentMTD);

                            pCollectionElementDetailsContainer.Controls.Add(ucMovieInfo);
                            ucMovieInfo.BringToFront();
                        }

                        break;

                    case CollectionsSiteSectionType.SeriesType:
                        prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucMovieInfo", false);
                        if (prevInstance.Any())
                        {
                            pCollectionElementDetailsContainer.Controls.Remove(prevInstance[0]);
                        }

                        prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucEpisodeDetails", false);

                        if (prevInstance.Any())
                        {
                            ((ucEpisodeDetails)prevInstance[0]).LoadControls(seShortInfo.Id, null, "aaaa");
                        }
                        else
                        {
                            var seriesNode = tvCollections.AllNodes.FirstOrDefault(x => ((SeriesEpisodesShortInfo)x.Tag).Id == seShortInfo.SeriesId && ((SeriesEpisodesShortInfo)x.Tag).IsSeries);
                            var seriesName = seriesNode == null
                                    ? "unknown !!!"
                                    : ((SeriesEpisodesShortInfo)seriesNode.Tag).FileName;

                            var ucEpisodeDetails = new ucEpisodeDetails(seShortInfo.Id, seShortInfo.SeriesId, seriesName)
                            {
                                Dock = DockStyle.Top
                            };

                            pCollectionElementDetailsContainer.Controls.Add(ucEpisodeDetails);
                            ucEpisodeDetails.BringToFront();
                        }

                        break;
                    }
                }

                /*
                 * var prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucCollectionInfo", false);
                 *
                 * if (!isElementSeleted)
                 * {
                 *  if (prevInstance.Any())
                 *  {
                 *      ((ucCollectionInfo)prevInstance[0]).RefreshControls(seShortInfo);
                 *  }
                 *  else
                 *  {
                 *      prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucMovieInfo", false);
                 *      if (prevInstance.Any())
                 *          pCollectionElementDetailsContainer.Controls.Remove(prevInstance[0]);
                 *
                 *      prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucEpisodeDetails", false);
                 *      if (prevInstance.Any())
                 *          pCollectionElementDetailsContainer.Controls.Remove(prevInstance[0]);
                 *
                 *      var ucCol = new ucCollectionInfo() { Dock = DockStyle.Top };
                 *      ucCol.RefreshControls(seShortInfo);
                 *
                 *      pCollectionElementDetailsContainer.Controls.Add(ucCol);
                 *  }
                 * }
                 * else
                 * {
                 *  if (prevInstance.Any()) //the CollectionInfo UserControl
                 *      pCollectionElementDetailsContainer.Controls.Remove(prevInstance[0]);
                 *
                 *  var opRes = DAL.LoadMTD(seShortInfo.Id, true);
                 *
                 *  if (!opRes.Success)
                 *  {
                 *      MsgBox.Show(string.Format("The following error occurred while loading the file details:{0}{0}{1}", Environment.NewLine, opRes.CustomErrorMessage),
                 *          "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 *      return;
                 *  }
                 *
                 *
                 *  prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucCollectionInfo", false);
                 *
                 *  switch ((CollectionsSiteSectionType)seShortInfo.SectionType)
                 *  {
                 *      case CollectionsSiteSectionType.MovieType:
                 *
                 *          prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucEpisodeDetails", false);
                 *          if (prevInstance.Any())
                 *              pCollectionElementDetailsContainer.Controls.Remove(prevInstance[0]);
                 *
                 *          prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucMovieInfo", false);
                 *
                 *          if (prevInstance.Any())
                 *              ((ucMovieInfo)prevInstance[0]).RefreshControls(DAL.CurrentMTD);
                 *          else
                 *          {
                 *              var ucMovieInfo = new ucMovieInfo(false) { Dock = DockStyle.Top };
                 *              ucMovieInfo.RefreshControls(DAL.CurrentMTD);
                 *
                 *              pCollectionElementDetailsContainer.Controls.Add(ucMovieInfo);
                 *              ucMovieInfo.BringToFront();
                 *          }
                 *
                 *          break;
                 *
                 *      case CollectionsSiteSectionType.SeriesType:
                 *          prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucMovieInfo", false);
                 *          if (prevInstance.Any())
                 *              pCollectionElementDetailsContainer.Controls.Remove(prevInstance[0]);
                 *
                 *          prevInstance = pCollectionElementDetailsContainer.Controls.Find("ucEpisodeDetails", false);
                 *
                 *          if (prevInstance.Any())
                 *              ((ucEpisodeDetails)prevInstance[0]).LoadControls(seShortInfo.Id, null, "aaaa");
                 *          else
                 *          {
                 *              var seriesNode = tvCollections.AllNodes.FirstOrDefault(x => ((SeriesEpisodesShortInfo)x.Tag).Id == seShortInfo.SeriesId && ((SeriesEpisodesShortInfo)x.Tag).IsSeries);
                 *              var seriesName = seriesNode == null
                 *                  ? "unknown !!!"
                 *                  : ((SeriesEpisodesShortInfo)seriesNode.Tag).FileName;
                 *
                 *              var ucEpisodeDetails = new ucEpisodeDetails(seShortInfo.Id, seShortInfo.SeriesId, seriesName) { Dock = DockStyle.Top };
                 *
                 *              pCollectionElementDetailsContainer.Controls.Add(ucEpisodeDetails);
                 *              ucEpisodeDetails.BringToFront();
                 *          }
                 *
                 *          break;
                 *  }
                 * }
                 */
            }
            finally
            {
                if (scrollAt > -1)
                {
                    pCollectionElementDetailsContainer.VerticalScroll.Value = scrollAt;
                }

                SetSaveButtonState(false);

                DrawingControl.ResumeDrawing(pCollectionElementDetailsContainer);
                pCollectionElementDetailsContainer.PerformLayout(); //to refresh the vertical scrollbar

                Cursor = Cursors.Default;
            }
        }