public frmAjoutDependant(out Dependants dependant, int typeDependant, string idAbonnement)
 {
     InitializeComponent();
     dependant = new Dependants();
     this.dependant = dependant;
     this.typeDependant = typeDependant;
     this.idAbonnement = idAbonnement;
 }
 private void btnAjout_Click(object sender, EventArgs e)
 {
     if (this.ValidateChildren())
     {
         Abonnements abonnement = new Abonnements();
         abonnement.Cellulaire = cellulaireMaskedTextBox.Text == "(   )    -" ? "" : cellulaireMaskedTextBox.Text;
         abonnement.CodePostal = codePostalTextBox.Text;
         abonnement.Courriel = courrielTextBox.Text;
         abonnement.DateAbonnement = dateAbonnementDateTimePicker.Value;
         abonnement.DateNaissance = dateNaissanceDateTimePicker.Value;
         abonnement.Id = idTextBox.Text;
         abonnement.IdProvince = provincesComboBox.SelectedValue.ToString();
         abonnement.NoCivique = noCiviqueTextBox.Text;
         abonnement.Nom = nomTextBox.Text;
         abonnement.NoTypeAbonnement = (int)typesAbonnementComboBox.SelectedValue;
         abonnement.Prenom = prenomTextBox.Text;
         abonnement.Remarque = remarqueTextBox.Text;
         abonnement.Rue = rueTextBox.Text;
         abonnement.Sexe = cmbSexe.SelectedItem.ToString();
         abonnement.Telephone = telephoneMaskedTextBox.Text;
         abonnement.Ville = villeTextBox.Text;
         dataContexteProjet1.Abonnements.InsertOnSubmit(abonnement);
         List<Dependants> enfantList = new List<Dependants>();
         var conjoint = new Dependants();
         if (abonnement.NoTypeAbonnement >= 3)
         {
             var ajoutConjoint = new frmAjoutDependant(out conjoint, 3, abonnement.Id);
             ajoutConjoint.ShowDialog();
             dataContexteProjet1.Dependants.InsertOnSubmit(conjoint);
             if (abonnement.NoTypeAbonnement >= 4)
             {
                 int typeAbonnement = abonnement.NoTypeAbonnement;
                 if (typeAbonnement == 6)
                 {
                     typeAbonnement = 3 + (int)nbEnfantsNumericUpDown.Value;
                 }
                 for (int i = 4; i <= typeAbonnement; i++)
                 {
                     var enfant = new Dependants();
                     var ajoutEnfant = new frmAjoutDependant(out enfant, i, abonnement.Id);
                     enfantList.Add(enfant);
                     ajoutEnfant.ShowDialog();
                     dataContexteProjet1.Dependants.InsertOnSubmit(enfant);
                 }
             }
         }
         try
         {
             dataContexteProjet1.SubmitChanges();
             String mail = "";
             mail += "-------Abonnement-------\r\n";
             mail += "Type d'abonnement: " + abonnement.TypesAbonnement.Description + "\r\n";
             mail += "Coût annuel: " + abonnement.TypesAbonnement.PrixDepensesAbonnements.First().Prix + "\r\n";
             mail += "Dépenses obligatoires annuelles: " + abonnement.TypesAbonnement.PrixDepensesAbonnements.First().Prix + "\r\n";
             mail += "Date d'abonnement/du dernier réabonnement: " + abonnement.DateAbonnement + "\r\n";
             mail += "-------Abonné Principal-------\r\n";
             mail += "Nom: " + abonnement.Prenom + " " + abonnement.Nom + "\r\n";
             mail += "No d'abonnement: " + abonnement.Id + "\r\n";
             if (abonnement.NoTypeAbonnement >= 3)
             {
                 if (conjoint.Sexe == "H")
                 {
                     mail += "-------Conjoint-------\r\n";
                 }
                 else
                 {
                     mail += "-------Conjointe-------\r\n";
                 }
                 mail += "Nom: " + conjoint.Prenom + " " + conjoint.Nom + "\r\n";
                 mail += "No du conjoint: " + conjoint.Id + "\r\n";
             }
             if (abonnement.NoTypeAbonnement >= 4)
             {
                 int compteur = 1;
                 foreach (Dependants enfant in enfantList)
                 {
                     mail += "-------Enfant #" + compteur + "-------\r\n";
                     mail += "Nom: " + enfant.Prenom + " " + enfant.Nom + "\r\n";
                     mail += "No de l'enfant: " + enfant.Id + "\r\n";
                     compteur++;
                 }
             }
             Email.SendGMail(Resources.SujetMailAbonnement, mail, emp.Prenom + " " + emp.Nom, abonnement.Courriel, abonnement.Prenom + " " + abonnement.Nom);
             MessageBox.Show(Resources.EnregistrementReussi, Resources.TitreReussi);
             this.Close();
         }
         catch (DBConcurrencyException erreur)
         {
             MessageBox.Show(Resources.ConflitAccesConcurrentiel, Resources.TitreErreur);
         }
         catch
         {
             MessageBox.Show(Resources.ErreurEnregistrement, Resources.TitreErreur);
         }
     }
 }
        private void btnReabonnement_Click(object sender, EventArgs e)
        {
            Reabonnements reab = new Reabonnements();
            reab.Remarque = remarqueTextBox.Text;
            reab.IdAbonnement = abonnementsDataGridView.SelectedRows[0].Cells[0].Value.ToString();
            reab.DateRenouvellement = DateTime.Now;

            var lstReab = from unReab in dataContexteProjet1.Reabonnements
                          where unReab.IdAbonnement == reab.IdAbonnement && unReab.DateRenouvellement.Year == reab.DateRenouvellement.Year
                          select unReab;
            var lstAbonnement = from unAbonnement in dataContexteProjet1.Abonnements
                                where unAbonnement.Id == reab.IdAbonnement && unAbonnement.DateAbonnement.Year == reab.DateRenouvellement.Year
                                select unAbonnement;

            if (lstReab.Count() == 0 && lstAbonnement.Count() == 0)
            {
                dataContexteProjet1.Reabonnements.InsertOnSubmit(reab);
                try
                {
                    dataContexteProjet1.SubmitChanges();
                    var enumerableAbonnement = from unAbonnement in dataContexteProjet1.Abonnements
                                               where unAbonnement.Id == reab.IdAbonnement
                                               select unAbonnement;
                    var enumerableDependants = from unDependant in dataContexteProjet1.Dependants
                                               where unDependant.IdAbonnement == reab.IdAbonnement
                                               select unDependant;
                    Abonnements abonnement = enumerableAbonnement.First();

                    String mail = "";
                    mail += "-------Abonnement-------\r\n";
                    mail += "Type d'abonnement: " + abonnement.TypesAbonnement.Description + "\r\n";
                    mail += "Coût annuel: " + abonnement.TypesAbonnement.PrixDepensesAbonnements.First().Prix + "\r\n";
                    mail += "Dépenses obligatoires annuelles: " + abonnement.TypesAbonnement.PrixDepensesAbonnements.First().Prix + "\r\n";
                    mail += "Date d'abonnement/du dernier réabonnement: " + reab.DateRenouvellement + "\r\n";
                    mail += "-------Abonné Principal-------\r\n";
                    mail += "Nom: " + abonnement.Prenom + " " + abonnement.Nom + "\r\n";
                    mail += "No d'abonnement: " + abonnement.Id + "\r\n";
                    Dependants conjoint = new Dependants();
                    List<Dependants> enfantList = new List<Dependants>();
                    foreach (Dependants dependant in enumerableDependants)
                    {
                        if (dependant.Id.Substring(dependant.Id.Length - 1) == "0")
                        {
                            conjoint = dependant;
                        }
                        else
                        {
                            enfantList.Add(dependant);
                        }
                    }
                    if (abonnement.NoTypeAbonnement >= 3)
                    {
                        if (conjoint.Sexe == "H")
                        {
                            mail += "-------Conjoint-------\r\n";
                        }
                        else
                        {
                            mail += "-------Conjointe-------\r\n";
                        }
                        mail += "Nom: " + conjoint.Prenom + " " + conjoint.Nom + "\r\n";
                        mail += "No du conjoint: " + conjoint.Id + "\r\n";
                    }
                    if (abonnement.NoTypeAbonnement >= 4)
                    {
                        int compteur = 1;
                        foreach (Dependants enfant in enfantList)
                        {
                            mail += "-------Enfant #" + compteur + "-------\r\n";
                            mail += "Nom: " + enfant.Prenom + " " + enfant.Nom + "\r\n";
                            mail += "No de l'enfant: " + enfant.Id + "\r\n";
                            compteur++;
                        }
                    }
                    Email.SendGMail(Resources.SujetMailReabonnement, mail, emp.Prenom + " " + emp.Nom, abonnement.Courriel, abonnement.Prenom + " " + abonnement.Nom);
                    MessageBox.Show(Resources.UtilisateurReabonne, Resources.TitreReabonne);
                }
                catch (DBConcurrencyException erreur)
                {
                    MessageBox.Show(Resources.ConflitAccesConcurrentiel, Resources.TitreErreur);
                }
                catch
                {
                    MessageBox.Show(Resources.ErreurEnregistrement, Resources.TitreErreur);
                }
            }
            else
            {
                MessageBox.Show(Resources.ClientDejaReabonne, Resources.TitreErreur);
            }
        }
		private void detach_Dependants(Dependants entity)
		{
			this.SendPropertyChanging();
			entity.Abonnements = null;
		}
 partial void DeleteDependants(Dependants instance);
 partial void UpdateDependants(Dependants instance);
 partial void InsertDependants(Dependants instance);