Exemplo n.º 1
0
        public void Alterar(VeiculoInfo veiculo)
        {
            //Outra forma de instanciar o objeto cn
            using (SqlConnection cn = new SqlConnection(Dados.StringDeConexao()))
            {
                //Outra forma de instanciar o objeto cmd
                using (SqlCommand cmd = new SqlCommand("spVeiculo_Upd", cn))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@placa", veiculo.Placa);
                    cmd.Parameters.AddWithValue("@modelo", veiculo.Modelo);
                    cmd.Parameters.AddWithValue("@cor", veiculo.Cor);
                    cmd.Parameters.AddWithValue("@ano", veiculo.Ano);

                    try
                    {
                        cn.Open();
                        cmd.ExecuteNonQuery();
                        cn.Close();
                    }
                    catch (SqlException ex)
                    {
                        throw new Exception("Erro na Conexão - nº " + ex.Number);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void Incluir(VeiculoInfo veiculo)
        {
            if (String.IsNullOrEmpty(veiculo.Placa))
            {
                throw new Exception("Informe a placa do veículo.");
            }

            if (String.IsNullOrEmpty(veiculo.Modelo))
            {
                throw new Exception("Informe o modelo do veículo.");
            }

            if (String.IsNullOrEmpty(veiculo.Cor))
            {
                throw new Exception("Informe a cor do veículo.");
            }

            if (String.IsNullOrEmpty(veiculo.Ano.ToString()))
            {
                throw new Exception("Informe o ano do veículo.");
            }

            if (veiculo.Ano < 2000)
            {
                throw new Exception("O ano não pode ser menor que 2000");
            }


            VeiculoDAL obj = new VeiculoDAL();

            obj.Incluir(veiculo);
        }
Exemplo n.º 3
0
        private void alterarButton_Click(object sender, EventArgs e)
        {
            try
            {
                VeiculoInfo veiculo = new VeiculoInfo();

                veiculo.Placa  = placaTextBox.Text;
                veiculo.Modelo = modeloTextBox.Text;
                veiculo.Cor    = corTextBox.Text;
                veiculo.Ano    = Convert.ToInt16(anoTextBox.Text);

                VeiculoBLL obj = new VeiculoBLL();
                obj.Alterar(veiculo);

                MessageBox.Show("Veículo alterado com sucesso", "Aviso",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                placaTextBox.Focus();
                placaTextBox.SelectAll();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Alerta de Erro",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 4
0
        private void inserirButton_Click(object sender, EventArgs e)
        {
            try
            {
                VeiculoInfo veiculo = new VeiculoInfo();

                veiculo.Placa  = placaTextBox.Text;
                veiculo.Modelo = modeloTextBox.Text;
                veiculo.Cor    = corTextBox.Text;
                veiculo.Ano    = Convert.ToInt16(anoTextBox.Text);

                VeiculoBLL obj = new VeiculoBLL();
                obj.Incluir(veiculo);

                MessageBox.Show("Veículo cadastrado com sucesso", "Aviso",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                //Limpar a tela
                LimparTela();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Alerta de Erro",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 5
0
        private void excluirButton_Click(object sender, EventArgs e)
        {
            DialogResult resposta =
                MessageBox.Show("Deseja excluir este veículo?", "Alerta",
                                MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                MessageBoxDefaultButton.Button2);

            if (resposta == DialogResult.No)
            {
                return;
            }

            try
            {
                VeiculoInfo veiculo = new VeiculoInfo();

                veiculo.Placa = placaTextBox.Text;

                VeiculoBLL obj = new VeiculoBLL();
                obj.Excluir(veiculo);

                MessageBox.Show("Veículo excluído com sucesso", "Aviso",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);

                LimparTela();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Alerta de Erro",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);

                //Obs.: Erro 547 é conflito de chave estrangeira
            }
        }
Exemplo n.º 6
0
        public void Excluir(VeiculoInfo veiculo)
        {
            if (string.IsNullOrEmpty(veiculo.Placa))
            {
                throw new Exception("Informe a placa do veículo");
            }
            VeiculoDAL obj = new VeiculoDAL();

            obj.Excluir(veiculo);
        }
Exemplo n.º 7
0
        public void Incluir(VeiculoInfo veiculo)
        {
            //Estabelecer a conexão
            SqlConnection cn = new SqlConnection();

            //            cn.ConnectionString =
            //                            @"Integrated Security=SSPI;Persist Security Info=False;
            //                            Initial Catalog=Oficina;Data Source=.\sqlexpress";

            cn.ConnectionString = Dados.StringDeConexao();

            //Definir o comando
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cn;
            cmd.CommandText = "spVeiculo_Ins";

            //*** É NECESSÁRIO ACRESCENTAR A DIRETIVA using System.Data ***
            cmd.CommandType = CommandType.StoredProcedure;

            //Passando os parâmetros para o comando
            cmd.Parameters.AddWithValue("@placa", veiculo.Placa);
            cmd.Parameters.AddWithValue("@modelo", veiculo.Modelo);
            cmd.Parameters.AddWithValue("@cor", veiculo.Cor);
            cmd.Parameters.AddWithValue("@ano", veiculo.Ano);

            //Executar
            try
            {
                //Abrir a conexão
                cn.Open();

                //Executar o comando
                cmd.ExecuteNonQuery();

                //Fechar a conexão
                cn.Close();
            }
            catch (SqlException ex)
            {
                throw new Exception("Erro na Conexão - nº " + ex.Number);
            }
        }
Exemplo n.º 8
0
        public void Incluir(VeiculoInfo veiculo)
        {
            //Estabelecer a conexao
            SqlConnection cn = new SqlConnection();

            cn.ConnectionString = Dados.StringDeConexao();

            //Definir o Comando
            SqlCommand cmd = new SqlCommand();

            cmd.Connection = cn;

            //Definir a expressão sql
            cmd.CommandText = "Veiculo_Incluir";
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@placa", veiculo.Placa);
            cmd.Parameters.AddWithValue("@modelo", veiculo.Modelo);
            cmd.Parameters.AddWithValue("@cor", veiculo.Cor);
            cmd.Parameters.AddWithValue("@ano", veiculo.Ano);

            //Executar
            try
            {
                //Abrir a conexao
                cn.Open();

                //Executar o comando
                cmd.ExecuteNonQuery();
            }
            catch (SqlException ex)
            {
                throw new Exception("Erro na conexão:" + ex.Number);

                throw;
            }
            finally
            {
                cn.Close();
            }
        }
Exemplo n.º 9
0
        public List <VeiculoInfo> Listagem()
        {
            var cn  = new SqlConnection(Dados.StringDeConexao());
            var cmd = new SqlCommand("Select * from Veiculo", cn);

            cn.Open();
            var dr    = cmd.ExecuteReader();
            var lista = new List <VeiculoInfo>();

            while (dr.Read())
            {
                var veiculo = new VeiculoInfo();
                veiculo.Ano    = Convert.ToInt16(dr["Ano"]);
                veiculo.Cor    = Convert.ToString(dr["Cor"]);
                veiculo.Modelo = Convert.ToString(dr["Modelo"]);
                veiculo.Placa  = Convert.ToString(dr["Placa"]);
                lista.Add(veiculo);
            }
            dr.Close();
            cn.Close();
            return(lista);
        }
Exemplo n.º 10
0
        public void Alterar(VeiculoInfo veiculo)
        {
            if (string.IsNullOrEmpty(veiculo.Placa))
            {
                throw new Exception("Informe a placa do veículo");
            }
            else if (string.IsNullOrEmpty(veiculo.Modelo))
            {
                throw new Exception("Informe o modelo do veículo");
            }
            else if (string.IsNullOrEmpty(veiculo.Cor))
            {
                throw new Exception("Informe a cor do veículo");
            }
            else if (string.IsNullOrEmpty(veiculo.Ano.ToString()))
            {
                throw new Exception("Informe o ano do veículo");
            }
            VeiculoDAL obj = new VeiculoDAL();

            obj.Alterar(veiculo);
        }
Exemplo n.º 11
0
        public VeiculoPage(VeiculoInfo veiculo)
        {
            Title               = "Dados do Veículo";
            Style               = Estilo.Current[Estilo.TELA_PADRAO];
            _veiculo            = veiculo;
            this.BindingContext = _veiculo;
            inicializarComponente();

            Content = new StackLayout
            {
                Orientation       = StackOrientation.Vertical,
                VerticalOptions   = LayoutOptions.Fill,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Margin            = 3,
                Children          =
                {
                    new ScrollView                                {
                        Orientation       = ScrollOrientation.Vertical,
                        VerticalOptions   = LayoutOptions.FillAndExpand,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        Content           = new StackLayout       {
                            Spacing           = 7,
                            Orientation       = StackOrientation.Vertical,
                            VerticalOptions   = LayoutOptions.Start,
                            HorizontalOptions = LayoutOptions.FillAndExpand,
                            Children          =
                            {
                                new StackLayout                   {
                                    Orientation       = StackOrientation.Horizontal,
                                    VerticalOptions   = LayoutOptions.Start,
                                    HorizontalOptions = LayoutOptions.FillAndExpand,
                                    Children          =
                                    {
                                        new StackLayout           {
                                            Spacing           = 3,
                                            Orientation       = StackOrientation.Horizontal,
                                            VerticalOptions   = LayoutOptions.Start,
                                            HorizontalOptions = LayoutOptions.CenterAndExpand,
                                            Children          =
                                            {
                                                _TituloLabel,
                                                new Label         {
                                                    VerticalOptions   = LayoutOptions.Start,
                                                    HorizontalOptions = LayoutOptions.Start,
                                                    Text      = " ou similar",
                                                    TextColor = Color.FromHex("#696969")
                                                }
                                            }
                                        },
                                        _PromoLabel
                                    }
                                },
                                new StackLayout                   {
                                    Orientation       = StackOrientation.Horizontal,
                                    VerticalOptions   = LayoutOptions.Start,
                                    HorizontalOptions = LayoutOptions.FillAndExpand,
                                    Children          =
                                    {
                                        _FotoImage,
                                        new StackLayout           {
                                            Orientation       = StackOrientation.Vertical,
                                            VerticalOptions   = LayoutOptions.Start,
                                            HorizontalOptions = LayoutOptions.FillAndExpand,
                                            Children          =
                                            {
                                                new StackLayout   {
                                                    Spacing           = 0,
                                                    Padding           = new Thickness(0, 0, 10, 0),
                                                    Orientation       = StackOrientation.Vertical,
                                                    VerticalOptions   = LayoutOptions.Start,
                                                    HorizontalOptions = LayoutOptions.EndAndExpand,
                                                    Children          =
                                                    {
                                                        new Label {
                                                            Text              = "Locadora",
                                                            FontSize          = 11,
                                                            TextColor         = Color.Gray,
                                                            VerticalOptions   = LayoutOptions.Start,
                                                            HorizontalOptions = LayoutOptions.End
                                                        },
                                                        _NomeLoja
                                                    }
                                                },
                                                new StackLayout   {
                                                    Spacing           = 0,
                                                    Padding           = new Thickness(0, 0, 10, 0),
                                                    Orientation       = StackOrientation.Vertical,
                                                    VerticalOptions   = LayoutOptions.Start,
                                                    HorizontalOptions = LayoutOptions.EndAndExpand,
                                                    Children          =
                                                    {
                                                        new Label {
                                                            Text              = "Preço total de",
                                                            FontSize          = 11,
                                                            TextColor         = Color.Gray,
                                                            VerticalOptions   = LayoutOptions.Start,
                                                            HorizontalOptions = LayoutOptions.End
                                                        },
                                                        _ValorLabel
                                                    }
                                                }
                                            }
                                        }
                                    }
                                },
                                new StackLayout                   {
                                    Spacing           = 10,
                                    Orientation       = StackOrientation.Horizontal,
                                    VerticalOptions   = LayoutOptions.Start,
                                    HorizontalOptions = LayoutOptions.FillAndExpand,
                                    Children          =
                                    {
                                        new StackLayout           {
                                            Orientation       = StackOrientation.Vertical,
                                            VerticalOptions   = LayoutOptions.Start,
                                            HorizontalOptions = LayoutOptions.Start,
                                            Children          =
                                            {
                                                new Label         {
                                                    VerticalOptions   = LayoutOptions.Start,
                                                    HorizontalOptions = LayoutOptions.Start,
                                                    Text           = "Data de retirada",
                                                    FontAttributes = FontAttributes.Bold
                                                },
                                                _DataIniLabel
                                            }
                                        },
                                        new StackLayout           {
                                            Orientation       = StackOrientation.Vertical,
                                            VerticalOptions   = LayoutOptions.Start,
                                            HorizontalOptions = LayoutOptions.Start,
                                            Children          =
                                            {
                                                new Label         {
                                                    VerticalOptions   = LayoutOptions.Start,
                                                    HorizontalOptions = LayoutOptions.Start,
                                                    Text           = "Data de devolução",
                                                    FontAttributes = FontAttributes.Bold
                                                },
                                                _DataFimLabel
                                            }
                                        }
                                    }
                                },
                                new Label                         {
                                    VerticalOptions         = LayoutOptions.Start,
                                    HorizontalOptions       = LayoutOptions.FillAndExpand,
                                    HorizontalTextAlignment = TextAlignment.Center,
                                    Text           = "Características do Veículo",
                                    FontAttributes = FontAttributes.Bold
                                },
                                _CaracteristicaGrid,
                            }
                        }
                    },
                    _AlugarButton
                }
            };
        }