private void btRealizarEmprestimo_Click(object sender, EventArgs e) { inicioBLL ibll = new inicioBLL(); var ids = ibll.pesquisar_idClienteLivroReserva(reserva.idReserva); if (ids.Count != 0 && ids != null) { livrosEmprestimoDTO objLiv = new livrosEmprestimoDTO(); clientesEmprestimoDTO objCli = new clientesEmprestimoDTO(); objLiv.idLivro = ids[1]; objLiv.nomeLivro = cboLivroReserva.Text; objCli.idCliente = ids[0]; objCli.nomeCliente = cboClienteReserva.Text; List <livrosEmprestimoDTO> ledto = new List <livrosEmprestimoDTO>(); List <clientesEmprestimoDTO> cedto = new List <clientesEmprestimoDTO>(); ledto.Add(objLiv); cedto.Add(objCli); frmNovoEmprestimo frm = new frmNovoEmprestimo(ledto, cedto); this.Close(); frm.Show(); } else { MessageBox.Show("Não foi possível criar o empréstimo. \nPor favor, contate o desenvolvedor."); } }
private void cboLivroEmprestimo_KeyPress(object sender, KeyPressEventArgs e) { cboLivroEmprestimo.Items.Clear(); cboLivroEmprestimo.SelectionStart = cboLivroEmprestimo.Text.Length; if (codLivros.Count != 0) { codLivros.Clear(); } MySqlDataAdapter msa = new MySqlDataAdapter(); DataTable dt = new DataTable(); try { if (cboLivroEmprestimo.Text != "") { if (Conexao.con.State.ToString() == "Open") { Conexao.con.Close(); } Conexao.con.Open(); MySqlCommand msc = Conexao.con.CreateCommand(); msc.CommandType = CommandType.Text; msc.CommandText = "call pesquisar_livros(@texto, @limite)"; msc.Parameters.AddWithValue("@texto", cboLivroEmprestimo.Text); msc.Parameters.AddWithValue("@limite", 10); MySqlDataReader msdr = msc.ExecuteReader(); if (msdr.HasRows) { lblErroBuscaLivro.Text = ""; Conexao.con.Close(); MySqlDataAdapter da = new MySqlDataAdapter(msc); da.Fill(dt); foreach (DataRow dr in dt.Rows) { livrosEmprestimoDTO ledto = new livrosEmprestimoDTO(); ledto.idLivro = dr[0].ToString(); ledto.nomeLivro = dr[1].ToString(); codLivros.Add(ledto); cboLivroEmprestimo.Items.Add(dr[1].ToString()); } } else { if (cboLivroEmprestimo.Text.Length >= 2) lblErroBuscaLivro.Text = String.Format("Não foi possível encontrar um livro com \'{0}\'", cboLivroEmprestimo.Text); } Conexao.con.Close(); } } catch (Exception ex) { MessageBox.Show("Não foi possível realizar a consulta dos livros" + ex.Message); } }