예제 #1
0
        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 cboClienteEmprestimo_KeyPress(object sender, KeyPressEventArgs e)
        {
            cboClienteEmprestimo.Items.Clear();
            cboClienteEmprestimo.SelectionStart = cboClienteEmprestimo.Text.Length;

            if (listClientes.Count != 0)
            {
                listClientes.Clear();
            }

            MySqlDataAdapter msa = new MySqlDataAdapter();
            DataTable dt = new DataTable();

            try
            {
                if (cboClienteEmprestimo.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_cliente_regularizado(@texto)";
                    msc.Parameters.AddWithValue("@texto", cboClienteEmprestimo.Text);
                    MySqlDataReader msdr = msc.ExecuteReader();

                    if (msdr.HasRows)
                    {
                        lblErroBuscaCliente.Text = "";
                        Conexao.con.Close();
                        MySqlDataAdapter da = new MySqlDataAdapter(msc);
                        da.Fill(dt);

                        foreach (DataRow dr in dt.Rows)
                        {
                            clientesEmprestimoDTO cedto = new clientesEmprestimoDTO();
                            cedto.idCliente = dr[0].ToString();
                            cedto.nomeCliente = dr[1].ToString();
                            listClientes.Add(cedto);
                            cboClienteEmprestimo.Items.Add(dr[1].ToString());
                        }
                    }
                    else
                    {
                        if (cboClienteEmprestimo.Text.Length >= 2)
                            lblErroBuscaCliente.Text = String.Format("Não foi encontrado nenhum cliente regulariado com \'{0}\'", cboClienteEmprestimo.Text);
                    }

                    Conexao.con.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Não foi possível realizar a consulta dos livros" + ex.Message);
            }
        }