Пример #1
0
        public Boolean Excluir(PacotesDTO pPacoteDTO )
        {
            try
            {
                DataTable dt = new DataTable();
                MySqlConnection Conexao = new MySqlConnection(StrCon);
                StringBuilder vSQLCommand = new StringBuilder();

                vSQLCommand.AppendLine("DELETE FROM pacotes");

                vSQLCommand.AppendLine(" WHERE 1 = 1 ");

                if (pPacoteDTO.Identificador != default(int))
                {
                    vSQLCommand.AppendLine("and idPacotes = @idPacotes ");
                }

                MySqlCommand com = new MySqlCommand(vSQLCommand.ToString(), Conexao);

                if (pPacoteDTO.Identificador != default(int))
                {
                    com.Parameters.Add(new MySqlParameter("@idPacotes", pPacoteDTO.Identificador));
                }
                Conexao.Open();
                //dt.Load(com.ExecuteReader());
                com.ExecuteReader();
                Conexao.Close();

                return true;

            }
            catch (DataAccessException ex)
            {
                // Verifica se ocorreu erro de constraint
                if (ex.InnerException is SqlException)
                {
                    if (((SqlException)ex.InnerException).Number == 547)
                        //throw new RegistroEmUso();
                        throw new Exception();
                    else
                        throw;
                }
                else
                    throw;
            }
            catch (Exception e)
            {
                int pos = 0;
                pos = e.Message.ToString().IndexOf("Cannot delete or update a parent row: a foreign key constraint fails (");
                if (pos > 0)
                {
                    //throw new RegistroEmUso();
                    throw new Exception();
                }
                else
                throw new DataAccessException("Ocorreu um erro ao excluir o Cliente.", DataAccessExceptionLocation.DAO, e);
            }
        }
Пример #2
0
 public void InsercaoDePacoteValido()
 {
     PacotesCT pacoteCT = new PacotesCT();
     PacotesDTO pacotesDTO = new PacotesDTO();
     pacotesDTO.DescPacote = "Descrição do Pacote de Teste";
     pacotesDTO.NomePacote = "Nome do Pacote de Teste";
     pacotesDTO.ValorPacote = 20;
     bool resultado = pacoteCT.Insere(pacotesDTO);
     Assert.AreEqual(true, resultado);
 }
Пример #3
0
 public DataTable SelecionarPorFiltroPesquisar(PacotesDTO pPacotesDTO)
 {
     try
     {
         return DAO.Selecionar(pPacotesDTO);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #4
0
 public Boolean Insere(PacotesDTO pPacotesDTO)
 {
     try
     {
         return DAO.Insere(pPacotesDTO);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #5
0
 public Boolean Excluir(PacotesDTO pPacotesDTO)
 {
     try
     {
         return DAO.Excluir(pPacotesDTO);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #6
0
 public Boolean Altera(PacotesDTO pPacotesDTO)
 {
     try
     {
         return DAO.Altera(pPacotesDTO);
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Пример #7
0
        public Boolean Altera(PacotesDTO pPacoteDTO)
        {
            try
            {
                 DataTable dt = new DataTable();
                 MySqlConnection Conexao = new MySqlConnection(StrCon);
                 StringBuilder vSQLCommand = new StringBuilder();
                 vSQLCommand.AppendLine("UPDATE pacotes SET");
                 vSQLCommand.AppendLine("NOMEPACOTE = @NOMEPACOTE, ");
                 vSQLCommand.AppendLine("DESCPACOTE = @DESCPACOTE, ");
                 vSQLCommand.AppendLine("VALORPACOTE = @VALORPACOTE ");
                 vSQLCommand.AppendLine(" WHERE 1 = 1 ");

                 if (pPacoteDTO.Identificador != default(int))
                       {
                          vSQLCommand.AppendLine("and idPacotes = @idPacotes ");
                       }

                 MySqlCommand com = new MySqlCommand(vSQLCommand.ToString(), Conexao);

                com.Parameters.Add(new MySqlParameter("@idPacotes", pPacoteDTO.Identificador));

                 com.Parameters.Add(new MySqlParameter("@NomePacote", pPacoteDTO.NomePacote));

                 com.Parameters.Add(new MySqlParameter("@DescPacote", pPacoteDTO.DescPacote));

                 com.Parameters.Add(new MySqlParameter("@ValorPacote", pPacoteDTO.ValorPacote));

                    Conexao.Open();
                    //dt.Load(com.ExecuteReader());
                    com.ExecuteReader();
                    Conexao.Close();

                    return true;
                }
                catch (Exception e)
                {
                    throw e;
                }
        }
Пример #8
0
 public void TesteQuantidadeDeCaracteres()
 {
     PacotesCT pacoteCT = new PacotesCT();
     PacotesDTO pacotesDTO = new PacotesDTO();
     pacotesDTO.DescPacote = "Descrição do Pacote de Teste";
     pacotesDTO.NomePacote = "Nome do Pacote de Teste Nome do Pacote de Teste Nome do Pacote de Teste Nome do Pacote de Teste";
     pacotesDTO.ValorPacote = Convert.ToDecimal("20");
     bool resultado = pacoteCT.Insere(pacotesDTO);
 }
Пример #9
0
 public void ConversaoValorPacote()
 {
     PacotesCT pacoteCT = new PacotesCT();
     PacotesDTO pacotesDTO = new PacotesDTO();
     pacotesDTO.ValorPacote = Convert.ToDecimal("teste valor");
 }
Пример #10
0
        public DataTable SelecionarPesquisar(PacotesDTO pPacoteDTO)
        {
            try
            {
                DataTable dt = new DataTable();
                MySqlConnection Conexao = new MySqlConnection(StrCon);

                StringBuilder vSQLCommand = new StringBuilder();
                vSQLCommand = new StringBuilder();
                vSQLCommand.AppendLine(" SELECT                    ");

                vSQLCommand.AppendLine(" IDPACOTES,");
                vSQLCommand.AppendLine(" NOMEPACOTE,");
                vSQLCommand.AppendLine(" DESCPACOTE,");
                vSQLCommand.AppendLine(" VALORPACOTE");

                vSQLCommand.AppendLine(" FROM PACOTES");

                vSQLCommand.AppendFormat(" WHERE (1=1) ");

                if (pPacoteDTO.Identificador!= default(int))
                    {
                        vSQLCommand.AppendLine("and idPacotes = @idPacotes ");
                    }
                if (!String.IsNullOrEmpty(pPacoteDTO.NomePacote))
                    {
                        vSQLCommand.AppendLine("and NomePacote like @NomePacote ");
                    }
                if (!String.IsNullOrEmpty(pPacoteDTO.DescPacote))
                    {
                        vSQLCommand.AppendLine("and DescPacote like @DescPacote ");
                    }

                MySqlCommand com = new MySqlCommand(vSQLCommand.ToString(), Conexao);

                if (pPacoteDTO.Identificador!= default(int))
                    {
                        com.Parameters.Add(new MySqlParameter("@idPacotes", pPacoteDTO.Identificador));
                    }
                if (!String.IsNullOrEmpty(pPacoteDTO.NomePacote))
                    {
                         com.Parameters.Add(new MySqlParameter("@NomePacote", "%" + pPacoteDTO.NomePacote + "%"));
                    }
                if (!String.IsNullOrEmpty(pPacoteDTO.DescPacote))
                    {
                         com.Parameters.Add(new MySqlParameter("@DescPacote", "%" + pPacoteDTO.DescPacote + "%"));
                    }

                Conexao.Open();
                dt.Load(com.ExecuteReader());
                com.ExecuteReader();
                Conexao.Close();

                return dt;
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #11
0
        public Boolean Insere(PacotesDTO pPacoteDTO)
        {
            try
            {
            MySqlConnection Conexao = new MySqlConnection(StrCon);
            StringBuilder vSQLCommand = new StringBuilder();
            vSQLCommand.AppendLine("INSERT INTO pacotes(");
            vSQLCommand.AppendLine("NOMEPACOTE,");
            vSQLCommand.AppendLine("DESCPACOTE,");
            vSQLCommand.AppendLine("VALORPACOTE) values (");
            //com.Parameters.Add(new MySqlParameter("@idPacotes", pPacoteDTO.Identificador));
            vSQLCommand.AppendLine(" @NomePacote,");
            vSQLCommand.AppendLine(" @DescPacote,");
            vSQLCommand.AppendLine(" @ValorPacote)");
            MySqlCommand com = new MySqlCommand(vSQLCommand.ToString(), Conexao);
            //com.Parameters.Add(new MySqlParameter("@idPacotes", pPacoteDTO.Identificador));

            com.Parameters.Add(new MySqlParameter("@NomePacote", pPacoteDTO.NomePacote));

            com.Parameters.Add(new MySqlParameter("@DescPacote", pPacoteDTO.DescPacote));

            com.Parameters.Add(new MySqlParameter("@ValorPacote", pPacoteDTO.ValorPacote));

            Conexao.Open();
            //dt.Load(com.ExecuteReader());
            com.ExecuteReader();
            Conexao.Close();

            return true;
            }
            catch (Exception e)
            {

            throw e;
            }
        }
Пример #12
0
        protected void grvPacote_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "editar")
            {
                pacoteCT = new PacotesCT();
                pacoteDTO = new PacotesDTO();
                txtIdPacote.Value = e.CommandArgument.ToString();
                pacoteDTO.Identificador = Convert.ToInt32(e.CommandArgument.ToString());
                DataTable dtPacotes = pacoteCT.SelecionarPorFiltro(pacoteDTO);

                if (dtPacotes.Rows.Count > 0)
                {
                    DataRow drCliente = dtPacotes.Rows[0];
                    pacoteDTO.Identificador = Convert.ToInt32(drCliente["IDPACOTES"].ToString());
                    txtNome.Text = drCliente["NOMEPACOTE"].ToString();
                    txtDescricao.Text = drCliente["DESCPACOTE"].ToString();
                    decimal valor = Convert.ToDecimal(drCliente["VALORPACOTE"].ToString());
                    txtValor.Text = valor.ToString("N2");

                }
            }
            else if (e.CommandName == "excluir")
            {
                pacoteCT = new PacotesCT();
                pacoteDTO = new PacotesDTO();
                pacoteDTO.Identificador = Convert.ToInt32(e.CommandArgument);

                try
                {

                    if (pacoteCT.Excluir(pacoteDTO))
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Aviso", "alert('Pacote Excluido com Sucesso!!!')", true);
                        Response.Redirect("~/ManterPacotes.aspx");
                    }
                }
                catch (Exception ex)
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Aviso", "alert('Erro ao Excluir o Pacote:\n" + ex.Message + "')", true);
                }

            }
        }
Пример #13
0
 private void Cancelar()
 {
     pacoteDTO = new PacotesDTO();
     txtIdPacote.Value = String.Empty;
     txtNome.Text = "";
     txtDescricao.Text = "";
     txtValor.Text = "";
     txtNome.Focus();
 }