public EditionDatabaseInfoModificationViewModel() { All.AddRange(MagicDatabase.GetAllEditionsOrdered()); ResetBlockCommand = new RelayCommand(ResetBlockExecute, ResetBlockCanExecute); Blocks = MagicDatabase.GetAllBlocks().ToArray(); Title = "Manage Edition"; }
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(null); } int idGatherer = System.Convert.ToInt32(value); if (idGatherer == 0) { return(null); } BitmapImage image = GetImage(idGatherer.ToString()); if (image != null) { return(image); } byte[] bytes = MagicDatabase.GetPicture(idGatherer)?.Image; if (null != bytes && bytes.Length != 0) { return(BytesToImage(bytes, idGatherer.ToString())); } return(GetDefaultCardImage()); }
protected override string ToLine(IImportExportCardCount cardCount) { //Ignore AltArt if (cardCount == null || (cardCount.FoilNumber == 0 && cardCount.Number == 0)) { return(null); } ICard card = MagicDatabase.GetCard(cardCount.IdGatherer); IEdition edition = MagicDatabase.GetEdition(cardCount.IdGatherer); if (card == null || edition == null) { throw new ImportExportException("Can't find card with IdGatherer={0}", cardCount.IdGatherer); } string ret = string.Empty; if (cardCount.Number > 0) { ret += string.Format("{0}#{1}#{2}#False\n", card, edition.AlternativeCode(Format), cardCount.Number); } if (cardCount.FoilNumber > 0) { ret += string.Format("{0}#{1}#{2}#True\n", card, edition.AlternativeCode(Format), cardCount.FoilNumber); } return(ret); }
protected override bool ApplyEditionToDatabase() { foreach (TranslationViewModel translation in AllTranslations.Where(t => t.Modified)) { MagicDatabase.UpdateTranslate(Selected, translation.Language, translation.Translation); } return(true); }
public TranslateDatabaseInfoModificationViewModel() { AllTranslations = new ObservableCollection <TranslationViewModel>(); All.AddRange(MagicDatabase.GetAllInfos().GetAllCardsOrderByTranslation(null).Select(kv => kv.Value)); _notUpdatableLanguages = new[] { MagicDatabase.GetDefaultLanguage(), MagicDatabase.GetEnglishLanguage() }; _allLanguages = MagicDatabase.GetAllLanguages().Where(l => !_notUpdatableLanguages.Contains(l)).ToArray(); Title = "Manage Translate"; }
protected override IImportExportCardCount ParseLine(string line) { Match m = _regLine.Match(line); if (!m.Success) { return(new ErrorImportExportCardInfo(line, "Can't parse line")); } int count = 0; int foilCount = 0; if (!int.TryParse(m.Groups["Count"].Value, out int tmpcount) || tmpcount <= 0) { return(new ErrorImportExportCardInfo(line, "Invalid value for count")); } if (m.Groups["Foil"].Value.ToUpper() == "TRUE") { foilCount = tmpcount; } else { count = tmpcount; } ICard card = MagicDatabase.GetCard(m.Groups["Name"].Value, null); if (card == null) { return(new ErrorImportExportCardInfo(line, string.Format("Can't find card named {0}", m.Groups["Name"].Value))); } IEdition edition = MagicDatabase.GetEditionFromCode(m.Groups["Edition"].Value); if (edition == null) { return(new ErrorImportExportCardInfo(line, string.Format("Can't find edition named {0}", m.Groups["Edition"].Value))); } int idGatherer = MagicDatabase.GetIdGatherer(card, edition); if (idGatherer == 0) { return(new ErrorImportExportCardInfo(line, string.Format("Can't find gatherer id for card {0} edition {1}", card, edition))); } CardCount cardCount = new CardCount { { CardCountKeys.Standard, count }, { CardCountKeys.Foil, foilCount } }; return(new ImportExportCardInfo(idGatherer, cardCount, 0)); }
protected override IImportExportCardCount ParseLine(string line) { Match m = _regLine.Match(line); if (!m.Success) { return(new ErrorImportExportCardInfo(line, "Can't parse line")); } if (!int.TryParse(m.Groups["IdGatherer"].Value, out int idGatherer) || MagicDatabase.GetCard(idGatherer) == null) { return(new ErrorImportExportCardInfo(line, "Invalid IdGatherer")); } if (!int.TryParse(m.Groups["Count"].Value, out int count) || count < 0) { return(new ErrorImportExportCardInfo(line, "Invalid Count")); } if (!int.TryParse(m.Groups["FoilCount"].Value, out int foilCount) || foilCount < 0) { return(new ErrorImportExportCardInfo(line, "Invalid FoilCount")); } int altArtCount = 0; string sAltArtCount = m.Groups["AltArtCount"].Value; if (!string.IsNullOrWhiteSpace(sAltArtCount)) { if (!int.TryParse(m.Groups["AltArtCount"].Value, out altArtCount) || altArtCount < 0) { return(new ErrorImportExportCardInfo(line, "Invalid AltArtCount")); } } int foilAltArtCount = 0; string sFoilAltArtCount = m.Groups["FoilAltArtCount"].Value; if (!string.IsNullOrWhiteSpace(sFoilAltArtCount)) { if (!int.TryParse(m.Groups["FoilAltArtCount"].Value, out foilAltArtCount) || foilAltArtCount < 0) { return(new ErrorImportExportCardInfo(line, "Invalid FoilAltArtCount")); } } if (!int.TryParse(m.Groups["Language"].Value, out int idLanguage) || MagicDatabase.GetLanguages(idGatherer).All(l => l.Id != idLanguage)) { return(new ErrorImportExportCardInfo(line, "Invalid idLanguage")); } CardCount cardCount = new CardCount { { CardCountKeys.Standard, count }, { CardCountKeys.Foil, foilCount }, { CardCountKeys.AltArt, altArtCount }, { CardCountKeys.FoilAltArt, foilAltArtCount } }; return(new ImportExportCardInfo(idGatherer, cardCount, idLanguage)); }
public CardUpdateViewModel(string collectionName, ICard card) : base(collectionName) { _editions = MagicDatabase.GetAllEditionIncludingCardOrdered(card) .ToArray(); Source = new CardSourceViewModel(MagicDatabase, SourceCollection, card); EditionSelected = Source.EditionSelected; Display.Title = "Update infos"; }
protected override bool ApplyEditionToDatabase() { if (Selected == null) { return(false); } MagicDatabase.UpdateEdition(Selected, GathererName, Name, HasFoil, Code, Block == null ? (int?)null : Block.Id, BlockPosition, CardNumber, ReleaseDate); All.Clear(); All.AddRange(MagicDatabase.GetAllEditionsOrdered()); return(true); }
protected override bool ApplyEditionToDatabase() { if (Selected == null) { MagicDatabase.InsertNewLanguage(Name, AlternativeName); } else { MagicDatabase.UpdateLanguage(Selected, Name, AlternativeName); } All.Clear(); All.AddRange(MagicDatabase.GetAllLanguages()); return(true); }
protected override bool ApplyEditionToDatabase() { if (Selected == null) { MagicDatabase.InsertNewBlock(Name); } else { MagicDatabase.UpdateBlock(Selected, Name); } All.Clear(); All.AddRange(MagicDatabase.GetAllBlocks()); return(true); }
public CardMoveOrCopyViewModel(string collectionName, ICard card, bool copy) : base(collectionName) { Source = new CardSourceViewModel(MagicDatabase, SourceCollection, card); Copy = copy; _collections = MagicDatabase.GetAllCollections().ToArray(); if (_collections.Length > 0) { if (SourceCollection != _collections[0] || _collections.Length == 1) { CardCollectionSelected = _collections[0]; } else { CardCollectionSelected = _collections[1]; } } }
public override object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is not string data) { return(null); } BitmapImage image = GetImage(data); if (image != null) { return(image); } byte[] bytes = MagicDatabase.GetTreePicture(data)?.Image; if (null != bytes && bytes.Length > 0) { return(BytesToImage(bytes, data)); } return(null); }
public LanguageDatabaseInfoModificationViewModel() { All.AddRange(MagicDatabase.GetAllLanguages()); Title = "Manage Language"; }
private void ChangeDestinationLanguage() { int idGatherer = MagicDatabase.GetIdGatherer(Source.Card, EditionSelected); Languages = MagicDatabase.GetLanguages(idGatherer).ToArray(); }
public BlockDatabaseInfoModificationViewModel() { All.AddRange(MagicDatabase.GetAllBlocks()); Title = "Manage Block"; }