Beispiel #1
0
        private async void IniciarSesion()
        {
            var page = new Page();
            try
            {
                IsBusy = true;
                var us = await _servicio.ValidarUsuario(_login);

                if (us != null)
                {
                    await _navigator.PopToRootAsync();
                    await _navigator.PushAsync<ContactosViewModel>(viewModel =>
                    {
                        Titulo = "Inicio de sesión";
                    });
                }
                else
                {
                    var xx = ""; //para comprobar que se haga bien.
                }

                //TODO: aquí navegaríamos a la pantalla principal o daríamos error
                await page.DisplayAlert(Strings.Error, Strings.UserDoesNotExist, Strings.Ok);
            }
            catch (Exception e)
            {
                await page.DisplayAlert(Strings.Error, e.Message, Strings.Ok);
            }
            finally
            {
                IsBusy = false;
            }
        }
 private async void GuardarUser()
 {
     _user.Avatar = "";
     var page = new Page();
     try
     {
         IsBusy = true;
         var r = await _servicio.AddUsuario(_user);
         if (r != null)
         {
             await page.DisplayAlert(Strings.UserCreatedTitle, 
                 Strings.UserCreatedText, Strings.Ok);
             await _navigator.PushModalAsync<LoginViewModel>();
         }
         else
         {
             var a = "";
         }
     }
     catch (Exception e)
     {
         
         await page.DisplayAlert(Strings.Error, Strings.UserAlreadyText, Strings.Ok);
     }
     finally
     {
         IsBusy = false;
     }
 }
		public FundsTransferViewModel (INavigation navigation, Page currentPage)
		{
			Navigation = navigation;
			CancelCommand = new Command(async () => await Navigation.PopAsync());
			TransferCommand = new Command(async () => await currentPage.DisplayAlert("Transfer", "Success", "Ok"));

		}
        //public void testIfString<T>(ref T var)
        //{
        //    string aString = "string";


        //    if (var.GetType() == aString.GetType())
        //    {

        //    }
        //}

        public void ErrorMessager(string messageBox)
        {
            Xamarin.Forms.Page ourPage = App.Current.MainPage.Navigation.NavigationStack.LastOrDefault();
            if (ourPage != null)
            {
                ourPage.DisplayAlert("Error", messageBox, "Ok");
            }
        }
        public static void AddToolBarItems(Xamarin.Forms.Page page)
        {
            Action action = () => page.DisplayAlert(Title, Message, Dismiss);

            page.ToolbarItems.Add(new ToolbarItem("Primary 1", "reminders.png", action, ToolbarItemOrder.Primary));
            page.ToolbarItems.Add(new ToolbarItem("Primary 2", "reminders.png", action, ToolbarItemOrder.Primary));
            page.ToolbarItems.Add(new ToolbarItem("Secondary 1", "reminders.png", action, ToolbarItemOrder.Secondary));
            page.ToolbarItems.Add(new ToolbarItem("Secondary 2", "reminders.png", action, ToolbarItemOrder.Secondary));
        }
        public async void Show(Page callingPage)
        {
            RateFeedbackResult result = RateFeedbackResult.None;

            await Task.Delay(1);
     
           // var rateAnswer = await callingPage.DisplayAlert(RateMessageTitle, RateMessage, RateButtonLabel, RateCancelLabel);

            callingPage.DisplayAlert(RateMessageTitle, RateMessage, RateButtonLabel, RateCancelLabel).ContinueWith(r =>
            {
                if (r.Result)
                {
                    IAppRater rater = DependencyService.Get<IAppRater>();
                    rater.RateApp(this.AppId);
                    result = RateFeedbackResult.Rate;

                    this.RateFeedbackCompleted(callingPage, new RateFeedbackEventArgs(result));
                }
                else
                {
                  //  var feedbackAnswer = await callingPage.DisplayAlert(FeebackMessageTitle, FeebackMessage, FeebackButtonLabel, FeebackCancelLabel);
                    callingPage.DisplayAlert(FeebackMessageTitle, FeebackMessage, FeebackButtonLabel, FeebackCancelLabel).ContinueWith(f =>
                    {
                        if (f.Result)
                        {
                            IEmailComposer emailer = DependencyService.Get<IEmailComposer>();
                            emailer.SendEmail(FeedbackEmail, FeedbackSubject, FeedbackBody);
                            result = RateFeedbackResult.Feedback;

                            this.RateFeedbackCompleted(callingPage, new RateFeedbackEventArgs(result));
                        }
                        else
                        {
                            this.RateFeedbackCompleted(callingPage, new RateFeedbackEventArgs(result));
                        }
                    }, TaskScheduler.FromCurrentSynchronizationContext()
                    );
                }
            }, TaskScheduler.FromCurrentSynchronizationContext()
            ); 

        }
        public static Layout CreateAddRemoveToolbarItemButtons(Xamarin.Forms.Page page)
        {
            Action action = () => page.DisplayAlert(Title, Message, Dismiss);

            var primaryButton = new Button {
                Text = "Add Primary", BackgroundColor = Color.Gray
            };

            primaryButton.Clicked += (sender, e) =>
            {
                int index = page.ToolbarItems.Count(item => item.Order == ToolbarItemOrder.Primary) + 1;
                page.ToolbarItems.Add(new ToolbarItem(string.Format("Primary {0}", index), "reminders.png", action, ToolbarItemOrder.Primary));
            };

            var secondaryButton = new Button {
                Text = "Add Secondary", BackgroundColor = Color.Gray
            };

            secondaryButton.Clicked += (sender, e) =>
            {
                int index = page.ToolbarItems.Count(item => item.Order == ToolbarItemOrder.Secondary) + 1;
                page.ToolbarItems.Add(new ToolbarItem(string.Format("Secondary {0}", index), "reminders.png", action, ToolbarItemOrder.Secondary));
            };

            var removeButton = new Button {
                Text = "Remove", BackgroundColor = Color.Gray
            };

            removeButton.Clicked += (sender, e) =>
            {
                if (page.ToolbarItems.Any())
                {
                    page.ToolbarItems.RemoveAt(0);
                }
            };

            return(new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.Center,
                Children = { primaryButton, secondaryButton, removeButton }
            });
        }
        public ListenerBindView(int defaultPort, Page parentPage)
        {
            _parentPage = parentPage;

            var portEntry = new Entry()
            {
                Placeholder = "Listen Port",
                Text = defaultPort.ToString(),
                HorizontalOptions = LayoutOptions.Start
            };

            var listenButton = new Button
            {
                Text = "Start Listening",
            };


            // listen / stop listening 
            listenButton.Clicked += async (sender, args) => 
            {
                // if not already listening
                if (!_listening)
                {
                    if (StartListeningTapped == null) return;

                    // check valid port
                    var port = -1;
                    var isNumeric = Int32.TryParse(portEntry.Text, out port);

                    if (!isNumeric || ((port < 1001 || port > 65535)))
                    {
                        await _parentPage.DisplayAlert("Invalid Port", "Port must be numeric value between 1001 & 65535", "My bad");
                        return;
                    }

                    // callback
                    if (await StartListeningTapped(port))
                    {
                        _listening = true;
                        listenButton.Text = "Stop Listening";
                    };
                }
                else
                {
                    if (StopListeningTapped == null) return;

                    // callback
                    await StopListeningTapped();
                    _listening = false;
                    listenButton.Text = "Start Listening";
                }
                
            };

            Content = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children =
                {
                    new Label { 
                        Text = "Listen port:", 
                        VerticalOptions = LayoutOptions.CenterAndExpand 
                    },
                    portEntry, 
                    listenButton
                }
            };
        }
		public static void InformUser(Page page, string message)
		{
			page.DisplayAlert ("Information", message, "OK");
		}
		public static void WarnUser(Page page, string warning)
		{
			page.DisplayAlert ("Warning", warning, "OK");
		}
		public static void WarnUser(Page page, Exception e)
		{
			page.DisplayAlert ("Exception encountered", e.ToString(), "OK");
		}
Beispiel #12
0
        public void exportXMLData(Xamarin.Forms.Page page)
        {
            var directory = new Java.IO.File(Android.OS.Environment.ExternalStorageDirectory, "OMIKAS_Raports").ToString();

            try
            {
                if (App.DAUtil.GetAllAlloys().Any())
                {
                    var xml = new XElement("Alloys", App.DAUtil.GetAllAlloys().Select(x => new XElement("Alloy",
                                                                                                        new XAttribute("name", x.name),
                                                                                                        new XAttribute("Fe", x.Fe),
                                                                                                        new XAttribute("C", x.C),
                                                                                                        new XAttribute("Si", x.Si),
                                                                                                        new XAttribute("Mn", x.Mn),
                                                                                                        new XAttribute("P", x.P),
                                                                                                        new XAttribute("S", x.S),
                                                                                                        new XAttribute("Cr", x.Cr),
                                                                                                        new XAttribute("Mo", x.Mo),
                                                                                                        new XAttribute("Ni", x.Ni),
                                                                                                        new XAttribute("Al", x.Al),
                                                                                                        new XAttribute("Co", x.Co),
                                                                                                        new XAttribute("Cu", x.Cu),
                                                                                                        new XAttribute("Nb", x.Nb),
                                                                                                        new XAttribute("Ti", x.Ti),
                                                                                                        new XAttribute("V", x.V),
                                                                                                        new XAttribute("W", x.W),
                                                                                                        new XAttribute("Pb", x.Pb),
                                                                                                        new XAttribute("Sn", x.Sn),
                                                                                                        new XAttribute("B", x.B),
                                                                                                        new XAttribute("Ca", x.Ca),
                                                                                                        new XAttribute("Zr", x.Zr),
                                                                                                        new XAttribute("As", x.As),
                                                                                                        new XAttribute("Bi", x.Bi),
                                                                                                        new XAttribute("Sb", x.Sb),
                                                                                                        new XAttribute("Zn", x.Zn),
                                                                                                        new XAttribute("Mg", x.Mg),
                                                                                                        new XAttribute("N", x.N),
                                                                                                        new XAttribute("H", x.H),
                                                                                                        new XAttribute("O", x.O))));

                    if (!Directory.Exists(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }

                    //sciezka do exportu xml
                    var path = Path.Combine(directory, "OMIKAS_AlloysExport.xml");
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                    xml.Save(path);
                    page.DisplayAlert("Export", "Skladniki stopowe wyeksportowano do pliku " + path.ToString(), "OK");
                }
                else
                {
                    page.DisplayAlert("Export", "Brak stopów do eksportu", "OK");
                }
            }
            catch (Exception ex)
            {
                page.DisplayAlert("Error", ex.ToString(), "OK");
            }
            try
            {
                if (App.DAUtil.GetAllSmelts().Any())
                {
                    var xml = new XElement("Smelts", App.DAUtil.GetAllSmelts().Select(x => new XElement("Smelt",
                                                                                                        new XAttribute("name", x.name),
                                                                                                        new XAttribute("minFe", x.Fe_min),
                                                                                                        new XAttribute("minC", x.C_min),
                                                                                                        new XAttribute("minSi", x.Si_min),
                                                                                                        new XAttribute("minMn", x.Mn_min),
                                                                                                        new XAttribute("minP", x.P_min),
                                                                                                        new XAttribute("minS", x.S_min),
                                                                                                        new XAttribute("minCr", x.Cr_min),
                                                                                                        new XAttribute("minMo", x.Mo_min),
                                                                                                        new XAttribute("minNi", x.Ni_min),
                                                                                                        new XAttribute("minAl", x.Al_min),
                                                                                                        new XAttribute("minCo", x.Co_min),
                                                                                                        new XAttribute("minCu", x.Cu_min),
                                                                                                        new XAttribute("minNb", x.Nb_min),
                                                                                                        new XAttribute("minTi", x.Ti_min),
                                                                                                        new XAttribute("minV", x.V_min),
                                                                                                        new XAttribute("minW", x.W_min),
                                                                                                        new XAttribute("minPb", x.Pb_min),
                                                                                                        new XAttribute("minSn", x.Sn_min),
                                                                                                        new XAttribute("minB", x.B_min),
                                                                                                        new XAttribute("minCa", x.Ca_min),
                                                                                                        new XAttribute("minZr", x.Zr_min),
                                                                                                        new XAttribute("minAs", x.As_min),
                                                                                                        new XAttribute("minBi", x.Bi_min),
                                                                                                        new XAttribute("minSb", x.Sb_min),
                                                                                                        new XAttribute("minZn", x.Zn_min),
                                                                                                        new XAttribute("minMg", x.Mg_min),
                                                                                                        new XAttribute("minN", x.N_min),
                                                                                                        new XAttribute("minH", x.H_min),
                                                                                                        new XAttribute("minO", x.O_min),

                                                                                                        new XAttribute("maxFe", x.Fe_max),
                                                                                                        new XAttribute("maxC", x.C_max),
                                                                                                        new XAttribute("maxSi", x.Si_max),
                                                                                                        new XAttribute("maxMn", x.Mn_max),
                                                                                                        new XAttribute("maxP", x.P_max),
                                                                                                        new XAttribute("maxS", x.S_max),
                                                                                                        new XAttribute("maxCr", x.Cr_max),
                                                                                                        new XAttribute("maxMo", x.Mo_max),
                                                                                                        new XAttribute("maxNi", x.Ni_max),
                                                                                                        new XAttribute("maxAl", x.Al_max),
                                                                                                        new XAttribute("maxCo", x.Co_max),
                                                                                                        new XAttribute("maxCu", x.Cu_max),
                                                                                                        new XAttribute("maxNb", x.Nb_max),
                                                                                                        new XAttribute("maxTi", x.Ti_max),
                                                                                                        new XAttribute("maxV", x.V_max),
                                                                                                        new XAttribute("maxW", x.W_max),
                                                                                                        new XAttribute("maxPb", x.Pb_max),
                                                                                                        new XAttribute("maxSn", x.Sn_max),
                                                                                                        new XAttribute("maxB", x.B_max),
                                                                                                        new XAttribute("maxCa", x.Ca_max),
                                                                                                        new XAttribute("maxZr", x.Zr_max),
                                                                                                        new XAttribute("maxAs", x.As_max),
                                                                                                        new XAttribute("maxBi", x.Bi_max),
                                                                                                        new XAttribute("maxSb", x.Sb_max),
                                                                                                        new XAttribute("maxZn", x.Zn_max),
                                                                                                        new XAttribute("maxMg", x.Mg_max),
                                                                                                        new XAttribute("maxN", x.N_max),
                                                                                                        new XAttribute("maxH", x.H_max),
                                                                                                        new XAttribute("maxO", x.O_max),

                                                                                                        new XAttribute("evoFe", x.Fe_evo),
                                                                                                        new XAttribute("evoC", x.C_evo),
                                                                                                        new XAttribute("evoSi", x.Si_evo),
                                                                                                        new XAttribute("evoMn", x.Mn_evo),
                                                                                                        new XAttribute("evoP", x.P_evo),
                                                                                                        new XAttribute("evoS", x.S_evo),
                                                                                                        new XAttribute("evoCr", x.Cr_evo),
                                                                                                        new XAttribute("evoMo", x.Mo_evo),
                                                                                                        new XAttribute("evoNi", x.Ni_evo),
                                                                                                        new XAttribute("evoAl", x.Al_evo),
                                                                                                        new XAttribute("evoCo", x.Co_evo),
                                                                                                        new XAttribute("evoCu", x.Cu_evo),
                                                                                                        new XAttribute("evoNb", x.Nb_evo),
                                                                                                        new XAttribute("evoTi", x.Ti_evo),
                                                                                                        new XAttribute("evoV", x.V_evo),
                                                                                                        new XAttribute("evoW", x.W_evo),
                                                                                                        new XAttribute("evoPb", x.Pb_evo),
                                                                                                        new XAttribute("evoSn", x.Sn_evo),
                                                                                                        new XAttribute("evoB", x.B_evo),
                                                                                                        new XAttribute("evoCa", x.Ca_evo),
                                                                                                        new XAttribute("evoZr", x.Zr_evo),
                                                                                                        new XAttribute("evoAs", x.As_evo),
                                                                                                        new XAttribute("evoBi", x.Bi_evo),
                                                                                                        new XAttribute("evoSb", x.Sb_evo),
                                                                                                        new XAttribute("evoZn", x.Zn_evo),
                                                                                                        new XAttribute("evoMg", x.Mg_evo),
                                                                                                        new XAttribute("evoN", x.N_evo),
                                                                                                        new XAttribute("evoH", x.H_evo),
                                                                                                        new XAttribute("evoO", x.O_evo))));

                    if (!Directory.Exists(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }
                    var path = Path.Combine(directory, "OMIKAS_SmeltsExport.xml");
                    if (File.Exists(path))
                    {
                        File.Delete(path);
                    }
                    xml.Save(path);
                    page.DisplayAlert("Export", "Wytopy wyeksportowano do pliku " + path.ToString(), "OK");
                }
                else
                {
                    page.DisplayAlert("Export", "Brak wytopów do eksportu", "OK");
                }
            }
            catch (Exception ex)
            {
                page.DisplayAlert("Error", ex.ToString(), "OK");
            }
        }
        public ClientConnectView(string defaultAddress, int defaultPort, Page parentPage)
        {
            _parentPage = parentPage;

            var addressEntry = new Entry
            {
                Placeholder = "Address",
                Text = defaultAddress,
                HorizontalOptions = LayoutOptions.StartAndExpand
            };

            var portEntry = new Entry()
            {
                Placeholder = "Port",
                Text = defaultPort.ToString(),
                HorizontalOptions = LayoutOptions.Start
            };

            var connectButton = new Button
            {
                Text = "Connect",
            };


            // connect / disconnect
            connectButton.Clicked += async (sender, args) => 
            {
                // if not already connected
                if (!_connected)
                {
                    if (ConnectTapped == null) return;

                    var address = addressEntry.Text;
                    // check valid port
                    var port = -1;
                    var isNumeric = Int32.TryParse(portEntry.Text, out port);

                    if (!isNumeric || ((port < 1001 || port > 65535)))
                    {
                        await _parentPage.DisplayAlert("Invalid Port", "Port must be numeric value between 1001 & 65535", "My bad");
                        return;
                    }

                    // callback
                    if (await ConnectTapped(address, port))
                    {
                        _connected = true;
                        connectButton.Text = "Disconnect";
                    };
                }
                else
                {
                    if (DisconnectTapped == null) return;

                    // callback
                    await DisconnectTapped();
                    _connected = false;
                    connectButton.Text = "Start Listening";
                }
                
            };

            Content = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children =
                {
                    new Label { 
                        Text = "Connect to:", 
                        VerticalOptions = LayoutOptions.CenterAndExpand 
                    },
                    addressEntry,
                    portEntry, 
                    connectButton
                }
            };
        }