Exemple #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
            };
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuItem menu  = (MenuItem)sender;
            int      index = VehicleList.ItemContainerGenerator.IndexFromContainer((VehicleList.ItemContainerGenerator.ContainerFromItem((sender as MenuItem).DataContext) as ListBoxItem));

            if (index != -1)
            {
                ViewModel.Vehicle SelectedVehicle = (ViewModel.Vehicle)VehicleList.Items[index];

                //Selected context menu item is to pin to start
                if (menu.Header.ToString().Equals("pin to start"))
                {
                    LiveTileHelper.CreateOrUpdateTile(new RadExtendedTileData()
                    {
                        Title = SelectedVehicle.Name.ToString(), BackgroundImage = new Uri("/Images/Car.png", UriKind.Relative)
                    }, new Uri("/VehicleInfo.xaml?Name=" + SelectedVehicle.Name.ToString(), UriKind.RelativeOrAbsolute));
                }
                //Selected context menu item is to delete the vehicle
                else if (menu.Header.ToString().Equals("delete"))
                {
                    RadMessageBox.Show("Delete " + SelectedVehicle.Name + "?", MessageBoxButtons.YesNo, "Are you sure you want to delete this vehicle? All information will be lost.", null,
                                       false, true, System.Windows.HorizontalAlignment.Stretch, System.Windows.VerticalAlignment.Top, closedHandler: (args) =>
                    {
                        if (args.Result == DialogResult.OK)
                        {
                            DeleteVehicle(SelectedVehicle);
                        }
                    }
                                       );
                }
            }
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddFill_Click(object sender, EventArgs e)
        {
            if (IsFillReady())
            {
                ViewModel.Vehicle _vehicle = (ViewModel.Vehicle)VehiclesList.SelectedItem;
                CreateFill(_vehicle);

                if (_isEdit)
                {
                    var _fil = from ViewModel.FillUp f in (App.Current as App).FillUps.FillUpItems where
                               f.VehicleName == EditFill.VehicleName &&
                               f.Cost == EditFill.Cost &&
                               f.Date == EditFill.Date &&
                               f.Notes == EditFill.Notes &&
                               f.Quantity == EditFill.Quantity select f;
                    (App.Current as App).FillUps.FillUpItems.DeleteAllOnSubmit(_fil);
                    (App.Current as App).FillUps.SubmitChanges();

                    (App.Current as App).FillUps.FillUpItems.InsertOnSubmit(fill);
                    (App.Current as App).FillUps.SubmitChanges();
                }
                else
                {
                    (App.Current as App).FillUps.FillUpItems.InsertOnSubmit(fill);
                }

                watcher.Stop();
                NavigationService.Navigate(new Uri("//VehicleInfo.xaml?Name=" + _vehicle.Name, UriKind.Relative));
            }
            else
            {
                MessageBox.Show("All values must be filled", "ERROR", MessageBoxButton.OK);
            }
        }
        /// <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);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void VehicleList_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (VehicleList.SelectedIndex != -1)
     {
         ViewModel.Vehicle vehicle = (ViewModel.Vehicle)VehicleList.SelectedItem;
         NavigationService.Navigate(new Uri("/VehicleInfo.xaml?Name=" + vehicle.Name, UriKind.Relative));
     }
 }
 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;
     }
 }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        public StatsTimeline(string VehicleName)
        {
            var fillItemsInDB = from ViewModel.FillUp fill in (App.Current as App).FillUps.FillUpItems where fill.VehicleName == VehicleName select fill;
            var vehicleItems  = from ViewModel.Vehicle veh in (App.Current as App).Vehicles.VehicleItems where veh.Name == VehicleName select veh;

            _fills         = new ObservableCollection <ViewModel.FillUp>(fillItemsInDB);
            _vehicle       = new ObservableCollection <ViewModel.Vehicle>(vehicleItems);
            CurrentVehicle = _vehicle[0];
            _fills.OrderByDescending(p => p.Odometer);
            _fills.Reverse();
            _fills = CalculateDistance(_fills);
        }
Exemple #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddNewFillBtn_Click(object sender, EventArgs e)
        {
            if (IsFillReady())
            {
                ViewModel.Vehicle _vehicle = (ViewModel.Vehicle)VehiclesList.SelectedItem;
                CreateFill(_vehicle);

                (App.Current as App).FillUps.FillUpItems.InsertOnSubmit(fill);
                (App.Current as App).FillUps.SubmitChanges();

                ResetControls();
            }
        }
Exemple #9
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);
        }
        /// <summary>
        ///
        /// </summary>
        private void DeleteVehicle(ViewModel.Vehicle Vehicle)
        {
            ShellTile Tile = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains("Name=" + Vehicle.Name.ToString()));

            if (Tile != null)
            {
                Tile.Delete();
            }
            var fil = from fill in (App.Current as App).FillUps.FillUpItems where fill.VehicleName == Vehicle.Name select fill;
            ObservableCollection <ViewModel.FillUp> fillDB = new ObservableCollection <ViewModel.FillUp>(fil);

            (App.Current as App).FillUps.FillUpItems.DeleteAllOnSubmit(fillDB);
            (App.Current as App).Vehicles.VehicleItems.DeleteOnSubmit(Vehicle);
            (App.Current as App).FillUps.SubmitChanges();
            (App.Current as App).Vehicles.SubmitChanges();

            var veh = from ViewModel.Vehicle vehs in (App.Current as App).Vehicles.VehicleItems select vehs;

            this.Vehicles = new ObservableCollection <ViewModel.Vehicle>(veh);
            //(App.Current as App).FillUps = fills;
            RefreshVehicleList();
        }
Exemple #11
0
        /// <summary>
        /// Add a new vehicle to data source
        /// </summary>
        /// <param name="sender">Object of event sender</param>
        /// <param name="e"> Event argument</param>
        private void AddBtn_Click(object sender, EventArgs e)
        {
            try
            {
                ViewModel.Vehicle vehicle = new ViewModel.Vehicle {
                    Name = Name_txt.Text, Make = Make_txt.Text, Model = Model_txt.Text, InitOdometer = Double.Parse(InitOdo_txt.Text)
                };

                if (Name_txt.Text != String.Empty)
                {
                    if (_vehicles.Contains(vehicle))
                    {
                        MessageBox.Show("This vehicle name already exists and cannot be duplicated. Pick a different name please.", "ERROR", MessageBoxButton.OK);
                    }
                    else
                    {
                        if (InitOdo_txt.Text != String.Empty)
                        {
                            (App.Current as App).Vehicles.VehicleItems.InsertOnSubmit(vehicle);
                            IsValueAdded = true;
                            NavigationService.Navigate(new Uri("//MainPage.xaml", UriKind.Relative));
                        }
                        else
                        {
                            MessageBox.Show("Please enter an intial odometer reading", "ERROR", MessageBoxButton.OK);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("The name of the vehicle cannot be empty", "ERROR", MessageBoxButton.OK);
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Double check your entries please. Something is wrong.", "ERROR", MessageBoxButton.OK);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="_name"></param>
        private void RefreshPage(string _name)
        {
            int i = 0;
            var FillUpItemsInDB = from ViewModel.FillUp fills in (App.Current as App).FillUps.FillUpItems where fills.VehicleName == _name select fills;
            var vehicle         = from ViewModel.Vehicle veh in (App.Current as App).Vehicles.VehicleItems where veh.Name == _name select veh;

            CurrentVehicle = vehicle.First();
            FillUpItems    = new ObservableCollection <ViewModel.FillUp>(FillUpItemsInDB);
            foreach (ViewModel.FillUp fill in FillUpItems)
            {
                if (fill.VehicleName == _name)
                {
                    break;
                }
                i++;
            }
            Index            = i;
            VehicleName.Text = _name;
            CalculateDistance();
            LoadStats();
            HistoryList.ItemsSource = FillUpItems;
            FillInfo();
        }