Esempio n. 1
0
    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;
        }
    }
Esempio n. 2
0
    protected void remplirProduits(XNamespace ss, XElement worksheet)
    {
        PPProduits produits = new PPProduits();

        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);
            }
            DateTime?nullableDate = null;
            if (arrayStr.Count() == 14)
            {
                produits.Add(new Produit(null)
                {
                    NoProduit     = Convert.ToInt64(arrayStr[0]),
                    NoVendeur     = Convert.ToInt64(arrayStr[1]),
                    NoCategorie   = Convert.ToInt32(arrayStr[2]),
                    Nom           = arrayStr[3],
                    Description   = arrayStr[4],
                    Photo         = arrayStr[5],
                    PrixDemande   = Convert.ToDecimal(arrayStr[6]),
                    NombreItems   = Convert.ToInt16(arrayStr[7]),
                    Disponibilité = (arrayStr[8] == "1" ? true : false),
                    DateVente     = (arrayStr[9] == "NULL" ? nullableDate : Convert.ToDateTime(arrayStr[9])),
                    PrixVente     = Convert.ToDecimal(arrayStr[10]),
                    Poids         = Convert.ToDecimal(arrayStr[11]),
                    DateCreation  = DateTime.Parse(arrayStr[12]),
                    DateMAJ       = (arrayStr[13] == "NULL" ? nullableDate : Convert.ToDateTime(arrayStr[13])),
                });
            }
        }
    }
Esempio n. 3
0
    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();
    }
Esempio n. 4
0
    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);
    }
    private void btnEnvoyer(object sender, EventArgs e)
    {
        PPClients leClient = new PPClients();

        if (dbContext.PPClients.Where(c => c.NoClient == noClient).Any())
        {
            leClient = dbContext.PPClients.Where(c => c.NoClient == noClient).First();
        }
        PPVendeurs leVendeur = new PPVendeurs();

        if (dbContext.PPVendeurs.Where(c => c.NoVendeur == noVendeur).Any())
        {
            leVendeur = dbContext.PPVendeurs.Where(c => c.NoVendeur == noVendeur).First();
        }
        PPProduits produitAfficher = new PPProduits();

        if (dbContext.PPProduits.Where(c => c.NoProduit == noProduit).Any())
        {
            produitAfficher = dbContext.PPProduits.Where(c => c.NoProduit == noProduit).First();
        }
        MailMessage message = new MailMessage(leVendeur.AdresseEmail, leClient.AdresseEmail);

        message.Subject = noProduit + " : " + produitAfficher.Nom;
        message.Body    = string.Format("Bonjour,\n\n" +
                                        "J'ai quelques questions à propos du produit {0} \n\n" +
                                        "Bonne journée\n" +
                                        "{1}, {2}\n",
                                        noProduit,
                                        leClient.Nom,
                                        leClient.Prenom);

        tbExpediteur.Text   = message.From.ToString();
        tbDestinataire.Text = message.To.ToString();
        tbSujet.Text        = message.Subject;
        tbCorps.Text        = message.Body;
        divCourriel.Visible = !divCourriel.Visible;
    }
    protected void btnSupprimer_Click(object sender, EventArgs e)
    {
        long       noProduit = long.Parse(Request.QueryString["NoProduit"]);
        PPProduits produit   = dbContext.PPProduits.Where(p => p.NoProduit == noProduit).First();

        using (var dbContextTransaction = dbContext.Database.BeginTransaction())
        {
            try
            {
                if (dbContext.PPArticlesEnPanier.Where(a => a.NoProduit == noProduit).Any())
                {
                    dbContext.PPArticlesEnPanier.RemoveRange(dbContext.PPArticlesEnPanier.Where(a => a.NoProduit == noProduit));
                }
                if (dbContext.PPDetailsCommandes.Where(d => d.NoProduit == noProduit).Any())
                {
                    produit.NombreItems   = 0;
                    produit.Disponibilité = null;
                }
                else
                {
                    File.Delete(Server.MapPath("~/static/images/") + produit.Photo);
                    dbContext.PPProduits.Remove(produit);
                }
                dbContext.SaveChanges();
                dbContextTransaction.Commit();
                string url = "~/Pages/SuppressionProduit.aspx?ResultatSuppr=OK";
                Response.Redirect(url, false);
            }
            catch
            {
                dbContextTransaction.Rollback();
                string url = "~/Pages/SuppressionProduit.aspx?ResultatSuppr=PasOk";
                Response.Redirect(url, false);
            }
        }
    }
    protected void btnInscription_Click(object sender, EventArgs e)
    {
        if (validerPage())
        {
            long noVendeur = Convert.ToInt64(Session["NoVendeur"]);
            long nbProduit = 0;
            foreach (PPProduits produit in dbContext.PPProduits.Where(p => p.NoVendeur == noVendeur))
            {
                if (long.Parse(produit.NoProduit.ToString().Substring(2)) > nbProduit)
                {
                    nbProduit = long.Parse(produit.NoProduit.ToString().Substring(2));
                }
            }

            PPProduits nouveauProduit = new PPProduits();
            nouveauProduit.NoProduit     = long.Parse(string.Format("{0}{1:D5}", noVendeur, nbProduit + 1));
            nouveauProduit.NoVendeur     = noVendeur;
            nouveauProduit.NoCategorie   = int.Parse(ddlCategorie.SelectedValue);
            nouveauProduit.Nom           = tbNom.Text;
            nouveauProduit.Description   = tbDescription.Text;
            nouveauProduit.Photo         = imgTeleverse.ImageUrl.Substring(imgTeleverse.ImageUrl.LastIndexOf("/") + 1);
            nouveauProduit.PrixDemande   = decimal.Parse(tbPrixDemande.Text.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator));
            nouveauProduit.NombreItems   = short.Parse(tbNbItems.Text);
            nouveauProduit.Disponibilité = rbDisponibilite.Value == "O" ? true : false;
            if (tbPrixVente.Text == "")
            {
                nouveauProduit.DateVente = null;
                nouveauProduit.PrixVente = null;
            }
            else
            {
                nouveauProduit.DateVente = Convert.ToDateTime(tbDateVente.Text + " 00:00:00");
                nouveauProduit.PrixVente = decimal.Parse(tbPrixVente.Text.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator));
            }
            nouveauProduit.Poids        = decimal.Parse(tbPoids.Text.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator));
            nouveauProduit.DateCreation = DateTime.Now;

            dbContext.PPProduits.Add(nouveauProduit);

            bool binOK = true;

            try
            {
                dbContext.SaveChanges();
            }
            catch (Exception)
            {
                binOK = false;
            }

            if (binOK)
            {
                lblMessage.Text     = "Le produit a été créé.";
                divMessage.CssClass = "alert alert-success alert-margins";
            }
            else
            {
                lblMessage.Text     = "Le produit n'a pas pu être créé. Réessayez ultérieurement.";
                divMessage.CssClass = "alert alert-danger alert-margins";
            }

            foreach (Control controle in Page.Form.Controls)
            {
                if (controle.HasControls())
                {
                    foreach (Control controleEnfant in controle.Controls)
                    {
                        if (controleEnfant is TextBox)
                        {
                            ((TextBox)controleEnfant).Text = "";
                        }
                        else if (controleEnfant is DropDownList)
                        {
                            ((DropDownList)controleEnfant).ClearSelection();
                        }
                        else
                        if (controle is TextBox)
                        {
                            ((TextBox)controle).Text = "";
                        }
                        else if (controle is DropDownList)
                        {
                            ((DropDownList)controle).ClearSelection();
                        }
                    }
                }
            }
            tbNo.Text                    = (nouveauProduit.NoProduit + 1).ToString();
            imgTeleverse.ImageUrl        = "~/static/images/image_placeholder.png";
            btnSelectionnerImage.Visible = true;
            btnChangerImage.Visible      = false;
            tbNbItems.Text               = "";
            initialiserDate();
            btnOui.CssClass       = "btn Orange active";
            btnNon.CssClass       = "btn Orange notActive";
            rbDisponibilite.Value = "O";
            divMessage.Visible    = true;
        }
        else
        {
            afficherErreurs();

            if (rbDisponibilite.Value != "O")
            {
                btnOui.CssClass = "btn Orange notActive";
                btnNon.CssClass = "btn Orange active";
            }
            else
            {
                btnOui.CssClass = "btn Orange active";
                btnNon.CssClass = "btn Orange notActive";
            }
        }
    }
    protected void btnModifier_Click(object sender, EventArgs e)
    {
        if (validerPage())
        {
            long noProduit = long.Parse(Request.QueryString["NoProduit"]);

            PPProduits produit = dbContext.PPProduits.Where(p => p.NoProduit == noProduit).Single();
            produit.NoCategorie   = int.Parse(ddlCategorie.SelectedValue);
            produit.Nom           = tbNom.Text;
            produit.Description   = tbDescription.Text;
            produit.PrixDemande   = decimal.Parse(tbPrixDemande.Text.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator));
            produit.NombreItems   = short.Parse(tbNbItems.Text);
            produit.Disponibilité = rbDisponibilite.Value == "O" ? true : false;
            if (tbPrixVente.Text == "")
            {
                produit.DateVente = null;
                produit.PrixVente = null;
            }
            else
            {
                produit.DateVente = Convert.ToDateTime(tbDateVente.Text + " 00:00:00");
                produit.PrixVente = decimal.Parse(tbPrixVente.Text.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator));
            }
            produit.Poids   = decimal.Parse(tbPoids.Text.Replace(".", System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator));
            produit.DateMAJ = DateTime.Now;

            bool binOK = true;

            try
            {
                dbContext.SaveChanges();
            }
            catch (Exception)
            {
                binOK = false;
            }

            if (binOK)
            {
                Response.Redirect("~/Pages/SuppressionProduit.aspx?ResultatModif=OK");
            }
            else
            {
                Response.Redirect("~/Pages/SuppressionProduit.aspx?ResultatModif=PasOk");
            }
        }
        else
        {
            afficherErreurs();

            if (rbDisponibilite.Value != "O")
            {
                btnOui.CssClass = "btn Orange notActive";
                btnNon.CssClass = "btn Orange active";
            }
            else
            {
                btnOui.CssClass = "btn Orange active";
                btnNon.CssClass = "btn Orange notActive";
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        string url = null;

        if (Session["TypeUtilisateur"] == null)
        {
            url = "~/Pages/AccueilInternaute.aspx?";
        }
        else if (Session["TypeUtilisateur"].ToString() != "V")
        {
            if (Session["TypeUtilisateur"].ToString() == "C")
            {
                url = "~/Pages/AccueilClient.aspx?";
            }
            else
            {
                url = "~/Pages/AcceuilGestionnaire.aspx?";
            }
        }
        if (url != null)
        {
            Response.Redirect(url, true);
        }

        if (!IsPostBack)
        {
            if (Request.UrlReferrer != null)
            {
                ViewState["RefUrl"] = Request.UrlReferrer.ToString();
            }
            chargerListeDeroulante();
            initialiserDate();

            Page.Title = "S'inscrire comme client";

            if (Request.QueryString["Operation"] != null)
            {
                string operation = Request.QueryString["Operation"].ToString();
                if (operation == "Afficher" || operation == "Modifier" || operation == "Supprimer")
                {
                    if (Request.QueryString["NoProduit"] != null)
                    {
                        if (Regex.IsMatch(Request.QueryString["NoProduit"].ToString(), "^\\d{7}$"))
                        {
                            long noProduit = long.Parse(Request.QueryString["NoProduit"]);
                            long noVendeur = Convert.ToInt64(Session["NoVendeur"]);
                            if (dbContext.PPProduits.Where(p => p.NoProduit == noProduit && p.NoVendeur == noVendeur).Any())
                            {
                                PPProduits produit = dbContext.PPProduits.Where(p => p.NoProduit == noProduit).Single();
                                tbNo.Text = produit.NoProduit.ToString();
                                ddlCategorie.SelectedValue = produit.NoCategorie.ToString();
                                tbNom.Text         = produit.Nom;
                                tbPrixDemande.Text = produit.PrixDemande.ToString()
                                                     .Remove(produit.PrixDemande.ToString().IndexOf(System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator) + 3)
                                                     .Replace(System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator, ".");
                                tbDescription.Text  = produit.Description;
                                tbDateCreation.Text = produit.DateCreation.Value.ToShortDateString();
                                tbNbItems.Text      = produit.NombreItems.ToString();
                                if (produit.PrixVente != null)
                                {
                                    tbPrixVente.Text = produit.PrixVente.ToString()
                                                       .Remove(produit.PrixVente.ToString().IndexOf(System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator) + 3)
                                                       .Replace(System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator, ".");
                                    tbDateVente.Text      = produit.DateVente.Value.ToShortDateString();
                                    divDateVente.CssClass = "form-group";
                                }
                                tbPoids.Text = produit.Poids.ToString().Replace(System.Globalization.NumberFormatInfo.CurrentInfo.NumberDecimalSeparator, ".");
                                if (!(bool)produit.Disponibilité)
                                {
                                    btnOui.CssClass = "btn Orange notActive";
                                    btnNon.CssClass = "btn Orange active";
                                }
                                rbDisponibilite.Value = (bool)produit.Disponibilité ? "O" : "N";
                                imgTeleverse.ImageUrl = "~/static/images/" + produit.Photo;

                                if (operation == "Afficher" || operation == "Supprimer")
                                {
                                    ddlCategorie.Enabled         = false;
                                    errCategorie.Visible         = false;
                                    tbNom.Enabled                = false;
                                    errNom.Visible               = false;
                                    tbPrixDemande.Enabled        = false;
                                    errPrixDemande.Visible       = false;
                                    tbDescription.Enabled        = false;
                                    errDescription.Visible       = false;
                                    lblImage.Visible             = true;
                                    fImage.Visible               = false;
                                    errImage.Visible             = false;
                                    btnSelectionnerImage.Visible = false;
                                    btnTeleverserImage.Visible   = false;
                                    tbNbItems.Enabled            = false;
                                    errNbItems.Visible           = false;
                                    if (produit.PrixVente != null)
                                    {
                                        tbPrixVente.Enabled  = false;
                                        errPrixVente.Visible = false;
                                        tbDateVente.Enabled  = false;
                                        errDateVente.Visible = false;
                                    }
                                    else
                                    {
                                        divNbItems.CssClass  = "form-group col-sm-12";
                                        divPrixVente.Visible = false;
                                        divDateVente.Visible = false;
                                    }
                                    tbPoids.Enabled  = false;
                                    errPoids.Visible = false;
                                }

                                lblCategorie.Visible    = true;
                                lblNom.Visible          = true;
                                lblPrixDemande.Visible  = true;
                                lblDescription.Visible  = true;
                                divDateCreation.Visible = true;
                                lblNbItems.Visible      = true;
                                lblPrixVente.Visible    = true;
                                if (produit.PrixVente != null)
                                {
                                    lblDateVente.InnerText = "Date d’expiration du prix de vente";
                                }
                                lblPoids.Visible              = true;
                                lblDisponibilite.Visible      = true;
                                lblDisponibiliteAjout.Visible = false;

                                if (operation == "Afficher")
                                {
                                    Page.Title = produit.Nom;

                                    btnRetour.Visible = true;
                                }
                                else if (operation == "Modifier")
                                {
                                    Page.Title = "Modification produit";

                                    btnChangerImage.Visible = true;
                                    btnModifier.Visible     = true;
                                }
                                else if (operation == "Supprimer")
                                {
                                    Page.Title = "Suppression produit";

                                    if (dbContext.PPArticlesEnPanier.Where(a => a.NoProduit == noProduit).Count() > 0)
                                    {
                                        btnSupprimer.OnClientClick = "if (!confirm('Ce produit a été déposé dans un panier. Voulez-vous vraiment le supprimer?')) { return false; }";
                                    }
                                    else
                                    {
                                        btnSupprimer.OnClientClick = "if (!confirm('Voulez-vous vraiment supprimer ce produit?')) { return false; }";
                                    }
                                    btnSupprimer.Visible = true;
                                }
                            }
                            else
                            {
                                object refUrl = ViewState["RefUrl"];
                                if (refUrl != null)
                                {
                                    Response.Redirect((string)refUrl);
                                }
                                else
                                {
                                    Response.Redirect("~/Pages/SuppressionProduit.aspx?");
                                }
                            }
                        }
                        else
                        {
                            object refUrl = ViewState["RefUrl"];
                            if (refUrl != null)
                            {
                                Response.Redirect((string)refUrl);
                            }
                            else
                            {
                                Response.Redirect("~/Pages/SuppressionProduit.aspx?");
                            }
                        }
                    }
                    else
                    {
                        object refUrl = ViewState["RefUrl"];
                        if (refUrl != null)
                        {
                            Response.Redirect((string)refUrl);
                        }
                        else
                        {
                            Response.Redirect("~/Pages/SuppressionProduit.aspx?");
                        }
                    }
                }
                else
                {
                    object refUrl = ViewState["RefUrl"];
                    if (refUrl != null)
                    {
                        Response.Redirect((string)refUrl);
                    }
                    else
                    {
                        Response.Redirect("~/Pages/SuppressionProduit.aspx?");
                    }
                }
            }
            else
            {
                Page.Title = "Ajout produit";

                long noVendeur = Convert.ToInt64(Session["NoVendeur"]);
                long nbProduit = 0;
                foreach (PPProduits produit in dbContext.PPProduits.Where(p => p.NoVendeur == noVendeur))
                {
                    if (long.Parse(produit.NoProduit.ToString().Substring(2)) > nbProduit)
                    {
                        nbProduit = long.Parse(produit.NoProduit.ToString().Substring(2));
                    }
                }
                tbNo.Text = string.Format("{0}{1:D5}", noVendeur, nbProduit + 1);
                btnSelectionnerImage.Visible = true;
                btnInscription.Visible       = true;
            }
        }
        else
        {
            divMessage.Visible = false;
        }

        if (Request.QueryString["Operation"] == null || (Request.QueryString["Operation"] != null && Request.QueryString["Operation"] == "Modifier"))
        {
            ClientScript.RegisterStartupScript(GetType(), "toggleRbDisponibilite",
                                               "<script>" +
                                               "   $('#radioBtn a').on('click', function () {" +
                                               "      var sel = $(this).data('title');" +
                                               "      var tog = $(this).data('toggle');" +
                                               "      $('#contentBody_' + tog).prop('value', sel);" +
                                               "      $('a[data-toggle=\"' + tog + '\"]').not('[data-title=\"' + sel + '\"]').removeClass('active').addClass('notActive');" +
                                               "      $('a[data-toggle=\"' + tog + '\"][data-title=\"' + sel + '\"]').removeClass('notActive').addClass('active');" +
                                               "   });" +
                                               "</script>");
        }
    }
    protected void btnTeleverserImage_Click(object sender, EventArgs e)
    {
        if ((fImage.PostedFile.ContentType != "image/jpeg" && fImage.PostedFile.ContentType != "image/png") || fImage.PostedFile.ContentLength >= 31457280)
        {
            if (fImage.PostedFile.ContentType != "image/jpeg" && fImage.PostedFile.ContentType != "image/png")
            {
                errImage.Text = "L'image sélectionnée doit être au format jpeg ou png";
            }
            else
            {
                errImage.Text = "L'image sélectionnée doit être inférieure à 30 mo";
            }
            errImage.CssClass = "text-danger";
        }
        else
        {
            errImage.Text     = "";
            errImage.CssClass = "text-danger hidden";

            bool binOK = true;

            if (Request.QueryString["NoProduit"] == null)
            {
                long noVendeur = Convert.ToInt64(Session["NoVendeur"]);
                long nbProduit = 0;
                foreach (PPProduits produit in dbContext.PPProduits.Where(p => p.NoVendeur == noVendeur))
                {
                    if (long.Parse(produit.NoProduit.ToString().Substring(2)) > nbProduit)
                    {
                        nbProduit = long.Parse(produit.NoProduit.ToString().Substring(2));
                    }
                }
                long noProduit = long.Parse(string.Format("{0}{1:D5}", noVendeur, nbProduit + 1));

                try
                {
                    if (File.Exists(Server.MapPath("~/static/images/") + noProduit + ".jpg"))
                    {
                        File.Delete(Server.MapPath("~/static/images/") + noProduit + ".jpg");
                    }
                    else if (File.Exists(Server.MapPath("~/static/images/") + noProduit + ".JPG"))
                    {
                        File.Delete(Server.MapPath("~/static/images/") + noProduit + ".JPG");
                    }
                    else if (File.Exists(Server.MapPath("~/static/images/") + noProduit + ".png"))
                    {
                        File.Delete(Server.MapPath("~/static/images/") + noProduit + ".png");
                    }
                    else if (File.Exists(Server.MapPath("~/static/images/") + noProduit + ".PNG"))
                    {
                        File.Delete(Server.MapPath("~/static/images/") + noProduit + ".PNG");
                    }
                }
                catch
                {
                    errImage.Text     = "L'image sélectionnée n'a pas pu être téléversée.";
                    errImage.CssClass = "text-danger";
                    binOK             = false;
                }

                if (binOK)
                {
                    try
                    {
                        fImage.SaveAs(Server.MapPath("~/static/images/") + noProduit + fImage.FileName.Substring(fImage.FileName.LastIndexOf(".")));
                    }
                    catch (Exception ex)
                    {
                        errImage.Text     = "L'image sélectionnée n'a pas pu être téléversée. L'erreur suivante est survenue : " + ex.Message;
                        errImage.CssClass = "text-danger";
                        binOK             = false;
                    }
                }

                if (binOK)
                {
                    imgTeleverse.ImageUrl        = "~/static/images/" + noProduit + fImage.FileName.Substring(fImage.FileName.LastIndexOf("."));
                    btnSelectionnerImage.Visible = false;
                    btnChangerImage.Visible      = true;
                }
            }
            else
            {
                long       noProduit = long.Parse(Request.QueryString["NoProduit"]);
                PPProduits produit   = dbContext.PPProduits.Where(p => p.NoProduit == noProduit).Single();

                try
                {
                    File.Move(Server.MapPath("~/static/images/") + produit.Photo,
                              Server.MapPath("~/static/images/") + produit.NoProduit + "_old" + produit.Photo.Substring(produit.Photo.IndexOf(".")));
                }
                catch
                {
                    errImage.Text     = "L'image sélectionnée n'a pas pu être téléversée.";
                    errImage.CssClass = "text-danger";
                    binOK             = false;
                }

                if (binOK)
                {
                    try
                    {
                        fImage.SaveAs(Server.MapPath("~/static/images/") + produit.NoProduit + fImage.FileName.Substring(fImage.FileName.LastIndexOf(".")));
                    }
                    catch (Exception ex)
                    {
                        errImage.Text     = "L'image sélectionnée n'a pas pu être téléversée. L'erreur suivante s'est produite : " + ex.Message;
                        errImage.CssClass = "text-danger";
                        binOK             = false;
                    }
                }

                if (binOK)
                {
                    try
                    {
                        File.Delete(Server.MapPath("~/static/images/") + produit.NoProduit + "_old" + produit.Photo.Substring(produit.Photo.IndexOf(".")));
                    }
                    catch { }
                }
                else
                {
                    try
                    {
                        File.Move(Server.MapPath("~/static/images/") + produit.NoProduit + "_old" + produit.Photo.Substring(produit.Photo.IndexOf(".")),
                                  Server.MapPath("~/static/images/") + produit.Photo);
                    }
                    catch
                    {
                        produit.Photo = produit.NoProduit + "_old" + produit.Photo.Substring(produit.Photo.IndexOf("."));

                        imgTeleverse.ImageUrl = "~/static/images/" + produit.NoProduit + "_old" + produit.Photo.Substring(produit.Photo.IndexOf("."));

                        try
                        {
                            dbContext.SaveChanges();
                        }
                        catch { }
                    }
                }

                if (binOK)
                {
                    imgTeleverse.ImageUrl = "~/static/images/" + produit.NoProduit + fImage.FileName.Substring(fImage.FileName.LastIndexOf("."));
                }
            }
        }

        if (rbDisponibilite.Value != "O")
        {
            btnOui.CssClass = "btn Orange notActive";
            btnNon.CssClass = "btn Orange active";
        }
        else
        {
            btnOui.CssClass = "btn Orange active";
            btnNon.CssClass = "btn Orange notActive";
        }
    }
    private void creerPage()
    {
        System.Diagnostics.Debug.WriteLine("PAGE LOAD LE DDL = " + nbMois);

        Panel panelGroup = LibrairieControlesDynamique.divDYN(phDynamique, nomEntreprise + "_PanelGroup2", "panel-group container-fluid marginFluid");
        Panel panelBase  = LibrairieControlesDynamique.divDYN(panelGroup, nomEntreprise + "_base2", "panel panel-default");
        // Nom de l'entreprise
        Panel panelHeader = LibrairieControlesDynamique.divDYN(panelBase, nomEntreprise + "_header2", "panel-heading");

        Panel rowInactif = LibrairieControlesDynamique.divDYN(panelHeader, nomEntreprise + "_rowInactif2_", "row");
        Panel colInactif = LibrairieControlesDynamique.divDYN(rowInactif, nomEntreprise + "_colInactif2_", "col-sm-12");

        LibrairieControlesDynamique.lblDYN(colInactif, nomEntreprise + "_nom2", nomEntreprise + " - " + leVendeur.AdresseEmail, "nom-entreprise");
        panelBody2 = LibrairieControlesDynamique.divDYN(panelBase, nomEntreprise + "_PanelBody2", "panel-body");

        DateTime dateParMois    = DateTime.Now.AddMonths(-nbMois);
        DateTime dateParMoisMax = DateTime.Now.AddMonths(-(nbMois + 1));

        System.Diagnostics.Debug.WriteLine(" LE NBMOIS = " + nbMois + " dateParMois = " + dateParMois + " dateParMoisMAx = " + dateParMoisMax);
        if (nbMois == 7)
        {
            dateParMoisMax = DateTime.MinValue;
        }
        List <PPArticlesEnPanier> lstPaniersEntreprise = new List <PPArticlesEnPanier>();
        List <PPArticlesEnPanier> lstArticles          = dbContext.PPArticlesEnPanier.GroupBy(x => x.NoClient).Select(t => t.OrderBy(c => c.DateCreation).FirstOrDefault()).ToList();

        foreach (PPArticlesEnPanier lesArticles in lstArticles)
        {
            if ((lesArticles.DateCreation <= dateParMois) && (lesArticles.DateCreation >= dateParMoisMax))
            {
                lstPaniersEntreprise.AddRange(dbContext.PPArticlesEnPanier.Where(c => (c.NoVendeur == noVendeur) && (c.NoClient == lesArticles.NoClient)).OrderBy(C => C.DateCreation).ToList());
            }
        }
        panelBody2.Controls.Clear();
        Panel panCategorie   = LibrairieControlesDynamique.divDYN(panelBody2, nomEntreprise + "_pretLivraison2_", "row text-center");
        Panel colCatAfficher = LibrairieControlesDynamique.divDYN(panCategorie, nomEntreprise + "_colLabelPretLivraison2", "col-sm-12");

        LibrairieControlesDynamique.lblDYN(colCatAfficher, nomEntreprise + "_labelCategorie2", "Panier Courants ", "infos-payage OrangeTitle");
        LibrairieControlesDynamique.hrDYN(colCatAfficher, "OrangeBorderPanier", 5);

        // Rajouter les produits dans le panier

        if (lstPaniersEntreprise.Count > 0)
        {
            long ancienID = 0;
            for (int i = 0; i < lstPaniersEntreprise.Count; i++)
            {
                long         idItem      = lstPaniersEntreprise[i].NoPanier;
                long         idProduit   = lstPaniersEntreprise[i].NoProduit.Value;
                PPProduits   leProduit   = dbContext.PPProduits.Where(c => c.NoProduit == idProduit).First();
                PPCategories laCategorie = dbContext.PPCategories.Where(c => c.NoCategorie == leProduit.NoCategorie).First();
                long         idClient    = lstPaniersEntreprise[i].NoClient.Value;
                int          NbVisites   = dbContext.PPVendeursClients.Where(c => (c.NoClient == idClient) && (c.NoVendeur == noVendeur)).Count();
                PPClients    leClient    = dbContext.PPClients.Where(c => c.NoClient == idClient).First();
                decimal      prix        = leProduit.PrixDemande.Value;
                String       nomProduit  = leProduit.Nom.ToString();
                String       urlImage    = "../static/images/" + leProduit.Photo.ToString();


                if (ancienID != lstPaniersEntreprise[i].NoClient.Value)
                {
                    //Trigger panel pour accordeon
                    Panel panelTrigger = LibrairieControlesDynamique.divDYN(panelBody2, nomEntreprise + "_PanelTrigger" + i, "trigger");
                    Panel rowClient    = LibrairieControlesDynamique.divDYN(panelTrigger, nomEntreprise + "_rowTrigger_" + idItem, "row top15 text-center border-left");
                    // Col Glyph
                    Panel colGlyph = LibrairieControlesDynamique.divDYN(rowClient, nomEntreprise + "_colGlyph_" + idItem, "col-sm-2");
                    LibrairieControlesDynamique.lblDYN(colGlyph, nomEntreprise + "_GlyphPanier_" + idItem, "", "glyphicon glyphicon-shopping-cart text-left");
                    //Nom Client
                    Panel  colNomClient = LibrairieControlesDynamique.divDYN(rowClient, nomEntreprise + "_colClient2_" + idItem, "col-sm-2 text-left");
                    string nomClient    = (leClient.Nom != null && leClient.Nom != "") ? "Client : " + leClient.Prenom + " " + leClient.Nom : "Client : " + leClient.AdresseEmail;
                    LibrairieControlesDynamique.lblDYN(colNomClient, nomEntreprise + "_NomClient2_" + idItem, nomClient, "nomClient prix_item");
                    // Nb Visites du client
                    Panel colClientVisites = LibrairieControlesDynamique.divDYN(rowClient, nomEntreprise + "_colVisites_" + idItem, "col-sm-2 text-left");
                    LibrairieControlesDynamique.lblDYN(colClientVisites, nomEntreprise + "_VisiteClient_" + idItem, " Nombre de visites : " + NbVisites, "nomClient prix_item");

                    //Date
                    Panel colDate = LibrairieControlesDynamique.divDYN(rowClient, nomEntreprise + "_colDate_" + idItem, "col-sm-2 text-left");
                    LibrairieControlesDynamique.lblDYN(colDate, nomEntreprise + "_date_" + idItem, "Date de création : " + Convert.ToDateTime(lstPaniersEntreprise[i].DateCreation).ToShortDateString(), "prix_item");

                    //SousTotal du panier
                    decimal sousTotalPanier = 0;
                    for (int j = 0; j < lstPaniersEntreprise.Count; j++)
                    {
                        if (lstPaniersEntreprise[j].NoClient == leClient.NoClient)
                        {
                            long    idItem2         = lstPaniersEntreprise[j].NoProduit.Value;
                            decimal calculSousTotal = (decimal)dbContext.PPProduits.Where(c => c.NoProduit == idItem2).First().PrixDemande;
                            sousTotalPanier += calculSousTotal * lstPaniersEntreprise[j].NbItems.Value;
                        }
                    }
                    Panel colSousTotal = LibrairieControlesDynamique.divDYN(rowClient, nomEntreprise + "_colSousTotalPanier_" + idItem, "col-sm-2 text-center");
                    LibrairieControlesDynamique.lblDYN(colSousTotal, nomEntreprise + "_SousTotalPanier_" + idItem, sousTotalPanier.ToString("C", CultureInfo.CurrentCulture), "nomClient prix_item");

                    if (nbMois == 7)
                    {
                        Panel  colDel       = LibrairieControlesDynamique.divDYN(rowClient, nomEntreprise + "_colDel_", "col-sm-2");
                        Button btnSupprimer = LibrairieControlesDynamique.btnDYN(colDel, "btnSupprimer_" + idClient, "btn btn-danger", "Supprimer", btnSupprimer_click);
                        btnSupprimer.OnClientClick = "if( !PanierDeleteConfirmation()) return false;";
                        //btnSupprimer.Attributes.Add("onClientClick", );
                    }


                    //Panneau Accordeon
                    PanelCollapse = LibrairieControlesDynamique.divDYN(panelBody2, nomEntreprise + "_PanelCollapse" + i, "panel panelAccord");
                }

                Panel rowItem = LibrairieControlesDynamique.divDYN(PanelCollapse, nomEntreprise + "_rowItem2_" + idItem, "row valign top15");

                // ajouter l'image
                Panel colImg = LibrairieControlesDynamique.divDYN(rowItem, nomEntreprise + "_colImg2_" + idItem, "col-sm-2 ");
                LibrairieControlesDynamique.imgDYN(colImg, nomEntreprise + "_img2_" + idItem, urlImage, "img-size center-block");
                LibrairieControlesDynamique.lblDYN(colImg, nomEntreprise + "_noproduit2_" + idItem, idProduit.ToString(), "caption center-block text-center");


                // Nom du produit
                Panel colNom = LibrairieControlesDynamique.divDYN(rowItem, nomEntreprise + "_colNom2_" + idItem, "col-sm-3 LiensProduits nomClient");
                LibrairieControlesDynamique.lbDYN(colNom, nomEntreprise + "_nom2_" + idItem + "-" + idProduit, nomProduit, descriptionProduit);

                // Quantité restant
                Panel colQuantite = LibrairieControlesDynamique.divDYN(rowItem, nomEntreprise + "_colQuantite2_" + idItem, "col-sm-2 text-right");
                LibrairieControlesDynamique.lblDYN(colQuantite, nomEntreprise + "_quantite2_" + idItem, "Qte : " + lstPaniersEntreprise[i].NbItems, "prix_item");

                // Categorie
                Panel colCat = LibrairieControlesDynamique.divDYN(rowItem, nomEntreprise + "_colCategorie_" + idItem, "col-sm-3 text-right");
                LibrairieControlesDynamique.lblDYN(colCat, nomEntreprise + "_categorie2_" + idItem, laCategorie.Description.ToString(), "cat_item");

                // Prix item
                Panel colPrix = LibrairieControlesDynamique.divDYN(rowItem, nomEntreprise + "_colPri2x_" + idItem, "col-sm-2 text-center");
                LibrairieControlesDynamique.lblDYN(colPrix, nomEntreprise + "_prix2_" + idItem, "Prix Unitaire<br>" + prix.ToString("C", CultureInfo.CurrentCulture), "prix_item");



                ancienID = idClient;
            }
            LibrairieControlesDynamique.hrDYN(panelBody2, "OrangeBorderPanier", 5);
        }
        else
        {
            Panel row              = LibrairieControlesDynamique.divDYN(panelBody2, 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-danger alert-margins");
            LibrairieControlesDynamique.lblDYN(messageContainer, nomEntreprise + "_leMessageLabel", "Vous avez aucun panier courant.");
            LibrairieControlesDynamique.hrDYN(panelBody2, "OrangeBorderPanier", 5);
        }
    }
    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;
        }
    }
Esempio n. 13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Session.IsClient())
        {
            Response.Redirect(SessionManager.RedirectConnexionLink);
        }
        if (!IsPostBack)
        {
            var url = Request.UrlReferrer;
            if (url != null)
            {
                ViewState["PreviousPageUrl"] = url.ToString();
            }
        }
        long produitARG;

        // se faire passer la valeur du produit par ce tag [ID] i.e : ?ID=noProduit
        if (long.TryParse(Request.QueryString["ID"], out produitARG))
        {
            //long produitARG = 1200001;
            PPProduits produits   = new PPProduits();
            Produit    monProduit = new Produit(null);
            foreach (Produit prod in produits.Values.Where(x => x.NoProduit == (long?)produitARG))
            {
                monProduit = produits.Values.Where(x => x.NoProduit == (long?)produitARG).ToList().First();
            }

            if (monProduit.NoProduit != null)
            {
                panelImage.Visible = true;
                Image img = panelImage.ImgDyn("", "~/Pictures/" + monProduit.Photo, "img-fluid");


                Table     table   = panelDetails.TableDyn("", "table table-striped");
                TableRow  rowDet  = table.TrDyn();
                TableCell colDet1 = rowDet.TdDyn();
                TableCell colDet2 = rowDet.TdDyn();

                //nom
                colDet1.LblDyn("", "Nom du produit", "text-info h3");
                colDet2.LblDyn("", monProduit.Nom, "h3 text-success");

                PPCategories categos = new PPCategories();
                Categorie    categ   = new Categorie(null);
                foreach (Categorie cat in categos.Values.Where(x => x.NoCategorie == monProduit.NoCategorie))
                {
                    categ = cat;
                }
                if (categ.NoCategorie != null)
                {
                    //Catégorie
                    rowDet  = table.TrDyn();
                    colDet1 = rowDet.TdDyn();
                    colDet2 = rowDet.TdDyn();

                    colDet1.LblDyn("", "Catégorie", "text-info h5");
                    colDet2.LblDyn("", categ.Description, "h5");

                    //Description
                    rowDet  = table.TrDyn();
                    colDet1 = rowDet.TdDyn();
                    colDet2 = rowDet.TdDyn();

                    colDet1.LblDyn("", "Description du produit", "text-info h5");
                    colDet2.LblDyn("", monProduit.Description, "h5");

                    //Prix demandé
                    rowDet  = table.TrDyn();
                    colDet1 = rowDet.TdDyn();
                    colDet2 = rowDet.TdDyn();

                    colDet1.LblDyn("", "Prix demandé", "text-info h5");
                    colDet2.LblDyn("", monProduit.PrixDemande.Value.ToString("N2") + " $", "h5");

                    //Prix Vente
                    rowDet  = table.TrDyn();
                    colDet1 = rowDet.TdDyn();
                    colDet2 = rowDet.TdDyn();

                    colDet1.LblDyn("", "Prix de vente", "text-info h5");
                    if (monProduit.PrixVente.Value != monProduit.PrixDemande.Value)
                    {
                        colDet2.LblDyn("", monProduit.PrixVente.Value.ToString("N2") + " $", "h5");
                    }
                    else
                    {
                        colDet2.LblDyn("", "Pas en vente", "h5");
                    }

                    //qte
                    rowDet  = table.TrDyn();
                    colDet1 = rowDet.TdDyn();
                    colDet2 = rowDet.TdDyn();

                    colDet1.LblDyn("", "Quantité disponible", "text-info h5");
                    if (monProduit.NombreItems == 0)
                    {
                        colDet2.LblDyn("", "Aucun article disponible", "h5");
                    }
                    else
                    {
                        colDet2.LblDyn("", monProduit.NombreItems.ToString(), "h5");
                    }


                    //Poids
                    rowDet  = table.TrDyn();
                    colDet1 = rowDet.TdDyn();
                    colDet2 = rowDet.TdDyn();

                    colDet1.LblDyn("", "Poids du produit", "text-info h5");
                    colDet2.LblDyn("", monProduit.Poids.Value.ToString("N2") + " Lbs", "h5");

                    //Date de vente
                    rowDet  = table.TrDyn();
                    colDet1 = rowDet.TdDyn();
                    colDet2 = rowDet.TdDyn();

                    string dateVente = "indéfénie";
                    if (monProduit.DateVente.HasValue)
                    {
                        dateVente = monProduit.DateVente.Value.ToString("yyyy/MM/dd");
                    }

                    colDet1.LblDyn("", "Fin de la vente", "text-info h5");
                    colDet2.LblDyn("", dateVente, "h5");

                    if (monProduit.NombreItems != 0)
                    {
                        rowDet = table.TrDyn();

                        colDet1 = rowDet.TdDyn();
                        colDet1.LblDyn("", "Quantité à commander: ", "text-info h5");
                        colDet2 = rowDet.TdDyn();
                        DropDownList ddl = new DropDownList();
                        for (int i = 0; i < monProduit.NombreItems.Value; i++)
                        {
                            ddl.Items.Add((i + 1).ToString());
                        }
                        ddl.SelectedIndex = 0;
                        ddl.CssClass      = "form-control w-25 d-inline align-middle mr-3";
                        colDet2.Controls.Add(ddl);
                        TableCell colDet3 = rowDet.TdDyn();
                        Button    btn     = colDet2.BtnClientDyn("", "Ajouter au panier", $"ajouterArticle({Session.GetClient().NoClient},{monProduit.NoProduit},'{ddl.ClientID}');return false;", "btn btn-success d-inline");
                    }
                    panelDetails.BtnDyn("", "Retour", retour, "btn  btn-outline-dark classBoutonsMargins100");


                    Button btnContactV = panelDetails.BtnDyn("", "Contacter le vendeur", btnCourrielVendeur_Click, "btn btn-secondary classBoutonsMargins100");
                    btnContactV.CommandArgument = monProduit.NoVendeur.ToString();
                    btnContactV.CommandName     = monProduit.Nom;
                }
            }
        }
    }
Esempio n. 14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //section du haut
        Panel pnRow1 = pnInfos.DivDyn("", "row ml-3");

        pnRow1.LblDyn("", "Enregistrez vous comme client pour bénéficier des avantages suivants : ", "h5");

        Panel pnRow2  = pnInfos.DivDyn("", "row");
        Panel vide    = pnRow2.DivDyn("", "col-1");
        Panel colonne = pnRow2.DivDyn("", "col");

        colonne.LblDyn("", "- Avoir accès aux catalogues de produits", "h4 text-info");


        vide    = pnRow2.DivDyn("", "col-1");
        colonne = pnRow2.DivDyn("", "col");
        colonne.LblDyn("", "- Avoir accès aux paniers", "h4 text-info");

        pnRow2  = pnInfos.DivDyn("", "row");
        vide    = pnRow2.DivDyn("", "col-1");
        colonne = pnRow2.DivDyn("", "col");
        colonne.LblDyn("", "- Passer des commandes", "h4 text-info");


        vide    = pnRow2.DivDyn("", "col-1");
        colonne = pnRow2.DivDyn("", "col");
        colonne.LblDyn("", "- Rechercher sur le site", "h4 text-info");

        Panel  pnRowBtn = pnInfos.DivDyn("", "row ml-3 mt-3");
        Button btn      = pnRowBtn.BtnDyn("", "S'inscrire", ouvrirInscription, "btn btn-outline-success classBoutonsMargins100 mr-3");

        //section du bas où il y a 15 articles.

        PPProduits     produits      = new PPProduits();
        List <Produit> nouvelleListe = produits.Values.OrderByDescending(c => c.DateCreation).Where(x => x.Disponibilité == true && x.NombreItems > 0).ToList();

        int   index  = 0;
        int   index2 = 0;
        Panel rows   = null;

        foreach (var produit in nouvelleListe.Take(15))
        {
            if (index % 3 == 0)
            {
                rows = pnNouveautes.DivDyn("", "row mb-3");
                index2++;
            }
            PPVendeurs leVendeur  = new PPVendeurs();
            Vendeur    monVendeur = leVendeur.Values.Where(c => c.NoVendeur == produit.NoVendeur).First();

            Panel           panelCard            = rows.DivDyn("", "col-4");
            Panel           card                 = panelCard.DivDyn("", "card");
            Panel           panelTitreCategories = card.DivDyn("", "card-header fake-button");
            Table           tableT               = panelTitreCategories.TableDyn("", "");
            TableHeaderRow  headerrow            = tableT.ThrDyn();
            TableHeaderCell cellHd               = headerrow.ThdDyn();
            cellHd.LblDyn("", " " + monVendeur.NomAffaires, "card-title h5 text-primary");
            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");

            rowt.Attributes.Add("data-toggle", "modal");
            rowt.Attributes.Add("data-target", "#Contenu_ContenuPrincipal_myModal" + index.ToString());

            headerrow.Attributes.Add("data-toggle", "modal");
            headerrow.Attributes.Add("data-target", "#Contenu_ContenuPrincipal_myModal" + index.ToString());

            modal(panelAvecModal, "myModal" + index.ToString(), "btnOk" + index.ToString(), "btnAnnulerLiv" + index.ToString(), "Inscrivez-vous!", "Inscrivez-Vous pour avoir accèz aux détails!", true);

            index++;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        verifierPermissions("C");

        getNbMois();
        long parseNoClient;

        if (Session["NoClient"] != null && long.TryParse(Session["NoClient"].ToString(), out parseNoClient))
        {
            if (dbContext.PPProduits.Where(c => c.NoProduit.Equals(noProduit)).Any())
            {
                noVendeur = dbContext.PPProduits.Where(c => c.NoProduit.Equals(noProduit)).First().NoVendeur.Value;
            }
            noClient = parseNoClient;
        }
        else
        {
            string url = "~/Pages/Connexion.aspx?";
            Response.Redirect(url);
        }


        if (!IsPostBack)
        {
            if (Request.UrlReferrer != null)
            {
                ViewState["RefUrl"] = Request.UrlReferrer.ToString();
            }
        }
        PPProduits produitAfficher = new PPProduits();

        if (dbContext.PPProduits.Where(c => c.NoProduit == noProduit).Any())
        {
            produitAfficher = dbContext.PPProduits.Where(c => c.NoProduit == noProduit).First();
        }

        Page.Title = produitAfficher.Nom;

        nomEntreprise = dbContext.PPVendeurs.Where(c => c.NoVendeur == produitAfficher.NoVendeur).First().NomAffaires;


        // Créer le panier du vendeur X
        Panel panelBase = LibrairieControlesDynamique.divDYN(phDynamique, nomEntreprise + "_base", "panel panel-default");

        // Nom de l'entreprise
        Panel panelHeader     = LibrairieControlesDynamique.divDYN(panelBase, nomEntreprise + "_header", "panel-heading");
        Panel rowTitreMessage = LibrairieControlesDynamique.divDYN(panelHeader, nomEntreprise + "_rowTitreMessage", "row");
        Panel colLeTitre      = LibrairieControlesDynamique.divDYN(rowTitreMessage, nomEntreprise + "_colTitreUnique_", "col-sm-11");

        LibrairieControlesDynamique.lblDYN(colLeTitre, nomEntreprise + "_nom", nomEntreprise, "nom-entreprise");
        Panel colMessage = LibrairieControlesDynamique.divDYN(rowTitreMessage, nomEntreprise + "_colEnvoieMessage_", "col-sm-1");

        LibrairieControlesDynamique.htmlbtnDYN(colMessage, nomEntreprise + "leIconeMessage", "", "", "glyphicon glyphicon-envelope", btnEnvoyer);

        // Liste des items + le total
        Panel panelBody = LibrairieControlesDynamique.divDYN(panelBase, nomEntreprise + "_body", "panel-body");

        // LibrairieControlesDynamique.hrDYN(panelBody);


        // Rajouter les produits dans le panier

        long idItem = produitAfficher.NoProduit;


        Double prix;

        if (produitAfficher.DateVente > DateTime.Now.Date)
        {
            prix = Convert.ToDouble(produitAfficher.PrixVente);
        }
        else
        {
            prix = Convert.ToDouble(produitAfficher.PrixDemande);
        }

        decimal?montantRabais = produitAfficher.PrixDemande - produitAfficher.PrixVente;

        if (produitAfficher.DateVente < DateTime.Now)
        {
            montantRabais = 0;
        }


        String urlImage = "../static/images/" + produitAfficher.Photo;

        Panel rowItem = LibrairieControlesDynamique.divDYN(panelBody, nomEntreprise + "_rowItem_" + idItem, "row");

        // ajouter l'image
        Panel colImg = LibrairieControlesDynamique.divDYN(rowItem, nomEntreprise + "_colImg_" + idItem, "col-sm-1");

        LibrairieControlesDynamique.imgDYN(colImg, nomEntreprise + "_img_" + idItem, urlImage, "img-size center-block");
        LibrairieControlesDynamique.lblDYN(colImg, nomEntreprise + "_noproduit_" + idItem, idItem.ToString(), "caption center-block text-center");


        // Nom du produit
        Panel colNom = LibrairieControlesDynamique.divDYN(rowItem, nomEntreprise + "_colNom_" + idItem, "col-sm-3 breakWord");

        //LibrairieControlesDynamique.lbDYN(colNom, nomEntreprise + "_nom_" + idItem, nomProduit,null);
        LibrairieControlesDynamique.lblDYN(colNom, nomEntreprise + "_nom_" + idItem, produitAfficher.Nom, "cat_item");

        // Quantité restant
        Panel colQuantite = LibrairieControlesDynamique.divDYN(rowItem, nomEntreprise + "_colQuantiteProduit_" + idItem, "col-sm-1");

        LibrairieControlesDynamique.lblDYN(colQuantite, nomEntreprise + "_quantiteProduit_" + idItem, "Qte : " + produitAfficher.NombreItems, "border-quantite cat_item");

        Panel colPoids = LibrairieControlesDynamique.divDYN(rowItem, nomEntreprise + "_colPoids_" + idItem, "col-sm-1");

        LibrairieControlesDynamique.lblDYN(colPoids, nomEntreprise + "_Poids_" + idItem, produitAfficher.Poids + " lbs", "cat_item");

        // Categorie
        string categorie = dbContext.PPCategories.Where(c => c.NoCategorie == produitAfficher.NoCategorie).First().Description;
        Panel  colCat    = LibrairieControlesDynamique.divDYN(rowItem, nomEntreprise + "_colCategorie_" + idItem, "col-sm-2 breakWord");

        LibrairieControlesDynamique.lblDYN(colCat, nomEntreprise + "_categorie_" + idItem, categorie, "cat_item");

        // Prix item
        Panel colPrix = LibrairieControlesDynamique.divDYN(rowItem, nomEntreprise + "_colPrix_" + idItem, "col-sm-1 text-right");

        LibrairieControlesDynamique.lblDYN(colPrix, nomEntreprise + "_prixDemande_" + idItem, prix.ToString("C", CultureInfo.CurrentCulture), "prix_item");
        LibrairieControlesDynamique.brDYN(colPrix);
        LibrairieControlesDynamique.lblDYN(colPrix, "lblRabais" + idItem, (montantRabais > 0) ? "Rabais de " + Decimal.Round((Decimal)montantRabais, 2).ToString("C", CultureInfo.CurrentCulture) : "", "rabais");



        // Quantité restant
        colQuantite = LibrairieControlesDynamique.divDYN(rowItem, nomEntreprise + "_colQuantite_" + idItem, "col-sm-1 text-center");

        tbQuantite = LibrairieControlesDynamique.numericUpDownDYN(colQuantite, "quantite_" + idItem, (produitAfficher.NombreItems < 1) ? "0" : "1"
                                                                  , (produitAfficher.NombreItems < 1) ? "0" : produitAfficher.NombreItems.ToString(), "numUD form-control border-quantite");
        LibrairieControlesDynamique.lblDYN(colQuantite, nomEntreprise + "_nbQuantiteMax_" + idItem, "<br>Quantité : " + produitAfficher.NombreItems, "");



        colAjout = LibrairieControlesDynamique.divDYN(rowItem, nomEntreprise + "_colAjout_" + idItem, "col-sm-2 text-center");
        Button btnAjout = LibrairieControlesDynamique.btnDYN(colAjout, "btnAjouter_" + idItem, "btn valignMessage btnPageOrange", "Ajouter au panier", btnAjouter_click);

        btnAjout.UseSubmitBehavior = false;
        LibrairieControlesDynamique.lblDYN(colAjout, nomEntreprise + "_espaceGlyph_" + idItem, "<br>", "");
        long  leVendeurProduit  = produitAfficher.NoVendeur.Value;
        short nbProduitEnPanier = 0;

        if (dbContext.PPArticlesEnPanier.Where(c => (c.NoClient.Value.Equals(noClient)) && (c.NoVendeur.Value.Equals(leVendeurProduit)) && (c.NoProduit.Value.Equals(idItem))).Any())
        {
            nbProduitEnPanier = dbContext.PPArticlesEnPanier.Where(c => (c.NoClient.Value.Equals(noClient)) && (c.NoVendeur.Value.Equals(leVendeurProduit)) && (c.NoProduit.Value.Equals(idItem))).First().NbItems.Value;
        }
        LibrairieControlesDynamique.lblDYN(colAjout, nomEntreprise + "_nbEnPanier_" + idItem, "(" + nbProduitEnPanier + ")", "glyphicon glyphicon-shopping-cart");

        if (produitAfficher.NombreItems < 1)
        {
            tbQuantite.Enabled = false;
            LibrairieControlesDynamique.lblDYN(colQuantite, "lblRupture" + idItem, "<br>Rupture de stock", "rupture-stock");
            btnAjout.Enabled  = false;
            btnAjout.CssClass = "btn valignMessage btnPageOrange disabled";
        }
        else
        {
            tbQuantite.Enabled = true;
            btnAjout.Enabled   = true;
            btnAjout.CssClass  = "btn valignMessage btnPageOrange";
        }



        Panel rowDescription = LibrairieControlesDynamique.divDYN(panelBody, nomEntreprise + "_rowDescription_" + idItem, "row top15");

        LibrairieControlesDynamique.lblDYN(rowDescription, nomEntreprise + "_descTitle_" + idItem, "Description", "cat_item col-sm-2 center-block text-center");
        LibrairieControlesDynamique.lblDYN(rowDescription, nomEntreprise + "_description_" + idItem, produitAfficher.Description, "description_item cat_item col-sm-10 center-block breakWord ");
        LibrairieControlesDynamique.hrDYN(panelBody);
        Panel panelRetour = LibrairieControlesDynamique.divDYN(panelBody, nomEntreprise + "_retour_", "row center-block text-center Retour");

        LibrairieControlesDynamique.lbDYN(panelRetour, "back_", "Retour", btnRetour);
    }
Esempio n. 16
0
    private void PageVendeur(Panel panel, Vendeur vendeur = null, String categorie = null, int nbArticleParPage = 15, int page = 1, int TypeRecherche = 0, string rechercher = "", Boolean effectuerRecherche = false)
    {
        lblProduits.Text = vendeur == null? "Produits de tous les vendeurs": "Produits du vendeur " + vendeur.NomAffaires;
        PPProduits            produits  = new PPProduits();
        IEnumerable <Produit> enumProds = produits.Values.Where(p => p.NombreItems != -1 || p.Disponibilité == true);

        enumProds = vendeur == null ? enumProds : enumProds.Where(c => c.NoVendeur == vendeur.NoVendeur);
        enumProds = categorie == null ? enumProds : enumProds.Where(c => c.NoCategorie.ToString().Equals(categorie));
        if (effectuerRecherche)
        {
            switch (TypeRecherche)
            {
            case 0:
                enumProds = enumProds.Where(p => p.DateCreation.ToString().Contains(rechercher));
                break;

            case 1:
                enumProds = enumProds.Where(p => p.NoProduit.ToString().Contains(rechercher));
                break;

            case 2:
                //la recherche s'effectue sur seulement 1 catégorie.
                List <Categorie> cat = categories.Values.Where(c => c.Description.Contains(rechercher)).ToList();
                if (cat.Count == 1)
                {
                    enumProds = enumProds.Where(p => p.NoCategorie.Equals(cat.First().NoCategorie));
                }
                break;

            case 3:
                enumProds = enumProds.Where(p => p.Description.Contains(rechercher));
                break;
            }
        }
        if (int.TryParse(Request.QueryString["Tri"], out int noTri))
        {
            ddlTri.SelectedIndex = noTri;
        }
        switch (ddlTri.SelectedIndex)
        {
        case 0:
            enumProds = enumProds.OrderBy(c => c.NoCategorie).ThenBy(c => c.Description);
            break;

        case 1:
            enumProds = enumProds.OrderBy(c => c.NoProduit);
            break;

        case 2:
            enumProds = enumProds.OrderBy(c => c.NoCategorie);
            break;

        case 3:
            enumProds = enumProds.OrderBy(c => c.DateCreation);
            break;
        }
        List <Produit> nouvelleListe = enumProds.ToList();

        int    index2     = 0;
        Panel  rows       = panelTable.DivDyn("", "");
        Double nbPagesMax = 1;

        if (nbArticleParPage != 0)
        {
            nbPagesMax = Math.Ceiling(Double.Parse((nouvelleListe.Count() / nbArticleParPage).ToString())) + 1;
        }
        ddlNbItemPage.SelectedValue = nbArticleParPage.ToString();
        if (vendeur != null)
        {
            ddlNomVendeur.SelectedValue = vendeur.NoVendeur.ToString();
            string image = "";

            if (vendeur.Configuration != null)
            {
                if (vendeur.Configuration.Contains(";"))
                {
                    string[] liste = vendeur.Configuration.Split(';');

                    if (liste.Length == 2)
                    {
                        if (liste[0] != "")
                        {
                            image = "~/Logos/" + liste[0];
                        }
                    }
                    else if (liste.Length == 3)
                    {
                        if (liste[0] != "")
                        {
                            image = "~/Logos/" + liste[0];
                        }
                    }
                }
                else
                {
                    image = "~/Logos/" + vendeur.Configuration;
                }
            }

            if (image != "")
            {
                imgLogo.ImageUrl = image;
                imgLogo.Visible  = true;
            }
        }
        else
        {
            ddlNomVendeur.SelectedValue = "";
        }

        for (int nbPage = 1; nbPage <= nbPagesMax; nbPage++)
        {
            HtmlGenericControl li = new HtmlGenericControl("li");
            li.Attributes["class"] = "page-item " + ((nbPage == page) ? "disabled" : "");
            pagination.Controls.Add(li);

            HtmlGenericControl anchor = new HtmlGenericControl("a");
            anchor.Attributes["class"] = "page-link";
            string strUrl = "/Pages/Client/Catalogue.aspx?";
            if (vendeur != null)
            {
                strUrl += "NoVendeur=" + vendeur.NoVendeur + "&";
            }
            if (categorie != null)
            {
                strUrl += "NoCategorie=" + categorie + "&";
            }
            strUrl += "NbArticles=" + nbArticleParPage.ToString() + "&Page=" + nbPage.ToString();
            if (effectuerRecherche)
            {
                strUrl += "&TypeRecherche=" + Request.QueryString["TypeRecherche"] + "&Recherche=" + Request.QueryString["Recherche"];
            }
            anchor.Attributes.Add("href", strUrl + "&Tri=" + ddlTri.SelectedIndex);
            anchor.InnerText = nbPage.ToString();
            li.Controls.Add(anchor);
        }
        int nbArticleAffiche = 0;

        for (int indexItem = 0; indexItem < nouvelleListe.Count(); indexItem++)
        {
            if (nbArticleParPage == 0 || (indexItem >= ((page - 1) * nbArticleParPage) && indexItem < (page * nbArticleParPage)))
            {
                if (nbArticleAffiche % 3 == 0)
                {
                    rows = panelTable.DivDyn("", "row");
                    index2++;
                }
                string strCategorie = "";
                foreach (Categorie cat in categories.Values)
                {
                    if (cat.NoCategorie.Equals(nouvelleListe[indexItem].NoCategorie))
                    {
                        strCategorie = cat.Description;
                        break;
                    }
                }
                Panel     panelCard            = rows.DivDyn("", "col-fhd-4 mb-3");
                Panel     card                 = panelCard.DivDyn("", "card");
                Panel     panelTitreCategories = card.DivDyn("", "card-header fake-button");
                Table     tableT               = panelTitreCategories.TableDyn("", "");
                TableRow  rowt                 = tableT.TrDyn();
                TableCell cell1                = rowt.TdDyn();
                cell1.ImgDyn("", "~/Pictures/" + nouvelleListe[indexItem].Photo, "imgResize");
                TableCell cell2 = rowt.TdDyn();
                cell2.LblDyn("", " " + nouvelleListe[indexItem].Nom, "card-title h6");
                cell2.LblDyn("", " (#" + nouvelleListe[indexItem].NoProduit.ToString() + ")  <br/>Catégorie: " + strCategorie, "card-title h6");
                if (couleurTexte != "")
                {
                    cell2.ForeColor = System.Drawing.ColorTranslator.FromHtml(couleurTexte);
                }
                bool EstEnRupture = nouvelleListe[indexItem].NombreItems == 0 ? true : false;
                if (EstEnRupture)
                {
                    cell2.LblDyn("", " Rupture de stock!", "card-title h6 text-uppercase font-weight-bold text-danger");
                }
                panelTitreCategories.Attributes.Add("data-toggle", "collapse");
                panelTitreCategories.Attributes.Add("data-target", "#Contenu_ContenuPrincipal_collapsePanier" + indexItem.ToString() + index2.ToString());
                panelTitreCategories.Attributes.Add("aria-expanded", "false");
                panelTitreCategories.Attributes.Add("aria-controls", "Contenu_ContenuPrincipal_collapsePanier" + indexItem.ToString() + index2.ToString());

                Panel collapsable;
                //body des categories

                collapsable = card.DivDyn("collapsePanier" + indexItem.ToString() + index2.ToString(), "collapse collapse");

                //colones header
                Panel panelBodyCat = collapsable.DivDyn("", "card-body");

                HyperLink hlink = new HyperLink();
                hlink.NavigateUrl = "/Pages/Client/InfoProduit.aspx?ID=" + nouvelleListe[indexItem].NoProduit;
                hlink.Text        = "Détails du produit";
                hlink.Attributes.Add("role", "button");
                hlink.CssClass = "btn btn-info w-100";
                panelBodyCat.Controls.Add(hlink);
                //panelBodyCat.LblDyn("", "Catégorie: " + strCategorie);
                Table          table    = panelBodyCat.TableDyn("", "table");
                TableHeaderRow rowTable = table.ThrDyn();


                rowTable.ThdDyn("Date de parution");
                rowTable.ThdDyn("Poids");
                rowTable.ThdDyn("Prix");
                rowTable.ThdDyn("Qte");

                TableRow rowTableB = table.TrDyn();

                rowTableB.TdDyn(nouvelleListe[indexItem].DateCreation.GetValueOrDefault().Date.ToShortDateString());
                rowTableB.TdDyn(nouvelleListe[indexItem].Poids.Value.ToString("N2") + " Lbs");
                rowTableB.TdDyn(nouvelleListe[indexItem].PrixDemande.Value.ToString("N2") + " $");
                rowTableB.TdDyn(nouvelleListe[indexItem].NombreItems.Value.ToString());

                if (!EstEnRupture)
                {
                    TableRow rowTableC = table.TrDyn();

                    TableCell tbcell1 = rowTableC.TdDyn();
                    tbcell1.LblDyn("", "Quantité à commander: ");
                    TableCell    tbcell2 = rowTableC.TdDyn();
                    DropDownList ddl     = new DropDownList();
                    for (int i = 0; i < nouvelleListe[indexItem].NombreItems.Value; i++)
                    {
                        ddl.Items.Add((i + 1).ToString());
                    }
                    ddl.SelectedIndex = 0;
                    ddl.CssClass      = "form-control";
                    tbcell2.Controls.Add(ddl);
                    TableCell tbcell3 = rowTableC.TdDyn();

                    Button btn = tbcell3.BtnClientDyn("", "Ajouter au panier", $"ajouterArticle({Session.GetClient().NoClient},{nouvelleListe[indexItem].NoProduit},'{ddl.ClientID}');return false;", "btn btn-success");
                    btn.Attributes.Add("data-toggle", "modal");
                    btn.Attributes.Add("data-target", "#Contenu_ContenuPrincipal_myModal" + indexItem.ToString() + index2.ToString());
                }
                nbArticleAffiche++;
            }
        }
        if (nouvelleListe.Count() == 0)
        {
            panelTable.TbDyn("", "Il n'y a pas de produit qui correspond aux critères de recherche", 100, "w-100 text-center");
        }
    }
    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");
        }
    }
Esempio n. 18
0
    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++;
            }
        }
    }
Esempio n. 19
0
    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");
         * }*/
    }
    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");
        }
    }