private bool TagsFilter(object x)
        {
            if (!IsFavouritesMode)
            {
                return(true);
            }

            PartViewModel part = (PartViewModel)x;

            string[] tokens    = m_searchField.ToUpper().Split(' ');
            string   upperName = (part.Name == null ? string.Empty : part.Name.ToUpper());

            foreach (var item in tokens)
            {
                var result = part.Tags.FirstOrDefault(tag => tag.Value.ToUpper().StartsWith(item));
                if (result == null)
                {
                    if (!upperName.Contains(item))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        public EditPartViewModel(PartViewModel part)
            : this()
        {
            m_part = part;

            m_isCustom = m_part.Custom;

            ApplyData();
        }
        private void AddCustom(object param)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();

            openFileDialog.Filter      = Global.PdfFilter;
            openFileDialog.Multiselect = true;
            openFileDialog.ShowDialog(Global.Dialogs.GetWindow(this));
            foreach (var fileName in openFileDialog.FileNames)
            {
                if (string.IsNullOrWhiteSpace(fileName) || !File.Exists(fileName))
                {
                    continue;
                }

                bool          add  = true;
                PartViewModel part = null;

                if (openFileDialog.FileNames.Length == 1) // if there is only one pdf to add, open window to edit properties of it
                {
                    EditPartViewModel dialogViewModel = new EditPartViewModel(openFileDialog.FileName);
                    Global.Dialogs.ShowDialog(this, dialogViewModel);
                    if (dialogViewModel.Result != EditPartViewModel.EditPartResult.Ok)
                    {
                        add = false;
                    }
                    else
                    {
                        part = dialogViewModel.Part;
                    }
                }
                else // if more then just add it
                {
                    part = PartViewModel.MakeCustom(fileName);
                    File.Copy(fileName, part.CustomPath);
                }

                if (add)
                {
                    m_searchResults.Add(part);
                    m_savedParts.Add(part);
                    part.LastUseDate = DateTime.MinValue;

                    ActionDialogViewModel actionDialogViewModel = new ActionDialogViewModel(part.ComputePagesCount(), Global.GetStringResource("StringCountingPages"));
                    Global.Dialogs.ShowDialog(this, actionDialogViewModel);
                }
            }

            m_filteredResults.Refresh();
        }
 private void AddResults(List <AllDataSheetPart> results)
 {
     foreach (var item in results)
     {
         PartViewModel viewModel = PartViewModel.FromAllDataSheetPart(item);
         PartViewModel found     = m_savedParts.FirstOrDefault(x => x.Code == viewModel.Code);
         if (found != null)
         {
             viewModel = found;
         }
         PartViewModel.GetDownloadingIfExists(viewModel.Code, ref viewModel);
         if (viewModel.Context.OnlyContext)
         {
             viewModel.Context = item;
         }
         viewModel.LoadImage();
         m_searchResults.Add(viewModel);
     }
 }
        private async void AddToFavourites(object param)
        {
            if (m_selectedResult == null)
            {
                return;
            }

            if (m_selectedResult.State == PartDatasheetState.Saved)
            {
                if (Global.MessageBox(this, Global.GetStringResource("StringDoYouWantToRemoveFromFavourites"), MessageBoxExPredefinedButtons.YesNo) != MessageBoxExButton.Yes)
                {
                    return;
                }
                m_selectedResult.RemovePdf();
                m_savedParts.Remove(m_selectedResult);
                if (IsFavouritesMode)
                {
                    m_searchResults.Remove(m_selectedResult);
                    Global.SaveSavedParts();
                }
                return;
            }

            try
            {
                ActionsCount++;
                PartViewModel part = m_selectedResult;
                await part.SavePdf();

                m_savedParts.Add(part);
                Global.SaveSavedParts();
            }
            catch
            {
                Global.MessageBox(this, Global.GetStringResource("StringDownloadError"), MessageBoxExPredefinedButtons.Ok);
            }
            finally
            {
                ActionsCount--;
            }
        }
 public EditPartViewModel(string originalPath)
     : this(PartViewModel.MakeCustom(originalPath))
 {
     m_addingOriginalPath = originalPath;
 }