1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| // Code permettant de remplir la base de données.
SqlConnection connection;
SqlCommand command;
connection = new SqlConnection("Data Source=DIST-5B8D87E3A9;Initial Catalog=DistribInfo;Integrated Security=SSPI");
// Si Le NumMachine existe dans la base
// alors on l'enregistre pas
// sinon on l'enregistre.
command = new SqlCommand ("Select M_IDMAT FROM MACHINE WHERE M_IDMAT= '" + NumMachine.Text + "'");
Typeretour mIdMat = (Typeretour) commandselect .executeScalar();
if (NumMachine==mIdMat)
{
command = new SqlCommand("INSERT INTO INTERVENTION(IN_NUMINTER, C_NUMCLT, IN_M_NUMCLT, IN_IDMAT, IN_RESINTER, IN_DEPOMAT, IN_RECEPMAT, IN_PRICHARG) VALUES('" + NumInter.Text + "', '" + NumClt.Text + "', '" + NumClt.Text + "','" + NumMachine.Text +"', '" + RaisonInter.Text + "', '" + Dépositaire.Text + "', '" + Réceptionneur.Text + "', '" + DatePrisEnCharge.Text + "'", connection);
}
else
{
command = new SqlCommand("INSERT INTO MACHINE(M_IDMAT, M_NUMCLT, M_NUMCTACT, M_NOMMAT, M_CONFMAT, M_NOMUTIL, M_RAP_RESP, M_RESINTER) VALUES('" + NumMachine.Text + "', '" + NumClt.Text + "', '" + NumContact.Text + "','" + NomMachine.Text +"', '" + ConfigMachine.Text + "', '" + NomUtMachine.Text + "', '" + RespUt.Text + "', '" + RaisonInter.Text + "'", connection);
command = new SqlCommand("INSERT INTO INTERVENTION(IN_NUMINTER, C_NUMCLT, IN_M_NUMCLT, IN_IDMAT, IN_RESINTER, IN_DEPOMAT, IN_RECEPMAT, IN_PRICHARG) VALUES('" + NumInter.Text + "', '" + NumClt.Text + "', '" + NumClt.Text + "','" + NumMachine.Text +"', '" + RaisonInter.Text + "', '" + Dépositaire.Text + "', '" + Réceptionneur.Text + "', '" + DatePrisEnCharge.Text + "'", connection);
}
connection.Open();
try
{
command.ExecuteNonQuery();
}
finally
{
connection.Close();
} |
Partager