Exemplo n.º 1
0
        void Popular_Parametros(VEICULO_DTO VEICULO, SqlCommand scm)
        {
            scm.Parameters.AddWithValue("@ID", VEICULO.ID);
            scm.Parameters.AddWithValue("@SITUACAO", VEICULO.SITUACAO);
            scm.Parameters.AddWithValue("@MARCA", VEICULO.MARCA);
            scm.Parameters.AddWithValue("@MODELO", VEICULO.MODELO);
            scm.Parameters.AddWithValue("@PLACA", VEICULO.PLACA);
            scm.Parameters.AddWithValue("@ANO_FABRICACAO", VEICULO.ANO_FABRICACAO);
            scm.Parameters.AddWithValue("@ANO_MODELO", VEICULO.ANO_MODELO);
            scm.Parameters.AddWithValue("@CATEGORIA", VEICULO.CATEGORIA);
            scm.Parameters.AddWithValue("@RENAVAM", VEICULO.RENAVAM);
            scm.Parameters.AddWithValue("@CHASSI", VEICULO.CHASSI);
            scm.Parameters.AddWithValue("@COMBUSTIVEL", VEICULO.COMBUSTIVEL);
            scm.Parameters.AddWithValue("@COR", VEICULO.COR);
            scm.Parameters.AddWithValue("@KM_ATUAL", VEICULO.KM_ATUAL);
            scm.Parameters.AddWithValue("@OBSERVACAO", VEICULO.OBSERVACAO);

            foreach (SqlParameter Parameter in scm.Parameters)
            {
                if (Parameter.Value == null)
                {
                    Parameter.Value = DBNull.Value;
                }
            }
        }
Exemplo n.º 2
0
        private void DtgVeiculos_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                //Setando o mousepointer para ocupado.
                Cursor.Current = Cursors.WaitCursor;

                //Verifica se existem registros no datagrid
                if (dtgVeiculos.RowCount == 0)
                {
                    return;
                }

                //Visualizando o registro selecionado
                int Id = Convert.ToInt32(dtgVeiculos.CurrentRow.Cells["Id"].Value.ToString());
                if (Id != 0)
                {
                    veiculo = new VEICULO_BLL().Seleciona(Id);
                    PopularTelaVeiculo();
                    tabVeiculo_InfoDoc.SelectedTab = tabVeiculo_Info;
                }
                else
                {
                    throw new Exception("O Descricao do registro selecionado está incorreto!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 3
0
 public void Alterar(VEICULO_DTO VEICULO)
 {
     try
     {
         ValidarDTO(VEICULO);
         DAO.Alterar(VEICULO);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 4
0
 public int Incluir(VEICULO_DTO VEICULO)
 {
     try
     {
         ValidarDTO(VEICULO);
         return(DAO.Incluir(VEICULO));
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 5
0
 void ValidarDTO(VEICULO_DTO VEICULO_DTO)
 {
     if (string.IsNullOrEmpty(VEICULO_DTO.SITUACAO))
     {
         throw new ValidaException("Favor informa a situação");
     }
     if (string.IsNullOrEmpty(VEICULO_DTO.MARCA))
     {
         throw new ValidaException("Favor informa a marca");
     }
     if (string.IsNullOrEmpty(VEICULO_DTO.MODELO))
     {
         throw new ValidaException("Favor informa o modelo");
     }
     if (string.IsNullOrEmpty(VEICULO_DTO.PLACA))
     {
         throw new ValidaException("Favor informa a placa");
     }
     if (string.IsNullOrEmpty(VEICULO_DTO.CATEGORIA))
     {
         throw new ValidaException("Favor informa a categoria");
     }
     if (string.IsNullOrEmpty(VEICULO_DTO.RENAVAM))
     {
         throw new ValidaException("Favor informa o renavam");
     }
     if (string.IsNullOrEmpty(VEICULO_DTO.CHASSI))
     {
         throw new ValidaException("Favor informa o chassi");
     }
     if (string.IsNullOrEmpty(VEICULO_DTO.COMBUSTIVEL))
     {
         throw new ValidaException("Favor informa o combustivel");
     }
     if (string.IsNullOrEmpty(VEICULO_DTO.COR))
     {
         throw new ValidaException("Favor informa a cor");
     }
     if (VEICULO_DTO.KM_ATUAL == null)
     {
         throw new ValidaException("Favor informa os km");
     }
 }
Exemplo n.º 6
0
        public VEICULO_DTO Seleciona(int Id)
        {
            using (SqlConnection scn = new SqlConnection(this.strConnection))
            {
                SqlDataReader dtr     = null;
                VEICULO_DTO   VEICULO = new VEICULO_DTO();

                try
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("SELECT * FROM [dbo].[VEICULO] Where (ID = " + Id + ");");
                    scn.Open();
                    SqlCommand scm = new SqlCommand(sb.ToString(), scn);

                    dtr = scm.ExecuteReader();

                    if (dtr.Read())
                    {
                        Popular_DTO(VEICULO, dtr);
                    }

                    return(VEICULO);
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (dtr != null)
                    {
                        dtr.Close();
                    }
                    scn.Close();
                }
            }
        }
Exemplo n.º 7
0
        public Cadastros(string tela = "", int ID = 0)
        {
            InitializeComponent();
            PopularCombos();
            try
            {
                switch (tela.ToLower())
                {
                //MOTORISTA
                case "motorista":
                    motorista = new MOTORISTA_DTO();
                    txtMotorista_ID.Enabled = false;
                    break;

                //VEICULO
                case "veiculo":
                    veiculo = new VEICULO_DTO();
                    txtVeiculo_Id.Enabled = false;
                    break;

                //TRANSAÇÕES
                case "transacoes":
                    transacoes = new TRANSACOES_DTO();
                    txtTransacao_Id.Enabled = false;
                    break;

                //ITEM ESTOQUE
                case "item estoque":
                    itens_estoque             = new ITENS_ESTOQUE_DTO();
                    txtItemEstoque_ID.Enabled = false;
                    break;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 8
0
 public void Popular_DTO(VEICULO_DTO VEICULO, SqlDataReader dtr)
 {
     try
     {
         VEICULO.ID             = (dtr["Id"]) == DBNull.Value ? (int?)null : Convert.ToInt32(dtr["Id"]);
         VEICULO.SITUACAO       = Convert.ToString(dtr["SITUACAO"]);
         VEICULO.MARCA          = Convert.ToString(dtr["MARCA"]);
         VEICULO.MODELO         = Convert.ToString(dtr["MODELO"]);
         VEICULO.PLACA          = Convert.ToString(dtr["PLACA"]);
         VEICULO.ANO_FABRICACAO = Convert.ToString(dtr["ANO_FABRICACAO"]);
         VEICULO.ANO_MODELO     = Convert.ToString(dtr["ANO_MODELO"]);
         VEICULO.CATEGORIA      = Convert.ToString(dtr["CATEGORIA"]);
         VEICULO.RENAVAM        = Convert.ToString(dtr["RENAVAM"]);
         VEICULO.CHASSI         = Convert.ToString(dtr["CHASSI"]);
         VEICULO.COMBUSTIVEL    = Convert.ToString(dtr["COMBUSTIVEL"]);
         VEICULO.COR            = Convert.ToString(dtr["COR"]);
         VEICULO.KM_ATUAL       = dtr["KM_ATUAL"] == DBNull.Value? (double?)null : Convert.ToDouble(dtr["KM_ATUAL"]);
         VEICULO.OBSERVACAO     = Convert.ToString(dtr["OBSERVACAO"]);
     }
     catch
     {
     }
 }
Exemplo n.º 9
0
        public int Incluir(VEICULO_DTO VEICULO)
        {
            using (SqlConnection scn = new SqlConnection(this.strConnection))
            {
                try
                {
                    scn.Open();
                    SqlCommand     scm = scn.CreateCommand();
                    SqlTransaction transaction;
                    transaction     = scn.BeginTransaction(IsolationLevel.ReadCommitted);
                    scm.Connection  = scn;
                    scm.Transaction = transaction;

                    StringBuilder sb = new StringBuilder();

                    sb.Append("INSERT INTO dbo.VEICULO   ");
                    sb.Append("           (SITUACAO   ");
                    sb.Append("           ,MARCA         ");
                    sb.Append("           ,MODELO        ");
                    sb.Append("           ,PLACA         ");
                    sb.Append("           ,ANO_FABRICACAO");
                    sb.Append("           ,ANO_MODELO    ");
                    sb.Append("           ,CATEGORIA     ");
                    sb.Append("           ,RENAVAM       ");
                    sb.Append("           ,CHASSI        ");
                    sb.Append("           ,COMBUSTIVEL   ");
                    sb.Append("           ,COR           ");
                    sb.Append("           ,KM_ATUAL      ");
                    sb.Append("           ,OBSERVACAO)   ");
                    sb.Append("VALUES                    ");
                    sb.Append("      (                   ");
                    sb.Append("	     @SITUACAO,       ");
                    sb.Append("      @MARCA,             ");
                    sb.Append("      @MODELO,            ");
                    sb.Append("      @PLACA,             ");
                    sb.Append("      @ANO_FABRICACAO,    ");
                    sb.Append("      @ANO_MODELO,        ");
                    sb.Append("      @CATEGORIA,         ");
                    sb.Append("      @RENAVAM,           ");
                    sb.Append("      @CHASSI,            ");
                    sb.Append("      @COMBUSTIVEL,       ");
                    sb.Append("      @COR,               ");
                    sb.Append("      @KM_ATUAL,          ");
                    sb.Append("      @OBSERVACAO         ");
                    sb.Append("	     )                   ");
                    sb.Append("select Scope_Identity();");


                    try
                    {
                        scm.CommandText = sb.ToString();

                        Popular_Parametros(VEICULO, scm);

                        VEICULO.ID = Convert.ToInt32(scm.ExecuteScalar());

                        transaction.Commit();

                        return(Convert.ToInt32(VEICULO.ID));
                    }
                    catch (Exception e)
                    {
                        try
                        {
                            transaction.Rollback();
                            throw e;
                        }
                        catch (SqlException ex)
                        {
                            if (transaction == null || transaction.Connection == null)
                            {
                                throw ex;
                            }
                            else
                            {
                                throw new Exception("Erro ao gravar dados do registro atual: " + e.Message + " não foi possível reverter transação,motivo: " + ex.Message);
                            }
                        }
                    }
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    scn.Close();
                }
            }
        }
Exemplo n.º 10
0
        public void Alterar(VEICULO_DTO VEICULO)
        {
            using (SqlConnection scn = new SqlConnection(this.strConnection))
            {
                try
                {
                    scn.Open();

                    SqlCommand scm = scn.CreateCommand();
                    scm.Connection = scn;

                    StringBuilder sb = new StringBuilder();
                    sb.Append("UPDATE VEICULO                          ");
                    sb.Append("   SET SITUACAO = @SITUACAO,      ");
                    sb.Append("      MARCA = @MARCA,                   ");
                    sb.Append("      MODELO = @MODELO,                 ");
                    sb.Append("      PLACA = @PLACA,                   ");
                    sb.Append("      ANO_FABRICACAO = @ANO_FABRICACAO, ");
                    sb.Append("      ANO_MODELO = @ANO_MODELO,         ");
                    sb.Append("      CATEGORIA = @CATEGORIA,           ");
                    sb.Append("      RENAVAM = @RENAVAM,               ");
                    sb.Append("      CHASSI = @CHASSI,                 ");
                    sb.Append("      COMBUSTIVEL = @COMBUSTIVEL,       ");
                    sb.Append("      COR = @COR,                       ");
                    sb.Append("      KM_ATUAL = @KM_ATUAL,             ");
                    sb.Append("      OBSERVACAO = @OBSERVACAO          ");
                    sb.Append(" WHERE ID =ID                           ");

                    try
                    {
                        scm.CommandText = sb.ToString();

                        Popular_Parametros(VEICULO, scm);

                        scm.ExecuteNonQuery();
                    }
                    catch (Exception e)
                    {
                        try
                        {
                            throw e;
                        }
                        catch (SqlException ex)
                        {
                            throw new Exception("Erro ao gravar dados do registro atual: " + e.Message + " não foi possível reverter transação,motivo: " + ex.Message);
                        }
                    }
                }
                catch (SqlException ex)
                {
                    throw ex;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    scn.Close();
                }
            }
        }