Exemplo n.º 1
0
        public int IncluirDados(EventoEntidade entidade)
        {
            int resultado = -1;

            using (SQLiteConnection conn = new SQLiteConnection(connectionString))
            {
                conn.Open();
                using (SQLiteCommand cmd = new SQLiteCommand(conn))
                {
                    cmd.CommandText = "INSERT INTO TB_EVENTO(NOME,LOCAL,DATA) VALUES (@nome,@local,@data)";
                    cmd.Prepare();
                    cmd.Parameters.AddWithValue("@nome", entidade.Nome);
                    cmd.Parameters.AddWithValue("@local", entidade.Local);
                    cmd.Parameters.AddWithValue("@data", entidade.Data);
                    try
                    {
                        resultado = cmd.ExecuteNonQuery();
                    }
                    catch (SQLiteException ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            return(resultado);
        }
Exemplo n.º 2
0
        public int AtualizaDados(EventoEntidade entidade)
        {
            int resultado = -1;

            using (SQLiteConnection conn = new SQLiteConnection(connectionString))
            {
                conn.Open();
                using (SQLiteCommand cmd = new SQLiteCommand(conn))
                {
                    cmd.CommandText = "UPDATE TB_EVENTO SET NOME=@nome, LOCAL=@local, DATA=@data WHERE ID_EVENTO = @id";
                    cmd.Prepare();
                    cmd.Parameters.AddWithValue("@Id", entidade.IdEvento);
                    cmd.Parameters.AddWithValue("@nome", entidade.Nome);
                    cmd.Parameters.AddWithValue("@local", entidade.Local);
                    cmd.Parameters.AddWithValue("@data", entidade.Data);
                    try
                    {
                        resultado = cmd.ExecuteNonQuery();
                    }
                    catch (SQLiteException ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            return(resultado);
        }
Exemplo n.º 3
0
        public int DeletaDados(EventoEntidade entidade)
        {
            int resultado = -1;

            using (SQLiteConnection conn = new SQLiteConnection(connectionString))
            {
                conn.Open();

                DeletaDadosRelacionados(BuscaIdListaEvento(entidade.IdEvento.ToString()));

                using (SQLiteCommand cmd = new SQLiteCommand(conn))
                {
                    cmd.CommandText = "DELETE FROM TB_EVENTO WHERE ID_EVENTO = @Id;";
                    cmd.Prepare();
                    cmd.Parameters.AddWithValue("@Id", entidade.IdEvento);
                    try
                    {
                        resultado = cmd.ExecuteNonQuery();
                    }
                    catch (SQLiteException ex)
                    {
                        throw ex;
                    }
                    finally
                    {
                        conn.Close();
                    }
                }
            }
            return(resultado);
        }
Exemplo n.º 4
0
        //BOTÕES
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            if (ValidaDados())
            {
                try
                {
                    var entidade = new EventoEntidade
                    {
                        IdEvento = int.Parse(txtId.Text),
                        Nome     = txtNome.Text,
                        Local    = txtLocal.Text,
                        Data     = Convert.ToDateTime(dataEvento.Text)
                    };

                    if (operacao == "incluir")
                    {
                        if (IncluirDados(entidade) > 0)
                        {
                            MessageBox.Show("Dados incluídos com sucesso.");
                            Close();
                        }
                        else
                        {
                            MessageBox.Show("Os dados não foram incluídos.");
                        }
                    }
                    else
                    {
                        if (AtualizaDados(entidade) > 0)
                        {
                            MessageBox.Show("Dados atualizados com sucesso.");
                            Close();
                        }
                        else
                        {
                            MessageBox.Show("Os dados não foram atualizados.");
                            Close();
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Erro : " + ex.Message);
                    Close();
                }
            }
            else
            {
                MessageBox.Show("Preencha o formulário corretamente");
            }
        }
Exemplo n.º 5
0
        //BOTÕES CRUD
        private void btnIncluir_Click(object sender, EventArgs e)
        {
            try
            {
                EventoEntidade _entidade  = null;
                var            formEvento = new FormEvento(_entidade);

                formEvento.ShowDialog();
                CarregaDados();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro : " + ex.Message);
            }
        }
        // PUT: api/Evento/5
        public bool Put([FromBody] EventoEntidade aEntidade)
        {
            try
            {
                return(new EventoNegocio().Editar(aEntidade));
            }
            catch (Exception ex)
            {
                var erro = new HttpResponseMessage(HttpStatusCode.NotAcceptable)
                {
                    Content = new StringContent(ex.Message)
                };

                throw new HttpResponseException(erro);
            }
        }
Exemplo n.º 7
0
 private EventoEntidade GetDadosDoGrid()
 {
     try
     {
         int linha;
         linha = dataGridView1.CurrentRow.Index;
         var entidade = new EventoEntidade();
         entidade.IdEvento = Convert.ToInt32(dataGridView1[0, linha].Value);
         entidade.Nome     = dataGridView1[1, linha].Value.ToString();
         entidade.Local    = dataGridView1[2, linha].Value.ToString();
         entidade.Data     = Convert.ToDateTime(dataGridView1[3, linha].Value);
         return(entidade);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 8
0
 public FormEvento(EventoEntidade entidade)
 {
     InitializeComponent();
     _entidade = entidade;
     this.CenterToScreen();
 }