private void ajoutPrescrire()
        {
            prescrire nouveauPrescrire = new prescrire();

            nouveauPrescrire.id_medicament    = 0;
            nouveauPrescrire.id_dosage        = 0;
            nouveauPrescrire.id_type_individu = 0;
            if (tbTypeIndividu.Text != "")
            {
                nouveauPrescrire.type_individu.lib_type_individu = tbTypeIndividu.Text;
            }
            if (tbPosologie.Text != "")
            {
                nouveauPrescrire.posologie = tbPosologie.Text;
            }

            if (cbMedicament.SelectedIndex != 0)
            {
                nouveauPrescrire.id_medicament = cbMedicament.SelectedIndex;
            }
            if (cbDosage.SelectedIndex != 0)
            {
                nouveauPrescrire.id_dosage = cbDosage.SelectedIndex;
            }
            ;
            BD.prescrire.Add(nouveauPrescrire);
            bool flag = false;

            try
            {
                BD.SaveChanges();
            }
            catch
            {
                MessageBox.Show("Le visiteur n'a pas pu être créé !", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                flag = true;
            }
            prescription = nouveauPrescrire;
            if (!flag)
            {
                if (retourRes != null && retourRes.LongCount() > 0)
                {
                    MessageBox.Show("La prescription a bien été ajouté, vous pouvez maintenant le modifier.", "Confirmation d'ajout", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    System.Threading.Thread monthread = new System.Threading.Thread(new System.Threading.ThreadStart(nouveauFormModifList));
                    monthread.Start();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("La prescription a bien été ajouté, vous pouvez maintenant le modifier.", "Confirmation d'ajout", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    System.Threading.Thread monthread = new System.Threading.Thread(new System.Threading.ThreadStart(nouveauFormModif));
                    monthread.Start();
                    this.Close();
                }
            }
        }
 public FormPrescrire(gsbEntities p_bd, prescrire v)
 {
     InitializeComponent();
     BD = p_bd;
     initCbs();
     prescription       = v;
     btValider.Location = new Point(98, 245);
     btSupp.Location    = new Point(183, 245);
     btSupp.Visible     = true;
     btAnnuler.Location = new Point(268, 245);
     remplirForm(v);
 }
        public FormPrescrire(gsbEntities p_bd, prescrire v, List <prescrire> resultats)
        {
            InitializeComponent();
            BD = p_bd;
            initCbs();
            retourRes          = resultats;
            prescription       = v;
            btValider.Location = new Point(55, 245);
            btSupp.Location    = new Point(140, 245);
            btSupp.Visible     = true;

            btAnnuler.Location = new Point(310, 245);
            remplirForm(v);
        }
 private void remplirForm(prescrire v)
 {
     if (v.id_medicament != 0)
     {
         cbMedicament.SelectedIndex = v.id_medicament;
     }
     if (v.id_dosage != 0)
     {
         cbDosage.SelectedIndex = v.id_dosage;
     }
     if (v.id_type_individu != 0 && v.type_individu.lib_type_individu != "")
     {
         tbTypeIndividu.Text = v.type_individu.lib_type_individu;
     }
     if (v.posologie != null && v.posologie != "")
     {
         tbPosologie.Text = v.posologie;
     }
 }
        private void rechercher()
        {
            var donnee = lvListePrescrire.SelectedIndices;

            foreach (int index in donnee)
            {
                int i   = listIds[index];
                var req = from prescrire in BD.prescrire
                          where prescrire.id_medicament == i
                          where prescrire.id_dosage == i
                          where prescrire.id_type_individu == i
                          select prescrire;
                foreach (prescrire v in req)
                {
                    prescription = v;
                    System.Threading.Thread monthread = new System.Threading.Thread(new System.Threading.ThreadStart(details));
                    monthread.Start();
                    this.Close();
                }
            }
        }
        private void modifPrescrire()
        {
            using (gsbEntities bdd = new gsbEntities())
            {
                prescrire visi = (from prescrire in bdd.prescrire
                                  where prescrire.id_medicament == prescription.id_medicament
                                  where prescrire.id_type_individu == prescription.id_type_individu
                                  where prescrire.id_dosage == prescription.id_dosage
                                  select prescrire).FirstOrDefault();


                if (visi.type_individu.lib_type_individu != tbTypeIndividu.Text)
                {
                    if (tbTypeIndividu.Text == "")
                    {
                        visi.id_type_individu = 0;
                    }
                    else
                    {
                        visi.id_type_individu = prescription.id_type_individu + 1;
                    }
                }
                if (visi.posologie != tbPosologie.Text)
                {
                    if (tbPosologie.Text == "")
                    {
                        visi.posologie = null;
                    }
                    else
                    {
                        visi.posologie = tbPosologie.Text;
                    }
                }
                if (visi.id_medicament != cbMedicament.SelectedIndex)
                {
                    if (cbMedicament.SelectedIndex == 0)
                    {
                        visi.id_medicament = 0;
                    }
                    else
                    {
                        visi.id_medicament = cbMedicament.SelectedIndex;
                    }
                }
                if (visi.id_dosage != cbDosage.SelectedIndex)
                {
                    if (cbDosage.SelectedIndex == 0)
                    {
                        visi.id_dosage = 0;
                    }
                    else
                    {
                        visi.id_dosage = cbDosage.SelectedIndex;
                    }
                }
                prescription = visi;
                if (retourRes != null && retourRes.LongCount() > 0)
                {
                    int  index = 0;
                    bool verif = false;
                    foreach (prescrire unVisi in retourRes)
                    {
                        if (unVisi.id_medicament == visi.id_medicament && unVisi.id_type_individu == visi.id_type_individu && unVisi.id_dosage == visi.id_dosage)
                        {
                            verif = true;
                            break;
                        }
                        index++;
                    }
                    if (verif)
                    {
                        retourRes.RemoveAt(index);
                        retourRes.Add(visi);
                        retourRes.Sort(delegate(prescrire vis1, prescrire vis2) { return(string.Compare(vis1.posologie, vis2.posologie)); });
                    }
                }
                bool flag = false;
                try
                {
                    bdd.SaveChanges();
                }
                catch
                {
                    MessageBox.Show("La modification n'a pas pu être enregistrée !", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    flag = true;
                }
                if (!flag)
                {
                    if (retourRes != null && retourRes.LongCount() > 0)
                    {
                        MessageBox.Show("La prescription a bien été modifié !", "Confirmation de modification", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        System.Threading.Thread monthread = new System.Threading.Thread(new System.Threading.ThreadStart(nouveauFormModifList));
                        monthread.Start();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("La prescription a bien été modifié !", "Confirmation de modification", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        System.Threading.Thread monthread = new System.Threading.Thread(new System.Threading.ThreadStart(nouveauFormModif));
                        monthread.Start();
                        this.Close();
                    }
                }
            }
        }