Esempio n. 1
0
 public void AlterarCadastro(ModelCads cads)
 {
     try
     {
         if (string.IsNullOrEmpty(cads.Nome))
         {
             throw new Exception("Nome não informado");
         }
         if (string.IsNullOrEmpty(cads.NomeMae))
         {
             throw new Exception("Nome da mãe não informado");
         }
         if (string.IsNullOrEmpty(cads.Sexo))
         {
             throw new Exception("Sexo não informado");
         }
         if (string.IsNullOrEmpty(cads.Endereco))
         {
             throw new Exception("Endereço não informado");
         }
         if (string.IsNullOrEmpty(cads.Estado))
         {
             throw new Exception("Estado não informado");
         }
         conn.Update(cads);
         StatusMessage = "Cadastro alterado com sucesso!";
     }
     catch (Exception ex)
     {
         throw new Exception(string.Format("Erro: {0}", ex.Message));
     }
 }
Esempio n. 2
0
        private void ListandoCads_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            ModelCads        cads = (ModelCads)ListandoCads.SelectedItem;
            MasterDetailPage p    = (MasterDetailPage)Application.Current.MainPage;

            p.Detail = new NavigationPage(new PageCadastrar(cads));
        }
Esempio n. 3
0
        public ModelCads PegaCads(int id)
        {
            ModelCads m = new ModelCads();

            try
            {
                m             = conn.Table <ModelCads>().First(n => n.Id == id);
                StatusMessage = "Encontrei o cadastro";
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Erro: {0}", ex.Message));
            }
            return(m);
        }
Esempio n. 4
0
        private void btnCads_Clicked(object sender, EventArgs e)
        {
            try
            {
                ModelCads cads = new ModelCads();
                //Pegando Dados
                cads.Nome     = txtNome.Text;
                cads.Sexo     = txtSexo.Text;
                cads.NomeMae  = txtNomeMae.Text;
                cads.Endereco = txtEnd.Text;
                cads.Estado   = txtEst.Text;
                //Pegando caminho do DB
                ServicesDBCads dbCads = new ServicesDBCads(App.DbPath);

                if (btnCads.Text == "Cadastrar")
                {
                    dbCads.Inserir(cads);
                    DisplayAlert("Resultado da operação: ", dbCads.StatusMessage, "OK");
                    MasterDetailPage p = (MasterDetailPage)Application.Current.MainPage;
                    p.Detail = new NavigationPage(new PageHome());
                }
                else
                {
                    if (btnCads.Text == "Alterar")
                    {
                        cads.Id = Convert.ToInt32(txtId.Text);
                        dbCads.AlterarCadastro(cads);
                        DisplayAlert("Resultado da operação: ", dbCads.StatusMessage, "OK");
                        MasterDetailPage p = (MasterDetailPage)Application.Current.MainPage;
                        p.Detail = new NavigationPage(new PageListar());
                    }
                }

                //Deixando campos vazios
                txtNome.Text    = String.Empty;
                txtSexo.Text    = String.Empty;
                txtNomeMae.Text = String.Empty;
                txtEnd.Text     = String.Empty;
                txtEst.Text     = String.Empty;
                //Redirecionando página
            }
            catch (Exception ex)
            {
                DisplayAlert("Erro ", ex.Message, "OK");
            }

            ;
        }
Esempio n. 5
0
        public PageCadastrar(ModelCads cads)
        {
            InitializeComponent();
            btnCads.Text               = "Alterar";
            btnCads.BackgroundColor    = Color.Gray;
            btnExcluir.BackgroundColor = Color.Gray;
            btnVoltar.BackgroundColor  = Color.Gray;
            lblTitulo.Text             = "Alterando Cadastro";
            btnExcluir.IsVisible       = true;
            btnVoltar.IsVisible        = true;
            lblId.IsVisible            = true;
            txtId.IsVisible            = true;

            txtId.Text      = cads.Id.ToString();
            txtNome.Text    = cads.Nome;
            txtSexo.Text    = cads.Sexo;
            txtNomeMae.Text = cads.NomeMae;
            txtEnd.Text     = cads.Endereco;
            txtEst.Text     = cads.Estado;
        }
Esempio n. 6
0
 public void Inserir(ModelCads cads)
 {
     try
     {
         if (string.IsNullOrEmpty(cads.Nome))
         {
             throw new Exception(this.StatusMessage = string.Format("O nome não informado"));
         }
         if (string.IsNullOrEmpty(cads.Sexo))
         {
             throw new Exception(this.StatusMessage = string.Format("Sexo não informado"));
         }
         if (string.IsNullOrEmpty(cads.NomeMae))
         {
             throw new Exception(this.StatusMessage = string.Format("O nome da mãe não informado"));
         }
         if (string.IsNullOrEmpty(cads.Endereco))
         {
             throw new Exception(this.StatusMessage = string.Format("Endereço não informado"));
         }
         if (string.IsNullOrEmpty(cads.Estado))
         {
             throw new Exception(this.StatusMessage = string.Format("Estado não informado"));
         }
         int result = conn.Insert(cads);
         if (result != 0)
         {
             this.StatusMessage = string.Format("Cadastro realizado com sucesso!");
             // DateTime.Now.ToString() para pegar a data e hora
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }