Example #1
0
        public LoginPageViewModel(ContentPage page)
        {
            this.page = page;

            ws = WSUtil.Instance;

            IsRunning = false;

            dao08 = DAO_Pesquisa08.Instance;

            CmdEntrar = new Command(() => {
                Entrar();
            });
        }
Example #2
0
        public EventoPageViewModel(ContentPage page)
        {
            this.page = page;
            ws        = WSUtil.Instance;

            pesquisador = Utils.ObterPesquisadorLogado();

            Title    = pesquisador.razaosocial;
            SubTitle = pesquisador.nome;

            IsRunning = false;

            CmdInformarParticipante = new Command(() => {
                InformarParticipante();
            });

            CmdCadastrarParticipante = new Command(() => {
                CadastrarParticipante();
            });
        }
Example #3
0
        private async void Entrar()
        {
            try
            {
                bool isOnline = Utils.IsOnline();

                if (!isOnline)
                {
                    throw new Exception("Não há conexão disponível.");
                }

                IsRunning = true;

                ws = WSUtil.Instance;

                JObject obj = new JObject();
                obj["idpesquisador"] = TxtId;
                obj["senha"]         = TxtSenha;

                String imei = Utils.ObterImei();

                if (!String.IsNullOrEmpty(imei))
                {
                    obj["imei"] = imei;

                    HttpResponseMessage resposta = await ws.Post("login", obj);

                    String message = await resposta.Content.ReadAsStringAsync();

                    if (resposta.IsSuccessStatusCode)
                    {
                        Pesquisador pesquisadorWeb = JsonConvert.DeserializeObject <Pesquisador>(message);

                        pesquisador = dao08.ObterPesquisador(Int32.Parse(TxtId));

                        if (pesquisador == null)
                        {
                            pesquisadorWeb.pesquisador.idpesquisador = Int32.Parse(TxtId);
                            pesquisadorWeb.pesquisador.senha         = TxtSenha;
                            pesquisadorWeb.pesquisador.logado        = 1;
                            dao08.InserirPesquisador(pesquisadorWeb.pesquisador);
                        }
                        else
                        {
                            pesquisador.logado      = 1;
                            pesquisador.nome        = pesquisadorWeb.pesquisador.nome;
                            pesquisador.razaosocial = pesquisadorWeb.pesquisador.razaosocial;
                            dao08.AtualizarPesquisador(pesquisador);
                        }

                        await this.page.Navigation.PushAsync(new PesquisaPage());
                    }
                    else
                    {
                        throw new Exception(message);
                    }
                }
            }
            catch (Exception ex)
            {
                await this.page.DisplayAlert("Erro", ex.Message, "Ok");
            }
            finally
            {
                IsRunning = false;
            }
        }