示例#1
0
        /// <summary>
        /// Dodanie nowej stacji do bazy
        /// </summary>
        /// <param name="gasStation">Instancja klasy GasStation</param>
        /// <returns>Utworzony rekord</returns>
        public GasStation AddGasStation(GasStation gasStation)
        {
            var x = gasolineEntities.GasStations.Add(gasStation);

            gasolineEntities.SaveChanges();

            return(x);
        }
        /// <summary>
        /// Funkcja wywoływana przez przycisk
        /// </summary>
        /// <param name="sender">Źródło wywołania funkcji</param>
        /// <param name="e"></param>
        private void ViewStation_ButtonClick(object sender, System.Windows.RoutedEventArgs e)
        {
            // Numer stacji na podstawie nazwy przycisku
            string     v            = (sender as Button).Name.Replace("B", "");
            int        gasStationId = int.Parse(v);
            GasStation gs           = gasStations[gasStationId];

            // Zmiana widoku
            mainFrame.Content = new View_ViewGasStation(mainFrame, gs, _gasolineService);
        }
示例#3
0
        /// <summary>
        /// Usunięcie stacji z bazy
        /// </summary>
        /// <param name="guid">Guid usuwanej stacji</param>
        /// <returns>true jeżeli znaleziono i usunięto, false jeśli nie</returns>
        public bool RemoveGasStation(Guid guid)
        {
            GasStation gs = gasolineEntities.GasStations.FirstOrDefault(x => x.Id == guid);

            if (gs != null)
            {
                var remove = gasolineEntities.GasStations.Remove(gs);

                gasolineEntities.SaveChanges();

                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Wydarzenie po kliknięciu przycisku
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Submit_Click(object sender, RoutedEventArgs e)
        {
            GasStation gasStation = new GasStation
            {
                Id         = Guid.NewGuid(),
                Name       = station_name.Text,
                City       = station_city.Text,
                Street     = station_street.Text,
                PostalCode = station_postalcode.Text
            };

            _gasolineService.AddGasStation(gasStation);

            _mainFrame.Content = new View_GasStations(_mainFrame, _gasolineService);
        }
        /// <summary>
        /// Konstruktor klasy
        /// </summary>
        /// <param name="_mainFrame">Ramka, w której ma zostać zmieniany widok</param>
        /// <param name="_fuelType">Instancja paliwa</param>
        /// <param name="gasolineService">Serwis GasolineService</param>
        public View_FuelType(Frame _mainFrame, FuelType _fuelType, GasolineService gasolineService)
        {
            _gasolineService = gasolineService;
            mainFrame        = _mainFrame;
            fuelType         = _fuelType;

            InitializeComponent();

            List <GasStationFuel> stationWithFuel = _gasolineService.GetGasStationFuelsByFuelId(fuelType.Id);

            stationWithFuel = stationWithFuel.OrderBy(x => x.Price).ToList();

            FuelName.Content = fuelType.FuelName;

            for (int i = 0; i < stationWithFuel.Count; i++)
            {
                var        gf = stationWithFuel[i];
                GasStation gs = _gasolineService.GetGasStationById(gf.GasStationId);

                if (gs != null)
                {
                    // Utworzenie panelu, aby pogrupować stacje
                    StackPanel sp = new StackPanel();

                    // Utworzenie napisu z nazwą stacji i ceną
                    Label lbl = new Label()
                    {
                        Name = "StationName"
                    };
                    lbl.Content = gs.Name + ", " + gf.Price + " zł";
                    sp.Children.Add(lbl);

                    // Utworzenie przycisku
                    Button btn = new Button()
                    {
                        Name = "B" + i, Content = "Zobacz"
                    };
                    btn.Click += ViewStation_ButtonClick;
                    sp.Children.Add(btn);

                    // Przypisanie grupy do widoku
                    Stations.Children.Add(sp);
                }

                gasStations.Add(gs);
            }
        }
        /// <summary>
        /// Konstruktor klasy
        /// </summary>
        /// <param name="mainFrame">Referencja do głównej ramki w aplikacji w celu umożliwienia zmiany widoku/strony</param>
        /// <param name="gasolineService">Przekazanie serwisu GasolineService</param>
        public View_GasStations(Frame mainFrame, GasolineService gasolineService)
        {
            MainFrame        = mainFrame;
            _gasolineService = gasolineService;

            InitializeComponent();

            gasStations = _gasolineService.GetAllGasStations();

            GasStationParent.Children.Clear();


            // Utworzenie nowych przycisków
            for (int i = 0; i < gasStations.Count; i++)
            {
                GasStation gs = gasStations[i];

                // Utworzenie nowego napisu, wraz z nadaniem mu wartości
                System.Windows.Controls.Label newLbl = new Label
                {
                    Content = $"{gs.Name}, {gs.City}, {gs.Street}",
                    Name    = $"Label{i}"
                };

                // Utworzenie nowego przycisku, wraz z nadaniem mu wartości
                System.Windows.Controls.Button newBtn = new Button()
                {
                    HorizontalAlignment = HorizontalAlignment.Left,
                    Margin = new Thickness(newLbl.ActualWidth)
                };
                newBtn.Content = "Wyświetl";
                newBtn.Name    = $"B{i}";

                // Przypisanie handlera do przycisku
                newBtn.Click += ViewStationHandler;

                // Dodanie przycisku, oraz napisu do widoku
                GasStationParent.Children.Add(newLbl);
                GasStationParent.Children.Add(newBtn);
            }
        }
        public View_ViewGasStation(Frame mainFrame, GasStation gasStation, GasolineService gasolineService)
        {
            _gasolineService = gasolineService;
            ge        = new GasolineEntities1();
            MainFrame = mainFrame;
            InitializeComponent();

            ge = new GasolineEntities1();
            gs = gasStation;

            station_name.Content       = gs.Name;
            station_postalcode.Content = gs.PostalCode;
            station_street.Content     = gs.Street;
            station_city.Content       = gs.City;


            fuelTypes       = _gasolineService.GetAllFuelTypes();
            gasStationFuels = ge.GasStationFuels.Where(x => x.GasStationId == gs.Id).ToList();

            UpdateFuels();
        }