示例#1
0
        //Event quand l'utilisateur click sur le bouton supprimer
        private void button1_Click(object sender, EventArgs e)
        {
            //Création de la connection
            connect = new CURS(LoginPage.ChaineConnexion);
            //Requete de suppression avec l'id du rapport
            string supprRequest = requestSuppr + "'" + rapport[1].ToString() + "'";
            //Requete de sauvegarde
            string requete = "INSERT INTO save_rapport (COL_MATRICULE, RAP_NUM, PRA_NUM, RAP_DATE, RAP_BILAN, date_visite, CoefConf, id_motif, PRA_NUM_REMP)" +
                             " VALUES (";

            //Ajout des variables dans la requête de sauvegarde
            foreach (object rap in rapport)
            {
                //Test si la variable est null
                if (rap.ToString() == "")
                {
                    //Rajout de "null" si la variable est null
                    requete += "null";
                }
                else
                {
                    //Rajout de la variable en text si elle est différent de null
                    //Si c'est une date on l'enregistre spécialement car en base c'est un type DateTime
                    if (rap.ToString() == rapport[3].ToString() || rap.ToString() == rapport[5].ToString())
                    {
                        DateTime date = DateTime.Parse(rap.ToString());
                        requete += "'" + date.ToString("yyyy-MM-dd HH:mm:ss") + "'";
                    }
                    else
                    {
                        requete += "'" + rap.ToString() + "'";
                    }
                }
                //Ajout d'une virgule à chaque tour
                requete += ", ";
            }//foreach(object rap in rapport)
            //Ajout de la parenthèse a la fin de la requête
            requete = requete.Substring(0, requete.Length - 2) + ")";
            //éxecution de la sauvegarde dans une autre table
            connect.ReqAdmin(requete);
            //éxecution de la requête de suppression
            connect.ReqAdmin(supprRequest);
            //Fermeture de la connection a la base
            connect.fermer();

            //Fermeture de la fenêtre
            Close();
            //Réouverture de la fenêtre pour actualisé les données
            menu main = new menu();

            main.Show();
        }
        private void btn_val_Click(object sender, EventArgs e)
        {
            string strErreur = "";

            if (cbx_prat.Text == "")
            {
                strErreur = " - Vous n'avez pas sélectionné un praticien \n";
            }
            if (richTextBox1.Text == "")
            {
                strErreur = strErreur + " - Vous n'avez pas saisi le bilan \n";
            }
            if (dateboxVisite.Value.ToString("dd/MM/yyyy") == "01/01/2020")
            {
                strErreur = strErreur + " - Vous n'avez pas sélectionné une date différente de celle de départ \n";
            }
            if (strErreur != "")
            {
                strErreur = "La création du rapport ne peut se faire : \n" + strErreur;
                DialogResult dresult = MessageBox.Show(strErreur, "Erreur de saisie");
            }
            else
            {
                string NumRapport          = txtbox_numrap.Text;
                string Nom_prenom_visiteur = txtbox_visiteur.Text;
                string NomPre_Praticien    = ((KeyValuePair <string, string>)cbx_prat.SelectedItem).Key;
                string NomPre_Prat_Remp    = ((KeyValuePair <string, string>)cbx_prat_remp.SelectedItem).Key;
                string datebox_rapport     = datebox.Value.ToString("yyyy/MM/dd");
                string datebox_visite      = dateboxVisite.Value.ToString("yyyy/MM/dd");
                string motif      = ((KeyValuePair <string, string>)cbx_motif.SelectedItem).Key;
                string bilan      = richTextBox1.Text;
                string coefConf   = trackBar_CoefConf.Value.ToString();
                string medicament = "";
                string quantite   = "";

                for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
                {
                    medicament = dataGridView1.Rows[i].Cells[0].Value.ToString();
                    quantite   = dataGridView1.Rows[i].Cells[1].Value.ToString();
                    CURS   csInsertEchantillons  = new CURS(LoginPage.ChaineConnexion);
                    string reqInsertEchantillons = "INSERT INTO `offrir`(`COL_MATRICULE`, `RAP_NUM`, `MED_DEPOTLEGAL`, `OFF_QTE`) VALUES ('";
                    reqInsertEchantillons += LoginPage.Id + "', ";
                    reqInsertEchantillons += NumRapport + ", '";
                    reqInsertEchantillons += medicament + "', ";
                    reqInsertEchantillons += quantite + ");";
                    csInsertEchantillons.ReqAdmin(reqInsertEchantillons);
                }

                //string resultat = NumRapport + " " + Nom_prenom_visiteur + " " + NomPre_Praticien + " " + NomPre_Prat_Remp + " " + datebox_rapport + " " + datebox_visite + " " + motif + " " + bilan + " " + medicament + " " + quantite + " " + coefConf;
                //richTest.Text = resultat;

                CURS   csInsert  = new CURS(LoginPage.ChaineConnexion);
                string reqInsert = "INSERT INTO rapport_visite (COL_MATRICULE, RAP_NUM, PRA_NUM, RAP_DATE, RAP_BILAN, date_visite, id_motif, PRA_NUM_REMP, CoefConf) VALUES ('";
                reqInsert += LoginPage.Id + "', ";
                reqInsert += NumRapport + ", ";
                reqInsert += NomPre_Praticien + ", ";
                if (chkbox_date_rapport.Checked)
                {
                    reqInsert += "'" + datebox_rapport + "', ";
                }
                else
                {
                    reqInsert += "NULL, ";
                }

                reqInsert += "'" + bilan + "', ";
                reqInsert += "'" + datebox_visite + "', ";
                reqInsert += motif + ", ";
                if (cbx_prat_remp.Text == " ")
                {
                    reqInsert += "NULL, ";
                }
                else
                {
                    reqInsert += NomPre_Prat_Remp + ", ";
                }
                reqInsert += coefConf + ");";
                csInsert.ReqAdmin(reqInsert);
                DialogResult dresult2 = MessageBox.Show("La création du rapport s'est bien passée.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Close();
            }
        }