private void buttonValider_Click(object sender, EventArgs e) { int idPrevision = 0; if (!buttonValiderModifClick &&comboBoxQualification.SelectedItem != null && numericUpDownNbJours.Value > 0) { Prevision Prev = new Prevision(((ProjetForfait)comboBoxProjet.SelectedItem).CodeProjet, ((Qualification)comboBoxQualification.SelectedItem), (short)numericUpDownNbJours.Value, idPrevision ); if (DaoProjet.AddPrevision(Prev, out idPrevision) == true) { Prev.CodePrevision = idPrevision; previsionBindingSource.Add(Prev); } else MessageBox.Show("La prévision n'a pas été ajouté"); previsionBindingSource.ResumeBinding(); } else if(buttonValiderModifClick) { ((Prevision)laQualifDataGridViewTextBoxColumn.DataGridView.CurrentRow.DataBoundItem).LaQualif = (Qualification)comboBoxQualification.SelectedItem; Prevision p = (Prevision)dataGridViewPrevisions.CurrentRow.DataBoundItem; p.NbJours = Convert.ToInt16(numericUpDownNbJours.Value); previsionBindingSource.ResetBindings(true); } groupBoxPrevision.Visible = false; }
public static bool AddPrevision(Prevision prev, out int idPrev) { using (SqlConnection sqlConnect = GetConnection()) { using (SqlCommand sqlCde = new SqlCommand()) { sqlCde.Connection = sqlConnect; string strsql = "AddPrevision"; try { sqlCde.CommandType = CommandType.StoredProcedure; sqlCde.CommandText = strsql; //Ajout des paramètres sqlCde.Parameters.Add(new SqlParameter("@idprojet", SqlDbType.Int)).Value = prev.CodeProjet; sqlCde.Parameters.Add(new SqlParameter("@idqualif", SqlDbType.TinyInt)).Value = Convert.ToInt32(prev.LaQualif.CodeQualif); sqlCde.Parameters.Add(new SqlParameter("@nbJours", SqlDbType.SmallInt)).Value = prev.NbJours; sqlCde.Parameters.Add(new SqlParameter("@idPrevision", SqlDbType.Int)).Direction = ParameterDirection.Output; int n = sqlCde.ExecuteNonQuery(); if (n == 1) MessageBox.Show("Mise a jour éffectuée"); idPrev = (int)sqlCde.Parameters["@idPrevision"].Value; return true; } catch (Exception ex) { throw new DAOException(ex.Message); } } } }
public static List<Prevision> GetPrevisionByProjet(int idProjet) { using (SqlConnection sqlConnect = GetConnection()) { using (SqlCommand sqlCde = new SqlCommand()) { sqlCde.Connection = sqlConnect; string strsql = "GetAllPrevisions"; try { sqlCde.CommandType = CommandType.StoredProcedure; sqlCde.CommandText = strsql; //Definition du parametre SqlParameter p1 = new SqlParameter("@vidprojet", SqlDbType.Int); p1.Direction = ParameterDirection.Input; p1.Value = idProjet; sqlCde.Parameters.Add(p1); SqlDataReader sqlRdr = sqlCde.ExecuteReader(); previsions = new List<Prevision>(); while (sqlRdr.Read()) { Prevision previs = new Prevision() { CodePrevision = sqlRdr.GetInt32(0), CodeProjet = sqlRdr.GetInt32(1), NbJours = sqlRdr.GetInt16(3), LaQualif = new Qualification() { CodeQualif = (sbyte)sqlRdr.GetByte(2) }, }; previsions.Add(previs); } sqlRdr.Close(); return previsions; } catch (Exception ex) { throw new DAOException(ex.Message); } } } }