private void LvAMAEntries_SelectionChanged(object sender, SelectionChangedEventArgs e) { AMACardEntry old = null; if (lvAMAEntries.SelectedIndex == -1) { return; } btnLoadData.Visibility = Visibility.Collapsed; BtnAddEntry.Visibility = Visibility.Collapsed; if (e.RemovedItems.Count > 0) { old = e.RemovedItems[0] as AMACardEntry; } if (e.AddedItems.Count > 0) { } ; if (EditMode) { var result = MessageBox.Show("You are currently editting a record. If you leave now changes will be lost. Press OK to continue. Press Cancel to stay on the current page and continue editing.", "Undo Changes", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { EditMode = false; BtnUpdate.Visibility = Visibility.Collapsed; var entry = (sender as ListView).SelectedItem as AMACardEntry; BtnClear.Visibility = Visibility.Visible; BtnDelete.Visibility = Visibility.Visible; SetUIElementsToCardData(entry); } else if (old != null) { lvAMAEntries.SelectionChanged -= LvAMAEntries_SelectionChanged; lvAMAEntries.SelectedIndex = old.RowNumber - 1; lvAMAEntries.SelectionChanged += LvAMAEntries_SelectionChanged; } } else { var entry = (sender as ListView).SelectedItem as AMACardEntry; BtnClear.Visibility = Visibility.Visible; BtnDelete.Visibility = Visibility.Visible; SetUIElementsToCardData(entry); } }
private void BtnScanData_Click(object sender, RoutedEventArgs e) { var window = new CardSwipeView() { Owner = this, WindowStartupLocation = WindowStartupLocation.CenterOwner }; window.ShowDialog(); var data = window.DataString; if (data?.Length >= 101) { try { var entry = AMACardEntry.ParseEntryFromCardData(data, vm.Entries.Count + 1); int nextRiderNumber = 1; var last = vm.Entries.LastOrDefault(); if (last != null && int.TryParse(last.RiderNumber, out int result)) { nextRiderNumber = result + 1; } entry.RiderNumber = nextRiderNumber.ToString(); SetUIElementsToCardData(entry); rbDualSport.IsChecked = true; rbNone.IsChecked = true; } catch { MessageBox.Show("There was a problem trying to parse your card data. Please try reading again."); } } }
private void ReadFile() { ClearUIScreen(); vm.Entries.Clear(); var data = File.ReadAllText(vm.FilePath); if (!string.IsNullOrWhiteSpace(data)) { var listOfEntries = data.Split('\r'); int index = 1; bool error = false; foreach (var csvRow in listOfEntries) { try { var entry = AMACardEntry.ParseEntryFromCSVRow(csvRow, index++); vm.Entries.Add(entry); } catch { error = true; } } UpdateEntryStatistics(); if (error) { MessageBox.Show("There was an error while trying to read this CSV File. Some rows may not have loaded."); } } //outerGrid.Visibility = Visibility.Visible; }
private void SetUIElementsToCardData(AMACardEntry entry) { ClearUIScreen(false); if (entry != null) { vm.SelectedEntry = entry; /* * txtFirstName.Text = entry.Firstname; * txtLastName.Text = entry.Lastname; * txtAddress.Text = entry.Address; * txtCity.Text = entry.City; * txtState.Text = entry.State; * txtZipcode.Text = entry.Zipcode; * txtAMANumber.Text = entry.AMACardNumber; * txtExpiration.Text = entry.Expiration; * txtRideNumber.Text = entry.RiderNumber; * txtEmail.Text = entry.Email; * txtPhoneNumber.Text = entry.Phone; * txtYear.Text = entry.Year; * txtAmount.Text = entry.PaidAmount; * txtCC.Text = entry.CC; * txtNumBarbecue.Text = entry.Barbecue; * txtNumShirts.Text = entry.TShirt; * txtAMAAmount.Text = entry.AMAPaidAmount; * //*/ double value = 0; if (Double.TryParse(entry.PaidAmount, out double dabbersPaid)) { if (Double.TryParse(entry.AMAPaidAmount, out double amaPaid)) { value = dabbersPaid + amaPaid; } else { value = dabbersPaid; } } else if (Double.TryParse(entry.AMAPaidAmount, out double amaPaid)) { value = amaPaid; } txtCombinedPayment.Text = $"${value.ToString()}"; if (entry.RideType == "Dual Sport") { rbDualSport.IsChecked = true; } else if (entry.RideType == "Adventure") { rbAdventure.IsChecked = true; } if (entry.AMAPaidAmount == "49.00") { rbAnnual.IsChecked = true; } else if (entry.AMAPaidAmount == "20.00") { rb1Day.IsChecked = true; } else { rbNone.IsChecked = true; } checkboxDay1.IsChecked = entry.Day1 == "X"; checkboxDay2.IsChecked = entry.Day2 == "X"; checkboxCamping.IsChecked = entry.Camping == "X"; foreach (ComboBoxItem comboitem in cbPaymentMethod.Items) { if (comboitem.Content.ToString() == entry.MannerOfPayment) { cbPaymentMethod.SelectedValue = comboitem; } } var vehicleMakeMatch = vm.Vehicles.FirstOrDefault(x => x.Name == entry.Make); if (vehicleMakeMatch == null) { cbMake.SelectedIndex = -1; cbMake.Text = entry.Make; cbModels.SelectedIndex = -1; cbModels.Text = entry.Model; return; } else { cbMake.SelectedItem = vehicleMakeMatch; } var vehicleModelMatch = vehicleMakeMatch.Models.FirstOrDefault(x => x == entry.Model); if (vehicleModelMatch == null) { cbModels.SelectedIndex = -1; cbModels.Text = entry.Model; } else { cbModels.SelectedItem = vehicleModelMatch; } } }