Exemple #1
0
        private decimal calcularMulta()
        {
            decimal total = 0;

            if (tbox_codLoc.Text != "")
            {
                DateTime dataInicio = dtp_previsaoDevolucao.Value.Date;
                DateTime dataFim    = dtp_devolucaoEfetiva.Value.Date;
                int      dias       = Convert.ToInt32(dataFim.Subtract(dataInicio).TotalDays);
                tbox_diferencaDias.Text = dias.ToString();
                int     codLoc = (int.Parse(tbox_codLoc.Text));
                locacao loc    = (new locacaoRepositorio()).selecionar(codLoc);
                if (loc != null)
                {
                    int   codCar = loc.carro_codigo;
                    carro car    = (new carroRepositorio()).selecionar(codCar);
                    if (car != null)
                    {
                        decimal   valorCarro = car.carro_valorDiaria.Value;
                        int       tipoCarro  = (int)car.tipocarro_codigo;
                        tipocarro tpc        = (new tipocarroRepositorio()).selecionar(tipoCarro);
                        if (tpc != null)
                        {
                            decimal valorTpCarro = (decimal)tpc.tipocarro_valor;
                            total = (valorCarro + valorTpCarro) * dias * 2;
                        }
                    }
                }
            }
            return(total);
        }
 private void btn_localizar_Click(object sender, EventArgs e)
 {
     try
     {
         ConsultaTipoCarro frm = new ConsultaTipoCarro();
         frm.ShowDialog();
         //codigo selecionado
         int codigo = frm.codigo;
         frm = null;
         if (codigo != 0)
         {
             tipocarro tpcar = (new tipocarroRepositorio()).selecionar(codigo);
             if (tpcar != null)
             {
                 tbox_codigo.Text    = tpcar.tipocarro_codigo.ToString();
                 tbox_tipoCarro.Text = tpcar.tipocarro_tipo.ToString();
                 tbox_valor.Text     = tpcar.tipocarro_valor.ToString();
             }
             else
             {
                 MessageBox.Show("Dados não localizados!");
                 btn_cancelar_Click(sender, e);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Erro ao localizar! " + ex.Message);
     }
 }
Exemple #3
0
        private decimal atualizarTotal()
        {
            decimal total = 0;

            if (tbox_codCar.Text != "")
            {
                DateTime dataInicio = dtp_locacao.Value.Date;
                DateTime dataFim    = dtp_previsaoDevolucao.Value.Date;
                int      dias       = Convert.ToInt32(dataFim.Subtract(dataInicio).TotalDays);
                if (dias == 0)
                {
                    dias++;
                }
                tbox_totalDias.Text = dias.ToString();

                carro     car          = (new carroRepositorio()).selecionar(int.Parse(tbox_codCar.Text));
                decimal   valorCarro   = car.carro_valorDiaria.Value;
                int       tipoCarro    = car.tipocarro_codigo.Value;
                tipocarro tpc          = (new tipocarroRepositorio()).selecionar(tipoCarro);
                decimal   valorTpCarro = tpc.tipocarro_valor.Value;
                total = (valorCarro + valorTpCarro) * dias;
            }
            tbox_totalLocacao.Text = total.ToString("#.00");
            return(total);
        }
        private void btn_excluir_Click(object sender, EventArgs e)
        {
            try
            {
                if (tbox_codigo.Text != "")
                {
                    tipocarro tpcar = (new tipocarroRepositorio()).selecionar(int.Parse(tbox_codigo.Text));

                    (new tipocarroRepositorio()).excluir(tpcar);

                    btn_cancelar_Click(sender, e);
                    MessageBox.Show("Dados excluidos!");
                }
                else
                {
                    MessageBox.Show("Informar o código!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro ao excluir! " + ex.Message);
            }
        }
        private void btn_salvar_Click(object sender, EventArgs e)
        {
            try
            {
                if (tbox_tipoCarro.Text != "" && tbox_valor.Text != "")
                {
                    tipocarro tpcar = new tipocarro()
                    {
                        tipocarro_tipo  = tbox_tipoCarro.Text,
                        tipocarro_valor = (decimal.Parse(tbox_valor.Text))
                    };

                    if (tbox_codigo.Text == "")
                    {
                        (new tipocarroRepositorio()).inserir(tpcar);
                    }
                    else
                    {
                        //alterar
                        tpcar.tipocarro_codigo = int.Parse(tbox_codigo.Text);
                        (new tipocarroRepositorio()).alterar(tpcar);
                    }


                    MessageBox.Show("Dados salvos! Código: " + tpcar.tipocarro_codigo);
                    btn_cancelar_Click(sender, e);
                }
                else
                {
                    MessageBox.Show("Informar o nome!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erro ao salvar! " + ex.Message);
            }
        }