private void ListarRegistos() { if (!BDconnection.verifySGBDConnection()) { return; } SqlCommand cmd = new SqlCommand(); cmd.Connection = BDconnection.getConnection(); cmd.CommandText = "SELECT * FROM SAA.REGISTOS_DO_NMEC ( @NMEC )"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@NMEC", nmecAluno.Text); SqlDataReader reader = cmd.ExecuteReader(); listRegistos.Items.Clear(); while (reader.Read()) { Registo R = new Registo(); R.ID_Registo = reader["ID_Registo"].ToString(); R.NMEC = reader["NMEC"].ToString(); R.ID_UC = reader["ID_UC"].ToString(); R.ID_Aval = reader["ID_Aval"].ToString(); listRegistos.Items.Add(R); } BDconnection.getConnection().Close(); currentRegisto = 0; ShowRegisto(); }
private void ShowRegisto() { if (listRegistos.Items.Count == 0 | currentRegisto < 0) { return; } Registo R = new Registo(); R = (Registo)listRegistos.Items[currentRegisto]; id_registo.Text = R.ID_Registo.ToString(); nmecRegisto.Text = R.NMEC; id_uc_Registo.Text = R.ID_UC; id_Aval_Registo.Text = R.ID_Aval; }
private void confirmUpdateBtn_Click(object sender, EventArgs e) { if (!BDconnection.verifySGBDConnection()) { if (!BDconnection.verifySGBDConnection()) { return; } } Registo R = new Registo(); SqlCommand cmd = new SqlCommand(); cmd.Connection = BDconnection.getConnection(); if (String.IsNullOrEmpty(id_falta.Text)) { if (String.IsNullOrEmpty(id_uc_Registo.Text) || String.IsNullOrEmpty(notaBox.Text)) //id_aval???? { MessageBox.Show("Todos os campos devem estar preenchidos"); } else { try { cmd.CommandText = "EXEC SAA.updateNota @ID_Nota, @Nota, @ID_Registo, @ID_UC, @ID_Aval "; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@ID_Nota", Int32.Parse(id_nota.Text)); cmd.Parameters.AddWithValue("@Nota", Decimal.Parse(notaBox.Text)); cmd.Parameters.AddWithValue("@ID_Registo", Int32.Parse(id_registo.Text)); cmd.Parameters.AddWithValue("@ID_UC", Int32.Parse(id_uc_Registo.Text)); cmd.Parameters.AddWithValue("@ID_Aval", Int32.Parse(id_Aval_Registo.Text)); cmd.ExecuteNonQuery(); string output = String.Format("Nota:{0} Atualizada", id_nota.Text); MessageBox.Show(output); } catch (SqlException ex) { DisplaySqlErrors(ex); } catch { MessageBox.Show("Ditite os campos corretamente"); } } } if (String.IsNullOrEmpty(id_nota.Text)) { if (String.IsNullOrEmpty(id_uc_Registo.Text) || String.IsNullOrEmpty(comboBoxtipoFalta.Text)) //id_aval???? { MessageBox.Show("Todos os campos devem estar preenchidos"); } else { try { cmd.CommandText = "EXEC SAA.updateFalta @ID_FALTA, @TipoFalta, @ID_Registo, @ID_UC, @ID_Aval "; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@ID_FALTA", Int32.Parse(id_falta.Text)); cmd.Parameters.AddWithValue("@TipoFalta", comboBoxtipoFalta.SelectedItem); cmd.Parameters.AddWithValue("@ID_Registo", Int32.Parse(id_registo.Text)); cmd.Parameters.AddWithValue("@ID_UC", Int32.Parse(id_uc_Registo.Text)); cmd.Parameters.AddWithValue("@ID_Aval", Int32.Parse(id_Aval_Registo.Text)); cmd.ExecuteNonQuery(); string output = String.Format("Falta:{0} Atualizada", id_falta.Text); MessageBox.Show(output); } catch (SqlException ex) { DisplaySqlErrors(ex); } catch { MessageBox.Show("Ditite os campos corretamente"); } } } comboBoxtipoFalta.Enabled = false; notaBox.ReadOnly = true; confirmUpdateBtn.Visible = false; cancelarBtn.Visible = false; eliminarBtn.Visible = true; confirmUpdateBtn.Visible = false; updateBtn.Visible = true; id_uc_Registo.ReadOnly = true; id_Aval_Registo.ReadOnly = true; }
private void ListarFN() { if (!BDconnection.verifySGBDConnection()) { return; } SqlCommand cmd = new SqlCommand(); cmd.Connection = BDconnection.getConnection(); cmd.CommandText = "EXEC SAA.INFO_REGISTO @ID_Registo"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@ID_Registo", id_registo.Text); SqlDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { //Falta_Nota FN = new Falta_Nota(); Registo R = new Registo(); try { R.ID_Registo = reader["ID_Registo"].ToString(); R.ID_Nota = reader["ID_Nota"].ToString(); R.Nota = reader["Nota"].ToString(); R.NMEC = reader["NMEC"].ToString(); R.ID_UC = reader["ID_UC"].ToString(); R.ID_Aval = reader["ID_Aval"].ToString(); id_nota.Text = R.ID_Nota; notaBox.Text = R.Nota; nmecRegisto.Text = R.NMEC; id_uc_Registo.Text = R.ID_UC; id_Aval_Registo.Text = R.ID_Aval; } catch (Exception e) { Console.WriteLine("Nao e nota"); } try { R.ID_Registo = reader["ID_Registo"].ToString(); R.NMEC = reader["NMEC"].ToString(); R.ID_UC = reader["ID_UC"].ToString(); R.ID_Aval = reader["ID_Aval"].ToString(); R.ID_Falta = reader["ID_Falta"].ToString(); R.tipoFalta = reader["tipo_Falta"].ToString(); id_falta.Text = R.ID_Falta; nmecRegisto.Text = R.NMEC; id_uc_Registo.Text = R.ID_UC; id_Aval_Registo.Text = R.ID_Aval; comboBoxtipoFalta.Text = R.tipoFalta; } catch (Exception e) { Console.WriteLine("Nao e falta"); } } BDconnection.getConnection().Close(); currentRegisto = 0; //ShowFN(); }