public static object RestaurerT1()
        {
            string[] text = { };
            try {
                if (File.Exists(@"Huiles.txt"))
                {
                    text = File.ReadAllLines(@"Huiles.txt");

                    if (text.Length != 0)
                    {
                        foreach (string line in text)
                        {
                            string[] champs = line.Split('-');
                            Huile    huile  = new Huile(champs[0], Convert.ToInt32(champs[1]), Convert.ToInt32(champs[2]),
                                                        Convert.ToDouble(champs[3]), Convert.ToInt32(champs[4]), champs[5]);
                            Saisie(huile);
                        }
                    }
                }
            }
            catch (IOException e)
            {
                return("Erreur dans l'ouverture du fichier!");
            }catch (IndexOutOfRangeException e)
            {
                return("Le format du fichier est incompatible!");
            }

            return(text);
        }
        public int Compare(object x, object y)
        {
            Huile h1 = (Huile)x;
            Huile h2 = (Huile)y;

            return(h1.GetStock().CompareTo(h2.GetStock()));
        }
        public static ArrayList MaxVF()
        {
            ArrayList maxVF = new ArrayList();

            for (int i = 0; i < T1.Count; i++)
            {
                Huile huile = (Huile)T1[i];
                if (huile.GetVf() == 20)
                {
                    maxVF.Add(huile);
                }
            }
            return(maxVF);
        }
        public static ArrayList Rupture_Stock()
        {
            ArrayList T2 = new ArrayList();

            for (int i = 0; i < T1.Count; i++)
            {
                Huile huile = (Huile)T1[i];
                if (huile.GetStock() == 0)
                {
                    T2.Add(huile);
                }
            }
            return(T2);
        }
        public static double Valeur_total(string fournisseur)
        {
            double total = 0;

            for (int i = 0; i < T1.Count; i++)
            {
                Huile huile = (Huile)T1[i];
                if (huile.GetPetrolier().Equals(fournisseur))
                {
                    total += huile.GetPrix() * huile.GetStock();
                }
            }
            return(total);
        }
        public static ArrayList Viscosite_Max()
        {
            ArrayList viscositeMax = new ArrayList();

            for (int i = 0; i < T1.Count; i++)
            {
                Huile huile = (Huile)T1[i];
                if (huile.GetVf() == 20 || huile.GetVc() == 50)
                {
                    viscositeMax.Add(huile);
                }
            }
            return(viscositeMax);
        }
        public static ArrayList MaxVC()
        {
            ArrayList maxVC = new ArrayList();

            for (int i = 0; i < T1.Count; i++)
            {
                Huile huile = (Huile)T1[i];
                if (huile.GetVc() == 50)
                {
                    maxVC.Add(huile);
                }
            }
            return(maxVC);
        }
        public static ArrayList Destockage()
        {
            ArrayList T3 = new ArrayList();

            for (int i = 0; i < T1.Count; i++)
            {
                Huile huile = (Huile)T1[i];
                if (huile.GetStock() > 0 && huile.GetStock() <= 5)
                {
                    double nouveauPrix = huile.GetPrix() - huile.GetPrix() * 40 / 100;
                    huile.SetPrix(nouveauPrix);
                    T3.Add(huile);
                }
            }
            SauvegarderT1();
            return(T3);
        }
        public static string Supprimer_Viscosite(int vf, int vc)
        {
            string message = "Aucun huile trouvé!";

            for (int i = 0; i < T1.Count; i++)
            {
                Huile huile = (Huile)T1[i];
                if (huile.GetVf().Equals(vf) && huile.GetVc().Equals(vc))
                {
                    T1.Remove(huile);
                    message = "Huiles supprimé avec succés";
                }
            }
            SauvegarderT1();

            return(message);
        }
示例#10
0
        private void valider_btn_Click(object sender, EventArgs e)
        {
            string nom = nom_txt.Text;
            int    vf = Convert.ToInt32(vf_combo.SelectedItem), vc = Convert.ToInt32(vc_combo.SelectedItem);
            double prix      = Convert.ToDouble(prix_txt.Text);
            int    stock     = Convert.ToInt32(stock_txt.Text);
            string petrolier = petrolier_txt.Text;
            Huile  huile     = new Huile(nom, vf, vc, prix, stock, petrolier);

            try
            {
                Program.Menu("Ajouter", huile);
                message_lbl.Text = "Huile ajouté avec succés";
            }catch (Exception exp)
            {
                message_lbl.Text = "Oups Il y a un problème";
            }


            reinitialiser_btn_Click(sender, e);
        }
 public static void Saisie(Huile huile)
 {
     T1.Add(huile);
     SauvegarderT1();
 }