protected void afficherLesDonnees() { PPGestionnaires gestionnaires = new PPGestionnaires(); lblgestionnaires.Text = gestionnaires.Values.Count.ToString() + " donnée(s)"; PPDetailsCommandes detailsCommandes = new PPDetailsCommandes(); lbldetailscommandes.Text = detailsCommandes.Values.Count.ToString() + " donnée(s)"; PPCommandes commandes = new PPCommandes(); lblcommandes.Text = commandes.Values.Count.ToString() + " donnée(s)"; PPPoidsLivraisons poidLivraison = new PPPoidsLivraisons(); lblpoidslivraisons.Text = poidLivraison.Values.Count.ToString() + " donnée(s)"; PPTypesLivraison typeLivraison = new PPTypesLivraison(); lbltypeslivraison.Text = typeLivraison.Values.Count.ToString() + " donnée(s)"; PPTypesPoids typePoids = new PPTypesPoids(); lbltypespoids.Text = typePoids.Values.Count.ToString() + " donnée(s)"; PPVendeursClients vendeursClients = new PPVendeursClients(); lblvendeursclients.Text = vendeursClients.Values.Count.ToString() + " donnée(s)"; PPArticlesEnPanier articlesEnPanier = new PPArticlesEnPanier(); lblarticlesenpanier.Text = articlesEnPanier.Values.Count.ToString() + " donnée(s)"; PPClients clients = new PPClients(); lblclients.Text = clients.Values.Count.ToString() + " donnée(s)"; PPProduits produits = new PPProduits(); lblproduits.Text = produits.Values.Count.ToString() + " donnée(s)"; PPVendeurs vendeurs = new PPVendeurs(); lblvendeurs.Text = vendeurs.Values.Count.ToString() + " donnée(s)"; PPCategories categories = new PPCategories(); lblcategories.Text = categories.Values.Count.ToString() + " donnée(s)"; PPHistoriquePaiements historique = new PPHistoriquePaiements(); lblhistoriquepaiements.Text = historique.Values.Count.ToString() + " donnée(s)"; PPTaxeFederale taxeFed = new PPTaxeFederale(); lbltaxefederale.Text = taxeFed.Values.Count.ToString() + " donnée(s)"; PPTaxeProvinciale taxeProv = new PPTaxeProvinciale(); lbltaxeprovinciale.Text = taxeProv.Values.Count.ToString() + " donnée(s)"; if ((gestionnaires.Values.Count > 0) || (detailsCommandes.Values.Count > 0) || (commandes.Values.Count > 0) || (poidLivraison.Values.Count > 0) || (typeLivraison.Values.Count > 0) || (typePoids.Values.Count > 0) || (vendeursClients.Values.Count > 0) || (articlesEnPanier.Values.Count > 0) || (clients.Values.Count > 0) || (produits.Values.Count > 0) || (vendeurs.Values.Count > 0) || (categories.Values.Count > 0) || (historique.Values.Count > 0) || (taxeFed.Values.Count > 0) || (taxeProv.Values.Count > 0)) { idCreerDatabase.Enabled = false; idViderDatabase.Enabled = true; } else { idCreerDatabase.Enabled = true; idViderDatabase.Enabled = false; } }
protected void remplirArticlesEnPanier(XNamespace ss, XElement worksheet) { PPArticlesEnPanier articlesEnPanier = new PPArticlesEnPanier(); 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); } if (arrayStr.Count() == 6) { articlesEnPanier.Add(new ArticleEnPanier(null) { NoPanier = Convert.ToInt64(arrayStr[0]), NoClient = Convert.ToInt64(arrayStr[1]), NoVendeur = Convert.ToInt64(arrayStr[2]), NoProduit = Convert.ToInt64(arrayStr[3]), DateCreation = Convert.ToDateTime(arrayStr[4]), NbItems = Convert.ToInt16(arrayStr[5]) }); } } }
private void click_supprimer_confirme(object sender, EventArgs e) { Button btn = (Button)sender; string id = btn.ID; PPArticlesEnPanier articles = new PPArticlesEnPanier(); List <ArticleEnPanier> listePanier = articles.Values.Where(x => x.NoVendeur == vendeur.NoVendeur && x.NoClient == int.Parse(id)).ToList(); /*foreach (ArticleEnPanier article in listePanier) * { * articles.Remove(article); * } * articles.Update();*/ articles.Remove(listePanier); PPClients ppc = new PPClients(); Client cl = ppc.Values.Find(c => c.NoClient == int.Parse(id)); Response.Clear(); var sb = new System.Text.StringBuilder(); sb.Append("<html>"); sb.AppendFormat("<body onload='document.forms[0].submit()'>"); sb.AppendFormat("<form action='{0}' method='post'>", "/Pages/Courriel.aspx"); sb.AppendFormat("<input type='hidden' name='courrielC' value='{0}'>", cl.AdresseEmail); sb.AppendFormat("<input type='hidden' name='sujet' value='Votre panier a été supprimé.'>"); sb.AppendFormat("<input type='hidden' name='contenu' value='Raison:'>"); sb.AppendFormat("<input type='hidden' name='boutonAnnuler' value='Raison:'>"); sb.Append("</form>"); sb.Append("</body>"); sb.Append("</html>"); Response.Write(sb.ToString()); Response.End(); }
public void ChangerQuantite(long NoPanier, short NewNbItems) { PPArticlesEnPanier articlesEnPanier = new PPArticlesEnPanier(); ArticleEnPanier article = articlesEnPanier.Values.Find(x => x.NoPanier == NoPanier); article.NbItems = NewNbItems; articlesEnPanier.NotifyUpdated(article); articlesEnPanier.Update(); }
public void SupprimerPanier(long NoClient, long NoVendeur) { PPArticlesEnPanier articlesEnPanier = new PPArticlesEnPanier(); bool del = articlesEnPanier.RemoveByClientAndVendeur(NoClient, NoVendeur); Context.Response.Clear(); Context.Response.ContentType = "application/text"; Context.Response.AddHeader("content-length", del.ToString().Length.ToString()); Context.Response.Flush(); Context.Response.Write(del); }
public void SupprimerArticle(long DelArticle) { PPArticlesEnPanier articlesEnPanier = new PPArticlesEnPanier(); bool del = articlesEnPanier.RemoveById(DelArticle); Context.Response.Clear(); Context.Response.ContentType = "application/text"; Context.Response.AddHeader("content-length", del.ToString().Length.ToString()); Context.Response.Flush(); Context.Response.Write(del); }
protected void ViderBD() { PPGestionnaires gestionnaires = new PPGestionnaires(); gestionnaires.RemoveAll(); PPDetailsCommandes detailsCommandes = new PPDetailsCommandes(); detailsCommandes.RemoveAll(); PPCommandes commandes = new PPCommandes(); commandes.RemoveAll(); PPPoidsLivraisons poidLivraison = new PPPoidsLivraisons(); poidLivraison.RemoveAll(); PPTypesLivraison typeLivraison = new PPTypesLivraison(); typeLivraison.RemoveAll(); PPTypesPoids typePoids = new PPTypesPoids(); typePoids.RemoveAll(); PPVendeursClients vendeursClients = new PPVendeursClients(); vendeursClients.RemoveAll(); PPArticlesEnPanier articlesEnPanier = new PPArticlesEnPanier(); articlesEnPanier.RemoveAll(); PPClients clients = new PPClients(); clients.RemoveAll(); PPProduits produits = new PPProduits(); produits.RemoveAll(); PPVendeurs vendeurs = new PPVendeurs(); vendeurs.RemoveAll(); PPCategories categories = new PPCategories(); categories.RemoveAll(); PPHistoriquePaiements historique = new PPHistoriquePaiements(); historique.RemoveAll(); PPTaxeFederale taxeFed = new PPTaxeFederale(); taxeFed.RemoveAll(); PPTaxeProvinciale taxeProv = new PPTaxeProvinciale(); taxeProv.RemoveAll(); afficherLesDonnees(); }
public void AjouterPanier(long NoClient, long NoProduit, short NbItems) { string ret = "OK"; PPProduits produits = new PPProduits(); PPArticlesEnPanier articlesEnPanier = new PPArticlesEnPanier(); Produit produit = produits.Values.Find(x => x.NoProduit == NoProduit); ArticleEnPanier article = articlesEnPanier.Values.Find(x => x.NoProduit == produit.NoProduit && x.NoClient == NoClient); if (article != null) { int newNbItems = article.NbItems.Value + NbItems; if (newNbItems <= produit.NombreItems) { article.NbItems = (short)newNbItems; articlesEnPanier.NotifyUpdated(article); articlesEnPanier.Update(); } else { ret = "ERREUR;Impossible d'ajouter au panier"; } } else { ArticleEnPanier newArticle = new ArticleEnPanier(null) { NoPanier = articlesEnPanier.NextId(NoClient, produit.NoVendeur.Value), NoClient = NoClient, NoVendeur = produit.NoVendeur, NoProduit = produit.NoProduit, DateCreation = DateTime.Now, NbItems = NbItems }; articlesEnPanier.Add(newArticle); } Context.Response.Clear(); Context.Response.ContentType = "application/text"; Context.Response.AddHeader("content-length", ret.Length.ToString()); Context.Response.Flush(); Context.Response.Write(ret); }
protected void btnImporterDonnees_Click(object sender, EventArgs e) { bool binOK = true; using (var transaction = dbContext.Database.BeginTransaction()) { try { XDocument document = XDocument.Load(Server.MapPath("\\static\\xml\\PPVendeurs.xml")); XElement racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPVendeurs")) { PPVendeurs vendeur = new PPVendeurs(); vendeur.NoVendeur = long.Parse(element.Descendants("NoVendeur").Single().Value); vendeur.NomAffaires = element.Descendants("NomAffaires").Single().Value; vendeur.Nom = element.Descendants("Nom").Single().Value; vendeur.Prenom = element.Descendants("Prenom").Single().Value; vendeur.Rue = element.Descendants("Rue").Single().Value; vendeur.Ville = element.Descendants("Ville").Single().Value; vendeur.Province = element.Descendants("Province").Single().Value; vendeur.CodePostal = element.Descendants("CodePostal").Single().Value; vendeur.Pays = element.Descendants("Pays").Single().Value; vendeur.Tel1 = element.Descendants("Tel1").Single().Value; vendeur.Tel2 = element.Descendants("Tel2").Single().Value == "NULL" ? null : element.Descendants("Tel2").Single().Value; vendeur.AdresseEmail = element.Descendants("AdresseEmail").Single().Value; vendeur.MotDePasse = element.Descendants("MotDePasse").Single().Value; vendeur.PoidsMaxLivraison = int.Parse(element.Descendants("PoidsMaxLivraison").Single().Value); vendeur.LivraisonGratuite = decimal.Parse(element.Descendants("LivraisonGratuite").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); vendeur.Taxes = element.Descendants("Taxes").Single().Value == "1" ? true : false; if (element.Descendants("Pourcentage").Single().Value == "NULL") { vendeur.Pourcentage = null; } else { vendeur.Pourcentage = decimal.Parse(element.Descendants("Pourcentage").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); } vendeur.Configuration = element.Descendants("Configuration").Single().Value; if (element.Descendants("DateCreation").Single().Value == "NULL") { vendeur.DateCreation = null; } else { vendeur.DateCreation = DateTime.Parse(element.Descendants("DateCreation").Single().Value); } if (element.Descendants("DateMAJ").Single().Value == "NULL") { vendeur.DateMAJ = null; } else { vendeur.DateMAJ = DateTime.Parse(element.Descendants("DateMAJ").Single().Value); } if (element.Descendants("Statut").Single().Value == "NULL") { vendeur.Statut = null; } else { vendeur.Statut = short.Parse(element.Descendants("Statut").Single().Value); } dbContext.PPVendeurs.Add(vendeur); XDocument configuration = new XDocument(); XElement urlImage = new XElement("urlImage"); urlImage.Value = "image_magasin.jpg"; XElement couleurFond = new XElement("couleurFond"); couleurFond.Value = "#ffffff"; XElement couleurTexte = new XElement("couleurTexte"); couleurTexte.Value = "#000000"; configuration.Add(new XElement("configuration", urlImage, couleurFond, couleurTexte)); configuration.Save(Server.MapPath("\\static\\xml\\" + vendeur.Configuration)); } document = XDocument.Load(Server.MapPath("\\static\\xml\\PPClients.xml")); racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPClients")) { PPClients client = new PPClients(); client.NoClient = long.Parse(element.Descendants("NoClient").Single().Value); client.AdresseEmail = element.Descendants("AdresseEmail").Single().Value; client.MotDePasse = element.Descendants("MotDePasse").Single().Value; client.Nom = element.Descendants("Nom").Single().Value == "NULL" ? null : element.Descendants("Nom").Single().Value; client.Prenom = element.Descendants("Prenom").Single().Value == "NULL" ? null : element.Descendants("Prenom").Single().Value; client.Rue = element.Descendants("Rue").Single().Value == "NULL" ? null : element.Descendants("Rue").Single().Value; client.Ville = element.Descendants("Ville").Single().Value == "NULL" ? null : element.Descendants("Ville").Single().Value; client.Province = element.Descendants("Province").Single().Value == "NULL" ? null : element.Descendants("Province").Single().Value; client.CodePostal = element.Descendants("CodePostal").Single().Value == "NULL" ? null : element.Descendants("CodePostal").Single().Value; client.Pays = element.Descendants("Pays").Single().Value == "NULL" ? null : element.Descendants("Pays").Single().Value; client.Tel1 = element.Descendants("Tel1").Single().Value == "NULL" ? null : element.Descendants("Tel1").Single().Value; client.Tel2 = element.Descendants("Tel2").Single().Value == "NULL" ? null : element.Descendants("Tel2").Single().Value; client.DateCreation = DateTime.Parse(element.Descendants("DateCreation").Single().Value); if (element.Descendants("DateMAJ").Single().Value == "NULL") { client.DateMAJ = null; } else { client.DateMAJ = DateTime.Parse(element.Descendants("DateMAJ").Single().Value); } client.NbConnexions = short.Parse(element.Descendants("NbConnexions").Single().Value); if (element.Descendants("DateDerniereConnexion").Single().Value == "NULL") { client.DateDerniereConnexion = null; } else { client.DateDerniereConnexion = DateTime.Parse(element.Descendants("DateDerniereConnexion").Single().Value); } client.Statut = short.Parse(element.Descendants("Statut").Single().Value); dbContext.PPClients.Add(client); } document = XDocument.Load(Server.MapPath("\\static\\xml\\PPCategories.xml")); racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPCategories")) { PPCategories categorie = new PPCategories(); categorie.NoCategorie = int.Parse(element.Descendants("NoCategorie").Single().Value); categorie.Description = element.Descendants("Description").Single().Value; categorie.Details = element.Descendants("Details").Single().Value; dbContext.PPCategories.Add(categorie); } document = XDocument.Load(Server.MapPath("\\static\\xml\\PPProduits.xml")); racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPProduits")) { PPProduits produit = new PPProduits(); produit.NoProduit = long.Parse(element.Descendants("NoProduit").Single().Value); produit.NoVendeur = long.Parse(element.Descendants("NoVendeur").Single().Value); produit.NoCategorie = int.Parse(element.Descendants("NoCategorie").Single().Value); produit.Nom = element.Descendants("Nom").Single().Value; produit.Description = element.Descendants("Description").Single().Value; produit.Photo = element.Descendants("Photo").Single().Value; produit.PrixDemande = decimal.Parse(element.Descendants("PrixDemande").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); produit.NombreItems = short.Parse(element.Descendants("NombreItems").Single().Value); produit.Disponibilité = element.Descendants("Disponibilit_").Single().Value == "1" ? true : false; if (element.Descendants("DateVente").Single().Value == "NULL") { produit.DateVente = null; } else { produit.DateVente = DateTime.Parse(element.Descendants("DateVente").Single().Value); } if (element.Descendants("PrixVente").Single().Value == "NULL") { produit.PrixVente = null; } else { produit.PrixVente = decimal.Parse(element.Descendants("PrixVente").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); } produit.Poids = decimal.Parse(element.Descendants("Poids").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); produit.DateCreation = DateTime.Parse(element.Descendants("DateCreation").Single().Value); if (element.Descendants("DateMAJ").Single().Value == "NULL") { produit.DateMAJ = null; } else { produit.DateMAJ = DateTime.Parse(element.Descendants("DateMAJ").Single().Value); } dbContext.PPProduits.Add(produit); } document = XDocument.Load(Server.MapPath("\\static\\xml\\PPArticlesEnPanier.xml")); racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPArticlesEnPanier")) { PPArticlesEnPanier articleEnPanier = new PPArticlesEnPanier(); articleEnPanier.NoPanier = long.Parse(element.Descendants("NoPanier").Single().Value); articleEnPanier.NoClient = long.Parse(element.Descendants("NoClient").Single().Value); articleEnPanier.NoVendeur = long.Parse(element.Descendants("NoVendeur").Single().Value); articleEnPanier.NoProduit = long.Parse(element.Descendants("NoProduit").Single().Value); articleEnPanier.DateCreation = DateTime.Parse(element.Descendants("DateCreation").Single().Value); articleEnPanier.NbItems = short.Parse(element.Descendants("NbItems").Single().Value); dbContext.PPArticlesEnPanier.Add(articleEnPanier); } document = XDocument.Load(Server.MapPath("\\static\\xml\\PPTypesPoids.xml")); racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPTypesPoids")) { PPTypesPoids typePoids = new PPTypesPoids(); typePoids.CodePoids = short.Parse(element.Descendants("CodePoids").Single().Value); typePoids.PoidsMin = decimal.Parse(element.Descendants("PoidsMin").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); typePoids.PoidsMax = decimal.Parse(element.Descendants("PoidsMax").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); dbContext.PPTypesPoids.Add(typePoids); } document = XDocument.Load(Server.MapPath("\\static\\xml\\PPTypesLivraison.xml")); racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPTypesLivraison")) { PPTypesLivraison typeLivraison = new PPTypesLivraison(); typeLivraison.CodeLivraison = short.Parse(element.Descendants("CodeLivraison").Single().Value); typeLivraison.Description = element.Descendants("Description").Single().Value; dbContext.PPTypesLivraison.Add(typeLivraison); } document = XDocument.Load(Server.MapPath("\\static\\xml\\PPPoidsLivraisons.xml")); racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPPoidsLivraisons")) { PPPoidsLivraisons poidsLivraison = new PPPoidsLivraisons(); poidsLivraison.CodeLivraison = short.Parse(element.Descendants("CodeLivraison").Single().Value); poidsLivraison.CodePoids = short.Parse(element.Descendants("CodePoids").Single().Value); poidsLivraison.Tarif = decimal.Parse(element.Descendants("Tarif").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); dbContext.PPPoidsLivraisons.Add(poidsLivraison); } document = XDocument.Load(Server.MapPath("\\static\\xml\\PPCommandes.xml")); racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPCommandes")) { PPCommandes commande = new PPCommandes(); commande.NoCommande = long.Parse(element.Descendants("NoCommande").Single().Value); commande.NoClient = long.Parse(element.Descendants("NoClient").Single().Value); commande.NoVendeur = long.Parse(element.Descendants("NoVendeur").Single().Value); commande.DateCommande = DateTime.Parse(element.Descendants("DateCommande").Single().Value); commande.CoutLivraison = decimal.Parse(element.Descendants("CoutLivraison").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); commande.TypeLivraison = short.Parse(element.Descendants("TypeLivraison").Single().Value); commande.MontantTotAvantTaxes = decimal.Parse(element.Descendants("MontantTotAvantTaxes").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); commande.TPS = decimal.Parse(element.Descendants("TPS").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); commande.TVQ = decimal.Parse(element.Descendants("TVQ").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); commande.PoidsTotal = decimal.Parse(element.Descendants("PoidsTotal").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); commande.Statut = element.Descendants("Statut").Single().Value; commande.NoAutorisation = element.Descendants("NoAutorisation").Single().Value; dbContext.PPCommandes.Add(commande); } document = XDocument.Load(Server.MapPath("\\static\\xml\\PPDetailsCommandes.xml")); racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPDetailsCommandes")) { PPDetailsCommandes detailCommande = new PPDetailsCommandes(); detailCommande.NoDetailCommandes = long.Parse(element.Descendants("NoDetailCommandes").Single().Value); detailCommande.NoCommande = long.Parse(element.Descendants("NoCommande").Single().Value); detailCommande.NoProduit = long.Parse(element.Descendants("NoProduit").Single().Value); detailCommande.PrixVente = decimal.Parse(element.Descendants("PrixVente").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); detailCommande.Quantité = short.Parse(element.Descendants("Quantit_").Single().Value); dbContext.PPDetailsCommandes.Add(detailCommande); } document = XDocument.Load(Server.MapPath("\\static\\xml\\PPVendeursClients.xml")); racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPVendeursClients")) { PPVendeursClients vendeurClient = new PPVendeursClients(); vendeurClient.NoVendeur = long.Parse(element.Descendants("NoVendeur").Single().Value); vendeurClient.NoClient = long.Parse(element.Descendants("NoClient").Single().Value); vendeurClient.DateVisite = DateTime.Parse(element.Descendants("DateVisite").Single().Value); dbContext.PPVendeursClients.Add(vendeurClient); } document = XDocument.Load(Server.MapPath("\\static\\xml\\PPHistoriquePaiements.xml")); racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPHistoriquePaiements")) { PPHistoriquePaiements historiquePaiement = new PPHistoriquePaiements(); historiquePaiement.NoHistorique = long.Parse(element.Descendants("NoHistorique").Single().Value); historiquePaiement.MontantVenteAvantLivraison = decimal.Parse(element.Descendants("MontantVenteAvantLivraison").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); historiquePaiement.NoVendeur = long.Parse(element.Descendants("NoVendeur").Single().Value); historiquePaiement.NoClient = long.Parse(element.Descendants("NoClient").Single().Value); historiquePaiement.NoCommande = long.Parse(element.Descendants("NoCommande").Single().Value); historiquePaiement.DateVente = DateTime.Parse(element.Descendants("DateVente").Single().Value); historiquePaiement.NoAutorisation = element.Descendants("NoCommande").Single().Value; historiquePaiement.FraisLesi = decimal.Parse(element.Descendants("FraisLesi").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); historiquePaiement.Redevance = decimal.Parse(element.Descendants("Redevance").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); historiquePaiement.FraisLivraison = decimal.Parse(element.Descendants("FraisLivraison").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); historiquePaiement.FraisTPS = decimal.Parse(element.Descendants("FraisTPS").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); historiquePaiement.FraisTVQ = decimal.Parse(element.Descendants("FraisTVQ").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); dbContext.PPHistoriquePaiements.Add(historiquePaiement); } document = XDocument.Load(Server.MapPath("\\static\\xml\\PPTaxeProvinciale.xml")); racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPTaxeProvinciale")) { PPTaxeProvinciale taxeProvinciale = new PPTaxeProvinciale(); taxeProvinciale.NoTVQ = byte.Parse(element.Descendants("NoTVQ").Single().Value); taxeProvinciale.DateEffectiveTVQ = DateTime.Parse(element.Descendants("DateEffectiveTVQ").Single().Value); taxeProvinciale.TauxTVQ = decimal.Parse(element.Descendants("TauxTVQ").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); dbContext.PPTaxeProvinciale.Add(taxeProvinciale); } document = XDocument.Load(Server.MapPath("\\static\\xml\\PPTaxeFederale.xml")); racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPTaxeFederale")) { PPTaxeFederale taxeFederale = new PPTaxeFederale(); taxeFederale.NoTPS = byte.Parse(element.Descendants("NoTPS").Single().Value); taxeFederale.DateEffectiveTPS = DateTime.Parse(element.Descendants("DateEffectiveTPS").Single().Value); taxeFederale.TauxTPS = decimal.Parse(element.Descendants("TauxTPS").Single().Value.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator)); dbContext.PPTaxeFederale.Add(taxeFederale); } document = XDocument.Load(Server.MapPath("\\static\\xml\\PPGestionnaires.xml")); racine = document.Element("dataroot"); foreach (var element in racine.Elements("PPGestionnaires")) { PPGestionnaires gestionnaire = new PPGestionnaires(); gestionnaire.ID = long.Parse(element.Descendants("ID").Single().Value); gestionnaire.courriel = element.Descendants("courriel").Single().Value; gestionnaire.motDePasse = element.Descendants("motDePasse").Single().Value; dbContext.PPGestionnaires.Add(gestionnaire); } dbContext.SaveChanges(); transaction.Commit(); lblMessage.Text = "Les données du jeu d'essai ont été importées."; divMessage.CssClass = "alert alert-success alert-margins"; } catch (DbUpdateException ex) { transaction.Rollback(); if (ex.InnerException is UpdateException && ex.InnerException.InnerException is SqlException) { lblMessage.Text = "Une erreur s'est produite lors de l'importation du jeu d'essai. Les données n'ont pas été importées. Voici l'erreur : " + ex.InnerException.InnerException.Message; } else { lblMessage.Text = "Une erreur s'est produite lors de l'importation du jeu d'essai. Les données n'ont pas été importées. Voici l'erreur : " + ex.Message; } divMessage.CssClass = "alert alert-danger alert-margins"; binOK = false; } catch (Exception ex) { transaction.Rollback(); lblMessage.Text = "Une erreur s'est produite lors de l'importation du jeu d'essai. Les données n'ont pas été importées. Voici l'erreur : " + ex.Message; divMessage.CssClass = "alert alert-danger alert-margins"; binOK = false; } } divMessage.Visible = true; remplirTableau(true); if (binOK) { btnImporterDonnees.Visible = false; btnViderBD.Visible = true; } }
public ActionResult ajouterLesDonnees() { try { /* * PPTypesPoids */ var docTypePoids = (from typePoids in XDocument .Load(Server.MapPath("/XML/PPTypesPoids.xml")).Descendants("row") select new { CodePoids = typePoids.Element("CodePoids").Value, PoidsMin = typePoids.Element("PoidsMin").Value, PoidsMax = typePoids.Element("PoidsMax").Value }).ToList(); PPTypesPoid typesPoid; foreach (var type in docTypePoids) { typesPoid = new PPTypesPoid(); typesPoid.CodePoids = Convert.ToInt16(type.CodePoids); typesPoid.PoidsMin = Convert.ToDecimal(type.PoidsMin, culture); typesPoid.PoidsMax = Convert.ToDecimal(type.PoidsMax, culture); context.PPTypesPoids.InsertOnSubmit(typesPoid); } /* * PPTypesLivraison */ var docTypeLivraison = (from typeLivraison in XDocument .Load(Server.MapPath("/XML/PPTypesLivraison.xml")).Descendants("row") select new { CodeLivraison = typeLivraison.Element("CodeLivraison").Value, Description = typeLivraison.Element("Description").Value }).ToList(); PPTypesLivraison objTypesLivraison; foreach (var type in docTypeLivraison) { objTypesLivraison = new PPTypesLivraison(); objTypesLivraison.CodeLivraison = Convert.ToInt16(type.CodeLivraison); objTypesLivraison.Description = type.Description; context.PPTypesLivraisons.InsertOnSubmit(objTypesLivraison); } /* * PPPoidsLivraison */ var docPoidsLivraison = (from poidslivraison in XDocument .Load(Server.MapPath("/XML/PPPoidsLivraison.xml")).Descendants("row") select new { CodeLivraison = poidslivraison.Element("CodeLivraison").Value, CodePoids = poidslivraison.Element("CodePoids").Value, Tarif = poidslivraison.Element("Tarif").Value }).ToList(); PPPoidsLivraison podLivraison; foreach (var type in docPoidsLivraison) { podLivraison = new PPPoidsLivraison(); podLivraison.CodeLivraison = Convert.ToInt16(type.CodeLivraison); podLivraison.CodePoids = Convert.ToInt16(type.CodePoids); podLivraison.Tarif = Convert.ToDecimal(type.Tarif, culture); context.PPPoidsLivraisons.InsertOnSubmit(podLivraison); } /* * PPCategories */ var docCategorie = (from unCategorie in XDocument .Load(Server.MapPath("/XML/PPCategorie.xml")).Descendants("row") select new { NoCategorie = unCategorie.Element("NoCategorie").Value, Description = unCategorie.Element("Description").Value, Details = unCategorie.Element("Details").Value }).ToList(); PPCategory category; foreach (var unCat in docCategorie) { category = new PPCategory(); category.NoCategorie = Convert.ToInt32(unCat.NoCategorie); category.Details = unCat.Details; category.Description = unCat.Description; context.PPCategories.InsertOnSubmit(category); } /* * PPGestionnaires */ var objGestionnaire = (from unGestionnaire in XDocument .Load(Server.MapPath("/XML/PPGestionnaire.xml")).Descendants("row") select new PPGestionnaire { NoGestionnaire = Convert.ToInt64(unGestionnaire.Element("NoGestionnaire").Value), Nom = unGestionnaire.Element("Nom").Value, Prenom = unGestionnaire.Element("Prenom").Value, AdresseEmail = unGestionnaire.Element("AdresseEmail").Value, MotDePasse = unGestionnaire.Element("MotDePasse").Value }).ToList(); foreach (var objG in objGestionnaire) { using (SqlConnection connection = new SqlConnection( WebConfigurationManager.ConnectionStrings["BD6B8_424QConnectionString"].ToString())) { connection.Open(); SqlCommand insert = new SqlCommand { CommandText = string.Format( "INSERT INTO PPGestionnaires (NoGestionnaire, Nom, Prenom, AdresseEmail, MotDePasse) VALUES (" + "{0}, '{1}', '{2}', '{3}', '{4}')", objG.NoGestionnaire, objG.Nom, objG.Prenom, objG.AdresseEmail, objG.MotDePasse), Connection = connection }; insert.ExecuteNonQuery(); connection.Close(); } } /* * PPClients */ var docClient = (from unClient in XDocument .Load(Server.MapPath("/XML/PPClients.xml")).Descendants("row") select new { NoClient = unClient.Element("NoClient").Value, AdresseEmail = unClient.Element("AdresseEmail").Value, MotDePasse = unClient.Element("MotDePasse").Value, Nom = unClient.Element("Nom").Value, Prenom = unClient.Element("Prenom").Value, Rue = unClient.Element("Rue").Value, Ville = unClient.Element("Ville").Value, Province = unClient.Element("Province").Value, CodePostal = unClient.Element("CodePostal").Value, Pays = unClient.Element("Pays").Value, Tel1 = unClient.Element("Tel1").Value, Tel2 = unClient.Element("Tel2").Value, DateCreation = unClient.Element("DateCreation").Value, DateMAJ = unClient.Element("DateMAJ").Value, NbConnexions = unClient.Element("NbConnexions").Value, DateDerniereConnexion = unClient.Element("DateDerniereConnexion").Value, Statut = unClient.Element("Statut").Value }).ToList(); PPClient objClient; foreach (var unclient in docClient) { objClient = new PPClient(); objClient.NoClient = Convert.ToInt64(unclient.NoClient); objClient.AdresseEmail = unclient.AdresseEmail; objClient.MotDePasse = unclient.MotDePasse; objClient.Nom = unclient.Nom; objClient.Prenom = unclient.Prenom; objClient.Rue = unclient.Rue; objClient.Ville = unclient.Ville; objClient.Province = unclient.Province; objClient.CodePostal = unclient.CodePostal; objClient.Pays = unclient.Pays; objClient.Tel1 = unclient.Tel1; objClient.Tel2 = unclient.Tel2; if (unclient.DateCreation != "") { objClient.DateCreation = Convert.ToDateTime(unclient.DateCreation); } if (unclient.DateMAJ != "") { objClient.DateMAJ = Convert.ToDateTime(unclient.DateMAJ); } if (unclient.DateDerniereConnexion != "") { objClient.DateDerniereConnexion = Convert.ToDateTime(unclient.DateDerniereConnexion); } objClient.NbConnexions = Convert.ToInt16(unclient.NbConnexions); objClient.Statut = Convert.ToInt16(unclient.Statut); context.PPClients.InsertOnSubmit(objClient); } /* * PPVendeurs */ var docVendeur = (from unVendeur in XDocument .Load(Server.MapPath("/XML/PPVendeur.xml")).Descendants("row") select new { NoVendeur = unVendeur.Element("NoVendeur").Value, NomAffaires = unVendeur.Element("NomAffaires").Value, Nom = unVendeur.Element("Nom").Value, Prenom = unVendeur.Element("Prenom").Value, Rue = unVendeur.Element("Rue").Value, Ville = unVendeur.Element("Ville").Value, Province = unVendeur.Element("Province").Value, CodePostal = unVendeur.Element("CodePostal").Value, Pays = unVendeur.Element("Pays").Value, Tel1 = unVendeur.Element("Tel1").Value, Tel2 = unVendeur.Element("Tel2").Value, AdresseEmail = unVendeur.Element("AdresseEmail").Value, MotDePasse = unVendeur.Element("MotDePasse").Value, PoidsMaxLivraison = unVendeur.Element("PoidsMaxLivraison").Value, LivraisonGraduite = unVendeur.Element("LivraisonGraduite").Value, Taxes = unVendeur.Element("Taxes").Value, Pourcentage = unVendeur.Element("Pourcentage").Value, Configuration = unVendeur.Element("Configuration").Value, DateCreation = unVendeur.Element("DateCreation").Value, DateMAJ = unVendeur.Element("DateMAJ").Value, Statut = unVendeur.Element("Statut").Value }).ToList(); PPVendeur objVendeur; foreach (var unVendeur in docVendeur) { objVendeur = new PPVendeur(); objVendeur.NoVendeur = Convert.ToInt64(unVendeur.NoVendeur); objVendeur.NomAffaires = unVendeur.NomAffaires; objVendeur.Nom = unVendeur.Nom; objVendeur.Prenom = unVendeur.Prenom; objVendeur.Rue = unVendeur.Rue; objVendeur.Ville = unVendeur.Ville; objVendeur.Province = unVendeur.Province; objVendeur.CodePostal = unVendeur.CodePostal; objVendeur.Pays = unVendeur.Pays; objVendeur.Tel1 = unVendeur.Tel1; objVendeur.Tel2 = unVendeur.Tel2; objVendeur.AdresseEmail = unVendeur.AdresseEmail; objVendeur.MotDePasse = unVendeur.MotDePasse; objVendeur.PoidsMaxLivraison = Convert.ToInt32(unVendeur.PoidsMaxLivraison); objVendeur.LivraisonGratuite = Convert.ToDecimal(unVendeur.LivraisonGraduite, culture); objVendeur.Taxes = unVendeur.Taxes == "1" ? true : false; objVendeur.Pourcentage = Convert.ToDecimal(unVendeur.Pourcentage, culture); if (unVendeur.DateCreation != "") { objVendeur.DateCreation = Convert.ToDateTime(unVendeur.DateCreation); } if (unVendeur.DateMAJ != "") { objVendeur.DateMAJ = Convert.ToDateTime(unVendeur.DateMAJ); } objVendeur.Configuration = unVendeur.Configuration; objVendeur.Statut = Convert.ToInt16(unVendeur.Statut); context.PPVendeurs.InsertOnSubmit(objVendeur); } /* * PPVendeursClients */ var docVendeurClient = (from unVendeurClient in XDocument .Load(Server.MapPath("/XML/PPVendeurClient.xml")).Descendants("row") select new { NoVendeur = unVendeurClient.Element("NoVendeur").Value, NoClient = unVendeurClient.Element("NoClient").Value, DateVisite = unVendeurClient.Element("DateVisite").Value }).ToList(); PPVendeursClient objVendeursClient; foreach (var unvendeursClient in docVendeurClient) { objVendeursClient = new PPVendeursClient(); objVendeursClient.NoVendeur = Convert.ToInt64(unvendeursClient.NoVendeur); objVendeursClient.NoClient = Convert.ToInt64(unvendeursClient.NoClient); if (unvendeursClient.DateVisite != "") { objVendeursClient.DateVisite = Convert.ToDateTime(unvendeursClient.DateVisite); } context.PPVendeursClients.InsertOnSubmit(objVendeursClient); } /* * PPTaxeFederale */ var docTPS = (from taxFederal in XDocument .Load(Server.MapPath("/XML/PPTaxeFederale.xml")).Descendants("row") select new { NoTPS = taxFederal.Element("NoTPS").Value, DateEffectiveTPS = taxFederal.Element("DateEffectiveTPS").Value, TauxTPS = taxFederal.Element("TauxTPS").Value }).ToList(); PPTaxeFederale objTaxeFederale; foreach (var taxe in docTPS) { objTaxeFederale = new PPTaxeFederale(); objTaxeFederale.NoTPS = Convert.ToByte(taxe.NoTPS); objTaxeFederale.DateEffectiveTPS = Convert.ToDateTime(taxe.DateEffectiveTPS); objTaxeFederale.TauxTPS = Convert.ToDecimal(taxe.TauxTPS, culture); context.PPTaxeFederales.InsertOnSubmit(objTaxeFederale); } /* * PPTaxeProvinciale */ var docTVQ = (from taxeTVQ in XDocument .Load(Server.MapPath("/XML/PPTaxeProvinciale.xml")).Descendants("row") select new { NoTVQ = taxeTVQ.Element("NoTVQ").Value, DateEffectiveTVQ = taxeTVQ.Element("DateEffectiveTVQ").Value, TauxTVQ = taxeTVQ.Element("TauxTVQ").Value }).ToList(); PPTaxeProvinciale objTaxeProvinciale; foreach (var taxe in docTVQ) { objTaxeProvinciale = new PPTaxeProvinciale(); objTaxeProvinciale.NoTVQ = Convert.ToByte(taxe.NoTVQ); objTaxeProvinciale.DateEffectiveTVQ = Convert.ToDateTime(taxe.DateEffectiveTVQ); objTaxeProvinciale.TauxTVQ = Convert.ToDecimal(taxe.TauxTVQ, culture); context.PPTaxeProvinciales.InsertOnSubmit(objTaxeProvinciale); } /* * PPProduits */ var docProduits = (from unProduit in XDocument .Load(Server.MapPath("/XML/PPProduits.xml")).Descendants("row") select new { NoProduit = unProduit.Element("NoProduit").Value, NoVendeur = unProduit.Element("NoVendeur").Value, NoCategorie = unProduit.Element("NoCategorie").Value, Nom = unProduit.Element("Nom").Value, Description = unProduit.Element("Description").Value, Photo = unProduit.Element("Photo").Value, PrixDemande = unProduit.Element("PrixDemande").Value, NombreItems = unProduit.Element("NombreItems").Value, Disponibilite = unProduit.Element("Disponibilite").Value, DateVente = unProduit.Element("DateVente").Value, PrixVente = unProduit.Element("PrixVente").Value, Poids = unProduit.Element("Poids").Value, DateCreation = unProduit.Element("DateCreation").Value, DateMAJ = unProduit.Element("DateMAJ").Value }).ToList(); PPProduit objProduit; foreach (var type in docProduits) { objProduit = new PPProduit(); objProduit.NoProduit = Convert.ToInt64(type.NoProduit); objProduit.NoVendeur = Convert.ToInt64(type.NoVendeur); objProduit.NoCategorie = Convert.ToInt32(type.NoCategorie); objProduit.Nom = type.Nom; objProduit.Description = type.Description; objProduit.Photo = type.Photo; objProduit.Disponibilité = type.Disponibilite != "1" ? false : true; objProduit.PrixDemande = Convert.ToDecimal(type.PrixDemande, culture); objProduit.NombreItems = Convert.ToInt16(type.NombreItems); if (type.DateVente != "") { objProduit.DateVente = Convert.ToDateTime(type.DateVente, culture); } if (type.PrixVente != "") { objProduit.PrixVente = Convert.ToDecimal(type.PrixVente, culture); } objProduit.Poids = Convert.ToDecimal(type.Poids, culture); objProduit.DateCreation = Convert.ToDateTime(type.DateCreation); if (type.DateMAJ != "") { objProduit.DateMAJ = Convert.ToDateTime(type.DateMAJ); } context.PPProduits.InsertOnSubmit(objProduit); } /* * PPArticlesEnPanier */ var docArticleEnPanier = (from unPanier in XDocument .Load(Server.MapPath("/XML/PPArticlesEnPanier.xml")).Descendants("row") select new { NoPanier = unPanier.Element("NoPanier").Value, NoClient = unPanier.Element("NoClient").Value, NoVendeur = unPanier.Element("NoVendeur").Value, NoProduit = unPanier.Element("NoProduit").Value, DateCreation = unPanier.Element("DateCreation").Value, NbItems = unPanier.Element("NbItems").Value }).ToList(); PPArticlesEnPanier objPanier; foreach (var type in docArticleEnPanier) { objPanier = new PPArticlesEnPanier(); objPanier.NoPanier = Convert.ToInt64(type.NoPanier); objPanier.NoClient = Convert.ToInt64(type.NoClient); objPanier.NoVendeur = Convert.ToInt64(type.NoVendeur); objPanier.NoProduit = Convert.ToInt64(type.NoProduit); objPanier.DateCreation = Convert.ToDateTime(type.DateCreation); objPanier.NbItems = Convert.ToInt16(type.NbItems); context.PPArticlesEnPaniers.InsertOnSubmit(objPanier); } /* * PPCommandes */ var docCommande = (from commande in XDocument .Load(Server.MapPath("/XML/PPCommandes.xml")).Descendants("row") select new { NoCommande = commande.Element("NoCommande").Value, NoClient = commande.Element("NoClient").Value, NoVendeur = commande.Element("NoVendeur").Value, DateCommande = commande.Element("DateCommande").Value, CoutLivraison = commande.Element("CoutLivraison").Value, TypeLivraison = commande.Element("TypeLivraison").Value, MontantTotAvantTaxes = commande.Element("MontantTotAvantTaxes").Value, TPS = commande.Element("TPS").Value, TVQ = commande.Element("TVQ").Value, PoidsTotal = commande.Element("PoidsTotal").Value, Statut = commande.Element("Statut").Value, NoAutorisation = commande.Element("NoAutorisation").Value }).ToList(); PPCommande objcommande; foreach (var type in docCommande) { objcommande = new PPCommande(); objcommande.NoCommande = Convert.ToInt64(type.NoCommande); objcommande.NoClient = Convert.ToInt64(type.NoClient); objcommande.NoVendeur = Convert.ToInt64(type.NoVendeur); objcommande.DateCommande = Convert.ToDateTime(type.DateCommande); if (type.CoutLivraison != "") { objcommande.CoutLivraison = Convert.ToDecimal(type.CoutLivraison, culture); } objcommande.TypeLivraison = Convert.ToInt16(type.TypeLivraison); objcommande.MontantTotAvantTaxes = Convert.ToDecimal(type.MontantTotAvantTaxes, culture); if (type.TPS != "") { objcommande.TPS = Convert.ToDecimal(type.TPS, culture); } if (type.TVQ != "") { objcommande.TVQ = Convert.ToDecimal(type.TVQ, culture); } objcommande.PoidsTotal = Convert.ToDecimal(type.PoidsTotal, culture); objcommande.Statut = Convert.ToChar(type.Statut); objcommande.NoAutorisation = type.NoAutorisation; context.PPCommandes.InsertOnSubmit(objcommande); } /* * PPDetailsCommande */ var docDetailsCommande = (from unDetailCommande in XDocument .Load(Server.MapPath("/XML/PPDetailsCommande.xml")).Descendants("row") select new { NoDetailCommandes = unDetailCommande.Element("NoDetailCommandes").Value, NoCommande = unDetailCommande.Element("NoCommande").Value, NoProduit = unDetailCommande.Element("NoProduit").Value, PrixVente = unDetailCommande.Element("PrixVente").Value, Quantité = unDetailCommande.Element("Quantité").Value }).ToList(); PPDetailsCommande objDetailsCommande; foreach (var type in docDetailsCommande) { objDetailsCommande = new PPDetailsCommande(); objDetailsCommande.NoDetailCommandes = Convert.ToInt64(type.NoDetailCommandes); objDetailsCommande.NoCommande = Convert.ToInt64(type.NoCommande); objDetailsCommande.NoProduit = Convert.ToInt64(type.NoProduit); objDetailsCommande.PrixVente = Convert.ToDecimal(type.PrixVente, culture); objDetailsCommande.Quantité = Convert.ToInt16(type.Quantité); context.PPDetailsCommandes.InsertOnSubmit(objDetailsCommande); } /* * PPHistoriquePayement */ var docHistorique = (from uneHistorique in XDocument .Load(Server.MapPath("/XML/PPHistoriquePayement.xml")) .Descendants("row") select new { NoHistorique = uneHistorique.Element("NoHistorique").Value, MontantVenteAvantLivraison = uneHistorique.Element("MontantVenteAvantLivraison").Value, NoVendeur = uneHistorique.Element("NoVendeur").Value, NoClient = uneHistorique.Element("NoClient").Value, NoCommande = uneHistorique.Element("NoCommande").Value, DateVente = uneHistorique.Element("DateVente").Value, NoAutoristion = uneHistorique.Element("NoAutoristion").Value, FraisLesi = uneHistorique.Element("FraisLesi").Value, Redevance = uneHistorique.Element("Redevance").Value, FraisLivraison = uneHistorique.Element("FraisLivraison").Value, FraisTPS = uneHistorique.Element("FraisTPS").Value, FraisTVQ = uneHistorique.Element("FraisTVQ").Value }).ToList(); PPHistoriquePaiement objHistoriquePaiement; foreach (var unHistorique in docHistorique) { objHistoriquePaiement = new PPHistoriquePaiement(); objHistoriquePaiement.NoHistorique = Convert.ToInt32(unHistorique.NoHistorique); objHistoriquePaiement.MontantVenteAvantLivraison = Convert.ToDecimal(unHistorique.MontantVenteAvantLivraison, culture); objHistoriquePaiement.NoVendeur = Convert.ToInt64(unHistorique.NoVendeur); objHistoriquePaiement.NoClient = Convert.ToInt64(unHistorique.NoClient); objHistoriquePaiement.NoCommande = Convert.ToInt64(unHistorique.NoCommande); objHistoriquePaiement.DateVente = Convert.ToDateTime(unHistorique.DateVente); objHistoriquePaiement.NoAutorisation = unHistorique.NoAutoristion; objHistoriquePaiement.FraisLesi = Convert.ToDecimal(unHistorique.FraisLesi, culture); objHistoriquePaiement.Redevance = Convert.ToDecimal(unHistorique.Redevance, culture); if (unHistorique.FraisLivraison != "") { objHistoriquePaiement.FraisLivraison = Convert.ToDecimal(unHistorique.FraisLivraison, culture); } if (unHistorique.FraisTPS != "") { objHistoriquePaiement.FraisTPS = Convert.ToDecimal(unHistorique.FraisTPS, culture); } if (unHistorique.FraisTVQ != "") { objHistoriquePaiement.FraisTVQ = Convert.ToDecimal(unHistorique.FraisTVQ, culture); } context.PPHistoriquePaiements.InsertOnSubmit(objHistoriquePaiement); } /* * PPLieu */ var docLieu = (from unLieu in XDocument.Load(Server.MapPath("/XML/PPLieu.xml")) .Descendants("row") select new { NoLieu = unLieu.Element("NoLieu").Value, Description = unLieu.Element("Description").Value }).ToList(); PPLieu objLieu; foreach (var unLieu in docLieu) { objLieu = new PPLieu(); objLieu.NoLieu = Convert.ToInt16(unLieu.NoLieu); objLieu.Description = unLieu.Description; context.PPLieus.InsertOnSubmit(objLieu); } /* * PPDestinataires * * var docDestinataires = (from unDestinataire in XDocument * .Load(Server.MapPath("/XML/PPDestinataires.xml")) * .Descendants("row") * select new * { * NoMsg = unDestinataire.Element("NoMsg").Value, * NoDestinataire = unDestinataire.Element("NoDestinataire").Value, * EtatLu = unDestinataire.Element("EtatLu").Value, * Lieu = unDestinataire.Element("Lieu").Value * }).ToList(); * * PPDestinataire ppDestinataire; * * foreach (var unDest in docDestinataires) * { * ppDestinataire=new PPDestinataire(); * * ppDestinataire.NoMsg = Convert.ToInt32(unDest.NoMsg); * ppDestinataire.NoDestinataire = Convert.ToInt32(unDest.NoDestinataire); * ppDestinataire.EtatLu = Convert.ToInt16(unDest.EtatLu); * ppDestinataire.Lieu = Convert.ToInt16(unDest.Lieu); * * * * context.PPDestinataires.InsertOnSubmit(ppDestinataire); * } * * * PPMessages * * var docMessages = (from unMessage in XDocument * .Load(Server.MapPath("/XML/PPMessages.xml")) * .Descendants("row") * select new * { * NoMsg = unMessage.Element("NoMsg").Value, * NoExpediteur = unMessage.Element("NoExpediteur").Value, * DescMsg = unMessage.Element("DescMsg").Value, * FichierJoint = unMessage.Element("FichierJoint").Value, * Lieu = unMessage.Element("Lieu").Value, * dateEnvoi = unMessage.Element("dateEnvoi").Value, * objet = unMessage.Element("objet").Value * }).ToList(); * * PPMessage objMessage; * * foreach (var unMessages in docMessages) * { * objMessage = new PPMessage(); * * objMessage.NoMsg = Convert.ToInt32(unMessages.NoMsg); * objMessage.NoExpediteur = Convert.ToInt32(unMessages.NoExpediteur); * objMessage.DescMsg = unMessages.DescMsg; * objMessage.FichierJoint = unMessages.FichierJoint; * objMessage.Lieu = Convert.ToInt16(unMessages.Lieu); * objMessage.dateEnvoi = Convert.ToDateTime(unMessages.dateEnvoi); * objMessage.objet = unMessages.objet; * * context.PPMessages.InsertOnSubmit(objMessage); * } * * PPEvaluation */ var docEvalu = (from uneEvaluation in XDocument .Load(Server.MapPath("/XML/PPEvaluations.xml")) .Descendants("row") select new { NoClient = uneEvaluation.Element("NoClient").Value, NoProduit = uneEvaluation.Element("NoProduit").Value, Cote = uneEvaluation.Element("Cote").Value, Commentaire = uneEvaluation.Element("Commentaire").Value, DateMAJ = uneEvaluation.Element("DateMAJ").Value, DateCreation = uneEvaluation.Element("DateCreation").Value }).ToList(); PPEvaluation objEvaluation; foreach (var uneEvalu in docEvalu) { objEvaluation = new PPEvaluation(); objEvaluation.NoClient = Convert.ToInt32(uneEvalu.NoClient); objEvaluation.NoProduit = Convert.ToInt32(uneEvalu.NoProduit); objEvaluation.Cote_ = Convert.ToDecimal(uneEvalu.Cote); objEvaluation.Commentaire_ = uneEvalu.Commentaire; objEvaluation.DateMAJ_ = Convert.ToDateTime(uneEvalu.DateMAJ); objEvaluation.DateCreation_ = Convert.ToDateTime(uneEvalu.DateCreation); context.PPEvaluations.InsertOnSubmit(objEvaluation); } try { context.SubmitChanges(); } catch (Exception e) { ViewBag.lsMessageRemplir = e.Message; } return(RedirectToAction("Index", new { status = "vider" })); } catch (Exception e) { return(Content("Remplissage échoué: " + e)); } }
private void paniersAccueilClient(Panel panel) { PPProduits produits = new PPProduits(); List <Produit> nouvelleListe = produits.Values.OrderByDescending(x => x.DateCreation.Value).Where(c => c.NoVendeur == vendeur.NoVendeur).ToList(); int index = 0; int index2 = 0; Panel rows = null; if (nouvelleListe.Count() > 0) { foreach (var produit in nouvelleListe) { if (index % 3 == 0) { rows = panelTable.DivDyn("", "row"); index2++; } bool inactif = false; Panel panelCard = rows.DivDyn("", "col-1200-4 mb-3"); Panel card = panelCard.DivDyn("", "card"); string strInactif = ""; if (!produit.Disponibilité.Value && produit.NombreItems.Value == -1) { strInactif = "Inactif"; inactif = true; } else if (!produit.Disponibilité.Value) { strInactif = "Indisponible"; } else if (produit.NombreItems == 0) { strInactif = "Rupture de stock"; } Panel panelTitreCategories; if (inactif) { panelTitreCategories = card.DivDyn("", "card-header fake-button bg-warning"); } else { panelTitreCategories = card.DivDyn("", "card-header fake-button"); } Table tableT = panelTitreCategories.TableDyn("", "table borderless"); TableRow rowt = tableT.TrDyn(); TableCell cell1 = rowt.TdDyn(); cell1.ImgDyn("", "~/Pictures/" + produit.Photo, "imgResize"); TableCell cell2 = rowt.TdDyn(); cell2.LblDyn("", produit.Nom, "card-title h6"); cell2.ForeColor = System.Drawing.ColorTranslator.FromHtml(couleurTexte); if (!produit.Disponibilité.Value && produit.NombreItems.Value == -1) { TableCell cell3 = rowt.TdDyn(); cell3.LblDyn("", strInactif, "card-title h6 text-danger"); } else if (!produit.Disponibilité.Value || produit.NombreItems.Value == 0) { TableCell cell3 = rowt.TdDyn(); cell3.LblDyn("", strInactif, "card-title h6 text-danger"); } if (produit.PrixDemande != produit.PrixVente && produit.DateVente >= DateTime.Today) { decimal montantRabais = produit.PrixDemande.Value - produit.PrixVente.Value; TableCell cell3ou4 = rowt.TdDyn(); cell3ou4.LblDyn("", "rabais!<br/>", "card-title h6 text-success"); cell3ou4.LblDyn("", "(" + montantRabais.ToString("N2") + "$)<br/>" + produit.DateVente.Value.ToString("yyyy-MM-dd"), "h6 text-success"); } else if (produit.PrixDemande != produit.PrixVente && produit.DateVente < DateTime.Today) { TableCell cell3ou4 = rowt.TdDyn(); cell3ou4.LblDyn("", "rabais fini", "card-title h6 text-warning"); } panelTitreCategories.Attributes.Add("data-toggle", "collapse"); panelTitreCategories.Attributes.Add("data-target", "#Contenu_ContenuPrincipal_collapsePanier" + index.ToString() + index2.ToString()); panelTitreCategories.Attributes.Add("aria-expanded", "false"); panelTitreCategories.Attributes.Add("aria-controls", "Contenu_ContenuPrincipal_collapsePanier" + index.ToString() + index2.ToString()); Panel collapsable; //body des categories collapsable = card.DivDyn("collapsePanier" + index.ToString() + index2.ToString(), "collapse collapse"); //colones header Panel panelBodyCat = collapsable.DivDyn("", "card-body"); Table table = panelBodyCat.TableDyn("", "table"); TableHeaderRow rowTable = table.ThrDyn(); TableHeaderCell headerCss = rowTable.ThdDyn("Date"); headerCss = rowTable.ThdDyn("Poids"); headerCss.CssClass = "text-right"; headerCss = rowTable.ThdDyn("Prix habituel"); headerCss.CssClass = "text-right"; headerCss = rowTable.ThdDyn("Qte"); TableRow rowTableB = table.TrDyn(); TableCell celluleCss = rowTableB.TdDyn(produit.DateCreation.Value.ToString("yyyy/MM/dd")); celluleCss = rowTableB.TdDyn(produit.Poids.Value.ToString("N2") + " Lbs"); celluleCss.CssClass = "text-right"; celluleCss = rowTableB.TdDyn(produit.PrixDemande.Value.ToString("N2") + " $"); celluleCss.CssClass = "text-right"; string nbItems = "--"; if (produit.NombreItems.Value != -1) { nbItems = "(" + produit.NombreItems.Value.ToString() + ")"; } rowTableB.TdDyn(nbItems); if (!inactif) { Panel rowBtnSupprimer = collapsable.DivDyn("", "row ml-3 mb-3"); rowBtnSupprimer.BtnDyn(produit.NoProduit.ToString(), "Détails", ouvrirDetailsProduits, "btn btn-outline-info col-3"); rowBtnSupprimer.DivDyn("", "col-1"); rowBtnSupprimer.BtnDyn("m" + produit.NoProduit.ToString(), "Modifier", ouvrirModificationsProduits, "btn btn-outline-dark col-3"); rowBtnSupprimer.DivDyn("", "col-1"); Button btn = rowBtnSupprimer.BtnDyn("", "X", null, "btn btn-outline-danger col-3"); btn.OnClientClick = "return false;"; btn.Attributes.Add("data-toggle", "modal"); btn.Attributes.Add("data-target", "#Contenu_ContenuPrincipal_myModal" + index.ToString() + index2.ToString()); //Regarder ici si dans panier, alors loader le bon modal. bool panier = false; PPArticlesEnPanier paniers = new PPArticlesEnPanier(); List <ArticleEnPanier> trouverSiPanier = paniers.Values.Where(x => x.NoProduit == produit.NoProduit).ToList(); if (trouverSiPanier.Count() != 0) { //Dans panier panier = true; } if (!panier) { modal(panelAvecModal, "myModal" + index.ToString() + index2.ToString(), produit.NoProduit.ToString() /*l'ID du btn est le noProduit*/, "idBtnAnnuler" + index.ToString() + index2.ToString(), "Supression", "Voulez vous supprimer ce produit : " + produit.Nom, true); } else { modal(panelAvecModal, "myModal" + index.ToString() + index2.ToString(), produit.NoProduit.ToString() /*l'ID du btn est le noProduit*/, "idBtnAnnuler" + index.ToString() + index2.ToString(), "Attention!", "Ce produit (" + produit.Nom + ") est dans au moins un panier, voulez-vous vraiment le supprimer?", true); } } index++; } } else { panelTable.LblDyn("", "Vous n'avez aucun article dans ce moment", "h4 text-info ml-3"); } }
protected void Page_Load(object sender, EventArgs e) { bool connecte = false; if (Session.IsClient()) { panelInformations.Visible = true; pnClientPanier.Visible = true; PanelVendeurs.Visible = true; connecte = true; } PPCategories categories = new PPCategories(); PPVendeurs vendeurs = new PPVendeurs(); PPProduits produits = new PPProduits(); var groupe = from produit in produits.Values group produit by produit.NoCategorie into groupement join categorie in categories.Values on groupement.Key equals categorie.NoCategorie select new { LCategories = groupement.ToList(), Categories = categorie }; //for pour remplir le pnHaut (Correspond au panel avec le titre : catégorie int index = 0; int index2 = 0; Panel rows = null; foreach (var categorie in groupe) { //requete pour grouper les vendeurs var groupement = (from gr in categorie.LCategories.AsEnumerable() group gr by gr.NoVendeur into ok join vendeur in vendeurs.Values on ok.Key equals vendeur.NoVendeur select new { Vendeurs = vendeur }).Where(v => v.Vendeurs.Statut != -1); string nomCategorie = categorie.Categories.Description; if (index % 2 == 0) { rows = pnHaut.DivDyn("", "row"); index2++; } //header des categories Panel panelCard = rows.DivDyn("", "col-lg-6 mb-3"); panelCard.CardDynCollapse("", "", index2 == 1 && index == 0 ? "show" : "", header => { header.LblDyn("", nomCategorie, "card-title h5 text-primary"); header.LblDyn("", $"({groupement.Count()} vendeurs)", "card-title ml-3 h5 text-primary"); }, body => { Table table = body.TableDyn("", "table table-hover fake-button"); TableHeaderRow rowTable = table.ThrDyn(); rowTable.ThdDyn(""); rowTable.ThdDyn("Vendeur"); rowTable.ThdDyn("Quantité d'articles dans cette catégorie"); foreach (var vendeur in groupement) { PPProduits produitsCount = new PPProduits(); List <Produit> liste = produits.Values.Where(x => x.NoVendeur == vendeur.Vendeurs.NoVendeur && x.NoCategorie == categorie.Categories.NoCategorie).ToList(); //contenu des collapse TableRow nRow = table.TrDyn(); if (connecte) { nRow.Attributes.Add("OnClick", "window.location.assign('/Pages/Client/Catalogue.aspx?NoVendeur=" + vendeur.Vendeurs.NoVendeur + "&NoCategorie=" + categorie.Categories.NoCategorie + "');"); } else { nRow.Attributes.Add("OnClick", "window.location.assign('/Pages/Nouveautes.aspx');"); } string strLogo = "placeholder.png"; if (vendeur.Vendeurs.Configuration != null) { strLogo = vendeur.Vendeurs.Configuration.Split(';')[0]; } TableCell cell1 = nRow.TdDyn("", ""); cell1.ImgDyn("", "~/Logos/" + strLogo, "imgResize"); TableCell cell2 = nRow.TdDyn(); cell2.LblDyn("", vendeur.Vendeurs.NomAffaires, "text-info h5"); TableCell cell3 = nRow.TdDyn(); cell3.LblDyn("", "(" + liste.Count() + ")", ""); } index++; }); } //section client if (connecte) { Client client = Session.GetClient(); //row de recherche //panel pnInfos Panel rowInfos = pnInfos.DivDyn("", "row"); Panel pnPourConn = rowInfos.DivDyn("", "col-md-6"); pnPourConn.LblDyn("", "Votre nombre de connexions : ", "align-self-center h5"); pnPourConn.LblDyn("lblNbCo", client.NbConnexions.ToString(), "text-primary align-self-center h5"); Panel pnDate = rowInfos.DivDyn("", "col-md-6"); pnDate.LblDyn("", "Dernière connexion : ", "align-self-center h5"); pnDate.LblDyn("", client.DateDerniereConnexion.Value.ToString("yyyy/MM/dd"), "align-self-center h5 text-primary"); PPArticlesEnPanier articlesEnPanier = new PPArticlesEnPanier(); var panierArticlesParVendeurs = (from article in articlesEnPanier.Values join produit in produits.Values on article.NoProduit equals produit.NoProduit where article.NoClient == client.NoClient select new { Article = article, Produit = produit } into articleProduit group articleProduit by articleProduit.Article.NoVendeur into g join vendeur in vendeurs.Values on g.Key equals vendeur.NoVendeur select new { Vendeur = vendeur, Articles = g.ToList() }).Where(v => v.Vendeur.Statut != -1); index = 0; index2 = 0; rows = null; foreach (var group in panierArticlesParVendeurs) { string nomVendeur = group.Vendeur.NomAffaires; string noVendeur = group.Vendeur.NoVendeur.ToString(); decimal montant = 0; int nombreArticles = 0; DateTime datePanier = DateTime.Now; foreach (var article in group.Articles) { nombreArticles++; montant += article.Produit.PrixVente.Value * article.Article.NbItems.Value; datePanier = article.Article.DateCreation.Value.Date; } // Panel card = pnHaut.DivDyn("card" + i.ToString(), "card"); if (index % 2 == 0) { rows = pnPaniers.DivDyn("", "row"); index2++; } //header des categories Panel panelCard = rows.DivDyn("", "col-xl-6 mb-3"); panelCard.CardDynCollapse("", "", "", header => { header.LblDyn("", nomVendeur, "card-title h5 text-info"); header.LblDyn("", $"valeur de {montant.ToString("N2")}$", "card-title ml-3 h6"); header.LblDyn("", $"Articles ({nombreArticles})", "card-title ml-3 h6"); }, body => { body.BtnClientDyn("", "Aller au panier", $"panierVendeur({noVendeur}); return false;", "btn btn-secondary btn-block mb-3"); //colones header Table table = body.TableDyn("", "table table-hover fake-button"); TableHeaderRow rowTable = table.ThrDyn(); rowTable.ThdDyn(""); rowTable.ThdDyn("Produit"); rowTable.ThdDyn("Poids unitaire"); rowTable.ThdDyn("Quantite"); rowTable.ThdDyn("Prix unitaire"); rowTable.ThdDyn("Prix total"); foreach (var article in group.Articles) { //contenu des collapse string nomArticle = article.Produit.Nom; decimal montantArticle = article.Produit.PrixVente.Value; decimal poidsArticle = article.Produit.Poids.Value; short nbItems = article.Article.NbItems.Value; decimal prix = article.Produit.PrixVente.Value * article.Article.NbItems.Value; TableRow nRow = table.TrDyn(); nRow.Attributes.Add("OnClick", "window.location.assign('/Pages/Client/InfoProduit.aspx?ID=" + article.Produit.NoProduit + "');"); TableCell cell1 = nRow.TdDyn("", ""); cell1.ImgDyn("", "~/Pictures/" + article.Produit.Photo, "imgResize"); TableCell cell2 = nRow.TdDyn(); cell2.LblDyn("", nomArticle, "h5"); TableCell cell3 = nRow.TdDyn(); cell3.LblDyn("", poidsArticle.ToString("N2") + " Lbs", ""); TableCell cell4 = nRow.TdDyn(); cell4.LblDyn("", "(" + nbItems.ToString() + ")", ""); TableCell cell5 = nRow.TdDyn(); cell5.CssClass = "moneyDroite"; cell5.LblDyn("", montantArticle.ToString("N2") + " $", "moneyDroite"); TableCell cell6 = nRow.TdDyn(); cell6.CssClass = "moneyDroite"; cell6.LblDyn("", prix.ToString("N2") + " $", "text-success moneyDroite"); } //prix total Panel rowTotal = body.DivDyn("", "moneyDroite"); rowTotal.LblDyn("", "Total de ce panier : ", "h4 mb-3"); rowTotal.LblDyn("", montant.ToString("N2") + " $", "h4 text-success mb-3 ml-2"); index++; }); } index = 0; index2 = 0; rows = null; foreach (var vendeur in vendeurs.Values.Where(v => v.Statut == 1)) { string nomVendeur = vendeur.NomAffaires; if (index % 2 == 0) { rows = pnVendeurs.DivDyn("", "row"); index2++; } //header des categories Panel panelCard = rows.DivDyn("", "col-md-6 mb-3"); Panel card = panelCard.DivDyn("", "card"); Panel panelTitreCategories = card.DivDyn("", "card-header fake-button"); var prod = produits.Values.Where(v => v.NoVendeur.Equals(vendeur.NoVendeur)).Count(); panelTitreCategories.LblDyn("", nomVendeur + " (" + prod + " produits)", "card-title h5 text-primary"); panelTitreCategories.Attributes.Add("OnClick", "window.location.assign('/Pages/Client/Catalogue.aspx?NoVendeur=" + vendeur.NoVendeur + "');"); index++; } } }
protected void nombreClientParVendeur() { Table tableCliensPourVendeur = panelNBVisite.TableDyn("", "table table-active mt-3"); TableHeaderRow thr = tableCliensPourVendeur.ThrDyn(); thr.CssClass = "text-primary"; thr.ThdDyn("Clients actifs"); thr.ThdDyn("Clients potentiels"); thr.ThdDyn("Clients visiteurs"); TableHeaderCell cellh = thr.ThdDyn("Nombre total de clients"); cellh.CssClass = "h4 text-success"; int nbClientActif = 0; int nbClientPotentiel = 0; int nbClientVisiteur = 0; foreach (Client client in clients.Values) { Boolean clientTrouve = false; foreach (VendeurClient vendeurClient in vendeursClients.Values) { if (client.NoClient.Equals(vendeurClient.NoClient) && (vendeur.NoVendeur.Equals(vendeurClient.NoVendeur))) { clientTrouve = true; } } if (clientTrouve) { Boolean booCommande = false; Boolean booArticlePanier = false; foreach (Commande commande in commandes.Values) { if (commande.NoClient.Equals(client.NoClient) && (commande.NoVendeur.Equals(vendeur.NoVendeur))) { booCommande = true; } } PPArticlesEnPanier paniers = new PPArticlesEnPanier(); foreach (ArticleEnPanier panier in paniers.Values) { if (panier.NoClient.Equals(client.NoClient) && (panier.NoVendeur.Equals(vendeur.NoVendeur))) { booArticlePanier = true; } } if (booCommande) { nbClientActif++; } else if (booArticlePanier) { nbClientPotentiel++; } else { nbClientVisiteur++; } } } TableRow rowVendeur = new TableRow(); rowVendeur.CssClass = "text-primary"; TableCell cellActif = new TableCell(); TableCell cellPotentiel = new TableCell(); TableCell cellVisiteur = new TableCell(); TableCell cellTotal = new TableCell(); cellTotal.CssClass = "h5 text-success"; cellActif.Text = nbClientActif.ToString(); rowVendeur.Cells.Add(cellActif); cellPotentiel.Text = nbClientPotentiel.ToString(); rowVendeur.Cells.Add(cellPotentiel); cellVisiteur.Text = nbClientVisiteur.ToString(); rowVendeur.Cells.Add(cellVisiteur); cellTotal.Text = (nbClientActif + nbClientPotentiel + nbClientVisiteur).ToString(); rowVendeur.Cells.Add(cellTotal); tableCliensPourVendeur.Rows.Add(rowVendeur); }
protected void Page_Load(object sender, EventArgs e) { if (!Session.IsVendeur()) { Response.Redirect(SessionManager.RedirectConnexionLink); } vendeur = Session.GetVendeur(); //Requetes pour commandes non traitées //PPCommandes commandes = new PPCommandes(); PPDetailsCommandes details = new PPDetailsCommandes(); PPClients clients = new PPClients(); var commandesVendeur = from commande in commandes.Values join monClient in clients.Values on commande.NoClient equals monClient.NoClient where commande.NoVendeur == vendeur.NoVendeur && commande.Statut == "0" orderby commande.DateCommande ascending let lstDetails = details.Values.Where(x => x.NoCommande == commande.NoCommande).ToList() select new { Commande = commande, Client = monClient, Details = lstDetails }; //Commandes int indexCom = 0; if (commandesVendeur.Count() > 0) { foreach (var com in commandesVendeur) { TableRow row = new TableRow(); long? noCommande = com.Commande.NoCommande; string nomClient = com.Client.Prenom + " " + com.Client.Nom; DateTime dateCommande = com.Commande.DateCommande.Value; decimal poidsCommande = com.Commande.PoidsTotal.Value; PPHistoriquePaiements historique = new PPHistoriquePaiements(); //requete pour aller cherche le montant dans l'historique var montant = from montantHisto in historique.Values where montantHisto.NoCommande == com.Commande.NoCommande select montantHisto.MontantVenteAvantLivraison; decimal montantCom = montant.First().Value; string nomPDF = ""; if (File.Exists(Server.MapPath("~/Factures/" + noCommande.ToString() + ".pdf"))) { nomPDF = noCommande.ToString() + ".pdf"; } else { nomPDF = "defaut.pdf"; } TableCell cellNom = new TableCell(); /* cellNom.Text = "Marcel Leboeuf"; * cellNom.Attributes.Add("OnClick", "window.location.assign('http://www.google.com');");*/ //cellNom.BtnDyn("", nomClient, ouvrirInfosClients, "table btn btn-outline-secondary text-left"); cellNom.Text = nomClient; cellNom.Attributes.Add("OnClick", "ouvrirPDF('" + nomPDF + "');"); row.Cells.Add(cellNom); TableCell cellDate = new TableCell(); cellDate.Text = dateCommande.ToString("yyyy/MM/dd"); cellDate.Attributes.Add("OnClick", "ouvrirPDF('" + nomPDF + "');"); row.Cells.Add(cellDate); TableCell cellPrix = new TableCell(); cellPrix.CssClass = "text-right"; cellPrix.Text = montantCom.ToString("N2") + " $"; cellPrix.Attributes.Add("OnClick", "ouvrirPDF('" + nomPDF + "');"); row.Cells.Add(cellPrix); TableCell cellStatut = new TableCell(); cellStatut.CssClass = "text-right"; cellStatut.Text = poidsCommande.ToString("N2") + " Lbs"; cellStatut.Attributes.Add("OnClick", "ouvrirPDF('" + nomPDF + "');"); row.Cells.Add(cellStatut); //modal (il faut faire référence à la div à cet effet dans le front-hand. modal(panelAvecModal, "myModal" + indexCom.ToString(), noCommande.ToString(), "btnAnnulerLiv" + indexCom.ToString(), "Livraison", "Voulez-vous vraiment confirmer la livraison de cette commande? (" + noCommande.ToString() + ")", true); TableCell cellBtn = row.TdDyn(); Button btnLivrer = cellBtn.BtnDyn("", "Prêt à livrer", null, "btn btn-secondary btn-block btn-sm"); btnLivrer.OnClientClick = "return false;"; btnLivrer.Attributes.Add("data-toggle", "modal"); btnLivrer.Attributes.Add("data-target", "#Contenu_ContenuPrincipal_myModal" + indexCom.ToString()); row.Cells.Add(cellBtn); tableCommandesNonTraitee.Rows.Add(row); indexCom++; } } else { tableCommandesNonTraitee.Visible = false; pnUseless.LblDyn("", "Vous n'avez aucune commande non traités", "h4 text-info"); } PPArticlesEnPanier articlesEnPanier = new PPArticlesEnPanier(); PPProduits produits = new PPProduits(); var yes = from article in articlesEnPanier.Values //join vendeur in vendeurs.Values on article.NoVendeur equals vendeur.NoVendeur join produit in produits.Values on article.NoProduit equals produit.NoProduit where article.NoVendeur == vendeur.NoVendeur orderby article.DateCreation ascending select new { Article = article, Produit = produit }; var grouped = from article in yes group article by article.Article.NoClient into g join client in clients.Values on g.Key equals client.NoClient select new { NoClient = g.Key, Client = client, Articles = g.ToList() }; int index = 0; if (grouped.Count() > 0) { foreach (var group in grouped) { string nomClient = "Anonyme"; string noClient = group.Client.NoClient.ToString(); decimal montant = 0; int nombreArticles = 0; DateTime datePanier = DateTime.Now; if (group.Client.Prenom != null && group.Client.Nom != null) { nomClient = group.Client.Prenom + " " + group.Client.Nom; } foreach (var article in group.Articles) { nombreArticles++; montant += article.Produit.PrixDemande.Value * article.Article.NbItems.Value; datePanier = article.Article.DateCreation.Value.Date; } Panel pnCard = panelPanier.DivDyn("", "card mb-3"); Panel pnHeader = pnCard.DivDyn("", "card-header fake-button"); pnHeader.LblDyn("", "(" + noClient + ") ", "card-title h5 text-info"); pnHeader.LblDyn("", nomClient, "card-title h5 text-info"); pnHeader.LblDyn("", "valeur de " + montant.ToString("N2") + " $", "ml-3 card-title h6"); pnHeader.LblDyn("", "Articles (" + nombreArticles.ToString() + ")", "ml-3 card-title h6"); pnHeader.LblDyn("", datePanier.ToString("yyyy/MM/dd"), "ml-3 card-title h6 text-success"); pnHeader.Attributes.Add("data-toggle", "collapse"); pnHeader.Attributes.Add("data-target", "#Contenu_ContenuPrincipal_collapsePanierBas" + index.ToString()); pnHeader.Attributes.Add("aria-expanded", "false"); pnHeader.Attributes.Add("aria-controls", "Contenu_ContenuPrincipal_collapsePanierBas" + index.ToString()); Panel collapsable = pnCard.DivDyn("collapsePanierBas" + index.ToString(), "collapse collapse"); Panel panelBodyCat = collapsable.DivDyn("", "card-body"); //prix Panel rowTotal = panelBodyCat.DivDyn("", "row ml-3"); rowTotal.LblDyn("", "total de ce panier : ", "h4 mb-3"); rowTotal.LblDyn("", montant.ToString("N2") + " $", "h4 text-success mb-3 ml-2"); Table table = panelBodyCat.TableDyn("", "table table-hover fake-button"); TableHeaderRow rowTable = table.ThrDyn(); rowTable.ThdDyn(""); rowTable.ThdDyn("Produit"); TableHeaderCell headerCss = rowTable.ThdDyn("Prix unitaire"); headerCss.CssClass = "moneyDroite"; headerCss = rowTable.ThdDyn("Poids unitaire"); headerCss.CssClass = "moneyDroite"; headerCss = rowTable.ThdDyn("Qte."); headerCss.CssClass = "text-center"; headerCss = rowTable.ThdDyn("Prix total (sans rabais)"); headerCss.CssClass = "moneyDroite"; /* for (int j = 0; j < 5; j++) * {*/ foreach (var article in group.Articles) { string lblRabais = ""; string nomArticle = article.Produit.Nom; decimal montantArticle = -1; if (article.Produit.PrixVente != article.Produit.PrixDemande && article.Produit.DateVente >= DateTime.Today) { decimal montantRabais = article.Produit.PrixDemande.Value - article.Produit.PrixVente.Value; lblRabais = "<br/>rabais! (" + montantRabais.ToString("N2") + "$) finit le " + article.Produit.DateVente.Value.ToString("yyyy-MM-dd"); montantArticle = article.Produit.PrixDemande.Value; } else { montantArticle = article.Produit.PrixDemande.Value; } decimal poidsArticle = article.Produit.Poids.Value; short nbItems = article.Article.NbItems.Value; decimal prix = article.Produit.PrixDemande.Value * article.Article.NbItems.Value; TableRow nRow = table.TrDyn(); nRow.Attributes.Add("OnClick", "ouvrirDetailProduit('" + article.Produit.NoProduit.ToString() + "');"); TableCell cell1 = nRow.TdDyn("", ""); cell1.ImgDyn("", "~/Pictures/" + article.Produit.Photo, "imgResize"); TableCell cell2 = nRow.TdDyn("", ""); cell2.LblDyn("", nomArticle, ""); TableCell cell3 = nRow.TdDyn("", "moneyDroite"); cell3.LblDyn("", montantArticle.ToString("N2") + " $ ", ""); cell3.LblDyn("", lblRabais, "text-success"); TableCell cell4 = nRow.TdDyn("", "moneyDroite"); cell4.LblDyn("", poidsArticle.ToString("N2") + " Lbs", ""); TableCell cell5 = nRow.TdDyn("", "text-center"); cell5.LblDyn("", "(" + nbItems.ToString() + ")", ""); TableCell cell6 = nRow.TdDyn("", "moneyDroite"); cell6.LblDyn("", prix.ToString("N2") + " $", "text-success"); } Panel rowBtnSupprimer = collapsable.DivDyn("", "row ml-3 mr-3 mb-3"); Button btnClient = rowBtnSupprimer.BtnDyn("btnCourriel" + index.ToString(), "Courriel", btnCourriel_Click, "btn btn-outline-dark btn-block"); btnClient.CommandArgument = (group.NoClient).ToString(); index++; } } else { panelPanier.LblDyn("", "Vous n'avez aucun panier présentement", "h4 text-info"); } panelNBVisite.LblDyn("", "Vous êtes présentement à ", "h5"); //requete trouver nbVisites int visites = 0; PPVendeursClients clientsVendeur = new PPVendeursClients(); VendeurClient client2 = clientsVendeur.Values.Find(x => x.NoVendeur == vendeur.NoVendeur); foreach (VendeurClient vc in clientsVendeur.Values) { if (vc.NoVendeur == vendeur.NoVendeur) { visites++; } } panelNBVisite.LblDyn("", visites.ToString(), "text-primary h4"); panelNBVisite.LblDyn("", " visites de clients", "h5"); nombreClientParVendeur(); //ajouter les stats ici }
protected void Page_Load(object sender, EventArgs e) { if (!Session.IsVendeur()) { Response.Redirect(SessionManager.RedirectConnexionLink); } if (!IsPostBack) { ddlChoix.Items.Add(new ListItem("1 mois", "1")); ddlChoix.Items.Add(new ListItem("2 mois", "2")); ddlChoix.Items.Add(new ListItem("3 mois", "3")); ddlChoix.Items.Add(new ListItem("6 mois", "6")); ddlChoix.SelectedValue = "6"; } //for pour remplir les paniers vendeur = Session.GetVendeur(); PPArticlesEnPanier articlesEnPanier = new PPArticlesEnPanier(); PPProduits produits = new PPProduits(); PPClients clients = new PPClients(); int nbMois = int.Parse(ddlChoix.SelectedValue); DateTime min = DateTime.Today.AddMonths(-1 * nbMois); var yes = from article in articlesEnPanier.Values //join vendeur in vendeurs.Values on article.NoVendeur equals vendeur.NoVendeur join produit in produits.Values on article.NoProduit equals produit.NoProduit where article.NoVendeur == vendeur.NoVendeur // && article.DateCreation.Value.Date > min orderby article.DateCreation ascending select new { Article = article, Produit = produit }; var grouped = from article in yes group article by article.Article.NoClient into g join client in clients.Values on g.Key equals client.NoClient select new { NoClient = g.Key, Client = client, Articles = g.ToList() }; int index = 0; int index2 = 0; Panel rows = null; /* if (grouped.Count() == 0) * { * rows = pnHaut.DivDyn("", "row mb-3"); * rows.DivDyn("", "col-2"); * Panel pnCol = rows.DivDyn("", ""); * pnCol.LblDyn("lblVide", "Vous n'avez aucun panier pour cette période de temps : " + ddlChoix.SelectedItem, "h4 text-info"); * } * else { */ bool auMoinsUNPanier = false; foreach (var group in grouped) { bool dateChecker = false; foreach (var ap in group.Articles) { if (ap.Article.DateCreation.Value.Date >= min) { dateChecker = true; auMoinsUNPanier = true; } } if (dateChecker) { string nomClient = "Annonyme"; string noClient = group.Client.NoClient.ToString(); decimal montant = 0; int nombreArticles = 0; DateTime datePanier = DateTime.Now; if (group.Client.Prenom != null && group.Client.Nom != null) { nomClient = group.Client.Prenom + " " + group.Client.Nom; } foreach (var article in group.Articles) { nombreArticles++; montant += article.Produit.PrixDemande.Value * article.Article.NbItems.Value; datePanier = article.Article.DateCreation.Value.Date; } rows = pnHaut.DivDyn("", "row mb-3"); /* if (index % 2 == 0) * { * rows = pnHaut.DivDyn("", "row mb-3"); * index2++; * }*/ //header des categories Panel panelCard = rows.DivDyn("", "col-12"); Panel card = panelCard.DivDyn("", "card"); Panel panelTitreCategories = card.DivDyn("", "card-header fake-button"); panelTitreCategories.LblDyn("", nomClient, "card-title h5 text-info"); panelTitreCategories.LblDyn("", "valeur de " + montant.ToString("N2") + " $", "ml-3 card-title h6"); panelTitreCategories.LblDyn("", "Articles (" + nombreArticles.ToString() + ")", "ml-3 card-title h6"); panelTitreCategories.LblDyn("", datePanier.ToString("yyyy/MM/dd"), "ml-3 card-title h6 text-success"); //Assigner les options de collapse au header panelTitreCategories.Attributes.Add("data-toggle", "collapse"); panelTitreCategories.Attributes.Add("data-target", "#Contenu_ContenuPrincipal_collapsePanier" + index.ToString() + index2.ToString()); panelTitreCategories.Attributes.Add("aria-expanded", "false"); panelTitreCategories.Attributes.Add("aria-controls", "Contenu_ContenuPrincipal_collapsePanier" + index.ToString() + index2.ToString()); Panel collapsable; //body des categories collapsable = card.DivDyn("collapsePanier" + index.ToString() + index2.ToString(), "collapse collapse"); Panel panelBodyCat = collapsable.DivDyn("", "card-body"); //prix total Panel rowTotal = panelBodyCat.DivDyn("", "row ml-3"); rowTotal.LblDyn("", "total de ce panier : ", "h4 mb-3"); rowTotal.LblDyn("", montant.ToString("N2") + " $", "h4 text-success mb-3 ml-2"); //colones header Table table = panelBodyCat.TableDyn("", "table table-hover fake-button"); TableHeaderRow rowTable = table.ThrDyn(); TableHeaderCell CellCss = rowTable.ThdDyn(""); rowTable.ThdDyn("Produit"); CellCss = rowTable.ThdDyn("Prix unitaire"); CellCss.CssClass = "text-right"; CellCss = rowTable.ThdDyn("Poids unitaire"); CellCss.CssClass = "text-right"; CellCss = rowTable.ThdDyn("Qte"); CellCss.CssClass = "text-center"; CellCss = rowTable.ThdDyn("Prix total (sans rabais)"); CellCss.CssClass = "text-right"; foreach (var article in group.Articles) { //contenu des collapse string nomArticle = article.Produit.Nom; string lblRabais = ""; decimal montantArticle = -1; if (article.Produit.PrixVente != article.Produit.PrixDemande && article.Produit.DateVente >= DateTime.Today) { decimal montantRabais = article.Produit.PrixDemande.Value - article.Produit.PrixVente.Value; lblRabais = "rabais! (" + montantRabais.ToString("N2") + "$) finit le " + article.Produit.DateVente.Value.ToString("yyyy-MM-dd"); montantArticle = article.Produit.PrixDemande.Value; } else { montantArticle = article.Produit.PrixDemande.Value; } decimal poidsArticle = article.Produit.Poids.Value; short nbItems = article.Article.NbItems.Value; decimal prix = article.Produit.PrixDemande.Value * article.Article.NbItems.Value; TableRow nRow = table.TrDyn(); nRow.Attributes.Add("OnClick", "ouvrirDetailProduit('" + article.Produit.NoProduit.ToString() + "');"); TableCell cell1 = nRow.TdDyn("", ""); cell1.ImgDyn("", "~/Pictures/" + article.Produit.Photo, "imgResize"); TableCell cell2 = nRow.TdDyn(); cell2.LblDyn("", nomArticle, ""); TableCell cell3 = nRow.TdDyn("", "text-right"); cell3.LblDyn("", montantArticle.ToString("N2") + " $ ", ""); cell3.BrDyn(); cell3.LblDyn("", lblRabais, "text-success"); TableCell cell4 = nRow.TdDyn("", "text-right"); cell4.LblDyn("", poidsArticle.ToString("N2") + " Lbs", ""); TableCell cell5 = nRow.TdDyn("", "text-center"); cell5.LblDyn("", "(" + nbItems.ToString() + ")", ""); TableCell cell6 = nRow.TdDyn("", "text-right"); cell6.LblDyn("", prix.ToString("N2") + " $", "text-success"); } Panel rowBtnSupprimer = collapsable.DivDyn("", "row ml-3 mr-3 mb-3"); Button btnClient = rowBtnSupprimer.BtnDyn("btn" + group.NoClient, "Courriel", btnCourriel_Click, "btn btn-outline-dark btn-block"); btnClient.CommandArgument = (group.NoClient).ToString(); } index++; } if (!auMoinsUNPanier) { rows = pnHaut.DivDyn("", "row mb-3"); rows.DivDyn("", "col-2"); Panel pnCol = rows.DivDyn("", ""); pnCol.LblDyn("lblVide", "Vous n'avez aucun panier pour cette période de temps : " + ddlChoix.SelectedItem, "h4 text-info"); } // } //paniers du bas PPArticlesEnPanier articlesEnPanier2 = new PPArticlesEnPanier(); PPProduits produits2 = new PPProduits(); PPClients clients2 = new PPClients(); rows = null; min = DateTime.Today.AddMonths(-6); var yes2 = from article in articlesEnPanier2.Values //join vendeur in vendeurs.Values on article.NoVendeur equals vendeur.NoVendeur join produit in produits2.Values on article.NoProduit equals produit.NoProduit where article.NoVendeur == vendeur.NoVendeur //&& article.DateCreation.Value.Date < min // Mettre la variable pour gérer les mois orderby article.DateCreation ascending select new { Article = article, Produit = produit }; var groupedBas = from article in yes2 group article by article.Article.NoClient into g join client in clients2.Values on g.Key equals client.NoClient select new { NoClient = g.Key, Client = client, Articles = g.ToList() }; index = 0; index2 = 0; bool auMoinsUNPanierH = false; if (groupedBas.Count() <= 0) { auMoinsUNPanierH = true; } foreach (var group in groupedBas) { bool dateChecker = false; foreach (var ap in group.Articles) { if (ap.Article.DateCreation.Value.Date > min) { dateChecker = true; } } if (!dateChecker) { auMoinsUNPanierH = true; string nomClient = "Annonyme"; string noClient = group.Client.NoClient.ToString(); decimal montant = 0; int nombreArticles = 0; DateTime datePanier = DateTime.Now; if (group.Client.Prenom != null && group.Client.Nom != null) { nomClient = group.Client.Prenom + " " + group.Client.Nom; } foreach (var article in group.Articles) { nombreArticles++; montant += article.Produit.PrixDemande.Value * article.Article.NbItems.Value; datePanier = article.Article.DateCreation.Value.Date; } rows = panelVieux.DivDyn("", "row mb-3"); /* if (index % 2 == 0) * { * rows = panelVieux.DivDyn("", "row mb-3"); * index2++; * }*/ //header des categories Panel panelCard = rows.DivDyn("", "col-12"); Panel card = panelCard.DivDyn("", "card"); Panel panelTitreCategories = card.DivDyn("", "card-header fake-button"); panelTitreCategories.LblDyn("", nomClient, "card-title h5 text-info"); panelTitreCategories.LblDyn("", "valeur de " + montant.ToString("N2") + " $", "ml-3 card-title h6"); panelTitreCategories.LblDyn("", "Articles (" + nombreArticles.ToString() + ")", "ml-3 card-title h6"); panelTitreCategories.LblDyn("", datePanier.ToString("yyyy/MM/dd"), "ml-3 card-title h6 text-danger"); //Assigner les options de collapse au header panelTitreCategories.Attributes.Add("data-toggle", "collapse"); panelTitreCategories.Attributes.Add("data-target", "#Contenu_ContenuPrincipal_collapsePanierBas" + index.ToString() + index2.ToString()); panelTitreCategories.Attributes.Add("aria-expanded", "false"); panelTitreCategories.Attributes.Add("aria-controls", "Contenu_ContenuPrincipal_collapsePanierBas" + index.ToString() + index2.ToString()); Panel collapsable; //body des categories collapsable = card.DivDyn("collapsePanierBas" + index.ToString() + index2.ToString(), "collapse collapse"); Panel panelBodyCat = collapsable.DivDyn("", "card-body"); //prix total Panel rowTotal = panelBodyCat.DivDyn("", "row ml-3"); rowTotal.LblDyn("", "total de ce panier : ", "h4 mb-3"); rowTotal.LblDyn("", montant.ToString("N2") + " $", "h4 text-success mb-3 ml-2"); //colones header Table table = panelBodyCat.TableDyn("", "table table-hover fake-button"); TableHeaderRow rowTable = table.ThrDyn(); TableHeaderCell CellCss = rowTable.ThdDyn(""); rowTable.ThdDyn("Produit"); CellCss = rowTable.ThdDyn("Prix unitaire"); CellCss.CssClass = "text-right"; CellCss = rowTable.ThdDyn("Poids unitaire"); CellCss.CssClass = "text-right"; CellCss = rowTable.ThdDyn("Qte"); CellCss.CssClass = "text-center"; CellCss = rowTable.ThdDyn("Prix total (sans rabais)"); CellCss.CssClass = "text-right"; foreach (var article in group.Articles) { //contenu des collapse string nomArticle = article.Produit.Nom; string lblRabais = ""; decimal montantArticle = -1; if (article.Produit.PrixVente != article.Produit.PrixDemande && article.Produit.DateVente >= DateTime.Today) { decimal montantRabais = article.Produit.PrixDemande.Value - article.Produit.PrixVente.Value; lblRabais = "rabais! (" + montantRabais.ToString("N2") + "$) finit le" + article.Produit.DateVente.Value.ToString("yyyy-MM-dd"); montantArticle = article.Produit.PrixDemande.Value; } else { montantArticle = article.Produit.PrixDemande.Value; } decimal poidsArticle = article.Produit.Poids.Value; short nbItems = article.Article.NbItems.Value; decimal prix = article.Produit.PrixDemande.Value * article.Article.NbItems.Value; TableRow nRow = table.TrDyn(); nRow.Attributes.Add("OnClick", "ouvrirDetailProduit('" + article.Produit.NoProduit.ToString() + "');"); TableCell cell1 = nRow.TdDyn("", ""); cell1.ImgDyn("", "~/Pictures/" + article.Produit.Photo, "imgResize"); TableCell cell2 = nRow.TdDyn(); cell2.LblDyn("", nomArticle, "h6"); TableCell cell3 = nRow.TdDyn("", "text-right"); cell3.LblDyn("", montantArticle.ToString("N2") + " $ ", ""); cell3.BrDyn(); cell3.LblDyn("", lblRabais, "text-success"); TableCell cell4 = nRow.TdDyn("", "text-right"); cell4.LblDyn("", poidsArticle.ToString("N2") + " Lbs", ""); TableCell cell5 = nRow.TdDyn("", "text-center"); cell5.LblDyn("", "(" + nbItems.ToString() + ")", ""); TableCell cell6 = nRow.TdDyn("", "text-right"); cell6.LblDyn("", prix.ToString("N2") + " $", "text-success"); } Panel rowBtnSupprimer = collapsable.DivDyn("", "row ml-3 mr-3 mb-3"); Button btnClient = rowBtnSupprimer.BtnDyn("", "Courriel", btnCourriel_Click, "btn btn-outline-dark col-5"); btnClient.CommandArgument = group.NoClient.ToString(); rowBtnSupprimer.DivDyn("", "col-2"); Button btn = rowBtnSupprimer.BtnDyn("", "Supprimer", null, "btn btn-outline-danger col-5"); btn.OnClientClick = "return false;"; btn.Attributes.Add("data-toggle", "modal"); btn.Attributes.Add("data-target", "#Contenu_ContenuPrincipal_myModal" + index.ToString() + index2.ToString()); modal(panelAvecModal, "myModal" + index.ToString() + index2.ToString(), group.NoClient.ToString(), "idBtnAnnuler" + index.ToString() + index2.ToString(), "Supression", "Voulez vous supprimer ce panier", true); } index++; } if (!auMoinsUNPanierH) { panelVieux.LblDyn("", "Vous n'avez aucun panier vieux de plus de 6 mois", "text-info h4"); } /* } * else * { * panelVieux.LblDyn("", "Vous n'avez aucun panier vieux de plus de 6 mois", "text-info h4"); * }*/ }
public HttpStatusCodeResult AjouterProduitAuPanier(int NoProduit, short Quantite) { var requeteProduit = from unProduit in context.PPProduits where unProduit.NoProduit == NoProduit select unProduit; if (!requeteProduit.Any()) { return(new HttpStatusCodeResult(HttpStatusCode.Gone)); } if (Quantite > requeteProduit.FirstOrDefault().NombreItems) { return(new HttpStatusCodeResult(HttpStatusCode.Conflict)); } var articlePresent = from a in context.PPArticlesEnPaniers where a.NoClient == NOCLIENT && a.PPProduit.NoProduit == NoProduit select a; if (articlePresent.Any()) { var art = articlePresent.FirstOrDefault(); if (art.NbItems + Quantite > requeteProduit.FirstOrDefault().NombreItems) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } art.NbItems += Quantite; } else { var noVendeur = (int)requeteProduit.First().NoVendeur; var dateCreation = DateTime.Now; var nbItems = Quantite; var noPanier = (from unPanier in context.PPArticlesEnPaniers select unPanier.NoPanier).Max() + 1; var article = new PPArticlesEnPanier { NoPanier = noPanier, NoClient = NOCLIENT, NoVendeur = noVendeur, DateCreation = dateCreation, NbItems = nbItems, NoProduit = NoProduit }; context.PPArticlesEnPaniers.InsertOnSubmit(article); } try { context.SubmitChanges(); } catch (Exception e) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
private void btnAjouter_click(object sender, EventArgs e) { Button btnAjout = (Button)sender; long noProduit = long.Parse(btnAjout.ID.Replace("btnAjouter_", "")); TextBox tb = (TextBox)colQuantite.FindControl("quantite_" + noProduit); short nbItems = short.Parse(tb.Text.Trim()); PPArticlesEnPanier nouvelArticle = new PPArticlesEnPanier(); System.Diagnostics.Debug.WriteLine(" NO CLIENT " + noClient + " noVendeur " + noVendeur + " noProduit " + noProduit); List <PPArticlesEnPanier> articleExistants = dbContext.PPArticlesEnPanier.Where(c => (c.NoClient == noClient) && (c.NoVendeur == noVendeur) && (c.NoProduit == noProduit)).ToList(); if (dbContext.PPProduits.Where(c => c.NoProduit == noProduit).Any()) { if (nbItems > dbContext.PPProduits.Where(c => c.NoProduit == noProduit).First().NombreItems.Value) { nbItems = dbContext.PPProduits.Where(c => c.NoProduit == noProduit).First().NombreItems.Value; TextBox tbQuantite = (TextBox)colQuantite.FindControl("quantite_" + noProduit); tbQuantite.Text = nbItems.ToString(); } } DateTime dateNow = DateTime.Now.Date; List <PPVendeursClients> nouvelVisite = dbContext.PPVendeursClients.Where(c => (c.NoClient == noClient) && (c.NoVendeur == noVendeur) && (c.DateVisite >= dateNow)).ToList(); PPVendeursClients modVisite = new PPVendeursClients(); if (!nouvelVisite.Any()) { modVisite.NoClient = noClient; modVisite.NoVendeur = noVendeur; modVisite.DateVisite = DateTime.Now; dbContext.PPVendeursClients.Add(modVisite); } if (articleExistants.Count > 0) { PPArticlesEnPanier articleExistant = articleExistants.First(); articleExistant.DateCreation = DateTime.Now; articleExistant.NbItems = nbItems; } else { nouvelArticle.NoPanier = dbContext.PPArticlesEnPanier.Max(c => c.NoPanier) + 1; nouvelArticle.NoClient = noClient; nouvelArticle.NoVendeur = noVendeur; nouvelArticle.NoProduit = noProduit; nouvelArticle.DateCreation = DateTime.Now; nouvelArticle.NbItems = nbItems; dbContext.PPArticlesEnPanier.Add(nouvelArticle); } try { dbContext.SaveChanges(); Label lblEnPanier = (Label)colAjout.FindControl(nomEntreprise + "_nbEnPanier_" + noProduit); short nbProduitEnPanier = 0; if (dbContext.PPArticlesEnPanier.Where(c => (c.NoClient.Value.Equals(noClient)) && (c.NoVendeur.Value.Equals(noVendeur)) && (c.NoProduit.Value.Equals(noProduit))).Any()) { nbProduitEnPanier = dbContext.PPArticlesEnPanier.Where(c => (c.NoClient.Value.Equals(noClient)) && (c.NoVendeur.Value.Equals(noVendeur)) && (c.NoProduit.Value.Equals(noProduit))).First().NbItems.Value; } lblEnPanier.Text = "(" + nbProduitEnPanier + ")"; Panel row = LibrairieControlesDynamique.divDYN(messageAction, nomEntreprise + "_rowPanierVide", "row marginFluid text-center"); Panel message = LibrairieControlesDynamique.divDYN(row, nomEntreprise + "_messagePanierVide", "message text-center top15"); Panel messageContainer = LibrairieControlesDynamique.divDYN(message, nomEntreprise + "_divMessage", "alert alert-success alert-margins"); string strMessage = "Le produit a été ajouté au panier"; if (nbItems > 1) { strMessage = "Les produits ont été ajoutés au panier"; } LibrairieControlesDynamique.lblDYN(messageContainer, nomEntreprise + "_leMessageLabel", strMessage); } catch (Exception ex) { } }
private void click_supprimer(object sender, EventArgs e) { Button btn = (Button)sender; PPProduits produits = new PPProduits(); Produit aSupprimer = produits.Values.Where(x => x.NoProduit == long.Parse(btn.ID.ToString().Split('s')[1])).ToList().First(); //je peux récupérer l'id a supprimer avec le code ci-haut bool panier = false; bool commande = false; string sortie = aSupprimer.NoProduit.ToString() + " ---> "; PPArticlesEnPanier paniers = new PPArticlesEnPanier(); List <ArticleEnPanier> listePanier = paniers.Values.Where(x => x.NoProduit == aSupprimer.NoProduit).ToList(); if (listePanier.Count() != 0) { //Dans panier panier = true; } PPDetailsCommandes detailsCommandes = new PPDetailsCommandes(); List <DetailsCommandes> listeCommande = detailsCommandes.Values.Where(x => x.NoProduit == aSupprimer.NoProduit).ToList(); if (listeCommande.Count() != 0) { //Dans commande commande = true; } if (!panier && !commande) { //null part //panelTable.LblDyn("", "On peut supprimer le produit"); produits.Remove(aSupprimer); produits.Update(); File.Delete(Server.MapPath("~/Pictures/") + aSupprimer.Photo); Response.Redirect(Request.RawUrl); } else if (panier && !commande) { //panier mais pas commande PPMessages ppM = new PPMessages(); PPDestinataires ppd = new PPDestinataires(); PPVendeurs ppv = new PPVendeurs(); long noM = ppM.NextId(); //@Marc ici on envoie un courriel a tous les clients ayant eu un panier pour le produit int noV = int.Parse(Session.GetVendeur().NoVendeur.ToString()); Vendeur venMess = ppv.Values.Find(v => v.NoVendeur == aSupprimer.NoVendeur); Message m = new Message(null) { NoMsg = (int)noM, DescMsg = $"Un des produits dans votre panier ({aSupprimer.Nom}) de {venMess.NomAffaires} fut supprimé.", objet = "Un des produits dans votre panier fut supprimé.", Lieu = 2, dateEnvoi = DateTime.Now, NoExpediteur = noV }; ppM.Add(m); ppM.Update(); //supprimer les paniers liés a ce produit foreach (ArticleEnPanier article in listePanier) { Destinataire d = new Destinataire(null) { NoDestinataire = (int)article.NoClient, NoMsg = (int)noM, EtatLu = 0, Lieu = 1 }; ppd.Add(d); ppd.Update(); paniers.Remove(article); } paniers.Update(); //supprimer le produit en question produits.Remove(aSupprimer); produits.Update(); File.Delete(Server.MapPath("~/Pictures/") + aSupprimer.Photo); Response.Redirect(Request.RawUrl); //panelTable.LblDyn("", "Retirer des paniers, aviser le vendeur : nb Panier : " + listePanier.Count().ToString()); } else if (!panier && commande) { //a revoir car pas vraiment supprimé... lol //dans commande mais pas panier aSupprimer.Disponibilité = false; aSupprimer.NombreItems = -1; produits.NotifyUpdatedOutside(aSupprimer); produits.Update(); Response.Redirect(Request.RawUrl); //panelTable.LblDyn("", "Reste au catalogue, qte devient 0 et dispo = non"); } else if (panier && commande) { //partout PPMessages ppM = new PPMessages(); PPDestinataires ppd = new PPDestinataires(); PPVendeurs ppv = new PPVendeurs(); long noM = ppM.NextId(); int noV = int.Parse(Session.GetVendeur().NoVendeur.ToString()); Vendeur venMess = ppv.Values.Find(v => v.NoVendeur == aSupprimer.NoVendeur); Message m = new Message(null) { NoMsg = (int)noM, DescMsg = $"Un des produits dans votre panier ({aSupprimer.Nom}) de {venMess.NomAffaires} fut supprimé.", objet = "Un des produits dans votre panier fut supprimé.", Lieu = 2, dateEnvoi = DateTime.Now, NoExpediteur = noV }; ppM.Add(m); ppM.Update(); //supprime les paniers foreach (ArticleEnPanier article in listePanier) { Destinataire d = new Destinataire(null) { NoDestinataire = (int)article.NoClient, NoMsg = (int)noM, EtatLu = 0, Lieu = 1 }; ppd.Add(d); ppd.Update(); paniers.Remove(article); } paniers.Update(); //change le statut a cause des commandes aSupprimer.Disponibilité = false; aSupprimer.NombreItems = -1; produits.NotifyUpdatedOutside(aSupprimer); produits.Update(); //@Marc ici on envoie un courriel a tous les clients ayant eu un panier pour le produit Response.Redirect(Request.RawUrl); //panelTable.LblDyn("", "Retirer panier et Mettre Qte a 0 et dispo = non"); } }