Beispiel #1
0
        //------------------------------------
        public static CValeurUnite operator *(CValeurUnite valeur1, CValeurUnite valeur2)
        {
            string strU2 = CUtilUnite.GetUniteHarmonisee(valeur1.Unite, valeur2.Unite);

            if (strU2 != valeur2.Unite)
            {
                valeur2 = valeur2.ConvertTo(strU2);
            }
            string[]     strCompos = CUtilUnite.Developpe(valeur1.Unite + "." + valeur2.Unite);
            string       strUnite  = CUtilUnite.Factorise(strCompos);
            CValeurUnite valeur    = new CValeurUnite(valeur1.Valeur * valeur2.Valeur, strUnite);

            return(valeur);
        }
Beispiel #2
0
        public CValeurUnite ConvertTo(string strUnite)
        {
            if (strUnite == Unite)
            {
                return(this);
            }
            string strMyCle    = CUtilUnite.GetIdClasseUnite(Unite);
            string strAutrecle = CUtilUnite.GetIdClasseUnite(strUnite);

            if (strMyCle == null || strAutrecle == null || strMyCle != strAutrecle)
            {
                throw new Exception(I.T("Can not convert from @1 to @2|20017", Unite, strUnite));
            }
            double fValeur = ConvertToBase();

            string[] strComposants = CUtilUnite.Developpe(strUnite);
            foreach (string strComposant in strComposants)
            {
                string strIdUnite = strComposant;
                bool   bDiviser   = false;
                if (strComposant[0] == '/')
                {
                    bDiviser   = true;
                    strIdUnite = strComposant.Substring(1);
                }
                IUnite unite = CGestionnaireUnites.GetUnite(strIdUnite);
                if (unite == null)
                {
                    return(this);
                }
                if (bDiviser)
                {
                    fValeur *= unite.FacteurVersBase;
                }
                else
                {
                    fValeur /= unite.FacteurVersBase;
                }
            }
            return(new CValeurUnite(fValeur, CUtilUnite.Factorise(strComposants)));
        }
Beispiel #3
0
        //------------------------------------
        public static CValeurUnite GetValeurFromValeurBase(double fValeurDeBase, string strUnite)
        {
            double fValeur = fValeurDeBase;

            string[] strComposants = CUtilUnite.Developpe(strUnite);
            foreach (string strComposant in strComposants)
            {
                string strIdUnite = strComposant;
                bool   bDiviser   = false;
                if (strComposant[0] == '/')
                {
                    bDiviser   = true;
                    strIdUnite = strComposant.Substring(1);
                }
                if (strComposant[0] == '.')
                {
                    strIdUnite = strComposant.Substring(1);
                }
                IUnite unite = CGestionnaireUnites.GetUnite(strIdUnite);
                if (unite == null)
                {
                    return(null);
                }
                if (bDiviser)
                {
                    fValeur *= unite.FacteurVersBase;
                }
                else
                {
                    fValeur /= unite.FacteurVersBase;
                }
                if (strComposant.Length == 1)
                {
                    fValeur -= unite.OffsetVersBase;
                }
            }
            return(new CValeurUnite(fValeur, strUnite));
        }
Beispiel #4
0
        //------------------------------------
        public double ConvertToBase()
        {
            double fValeur = Valeur;

            string[] strComposants = CUtilUnite.Developpe(Unite);
            foreach (string strComposant in strComposants)
            {
                string strIdUnite = strComposant;
                bool   bDiviser   = false;
                if (strComposant[0] == '/')
                {
                    bDiviser   = true;
                    strIdUnite = strComposant.Substring(1);
                }
                if (strComposant[0] == '.')
                {
                    strIdUnite = strComposant.Substring(1);
                }
                IUnite unite = CGestionnaireUnites.GetUnite(strIdUnite);
                if (unite == null)
                {
                    return(Valeur);
                }
                if (bDiviser)
                {
                    fValeur /= unite.FacteurVersBase;
                }
                else
                {
                    fValeur *= unite.FacteurVersBase;
                }
                if (strComposants.Length == 1)
                {
                    fValeur += unite.OffsetVersBase;
                }
            }
            return(fValeur);
        }