Exemple #1
0
        public ViewResult LoadList()
        {
            int            page_Size = 20;
            List <Product> ProList   = dao.GetAllProduct();
            string         current_P = Request["page"];

            if (current_P == null)
            {
                current_P = "1";
            }
            if (!System.Text.RegularExpressions.Regex.IsMatch(current_P, "[0-9]{1,5}"))
            {
                current_P = "1";
            }
            if (current_P.Equals("0"))
            {
                current_P = "1";
            }
            int totalRecord = ProList.Count;

            int total_Page = 1;

            if (totalRecord % page_Size == 0)
            {
                total_Page = totalRecord / page_Size;
            }
            else
            {
                total_Page = (totalRecord / page_Size) + 1;
            }
            if (int.Parse(current_P) > total_Page)
            {
                current_P = "1";
            }
            int            current_Page = int.Parse(current_P);
            List <Product> current_List = new List <Product>();

            for (int i = (current_Page - 1) * page_Size; i < (current_Page * page_Size); i++)
            {
                if (i == totalRecord)
                {
                    break;
                }
                else
                {
                    current_List.Add(ProList[i]);
                }
            }
            var          model = current_List;
            List <Brand> brand = dao_Brand.GetAllBrands();

            Session["Brand"] = brand;
            List <Category> category = dao_Category.GetAllCategories();

            Session["Category"] = category;
            Session["Page"]     = total_Page;
            return(View("LoadList", model));
        }
        /// <summary>
        /// Constructeur de la fenetre
        /// </summary>
        public AddArticleForm()
        {
            InitializeComponent();

            // rempli la combo box marque avec la liste des marques existante
            Brand[] AllBrand = BrandDAO.GetAllBrands();
            foreach (Brand B in AllBrand)
            {
                BrandComboBox.Items.Add(B);
            }

            // rempli la combo box famille avec la liste des familles existante
            Family[] AllFamily = FamilyDAO.GetAllFamilies();
            foreach (Family F in AllFamily)
            {
                FamilyComboBox.Items.Add(F);
            }

            //attend qu'une famille soit sélectionnée
            SubFamilyComboBox.Items.Add("Selectionnez d'abord une famille");
        }
Exemple #3
0
        /// <summary>
        /// Recréer les tableaux en fonctions des données de la bdd pour le mettre à jour
        /// </summary>
        /// <param name="NodeName"></param>
        private void UpdateListView(String NodeName)
        {
            int ColumnsWidth = 0;

            // reinitialise le trie
            MainListView.ListViewItemSorter = null;

            // choisi quel tableau mettre à jour ou créer
            switch (NodeName)
            {
            case "Articles":
                Article[] Articles = ArticleDAO.GetAllArticles();

                MainListView.Columns.Clear();
                MainListView.Items.Clear();
                MainListView.Groups.Clear();
                ColumnsWidth = MainListView.Width / 7;
                MainListView.Columns.Add("Quantité", ColumnsWidth);
                MainListView.Columns.Add("Description", ColumnsWidth);
                MainListView.Columns.Add("Référence", ColumnsWidth);
                MainListView.Columns.Add("Marque", ColumnsWidth);
                MainListView.Columns.Add("Famille", ColumnsWidth);
                MainListView.Columns.Add("Sous-Famille", ColumnsWidth);
                MainListView.Columns.Add("Prix H.T.", ColumnsWidth);
                foreach (Article A in Articles)
                {
                    string[] ArticleToAdd = new string[7];

                    ListViewItem ArticleItem;
                    // ajoute les items a la ListView
                    ArticleToAdd[0] = A.Quantity.ToString();
                    ArticleToAdd[1] = A.Description;
                    ArticleToAdd[2] = A.RefArticle;
                    ArticleToAdd[3] = A.RefBrand.ToString();
                    ArticleToAdd[4] = A.RefSubFamily.RefFamily.ToString();
                    ArticleToAdd[5] = A.RefSubFamily.ToString();
                    ArticleToAdd[6] = A.PriceHT.ToString();
                    ArticleItem     = new ListViewItem(ArticleToAdd);
                    MainListView.Items.Add(ArticleItem);
                }
                break;

            case "Marques":
                Brand[] Brands = BrandDAO.GetAllBrands();

                MainListView.Columns.Clear();
                MainListView.Items.Clear();
                MainListView.Groups.Clear();
                ColumnsWidth = MainListView.Width / 2;
                MainListView.Columns.Add("Nom", ColumnsWidth);
                MainListView.Columns.Add("Référence", ColumnsWidth);
                foreach (Brand B in Brands)
                {
                    string[] BrandToAdd = new string[2];

                    ListViewItem BrandItem;
                    // ajoute les items a la ListView
                    BrandToAdd[0] = B.NameBrand;
                    BrandToAdd[1] = B.RefBrand.ToString();
                    BrandItem     = new ListViewItem(BrandToAdd);
                    MainListView.Items.Add(BrandItem);
                }
                break;

            case "Familles":
                Family[] Families = FamilyDAO.GetAllFamilies();

                MainListView.Columns.Clear();
                MainListView.Items.Clear();
                MainListView.Groups.Clear();
                ColumnsWidth = MainListView.Width / 2;
                MainListView.Columns.Add("Nom", ColumnsWidth);
                MainListView.Columns.Add("Référence", ColumnsWidth);
                foreach (Family F in Families)
                {
                    string[] FamilyToAdd = new string[2];

                    ListViewItem FamilyItem;
                    // ajoute les items a la ListView
                    FamilyToAdd[0] = F.NameFamily;
                    FamilyToAdd[1] = F.RefFamily.ToString();
                    FamilyItem     = new ListViewItem(FamilyToAdd);
                    MainListView.Items.Add(FamilyItem);
                }
                break;

            case "Sous familles":
                SubFamily[] SubFamilies = SubFamilyDAO.GetAllSubFamilies();

                MainListView.Columns.Clear();
                MainListView.Items.Clear();
                MainListView.Groups.Clear();
                ColumnsWidth = MainListView.Width / 3;
                MainListView.Columns.Add("Nom", ColumnsWidth);
                MainListView.Columns.Add("Référence", ColumnsWidth);
                MainListView.Columns.Add("Familles", ColumnsWidth);
                foreach (SubFamily SF in SubFamilies)
                {
                    string[] SubFamilyToAdd = new string[3];

                    ListViewItem SubFamilyItem;
                    // ajoute les items a la ListView
                    SubFamilyToAdd[0] = SF.NameSubFamily;
                    SubFamilyToAdd[1] = SF.RefSubFamily.ToString();
                    SubFamilyToAdd[2] = SF.RefFamily.ToString();
                    SubFamilyItem     = new ListViewItem(SubFamilyToAdd);
                    MainListView.Items.Add(SubFamilyItem);
                }
                break;

            default:
                break;
            }
        }
        /// <summary>
        /// Constructeur de la fenetre qui initialise tout les champs à partir des données de l'article modifié
        /// </summary>
        /// <param name="SelectedItem"></param>
        public ModifyArticleForm(ListViewItem SelectedItem)
        {
            InitializeComponent();

            // rempli la combo box marque avec la liste des marques existante
            int Index      = 0;
            int IndexBrand = 0;

            Brand[] AllBrand = BrandDAO.GetAllBrands();
            foreach (Brand B in AllBrand)
            {
                BrandComboBox.Items.Add(B);
                if (B.ToString() == SelectedItem.SubItems[3].Text)
                {
                    IndexBrand = Index;
                }
                Index++;
            }

            BrandComboBox.SelectedIndex = IndexBrand;

            // rempli la combo box famille avec la liste des familles existante
            Index = 0;
            int IndexFamily = 0;

            Family[] AllFamily = FamilyDAO.GetAllFamilies();
            foreach (Family F in AllFamily)
            {
                FamilyComboBox.Items.Add(F);
                if (F.ToString() == SelectedItem.SubItems[4].Text)
                {
                    IndexFamily = Index;
                }
                Index++;
            }

            FamilyComboBox.SelectedIndex = IndexFamily;

            // rempli la combo box sous famille avec la liste des sous familles appartenant à la famille selectionnée
            Index = 0;
            int IndexSubFamily = 0;

            SubFamilyComboBox.Items.Clear();
            SubFamily[] AllLinkedSubFamilies = FamilyDAO.GetAllSubFamilies((Family)FamilyComboBox.SelectedItem);
            foreach (SubFamily SF in AllLinkedSubFamilies)
            {
                SubFamilyComboBox.Items.Add(SF);
                if (SF.ToString() == SelectedItem.SubItems[4].Text)
                {
                    IndexSubFamily = Index;
                }
                Index++;
            }

            SubFamilyComboBox.SelectedIndex = IndexSubFamily;

            // initialise les champs avec les données de l'article modifié
            ArticleNameLabel.Text   = SelectedItem.SubItems[2].Text;
            DescriptionTextBox.Text = SelectedItem.SubItems[1].Text;
            PriceHTTextBox.Text     = SelectedItem.SubItems[6].Text;
            QuantityTextBox.Text    = SelectedItem.SubItems[0].Text;
        }