Example #1
0
        private void buttonVal_Click(object sender, EventArgs e)
        {
            ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();
            ISession        session        = sessionFactory.OpenSession();

            using (ITransaction transaction = session.BeginTransaction())
            {
                interlocuteur.nomInterlocuteur    = textBoxNom.Text;
                interlocuteur.prenomInterlocuteur = textBoxPrenom.Text;
                interlocuteur.telInterlocuteur    = textBoxTel.Text;
                interlocuteur.mailInterlocuteur   = textBoxMail.Text;
                interlocuteur.porteFeuille        = utilisateur.porteFeuille;
                MessageBox.Show(interlocuteur.porteFeuille.ToString());
                session.Update(interlocuteur);
                transaction.Commit();
            }
            //Si l'interlocuteur était individu
            if (isIndividu)
            {
                // Si l'individu est modifié en individu
                if (radioButtonOui.Checked == true)
                {
                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        individu.adresseIndividu     = textBoxAdresse.Text;
                        individu.cpIndividu          = textBoxCp.Text;
                        individu.villeIndividu       = textBoxVille.Text;
                        individu.distanceSiege       = Int32.Parse(textBoxDistance.Text);
                        individu.infosSupplementaire = textBoxIC.Text;
                        MessageBox.Show(interlocuteur.idInterlocuteur.ToString());
                        individu.interlocuteur = interlocuteur;
                        session.Update(individu);
                        transaction.Commit();
                    }
                }
                // Sinon si l'individu est modifié en interlocuteur Structure
                else
                {       // Si il s'agit d'une nouvelle structure
                    if (radioNouvelleStructureOui.Checked == true)
                    {
                        using (ITransaction transaction = session.BeginTransaction())
                        {
                            Structure structure = new Structure();
                            structure.typeStructure       = (TypeStructure)comboBoxTS.SelectedItem;
                            structure.denominationSociale = textBoxDS.Text;
                            structure.adresseStructure    = textBoxAdresse.Text;
                            structure.cpStructure         = textBoxCp.Text;
                            structure.villeStructure      = textBoxVille.Text;
                            structure.distanceSiege       = float.Parse(textBoxDistanceKm.Text);
                            structure.infoSupplementaire  = textBoxIC.Text;
                            session.Save(structure);
                            InterlocuteurStructure interlocuteurStructure = new InterlocuteurStructure();
                            interlocuteurStructure.interlocuteur = interlocuteur;
                            interlocuteurStructure.structure     = structure;
                            session.Save(interlocuteurStructure);
                            transaction.Commit();
                        }
                    }
                    // Si il s'agit d'une structure existante
                    else
                    {
                        using (ITransaction transaction = session.BeginTransaction())
                        {
                            InterlocuteurStructure interlocuteurStructure = new InterlocuteurStructure();
                            interlocuteurStructure.interlocuteur = interlocuteur;
                            interlocuteurStructure.structure     = (Structure)comboBoxChoixStructure.SelectedItem;
                            session.Save(interlocuteurStructure);
                            // l'interlocuteur à été affilié à une structure, on supprime l'individu correspondant.
                            session.Delete(individu);
                            transaction.Commit();
                        }
                    }
                }
            }
            //Si l'interlocuteur était InterlocuteurStructure
            if (!isIndividu)
            {
                // Si l'interlocuteur est individu
                if (radioButtonOui.Checked == true)
                {
                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        Individu individu = new Individu();
                        individu.adresseIndividu     = textBoxAdresse.Text;
                        individu.cpIndividu          = textBoxCp.Text;
                        individu.villeIndividu       = textBoxVille.Text;
                        individu.distanceSiege       = Int32.Parse(textBoxDistance.Text);
                        individu.infosSupplementaire = textBoxIC.Text;
                        MessageBox.Show(interlocuteur.idInterlocuteur.ToString());
                        individu.interlocuteur = interlocuteur;
                        session.Save(individu);
                        // L'individu à été set, on supprime l'interlocuteurStructure
                        session.Delete(interlocuteurStructure);
                        transaction.Commit();
                    }
                }
                // Sinon si l'interlocuteur etait interlocuteur Structure
                else
                {       // Si il s'agit d'une nouvelle structure
                    if (radioNouvelleStructureOui.Checked == true)
                    {
                        using (ITransaction transaction = session.BeginTransaction())
                        {
                            Structure structure = new Structure();
                            structure.typeStructure       = (TypeStructure)comboBoxTS.SelectedItem;
                            structure.denominationSociale = textBoxDS.Text;
                            structure.adresseStructure    = textBoxAdresse.Text;
                            structure.cpStructure         = textBoxCp.Text;
                            structure.villeStructure      = textBoxVille.Text;
                            structure.distanceSiege       = float.Parse(textBoxDistanceKm.Text);
                            structure.infoSupplementaire  = textBoxIC.Text;
                            session.Save(structure);
                            InterlocuteurStructure interlocuteurStructureNew = new InterlocuteurStructure();
                            interlocuteurStructureNew.interlocuteur = interlocuteur;
                            interlocuteurStructureNew.structure     = structure;
                            session.Save(interlocuteurStructureNew);
                            // L'interlocuteurStructure à été set, on supprime l'ancien interlocuteurStructure :
                            session.Delete(interlocuteurStructure);
                            transaction.Commit();
                        }
                    }
                    // sinon si il s'agit d'une structure existante
                    else
                    {
                        // Si l'interocuteur est affilié à une structure différente de la sienne on crée un nouvel Interlocuteur Structure et on supprime l'ancien
                        if ((Structure)comboBoxChoixStructure.SelectedItem != interlocuteurStructure.structure)
                        {
                            using (ITransaction transaction = session.BeginTransaction())
                            {
                                InterlocuteurStructure interlocuteurStructureNew = new InterlocuteurStructure();
                                interlocuteurStructureNew.interlocuteur = interlocuteur;
                                interlocuteurStructureNew.structure     = (Structure)comboBoxChoixStructure.SelectedItem;
                                session.Save(interlocuteurStructureNew);
                                // L'interlocuteurStructure à été set, on supprime l'ancien interlocuteurStructure :
                                session.Delete(interlocuteurStructure);
                                transaction.Commit();
                            }
                        }
                    }
                }
                session.Dispose();
            }
            interUti.chargerDatagridInterlocuteurs();
            this.Close();
        }
        private void buttonVal_Click(object sender, EventArgs e)
        {
            using (ISession session = sessionFactory.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    interlocuteur.nomInterlocuteur    = textBoxNom.Text;
                    interlocuteur.prenomInterlocuteur = textBoxPrenom.Text;
                    interlocuteur.telInterlocuteur    = textBoxTel.Text;
                    interlocuteur.mailInterlocuteur   = textBoxMail.Text;
                    interlocuteur.porteFeuille        = utilisateur.porteFeuille;
                    MessageBox.Show(interlocuteur.porteFeuille.ToString());
                    session.Save(interlocuteur);
                    transaction.Commit();
                }

                if (radioButtonOui.Checked == true)
                {
                    using (ITransaction transaction = session.BeginTransaction())
                    {
                        Individu individu = new Individu();
                        individu.adresseIndividu     = textBoxAdresse.Text;
                        individu.cpIndividu          = textBoxCp.Text;
                        individu.villeIndividu       = textBoxVille.Text;
                        individu.distanceSiege       = Int32.Parse(textBoxDistance.Text);
                        individu.infosSupplementaire = textBoxIC.Text;
                        MessageBox.Show(interlocuteur.idInterlocuteur.ToString());
                        individu.interlocuteur = interlocuteur;
                        session.Save(individu);
                        transaction.Commit();
                    }
                }
                else
                {
                    if (radioNouvelleStructureOui.Checked == true)
                    {
                        using (ITransaction transaction = session.BeginTransaction())
                        {
                            Structure structure = new Structure();
                            structure.typeStructure       = (TypeStructure)comboBoxTS.SelectedItem;
                            structure.denominationSociale = textBoxDS.Text;
                            structure.adresseStructure    = textBoxAdresse.Text;
                            structure.cpStructure         = textBoxCp.Text;
                            structure.villeStructure      = textBoxVille.Text;
                            structure.distanceSiege       = float.Parse(textBoxDistanceKm.Text);
                            structure.infoSupplementaire  = textBoxIC.Text;
                            session.Save(structure);
                            InterlocuteurStructure interlocuteurStructure = new InterlocuteurStructure();
                            interlocuteurStructure.interlocuteur = interlocuteur;
                            interlocuteurStructure.structure     = structure;
                            session.Save(interlocuteurStructure);
                            transaction.Commit();
                        }
                    }
                    else
                    {
                        using (ITransaction transaction = session.BeginTransaction())
                        {
                            InterlocuteurStructure interlocuteurStructure = new InterlocuteurStructure();
                            interlocuteurStructure.interlocuteur = interlocuteur;
                            interlocuteurStructure.structure     = (Structure)comboBoxChoixStructure.SelectedItem;
                            session.Save(interlocuteurStructure);
                            transaction.Commit();
                        }
                    }
                }
                session.Dispose();
            }
            interUti.chargerDatagridInterlocuteurs();
            this.Close();
        }
Example #3
0
        private void Popup_ModifierClient_Load(object sender, EventArgs e)
        {
            ISessionFactory sessionFactory = new Configuration().Configure().BuildSessionFactory();
            ISession        session        = sessionFactory.OpenSession();

            using (ITransaction transaction = session.BeginTransaction())
            {
                TypeStructure lesTypeStructure = new TypeStructure();
                comboBoxTS.DataSource             = lesTypeStructure.GetLesTypesStructure();
                comboBoxChoixStructure.DataSource = session.CreateQuery(@"select e from Structure e order by e.denominationSociale asc").List <Structure>();

                if (interlocuteur != null)
                {
                    if (interlocuteur.nomInterlocuteur != null)
                    {
                        textBoxNom.Text = interlocuteur.nomInterlocuteur;
                    }

                    if (interlocuteur.prenomInterlocuteur != null)
                    {
                        textBoxPrenom.Text = interlocuteur.prenomInterlocuteur;
                    }

                    if (interlocuteur.telInterlocuteur != null)
                    {
                        textBoxTel.Text = interlocuteur.telInterlocuteur;
                    }

                    if (interlocuteur.telInterlocuteur != null)
                    {
                        textBoxTel.Text = interlocuteur.telInterlocuteur;
                    }

                    if (interlocuteur.mailInterlocuteur != null)
                    {
                        textBoxMail.Text = interlocuteur.mailInterlocuteur;
                    }

                    // Si l'interlocuteur est un particulier
                    if (isIndividu)
                    {
                        Individu individu = session.CreateQuery("select e from Individu e where e.interlocuteur.idInterlocuteur=:num").SetParameter("num", interlocuteur.idInterlocuteur).UniqueResult <Individu>();

                        if (individu.adresseIndividu != null)
                        {
                            textBoxAdresse.Text = individu.adresseIndividu;
                        }

                        if (individu.cpIndividu != null)
                        {
                            textBoxCp.Text = individu.cpIndividu;
                        }

                        if (individu.villeIndividu != null)
                        {
                            textBoxVille.Text = individu.villeIndividu;
                        }

                        if (individu.distanceSiege != null)
                        {
                            textBoxDistance.Text = individu.distanceSiege.ToString();
                        }

                        if (individu.infosSupplementaire != null)
                        {
                            textBoxIC.Text = individu.infosSupplementaire;
                        }
                    }

                    // Si l'interlocuteur est un interlocuteur_structure
                    if (!isIndividu)
                    {
                        groupBoxParticulier.Visible        = false;
                        groupBoxStructureExistante.Visible = true;

                        InterlocuteurStructure interlocuteurStructure = session.CreateQuery("select e from InterlocuteurStructure e where e.interlocuteur.idInterlocuteur=:num").SetParameter("num", interlocuteur.idInterlocuteur).UniqueResult <InterlocuteurStructure>();

                        if (interlocuteurStructure.structure != null)
                        {
                            foreach (Structure s in comboBoxChoixStructure.Items)
                            {
                                if (s.numStructure == interlocuteurStructure.structure.numStructure)
                                {
                                    comboBoxChoixStructure.SelectedItem = s;
                                }
                            }
                        }
                    }
                }
                session.Dispose();
            }
        }