public MainWindow() { InitializeComponent(); _vm = new MainWindowViewModel(); bool openFirstRunWindow = false; try { if (!string.IsNullOrEmpty(Options.CurrentUserOptions.DatabaseFileName)) { OpenDatabase(Options.CurrentUserOptions.DatabaseFileName, false, true); } else { openFirstRunWindow = true; } } catch (Exception ex) { Trace.WriteLine(ex); MessageBox.Show("There was a problem opening the database. It may have been moved or deleted.\n\n" + "Please use Open Database to find an existing database, or use New Database to create a new one.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } DatabaseGrid.SetFilter(this.FilterListView); StateChanged += MainWindowStateChangeRaised; this.DataContext = _vm; // Sort by ID code when the window first opens if (_vm.DarwinDatabase != null) { DatabaseGrid.Sort("IDCode", ListSortDirection.Ascending); } Loaded += delegate { SelectFirstFin(); }; if (openFirstRunWindow) { ContentRendered += delegate { var firstRunVM = new FirstRunViewModel(); var firstRunWindow = new FirstRunWindow(firstRunVM); firstRunWindow.Owner = this; firstRunWindow.ShowDialog(); }; } }
private void NextButton_Click(object sender, RoutedEventArgs e) { if (DatabaseGrid.Items == null || DatabaseGrid.Items.Count < 1) { return; } if (DatabaseGrid.SelectedIndex < DatabaseGrid.Items.Count - 1) { DatabaseGrid.SelectedIndex++; DatabaseGrid.ScrollIntoView(_vm.SelectedResult); } CheckNextPreviousEnabled(); }
private void ListPreviousButton_Click(object sender, RoutedEventArgs e) { if (DatabaseGrid.Items == null || DatabaseGrid.Items.Count < 1) { return; } if (DatabaseGrid.SelectedIndex > 0) { DatabaseGrid.SelectedIndex--; DatabaseGrid.ScrollIntoView(_vm.SelectedFin); } CheckNextPreviousEnabled(); }
public void RefreshDatabaseAfterAdd() { Trace.WriteLine("Start database refresh after add..."); _vm.Fins = new ObservableNotifiableCollection <DatabaseFin>( _vm.DarwinDatabase .GetAllFins() .Select(x => { x.ThumbnailFilename = x.ImageFilename; return(x); }) .ToList()); // Select the last fin, and scroll to it so the user can see it if (_vm.Fins != null) { Trace.WriteLine("Selecting added individual..."); _vm.SelectedFin = _vm.Fins[_vm.Fins.Count - 1]; DatabaseGrid.ScrollIntoView(_vm.SelectedFin); } Trace.WriteLine("Refresh complete."); }
private void SelectFirstFin() { if (DatabaseGrid.Items != null && DatabaseGrid.Items.Count > 0) { DatabaseGrid.SelectedIndex = 0; if (_vm.SelectedFin != null) { DatabaseGrid.ScrollIntoView(_vm.SelectedFin); } } else if (_vm.Fins?.Count > 0) { _vm.SelectedFin = _vm.Fins[0]; } else { _vm.SelectedFin = null; } }
private void AutoScrollTimer_Tick(object sender, EventArgs e) { if (_vm.AutoScroll && _vm.MatchResults?.Results?.Count > 0) { if (_vm.SelectedResult == null) { _vm.SelectedResult = _vm.MatchResults.Results[0]; } else { if (DatabaseGrid.SelectedIndex < DatabaseGrid.Items.Count - 1) { DatabaseGrid.SelectedIndex++; } else { DatabaseGrid.SelectedIndex = 0; } DatabaseGrid.ScrollIntoView(_vm.SelectedResult); CheckNextPreviousEnabled(); } } }
private void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e) { DatabaseGrid.RefreshFilter(); }
private void DatabaseFieldsGrid_Shown(object sender, EventArgs e) { int i; StoredStuff = new string[Dimensioned, Dimensioned]; openFileDialog1.InitialDirectory = Directory.GetCurrentDirectory(); DatabaseGrid.Columns.Add("Field Code", -2, HorizontalAlignment.Left); DatabaseGrid.Columns.Add("Field Code Description", -2, HorizontalAlignment.Left); DatabaseGrid.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize); XmlDocument doc = new XmlDocument(); try { doc.Load(@"DatabaseFields"); foreach (XmlNode node in doc.DocumentElement.ChildNodes) { foreach (XmlNode Cnode in node) { if (node.Name == "LastPath") { openFileDialog1.InitialDirectory = node.InnerText; } } } } catch { } DialogResult result = openFileDialog1.ShowDialog(); if (result != DialogResult.OK) { Close(); return; } FileToUse = openFileDialog1.FileName; DatabaseName.Text = Path.GetFileNameWithoutExtension(@FileToUse); XmlDocument Data = new XmlDocument(); XmlNode DataNode = Data.CreateXmlDeclaration("1.0", "UTF-8", null); Data.AppendChild(DataNode); XmlNode DataNodeRoot; XmlNode DataNodeNode; DataNodeRoot = Data.CreateElement("DataBaseFieldsDocumentation"); Data.AppendChild(DataNodeRoot); DataNodeNode = Data.CreateElement("LastPath"); DataNodeNode.AppendChild(Data.CreateTextNode(Path.GetDirectoryName(FileToUse))); DataNodeRoot.AppendChild(DataNodeNode); Data.Save("DataBaseFields"); try { doc.Load(@FileToUse); DatabaseName.Text = Path.GetFileNameWithoutExtension(@FileToUse); LastStoredStuff = 0; foreach (XmlNode node in doc.DocumentElement.ChildNodes) { ComboboxItem item = new ComboboxItem(); item.Text = node.Name; item.Value = LastStoredStuff; LastStoredStuff++; Fields.Items.Add(item); i = 0; foreach (XmlNode Cnode in node) { StoredStuff[LastStoredStuff - 1, i] = Cnode.Attributes.GetNamedItem("Code").Value; StoredStuff[LastStoredStuff - 1, i + 1] = Cnode.FirstChild.InnerText; i = i + 2; } } if (Fields.Items.Count > 0) { Fields.SelectedIndex = 0; } } catch { } Save.Enabled = false; }
private void MatchWork(object sender, DoWorkEventArgs e) { if (_vm.MatchingQueue.Fins.Count < 1) { return; } bool done = false; _vm.MatchingQueue.MatchRunning = true; int currentIndex = 0; do { if (_matchingWorker.CancellationPending) { e.Cancel = true; done = true; _vm.MatchingQueue.MatchRunning = false; } else if (_vm.PauseMatching) { // Sleep for a small amount of time Thread.Sleep(100); } else { // TODO: Put this logic inside the MatchingQueue class? if (_vm.MatchingQueue.Matches.Count < currentIndex + 1) { switch (_vm.MatchingQueue.Database.CatalogScheme.FeatureSetType) { case Features.FeatureSetType.DorsalFin: _vm.MatchingQueue.Matches.Add(new Match( _vm.MatchingQueue.Fins[currentIndex], _vm.MatchingQueue.Database, null, _vm.MatchingQueue.RegistrationMethod, (_vm.MatchingQueue.RangeOfPoints == RangeOfPointsType.AllPoints) ? true : false)); break; case Features.FeatureSetType.Bear: _vm.MatchingQueue.Matches.Add(new Match( _vm.MatchingQueue.Fins[currentIndex], _vm.MatchingQueue.Database, null, null, true)); break; default: throw new NotImplementedException(); } // This needs to run on the UI thread since it affects dependency objects Dispatcher.BeginInvoke(new Action(() => { _vm.SelectedFin = _vm.MatchingQueue.Fins[currentIndex]; DatabaseGrid.ScrollIntoView(_vm.SelectedFin); }), DispatcherPriority.Background); } // Do Work float percentComplete = _vm.MatchingQueue.Matches[currentIndex].MatchSingleIndividual(_vm.MatchingQueue.Database.Categories.ToList()); int roundedProgress = (int)Math.Round(percentComplete * 100); _vm.CurrentUnknownPercent = roundedProgress; var totalProgress = (int)Math.Round(((float)currentIndex / _vm.MatchingQueue.Fins.Count + percentComplete / _vm.MatchingQueue.Fins.Count) * 100); _vm.QueueProgressPercent = totalProgress; _matchingWorker.ReportProgress(roundedProgress); if (percentComplete >= 1.0) { //***1.5 - sort the results here, ONCE, rather than as list is built _vm.MatchingQueue.Matches[currentIndex].MatchResults.Sort(); if (currentIndex >= _vm.MatchingQueue.Fins.Count - 1) { _vm.SaveMatchResults(); done = true; _vm.MatchingQueue.MatchRunning = false; } else { currentIndex++; } } } } while (!done); }