private void btnDevolver_Click(object sender, EventArgs e) { try { if (txtId.Text.Trim() == "") { throw new Exception("id vazio"); } EmprestimoBLL bll = new EmprestimoBLL(); Emprestimo emp = bll.SelecionarEmprestimoPorId(int.Parse(txtId.Text)); // selecionamos o emprestimo escolhido if (emp.DataDevolucaoReal != Convert.ToDateTime("01/01/1900")) // se o emprestimo ja foi devolvido { throw new Exception("Livro já devolvido!"); } emp.DataDevolucaoReal = DateTime.Now; // atribuimos ao emprestimo a data atual bll.AlterarEmprestimo(emp); // alteramos o emprestimo com a nova data, ficando assim 'devolvido' if (emp.DataDevolucaoReal > emp.DataDevolucaoPrevista) { MessageBox.Show("Livro devolvido com atraso!"); } else { MessageBox.Show("Livro devolvido no prazo"); } } catch (Exception ex) { MessageBox.Show("Erro: " + ex.Message.ToString()); } }
private void btnAlterar_Click(object sender, EventArgs e) { Emprestimo empAlterado = new Emprestimo(int.Parse(txtIdLeitor.Text), int.Parse(txtIdLeitor.Text), Convert.ToDateTime(mtxtDataEmp.Text), Convert.ToDateTime(mtxtDataDev.Text)); try { EmprestimoBLL empBLL = new EmprestimoBLL(); empBLL.AlterarEmprestimo(empAlterado); } catch (Exception ex) { MessageBox.Show("Erro: " + ex.Message.ToString()); } }