public void AlterarEmprestimo(tb_emprestimo dto, int idemprestimo, tb_locatario professor)
        {
            try
            {
                AzureBiblioteca db   = new AzureBiblioteca();
                tb_locatario    data = db.tb_locatario.Where(x => x.nu_cpf == professor.nu_cpf).ToList().Single();

                if (data.nm_locatario != null)
                {
                    professor.id_locatario = data.id_locatario;
                    EmprestimoDB.AlterarEmprestimo(dto, idemprestimo, professor);
                }
            }
            catch (Exception)
            {
                AzureBiblioteca db = new AzureBiblioteca();
                int             id;

                db.tb_locatario.Add(professor);
                id = db.SaveChanges();

                dto.tb_locatario_id_locatario = id;

                EmprestimoDB.AlterarEmprestimo(dto, idemprestimo);
            }
        }
Example #2
0
        private void txtCPF_Leave(object sender, EventArgs e)
        {
            try
            {
                CPF val = new CPF();
                cpf = val.ValidarCPF(txtCPF.Text);

                AzureBiblioteca db        = new AzureBiblioteca();
                tb_locatario    locatario = db.tb_locatario.Where(x => x.nu_cpf == txtCPF.Text).ToList().Single();

                if (locatario.nm_locatario != null)
                {
                    txtNome.Text    = locatario.nm_locatario;
                    txtEmail.Text   = locatario.ds_email;
                    txtCelular.Text = locatario.nu_celular;
                }
            }
            catch (ArgumentException ex)
            {
                MessageBox.Show($"{ex.Message}", "Biblioteca",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("A sequência não contém elementos"))
                {
                    return;
                }
                else
                {
                    MessageBox.Show($"Ocorreu um erro não identificado: {ex.Message}", "Biblioteca",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        public void RemoverLocatorio(int idlocatorio)
        {
            var func = new tb_locatario {
                id_locatario = idlocatorio
            };

            db.Entry(func).State = EntityState.Deleted;
            db.SaveChanges();
        }
        public void AlterarLocatorio(tb_locatario dto, int idlocatario)
        {
            tb_locatario nha = db.tb_locatario.Where(x => x.id_locatario == idlocatario).ToList().Single();

            nha.nu_cpf       = dto.nu_cpf;
            nha.nm_locatario = dto.nm_locatario;
            nha.nu_celular   = dto.nu_celular;

            db.SaveChanges();
        }
Example #5
0
 private void ConsultarLocatario()
 {
     if (rdnlocatorio.Checked == true)
     {
         if (mktCPF.Text != "   .   .   -")
         {
             LocatorioBusiness locatorio = new LocatorioBusiness();
             tb_locatario      dto       = locatorio.ListarPOrCPFLocatario(mktCPF.Text);
             lblLocatario.Text = dto.nm_locatario;
             idlocatario       = dto.id_locatario;
         }
     }
 }
        public int CadastroNovoEmprestimo(tb_emprestimo dto, tb_locatario professor)
        {
            try
            {
                DateTime ontem = DateTime.Today;
                ontem = ontem.AddDays(-1);
                if (dto.dt_devolucao.Day - DateTime.Today.Day < 0)
                {
                    throw new ArgumentException("Impossivel devolver um livro ontem!");
                }

                ValidarTexto val = new ValidarTexto();
                val.ValidarEmail(professor.ds_email);
                val.ValidarNome(dto.nm_funcionario);
                val.ValidarNome(professor.nm_locatario);

                ValidarNumero valN = new ValidarNumero();
                valN.ValidarTelefoneCelular(professor.nu_celular);

                AzureBiblioteca db   = new AzureBiblioteca();
                tb_locatario    data = db.tb_locatario.Where(x => x.nu_cpf == professor.nu_cpf).ToList().Single();

                if (data.nm_locatario != null)
                {
                    dto.tb_locatario_id_locatario = data.id_locatario;
                    return(EmprestimoDB.CadastroNovoEmprestimo(dto));
                }

                return(0);
            }
            catch (ArgumentException ex)
            {
                System.Windows.Forms.MessageBox.Show($"{ex.Message}", "Biblioteca",
                                                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception)
            {
                AzureBiblioteca db = new AzureBiblioteca();
                int             id;

                db.tb_locatario.Add(professor);
                id = db.SaveChanges();

                dto.tb_locatario_id_locatario = id;

                return(EmprestimoDB.CadastroNovoEmprestimo(dto));
            }

            return(0);
        }
Example #7
0
        private void Emprestimo()
        {
            tb_emprestimo emprestimo = new tb_emprestimo();

            emprestimo.bt_devolvido      = false;
            emprestimo.dt_emprestimo     = DateTime.Now;
            emprestimo.nm_funcionario    = txtFuncionario.Text;
            emprestimo.dt_devolucao      = Convert.ToDateTime(dtpDevolucao.Text);
            emprestimo.tb_livro_id_livro = Convert.ToInt32(cboLivro.SelectedValue);

            tb_locatario prof = new tb_locatario();

            prof.nm_locatario = txtNome.Text;
            prof.nu_celular   = txtCelular.Text;
            prof.nu_cpf       = txtCPF.Text;
            prof.ds_email     = txtEmail.Text;

            EmprestimoBusiness emprestimos = new EmprestimoBusiness();

            cad = emprestimos.CadastroNovoEmprestimo(emprestimo, prof);
        }
Example #8
0
        private void AlterarEmprestimo()
        {
            tb_emprestimo emprestimo = new tb_emprestimo();

            emprestimo.bt_devolvido      = chkDevolvido.Checked;
            emprestimo.nm_funcionario    = txtFuncionario.Text;
            emprestimo.dt_devolucao      = Convert.ToDateTime(dtpDevolucao.Text);
            emprestimo.tb_livro_id_livro = Convert.ToInt32(cboLivro.SelectedValue);
            emprestimo.dt_emprestimo     = Convert.ToDateTime(dtpEmprestimo.Text);

            tb_locatario prof = new tb_locatario();

            prof.nm_locatario = txtNome.Text;
            prof.nu_celular   = txtCelular.Text;
            prof.nu_cpf       = txtCPF.Text;
            prof.ds_email     = txtEmail.Text;

            EmprestimoBusiness emprestimos = new EmprestimoBusiness();

            emprestimos.AlterarEmprestimo(emprestimo, id, prof);
        }
        public void AlterarEmprestimo(tb_emprestimo dto, int idemprestimo, tb_locatario locatario)
        {
            tb_locatario loc = db.tb_locatario.Where(x => x.id_locatario == locatario.id_locatario).ToList().Single();

            loc.nm_locatario = locatario.nm_locatario;
            loc.nu_celular   = locatario.nu_celular;
            loc.nu_cpf       = locatario.nu_cpf;
            loc.ds_email     = locatario.ds_email;

            db.SaveChanges();

            tb_emprestimo emp = db.tb_emprestimo.Where(x => x.id_emprestimo == idemprestimo).ToList().Single();

            emp.nm_funcionario    = dto.nm_funcionario;
            emp.dt_devolucao      = dto.dt_devolucao;
            emp.dt_emprestimo     = dto.dt_emprestimo;
            emp.bt_devolvido      = dto.bt_devolvido;
            emp.tb_livro_id_livro = dto.tb_livro_id_livro;

            db.SaveChanges();
        }
Example #10
0
 public void AlterarLocatario(tb_locatario dto, int idlocatario)
 {
     db.AlterarLocatorio(dto, idlocatario);
 }
Example #11
0
 public void CadastrarLocatario(tb_locatario dto)
 {
     db.CadastrarLocatorio(dto);
 }
        public tb_locatario ListarporLocatarioCPF(string CPF)
        {
            tb_locatario func = db.tb_locatario.Where(x => x.nu_cpf == CPF).ToList().Single();

            return(func);
        }
        public tb_locatario ListarporIdLocatario(int idlocatario)
        {
            tb_locatario func = db.tb_locatario.Where(x => x.id_locatario == idlocatario).ToList().Single();

            return(func);
        }
 public void CadastrarLocatorio(tb_locatario dto)
 {
     db.tb_locatario.Add(dto);
     db.SaveChanges();
 }