예제 #1
0
        public List <Alugados> Listar()
        {
            try
            {
                AbrirConexao();
                Cmd = new SqlCommand("SELECT * FROM Aluguel", Con);
                //Cmd.Parameters.AddWithValue("@v1", codigo);
                Dr = Cmd.ExecuteReader();

                List <Alugados> lista = new List <Alugados>(); // lista vazia

                while (Dr.Read())
                {
                    Alugados p = new Alugados();
                    p.codigoAluguel = Convert.ToInt32(Dr["codigoAluguel"]);
                    //p.codigoCliente = Convert.ToInt32(Dr["codigoCliente"]);
                    //p.codigoImovel = Convert.ToInt32(Dr["codigoImovel"]);
                    //p.dataInicioAluguel = Convert.ToDateTime(Dr["dataInicio"]);


                    lista.Add(p);
                }

                return(lista);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao listar os Clientes: " + ex.Message);
            }
            finally
            {
                FecharConexao();
            }
        }
예제 #2
0
        //    //Método para atualizar dados: Update
        //    public void Atualizar(Pessoa p)
        //    {
        //        try
        //        {
        //            AbrirConexao();
        //            Cmd = new SqlCommand("update Pessoa set Nome=@v1, Endereco=@v2, Email=@v3 where Id=@v4" , Con);

        //            Cmd.Parameters.AddWithValue("@v1", p.Nome);
        //            Cmd.Parameters.AddWithValue("@v2", p.Endereco);
        //            Cmd.Parameters.AddWithValue("@v3", p.Email);
        //            Cmd.Parameters.AddWithValue("@v4", p.Id);

        //            Cmd.ExecuteNonQuery();
        //        }
        //        catch (Exception ex)
        //        {

        //            throw new Exception("Erro ao atualizar o Cliente: " + ex.Message);
        //        }
        //        finally
        //        {
        //            FecharConexao();
        //        }
        //    }

        //    //Método para excluir dados: Delete
        //    public void Excluir(int Id)
        //    {
        //        try
        //        {
        //            AbrirConexao();
        //            Cmd = new SqlCommand("delete from Pessoa where Id=@v1", Con);

        //            Cmd.Parameters.AddWithValue("@v1", Id);

        //            Cmd.ExecuteNonQuery();
        //        }
        //        catch (Exception ex)
        //        {

        //            throw new Exception("Erro ao excluir o Cliente: " + ex.Message);
        //        }
        //        finally
        //        {
        //            FecharConexao();
        //        }
        //    }

        //    //Método para obter 1 Pessoa pelo Código(Chave Primária)
        //    public Pessoa PesquisarPorCodigo(int Id)
        //    {
        //        try
        //        {
        //            AbrirConexao();
        //            Cmd = new SqlCommand("select * from Pessoa where Id=@v1", Con);
        //            Cmd.Parameters.AddWithValue("@v1", Id);
        //            Dr = Cmd.ExecuteReader(); //execurção da leitura das informações do BD

        //            Pessoa p = null; //criando um espaço de memória: ponteiro

        //            if (Dr.Read())
        //            {
        //                p = new Pessoa();

        //                p.Id        = Convert.ToInt32(Dr["Id"]);
        //                p.Nome      = Convert.ToString(Dr["Nome"]);
        //                p.Endereco  = Convert.ToString(Dr["Endereco"]);
        //                p.Email     = Convert.ToString(Dr["Email"]);

        //            }
        //            return p;
        //        }
        //        catch (Exception ex)
        //        {

        //            throw new Exception("Erro ao pesquisar o Cliente: " + ex.Message);
        //        }
        //        finally
        //        {
        //            FecharConexao();
        //        }
        //}

        //    //Método para listar todos os clientes cadastrados:
        //    public List<Pessoa> Listar()
        //    {
        //        try
        //        {
        //            AbrirConexao();
        //            Cmd = new SqlCommand("select * from Pessoa", Con);
        //            Dr = Cmd.ExecuteReader();

        //            List<Pessoa> lista = new List<Pessoa>(); // lista vazia

        //            while(Dr.Read())
        //            {
        //                Pessoa p    = new Pessoa();
        //                p.Id        = Convert.ToInt32(Dr["Id"]);
        //                p.Nome      = Convert.ToString(Dr["Nome"]);
        //                p.Endereco  = Convert.ToString(Dr["Endereco"]);
        //                p.Email     = Convert.ToString(Dr["Email"]);

        //                lista.Add(p);
        //            }

        //            return lista;

        //        }
        //        catch (Exception ex)
        //        {

        //            throw new Exception("Erro ao listar os Clientes: " + ex.Message);
        //        }
        //        finally
        //        {
        //            FecharConexao();
        //        }
        //    }



        public Alugados PesquisarCodAluguel(int codigo)  //Método para obter Código(Chave Primária)
        {
            try
            {
                AbrirConexao();
                Cmd = new SqlCommand("select * from Aluguel where codigoAluguel=@v1", Con);
                Cmd.Parameters.AddWithValue("@v1", codigo);
                Dr = Cmd.ExecuteReader(); //execurção da leitura das informações do BD

                Alugados p = null;        //criando um espaço de memória: ponteiro

                if (Dr.Read())
                {
                    p = new Alugados();

                    p.codigoAluguel = Convert.ToInt32(Dr["codigoAluguel"]);
                    p.dataInicio    = Convert.ToDateTime(Dr["dataInicio"]);
                    p.dataFim       = Convert.ToDateTime(Dr["dataFim"]);
                    //p.Nome = Convert.ToString(Dr["Nome"]);
                    //p.Endereco = Convert.ToString(Dr["Endereco"]);
                    //p.Email = Convert.ToString(Dr["Email"]);
                }
                return(p);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao pesquisar o codigo aluguel" + ex.Message);
            }
            finally
            {
                FecharConexao();
            }
        }
예제 #3
0
        public Alugados PesquisarAgendado(int codigo, DateTime d)  //Método para obter Código(Chave Primária)
        {
            try
            {
                AbrirConexao();
                Cmd = new SqlCommand("select * from Aluguel where codigoCliente=@v1 and dataInicio>@v2", Con);
                Cmd.Parameters.AddWithValue("@v1", codigo);
                Cmd.Parameters.AddWithValue("@v2", d);
                Dr = Cmd.ExecuteReader(); //execurção da leitura das informações do BD

                Alugados p = null;        //criando um espaço de memória: ponteiro

                if (Dr.Read())
                {
                    p = new Alugados();

                    p.codigoAluguel = Convert.ToInt32(Dr["codigoAluguel"]);
                    p.codigoCliente = Convert.ToInt32(Dr["codigoCliente"]);
                    p.codigoImovel  = Convert.ToInt32(Dr["codigoImovel"]);
                    p.dataInicio    = Convert.ToDateTime(Dr["dataInicio"]);
                    p.dataFim       = Convert.ToDateTime(Dr["dataFim"]);
                    p.pagamento     = Convert.ToInt32(Dr["codigoPagamento"]);
                }
                return(p);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao pesquisar os dados do Cliente " + ex.Message);
            }
            finally
            {
                FecharConexao();
            }
        }
예제 #4
0
        public Alugados PesquisarImovelClienteDataAlugado(int codigo, int cli, DateTime di)  //Método para obter Código(Chave Primária)
        {
            try
            {
                AbrirConexao();
                Cmd = new SqlCommand("SELECT * FROM Aluguel where codigoImovel=@v1 and codigoCliente=@v2 and (dataInicio <= @v3 and dataFim >= @v3)", Con);
                Cmd.Parameters.AddWithValue("@v1", codigo);
                Cmd.Parameters.AddWithValue("@v2", cli);
                Cmd.Parameters.AddWithValue("@v3", di);
                Dr = Cmd.ExecuteReader(); //execurção da leitura das informações do BD

                Alugados p = null;        //criando um espaço de memória: ponteiro

                if (Dr.Read())
                {
                    p = new Alugados();

                    p.codigoAluguel = Convert.ToInt32(Dr["codigoAluguel"]);
                    p.dataInicio    = Convert.ToDateTime(Dr["dataInicio"]);
                }
                return(p);
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao pesquisar " + ex.Message);
            }
            finally
            {
                FecharConexao();
            }
        }
예제 #5
0
        protected void btnCadastrar_Click(object sender, EventArgs e)
        {
            string pagamento = DropDownList1.SelectedValue.ToString();

            if (pagamento == "Selecione:")
            {
                lblMensagem.Text = txtNome.Text + " não escolheu forma de pagamento!";
            }
            else
            {
                try
                {
                    Alugados alu = new Alugados();
                    alu.codigoImovel  = Convert.ToInt32(txtCodigo5.Text);
                    alu.codigoCliente = Convert.ToInt32(txtCodigo.Text);
                    alu.dataInicio    = Convert.ToDateTime(dataInicio.Text);
                    alu.dataFim       = Convert.ToDateTime(dataFim.Text);
                    alu.pagamento     = Convert.ToInt32(DropDownList1.SelectedValue);

                    AluguelDAL aludal = new AluguelDAL();

                    aludal.Gravar(alu); //gravando aluguel

                    int codigo5 = Convert.ToInt32(txtCodigo5.Text);
                    //Imovel2 i = new Imovel2();

                    ImovelDAL imovdal = new ImovelDAL();
                    imovdal.Atualizar(codigo5);

                    txtCodigo.Text   = "";
                    txtNome.Text     = "";
                    txtTelefone.Text = "";
                    txtCPF.Text      = "";
                    txtLogin.Text    = "";
                    txtSenha.Text    = "";

                    txtCodigo5.Text      = "";
                    txtBairro5.Text      = "";
                    txtTipoImovel5.Text  = "";
                    txtTipoNegocio5.Text = "";
                    txtQuarto5.Text      = "";
                    txtValor5.Text       = "";

                    dataInicio.Text = "";
                    dataFim.Text    = "";

                    pagamento             = "Selecione:";
                    DropDownList1.Enabled = false;

                    btnCadastrar.Enabled = false;

                    lblMensagem.Text = "Aluguel registrado com sucesso!";
                }
                catch (Exception ex)
                {
                    lblMensagem.Text = ex.Message;
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            txtCodigo.Text   = Request.QueryString["codigoCliente"];
            txtNome.Text     = Request.QueryString["nomeCliente"];
            txtTelefone.Text = Request.QueryString["telefoneCliente"];
            txtCPF.Text      = Request.QueryString["cpfCliente"];
            txtLogin.Text    = Request.QueryString["loginCliente"];
            txtSenha.Text    = Request.QueryString["senhaCliente"];

            //txtCodigo5.Text = Request.QueryString["codigoImovel"];
            //txtBairro5.Text = Request.QueryString["nomeBairro"];
            //txtTipoImovel5.Text = Request.QueryString["tipo"];
            //txtTipoNegocio5.Text = Request.QueryString["negocio"];
            //txtQuarto5.Text = Request.QueryString["quarto"];
            //txtValor5.Text = Request.QueryString["valor"];

            //dataInicio.Text = Request.QueryString["dataInicio"];
            //dataFim.Text = Request.QueryString["dataFim"];


            //pegando dados da tabela aluguel atraves do codigo
            int        codigo = Convert.ToInt32(txtCodigo.Text);
            AluguelDAL d      = new AluguelDAL();
            Alugados   c      = d.PesquisarCodigoCliente(codigo);

            if (c != null)
            {
                txtCodigoImovel.Text        = Convert.ToString(c.codigoImovel);
                txtdataFim.Text             = Convert.ToString(c.dataFim);
                DropDownList1.SelectedValue = Convert.ToString(c.pagamento);
                DropDownList1.Enabled       = false;
            }


            //pegando valor da tabela imovel atraves do codigo
            int       codigoImovel = Convert.ToInt32(c.codigoImovel);
            ImovelDAL aludal       = new ImovelDAL();
            Imovel    alu          = aludal.PesquisarCodigoImovel(codigoImovel);

            if (alu != null)
            {
                txtBairro.Text  = Convert.ToString(alu.nomeBairro);
                txtNegocio.Text = Convert.ToString(alu.negocioNome);
                txtTipo.Text    = Convert.ToString(alu.nomeTipoImovel);
                txtQuarto.Text  = Convert.ToString(alu.quantidadeQuarto);
                txtValor.Text   = Convert.ToString(alu.valorImovel);
            }
        }
예제 #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            txtCodigo3.Text      = Request.QueryString["codigoImovel"];
            txtBairro3.Text      = Request.QueryString["nomeBairro"];
            txtTipoImovel3.Text  = Request.QueryString["tipo"];
            txtTipoNegocio3.Text = Request.QueryString["negocio"];
            txtQuarto3.Text      = Request.QueryString["quarto"];
            txtValor3.Text       = Request.QueryString["valor"];
            txtDataIni.Text      = Request.QueryString["dataIni"];
            txtDatafim.Text      = Request.QueryString["datafim"];

            txtCodigoCliente.Text = Request.QueryString["codigoCliente"];
            tbNome.Text           = Request.QueryString["nomeCliente"];
            tbTelefone.Text       = Request.QueryString["telefoneCliente"];
            tbCPF.Text            = Request.QueryString["cpfCliente"];
            tbLogin.Text          = Request.QueryString["loginCliente"];
            tbSenha.Text          = Request.QueryString["senhaCliente"];



            DateTime dataAtual = DateTime.Now.Date;

            txtDataAtual.Text = Convert.ToString(dataAtual);

            tbNome.Enabled     = false;
            tbTelefone.Enabled = false;
            tbCPF.Enabled      = false;
            tbLogin.Enabled    = false;
            tbSenha.Enabled    = false;


            int codigo = Convert.ToInt32(txtCodigoCliente.Text);

            AluguelDAL aludal  = new AluguelDAL();
            Alugados   alugado = aludal.PesquisarCodigoClienteData(codigo);

            if (alugado != null)
            {
                lblMensagem2.Text = "Você tem um aluguel sem uma data de entrega definida!  Não pode fazer uma reserva! ";

                btnSeguinte.Visible = false;
            }
        }
예제 #8
0
        public void Excluir(Alugados a)
        {
            try
            {
                AbrirConexao();
                Cmd = new SqlCommand("delete from Aluguel where codigoCliente=@v1 and  dataInicio=@v2", Con);

                Cmd.Parameters.AddWithValue("@v1", a.codigoCliente);
                Cmd.Parameters.AddWithValue("@v2", a.dataInicio);

                Cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao excluir o Cliente: " + ex.Message);
            }
            finally
            {
                FecharConexao();
            }
        }
예제 #9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            txtCodigo3.Text      = Request.QueryString["codigoImovel"];
            txtBairro3.Text      = Request.QueryString["nomeBairro"];
            txtTipoImovel3.Text  = Request.QueryString["tipo"];
            txtTipoNegocio3.Text = Request.QueryString["negocio"];
            txtQuarto3.Text      = Request.QueryString["quarto"];
            txtValor3.Text       = Request.QueryString["valor"];

            txtCodigoCliente.Text = Request.QueryString["codigoCliente"];
            tbNome.Text           = Request.QueryString["nomeCliente"];
            tbTelefone.Text       = Request.QueryString["telefoneCliente"];
            tbCPF.Text            = Request.QueryString["cpfCliente"];
            tbLogin.Text          = Request.QueryString["loginCliente"];
            tbSenha.Text          = Request.QueryString["senhaCliente"];

            tbNome.Enabled     = false;
            tbTelefone.Enabled = false;
            tbCPF.Enabled      = false;
            tbLogin.Enabled    = false;
            tbSenha.Enabled    = false;

            int codigo = Convert.ToInt32(txtCodigoCliente.Text);

            AluguelDAL aludal  = new AluguelDAL();
            Alugados   alugado = aludal.PesquisarCodigoCliente(codigo);

            try
            {
                int codigoaluguel = alugado.codigoAluguel;


                lblMensagem.Text    = "Cliente " + tbNome.Text + " já possui um imóvel alugado!";
                btnSeguinte.Visible = false;
            }
            catch (Exception)
            {
            }
        }
예제 #10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            txtCodigo.Text      = Request.QueryString["codigoImovel"];
            txtBairro.Text      = Request.QueryString["nomeBairro"];
            txtTipoImovel.Text  = Request.QueryString["tipo"];
            txtTipoNegocio.Text = Request.QueryString["negocio"];
            txtSituacao.Text    = Request.QueryString["situacao"];
            txtQuarto.Text      = Request.QueryString["quarto"];
            txtValor.Text       = Request.QueryString["valor"];

            DateTime dataAtual = DateTime.Now.Date;

            txtDataAtual.Text = Convert.ToString(dataAtual);

            lbldataFim.Visible   = false;
            txtdataFim.Visible   = false;
            btnCadastrar.Visible = false;

            int      codigo = Convert.ToInt32(txtCodigo.Text);
            DateTime di     = DateTime.Now.Date;


            AluguelDAL dal = new AluguelDAL();
            Alugados   lu  = dal.PesquisarCodImovelDataFim(codigo);

            if (lu == null)
            {
                //lblMensagem.Text = "imovel nao existe em aluguel";
                txtSituacao.Text = "Disponivel";
            }
            else
            {
                lblMensagem.Text     = "* Imóvel sem Data de entrega definida!";
                btnCadastrar.Visible = false;
                btnResevar.Visible   = false;
                txtSituacao.Text     = "Indisponivel";
            }
        }
예제 #11
0
        public void Gravar2(Alugados a)
        {
            try
            {
                //Abrir Conexão:
                AbrirConexao();
                Cmd = new SqlCommand("insert into Aluguel (codigoImovel, codigoCliente, dataInicio, codigoPagamento) values (@v1, @v2, @v3, @v5)", Con);
                Cmd.Parameters.AddWithValue("@v1", a.codigoImovel);
                Cmd.Parameters.AddWithValue("@v2", a.codigoCliente);
                Cmd.Parameters.AddWithValue("@v3", a.dataInicio);
                Cmd.Parameters.AddWithValue("@v5", a.pagamento);

                Cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("Erro ao gravar: " + ex.Message);
            }
            finally
            {
                FecharConexao();
            }
        }
예제 #12
0
        protected void btnExcluir_Click(object sender, EventArgs e)
        {
            try
            {
                Alugados alu = new Alugados();

                alu.codigoCliente = Convert.ToInt32(txtCodigoCliente.Text);
                alu.dataInicio    = Convert.ToDateTime(lblInicio.Text);

                AluguelDAL aludal = new AluguelDAL();

                aludal.Excluir(alu); //excluindo aluguel

                lblInicio.Text = "";
                lblFim.Text    = "";


                lblMensagem2.Text = "Excluido com sucesso!";
            }
            catch (Exception)
            {
                lblMensagem.Text = "Erro ao excluir!";
            }
        }
        protected void btnSeguinte_Click(object sender, EventArgs e)
        {
            string codigocli = txtCodigoCliente.Text;


            int    codigo      = Convert.ToInt32(txtCodigoCliente.Text);
            string nomeCliente = tbNome.Text;
            int    telefone    = Convert.ToInt32(tbTelefone.Text);
            int    cpf         = Convert.ToInt32(tbCPF.Text);
            string login       = tbLogin.Text;
            string senha       = tbSenha.Text;

            AluguelDAL          aludal = new AluguelDAL();
            Alugados            alu    = aludal.PesquisarCodigoCliente(codigo);
            DateTime            datIni = alu.dataInicio;
            Nullable <DateTime> datFim = alu.dataFim;

            DateTime di = Convert.ToDateTime(datIni);

            DateTime data = DateTime.Now.Date;

            if (di != null)
            {
                if (data > di)
                {
                    //alugado

                    try         //entra no try para conferir se tem uma reserva
                    {
                        //agendado

                        //DateTime data = DateTime.Now.Date;

                        AluguelDAL          aludaldata   = new AluguelDAL();
                        Alugados            aludata      = aludaldata.PesquisarAgendado(codigo, data);
                        int                 codigoclire  = aludata.codigoCliente;
                        int                 codigoImovre = aludata.codigoImovel;
                        int                 pagamentore  = aludata.pagamento;
                        DateTime            dataInire    = aludata.dataInicio;
                        Nullable <DateTime> dataFimre    = aludata.dataFim;

                        ImovelDAL imodal       = new ImovelDAL();
                        Imovel    imov         = imodal.PesquisarCodigoImovel(codigoImovre);
                        string    nomeBairrore = imov.nomeBairro;
                        string    negociore    = imov.negocioNome;
                        string    tipore       = imov.nomeTipoImovel;
                        int       quartore     = imov.quantidadeQuarto;
                        float     valorre      = imov.valorImovel;

                        string pagre = "";
                        switch (pagamentore)
                        {
                        case 0:
                            pagre = "Selecione:";
                            break;

                        case 1:
                            pagre = "À Vista";
                            break;

                        case 2:
                            pagre = "Boleto";
                            break;

                        case 3:
                            pagre = "Cartão";
                            break;
                        }

                        lblMensagem.Text = "cliente possui um aluguel e uma reserva";
                        //string url = null;
                        //url = "DadosGerais.aspx?codigoImovel=" + codigoImovre + "&nomeBairro=" + nomeBairrore + "&tipo=" + tipore + "&negocio=" + negociore + "&quarto=" + quartore + "&valor=" + valorre + "&dataInicio=" + dataInire + "&pagamento=" + pagre + "&dataFim=" + dataFimre + "&codigoCliente=" + codigo + "&nomeCliente=" + nomeCliente + "&telefoneCliente=" + telefone + "&cpfCliente=" + cpf + "&loginCliente=" + login + "&senhaCliente=" + senha;
                        //Response.Redirect(url);
                    }
                    catch (Exception)         //se nao tiver uma reserva entra no catch, vai mostrar só o alugado.
                    {
                        //throw;

                        AluguelDAL          aludaldata    = new AluguelDAL();
                        Alugados            aludata       = aludaldata.PesquisarAlugado(codigo, data);
                        int                 codigoclidata = aludata.codigoCliente;
                        int                 codigoImov    = aludata.codigoImovel;
                        int                 pagamento     = aludata.pagamento;
                        DateTime            dataIni       = aludata.dataInicio;
                        Nullable <DateTime> dataFim       = aludata.dataFim;

                        ImovelDAL imodal     = new ImovelDAL();
                        Imovel    imov       = imodal.PesquisarCodigoImovel(codigoImov);
                        string    nomeBairro = imov.nomeBairro;
                        string    negocio    = imov.negocioNome;
                        string    tipo       = imov.nomeTipoImovel;
                        int       quarto     = imov.quantidadeQuarto;
                        float     valor      = imov.valorImovel;

                        string pag = "";
                        switch (pagamento)
                        {
                        case 0:
                            pag = "Selecione:";
                            break;

                        case 1:
                            pag = "À Vista";
                            break;

                        case 2:
                            pag = "Boleto";
                            break;

                        case 3:
                            pag = "Cartão";
                            break;
                        }

                        lblMensagem.Text = "cliente possui só um aluguel";
                        //string url = null;
                        //url = "DadosGerais.aspx?codigoImovel=" + codigoImov + "&nomeBairro=" + nomeBairro + "&tipo=" + tipo + "&negocio=" + negocio + "&quarto=" + quarto + "&valor=" + valor + "&dataInicio=" + dataIni + "&pagamento=" + pag + "&dataFim=" + dataFim + "&codigoCliente=" + codigo + "&nomeCliente=" + nomeCliente + "&telefoneCliente=" + telefone + "&cpfCliente=" + cpf + "&loginCliente=" + login + "&senhaCliente=" + senha;
                        //Response.Redirect(url);
                    }
                }
                else
                {
                    //agendado

                    try
                    {
                        // conferir se tem um aluguel

                        AluguelDAL          aludaldata    = new AluguelDAL();
                        Alugados            aludata       = aludaldata.PesquisarAlugado(codigo, data);
                        int                 codigoclidata = aludata.codigoCliente;
                        int                 codigoImov    = aludata.codigoImovel;
                        int                 pagamento     = aludata.pagamento;
                        DateTime            dataIni       = aludata.dataInicio;
                        Nullable <DateTime> dataFim       = aludata.dataFim;

                        ImovelDAL imodal     = new ImovelDAL();
                        Imovel    imov       = imodal.PesquisarCodigoImovel(codigoImov);
                        string    nomeBairro = imov.nomeBairro;
                        string    negocio    = imov.negocioNome;
                        string    tipo       = imov.nomeTipoImovel;
                        int       quarto     = imov.quantidadeQuarto;
                        float     valor      = imov.valorImovel;

                        string pag = "";
                        switch (pagamento)
                        {
                        case 0:
                            pag = "Selecione:";
                            break;

                        case 1:
                            pag = "À Vista";
                            break;

                        case 2:
                            pag = "Boleto";
                            break;

                        case 3:
                            pag = "Cartão";
                            break;
                        }

                        lblMensagem.Text = "cliente possui uma reserva e um aluguel";
                        //string url = null;
                        //url = "DadosGerais.aspx?codigoImovel=" + codigoImov + "&nomeBairro=" + nomeBairro + "&tipo=" + tipo + "&negocio=" + negocio + "&quarto=" + quarto + "&valor=" + valor + "&dataInicio=" + dataIni + "&pagamento=" + pag + "&dataFim=" + dataFim + "&codigoCliente=" + codigo + "&nomeCliente=" + nomeCliente + "&telefoneCliente=" + telefone + "&cpfCliente=" + cpf + "&loginCliente=" + login + "&senhaCliente=" + senha;
                        //Response.Redirect(url);
                    }
                    catch (Exception)         //entra no catch se nao houver aluguel, mostra a reserva
                    {
                        //throw;

                        //agendado

                        //DateTime data = DateTime.Now.Date;

                        AluguelDAL          aludaldata   = new AluguelDAL();
                        Alugados            aludata      = aludaldata.PesquisarAgendado(codigo, data);
                        int                 codigoclire  = aludata.codigoCliente;
                        int                 codigoImovre = aludata.codigoImovel;
                        int                 pagamentore  = aludata.pagamento;
                        DateTime            dataInire    = aludata.dataInicio;
                        Nullable <DateTime> dataFimre    = aludata.dataFim;

                        ImovelDAL imodal       = new ImovelDAL();
                        Imovel    imov         = imodal.PesquisarCodigoImovel(codigoImovre);
                        string    nomeBairrore = imov.nomeBairro;
                        string    negociore    = imov.negocioNome;
                        string    tipore       = imov.nomeTipoImovel;
                        int       quartore     = imov.quantidadeQuarto;
                        float     valorre      = imov.valorImovel;

                        string pagre = "";
                        switch (pagamentore)
                        {
                        case 0:
                            pagre = "Selecione:";
                            break;

                        case 1:
                            pagre = "À Vista";
                            break;

                        case 2:
                            pagre = "Boleto";
                            break;

                        case 3:
                            pagre = "Cartão";
                            break;
                        }

                        lblMensagem.Text = "cliente possui só uma reserva";
                        //string url = null;
                        //url = "DadosGerais.aspx?codigoImovel=" + codigoImovre + "&nomeBairro=" + nomeBairrore + "&tipo=" + tipore + "&negocio=" + negociore + "&quarto=" + quartore + "&valor=" + valorre + "&dataInicio=" + dataInire + "&pagamento=" + pagre + "&dataFim=" + dataFimre + "&codigoCliente=" + codigo + "&nomeCliente=" + nomeCliente + "&telefoneCliente=" + telefone + "&cpfCliente=" + cpf + "&loginCliente=" + login + "&senhaCliente=" + senha;
                        //Response.Redirect(url);
                    }
                }
            }
            else
            {
                lblMensagem.Text    = "<br />Cliente não possui imóvel alugado!<br /><br />Clique em Alugar para escolher um imóvel";
                btnAlugar.Visible   = true;
                btnSeguinte.Visible = false;
            }


            //string url = null;

            //url = "Cliente3.aspx?codigoCliente=" + codigo + "&nomeCliente=" + nomeCliente + "&telefoneCliente=" + telefone + "&cpfCliente=" + cpf + "&loginCliente=" + login + "&senhaCliente=" + senha;

            //Response.Redirect(url);
        }
예제 #14
0
        protected void btnCadastrar_Click(object sender, EventArgs e)
        {
            string dataini = Selecao2.Text;
            string datafim = Selecao.Text;

            if (dataini == "")
            {
                lblMensagem1.Text = "Escolha ao menos a data Inicial";
            }
            else
            {
                DateTime data           = DateTime.Now.Date;                 //gera data atual
                DateTime data2          = Convert.ToDateTime(Selecao2.Text); //dataInicial
                string   datafimreserva = txtDatafim.Text;                   //data final de reserva

                if (datafimreserva == "")                                    //data do fim da reserva estiver vazio
                {
                    if (data > data2)                                        //data atual maior que data inicial
                    {
                        //comandos
                        lblMensagem1.Text = "Data Incial não é válida!";
                        Selecao2.Text     = null;
                    }//fecha o if
                    else
                    {
                        if (Selecao.Text != "")                                      //campo data final não for vazio
                        {
                            DateTime dateIni    = Convert.ToDateTime(Selecao2.Text); //data inicial
                            DateTime data3      = Convert.ToDateTime(Selecao.Text);  //data Final
                            DateTime dataIniMes = dateIni.AddMonths(1);

                            if (data2 >= data3 || data3 < dataIniMes)//data inicial maior q data final
                            {
                                lblMensagem1.Text = "Data Final invalida! (Data de entrega menor que a Data Inicial ou Data de entrega menor que 30 dias da Data Inicial)";
                                Selecao.Text      = null;
                            }
                            else
                            {
                                try
                                {
                                    int      codImov    = Convert.ToInt32(txtCodigo4.Text);
                                    DateTime dataInicio = Convert.ToDateTime(Selecao2.Text);
                                    DateTime dataFim    = Convert.ToDateTime(Selecao.Text);

                                    AluguelDAL          aludal    = new AluguelDAL();
                                    Alugados            alu       = aludal.PesquisarCodigoClienteDataValida(codImov, dataInicio, dataFim);
                                    DateTime            datInicio = alu.dataInicio;
                                    Nullable <DateTime> datFim    = alu.dataFim;

                                    string datIni  = Convert.ToString(datInicio);
                                    string tamanho = datIni;
                                    datIni = tamanho.Remove(10, tamanho.Length - 10);

                                    string df       = Convert.ToString(datFim);
                                    string tamanho2 = df;
                                    df = tamanho2.Remove(10, tamanho.Length - 10);

                                    lblMensagem1.Text = "* Já existe um agendamento pra essa data! " + datInicio + " até " + datFim + ". Escolha outra data";
                                    Selecao.Text      = "";
                                    Selecao2.Text     = "";
                                }
                                catch (Exception)
                                {
                                    int    codigo3  = Convert.ToInt32(txtCodigo4.Text);
                                    string bairro3  = txtBairro4.Text;
                                    string tipo3    = txtTipoImovel4.Text;
                                    string negocio3 = txtTipoNegocio4.Text;
                                    int    quarto3  = Convert.ToInt32(txtQuarto4.Text);
                                    float  valor3   = Convert.ToUInt32(txtValor4.Text);

                                    string dataInicio = Selecao2.Text;
                                    string dataFim    = Selecao.Text;

                                    int    codigo      = Convert.ToInt32(txtCodigo.Text);
                                    string nomeCliente = txtNome.Text;
                                    int    telefone    = Convert.ToInt32(txtTelefone.Text);
                                    int    cpf         = Convert.ToInt32(txtCPF.Text);
                                    string login       = txtLogin.Text;
                                    string senha       = txtSenha.Text;
                                    string url         = null;


                                    url = "FormaPagamento.aspx?codigoImovel=" + codigo3 + "&nomeBairro=" + bairro3 + "&tipo=" + tipo3 + "&negocio=" + negocio3 + "&quarto=" + quarto3 + "&valor=" + valor3 + "&dataInicio=" + dataInicio + "&dataFim=" + dataFim + "&codigoCliente=" + codigo + "&nomeCliente=" + nomeCliente + "&telefoneCliente=" + telefone + "&cpfCliente=" + cpf + "&loginCliente=" + login + "&senhaCliente=" + senha;

                                    Response.Redirect(url);
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                int      codImov    = Convert.ToInt32(txtCodigo4.Text);
                                DateTime dataInicio = Convert.ToDateTime(Selecao2.Text);

                                AluguelDAL          aludal    = new AluguelDAL();
                                Alugados            alu       = aludal.PesquisarCodigoClienteDataIniValida(codImov, dataInicio);
                                DateTime            datInicio = alu.dataInicio;
                                Nullable <DateTime> datFim    = alu.dataFim;

                                string datIni  = Convert.ToString(datInicio);
                                string tamanho = datIni;
                                datIni = tamanho.Remove(10, tamanho.Length - 10);

                                string df       = Convert.ToString(datFim);
                                string tamanho2 = df;
                                df = tamanho2.Remove(10, tamanho.Length - 10);

                                lblMensagem1.Text = "* Já existe um agendamento pra essa data! " + datInicio + " até " + datFim + ". Escolha outra data";
                                Selecao.Text      = "";
                                Selecao2.Text     = "";
                            }
                            catch (Exception)
                            {
                                int    codigo3  = Convert.ToInt32(txtCodigo4.Text);
                                string bairro3  = txtBairro4.Text;
                                string tipo3    = txtTipoImovel4.Text;
                                string negocio3 = txtTipoNegocio4.Text;
                                int    quarto3  = Convert.ToInt32(txtQuarto4.Text);
                                float  valor3   = Convert.ToUInt32(txtValor4.Text);

                                string dataInicio = Selecao2.Text;
                                string dataFim    = null;

                                int    codigo      = Convert.ToInt32(txtCodigo.Text);
                                string nomeCliente = txtNome.Text;
                                int    telefone    = Convert.ToInt32(txtTelefone.Text);
                                int    cpf         = Convert.ToInt32(txtCPF.Text);
                                string login       = txtLogin.Text;
                                string senha       = txtSenha.Text;
                                string url         = null;


                                url = "FormaPagamento.aspx?codigoImovel=" + codigo3 + "&nomeBairro=" + bairro3 + "&tipo=" + tipo3 + "&negocio=" + negocio3 + "&quarto=" + quarto3 + "&valor=" + valor3 + "&dataInicio=" + dataInicio + "&dataFim=" + dataFim + "&codigoCliente=" + codigo + "&nomeCliente=" + nomeCliente + "&telefoneCliente=" + telefone + "&cpfCliente=" + cpf + "&loginCliente=" + login + "&senhaCliente=" + senha;

                                Response.Redirect(url);
                            }
                        }
                    }
                }
                else
                {
                    //repete o codigo sem a data gerada automaticamente
                    DateTime datafimre = Convert.ToDateTime(txtDatafim.Text);
                    string   tamanho   = txtDatafim.Text;
                    txtDatafim.Text = tamanho.Remove(10, tamanho.Length - 10);
                    if (datafimre >= data2) //data fim reserva maior que data inicial
                    {
                        //comandos
                        lblMensagem1.Text = "Escolha uma data inicial maior que " + txtDatafim.Text;
                        Selecao2.Text     = null;
                    }//fecha o if
                    else
                    {
                        if (Selecao.Text != "")                                      //campo data final não for vazio
                        {
                            DateTime dateIni    = Convert.ToDateTime(Selecao2.Text); //data inicial
                            DateTime data3      = Convert.ToDateTime(Selecao.Text);  //data Final
                            DateTime dataIniMes = dateIni.AddMonths(1);

                            if (data2 >= data3 || data3 < dataIniMes)//data inicial maior q data final
                            {
                                lblMensagem1.Text = "Data Final invalida! (Data de entrega menor que a Data Inicial ou Data de entrega menor que 30 dias da Data Inicial)";
                                Selecao.Text      = null;
                            }
                            else
                            {
                                try
                                {
                                    int      codImov    = Convert.ToInt32(txtCodigo4.Text);
                                    DateTime dataInicio = Convert.ToDateTime(Selecao2.Text);
                                    DateTime dataFim    = Convert.ToDateTime(Selecao.Text);

                                    AluguelDAL          aludal    = new AluguelDAL();
                                    Alugados            alu       = aludal.PesquisarCodigoClienteDataValida(codImov, dataInicio, dataFim);
                                    DateTime            datInicio = alu.dataInicio;
                                    Nullable <DateTime> datFim    = alu.dataFim;

                                    string datIni   = Convert.ToString(datInicio);
                                    string tamanho3 = datIni;
                                    datIni = tamanho3.Remove(10, tamanho.Length - 10);

                                    string df       = Convert.ToString(datFim);
                                    string tamanho4 = df;
                                    df = tamanho4.Remove(10, tamanho.Length - 10);

                                    lblMensagem1.Text = "* Já existe um agendamento pra essa data! " + datInicio + " até " + datFim + ". Escolha outra data";
                                    Selecao.Text      = "";
                                    Selecao2.Text     = "";
                                }
                                catch (Exception)
                                {
                                    int    codigo3  = Convert.ToInt32(txtCodigo4.Text);
                                    string bairro3  = txtBairro4.Text;
                                    string tipo3    = txtTipoImovel4.Text;
                                    string negocio3 = txtTipoNegocio4.Text;
                                    int    quarto3  = Convert.ToInt32(txtQuarto4.Text);
                                    float  valor3   = Convert.ToUInt32(txtValor4.Text);

                                    string dataInicio = Selecao2.Text;
                                    string dataFim    = Selecao.Text;

                                    int    codigo      = Convert.ToInt32(txtCodigo.Text);
                                    string nomeCliente = txtNome.Text;
                                    int    telefone    = Convert.ToInt32(txtTelefone.Text);
                                    int    cpf         = Convert.ToInt32(txtCPF.Text);
                                    string login       = txtLogin.Text;
                                    string senha       = txtSenha.Text;
                                    string url         = null;


                                    url = "FormaPagamento.aspx?codigoImovel=" + codigo3 + "&nomeBairro=" + bairro3 + "&tipo=" + tipo3 + "&negocio=" + negocio3 + "&quarto=" + quarto3 + "&valor=" + valor3 + "&dataInicio=" + dataInicio + "&dataFim=" + dataFim + "&codigoCliente=" + codigo + "&nomeCliente=" + nomeCliente + "&telefoneCliente=" + telefone + "&cpfCliente=" + cpf + "&loginCliente=" + login + "&senhaCliente=" + senha;

                                    Response.Redirect(url);
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                int      codImov    = Convert.ToInt32(txtCodigo4.Text);
                                DateTime dataInicio = Convert.ToDateTime(Selecao2.Text);


                                AluguelDAL          aludal    = new AluguelDAL();
                                Alugados            alu       = aludal.PesquisarCodigoClienteDataIniValida(codImov, dataInicio);
                                DateTime            datInicio = alu.dataInicio;
                                Nullable <DateTime> datFim    = alu.dataFim;

                                string datIni   = Convert.ToString(datInicio);
                                string tamanho5 = datIni;
                                datIni = tamanho5.Remove(10, tamanho.Length - 10);

                                string df       = Convert.ToString(datFim);
                                string tamanho6 = df;
                                df = tamanho6.Remove(10, tamanho.Length - 10);

                                lblMensagem1.Text = "* Já existe um agendamento pra essa data! " + datInicio + " até " + datFim + ". Escolha outra data";
                                Selecao.Text      = "";
                                Selecao2.Text     = "";
                            }
                            catch (Exception)
                            {
                                int    codigo3  = Convert.ToInt32(txtCodigo4.Text);
                                string bairro3  = txtBairro4.Text;
                                string tipo3    = txtTipoImovel4.Text;
                                string negocio3 = txtTipoNegocio4.Text;
                                int    quarto3  = Convert.ToInt32(txtQuarto4.Text);
                                float  valor3   = Convert.ToUInt32(txtValor4.Text);

                                string dataInicio = Selecao2.Text;
                                string dataFim    = null;

                                int    codigo      = Convert.ToInt32(txtCodigo.Text);
                                string nomeCliente = txtNome.Text;
                                int    telefone    = Convert.ToInt32(txtTelefone.Text);
                                int    cpf         = Convert.ToInt32(txtCPF.Text);
                                string login       = txtLogin.Text;
                                string senha       = txtSenha.Text;
                                string url         = null;


                                url = "FormaPagamento.aspx?codigoImovel=" + codigo3 + "&nomeBairro=" + bairro3 + "&tipo=" + tipo3 + "&negocio=" + negocio3 + "&quarto=" + quarto3 + "&valor=" + valor3 + "&dataInicio=" + dataInicio + "&dataFim=" + dataFim + "&codigoCliente=" + codigo + "&nomeCliente=" + nomeCliente + "&telefoneCliente=" + telefone + "&cpfCliente=" + cpf + "&loginCliente=" + login + "&senhaCliente=" + senha;

                                Response.Redirect(url);
                            }
                        }
                    }
                }
            }
        }
예제 #15
0
        protected void btnGravar_Click(object sender, EventArgs e)
        {
            //int codicli = Convert.ToInt32(txtCodigo.Text);

            try
            {
                if (txtDataFim.Text == "")
                {
                    Alugados alu = new Alugados();
                    alu.codigoImovel  = Convert.ToInt32(txtCodigo5.Text);
                    alu.codigoCliente = Convert.ToInt32(txtCodigo.Text);
                    alu.dataInicio    = Convert.ToDateTime(txtDataInicial.Text);

                    alu.pagamento = Convert.ToInt32(Request.QueryString["pagamento"]);

                    AluguelDAL aludal = new AluguelDAL();

                    aludal.Gravar2(alu); //gravando aluguel

                    int codigo5 = Convert.ToInt32(txtCodigo5.Text);
                    //Imovel2 i = new Imovel2();

                    ImovelDAL imovdal = new ImovelDAL();
                    imovdal.Atualizar(codigo5);//aqui é passado o id do imovel para mudar a situação do imovel para alugado.


                    btnVoltar.Visible   = false;
                    btnGravar.Visible   = false;
                    btnImprimir.Visible = true;


                    lblMensagem.Text = "Aluguel registrado com sucesso!";
                }
                else
                {
                    Alugados alu = new Alugados();
                    alu.codigoImovel  = Convert.ToInt32(txtCodigo5.Text);
                    alu.codigoCliente = Convert.ToInt32(txtCodigo.Text);
                    alu.dataInicio    = Convert.ToDateTime(txtDataInicial.Text);
                    alu.dataFim       = Convert.ToDateTime(txtDataFim.Text);
                    alu.pagamento     = Convert.ToInt32(Request.QueryString["pagamento"]);

                    AluguelDAL aludal = new AluguelDAL();

                    aludal.Gravar(alu); //gravando aluguel

                    int codigo5 = Convert.ToInt32(txtCodigo5.Text);
                    //Imovel2 i = new Imovel2();

                    ImovelDAL imovdal = new ImovelDAL();
                    imovdal.Atualizar(codigo5);//aqui é passado o id do imovel para mudar a situação do imovel para alugado.


                    btnVoltar.Visible   = false;
                    btnGravar.Visible   = false;
                    btnImprimir.Visible = true;

                    lblMensagem.Text = "Aluguel registrado com sucesso!";
                }
            }
            catch (Exception ex)
            {
                lblMensagem.Text = ex.Message;
            }
        }