private void loadClientesNome(object sender, EventArgs e) { if (!Connection.verifySGBDConnection()) { return; } String boxNome = textBoxSearchCnome.Text; // default search: lista todos os clientes na BD if (boxNome.Length == 0) { String query = "exec getCliente @nome=''"; if (!Clean.IsClean(query)) { MessageBox.Show(Clean.Err()); return; } SqlCommand cmd = new SqlCommand(query, Connection.get()); SqlDataReader reader = cmd.ExecuteReader(); listBoxClientes.Items.Clear(); while (reader.Read()) { Cliente C = new Cliente(); C.CC = reader["CC"].ToString(); C.NIF = reader["nif"].ToString(); C.UserID = reader["userID"].ToString(); C.Nome_proprio = reader["nome_proprio"].ToString(); C.Apelido = reader["apelido"].ToString(); C.Email = reader["email"].ToString(); double tmp; Double.TryParse(reader["saldo"].ToString(), out tmp); C.Saldo = tmp; C.Tel = reader["contacto_telefonico"].ToString(); listBoxClientes.Items.Add(C); } } else { String apelido = ""; String nome = ""; if (boxNome.Contains(" ")) { nome = boxNome.Split(' ')[0]; apelido = boxNome.Split(' ')[1]; } else { nome = boxNome; } String query = "exec getCliente @nome='" + nome + "', @apelido='" + apelido + "'"; if (!Clean.IsClean(query)) { MessageBox.Show(Clean.Err()); return; } SqlCommand cmd = new SqlCommand(query, Connection.get()); SqlDataReader reader = cmd.ExecuteReader(); listBoxClientes.Items.Clear(); while (reader.Read()) { Cliente C = new Cliente(); C.CC = reader["CC"].ToString(); C.NIF = reader["nif"].ToString(); C.UserID = reader["userID"].ToString(); C.Nome_proprio = reader["nome_proprio"].ToString(); C.Apelido = reader["apelido"].ToString(); C.Email = reader["email"].ToString(); double tmp; Double.TryParse(reader["saldo"].ToString(), out tmp); C.Saldo = tmp; C.Tel = reader["contacto_telefonico"].ToString(); listBoxClientes.Items.Add(C); } } Connection.close(); currentClient = 0; if (listBoxClientes.Items.Count == 0) { listBoxClientes.Items.Add("Sem clientes a apresentar"); currentClient = -1; } ShowClient(); }
private void loadFaturas(object sender = null, EventArgs e = null) { if (!Connection.verifySGBDConnection()) { return; } String minVal, maxVal, query; if (textBoxSearchFaturaMin.Text.Length == 0) { minVal = "null"; } else { minVal = textBoxSearchFaturaMin.Text; } if (textBoxSearchFaturaMax.Text.Length == 0) { maxVal = "null"; } else { maxVal = textBoxSearchFaturaMax.Text; } String queryDate = "@data=" + datePicked; if (datePicked != "null") { queryDate = "@data='" + datePicked + "'"; } if (minVal == "null") { query = "exec getFaturas @cc=" + Cliente.Escolhido.CC.ToString() + ", " + queryDate + ", @valor_max=" + maxVal; } else { query = "exec getFaturas @cc=" + Cliente.Escolhido.CC.ToString() + ", " + queryDate + ", @valor_min=" + minVal + ", @valor_max=" + maxVal; } if (!Clean.IsClean(query)) { MessageBox.Show(Clean.Err()); return; } SqlCommand cmd = new SqlCommand(query, Connection.get()); SqlDataReader reader = cmd.ExecuteReader(); listBoxFaturas.Items.Clear(); while (reader.Read()) { Fatura f = new Fatura(); f.Data = reader["data"].ToString(); f.Descricao = reader["descricao"].ToString(); f.Valor = reader["valor"].ToString(); listBoxFaturas.Items.Add(f); } currentFatura = 0; if (listBoxFaturas.Items.Count == 0) { listBoxFaturas.Items.Add("Sem faturas a apresentar"); currentFatura = -1; } Connection.close(); ShowFatura(); }
private void loadRevisores(object sender = null, EventArgs e = null) { if (!Connection.verifySGBDConnection()) { return; } boxNome = textBoxSearchRevisorNome.Text; boxApelido = "null"; if (boxNome.Length == 0) { boxNome = "null"; } else if (boxNome.Contains(" ")) { String[] tmp = boxNome.Split(' '); boxNome = tmp[0]; boxApelido = tmp[1]; } boxCC = textBoxSearchRevisorCC.Text; if (boxCC.Length == 0) { boxCC = "null"; } boxSalarioMin = textBoxSearchRevisorMin.Text; if (boxSalarioMin.Length == 0) { boxSalarioMin = "null"; } boxSalarioMax = textBoxSearchRevisorMax.Text; if (boxSalarioMax.Length == 0) { boxSalarioMax = "null"; } String query = "exec getRevisor @cc=" + boxCC + ", @nome=" + boxNome + ", @apelido=" + boxApelido + ", " + "@salario_min=" + boxSalarioMin + ", @salario_max=" + boxSalarioMax; if (!Clean.IsClean(query)) { MessageBox.Show(Clean.Err()); return; } SqlCommand cmd = new SqlCommand(query, Connection.get()); SqlDataReader reader = cmd.ExecuteReader(); listBoxRevisores.Items.Clear(); while (reader.Read()) { Revisor r = new Revisor(); r.Apelido = reader["apelido"].ToString(); r.Cc = reader["CC"].ToString(); r.Email = reader["email"].ToString(); r.NomeProprio = reader["nome_proprio"].ToString(); r.Salario = reader["salario"].ToString(); r.Telefone = reader["telefone"].ToString(); listBoxRevisores.Items.Add(r); } currentRevisor = 0; if (listBoxRevisores.Items.Count == 0) { listBoxRevisores.Items.Add("Sem revisores a apresentar"); currentRevisor = -1; } Connection.close(); ShowRevisor(); }
private void loadHorarios(object sender, EventArgs e) { if (!Connection.verifySGBDConnection()) { return; } bool PartidaEChegada = true; if (comboBoxPartida.SelectedItem == null) { MessageBox.Show("Partida inválida!"); return; } String hora_partida = "null"; String hora_chegada = "null"; String chegada = "null"; String partida = comboBoxPartida.SelectedItem.ToString(); if (comboBoxChegada.SelectedItem == null) { PartidaEChegada = false; } else { chegada = comboBoxChegada.SelectedItem.ToString(); } if (textBoxSearchHoraPartida.Text.Length > 0) { hora_partida = textBoxSearchHoraPartida.Text; } if (textBoxSearchHoraChegada.Text.Length > 0) { hora_chegada = textBoxSearchHoraChegada.Text; } String query; if (PartidaEChegada) { query = "exec horariosPC @partida='" + partida + "', @chegada='" + chegada + "', " + "@hora_partida=" + hora_partida + ", @hora_chegada=" + hora_chegada; } else { query = "exec horariosC @partida='" + partida + "', @hora_partida=" + hora_partida; } if (!Clean.IsClean(query, "-")) { MessageBox.Show(Clean.Err()); return; } SqlCommand cmd = new SqlCommand(query, Connection.get()); SqlDataReader reader = cmd.ExecuteReader(); listBoxHorarios.Items.Clear(); while (reader.Read()) { Horario h = new Horario(); h.Chegada = reader["estacaoC"].ToString(); h.Comboio = reader["comboio"].ToString(); h.HoraChegada = reader["horaC"].ToString(); h.HoraPartida = reader["horaP"].ToString(); h.Linha = reader["linha"].ToString(); h.ParagemChegada = reader["id2"].ToString(); h.ParagemPartida = reader["id1"].ToString(); h.Partida = reader["estacaoP"].ToString(); h.Viagem = reader["viagem"].ToString(); h.Preco = reader["preco"].ToString(); listBoxHorarios.Items.Add(h); } currentHorario = 0; if (listBoxHorarios.Items.Count == 0) { listBoxBilhetes.Items.Add("Sem horarios a apresentar"); currentHorario = -1; } Connection.close(); ShowHorario(); }