Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="_vehicle"></param>
        private void CreateFill(ViewModel.Vehicle _vehicle)
        {
            DateTime date = (DateTime)FillDate.Value;

            if (!LocationSwitch.IsChecked)
            {
                _lat = Double.NaN;
                _lon = Double.NaN;
            }
            else
            {
                _lat = watcher.Position.Location.Latitude;
                _lon = watcher.Position.Location.Longitude;
            }

            fill = new ViewModel.FillUp()
            {
                VehicleName = _vehicle.Name,
                Odometer    = Convert.ToInt32(Odo_txt.Text),
                Quantity    = Convert.ToDouble(Quantity_txt.Text),
                Cost        = Convert.ToDouble(Cost_txt.Text),
                Date        = date.Date.ToString(),
                Notes       = Notes_txt.Text,
                Latitude    = _lat,
                Longitude   = _lon
            };
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Override of navigation to
        /// </summary>
        /// <param name="e">Navigation event argument</param>
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            string Name;
            string index;

            if (NavigationContext.QueryString.TryGetValue("Name", out Name))
            {
                NavigationContext.QueryString.TryGetValue("Index", out index);
                _index = index;

                var fill = from ViewModel.FillUp fil in (App.Current as App).FillUps.FillUpItems where fil.VehicleName == Name select fil;
                var veh  = from ViewModel.Vehicle v in (App.Current as App).Vehicles.VehicleItems where v.Name == Name select v;
                ViewModel.Vehicle vehs = new ViewModel.Vehicle();
                vehs = veh.First();
                ObservableCollection <ViewModel.FillUp> fills = new ObservableCollection <ViewModel.FillUp>(fill);
                ViewModel.FillUp f = fills[Int32.Parse(_index)];
                CalcDistance(vehs, fills, f);
                FillControls(Name, f);

                if (Double.IsNaN(f.Latitude) || Double.IsNaN(f.Longitude))
                {
                    FillLocationMap.Visibility = System.Windows.Visibility.Collapsed;
                }
                else
                {
                    _location.Latitude     = f.Latitude;
                    _location.Longitude    = f.Longitude;
                    LocationPin.Location   = _location;
                    FillLocationMap.Center = LocationPin.Location;
                }
            }
            base.OnNavigatedTo(e);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        private void DeleteFill()
        {
            var fil = from ViewModel.FillUp fils in (App.Current as App).FillUps.FillUpItems where fils.Odometer == Int32.Parse(Odo_txt.Text) && fils.VehicleName == PageTitle.Text select fils;

            ViewModel.FillUp fill = fil.First();
            (App.Current as App).FillUps.FillUpItems.DeleteOnSubmit(fill);
            (App.Current as App).FillUps.SubmitChanges();
            NavigationService.Navigate(new Uri("/VehicleInfo.xaml?Name=" + PageTitle.Text, UriKind.Relative));
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="fill"></param>
        private void Delete(ViewModel.FillUp fill)
        {
            var fil = from ViewModel.FillUp fils in (App.Current as App).FillUps.FillUpItems where fils.Odometer == fill.Odometer && fils.VehicleName == VehicleName.Text select fils;

            ViewModel.FillUp fills = fil.First();
            (App.Current as App).FillUps.FillUpItems.DeleteOnSubmit(fills);
            (App.Current as App).FillUps.SubmitChanges();
            RefreshPage(VehicleName.Text);
        }
Ejemplo n.º 5
0
 private void FillControls(string Name, ViewModel.FillUp f)
 {
     PageTitle.Text    = Name;
     Odo_txt.Text      = f.Odometer.ToString();
     Dist_txt.Text     = f.Distance.ToString();
     Quantity_txt.Text = f.Quantity.ToString();
     Mile_txt.Text     = Math.Round((f.Distance / f.Quantity), 2).ToString();
     Cost_txt.Text     = f.Cost.ToString();
     Date_txt.Text     = f.Date.ToString();
     Notes_txt.Text    = f.Notes.ToString();
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Event when selection of history fills changes
        /// </summary>
        /// <param name="sender">Object of event sender</param>
        /// <param name="e"> Event argument</param>
        private void HistoryList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ViewModel.FillUp fill = (ViewModel.FillUp)HistoryList.SelectedItem;

            try
            {
                NavigationService.Navigate(new Uri("/ViewFill.xaml?Name=" + VehicleName.Text + "&Index=" + HistoryList.SelectedIndex.ToString(), UriKind.Relative));
                HistoryList.SelectedIndex = -1;
            }
            catch (NullReferenceException) { }
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            string index = String.Empty;

            LocationSwitch.IsChecked = (App.Current as App).LocationAware;

            var vehItemsInDB  = from ViewModel.Vehicle veh in (App.Current as App).Vehicles.VehicleItems select veh;
            var fillItemsInDB = from ViewModel.FillUp fill in (App.Current as App).FillUps.FillUpItems select fill;

            _vehicles = new ObservableCollection <ViewModel.Vehicle>(vehItemsInDB);
            _fills    = new ObservableCollection <ViewModel.FillUp>(fillItemsInDB);

            VehiclesList.ItemsSource = _vehicles;
            if (NavigationContext.QueryString.TryGetValue("Name", out index))
            {
                string isEdit = "0";
                string listIndex;
                NavigationContext.QueryString.TryGetValue("IsEdit", out isEdit);
                NavigationContext.QueryString.TryGetValue("Index", out listIndex);
                ViewModel.Vehicle veh = new ViewModel.Vehicle();
                veh.Name = index;
                VehiclesList.SelectedIndex = _vehicles.IndexOf(_vehicles.Single(vehic => vehic.Name.Equals(index)));
                _isEdit = false;
                if (isEdit == "1")
                {
                    ApplicationBarIconButton AppBtn = (ApplicationBarIconButton)ApplicationBar.Buttons[1];
                    AppBtn.IsEnabled = false;

                    _isEdit           = true;
                    ind               = int.Parse(listIndex);
                    EditFill          = _fills.FirstOrDefault(x => x.Odometer == ind);
                    Odo_txt.Text      = EditFill.Odometer.ToString();
                    Quantity_txt.Text = EditFill.Quantity.ToString();
                    Cost_txt.Text     = EditFill.Cost.ToString();
                    FillDate.Value    = DateTime.Parse(EditFill.Date);
                    Notes_txt.Text    = EditFill.Notes.ToString();
                }
                else
                {
                    EditLocationBtn.Visibility = System.Windows.Visibility.Collapsed;
                }
            }
            else
            {
                EditLocationBtn.Visibility = System.Windows.Visibility.Collapsed;
            }

            base.OnNavigatedTo(e);
        }
Ejemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="fill"></param>
 private void DeleteFill(ViewModel.FillUp fill)
 {
     RadMessageBox.Show("Delete Fill", MessageBoxButtons.OKCancel, "Are you sure you want to delete this fill? This can't be undone.",
                        null, false, true, System.Windows.HorizontalAlignment.Stretch, System.Windows.VerticalAlignment.Top, closedHandler: (args) =>
     {
         if (args.Result == DialogResult.OK)
         {
             Delete(fill);
         }
         else
         {
         }
     }
                        );
 }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ContextDelete_Click(object sender, RoutedEventArgs e)
        {
            MenuItem menu  = (MenuItem)sender;
            int      index = HistoryList.ItemContainerGenerator.IndexFromContainer((HistoryList.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem));

            if (index != -1)
            {
                ViewModel.FillUp fill = (ViewModel.FillUp)HistoryList.Items[index];
                if (menu.Header.ToString().Equals("delete"))
                {
                    try
                    {
                        DeleteFill(fill);
                    }
                    catch (NullReferenceException)
                    { }
                }
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ContextEdit_Click(object sender, RoutedEventArgs e)
        {
            MenuItem menu  = (MenuItem)sender;
            int      index = HistoryList.ItemContainerGenerator.IndexFromContainer((HistoryList.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem));

            if (index != -1)
            {
                ViewModel.FillUp fill = (ViewModel.FillUp)HistoryList.Items[index];
                if (menu.Header.ToString().Equals("edit"))
                {
                    try
                    {
                        NavigationService.Navigate(new Uri("/AddFill.xaml?Name=" + VehicleName.Text + "&IsEdit=1&Index=" + fill.Odometer.ToString(), UriKind.Relative));
                    }
                    catch (NullReferenceException)
                    { }
                }
            }
        }
Ejemplo n.º 11
0
 private void CalcDistance(ViewModel.Vehicle vehs, ObservableCollection <ViewModel.FillUp> fills, ViewModel.FillUp f)
 {
     if (_index.Equals("0"))
     {
         f.Distance = fills[Int32.Parse(_index)].Odometer - vehs.InitOdometer;
     }
     else
     {
         f.Distance = fills[Int32.Parse(_index)].Odometer - fills[Int32.Parse(_index) - 1].Odometer;
     }
 }