protected void remplirVendeur(XNamespace ss, XElement worksheet) { PPVendeurs vendeurs = new PPVendeurs(); foreach (XElement row in worksheet.Descendants(ss + "Row")) { List <String> arrayStr = new List <string>(); foreach (XElement cell in row.Descendants(ss + "Data")) { arrayStr.Add(cell.Value); } //Response.Write(arrayStr.Count()); if (arrayStr.Count() == 21) { vendeurs.Add(new Vendeur(null) { NoVendeur = Convert.ToInt64(arrayStr[0]), NomAffaires = arrayStr[1], Nom = arrayStr[2], Prenom = arrayStr[3], Rue = arrayStr[4], Ville = arrayStr[5], Province = arrayStr[6] == "NULL" ? "" : arrayStr[6], CodePostal = arrayStr[7], Pays = arrayStr[8] == "NULL" ? "":arrayStr[8], Tel1 = arrayStr[9], Tel2 = arrayStr[10], AdresseEmail = arrayStr[11], MotDePasse = arrayStr[12], PoidsMaxLivraison = arrayStr[13] == "NULL" ? nullableInt : Convert.ToInt32(arrayStr[13]), LivraisonGratuite = arrayStr[14] == "NULL" ? nullableInt : Convert.ToInt32(arrayStr[14]), Taxes = (arrayStr[15] == "1" ? true : false), Pourcentage = arrayStr[16] == "NULL" ? nullableInt:Convert.ToInt32(arrayStr[16]), Configuration = arrayStr[17] == "NULL" ? null : arrayStr[17], DateCreation = DateTime.Parse(arrayStr[18]), DateMAJ = arrayStr[19] == "NULL" ? nullableDate : DateTime.Parse(arrayStr[19]), Statut = Convert.ToInt16(arrayStr[20]) }); } /*foreach (XElement cell in row.Descendants(ss + "Data")) * { * //Response.Write(cell.Value); * }*/ } }
protected void btnConfirmer_Click(object sender, EventArgs e) { // Reset everything Courriel1.DefaultControl(); Courriel2.DefaultControl(); MDP.DefaultControl(); MDP2.DefaultControl(); tbNomAffaires.DefaultControl(); tbPrenom.DefaultControl(); tbNom.DefaultControl(); tbRue.DefaultControl(); tbVille.DefaultControl(); tbCodePostal.DefaultControl(); tbTelephone.DefaultControl(); tbTelephone2.DefaultControl(); tbPoidsMax.DefaultControl(); tbPrixLivGratuite.DefaultControl(); int poidsMax = -1; decimal prixLivGratuit = -1; // Check for errors bool[] arrError = new bool[] { // Courriel Courriel1.InvalidateIfEmpty(lblErrorCourriel1, "Le courriel doit être présent") || Courriel1.CheckFormatCourriel(lblErrorCourriel1) || Courriel1.CheckMatch(Courriel2, lblErrorCourriel1, lblErrorCourriel2, "Les courriels ne sont pas identiques"), Courriel2.InvalidateIfEmpty(lblErrorCourriel2, "La confirmation de courriel doit être présente") || Courriel2.CheckFormatCourriel(lblErrorCourriel2), // Mot de passe MDP.InvalidateIfEmpty(lblErrorMDP, "Le mot de passe doit être présent") || MDP.CheckMatch(MDP2, lblErrorMDP, lblErrorMDP2, "Les mots de passes ne sont pas identiques"), MDP2.InvalidateIfEmpty(lblErrorMDP2, "La confirmation de mot de passe doit être présente"), // Nom d'affaires tbNomAffaires.InvalidateIfEmpty(lblErrorNomAffaires, "Le nom d'affaires doit être présent"), tbPrenom.InvalidateIfEmpty(lblErrorPrenom, "Le prénom doit être présent") || tbPrenom.CheckFormatNomPrenom(lblErrorPrenom), tbNom.InvalidateIfEmpty(lblErrorNom, "Le nom doit être présent") || tbNom.CheckFormatNomPrenom(lblErrorNom), tbRue.InvalidateIfEmpty(lblErrorRue, "Les informations sur la rue (No Civique et Rue)") || tbRue.CheckFormatNomPrenom(lblErrorRue), tbVille.InvalidateIfEmpty(lblErrorVille, "Le nom de la ville doit être présent") || tbVille.CheckFormatNomPrenom(lblErrorVille), tbCodePostal.InvalidateIfEmpty(lblErrorCodePostal, "Le code postal doit être présent") || tbCodePostal.CheckContains(lblErrorCodePostal, "Le code postal doit être entré au complet", "_"), tbTelephone.InvalidateIfEmpty(lblErrorTelephone, "Le numéro de téléphone doit être présent") || tbTelephone.CheckContains(lblErrorTelephone, "Le numéro de téléphone doit être entré au complet", "_"), tbTelephone2.CheckContains(lblErrorTelephone2, "Le numéro de téléphone doit être entré au complet", "_"), // Poids Max tbPoidsMax.InvalidateIfEmpty(lblErrorPoidsMax, "Le poids maximal pour une livraison doit être présent") || tbPoidsMax.CheckInt(lblErrorPoidsMax, "Le poids maximal doit être un nomber entier", out poidsMax) || tbPoidsMax.CheckIntOver0(lblErrorPoidsMax, poidsMax), // Poids livraison gratuite //tbPrixLivGratuite.InvalidateIfEmpty(lblErrorPoidsLivGratuit, "Le poids auquel une livraison devient gratuite doit être présent") tbPrixLivGratuite.Text != "" && ( tbPrixLivGratuite.CheckDecimal(lblErrorPoidsLivGratuit, "Le prix auquel une livraison devient gratuite doit être un nombre décimal", out prixLivGratuit) || tbPrixLivGratuite.CheckDecimalOver0(lblErrorPoidsLivGratuit, prixLivGratuit) ) }; if (!arrError.Contains(true)) { PPVendeurs vendeurs = new PPVendeurs(); PPClients clients = new PPClients(); PPGestionnaires gestionnaires = new PPGestionnaires(); bool errorsDB = false; if (vendeurs.Values.Any(x => x.AdresseEmail == Courriel1.Text)) { Courriel1.Invalidate(); lblErrorCourriel1.Text = "Ce courriel est déjà utilisé par un vendeur"; errorsDB = true; } else if (clients.Values.Any(x => x.AdresseEmail == Courriel1.Text)) { Courriel1.Invalidate(); lblErrorCourriel1.Text = "Ce courriel est déjà utilisé par un client"; errorsDB = true; } else if (gestionnaires.Values.Any(x => x.Email == Courriel1.Text)) { Courriel1.Invalidate(); lblErrorCourriel1.Text = "Ce courriel est déjà utilisé par un gestionnaire"; errorsDB = true; } if (vendeurs.Values.Any(x => x.NomAffaires == tbNomAffaires.Text)) { tbNomAffaires.Invalidate(); lblErrorNomAffaires.Text = "Ce nom d'affaires est déjà utilisé par un autre vendeur"; errorsDB = true; } if (!errorsDB) { Vendeur newVendeur = new Vendeur(null) { NoVendeur = vendeurs.NextId(), NomAffaires = tbNomAffaires.Text, Nom = tbNom.Text, Prenom = tbPrenom.Text, Rue = tbRue.Text, Ville = tbVille.Text, Province = ddlProvince.SelectedValue, CodePostal = tbCodePostal.Text.ToUpper(), Pays = tbPays.Text, Tel1 = tbTelephone.Text, Tel2 = tbTelephone2.Text.ToStringEmptyNull(), AdresseEmail = Courriel1.Text, MotDePasse = MDP.Text, PoidsMaxLivraison = poidsMax, LivraisonGratuite = prixLivGratuit <= 0 ? null : (decimal?)prixLivGratuit, Taxes = rbTaxesOui.Checked, DateCreation = DateTime.Now, Statut = 0 }; vendeurs.Add(newVendeur); Response.Redirect("~/Pages/InscriptionVendeur.aspx?Reussite=true"); } } }