Example #1
0
 //Gestion de la suppression d'une mission
 public static bool DelMission(Mission miss)
 {
     using (SqlConnection sqlConnect = GetConnection())
     {
         using (SqlCommand sqlCde = new SqlCommand())
         {
             sqlCde.Connection = sqlConnect;
             string strsql = "DelMission";
             sqlCde.CommandText = strsql;
             sqlCde.CommandType = CommandType.StoredProcedure;
             sqlCde.Parameters.Clear();
             sqlCde.Parameters.Add(new SqlParameter("@idMission", SqlDbType.Int)).Value = miss.IdMission;
             try
             {
                 int n = sqlCde.ExecuteNonQuery();
                 if (n != 1)
                     throw new DaoExceptionAfficheMessage("La suppression a échoué");
                 return true;
             }
             catch (SqlException ex)
             {
                 throw new DaoExceptionAfficheMessage("La suppression a échoué : \n" + ex.Message, ex);
             }
         }
     }
 }
        public AfficherDétails(Mission miss, bool OuiNon, int code)
        {
            Demarrage(miss);
            if (OuiNon == true)
            {
                if (miss.Motif == null )
                {
                    ChangerEnabledTrueOrFalse(OuiNon);

                }
                else
                {
                    ChangerEnabledTrueOrFalse(!OuiNon);

                    MessageBox.Show("Cette mission est cloturée, la modification est désormais impossible");
                    buttonAnnuler.Enabled = true;

                }
            }
            else if (OuiNon == false)
            {
                ChangerEnabledTrueOrFalse(OuiNon);

                buttonValider.Enabled = false;
                buttonAnnuler.Enabled = true;

            }
            modifOrNot = true;
            codeEntreprise = code;
        }
Example #3
0
        // Ajout d'une mission
        public static bool AddMission(Mission miss, out int idMission)
        {
            using (SqlConnection sqlConnect = GetConnection())
            {
                using (SqlCommand sqlCde = new SqlCommand())
                {
                    sqlCde.Connection = sqlConnect;
                    string strSql = "AddMission";
                    try
                    {
                        sqlCde.CommandType = CommandType.StoredProcedure;
                        sqlCde.CommandText = strSql;

                        //Paramètres
                        sqlCde.Parameters.Add(new SqlParameter("@idEntreprise", SqlDbType.Int)).Value = miss.CodeEntreprise;
                        if (miss.Motif != null)
                            sqlCde.Parameters.Add(new SqlParameter("@idMotif", SqlDbType.TinyInt)).Value = miss.Motif.IdMotif;
                        sqlCde.Parameters.Add(new SqlParameter("@idQualification", SqlDbType.Int)).Value = miss.QualificationDemandee.IdQualification;
                        if(miss.NiveauDemande != null)
                            sqlCde.Parameters.Add(new SqlParameter("@idNiveau", SqlDbType.TinyInt)).Value = miss.NiveauDemande.IdNiveau;
                        sqlCde.Parameters.Add(new SqlParameter("@idConsultant", SqlDbType.TinyInt)).Value = miss.Consult.IdConsultant;
                        sqlCde.Parameters.Add(new SqlParameter("@dateouverture", SqlDbType.DateTime)).Value = miss.DateOuverture;
                        if (miss.DateFin != null)
                            sqlCde.Parameters.Add(new SqlParameter("@datefin", SqlDbType.DateTime)).Value = miss.DateFin;
                        if (miss.RemunerationProposee != null)
                            sqlCde.Parameters.Add(new SqlParameter("@remu", SqlDbType.Money)).Value = miss.RemunerationProposee;
                        if(miss.Precisions != string.Empty)
                        sqlCde.Parameters.Add(new SqlParameter("@precision", SqlDbType.VarChar)).Value = miss.Precisions;
                        if (miss.Duree != null)
                            sqlCde.Parameters.Add(new SqlParameter("@duree", SqlDbType.TinyInt)).Value = miss.Duree;

                        //Paramètre de sortie
                        sqlCde.Parameters.Add(new SqlParameter("@idMission", SqlDbType.Int)).Direction = ParameterDirection.Output;

                        int n = sqlCde.ExecuteNonQuery();
                        if (n != 1)
                            throw new DaoExceptionAfficheMessage("La création de la mission a échoué");
                        else
                            idMission = (int)sqlCde.Parameters["@idMission"].Value;
                        return true;
                    }
                    catch(SqlException ex)
                    {
                        throw new DaoExceptionAfficheMessage("La création de la mission a échoué : \n" + ex.Message, ex);
                    }

                }
            }
        }
 private void Demarrage(Mission miss)
 {
     InitializeComponent();
     try
     {
        missionBindingSource.ResumeBinding();
        missionBindingSource.DataSource = miss;
     }
     catch (DaoExceptionFinApplication defa)
     {
         MessageBox.Show(defa.Message);
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     AlimenterMotif();
     AlimenterNiveau();
     AlimenterQualifs();
     AlimenterConsultants();
     mission = miss;
     if (miss.Motif == null)
     {
         comboBoxMotif.SelectedIndex = -1;
     }
     if(miss.NiveauDemande == null)
     {
         comboBoxNiveau.SelectedIndex = -1;
     }
 }
        //Gestion de la validation
        private void buttonValider_Click(object sender, EventArgs e)
        {
            VerifsEtGestionDate();

            if (comboBoxConsultant.SelectedItem != null && comboBoxQualification.SelectedItem != null && motifDateFin == true)
            {
                int codeMiss = 0;
                Mission oMission = new Mission(codeMiss, codeEntreprise, (MotifFin)comboBoxMotif.SelectedItem, (Qualification)comboBoxQualification.SelectedItem,
                    (Niveau)comboBoxNiveau.SelectedItem, (Consultant)comboBoxConsultant.SelectedItem,
                    dateDebut, dateFin, remu, textBoxPrecision.Text, duree);
                if (comboBoxMotif.SelectedItem == null)
                    oMission.Motif = null;
                if (comboBoxNiveau.SelectedItem == null)
                    oMission.NiveauDemande = null;

                    if (modifOrNot == true)
                    {
                        try
                        {
                            if (DaoMission.UpdMission(oMission) == true)
                            {
                                codeMiss = mission.IdMission;
                                missionBindingSource.ResumeBinding();
                            }
                        }
                        catch (DaoExceptionAfficheMessage def)
                        {
                            MessageBox.Show(def.Message);
                        }
                        catch (Exception se)
                        {
                            MessageBox.Show(se.Message);
                        }
                    }
                    else if (modifOrNot == false)
                    {
                        try
                        {
                            if (DaoMission.AddMission(oMission, out codeMiss) == true)
                            {
                                oMission.IdMission = codeMiss;
                                frmMere.RefreshDataGridView(oMission);
                            }

                        }
                        catch (DaoExceptionAfficheMessage def)
                        {
                            MessageBox.Show(def.Message);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                    this.Close();
                }
            else
            {
                if (comboBoxConsultant.SelectedItem == null || comboBoxQualification.SelectedItem == null)
                {
                    labelMessageUtilis.ForeColor = Color.Red;
                    labelMessageUtilis.Text = "Veuillez renseigner les champs obligatoires";
                }
                else if (motifDateFin == false)
                {
                    labelMessageUtilis.ForeColor = Color.Red;
                    labelMessageUtilis.Text = "La date de fin et le motif de clôture sont indissociables";
                }

            }
        }
Example #6
0
 public static bool UpdMission(Mission miss)
 {
     using (SqlConnection sqlConnect = GetConnection())
     {
         using (SqlCommand sqlCde = new SqlCommand())
         {
             sqlCde.Connection = sqlConnect;
             string strsql = "UpdMissions";
             sqlCde.CommandText = strsql;
             sqlCde.CommandType = CommandType.StoredProcedure;
             sqlCde.Parameters.Clear();
             sqlCde.Parameters.Add(new SqlParameter("@idm", SqlDbType.Int)).Value = miss.IdMission;
             sqlCde.Parameters.Add(new SqlParameter("@vidEntreprise", SqlDbType.Int)).Value = miss.CodeEntreprise;
             if(miss.Motif != null)
                 sqlCde.Parameters.Add(new SqlParameter("@vidMotif", SqlDbType.TinyInt)).Value = miss.Motif.IdMotif;
             sqlCde.Parameters.Add(new SqlParameter("@vidQualif", SqlDbType.Int)).Value = miss.QualificationDemandee.IdQualification;
             if(miss.NiveauDemande != null)
                 sqlCde.Parameters.Add(new SqlParameter("@vidNiveau", SqlDbType.TinyInt)).Value = miss.NiveauDemande.IdNiveau;
             sqlCde.Parameters.Add(new SqlParameter("@vidConsult",SqlDbType.TinyInt)).Value = miss.Consult.IdConsultant;
             sqlCde.Parameters.Add(new SqlParameter("@vDateouv", SqlDbType.DateTime)).Value = miss.DateOuverture;
             if(miss.DateFin != null)
                 sqlCde.Parameters.Add(new SqlParameter("@vDatefin", SqlDbType.DateTime)).Value = miss.DateFin;
             if(miss.RemunerationProposee != null)
                 sqlCde.Parameters.Add(new SqlParameter("@vRemu", SqlDbType.Money)).Value = miss.RemunerationProposee;
             if(miss.Precisions != null)
                 sqlCde.Parameters.Add(new SqlParameter("@vPreci", SqlDbType.VarChar)).Value = miss.Precisions;
             if(miss.Duree != null)
                 sqlCde.Parameters.Add(new SqlParameter("@vDuree", SqlDbType.TinyInt)).Value = miss.Duree;
             try
             {
                 int n = sqlCde.ExecuteNonQuery();
                 if (n != 1)
                     throw new DaoExceptionAfficheMessage("La suppression a échoué");
                 return true;
             }
             catch (SqlException ex)
             {
                 throw new DaoExceptionAfficheMessage("La suppression a échoué : \n" + ex.Message, ex);
             }
         }
     }
 }
Example #7
0
        // Récupération de la liste des missions
        public static List<Mission> GetAllMissions(int idEntre)
        {
            List<Mission> Missions = new List<Mission>();
            using (SqlConnection sqlConnect = GetConnection())
            {
                using (SqlCommand sqlCde = new SqlCommand())
                {
                    sqlCde.Connection = sqlConnect;
                    string strsql = "GetAllMissions";
                    sqlCde.CommandType = CommandType.StoredProcedure;
                    sqlCde.CommandText = strsql;
                    SqlParameter p1 = new SqlParameter("@vidEntreprise", SqlDbType.Int);
                    p1.Direction = ParameterDirection.Input;
                    p1.Value = idEntre;
                    sqlCde.Parameters.Add(p1);

                    try
                    {

                        SqlDataReader sqlRdr = sqlCde.ExecuteReader();
                        while (sqlRdr.Read())
                        {
                            int idMission = sqlRdr.GetInt32(0);
                            Entreprise ent = new Entreprise() { IdEntreprise = sqlRdr.GetInt32(1) };
                            MotifFin motif = (!sqlRdr.IsDBNull(2)) ? new MotifFin() { IdMotif = (sbyte)sqlRdr.GetByte(2) } : null;
                            Qualification qualif = new Qualification() { IdQualification = sqlRdr.GetInt32(3), LibelleQualification = sqlRdr.GetString(4) };
                            Niveau niv = (!sqlRdr.IsDBNull(5)) ? new Niveau() { IdNiveau = (sbyte)sqlRdr.GetByte(5) } : null;
                            Consultant consult = new Consultant() { IdConsultant = (sbyte)sqlRdr.GetByte(6) };
                            DateTime dateOuv = sqlRdr.GetDateTime(7);
                            DateTime? dateFin = (sqlRdr.IsDBNull(8)) ? (DateTime?)null : sqlRdr.GetDateTime(8);
                            decimal? remu = (sqlRdr.IsDBNull(9)) ? (decimal?)null : sqlRdr.GetDecimal(9);
                            string precis = (!sqlRdr.IsDBNull(10)) ? sqlRdr.GetString(10) : string.Empty;
                            sbyte? duree = (sqlRdr.IsDBNull(11)) ? (sbyte?)null : (sbyte)sqlRdr.GetByte(11);

                            Mission miss = new Mission(idMission, ent, motif, qualif, niv, consult, dateOuv, dateFin, remu, precis, duree);
                            Missions.Add(miss);

                        }
                        sqlRdr.Close();
                        return Missions;
                    }
                    catch (SqlException ex)
                    {
                        throw new DaoExceptionFinApplication("Chargement des missions impossible, l'application va se fermer: \n" + ex.Message, ex);
                    }
                }
            }
        }
 //Méthode pour rafraichir la dgw
 public void RefreshDataGridView(Mission miss)
 {
     dataGridViewMissions.Refresh();
     missionBindingSource.Add(miss);
 }
        //Gestion de la datagridView
        private void dataGridViewMissions_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if(e.ColumnIndex == dataGridViewMissions.Columns["Details"].Index && e.RowIndex >= 0 )
            {
                AfficherDétails affdet = new AfficherDétails((Mission)dataGridViewMissions.CurrentRow.DataBoundItem, OuiNon = false, ((Entreprise)comboBoxChoixEntreprise.SelectedItem).IdEntreprise);
                affdet.Show();

            }
            else if(e.ColumnIndex == dataGridViewMissions.Columns["Modifier"].Index && e.RowIndex >= 0)
            {
                AfficherDétails affdet = new AfficherDétails((Mission)dataGridViewMissions.CurrentRow.DataBoundItem, OuiNon = true, ((Entreprise)comboBoxChoixEntreprise.SelectedItem).IdEntreprise);
                affdet.Show();

            }
            else if(e.ColumnIndex == dataGridViewMissions.Columns["Supprimer"].Index && e.RowIndex >= 0)
            {

                newMiss = (dataGridViewMissions.Rows[e.RowIndex].DataBoundItem) as Mission;
                if (newMiss.Motif == null)
                {
                    string message = "Etes-vous sûr de vouloir supprimer";
                    string caption = "Suppression d'une mission";
                    var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        try
                        {
                            if (DaoMission.DelMission(newMiss) == true)
                            {
                                missionBindingSource.Remove(newMiss);
                                missionBindingSource.ResetBindings(false);
                            }
                        }
                        catch (DaoExceptionAfficheMessage def)
                        {
                            MessageBox.Show(def.Message);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Une mission clôturée ne peut pas être supprimée");
                }

            }
            AfficheMessage();
            dataGridViewMissions.Refresh();
        }