// Método de Recuperação: Dados Aluguel public List <MODEL.Aluguel> Select() { List <MODEL.Aluguel> lstAluguel = new List <MODEL.Aluguel>(); SqlConnection conexao = new SqlConnection(strCon); string sql = "SELECT * FROM Aluguel;"; SqlCommand cmd = new SqlCommand(sql, conexao); try { conexao.Open(); SqlDataReader dados = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (dados.Read()) { //dados do emprestimo CAMADAS.MODEL.Aluguel aluguel = new MODEL.Aluguel(); aluguel.id = Convert.ToInt32(dados["id"].ToString()); aluguel.cliente_id = Convert.ToInt32(dados["clientes_id"].ToString()); aluguel.date = Convert.ToDateTime(dados["data"].ToString()); //recuperar nome do cliente CAMADAS.DAL.Clientes dalCli = new Clientes(); CAMADAS.MODEL.Clientes Clientes = dalCli.SelectById(aluguel.cliente_id); aluguel.nomeCli = Clientes.nome; lstAluguel.Add(aluguel); } } catch { Console.WriteLine("Deu erro na consulta de Alugueis"); } finally { conexao.Close(); } return(lstAluguel); }
private void btnGravar_Click(object sender, EventArgs e) { CAMADAS.BLL.Clientes bllCli = new CAMADAS.BLL.Clientes(); string msg = ""; if (lblID.Text == "0") { msg = "Deseja inserir um novo cliente?"; } else { msg = "Deseja alterar o cliente atual?"; } DialogResult resposta = MessageBox.Show(msg, "Gravar", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (resposta == DialogResult.Yes) { CAMADAS.MODEL.Clientes clientes = new CAMADAS.MODEL.Clientes(); clientes.nome = txtNome.Text; clientes.telefone = txtTelefone.Text; clientes.cidade = txtCidade.Text; clientes.estado = txtEstado.Text; clientes.endereco = txtEndereco.Text; clientes.numero = txtNumero.Text; if (lblID.Text == "0") { bllCli.Insert(clientes); } else { bllCli.Update(clientes); } MessageBox.Show("Dados Gravados", "Gravar", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Dados Não Gravados", "Gravar", MessageBoxButtons.OK, MessageBoxIcon.Warning); } dgvClientes.DataSource = ""; dgvClientes.DataSource = bllCli.Select(); limparControle(); habilitaControles(false); habilitaBotoes(true); }
private void dgvClientes_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e) { if (dgvClientes.SelectedRows.Count > 0) { lblID.Text = dgvClientes.SelectedRows[0].Cells[0].Value.ToString(); int id = Convert.ToInt32(lblID.Text); CAMADAS.DAL.Clientes dalCli = new CAMADAS.DAL.Clientes(); CAMADAS.MODEL.Clientes cliente = dalCli.SelectByID(id); txtNome.Text = cliente.nome; txtTelefone.Text = Convert.ToString(cliente.telefone); txtCidade.Text = cliente.cidade; txtEstado.Text = cliente.estado; txtEstado.Text = cliente.estado; txtEndereco.Text = cliente.endereco; txtNumero.Text = Convert.ToString(cliente.numero); } }
//select Aluguel public List <MODEL.Aluguel> Select() { List <MODEL.Aluguel> lstAluguel = new List <MODEL.Aluguel>(); SqlConnection conexao = new SqlConnection(strCon); string sql = "Select * from Aluguel;"; SqlCommand cmd = new SqlCommand(sql, conexao); //tratamento exceção try { conexao.Open(); SqlDataReader dados = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (dados.Read()) { CAMADAS.MODEL.Aluguel aluguel = new MODEL.Aluguel(); aluguel.id = Convert.ToInt32(dados["id"].ToString()); aluguel.clienteID = Convert.ToInt32(dados["clienteID"].ToString()); CAMADAS.DAL.Clientes dalCli = new Clientes(); CAMADAS.MODEL.Clientes cliente = dalCli.SelectbyIdAluguel(aluguel.clienteID); aluguel.nome = cliente.nome; aluguel.carroID = Convert.ToInt32(dados["carroID"].ToString()); CAMADAS.DAL.Carros dalCar = new Carros(); CAMADAS.MODEL.Carros carro = dalCar.SelectByIdAluguel(aluguel.carroID); aluguel.modelo = carro.modelo; lstAluguel.Add(aluguel); } } catch { Console.WriteLine("Erro no Select Aluguel"); } finally { conexao.Close(); } return(lstAluguel); }
public List <MODEL.Emprestimo> SelectByID(int id) { List <MODEL.Emprestimo> lstEmprestimo = new List <MODEL.Emprestimo>(); SqlConnection conexao = new SqlConnection(strCon); string sql = "SELECT * FROM Emprestimo WHERE id=@id;"; SqlCommand cmd = new SqlCommand(sql, conexao); cmd.Parameters.AddWithValue("@id", id); try { conexao.Open(); SqlDataReader dados = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (dados.Read()) { //preencher com dados do emprestimo CAMADAS.MODEL.Emprestimo emprestimo = new MODEL.Emprestimo(); emprestimo.id = Convert.ToInt32(dados["id"].ToString()); emprestimo.clienteID = Convert.ToInt32(dados["clienteID"].ToString()); emprestimo.data = Convert.ToDateTime(dados["data"].ToString()); //recuperar nome do cliente CAMADAS.DAL.Clientes dalCli = new Clientes(); CAMADAS.MODEL.Clientes cliente = dalCli.SelectById(emprestimo.clienteID); emprestimo.nomeCli = cliente.nome; lstEmprestimo.Add(emprestimo); } } catch { Console.WriteLine("Deu erro na consulta de Emprestimo..."); } finally { conexao.Close(); } return(lstEmprestimo); }
public List <MODEL.Emprestimo> SelectByID(int ID) { List <MODEL.Emprestimo> LstEmprestimo = new List <MODEL.Emprestimo>(); SqlConnection conexao = new SqlConnection(strCon); string sql = "SELECT * FROM EMPRESTIMO WHERE ID=@ID"; SqlCommand cmd = new SqlCommand(sql, conexao); cmd.Parameters.AddWithValue("@ID", ID); try { conexao.Open(); SqlDataReader dados = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (dados.Read()) { CAMADAS.MODEL.Emprestimo emprestimo = new MODEL.Emprestimo(); emprestimo.ID = Convert.ToInt32(dados["ID"].ToString()); emprestimo.CLIENTE_ID = Convert.ToInt32(dados["CLIENTE_ID"].ToString()); emprestimo.DATA = Convert.ToDateTime(dados["DATA"].ToString()); CAMADAS.DAL.Clientes dalCli = new Clientes(); CAMADAS.MODEL.Clientes cliente = dalCli.SelectID(emprestimo.CLIENTE_ID); emprestimo.NOME_CLI = cliente.NOME; LstEmprestimo.Add(emprestimo); } } catch { Console.WriteLine("Deu erro na consulta do Emprestimo..."); } finally { conexao.Close(); } return(LstEmprestimo); }
public List <MODEL.Aluguel> Select() { List <MODEL.Aluguel> lstAluguel = new List <MODEL.Aluguel>(); SqlConnection conexao = new SqlConnection(strCon); string sql = "Select * from Aluguel"; SqlCommand cmd = new SqlCommand(sql, conexao); try { conexao.Open(); SqlDataReader dados = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (dados.Read()) { MODEL.Aluguel aluguel = new MODEL.Aluguel(); aluguel.id = Convert.ToInt32(dados["id"].ToString()); aluguel.clienteID = Convert.ToInt32(dados["clienteID"].ToString()); aluguel.data = Convert.ToDateTime(dados["data"].ToString()); //recuperar cliente CAMADAS.BLL.Clientes bllCli = new BLL.Clientes(); CAMADAS.MODEL.Clientes cliente = bllCli.SelectByID(aluguel.clienteID); aluguel.nome = cliente.nome; lstAluguel.Add(aluguel); } } catch { Console.WriteLine("Erro ao listar Banco sql-Avioes"); } finally { conexao.Close(); } return(lstAluguel); }
public List <MODEL.Emprestimo> Select() { List <MODEL.Emprestimo> lstEmprestimo = new List <MODEL.Emprestimo>(); SqlConnection conexao = new SqlConnection(strCon); string sql = "SELECT * FROM Emprestimo"; SqlCommand cmd = new SqlCommand(sql, conexao); try { conexao.Open(); SqlDataReader dados = cmd.ExecuteReader(CommandBehavior.CloseConnection); while (dados.Read()) { MODEL.Emprestimo emprestimo = new MODEL.Emprestimo(); emprestimo.id = Convert.ToInt32(dados["id"].ToString()); emprestimo.clienteId = Convert.ToInt32(dados["clienteID"].ToString()); emprestimo.data = Convert.ToDateTime(dados["data"].ToString()); //recuperar cliente CAMADAS.BLL.Clientes bllCli = new BLL.Clientes(); CAMADAS.MODEL.Clientes cliente = bllCli.SelectByID(emprestimo.clienteId); emprestimo.cliente = cliente.nome; lstEmprestimo.Add(emprestimo); } } catch { Console.WriteLine("Erro listar Emprestimo"); } finally { conexao.Close(); } return(lstEmprestimo); }