Example #1
0
        public void LoadListView()
        {
            ModelList ModelList = new ModelList();

            ListView.GridLines = true;
            ListView.View      = System.Windows.Forms.View.Details;
            ModelList          = ModelListController.GetAllModelList();

            Node = TreeView.SelectedNode;

            if (Node.Text.Equals("Tous les articles"))
            {
                ListView.Clear();

                ListView.Columns.Add("Référence", "Référence");
                ListView.Columns.Add("Description", "Description");
                ListView.Columns.Add("Famille", "Famille");
                ListView.Columns.Add("Sous-famille", "Sous-famille");
                ListView.Columns.Add("Marque", "Marque");
                ListView.Columns.Add("Prix", "Prix H.T.");
                ListView.Columns.Add("Quantité", "Quantité");

                foreach (var Article in ModelList.Articles)
                {
                    ListView.Items.Add(new ListViewItem(Article.InfoTable()));
                }

                ListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
                ListView.Text = "Articles";
                ToolStripStatusLabel1.Text = "Tous les articles: " + ModelList.Articles.Count;
            }

            else if (Node.Text.Equals("Familles"))
            {
                ListView.Clear();

                ListView.Columns.Add("Description", "Description");

                this.ListView.ListViewItemSorter = new Util.ListViewItemComparer(0, ListView.Sorting);


                if (Node.Nodes.Count == 0)
                {
                    foreach (var Famille in ModelList.Familles)
                    {
                        ListView.Items.Add(new ListViewItem(Famille.InfoTable()));
                        TreeView.Nodes[1].Nodes.Add(Famille.FamilleName);
                        FamilleNames.Add(Famille.FamilleName);
                    }
                }
                else
                {
                    foreach (var Famille in ModelList.Familles)
                    {
                        ListView.Items.Add(new ListViewItem(Famille.InfoTable()));
                        FamilleNames.Add(Famille.FamilleName);
                    }
                }

                ListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
                ListView.Text = "Familles";
                ToolStripStatusLabel1.Text = "Familles: " + ModelList.Familles.Count;
            }

            else if (Node.Text.Equals("Marques"))
            {
                ListView.Clear();

                ListView.Columns.Add("Description", "Description");

                this.ListView.ListViewItemSorter = new Util.ListViewItemComparer(0, ListView.Sorting);

                if (Node.Nodes.Count == 0)
                {
                    foreach (var Marque in ModelList.Marques)
                    {
                        ListView.Items.Add(new ListViewItem(Marque.InfoTable()));
                        TreeView.Nodes[2].Nodes.Add(Marque.MarqueName);
                        MarqueNames.Add(Marque.MarqueName);
                    }
                }
                else
                {
                    foreach (var Marque in ModelList.Marques)
                    {
                        ListView.Items.Add(new ListViewItem(Marque.InfoTable()));
                        MarqueNames.Add(Marque.MarqueName);
                    }
                }

                ListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
                ListView.Text = "Marques";
                ToolStripStatusLabel1.Text = "Marques: " + ModelList.Marques.Count;
            }

            else if (FamilleNames.Contains(Node.Text))
            {
                List <SousFamilles> SousFamilles = SousFamilleController.FindSousFamillesByFamilleName(Node.Text);
                ListView.Clear();
                ListView.Columns.Add("Description", "Description");

                this.ListView.ListViewItemSorter = new Util.ListViewItemComparer(0, ListView.Sorting);

                if (Node.Nodes.Count == 0)
                {
                    foreach (var SousFamille in SousFamilles)
                    {
                        TreeView.Nodes[1].Nodes[FamilleNames.IndexOf(Node.Text)].Nodes.Add(SousFamille.SousFamilleName);
                        ListView.Items.Add(new ListViewItem(SousFamille.InfoTable()));
                        SousFamilleNames.Add(SousFamille.SousFamilleName);
                    }
                }
                else
                {
                    foreach (var SousFamille in SousFamilles)
                    {
                        ListView.Items.Add(new ListViewItem(SousFamille.InfoTable()));
                        SousFamilleNames.Add(SousFamille.SousFamilleName);
                    }
                }

                ListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
                ListView.Text = "SousFamilles";
                ToolStripStatusLabel1.Text = "SousFamilles de " + Node.Text + ": " + SousFamilles.Count;
            }

            else if (MarqueNames.Contains(Node.Text))
            {
                List <Articles> Articles = ArticlesController.FindArticlesByMarqueName(Node.Text);
                ListView.Clear();

                ListView.Columns.Add("Référence", "Référence");
                ListView.Columns.Add("Description", "Description");
                ListView.Columns.Add("Famille", "Famille");
                ListView.Columns.Add("Sous-famille", "Sous-famille");
                ListView.Columns.Add("Marque", "Marque");
                ListView.Columns.Add("Prix", "Prix H.T.");
                ListView.Columns.Add("Quantité", "Quantité");

                foreach (var Article in Articles)
                {
                    ListView.Items.Add(new ListViewItem(Article.InfoTable()));
                }

                ListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
                ListView.Text = "Articles";
                ToolStripStatusLabel1.Text = "Articles de Marque " + Node.Text + ": " + Articles.Count;
            }

            else if (SousFamilleNames.Contains(Node.Text))
            {
                List <Articles> Articles = ArticlesController.FindArticlesBySousFamilleName(Node.Text);
                ListView.Clear();

                ListView.Columns.Add("Référence", "Référence");
                ListView.Columns.Add("Description", "Description");
                ListView.Columns.Add("Famille", "Famille");
                ListView.Columns.Add("Sous-famille", "Sous-famille");
                ListView.Columns.Add("Marque", "Marque");
                ListView.Columns.Add("Prix", "Prix H.T.");
                ListView.Columns.Add("Quantité", "Quantité");

                foreach (var Article in Articles)
                {
                    ListView.Items.Add(new ListViewItem(Article.InfoTable()));
                }

                ListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
                ListView.Text = "Articles";
                ToolStripStatusLabel1.Text = "Articles de Sous-famille " + Node.Text + ": " + Articles.Count;
            }

            TreeView.ExpandAll();
            ListView.Sort();
            ListView.Show();
        }