private void btnEmprestimo_Click(object sender, EventArgs e) { try { if (txtIdLeitor.Text == "" || txtIdLivro.Text == "") { throw new Exception("Escolha o livro E o leitor antes de realizar um empréstimo"); } Emprestimo emprestimo = new Emprestimo(0, 0, 0, DateTime.Now, DateTime.Now, DateTime.Now); emprestimo.IdLivro = int.Parse(txtIdLivro.Text); emprestimo.IdLeitor = int.Parse(txtIdLeitor.Text); emprestimo.DataEmprestimo = Convert.ToDateTime(txtEmprestimo.Text); emprestimo.DataDevolucaoPrevista = DateTime.Now.AddDays(15); emprestimo.DataDevolucaoReal = new DateTime(1990, 01, 01); emprestimoBLL.IncluirEmprestimo(emprestimo); MessageBox.Show("Emprestimo realizado com sucesso!", "Aviso", MessageBoxButtons.OK); } catch (Exception ex) { MessageBox.Show("Erro: " + ex.Message.ToString()); } finally { txtIdLivro.Text = ""; txtCodigoLivro.Text = ""; txtTituloLivro.Text = ""; txtAutorLivro.Text = ""; } }
private void btnNovo_Click(object sender, EventArgs e) { Emprestimo novoEmp = new Emprestimo(int.Parse(txtIdLivro.Text), // instancia um novo obj emprestimo int.Parse(txtIdLeitor.Text), DateTime.Parse(mtxtDataEmp.Text), DateTime.Parse(mtxtDataDev.Text)); try { EmprestimoBLL empBLL = new EmprestimoBLL(); empBLL.IncluirEmprestimo(novoEmp); // inclui o emprestimo MessageBox.Show("Empréstimo incluído com sucesso"); // se deu certo, avisamos ao usuario limparTela(); } catch (Exception ex) { MessageBox.Show("Erro: " + ex.Message.ToString()); } }