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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
| private void Valider_Click(object sender, System.EventArgs e)
{
// Code permettant l'enregistrement des résultats
// dans la base de données SqlServer se nommant DistribInfo
SqlConnection connection;
connection = new SqlConnection("Data Source=DIST-5B8D87E3A9;Initial Catalog=DistribInfo;Integrated Security=SSPI");
connection.Open();
SqlCommand commander;
commander = new SqlCommand("UPDATE MACHINE SET M_CONFMAT = '" + ConfigMachine.Text + "' WHERE M_IDMAT = '" + NumMachine.Text + "'", connection);
commander.ExecuteNonQuery();
try
{
// RECUPERER LA LISTE DES CLIENTS QUI ONT POUR NUMERO NUMCLT.TEXT
SqlDataAdapter _MonDataAdapter;
System.Data.DataTable _MaDataTable;
string RequeteSQL = "SELECT C_NOMCLT FROM CLIENT WHERE C_NOMCLT='" + NomClient.Text + "'";
_MonDataAdapter = new SqlDataAdapter(RequeteSQL, connection);
_MaDataTable = new DataTable();
_MonDataAdapter.Fill(_MaDataTable);
// RECUPERER LA LISTE DES CONTACTS QUI ONT POUR NUMERO NUMCTACT.TEXT
SqlDataAdapter _MonDataAdapter1;
System.Data.DataTable _MaDataTable1;
string RequeteSQL1 = "SELECT CT_NUMCTACT FROM CONTACT WHERE CT_NUMCTACT='" + NumContact.Text + "'";
_MonDataAdapter1 = new SqlDataAdapter(RequeteSQL1, connection);
_MaDataTable1 = new DataTable();
_MonDataAdapter1.Fill(_MaDataTable1);
// RECUPERER LA LISTE DES MACHINES
SqlDataAdapter _MonDataAdapter2;
System.Data.DataTable _MaDataTable2;
string RequeteSQL2 = "SELECT M_IDMAT FROM MACHINE WHERE M_IDMAT='" + NumMachine.Text + "'";
_MonDataAdapter2 = new SqlDataAdapter(RequeteSQL2, connection);
_MaDataTable2 = new DataTable();
_MonDataAdapter2.Fill(_MaDataTable2);
// RECUPERER LA LISTE DES MACHINES
SqlDataAdapter _MonDataAdapter3;
System.Data.DataTable _MaDataTable3;
string RequeteSQL3 = "SELECT IN_RESINTER FROM INTERVENTION WHERE IN_RESINTER='" + RaisonInter.Text + "'";
_MonDataAdapter3 = new SqlDataAdapter(RequeteSQL3, connection);
_MaDataTable3 = new DataTable();
_MonDataAdapter3.Fill(_MaDataTable3);
// Si le contact n'as pas de fax
// alors <NULL> sera affiché dans la base
string fax="<NULL>";
if(!faxCtact.Text.Equals(""))
{
fax=faxCtact.Text;
}
// Si le contact n'as pas de responsable
// alors <NULL> sera affiché dans la base
string resp="<NULL>";
if(!RespCtact.Text.Equals(""))
{
resp=RespCtact.Text;
}
// Si le nom de l'utilisateur de la machine
// n'est pas renseignés
// alors <NULL> sera affiché dans la base
string NomUtil="<NULL>";
if(!NomUtMachine.Text.Equals(""))
{
NomUtil=NomUtMachine.Text;
}
// Si le nom du responsable de l'utilisateur
// n'est pas renseigné
// alors <NULL> sera affiché dans la base
string RapRespUtil="<NULL>";
if(!RespUt.Text.Equals(""))
{
RapRespUtil=RespUt.Text;
}
// Si le dépositaire n'est pas renseigné
// alors <NULL> sera affiché dans la base
string Depo="<NULL>";
if(!Depositaire.Text.Equals(""))
{
Depo=Depositaire.Text;
}
// Si le rceptionneur n'est pas renseigné
// alors <NULL> sera affiché dans la base
string Recep="<NULL>";
if(!Receptionneur.Text.Equals(""))
{
Recep=Receptionneur.Text;
}
// SI CLIENT NON EXISTANT
if (_MaDataTable.Rows.Count == 0)
{
// Enregistrement des informations sur le client
SqlParameter paramNClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
paramNClt.Value = NumClt.Text;
SqlParameter paramNomClt = new SqlParameter("@NomClt", SqlDbType.Char, 16);
paramNomClt.Value = NomClient.Text;
SqlParameter paramStatuClt = new SqlParameter("@StatuClt", SqlDbType.Char, 12);
paramStatuClt.Value = StatuClient.SelectedItem.ToString();
string strSql = string.Format("INSERT INTO CLIENT(C_NUMCLT, C_NOMCLT, C_STATUCLT) VALUES({0}, {1}, {2})", paramNClt.ParameterName, paramNomClt.ParameterName, paramStatuClt.ParameterName);
SqlCommand cmd = new SqlCommand(strSql, connection);
cmd.Parameters.Add(paramNClt);
cmd.Parameters.Add(paramNomClt);
cmd.Parameters.Add(paramStatuClt);
cmd.ExecuteNonQuery();
// Enregistrement des informations sur le contact
SqlParameter paramNumCtact = new SqlParameter("@NumCtact", SqlDbType.VarChar, 13);
paramNumCtact.Value = NumContact.Text;
SqlParameter paramNumClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
paramNumClt.Value = NumClt.Text;
SqlParameter paramNomCtact = new SqlParameter("@NomCtact", SqlDbType.Char, 20);
paramNomCtact.Value = NomContact.Text;
SqlParameter paramPnmCtact = new SqlParameter("@PnmCtact", SqlDbType.Char, 20);
paramPnmCtact.Value = PrenomContact.Text;
SqlParameter paramTelCtact = new SqlParameter("@TelCtact", SqlDbType.VarChar, 15);
paramTelCtact.Value = telContact.Text;
SqlParameter paramAnnivCtact = new SqlParameter("@AnnivCtact", SqlDbType.DateTime, 8);
paramAnnivCtact.Value = annivCtact.Text;
SqlParameter paramFctCtact = new SqlParameter("@FctCtact", SqlDbType.Char, 120);
paramFctCtact.Value = FctContact.Text;
string strSql1 = string.Format("INSERT INTO CONTACT(CT_NUMCTACT, CT_NUMCLT, CT_NOMCTACT, CT_PNMCTACT, CT_TELCTACT, CT_FAXCTACT, CT_ANICTACT, CT_FCTCTACT, CT_RSPCTACT) VALUES({0}, {1}, {2}, {3}, {4}, '" + fax + "', {5}, {6}, '" + resp + "')",paramNumCtact.ParameterName, paramNumClt.ParameterName, paramNomCtact.ParameterName, paramPnmCtact.ParameterName, paramTelCtact.ParameterName, paramAnnivCtact.ParameterName, paramFctCtact.ParameterName);
SqlCommand command = new SqlCommand(strSql1, connection);
command.Parameters.Add(paramNumCtact);
command.Parameters.Add(paramNumClt);
command.Parameters.Add(paramNomCtact);
command.Parameters.Add(paramPnmCtact);
command.Parameters.Add(paramTelCtact);
command.Parameters.Add(paramAnnivCtact);
command.Parameters.Add(paramFctCtact);
command.ExecuteNonQuery();
// Enregistrement des informations sur la machine
SqlParameter paramNClient = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
paramNClient.Value = NumClt.Text;
SqlParameter paramIdMat = new SqlParameter("@IdMat", SqlDbType.Decimal, 13);
paramIdMat.Value = decimal.Parse(NumMachine.Text);
SqlParameter paramNumContact = new SqlParameter("@NumCtact", SqlDbType.VarChar, 13);
paramNumContact.Value = NumContact.Text;
SqlParameter paramNomMat = new SqlParameter("@NomMat", SqlDbType.VarChar, 50);
paramNomMat.Value = NomMachine.Text;
SqlParameter paramConfMat = new SqlParameter("@ConfMat", SqlDbType.VarChar, 150);
paramConfMat.Value = ConfigMachine.Text;
SqlParameter paramRapResInter = new SqlParameter("@RapresInter", SqlDbType.Char, 50);
paramRapResInter.Value = RaisonInter.Text;
string strSql2 = string.Format("INSERT INTO MACHINE(M_NUMCLT, M_IDMAT, M_NUMCTACT, M_NOMMAT, M_CONFMAT, M_NOMUTIL, M_RAP_RESP, M_RESINTER) VALUES({0}, {1}, {2}, {3}, {4}, '" + NomUtil + "', '" + RapRespUtil + "', {5})", paramNClient.ParameterName, paramIdMat.ParameterName, paramNumContact.ParameterName, paramNomMat.ParameterName, paramConfMat.ParameterName, paramRapResInter.ParameterName);
SqlCommand Command = new SqlCommand(strSql2, connection);
Command.Parameters.Add(paramNClient);
Command.Parameters.Add(paramIdMat);
Command.Parameters.Add(paramNumContact);
Command.Parameters.Add(paramNomMat);
Command.Parameters.Add(paramConfMat);
Command.Parameters.Add(paramRapResInter);
Command.ExecuteNonQuery();
// Enregistrement des informations de l'intervention
SqlParameter paramNInter = new SqlParameter("@NumInter", SqlDbType.VarChar, 15);
paramNInter.Value = NumIntervention.Text;
SqlParameter paramNumeroClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
paramNumeroClt.Value = NumClt.Text;
SqlParameter paramNClt1 = new SqlParameter("@NumClt1", SqlDbType.VarChar, 13);
paramNClt1.Value = NumClt.Text;
SqlParameter paramIDMat = new SqlParameter("@IdMat", SqlDbType.Decimal, 9);
paramIDMat.Value = decimal.Parse(NumMachine.Text);
SqlParameter paramResInter = new SqlParameter("@ResInter", SqlDbType.VarChar, 250);
paramResInter.Value = RaisonInter.Text;
SqlParameter paramLieuInter = new SqlParameter("@LieuInter", SqlDbType.Text, 16);
paramLieuInter.Value = LieuInter.SelectedItem.ToString();
string strSql3 = string.Format("INSERT INTO INTERVENTION(IN_NUMINTER, IN_NUMCLT, IN_M_NUMCLT, IN_IDMAT, IN_RESINTER, IN_ETAINTER, IN_LIEINTER, IN_DEPOMAT, IN_RECEPMAT) VALUES({0},{1},{2}, {3}, {4}, 'demande', {5}, '" + Depo + "', '" + Recep + "')", paramNInter.ParameterName, paramNumeroClt.ParameterName, paramNClt1.ParameterName, paramIDMat.ParameterName, paramResInter.ParameterName, paramLieuInter.ParameterName);
SqlCommand comde = new SqlCommand(strSql3, connection);
comde.Parameters.Add(paramNInter);
comde.Parameters.Add(paramNumeroClt);
comde.Parameters.Add(paramNClt1);
comde.Parameters.Add(paramIDMat);
comde.Parameters.Add(paramResInter);
comde.Parameters.Add(paramLieuInter);
comde.ExecuteNonQuery();
}
// Sinon si le NuméroContact est inexistant
else if (_MaDataTable1.Rows.Count == 0)
{
// Enregistrement des informations sur le contact
SqlParameter paramNumCtact = new SqlParameter("@NumCtact", SqlDbType.VarChar, 13);
paramNumCtact.Value = NumContact.Text;
SqlParameter paramNumClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
paramNumClt.Value = NumClt.Text;
SqlParameter paramNomCtact = new SqlParameter("@NomCtact", SqlDbType.Char, 20);
paramNomCtact.Value = NomContact.Text;
SqlParameter paramPnmCtact = new SqlParameter("@PnmCtact", SqlDbType.Char, 20);
paramPnmCtact.Value = PrenomContact.Text;
SqlParameter paramTelCtact = new SqlParameter("@TelCtact", SqlDbType.VarChar, 15);
paramTelCtact.Value = telContact.Text;
SqlParameter paramAnnivCtact = new SqlParameter("@AnnivCtact", SqlDbType.DateTime, 8);
paramAnnivCtact.Value = annivCtact.Text;
SqlParameter paramFctCtact = new SqlParameter("@FctCtact", SqlDbType.Char, 120);
paramFctCtact.Value = FctContact.Text;
string strSql1 = string.Format("INSERT INTO CONTACT(CT_NUMCTACT, CT_NUMCLT, CT_NOMCTACT, CT_PNMCTACT, CT_TELCTACT, CT_FAXCTACT, CT_ANICTACT, CT_FCTCTACT, CT_RSPCTACT) VALUES({0}, {1}, {2}, {3}, {4}, '" + fax + "', {5}, {6}, '" + resp + "' )",paramNumCtact.ParameterName, paramNumClt.ParameterName, paramNomCtact.ParameterName, paramPnmCtact.ParameterName, paramTelCtact.ParameterName, paramAnnivCtact.ParameterName, paramFctCtact.ParameterName);
SqlCommand command = new SqlCommand(strSql1, connection);
command.Parameters.Add(paramNumCtact);
command.Parameters.Add(paramNumClt);
command.Parameters.Add(paramNomCtact);
command.Parameters.Add(paramPnmCtact);
command.Parameters.Add(paramTelCtact);
command.Parameters.Add(paramAnnivCtact);
command.Parameters.Add(paramFctCtact);
command.ExecuteNonQuery();
// Enregistrement des informations de l'intervention
SqlParameter paramNInter = new SqlParameter("@NumInter", SqlDbType.VarChar, 15);
paramNInter.Value = NumIntervention.Text;
SqlParameter paramNumeroClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
paramNumeroClt.Value = NumClt.Text;
SqlParameter paramNClt1 = new SqlParameter("@NumClt1", SqlDbType.VarChar, 13);
paramNClt1.Value = NumClt.Text;
SqlParameter paramIDMat = new SqlParameter("@IdMat", SqlDbType.Decimal, 9);
paramIDMat.Value = decimal.Parse(NumMachine.Text);
SqlParameter paramResInter = new SqlParameter("@ResInter", SqlDbType.VarChar, 250);
paramResInter.Value = RaisonInter.Text;
SqlParameter paramLieuInter = new SqlParameter("@LieuInter", SqlDbType.Text, 16);
paramLieuInter.Value = LieuInter.SelectedItem.ToString();
string strSql3 = string.Format("INSERT INTO INTERVENTION(IN_NUMINTER, IN_NUMCLT, IN_M_NUMCLT, IN_IDMAT, IN_RESINTER, IN_ETAINTER, IN_LIEINTER, IN_DEPOMAT, IN_RECEPMAT) VALUES({0},{1},{2}, {3}, {4}, 'demande', {5}, '" + Depo + "', '" + Recep + "')", paramNInter.ParameterName, paramNumeroClt.ParameterName, paramNClt1.ParameterName, paramIDMat.ParameterName, paramResInter.ParameterName, paramLieuInter.ParameterName);
SqlCommand comde = new SqlCommand(strSql3, connection);
comde.Parameters.Add(paramNInter);
comde.Parameters.Add(paramNumeroClt);
comde.Parameters.Add(paramNClt1);
comde.Parameters.Add(paramIDMat);
comde.Parameters.Add(paramResInter);
comde.Parameters.Add(paramLieuInter);
comde.ExecuteNonQuery();
}
// Sinon si le NumMachine est inexistant
else if (_MaDataTable2.Rows.Count == 0)
{
// Enregistrement des informations sur la machine
SqlParameter paramNClient = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
paramNClient.Value = NumClt.Text;
SqlParameter paramIdMat = new SqlParameter("@IdMat", SqlDbType.Decimal, 13);
paramIdMat.Value = decimal.Parse(NumMachine.Text);
SqlParameter paramNumContact = new SqlParameter("@NumCtact", SqlDbType.VarChar, 13);
paramNumContact.Value = NumContact.Text;
SqlParameter paramNomMat = new SqlParameter("@NomMat", SqlDbType.VarChar, 50);
paramNomMat.Value = NomMachine.Text;
SqlParameter paramConfMat = new SqlParameter("@ConfMat", SqlDbType.VarChar, 150);
paramConfMat.Value = ConfigMachine.Text;
SqlParameter paramRapResInter = new SqlParameter("@RapresInter", SqlDbType.Char, 50);
paramRapResInter.Value = RaisonInter.Text;
string strSql2 = string.Format("INSERT INTO MACHINE(M_NUMCLT, M_IDMAT, M_NUMCTACT, M_NOMMAT, M_CONFMAT, M_NOMUTIL, M_RAP_RESP, M_RESINTER) VALUES({0}, {1}, {2}, {3}, {4}, '" + NomUtil + "', '" + RapRespUtil + "', {5})", paramNClient.ParameterName, paramIdMat.ParameterName, paramNumContact.ParameterName, paramNomMat.ParameterName, paramConfMat.ParameterName, paramRapResInter.ParameterName);
SqlCommand Command = new SqlCommand(strSql2, connection);
Command.Parameters.Add(paramNClient);
Command.Parameters.Add(paramIdMat);
Command.Parameters.Add(paramNumContact);
Command.Parameters.Add(paramNomMat);
Command.Parameters.Add(paramConfMat);
Command.Parameters.Add(paramRapResInter);
Command.ExecuteNonQuery();
// Enregistrement des informations de l'intervention
SqlParameter paramNInter = new SqlParameter("@NumInter", SqlDbType.VarChar, 15);
paramNInter.Value = NumIntervention.Text;
SqlParameter paramNumeroClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
paramNumeroClt.Value = NumClt.Text;
SqlParameter paramNClt1 = new SqlParameter("@NumClt1", SqlDbType.VarChar, 13);
paramNClt1.Value = NumClt.Text;
SqlParameter paramIDMat = new SqlParameter("@IdMat", SqlDbType.Decimal, 9);
paramIDMat.Value = decimal.Parse(NumMachine.Text);
SqlParameter paramResInter = new SqlParameter("@ResInter", SqlDbType.VarChar, 250);
paramResInter.Value = RaisonInter.Text;
SqlParameter paramLieuInter = new SqlParameter("@LieuInter", SqlDbType.Text, 16);
paramLieuInter.Value = LieuInter.SelectedItem.ToString();
string strSql3 = string.Format("INSERT INTO INTERVENTION(IN_NUMINTER, IN_NUMCLT, IN_M_NUMCLT, IN_IDMAT, IN_RESINTER, IN_ETAINTER, IN_LIEINTER, IN_DEPOMAT, IN_RECEPMAT) VALUES({0},{1},{2}, {3}, {4}, 'demande', {5}, '" + Depo + "', '" + Recep + "')", paramNInter.ParameterName, paramNumeroClt.ParameterName, paramNClt1.ParameterName, paramIDMat.ParameterName, paramResInter.ParameterName, paramLieuInter.ParameterName);
SqlCommand comde = new SqlCommand(strSql3, connection);
comde.Parameters.Add(paramNInter);
comde.Parameters.Add(paramNumeroClt);
comde.Parameters.Add(paramNClt1);
comde.Parameters.Add(paramIDMat);
comde.Parameters.Add(paramResInter);
comde.Parameters.Add(paramLieuInter);
comde.ExecuteNonQuery();
}
else if (_MaDataTable3.Rows.Count > 0)
{
// Enregistrement des informations de l'intervention
SqlParameter paramNInter = new SqlParameter("@NumInter", SqlDbType.VarChar, 15);
paramNInter.Value = NumIntervention.Text;
SqlParameter paramNClt = new SqlParameter("@NumClt", SqlDbType.VarChar, 13);
paramNClt.Value = NumClt.Text;
SqlParameter paramNClt1 = new SqlParameter("@NumClt1", SqlDbType.VarChar, 13);
paramNClt1.Value = NumClt.Text;
SqlParameter paramIdMat = new SqlParameter("@IdMat", SqlDbType.Decimal, 9);
paramIdMat.Value = decimal.Parse(NumMachine.Text);
SqlParameter paramResInter = new SqlParameter("@ResInter", SqlDbType.VarChar, 250);
paramResInter.Value = RaisonInter.Text;
SqlParameter paramLieuInter = new SqlParameter("@LieuInter", SqlDbType.Text, 16);
paramLieuInter.Value = LieuInter.SelectedItem.ToString();
string strSql = string.Format("INSERT INTO INTERVENTION(IN_NUMINTER, IN_NUMCLT, IN_M_NUMCLT, IN_IDMAT, IN_RESINTER, IN_ETAINTER, IN_LIEINTER, IN_DEPOMAT, IN_RECEPMAT) VALUES({0},{1},{2}, {3}, {4}, 'demande', {5}, '" + Depo + "', '" + Recep + "')", paramNInter.ParameterName, paramNClt.ParameterName, paramNClt1.ParameterName, paramIdMat.ParameterName, paramResInter.ParameterName, paramLieuInter.ParameterName);
SqlCommand cmd = new SqlCommand(strSql, connection);
cmd.Parameters.Add(paramNInter);
cmd.Parameters.Add(paramNClt);
cmd.Parameters.Add(paramNClt1);
cmd.Parameters.Add(paramIdMat);
cmd.Parameters.Add(paramResInter);
cmd.Parameters.Add(paramLieuInter);
cmd.ExecuteNonQuery();
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally
{
connection.Close();
}
} |
Partager