Ejemplo n.º 1
0
        private async void OkButtonClicked(object sender, EventArgs e)
        {
            wateringEventViewModel = new WateringEventViewModel();
            WateringStationViewModel wateringStationViewModel = new WateringStationViewModel();
            string wateringStationFullName = pickerRelayPanelStationNumber.Items[pickerRelayPanelStationNumber.SelectedIndex];
            bool   existingStation         = await wateringStationViewModel.RetrieveWateringStation(Int32.Parse(wateringStationFullName.Substring(0, wateringStationFullName.IndexOf(" "))));

            if (existingStation)
            {
                wateringEventViewModel.stationFullName = wateringStationViewModel.FullName;
                wateringEventViewModel.wateringTime    = Int32.Parse(stepperWateringTimeValue.Text);
                wateringEventViewModel.startTime       = tpickerStartTime.Time.ToString();
                wateringEventViewModel.sunday          = switchSunday.On;
                wateringEventViewModel.monday          = switchMonday.On;
                wateringEventViewModel.tuesday         = switchTuesday.On;
                wateringEventViewModel.wednesday       = switchWednesday.On;
                wateringEventViewModel.thursday        = switchThursday.On;
                wateringEventViewModel.friday          = switchFriday.On;
                wateringEventViewModel.saturday        = switchSaturday.On;
                bool stationAdded = await wateringEventViewModel.SaveWateringEvent();

                if (stationAdded)
                {
                    await DisplayAlert("Info", string.Concat("Event added."), "OK");
                }
            }
            else
            {
                await DisplayAlert("Error", string.Concat("Error loading station."), "OK");
            }
            await Navigation.PopAsync();
        }
Ejemplo n.º 2
0
 public AddEditWateringStationModalPage(WateringStationViewModel wateringStationViewModel)
 {
     InitializeComponent();
     entryRelayPanelStationNumber.Text = wateringStationViewModel.Number.ToString();
     entryWateringStationName.Text     = wateringStationViewModel.Name;
     stepperWateringTimeValue.Text     = wateringStationViewModel.WateringTime.ToString();
     stepperWateringTime.Value         = Int32.Parse(stepperWateringTimeValue.Text);
 }
Ejemplo n.º 3
0
        private async void DeleteButtonClicked(object sender, EventArgs e)
        {
            wateringStationViewModel = new WateringStationViewModel(Int32.Parse(entryRelayPanelStationNumber.Text));
            bool stationDeleted = await wateringStationViewModel.DeleteWateringStation();

            if (stationDeleted)
            {
                await DisplayAlert("Info", string.Concat("Station ", wateringStationViewModel.FullName, " deleted."), "OK");
            }
            await Navigation.PopAsync();
        }
Ejemplo n.º 4
0
        private async void OnItemToggled(object sender, ToggledEventArgs e)
        {
            try
            {
                serviceActivityIndicator.IsRunning = true;
                SwitchCell toggledSwitch      = (SwitchCell)sender;
                string     stationID          = toggledSwitch.Text.Substring(0, toggledSwitch.Text.IndexOf(" "));
                WateringStationViewModel wsvm = new WateringStationViewModel(int.Parse(stationID));
                bool stationActive            = await App.restService.GetSwitchStateAsync(stationID);

                bool switchOn = toggledSwitch.On;
                if (!stationActive && switchOn)
                {
                    stationActive = await App.restService.ActivateSwitchAsync(stationID);

                    Device.StartTimer(new TimeSpan(0, 0, 0, 0, wsvm.WateringTime * 60 * 100), () =>
                    {
                        Device.BeginInvokeOnMainThread(async() =>
                        {
                            await wateringProgressBar.ProgressTo(wateringProgressBar.Progress + 0.1, 1000, Easing.SinOut);
                        });
                        if (wateringProgressBar.Progress == 1)
                        {
                            toggledSwitch.On = false;
                            return(false);
                        }
                        else
                        {
                            return(true);
                        }
                    });
                    await DisplayAlert("Info", string.Concat("Station ", stationID, " activated"), "OK");
                }
                else if (stationActive && !switchOn)
                {
                    stationActive = await App.restService.ActivateSwitchAsync(stationID);

                    wateringProgressBar.Progress = 0.0;
                    await DisplayAlert("Info", string.Concat("Station ", stationID, " deactivated"), "OK");
                }
                serviceActivityIndicator.IsRunning = false;
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", String.Concat("Failed to connect to Relay Panel - ", ex.Message), "Ok");
            }
            finally
            {
                serviceActivityIndicator.IsRunning = false;
            }
        }
Ejemplo n.º 5
0
        private async void OkButtonClicked(object sender, EventArgs e)
        {
            wateringStationViewModel              = new WateringStationViewModel(Int32.Parse(entryRelayPanelStationNumber.Text));
            wateringStationViewModel.Number       = Int32.Parse(entryRelayPanelStationNumber.Text);
            wateringStationViewModel.Name         = entryWateringStationName.Text;
            wateringStationViewModel.WateringTime = Int32.Parse(stepperWateringTimeValue.Text);
            bool stationAdded = await wateringStationViewModel.SaveWateringStation();

            if (stationAdded)
            {
                await DisplayAlert("Info", string.Concat("Station ", wateringStationViewModel.FullName, " added."), "OK");
            }
            await Navigation.PopAsync();
        }
Ejemplo n.º 6
0
        private async void EditButtonClicked(object sender, EventArgs e)
        {
            SwitchCell toggledSwitch = (SwitchCell)sender;
            string     stationID     = toggledSwitch.Text.Substring(0, toggledSwitch.Text.IndexOf(" "));
            WateringStationViewModel selectedStation = new WateringStationViewModel();
            bool stationFound = await selectedStation.RetrieveWateringStation(Int32.Parse(stationID));

            if (stationFound)
            {
                await Navigation.PushAsync(new AddEditWateringStationModalPage(selectedStation));

                //stationsList.ItemsSource = await AllWateringStationViewModel.RetrieveWateringStationsAsync();
            }
            else
            {
                await DisplayAlert("Error", string.Concat("Failed to locate station ", stationID, " on the database"), "OK");
            }
        }